sPyNNaker neural_modelling 7.1.1
Loading...
Searching...
No Matches
dma_common.h
1/*
2 * Copyright (c) 2020 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#ifndef _DMA_COMMON_H_
17#define _DMA_COMMON_H_
18#include <spin1_api.h>
19#include <spin1_api_params.h>
20#include <stdbool.h>
21
23#define DMA_COMPLETE 0x400
24
26#define DMA_CHECK_MASK 0x401
27
29static const uint32_t DMA_WRITE_FLAGS =
30 DMA_WIDTH << 24 | DMA_BURST_SIZE << 21 | DMA_WRITE << 19;
31
33static const uint32_t DMA_READ_FLAGS =
34 DMA_WIDTH << 24 | DMA_BURST_SIZE << 21 | DMA_READ << 19;
35
38static inline bool dma_done(void) {
39 return (dma[DMA_STAT] & DMA_CHECK_MASK) == DMA_COMPLETE;
40}
41
47static inline void do_fast_dma_write(void *tcm_address, void *system_address,
48 uint32_t n_bytes) {
49#if LOG_LEVEL >= LOG_DEBUG
50 // Useful for checking when things are going wrong, but shouldn't be
51 // needed in normal code
52 uint32_t stat = dma[DMA_STAT];
53 if (stat & 0x1FFFFF) {
54 log_error("DMA pending or in progress on write: 0x%08x", stat);
55 rt_error(RTE_SWERR);
56 }
57#endif
58 uint32_t desc = DMA_WRITE_FLAGS | n_bytes;
59 dma[DMA_ADRS] = (uint32_t) system_address;
60 dma[DMA_ADRT] = (uint32_t) tcm_address;
61 dma[DMA_DESC] = desc;
62}
63
69static inline void do_fast_dma_read(void *system_address, void *tcm_address,
70 uint32_t n_bytes) {
71#if LOG_LEVEL >= LOG_DEBUG
72 // Useful for checking when things are going wrong, but shouldn't be
73 // needed in normal code
74 uint32_t stat = dma[DMA_STAT];
75 if (stat & 0x1FFFFF) {
76 log_error("DMA pending or in progress on read: 0x%08x", stat);
77 rt_error(RTE_SWERR);
78 }
79#endif
80 uint32_t desc = DMA_READ_FLAGS | n_bytes;
81 dma[DMA_ADRS] = (uint32_t) system_address;
82 dma[DMA_ADRT] = (uint32_t) tcm_address;
83 dma[DMA_DESC] = desc;
84}
85
87static inline void wait_for_dma_to_complete(void) {
88#if LOG_LEVEL >= LOG_DEBUG
89 // Useful for checking when things are going wrong, but shouldn't be
90 // needed in normal code
91 uint32_t n_loops = 0;
92 while (!dma_done() && n_loops < 10000) {
93 n_loops++;
94 }
95 if (!dma_done()) {
96 log_error("Timeout on DMA loop: DMA stat = 0x%08x!", dma[DMA_STAT]);
97 rt_error(RTE_SWERR);
98 }
99#else
100 // This is the normal loop, done without checking
101 while (!dma_done()) {
102 continue;
103 }
104#endif
105 dma[DMA_CTRL] = 0x8;
106}
107
108
110static inline void cancel_dmas(void) {
111 dma[DMA_CTRL] = 0x3F;
112 while (dma[DMA_STAT] & 0x1) {
113 continue;
114 }
115 dma[DMA_CTRL] = 0xD;
116 while (dma[DMA_CTRL] & 0xD) {
117 continue;
118 }
119}
120
121#endif
void log_error(const char *message,...)
void rt_error(uint code,...)
DMA_READ
DMA_WRITE
#define DMA_BURST_SIZE
#define DMA_WIDTH
#define DMA_DESC
#define DMA_ADRT
#define DMA_CTRL
#define DMA_STAT
#define DMA_ADRS