spinnaker_tools 3.4.0
SpiNNaker API, sark, sc&mp, bmp firmware and build tools
Loading...
Searching...
No Matches
spin1_api.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 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
19#ifndef __SPIN1_API_H__
20#define __SPIN1_API_H__
21
22#include "sark.h"
23
24// ------------------------------------------------------------------------
25// Useful SpiNNaker parameters
26// ------------------------------------------------------------------------
27/* shared memory */
28/* system RAM address and size */
30#define SPINN_SYSRAM_BASE SYSRAM_BASE
32#define SPINN_SYSRAM_SIZE SYSRAM_SIZE
33/* SDRAM address and size */
35#define SPINN_SDRAM_BASE SDRAM_BASE
37#define SPINN_SDRAM_SIZE SDRAM_SIZE
38
39// ------------------------------------------------------------------------
40// general parameters and definitions
41// ------------------------------------------------------------------------
42/* boolean constants */
44#define TRUE (0 == 0)
46#define FALSE (0 != 0)
47/* function results */
49#define SUCCESS (uint) 1
51#define FAILURE (uint) 0
52
53#ifndef NULL
55#define NULL 0
56#endif // NULL
57
58// ------------------------------------------------------------------------
59// event definitions
60// ------------------------------------------------------------------------
62enum {
72};
73
75static const uint VIC_EVENTS[] = {
76 (1 << CC_MC_INT),
77 (1 << DMA_DONE_INT),
78 (1 << TIMER1_INT),
79 0,
80 (1 << SOFTWARE_INT),
81 (1 << CC_MC_INT),
82 (1 << CC_FR_INT),
83 (1 << CC_FR_INT)
84};
85
86// ------------------------------------------------------------------------
87// DMA transfer parameters
88// ------------------------------------------------------------------------
90enum {
92 DMA_WRITE = 1
93};
94
95// ------------------------------------------------------------------------
96// packet parameters
97// ------------------------------------------------------------------------
99enum {
101 WITH_PAYLOAD = 1
103
104// ------------------------------------------------------------------------
105// type definitions
106// ------------------------------------------------------------------------
107
109typedef void (*callback_t) (uint, uint); // callbacks
110// ------------------------------------------------------------------------
111
112
113// ------------------------------------------------------------------------
114// simulation control functions
115// ------------------------------------------------------------------------
132void spin1_exit(uint error);
133
138
141static inline void spin1_set_timer_tick(uint time)
142{
144}
145
151void spin1_pause(void);
154void spin1_resume(sync_bool sync);
160void spin1_rte(rte_code code);
161
168static inline void spin1_delay_us(uint n) {
169 sark_delay_us(n);
170}
171
176
177// ------------------------------------------------------------------------
178
179
180// ------------------------------------------------------------------------
181// callback and task functions
182// ------------------------------------------------------------------------
194NONNULL void
195spin1_callback_on(uint event_id, callback_t cback, int priority);
196
200void spin1_callback_off(uint event_id);
201
209NONNULL uint
210spin1_schedule_callback(callback_t cback, uint arg0, uint arg1, uint priority);
211
217// ------------------------------------------------------------------------
218
219
220// ------------------------------------------------------------------------
221// data transfer functions
222// ------------------------------------------------------------------------
235NONNULL uint
236spin1_dma_transfer(uint tag, void *system_address, void *tcm_address,
237 uint direction, uint length);
238
246void spin1_dma_flush(void);
247
253NONNULL void
254spin1_memcpy(void *dst, void const *src, uint len);
255// ------------------------------------------------------------------------
256
257
258// ------------------------------------------------------------------------
259// communications functions
260// ------------------------------------------------------------------------
261
273uint spin1_send_packet(uint key, uint data, uint TCR);
274
290static inline uint spin1_send_mc_packet(uint key, uint data, uint load) {
291 uint tcr = (load) ? PKT_MC_PL : PKT_MC;
292
293 return spin1_send_packet(key, data, tcr);
294}
295
311static inline uint spin1_send_fr_packet(uint key, uint data, uint load) {
312 uint tcr = (load) ? PKT_FR_PL : PKT_FR;
313
314 return spin1_send_packet(key, data, tcr);
315}
316
317// ------------------------------------------------------------------------
318
319
320// ------------------------------------------------------------------------
321// SDP related functions
322// ------------------------------------------------------------------------
323
326static inline NONNULL void spin1_msg_free(sdp_msg_t *msg) {
327 sark_msg_free(msg);
328}
329
332static inline sdp_msg_t* spin1_msg_get(void) {
333 return sark_msg_get();
334}
335
341static inline NONNULL uint
343 return sark_msg_send(msg, timeout);
344}
345
346// ------------------------------------------------------------------------
347
348
349// ------------------------------------------------------------------------
350// interrupt control functions
351// ------------------------------------------------------------------------
352
353#ifndef SPIN1_INLINE
354#ifdef __GNUC__
355#define SPIN1_INLINE static __inline __attribute__((always_inline))
356#else
357#define SPIN1_INLINE static __forceinline
358#endif
359#endif
360
361SPIN1_INLINE void spin1_store_barrier(void)
362{
363#ifdef __GNUC__
364 // GCC only really has one kind of barrier, and this is how to do it
365 asm volatile("" : : : "cc", "memory");
366#else
367 __force_stores();
368#endif
369}
370
371SPIN1_INLINE void spin1_memory_barrier(void)
372{
373#ifdef __GNUC__
374 // GCC only really has one kind of barrier, and this is how to do it
375 asm volatile("" : : : "cc", "memory");
376#else
377 __memory_changed();
378#endif
379}
380
389#ifdef THUMB
390// Implemented in sark_alib.s; needs to be in ARM mode, not THUMB
392#else
393SPIN1_INLINE uint spin1_irq_disable(void)
394{
395 uint old_val, new_val;
396
397#ifdef __GNUC__
398 asm volatile (
399 "mrs %[old_val], cpsr \n\
400 orr %[new_val], %[old_val], #0x80 \n\
401 msr cpsr_c, %[new_val] \n"
402 : [old_val] "=r" (old_val), [new_val] "=r" (new_val)
403 :
404 : );
405#else
406 __asm { mrs old_val, cpsr }
407 __asm { orr new_val, old_val, 0x80 }
408 __asm { msr cpsr_c, new_val }
409#endif
410
411 spin1_memory_barrier();
412 return old_val;
413}
414#endif
415
424#ifdef THUMB
425// Implemented in sark_alib.s; needs to be in ARM mode, not THUMB
427#else
428SPIN1_INLINE uint spin1_fiq_disable(void)
429{
430 uint old_val, new_val;
431
432#ifdef __GNUC__
433 asm volatile (
434 "mrs %[old_val], cpsr \n\
435 orr %[new_val], %[old_val], #0x40 \n\
436 msr cpsr_c, %[new_val] \n"
437 : [old_val] "=r" (old_val), [new_val] "=r" (new_val)
438 :
439 : );
440#else
441 __asm { mrs old_val, cpsr }
442 __asm { orr new_val, old_val, 0x40 }
443 __asm { msr cpsr_c, new_val }
444#endif
445
446 spin1_memory_barrier();
447 return old_val;
448}
449#endif
450
459#ifdef THUMB
460// Implemented in sark_alib.s; needs to be in ARM mode, not THUMB
462#else
463SPIN1_INLINE uint spin1_int_disable(void)
464{
465 uint old_val, new_val;
466
467#ifdef __GNUC__
468 asm volatile (
469 "mrs %[old_val], cpsr \n\
470 orr %[new_val], %[old_val], #0xc0 \n\
471 msr cpsr_c, %[new_val] \n"
472 : [old_val] "=r" (old_val), [new_val] "=r" (new_val)
473 :
474 : );
475#else
476 __asm { mrs old_val, cpsr }
477 __asm { orr new_val, old_val, 0xc0 }
478 __asm { msr cpsr_c, new_val }
479#endif
480
481 spin1_memory_barrier();
482 return old_val;
483}
484#endif
485
493#ifdef THUMB
494// Implemented in sark_alib.s; needs to be in ARM mode, not THUMB
495extern void spin1_mode_restore(uint value);
496#else
497SPIN1_INLINE void spin1_mode_restore(uint value)
498{
499 spin1_store_barrier();
500
501#ifdef __GNUC__
502 asm volatile (
503 "msr cpsr_c, %[value]"
504 :
505 : [value] "r" (value)
506 :);
507#else
508 __asm { msr cpsr_c, value }
509#endif
510}
511#endif
512
513
514// ------------------------------------------------------------------------
515
516
517// ------------------------------------------------------------------------
518// system resources access functions
519// ------------------------------------------------------------------------
522uint spin1_get_id(void);
529
530#if 0
531//## This routine has been removed - use "rtr_alloc", "rtr_mc_set" instead
532uint spin1_set_mc_table_entry(uint entry, uint key, uint mask, uint route);
533#endif
534
545static inline SARK_IS_A_MALLOC(1) void*
547 return sark_alloc(bytes, 1);
548}
549
566static inline void spin1_led_control(uint p) {
567 sark_led_set(p);
568}
569// ------------------------------------------------------------------------
570
571
572// ----------------------------------
573// pseudo-random number generation
574// ----------------------------------
575
583static inline void spin1_srand(uint seed) {
584 sark_srand(seed);
585}
586
597static inline uint spin1_rand(void) {
598 return sark_rand();
599}
600
601
602// ------------------------------------------------------------------------
604// ------------------------------------------------------------------------
628
631extern uchar leadAp;
632// ------------------------------------------------------------------------
633
634
635#endif /* __SPIN1_API_H__ */
Spinnaker Application Runtime Kernel API.
void sark_delay_us(uint delay)
Perform a busy-wait for the given number of microseconds.
void sark_srand(uint seed)
Seed the random number generator with the supplied value.
void * sark_alloc(uint count, uint size)
Allocate a block of memory of count × size bytes from the DTCM heap. Returns either a pointer to the ...
Definition sark_alloc.c:137
enum sync_bool_e sync_bool
Typedef for enum sync_bool_e.
Definition sark.h:365
uint sark_rand(void)
Return the next 32-bit pseudo-random number in the sequence.
uint sark_msg_send(sdp_msg_t *msg, uint timeout)
Send an SDP message.
Definition sark_base.c:531
enum rte_code_e rte_code
Typedef for enum rte_code_e.
Definition sark.h:238
void sark_led_set(uint leds)
Controls one or more of the LEDs attached to the SpiNNaker chip.
Definition sark_hw.c:146
void sark_msg_free(sdp_msg_t *msg)
Return an SDP message buffer which was acquired by sark_msg_get() to the free buffer pool.
Definition sark_base.c:295
sdp_msg_t * sark_msg_get(void)
Get an SDP message buffer from the pool maintained by SARK.
Definition sark_base.c:270
SDP message definition.
Definition sark.h:574
volatile uchar load
The current system load.
Definition scamp-3.c:184
uint dumped_mc_packets
total dumped MC packets by the router
Definition spin1_api.h:609
@ FRPL_PACKET_RECEIVED
Fixed route packet with payload received.
Definition spin1_api.h:71
@ MCPL_PACKET_RECEIVED
Multicast packet with payload received.
Definition spin1_api.h:69
@ NUM_EVENTS
Count of possible events.
Definition spin1_api.h:63
@ MC_PACKET_RECEIVED
Multicast packet received.
Definition spin1_api.h:64
@ SDP_PACKET_RX
SDP message received.
Definition spin1_api.h:67
@ DMA_TRANSFER_DONE
DMA transfer complete.
Definition spin1_api.h:65
@ USER_EVENT
User-triggered interrupt.
Definition spin1_api.h:68
@ TIMER_TICK
Regular timer tick.
Definition spin1_api.h:66
@ FR_PACKET_RECEIVED
Fixed route packet received.
Definition spin1_api.h:70
uint spin1_send_packet(uint key, uint data, uint TCR)
Send a packet. Do not normally call directly; use spin1_send_mc_packet() and spin1_send_fr_packet() i...
Definition spin1_api.c:1158
void spin1_pause(void)
Pause the simulation on this core. Waits for spin1_resume().
Definition spin1_api.c:382
uint user_event_queue_full
user event queue full count
Definition spin1_api.h:616
void spin1_set_timer_tick_and_phase(uint time, uint phase)
Set the timer tick rate and phase offset.
Definition spin1_api.c:708
uint spin1_trigger_user_event(uint arg0, uint arg1)
This function triggers a USER EVENT, i.e., a software interrupt.
Definition spin1_api.c:1485
volatile uint discarded_mc_packets
total discarded MC packets by API
Definition spin1_api.h:610
uint spin1_dma_transfer(uint tag, void *system_address, void *tcm_address, uint direction, uint length)
Initiates a DMA transfer.
Definition spin1_api.c:962
static void spin1_msg_free(sdp_msg_t *msg)
Frees a received SDP message.
Definition spin1_api.h:326
static uint spin1_rand(void)
This function generates a pseudo-random 32-bit integer.
Definition spin1_api.h:597
uint spin1_get_id(void)
Returns a global (machine-wide) ID for the processor.
Definition spin1_api.c:1252
static void * spin1_malloc(uint bytes)
Returns a pointer to a newly-allocated block of memory of size "bytes" in DTCM.
Definition spin1_api.h:546
uint total_times_tick_tic_callback_overran
the total number of times the timer tic callback overran
Definition spin1_api.h:625
void spin1_flush_rx_packet_queue(void)
Discards all received packets which are yet to be processed.
Definition spin1_api.c:1122
diagnostics_t diagnostics
Miscellaneous diagnostic information, available to the application.
Definition spin1_api.c:133
uint warnings
warnings type bit map
Definition spin1_api.h:607
uint total_mc_packets
total routed MC packets during simulation
Definition spin1_api.h:608
uint dma_bursts
total DMA bursts completed
Definition spin1_api.h:612
void spin1_dma_flush(void)
Flushes any current transfers in the DMA controller.
Definition spin1_api.c:1018
uint dma_transfers
total DMA transfers requested
Definition spin1_api.h:611
void spin1_rte(rte_code code)
Soft-RTEs the core.
Definition spin1_api.c:820
uint spin1_fiq_disable(void)
Sets the F bit in the CPSR in order to disable FIQ interrupts in the processor.
uint tx_packet_queue_full
transmitter packet queue full count
Definition spin1_api.h:615
uint spin1_schedule_callback(callback_t cback, uint arg0, uint arg1, uint priority)
This function places a cback into the scheduling queue corresponding to its priority.
Definition spin1_api.c:1417
uint writeBack_errors
write-back buffer error count
Definition spin1_api.h:617
uint spin1_irq_disable(void)
Sets the I bit in the CPSR in order to disable IRQ interrupts to the processor.
uint number_timer_tic_in_queue
the number of timer tic callbacks in the queue
Definition spin1_api.h:622
void spin1_flush_tx_packet_queue(void)
Flushes the outbound packet queue.
Definition spin1_api.c:1147
void spin1_resume(sync_bool sync)
Resume the simulation on this core that was paused with spin1_pause().
Definition spin1_api.c:406
uint spin1_get_simulation_time(void)
Returns the number of timer periods which have elapsed since the beginning of the simulation.
Definition spin1_api.c:658
uint in_timer_callback
bool which states if currently in timer callback
Definition spin1_api.h:621
uchar leadAp
lead appl. core has special functions
Definition spin1_api.c:32
void spin1_memcpy(void *dst, void const *src, uint len)
Directly copies data from src to dst.
Definition spin1_api.c:1093
uint dumped_fr_packets
total dumped FR packets by the router
Definition spin1_api.h:619
uint spin1_int_disable(void)
Sets the F and I bits in the CPSR in order to disable FIQ and IRQ interrupts in the processor.
static sdp_msg_t * spin1_msg_get(void)
Gets an SDP message that has been sent to this core.
Definition spin1_api.h:332
uint total_fr_packets
total routed FR packets during simulation
Definition spin1_api.h:618
static uint spin1_send_fr_packet(uint key, uint data, uint load)
This function enqueues a request to send a fixed-route packet.
Definition spin1_api.h:311
static void spin1_delay_us(uint n)
This function implements a delay measured in microseconds.
Definition spin1_api.h:168
@ NO_PAYLOAD
No payload word present.
Definition spin1_api.h:100
@ WITH_PAYLOAD
Payload word present.
Definition spin1_api.h:101
void(* callback_t)(uint, uint)
User callback for event handling.
Definition spin1_api.h:109
uint largest_number_of_concurrent_timer_tic_overruns
the max number of timer tics callbacks being queued at any time
Definition spin1_api.h:623
static void spin1_set_timer_tick(uint time)
Set the timer tick rate. No phase offset.
Definition spin1_api.h:141
void spin1_callback_off(uint event_id)
Disables a callback for a class of event.
Definition spin1_api.c:594
static uint spin1_send_sdp_msg(sdp_msg_t *msg, uint timeout)
Sends an SDP message.
Definition spin1_api.h:342
void spin1_exit(uint error)
Terminates a simulation passing a return code.
Definition spin1_api.c:679
static void spin1_srand(uint seed)
This function is used to initialize the seed for the pseudo-random number generator.
Definition spin1_api.h:583
static const uint VIC_EVENTS[]
Match events above to their VIC interrupts. Indices must match!
Definition spin1_api.h:75
uint spin1_get_chip_id(void)
Returns the (machine-wide) chip ID.
Definition spin1_api.c:1292
void spin1_enable_timer_schedule_proc(void)
This function enables the use of timer_schedule_proc.
Definition spin1_api.c:1453
static uint spin1_send_mc_packet(uint key, uint data, uint load)
This function enqueues a request to send a multicast packet.
Definition spin1_api.h:290
uint spin1_get_core_id(void)
Returns the core ID.
Definition spin1_api.c:1272
uint exit_code
simulation exit code
Definition spin1_api.h:606
uint spin1_start(sync_bool sync)
Begins a simulation by enabling the timer (if called for) and beginning the dispatcher loop....
Definition spin1_api.c:921
@ DMA_READ
DMA read from SDRAM to TCM.
Definition spin1_api.h:91
@ DMA_WRITE
DMA write from TCM to SDRAM.
Definition spin1_api.h:92
uint discarded_fr_packets
total discarded FR packets by API
Definition spin1_api.h:620
uint task_queue_full
task queue full count
Definition spin1_api.h:614
void spin1_mode_restore(uint value)
Sets the CPSR to the value given in sr, in order to restore the CPSR following a call to spin1_irq_di...
uint spin1_start_paused(void)
Begins a simulation by enabling the timer (if called for) and beginning the dispatcher loop once the ...
Definition spin1_api.c:926
uint dma_queue_full
DMA queue full count.
Definition spin1_api.h:613
static void spin1_led_control(uint p)
This function controls LEDs according to an input pattern.
Definition spin1_api.h:566
void spin1_callback_on(uint event_id, callback_t cback, int priority)
Enables a callback for a class of event.
Definition spin1_api.c:546
diagnostic data available to the application
Definition spin1_api.h:605
@ PKT_FR_PL
Fixed-route with payload.
Definition spinnaker.h:1057
@ PKT_FR
Packet is fixed route packet.
Definition spinnaker.h:1050
@ PKT_MC_PL
Multicast with payload.
Definition spinnaker.h:1054
@ PKT_MC
Packet is multicast packet.
Definition spinnaker.h:1046
@ SOFTWARE_INT
Used only for local software interrupt generation.
Definition spinnaker.h:356
@ CC_FR_INT
Local comms controller fixed route packet received.
Definition spinnaker.h:382
@ DMA_DONE_INT
Local DMA controller transfer complete.
Definition spinnaker.h:367
@ CC_MC_INT
Local comms controller multicast packet received.
Definition spinnaker.h:379
@ TIMER1_INT
Local counter/timer interrupt 1.
Definition spinnaker.h:359
unsigned char uchar
Unsigned integer - 8 bits.
Definition spinnaker.h:37
unsigned int uint
Unsigned integer - 32 bits.
Definition spinnaker.h:39