From a86e85c6b27c6c73e518e5d7463b2362a0f1de9c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 14 Mar 2018 19:50:32 +1100 Subject: [PATCH] HAL_ChibiOS: enable checking for DMA contention --- libraries/AP_HAL_ChibiOS/shared_dma.cpp | 12 ++++++++++++ libraries/AP_HAL_ChibiOS/shared_dma.h | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/libraries/AP_HAL_ChibiOS/shared_dma.cpp b/libraries/AP_HAL_ChibiOS/shared_dma.cpp index 9ef0f68447..025345c20c 100644 --- a/libraries/AP_HAL_ChibiOS/shared_dma.cpp +++ b/libraries/AP_HAL_ChibiOS/shared_dma.cpp @@ -105,6 +105,12 @@ bool Shared_DMA::lock_nonblock(void) { if (stream_id1 != SHARED_DMA_NONE) { if (chBSemWaitTimeout(&locks[stream_id1].semaphore, 1) != MSG_OK) { + chSysDisable(); + if (locks[stream_id1].obj != nullptr && locks[stream_id1].obj != this) { + locks[stream_id1].obj->contention = true; + } + chSysEnable(); + contention = true; return false; } } @@ -113,6 +119,12 @@ bool Shared_DMA::lock_nonblock(void) if (stream_id1 != SHARED_DMA_NONE) { chBSemSignal(&locks[stream_id1].semaphore); } + chSysDisable(); + if (locks[stream_id2].obj != nullptr && locks[stream_id2].obj != this) { + locks[stream_id2].obj->contention = true; + } + chSysEnable(); + contention = true; return false; } } diff --git a/libraries/AP_HAL_ChibiOS/shared_dma.h b/libraries/AP_HAL_ChibiOS/shared_dma.h index 2d5d957cfd..697042650b 100644 --- a/libraries/AP_HAL_ChibiOS/shared_dma.h +++ b/libraries/AP_HAL_ChibiOS/shared_dma.h @@ -58,6 +58,10 @@ public: //should be called inside the destructor of Shared DMA participants void unregister(void); + // return true if this DMA channel is being actively contended for + // by multiple drivers + bool has_contention(void) const { return contention; } + // lock all shared DMA channels. Used on reboot static void lock_all(void); @@ -68,6 +72,10 @@ private: uint8_t stream_id2; bool have_lock; + // we set the contention flag if two drivers are fighting over a DMA channel. + // the UART driver uses this to change its max transmit size to reduce latency + bool contention; + // core of lock call, after semaphores gained void lock_core(void);