From f083b807001156784b2bf59ee7e0fce54da33951 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 Jul 2018 13:12:21 +1000 Subject: [PATCH] HAL_ChibiOS: added preallocation of DMA bouncebuffers we need 512 bytes for microSD --- libraries/AP_HAL_ChibiOS/Device.cpp | 4 ++-- libraries/AP_HAL_ChibiOS/hwdef/common/bouncebuffer.c | 7 ++++++- libraries/AP_HAL_ChibiOS/hwdef/common/bouncebuffer.h | 2 +- libraries/AP_HAL_ChibiOS/sdcard.cpp | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/Device.cpp b/libraries/AP_HAL_ChibiOS/Device.cpp index 4c51a5efe9..f0b6779626 100644 --- a/libraries/AP_HAL_ChibiOS/Device.cpp +++ b/libraries/AP_HAL_ChibiOS/Device.cpp @@ -31,8 +31,8 @@ static const AP_HAL::HAL &hal = AP_HAL::get_HAL(); DeviceBus::DeviceBus(uint8_t _thread_priority) : thread_priority(_thread_priority) { - bouncebuffer_init(&bounce_buffer_tx); - bouncebuffer_init(&bounce_buffer_rx); + bouncebuffer_init(&bounce_buffer_tx, 10); + bouncebuffer_init(&bounce_buffer_rx, 10); } /* diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/bouncebuffer.c b/libraries/AP_HAL_ChibiOS/hwdef/common/bouncebuffer.c index 4ef1483361..bd7577fd2f 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/bouncebuffer.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/bouncebuffer.c @@ -32,10 +32,15 @@ /* initialise a bouncebuffer */ -void bouncebuffer_init(struct bouncebuffer_t **bouncebuffer) +void bouncebuffer_init(struct bouncebuffer_t **bouncebuffer, uint32_t prealloc_bytes) { (*bouncebuffer) = calloc(1, sizeof(struct bouncebuffer_t)); osalDbgAssert(((*bouncebuffer) != NULL), "bouncebuffer init"); + if (prealloc_bytes) { + (*bouncebuffer)->dma_buf = malloc_dma(prealloc_bytes); + osalDbgAssert(((*bouncebuffer)->dma_buf != NULL), "bouncebuffer preallocate"); + (*bouncebuffer)->size = prealloc_bytes; + } } /* diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/bouncebuffer.h b/libraries/AP_HAL_ChibiOS/hwdef/common/bouncebuffer.h index a3704884a6..da78234c7e 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/bouncebuffer.h +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/bouncebuffer.h @@ -21,7 +21,7 @@ struct bouncebuffer_t { /* initialise a bouncebuffer */ -void bouncebuffer_init(struct bouncebuffer_t **bouncebuffer); +void bouncebuffer_init(struct bouncebuffer_t **bouncebuffer, uint32_t prealloc_bytes); /* setup for reading from a device into memory, allocating a bouncebuffer if needed diff --git a/libraries/AP_HAL_ChibiOS/sdcard.cpp b/libraries/AP_HAL_ChibiOS/sdcard.cpp index 5721767c48..3c1e26f117 100644 --- a/libraries/AP_HAL_ChibiOS/sdcard.cpp +++ b/libraries/AP_HAL_ChibiOS/sdcard.cpp @@ -46,7 +46,7 @@ void sdcard_init() sdcard_init_done = true; #if HAL_USE_SDC - bouncebuffer_init(&SDCD1.bouncebuffer); + bouncebuffer_init(&SDCD1.bouncebuffer, 512); sdcStart(&SDCD1, NULL);