10000 stmhal: On SysTick IRQ, only process one DMA channel at a time. · micropython/micropython@22bd231 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22bd231

Browse files
committed
stmhal: On SysTick IRQ, only process one DMA channel at a time.
This can be generalised if/when more processing is needed by SysTick. Thanks to @chuckbook for the idea.
1 parent 9936aa3 commit 22bd231

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

stmhal/dma.c

Lines changed: 6 additions & 4 deletions
227
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,16 @@ void dma_invalidate_channel(DMA_Stream_TypeDef *dma_stream, uint32_t dma_channel
220220
}
221221
}
222222

223-
// Called from the SysTick handler (once per millisecond)
224-
void dma_idle_handler() {
223+
// Called from the SysTick handler
224+
// We use LSB of tick to select which controller to process
225+
void dma_idle_handler(int tick) {
225226
static const uint32_t controller_mask[] = {
226227
DMA1_ENABLE_MASK, DMA2_ENABLE_MASK
228
};
228-
for (int controller = 0; controller < NCONTROLLERS; controller++) {
229+
{
230+
int controller = tick & 1;
229231
if (dma_idle.counter[controller] == 0) {
230-
continue;
232+
return;
231233
}
232234
if (++dma_idle.counter[controller] > DMA_IDLE_TICK_MAX) {
233235
if ((dma_enable_mask & controller_mask[controller]) == 0) {

stmhal/dma.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ typedef union {
3838
extern volatile dma_idle_count_t dma_idle;
3939
#define DMA_IDLE_ENABLED() (dma_idle.enabled != 0)
4040

41-
#define DMA_SYSTICK_MASK 0x0F
41+
#define DMA_SYSTICK_MASK 0x0e
4242
#define DMA_MSECS_PER_SYSTICK (DMA_SYSTICK_MASK + 1)
4343
#define DMA_IDLE_TICK_MAX (8) // 128 msec
4444
#define DMA_IDLE_TICK(tick) (((tick) & DMA_SYSTICK_MASK) == 0)
@@ -48,4 +48,4 @@ extern const DMA_InitTypeDef dma_init_struct_spi_i2c;
4848
void dma_init(DMA_HandleTypeDef *dma, DMA_Stream_TypeDef *dma_stream, const DMA_InitTypeDef *dma_init, uint32_t dma_channel, uint32_t direction, void *data);
4949
void dma_deinit(DMA_HandleTypeDef *dma);
5050
void dma_invalidate_channel(DMA_Stream_TypeDef *dma_stream, uint32_t dma_channel);
51-
void dma_idle_handler();
51+
void dma_idle_handler(int controller);

stmhal/stm32_it.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,12 @@ void SysTick_Handler(void) {
269269
// work properly.
270270
SysTick->CTRL;
271271

272+
// Right now we just have the DMA controllers to process during this
273+
// interrupt and we use a custom dispatch handler. If this needs to
274+
// be generalised in the future then a dispatch table can be used as
275+
// follows: ((void(*)(void))(systick_dispatch[uwTick & 0xf]))();
272276
if (DMA_IDLE_ENABLED() && DMA_IDLE_TICK(uwTick)) {
273-
dma_idle_handler();
277+
dma_idle_handler(uwTick);
274278
}
275279
}
276280

0 commit comments

Comments
 (0)
0