sPyNNaker neural_modelling 7.3.1
Loading...
Searching...
No Matches
current_source_ac.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_AC_H_
22#define _CURRENT_SOURCE_AC_H_
23
24#include <sincos.h>
25
26// Structure for AC current source
27typedef struct ac_source_t {
28 uint32_t start;
29 uint32_t stop;
30 REAL amplitude;
31 REAL offset;
32 REAL frequency;
33 REAL phase;
35
36static ac_source_t **ac_source;
37
38static bool current_source_ac_init(uint32_t n_ac_sources, uint32_t *next) {
39 ac_source = spin1_malloc(n_ac_sources * sizeof(uint32_t*));
40 for (uint32_t n_ac=0; n_ac < n_ac_sources; n_ac++) {
41 ac_source[n_ac] = spin1_malloc(sizeof(ac_source_t));
42 if (ac_source[n_ac] == NULL) {
43 log_error("Unable to allocate DC source parameters - out of DTCM");
44 return false;
45 }
46 *next += sizeof(ac_source_t) / 4;
47 }
48 return true;
49}
50
51static bool current_source_ac_load_parameters(
52 address_t cs_address, uint32_t n_ac_sources, uint32_t *next) {
53 for (uint32_t n_ac=0; n_ac < n_ac_sources; n_ac++) {
54 spin1_memcpy(ac_source[n_ac], &cs_address[*next], sizeof(ac_source_t));
55 *next += sizeof(ac_source_t) / 4;
56 }
57 return true;
58}
59
60static REAL current_source_ac_get_offset(uint32_t cs_index, uint32_t time) {
61 if ((time >= ac_source[cs_index]->start) && (time < ac_source[cs_index]->stop)) {
62 REAL time_value = kbits((time - ac_source[cs_index]->start) << 15);
63 REAL sin_value = sink((time_value * ac_source[cs_index]->frequency) +
64 ac_source[cs_index]->phase);
65 REAL ac_current_offset = ac_source[cs_index]->offset + (
66 ac_source[cs_index]->amplitude * sin_value);
67 return ac_current_offset;
68 }
69 return ZERO;
70}
71
72#endif // _CURRENT_SOURCE_AC_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
s1615 sink(s1615 x)
void spin1_memcpy(void *dst, void const *src, uint len)