21#ifndef _CURRENT_SOURCE_STEP_H_
22#define _CURRENT_SOURCE_STEP_H_
29 uint32_t times_length;
41static REAL *step_cs_amp_last;
42static uint32_t *step_cs_index;
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");
55 if (step_cs_index == NULL) {
56 log_error(
"Unable to allocate step current source index - out of DTCM");
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);
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);
77 *next += 2 * (arr_len + 1);
79 step_cs_amp_last[n_step] =
ZERO;
80 step_cs_index[n_step] = 0;
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);
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);
94 *next += 2 * (arr_len + 1);
97 step_cs_amp_last[n_step] =
ZERO;
98 step_cs_index[n_step] = 0;
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]++;
109 return step_cs_amp_last[cs_index];
void log_error(const char *message,...)
accum REAL
Type used for "real" numbers.
void spin1_memcpy(void *dst, void const *src, uint len)