SpiNNFrontEndCommon 7.3.1
Common support code for user-facing front end systems.
Loading...
Searching...
No Matches
rt_single.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
17#include <stdbool.h>
18#include <spin1_api.h>
19#include <spin1_api_params.h>
20#include <debug.h>
21#include <malloc_extras.h>
22#include "../common/routing_table.h"
23
24#ifndef __RT_SINGLE_H__
25#define __RT_SINGLE_H__
26
40/* entry_t is defined as:
41 *
42 * typedef struct
43 * {
44 * uint32_t keymask;
45 * uint32_t mask;
46 * uint32_t route; // Routing direction
47 * uint32_t source; // Source of packets arriving at this entry
48 * } entry_t;
49 *
50 * The `source` field is used to determine if the entry could be replaced by
51 * default routing, it can be left blank if removing default entries is not to
52 * be used. Otherwise indicate which links will be used by packets expected to
53 * match the specified entry.
54 *
55 * NOTE: The routing table provided to this application MUST include all of the
56 * entries which are expected to arrive at this router (i.e., entries which
57 * could be replaced by default routing MUST be included in the table provided
58 * to this application).
59 *
60 * NOTE: The block of memory containing the header and initial routing table
61 * will be freed on exit by this application.
62 */
63
65#define RTR_MC_SET_FAILED 0
66
71
73static const uint32_t DMA_READ_FLAGS =
74 DMA_WIDTH << 24 | DMA_BURST_SIZE << 21 | DMA_READ << 19;
75
77#define DMA_COMPLETE 0x400
78
80#define DMA_CHECK_MASK 0x401
81
85typedef struct {
89 uint32_t app_id;
90
94
96 uint32_t table_size;
97
99 entry_t entries[];
100} header_t;
101
103 return table->size;
104}
105
106void routing_table_remove_from_size(int size_to_remove) {
107 table->size -= size_to_remove;
108}
109
110entry_t* routing_table_get_entry(uint32_t entry_id_to_find) {
111 return &table->entries[entry_id_to_find];
112}
113
116void print_header(header_t *header) {
117 log_debug("app_id = %d", header->app_id);
118 log_debug("compress_as_much_as_possible = %d",
120 log_debug("table_size = %d", header->table_size);
121}
122
125static void read_table(header_t *header) {
126 table = MALLOC(
127 sizeof(uint32_t) + (sizeof(entry_t) * header->table_size));
128 if (table == NULL) {
129 log_error("failed to allocate memory for routing tables");
131 }
132 // Copy the size of the table
133 table->size = header->table_size;
134
135 // Copy in the routing table entries
137 sizeof(entry_t) * table->size);
138}
139
144bool load_routing_table(uint32_t app_id) {
145 // Try to allocate sufficient room for the routing table.
146 uint32_t entry_id = rtr_alloc_id(table->size, app_id);
147 if (entry_id == 0) {
148 log_error("Unable to allocate routing table of size %u\n", table->size);
149 return FALSE;
150 }
151
152 // Load entries into the table (provided the allocation succeeded).
153 // Note that although the allocation included the specified
154 // application ID we also need to include it as the most significant
155 // byte in the route (see `sark_hw.c`).
156 for (uint32_t i = 0; i < table->size; i++) {
157 entry_t entry = table->entries[i];
158 uint32_t route = entry.route | (app_id << 24);
159 uint success = rtr_mc_set(
160 entry_id + i, entry.key_mask.key, entry.key_mask.mask, route);
161 if (success == RTR_MC_SET_FAILED) {
162 log_warning("failed to set a router table entry at index %d",
163 entry_id + i);
164 }
165 }
166
167 // Indicate we were able to allocate routing table entries.
168 return TRUE;
169}
170
176bool routing_table_get_entries(uint32_t start_entry, uint32_t n_entries,
177 entry_t *output) {
178 uint32_t length = n_entries * sizeof(entry_t);
179 uint32_t desc = DMA_READ_FLAGS | length;
180 dma[DMA_ADRS] = (uint32_t) &table->entries[start_entry];
181 dma[DMA_ADRT] = (uint32_t) output;
182 dma[DMA_DESC] = desc;
183 return false;
184}
185
186
189static inline bool dma_done(void) {
190 return (dma[DMA_STAT] & DMA_CHECK_MASK) == DMA_COMPLETE;
191}
192
196 while (!dma_done()) {
197 continue;
198 }
199 dma[DMA_CTRL] = 0x8;
200}
201
202#endif //__RT_SINGLE_H__
SpiNNaker debug header file.
void log_error(const char *message,...)
This function logs errors. Errors usually indicate a serious fault in the program,...
void log_warning(const char *message,...)
This function logs warnings.
void log_debug(const char *message,...)
This function logs debugging messages. This level of message is normally not printed except when the ...
#define DMA_BURST_SIZE
Use DMA bursts of 16 (24) transfer units (double words)
Support for adding debugging information to dynamic allocation.
#define MALLOC
An easily-insertable name for the memory allocator.
@ EXIT_FAIL
We went wrong but we dont want to RTE.
void malloc_extras_terminate(uint result_code)
Stops execution with a result code.
key_mask_t key_mask
Key and mask.
uint32_t mask
Mask for the key_mask.
entry_t entries[]
Entries in the table.
uint32_t size
Number of entries in the table.
uint32_t route
Routing direction.
uint32_t key
Key for the key_mask.
Holds data for a routing table entry.
Holds a routing table description.
uint32_t app_id
Definition rt_single.h:89
uint32_t table_size
Initial size of the routing table.
Definition rt_single.h:96
static bool dma_done(void)
Is there a DMA currently running?
Definition rt_single.h:189
static void read_table(header_t *header)
Read a new copy of the routing table from SDRAM.
Definition rt_single.h:125
#define DMA_COMPLETE
Value of the masked DMA status register when transfer is complete.
Definition rt_single.h:77
static const uint32_t DMA_READ_FLAGS
DMA read flags.
Definition rt_single.h:73
void print_header(header_t *header)
Print the header object for debug purposes.
Definition rt_single.h:116
entry_t entries[]
Routing table entries.
Definition rt_single.h:99
bool routing_table_get_entries(uint32_t start_entry, uint32_t n_entries, entry_t *output)
Gets a pointer to several entries.
Definition rt_single.h:176
#define RTR_MC_SET_FAILED
flag for if a rtr_mc_set() failure.
Definition rt_single.h:65
table_t * table
The table being manipulated.
Definition rt_single.h:70
#define DMA_CHECK_MASK
Mask to apply to the DMA status register to check for completion.
Definition rt_single.h:80
uint32_t compress_as_much_as_possible
Definition rt_single.h:93
int routing_table_get_n_entries(void)
Get the number of entries in the routing table.
Definition rt_single.h:102
bool load_routing_table(uint32_t app_id)
Load a routing table to the router.
Definition rt_single.h:144
entry_t * routing_table_get_entry(uint32_t entry_id_to_find)
Gets a pointer to where this entry is stored.
Definition rt_single.h:110
void routing_table_wait_for_last_transfer(void)
Waits for the last transfer from routing_table_get_entries to complete.
Definition rt_single.h:195
void routing_table_remove_from_size(int size_to_remove)
updates table stores accordingly.
Definition rt_single.h:106
The header of the routing table information in the input data block.
Definition rt_single.h:85
uint rtr_alloc_id(uint size, uint app_id)
uint rtr_mc_set(uint entry, uint key, uint mask, uint route)
#define NULL
void spin1_memcpy(void *dst, void const *src, uint len)
#define TRUE
#define FALSE
DMA_READ
#define DMA_WIDTH
#define DMA_DESC
#define DMA_ADRT
#define DMA_CTRL
unsigned int uint
#define DMA_STAT
#define DMA_ADRS