sPyNNaker neural_modelling  development
c_main_common.h
1 /*
2  * Copyright (c) 2017 The University of Manchester
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <stdbool.h>
18 #include <stdint.h>
19 
20 #include <debug.h>
21 #include <data_specification.h>
22 #include <simulation.h>
23 #include <profiler.h>
24 #include <recording.h>
25 
26 /* validates that the model being compiled does indeed contain a application
27  * magic number*/
28 #ifndef APPLICATION_NAME_HASH
29 #error APPLICATION_NAME_HASH was undefined. Make sure you define this\
30  constant
31 #endif
32 
36  uint32_t system;
38  uint32_t provenance;
40  uint32_t profiler;
42  uint32_t recording;
43 };
44 
48  uint32_t sdp;
50  uint32_t dma;
52  uint32_t timer;
53 };
54 
76 static inline bool initialise_common_regions(
77  uint32_t *timer_period, uint32_t *simulation_ticks,
78  uint32_t *infinite_run, uint32_t *time, uint32_t *recording_flags,
79  prov_callback_t store_provenance_function, callback_t timer_callback,
80  struct common_regions regions, struct common_priorities priorities,
81  data_specification_metadata_t **ds_regions) {
82 
83  // Get the address this core's DTCM data starts at from SRAM
84  *ds_regions = data_specification_get_data_address();
85 
86  // Read the header
87  if (!data_specification_read_header(*ds_regions)) {
88  return false;
89  }
90 
91  // Get the timing details and set up the simulation interface
92  if (!simulation_initialise(
93  data_specification_get_region(regions.system, *ds_regions),
94  APPLICATION_NAME_HASH, timer_period, simulation_ticks,
95  infinite_run, time, priorities.sdp, priorities.dma)) {
96  return false;
97  }
98  simulation_set_provenance_function(
99  store_provenance_function,
100  data_specification_get_region(regions.provenance, *ds_regions));
101 
102  // Setup profiler
103  profiler_init(data_specification_get_region(regions.profiler, *ds_regions));
104 
105  // Setup recording
106  void *rec_addr = data_specification_get_region(regions.recording, *ds_regions);
107  if (!recording_initialize(&rec_addr, recording_flags)) {
108  return false;
109  }
110 
111  if (timer_callback) {
112 
113  // Set up the timer tick callback (others are handled elsewhere)
114  spin1_callback_on(TIMER_TICK, timer_callback, priorities.timer);
115  }
116 
117  return true;
118 }
119 
122 static inline void common_pause(uint32_t recording_flags) {
123 
124  // Finalise any recordings that are in progress
125  if (recording_flags > 0) {
126  recording_finalise();
127  }
128 
129  profiler_finalise();
130 }
static uint32_t recording_flags
The recording flags indicating if anything is recording.
Definition: c_main.c:106
static uint32_t simulation_ticks
Simulation speed.
static uint32_t infinite_run
True if we're running forever.
static uint32_t timer_period
Used for configuring the timer hardware.
static void timer_callback(uint timer_count, uint unused1)
Main timer callback.
static uint32_t time
Simulation time.
The callback priorities used by all simulation cores.
Definition: c_main_common.h:46
uint32_t sdp
The SDP callback priority.
Definition: c_main_common.h:48
uint32_t dma
The DMA callback priority.
Definition: c_main_common.h:50
uint32_t timer
The timer callback priority.
Definition: c_main_common.h:52
The identifiers of the regions used by all simulation cores.
Definition: c_main_common.h:34
uint32_t provenance
Where provenance data will be stored.
Definition: c_main_common.h:38
uint32_t recording
Where recording metadata will be read and stored.
Definition: c_main_common.h:42
uint32_t profiler
Where profile data will be read and stored.
Definition: c_main_common.h:40
uint32_t system
Data for general simulation setup.
Definition: c_main_common.h:36