sPyNNaker neural_modelling  development
current_source_dc.h
Go to the documentation of this file.
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 
21 #ifndef _CURRENT_SOURCE_DC_H_
22 #define _CURRENT_SOURCE_DC_H_
23 
24 typedef struct dc_source_t {
25  REAL amplitude;
26  uint32_t start;
27  uint32_t stop;
28 } dc_source_t;
29 
30 static dc_source_t **dc_source;
31 
32 static bool current_source_dc_init(uint32_t n_dc_sources, uint32_t *next) {
33  dc_source = spin1_malloc(n_dc_sources * sizeof(uint32_t*));
34  for (uint32_t n_dc=0; n_dc < n_dc_sources; n_dc++) {
35  dc_source[n_dc] = spin1_malloc(sizeof(dc_source_t));
36  if (dc_source[n_dc] == NULL) {
37  log_error("Unable to allocate DC source parameters - out of DTCM");
38  return false;
39  }
40  *next += sizeof(dc_source_t) / 4;
41  }
42  return true;
43 }
44 
45 static bool current_source_dc_load_parameters(
46  address_t cs_address, uint32_t n_dc_sources, uint32_t *next) {
47  for (uint32_t n_dc=0; n_dc < n_dc_sources; n_dc++) {
48  spin1_memcpy(dc_source[n_dc], &cs_address[*next], sizeof(dc_source_t));
49  *next += sizeof(dc_source_t) / 4;
50  }
51  return true;
52 }
53 
54 static REAL current_source_dc_get_offset(uint32_t cs_index, uint32_t time) {
55  if ((time >= dc_source[cs_index]->start) && (time < dc_source[cs_index]->stop)) {
56  return dc_source[cs_index]->amplitude;
57  }
58  return ZERO;
59 }
60 
61 #endif // _CURRENT_SOURCE_DC_H_
static uint32_t time
Simulation time.
accum REAL
Type used for "real" numbers.
Definition: maths-util.h:91
#define ZERO
A REAL 0.0.
Definition: maths-util.h:123