sPyNNaker neural_modelling 7.2.2
Loading...
Searching...
No Matches
current_source_step.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_STEP_H_
22#define _CURRENT_SOURCE_STEP_H_
23
24#include <random.h>
25#include <normal.h>
26
27// Structures for different current sources used in this impl
29 uint32_t times_length;
30 uint32_t times[];
32
34 uint32_t amp_length;
35 REAL amplitudes[];
37
38// Global values used in step current source
39static step_current_source_times_t **step_cs_times;
40static step_current_source_amps_t **step_cs_amps;
41static REAL *step_cs_amp_last;
42static uint32_t *step_cs_index;
43
44static bool current_source_step_init(
45 address_t cs_address, uint32_t n_step_current_sources, uint32_t *next) {
46 if (n_step_current_sources > 0) {
47 step_cs_times = spin1_malloc(n_step_current_sources * sizeof(uint32_t*));
48 step_cs_amps = spin1_malloc(n_step_current_sources * sizeof(uint32_t*));
49 step_cs_amp_last = spin1_malloc(n_step_current_sources * sizeof(REAL));
50 step_cs_index = spin1_malloc(n_step_current_sources * sizeof(uint32_t));
51 if (step_cs_amp_last == NULL) {
52 log_error("Unable to allocate step current source amp last - out of DTCM");
53 return false;
54 }
55 if (step_cs_index == NULL) {
56 log_error("Unable to allocate step current source index - out of DTCM");
57 return false;
58 }
59 }
60 for (uint32_t n_step=0; n_step < n_step_current_sources; n_step++) {
61 uint32_t arr_len = (uint32_t) cs_address[*next];
62 uint32_t struct_size = (arr_len + 1) * sizeof(uint32_t);
63 step_cs_times[n_step] = spin1_malloc(struct_size);
64 if (step_cs_times[n_step] == NULL) {
65 log_error("Unable to allocate step current source times - out of DTCM",
66 "struct_size is %u next %u n_step %u)", struct_size, *next, n_step);
67 return false;
68 }
69
70 step_cs_amps[n_step] = spin1_malloc(struct_size);
71 if (step_cs_amps[n_step] == NULL) {
72 log_error("Unable to allocate step current source amplitudes - out of DTCM",
73 "(struct_size is %u next %u n_step %u)", struct_size, *next, n_step);
74 return false;
75 }
76
77 *next += 2 * (arr_len + 1);
78 // Initialise last value and current index along the array for this source
79 step_cs_amp_last[n_step] = ZERO;
80 step_cs_index[n_step] = 0;
81 }
82 return true;
83}
84
85static bool current_source_step_load_parameters(
86 address_t cs_address, uint32_t n_step_current_sources, uint32_t *next) {
87 for (uint32_t n_step=0; n_step < n_step_current_sources; n_step++) {
88 uint32_t arr_len = (uint32_t) cs_address[*next];
89 uint32_t struct_size = (arr_len + 1) * sizeof(uint32_t);
90
91 spin1_memcpy(step_cs_times[n_step], &cs_address[*next], struct_size);
92 spin1_memcpy(step_cs_amps[n_step], &cs_address[*next+arr_len+1], struct_size);
93
94 *next += 2 * (arr_len + 1);
95
96 // Does this need to happen here too? (What happens on reload??)
97 step_cs_amp_last[n_step] = ZERO;
98 step_cs_index[n_step] = 0;
99 }
100 return true;
101}
102
103static REAL current_source_step_get_offset(uint32_t cs_index, uint32_t time) {
104 if (time >= step_cs_times[cs_index]->times[step_cs_index[cs_index]]) {
105 step_cs_amp_last[cs_index] =
106 step_cs_amps[cs_index]->amplitudes[step_cs_index[cs_index]];
107 step_cs_index[cs_index]++;
108 }
109 return step_cs_amp_last[cs_index];
110}
111
112#endif // _CURRENT_SOURCE_STEP_H_
uint32_t * address_t
void log_error(const char *message,...)
accum REAL
Type used for "real" numbers.
Definition maths-util.h:91
#define ZERO
A REAL 0.0.
Definition maths-util.h:123
void spin1_memcpy(void *dst, void const *src, uint len)