From b4f6e1e553ad7ce32c6a13c54bd71c74f4ed7516 Mon Sep 17 00:00:00 2001 From: suiauthon Date: Mon, 15 Feb 2016 11:15:42 +0100 Subject: [PATCH 01/12] added support for FreeRTOS --- .../include/uavcan_stm32/build_config.hpp | 4 ++ .../driver/include/uavcan_stm32/thread.hpp | 42 ++++++++++++++- .../stm32/driver/src/internal.hpp | 30 ++++++++++- .../stm32/driver/src/uc_stm32_can.cpp | 26 +++++++--- .../stm32/driver/src/uc_stm32_clock.cpp | 20 ++++---- .../stm32/driver/src/uc_stm32_thread.cpp | 51 +++++++++++++++++++ 6 files changed, 154 insertions(+), 19 deletions(-) diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp index b3bf403594..0160cc662d 100644 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp +++ b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp @@ -19,6 +19,10 @@ # define UAVCAN_STM32_BAREMETAL 0 #endif +#ifndef UAVCAN_STM32_FREERTOS +# define UAVCAN_STM32_FREERTOS 0 +#endif + /** * Number of interfaces must be enabled explicitly */ diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp index ab7d25cc23..c1514d8782 100644 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp +++ b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp @@ -17,6 +17,12 @@ # include # include #elif UAVCAN_STM32_BAREMETAL +#elif UAVCAN_STM32_FREERTOS +# include +# include + #ifndef MAX_SEMAPHORE_COUNT + #define MAX_SEMAPHORE_COUNT 50 + #endif #else # error "Unknown OS" #endif @@ -136,7 +142,7 @@ public: (void)can_driver; } - bool wait(uavcan::MonotonicDuration) + bool wait(uavcan::MonotonicDuration duration) { (void)duration; bool lready = ready; @@ -161,6 +167,40 @@ public: void unlock() { } }; +#elif UAVCAN_STM32_FREERTOS + +class BusEvent +{ + SemaphoreHandle_t sem_; + BaseType_t xHigherPriorityTaskWoken; + +public: + BusEvent(CanDriver& can_driver) + { + (void)can_driver; + sem_ = xSemaphoreCreateCounting( MAX_SEMAPHORE_COUNT, 0 ); + } + + bool wait(uavcan::MonotonicDuration duration); + + void signal(); + + void signalFromInterrupt(); +}; + +class Mutex +{ + SemaphoreHandle_t mtx_; + BaseType_t xHigherPriorityTaskWoken; +public: + Mutex(void) + { + mtx_ = xSemaphoreCreateMutex(); + } + void lock(); + void unlock(); +}; + #endif diff --git a/libuavcan_drivers/stm32/driver/src/internal.hpp b/libuavcan_drivers/stm32/driver/src/internal.hpp index 2bdee57a66..79eab05b17 100644 --- a/libuavcan_drivers/stm32/driver/src/internal.hpp +++ b/libuavcan_drivers/stm32/driver/src/internal.hpp @@ -14,7 +14,10 @@ # include # include #elif UAVCAN_STM32_BAREMETAL -# include +# include +#elif UAVCAN_STM32_FREERTOS +# include +# include #else # error "Unknown OS" #endif @@ -71,6 +74,15 @@ # endif #endif +#if UAVCAN_STM32_FREERTOS +/** + * Priority mask for timer and CAN interrupts. + */ +# ifndef UAVCAN_STM32_IRQ_PRIORITY_MASK +# define UAVCAN_STM32_IRQ_PRIORITY_MASK configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY +# endif +#endif + /** * Glue macros */ @@ -122,6 +134,22 @@ struct CriticalSectionLocker } }; +#elif UAVCAN_STM32_FREERTOS + +struct CriticalSectionLocker +{ + //TODO napisati funkcije + CriticalSectionLocker() + { + taskENTER_CRITICAL(); + } + + ~CriticalSectionLocker() + { + taskEXIT_CRITICAL(); + } +}; + #endif namespace clock diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp index 40a5888725..5339748bc2 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp @@ -15,7 +15,10 @@ # include # include #elif UAVCAN_STM32_BAREMETAL -#include +#include +#elif UAVCAN_STM32_FREERTOS +#include +#include #else # error "Unknown OS" #endif @@ -200,11 +203,13 @@ int CanIface::computeTimings(const uavcan::uint32_t target_bitrate, Timings& out * Hardware configuration */ #if UAVCAN_STM32_BAREMETAL - const uavcan::uint32_t pclk = STM32_PCLK1_FREQUENCY; + const uavcan::uint32_t pclk = STM32_PCLK1; #elif UAVCAN_STM32_CHIBIOS const uavcan::uint32_t pclk = STM32_PCLK1; #elif UAVCAN_STM32_NUTTX const uavcan::uint32_t pclk = STM32_PCLK1_FREQUENCY; +#elif UAVCAN_STM32_FREERTOS + const uavcan::uint32_t pclk = HAL_RCC_GetPCLK1Freq(); #else # error "Unknown OS" #endif @@ -454,7 +459,7 @@ uavcan::int16_t CanIface::configureFilters(const uavcan::CanFilterConfig* filter bool CanIface::waitMsrINakBitStateChange(bool target_state) { -#if UAVCAN_STM32_NUTTX || UAVCAN_STM32_CHIBIOS +#if UAVCAN_STM32_NUTTX || UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_FREERTOS const unsigned Timeout = 1000; #else const unsigned Timeout = 2000000; @@ -471,6 +476,9 @@ bool CanIface::waitMsrINakBitStateChange(bool target_state) #endif #if UAVCAN_STM32_CHIBIOS ::chThdSleep(MS2ST(1)); +#endif +#if UAVCAN_STM32_FREERTOS + //::osDelay(1); #endif } return false; @@ -861,16 +869,18 @@ uavcan::int16_t CanDriver::select(uavcan::CanSelectMasks& inout_masks, } -#if UAVCAN_STM32_BAREMETAL +#if UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS -static void nvicEnableVector(int irq, uint8_t prio) +static void nvicEnableVector(IRQn_Type irq, uint8_t prio) { - NVIC_InitTypeDef NVIC_InitStructure; + /*NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = irq; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = prio; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); + NVIC_Init(&NVIC_InitStructure);*/ + HAL_NVIC_SetPriority(irq, prio, 0); + HAL_NVIC_EnableIRQ(irq); } #endif @@ -923,7 +933,7 @@ void CanDriver::initOnce() IRQ_ATTACH(STM32_IRQ_CAN2RX1, can2_irq); # endif # undef IRQ_ATTACH -#elif UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL +#elif UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS { CriticalSectionLocker lock; nvicEnableVector(CAN1_TX_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK); diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp index 1a04569acc..ccce1a3536 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp @@ -14,7 +14,7 @@ /* * Timer instance */ -# if (UAVCAN_STM32_CHIBIOS && CH_KERNEL_MAJOR == 2) || UAVCAN_STM32_BAREMETAL +# if (UAVCAN_STM32_CHIBIOS && CH_KERNEL_MAJOR == 2) || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS # define TIMX UAVCAN_STM32_GLUE2(TIM, UAVCAN_STM32_TIMER_NUMBER) # define TIMX_IRQn UAVCAN_STM32_GLUE3(TIM, UAVCAN_STM32_TIMER_NUMBER, _IRQn) # define TIMX_INPUT_CLOCK STM32_TIMCLK1 @@ -81,16 +81,18 @@ uavcan::uint64_t time_utc = 0; } -#if UAVCAN_STM32_BAREMETAL +#if UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS -static void nvicEnableVector(int irq, uint8_t prio) +static void nvicEnableVector(IRQn_Type irq, uint8_t prio) { - NVIC_InitTypeDef NVIC_InitStructure; + /*NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = irq; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = prio; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); + NVIC_Init(&NVIC_InitStructure);*/ + HAL_NVIC_SetPriority(irq, prio, 0); + HAL_NVIC_EnableIRQ(irq); } @@ -106,7 +108,7 @@ void init() initialized = true; -# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL +# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS // Power-on and reset TIMX_RCC_ENR |= TIMX_RCC_ENR_MASK; TIMX_RCC_RSTR |= TIMX_RCC_RSTR_MASK; @@ -178,7 +180,7 @@ void setUtc(uavcan::UtcTime time) static uavcan::uint64_t sampleUtcFromCriticalSection() { -# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL +# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS UAVCAN_ASSERT(initialized); UAVCAN_ASSERT(TIMX->DIER & TIM_DIER_UIE); @@ -228,7 +230,7 @@ uavcan::MonotonicTime getMonotonic() volatile uavcan::uint64_t time = time_mono; -# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL +# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS volatile uavcan::uint32_t cnt = TIMX->CNT; if (TIMX->SR & TIM_SR_UIF) @@ -435,7 +437,7 @@ UAVCAN_STM32_IRQ_HANDLER(TIMX_IRQHandler) { UAVCAN_STM32_IRQ_PROLOGUE(); -# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL +# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS TIMX->SR = 0; # endif # if UAVCAN_STM32_NUTTX diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp index 93b8c0a85c..24cdcb0268 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp @@ -7,6 +7,7 @@ #include #include "internal.hpp" + namespace uavcan_stm32 { @@ -79,6 +80,56 @@ void Mutex::unlock() # endif } + +#elif UAVCAN_STM32_FREERTOS + +bool BusEvent::wait(uavcan::MonotonicDuration duration) +{ + static const uavcan::int64_t MaxDelayMSec = 0x000FFFFF; + + const uavcan::int64_t msec = duration.toMSec(); + + BaseType_t ret; + + if (msec <= 0) + { + ret = xSemaphoreTake( sem_, ( TickType_t ) 0 ); + } + else + { + ret = xSemaphoreTake( sem_, (msec > MaxDelayMSec) ? (MaxDelayMSec/portTICK_RATE_MS) : (msec/portTICK_RATE_MS)); + } + return ret == pdTRUE; +} + +void BusEvent::signal() +{ + xSemaphoreGive( sem_ ); +} + +void BusEvent::signalFromInterrupt() +{ + xHigherPriorityTaskWoken = pdFALSE; + + xSemaphoreGiveFromISR( sem_, &xHigherPriorityTaskWoken ); + + portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); +} + +/* + * Mutex + */ +void Mutex::lock() +{ + xSemaphoreTake( mtx_, portMAX_DELAY ); +} + +void Mutex::unlock() +{ + xSemaphoreGive( mtx_ ); +} + + #elif UAVCAN_STM32_NUTTX const unsigned BusEvent::MaxPollWaiters; From ada61ef06b019357aaa3cb9a2a1bc06fe6c5acef Mon Sep 17 00:00:00 2001 From: suiauthon Date: Mon, 15 Feb 2016 11:21:10 +0100 Subject: [PATCH 02/12] added support for FreeRTOS --- libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp | 7 +++++-- libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp index 5339748bc2..3a8c29f165 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp @@ -873,14 +873,17 @@ uavcan::int16_t CanDriver::select(uavcan::CanSelectMasks& inout_masks, static void nvicEnableVector(IRQn_Type irq, uint8_t prio) { - /*NVIC_InitTypeDef NVIC_InitStructure; + #if !defined (USE_HAL_DRIVER) + NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = irq; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = prio; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure);*/ + NVIC_Init(&NVIC_InitStructure); + #else HAL_NVIC_SetPriority(irq, prio, 0); HAL_NVIC_EnableIRQ(irq); + #endif } #endif diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp index ccce1a3536..d67f1c7c1f 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp @@ -85,14 +85,17 @@ uavcan::uint64_t time_utc = 0; static void nvicEnableVector(IRQn_Type irq, uint8_t prio) { - /*NVIC_InitTypeDef NVIC_InitStructure; + #if !defined (USE_HAL_DRIVER) + NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = irq; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = prio; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure);*/ + NVIC_Init(&NVIC_InitStructure); + #else HAL_NVIC_SetPriority(irq, prio, 0); HAL_NVIC_EnableIRQ(irq); + #endif } From ee6ae3ec954e42d85a754c22b2ec3e166dda7965 Mon Sep 17 00:00:00 2001 From: suiauthon Date: Wed, 17 Feb 2016 09:46:36 +0100 Subject: [PATCH 03/12] added new method that yield from ISR after semaphore is given from ISR --- .../stm32/driver/include/uavcan_stm32/thread.hpp | 10 ++++++---- libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp index c1514d8782..9902e3e1f1 100644 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp +++ b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp @@ -20,9 +20,9 @@ #elif UAVCAN_STM32_FREERTOS # include # include - #ifndef MAX_SEMAPHORE_COUNT - #define MAX_SEMAPHORE_COUNT 50 - #endif +# ifndef MAX_SEMAPHORE_COUNT +# define MAX_SEMAPHORE_COUNT 50 +#endif #else # error "Unknown OS" #endif @@ -186,12 +186,14 @@ public: void signal(); void signalFromInterrupt(); + + void yieldFromISR(); }; class Mutex { SemaphoreHandle_t mtx_; - BaseType_t xHigherPriorityTaskWoken; + public: Mutex(void) { diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp index 24cdcb0268..9f246427af 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp @@ -116,6 +116,11 @@ void BusEvent::signalFromInterrupt() portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); } +void BusEvent::yieldFromISR() +{ + portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); +} + /* * Mutex */ From 6b307723537dd8872b34594b459978c065ec3d3b Mon Sep 17 00:00:00 2001 From: suiauthon Date: Wed, 17 Feb 2016 09:48:22 +0100 Subject: [PATCH 04/12] removed unnecessary comment --- libuavcan_drivers/stm32/driver/src/internal.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libuavcan_drivers/stm32/driver/src/internal.hpp b/libuavcan_drivers/stm32/driver/src/internal.hpp index 79eab05b17..f9d39a4181 100644 --- a/libuavcan_drivers/stm32/driver/src/internal.hpp +++ b/libuavcan_drivers/stm32/driver/src/internal.hpp @@ -138,7 +138,7 @@ struct CriticalSectionLocker struct CriticalSectionLocker { - //TODO napisati funkcije + CriticalSectionLocker() { taskENTER_CRITICAL(); From 8abfd18189b78c711ebd09fb11779e05bf4ba4fd Mon Sep 17 00:00:00 2001 From: suiauthon Date: Wed, 17 Feb 2016 09:51:50 +0100 Subject: [PATCH 05/12] uncommented osDelay --- libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp index 3a8c29f165..4beb8b980a 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp @@ -478,7 +478,7 @@ bool CanIface::waitMsrINakBitStateChange(bool target_state) ::chThdSleep(MS2ST(1)); #endif #if UAVCAN_STM32_FREERTOS - //::osDelay(1); + ::osDelay(1); #endif } return false; @@ -625,6 +625,10 @@ void CanIface::handleTxInterrupt(const uavcan::uint64_t utc_usec) update_event_.signalFromInterrupt(); pollErrorFlagsFromISR(); + + #if UAVCAN_STM32_FREERTOS + update_event_.yieldFromISR(); + #endif } void CanIface::handleRxInterrupt(uavcan::uint8_t fifo_index, uavcan::uint64_t utc_usec) @@ -688,6 +692,10 @@ void CanIface::handleRxInterrupt(uavcan::uint8_t fifo_index, uavcan::uint64_t ut update_event_.signalFromInterrupt(); pollErrorFlagsFromISR(); + + #if UAVCAN_STM32_FREERTOS + update_event_.yieldFromISR(); + #endif } void CanIface::pollErrorFlagsFromISR() From 13dbca3f0ea08044ae3059b39c7cb3146166e78e Mon Sep 17 00:00:00 2001 From: suiauthon Date: Tue, 29 Mar 2016 16:49:26 +0200 Subject: [PATCH 06/12] fixed yield from isr --- libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp | 2 +- libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp index 4beb8b980a..1fc697d09b 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp @@ -15,7 +15,7 @@ # include # include #elif UAVCAN_STM32_BAREMETAL -#include +#include #elif UAVCAN_STM32_FREERTOS #include #include diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp index 9f246427af..10befb184a 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp @@ -112,8 +112,6 @@ void BusEvent::signalFromInterrupt() xHigherPriorityTaskWoken = pdFALSE; xSemaphoreGiveFromISR( sem_, &xHigherPriorityTaskWoken ); - - portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); } void BusEvent::yieldFromISR() From b3818860de1842e62c496081dfbd37566f74fccb Mon Sep 17 00:00:00 2001 From: suiauthon Date: Fri, 1 Apr 2016 13:50:29 +0200 Subject: [PATCH 07/12] changes in includes for baremetal --- libuavcan_drivers/stm32/driver/src/internal.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libuavcan_drivers/stm32/driver/src/internal.hpp b/libuavcan_drivers/stm32/driver/src/internal.hpp index f9d39a4181..d39214f845 100644 --- a/libuavcan_drivers/stm32/driver/src/internal.hpp +++ b/libuavcan_drivers/stm32/driver/src/internal.hpp @@ -14,7 +14,7 @@ # include # include #elif UAVCAN_STM32_BAREMETAL -# include +# include #elif UAVCAN_STM32_FREERTOS # include # include From e006189ce587471a88ca9f3fe404ea6fa34ab086 Mon Sep 17 00:00:00 2001 From: suiauthon Date: Mon, 4 Apr 2016 10:06:59 +0200 Subject: [PATCH 08/12] changed counting semaphore to binary --- .../stm32/driver/include/uavcan_stm32/thread.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp index 9902e3e1f1..33ff54f575 100644 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp +++ b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp @@ -20,9 +20,6 @@ #elif UAVCAN_STM32_FREERTOS # include # include -# ifndef MAX_SEMAPHORE_COUNT -# define MAX_SEMAPHORE_COUNT 50 -#endif #else # error "Unknown OS" #endif @@ -178,7 +175,7 @@ public: BusEvent(CanDriver& can_driver) { (void)can_driver; - sem_ = xSemaphoreCreateCounting( MAX_SEMAPHORE_COUNT, 0 ); + sem_ = xSemaphoreCreateBinary(); } bool wait(uavcan::MonotonicDuration duration); From bd820fb86ab9b2c97038c3315be918b83baac0f6 Mon Sep 17 00:00:00 2001 From: suiauthon Date: Thu, 2 Jun 2016 15:42:10 +0200 Subject: [PATCH 09/12] added more generic include, fixed spacing --- libuavcan_drivers/stm32/driver/src/internal.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libuavcan_drivers/stm32/driver/src/internal.hpp b/libuavcan_drivers/stm32/driver/src/internal.hpp index d39214f845..80e3864b06 100644 --- a/libuavcan_drivers/stm32/driver/src/internal.hpp +++ b/libuavcan_drivers/stm32/driver/src/internal.hpp @@ -16,7 +16,7 @@ #elif UAVCAN_STM32_BAREMETAL # include #elif UAVCAN_STM32_FREERTOS -# include +# include # include #else # error "Unknown OS" @@ -141,12 +141,12 @@ struct CriticalSectionLocker CriticalSectionLocker() { - taskENTER_CRITICAL(); + taskENTER_CRITICAL(); } ~CriticalSectionLocker() { - taskEXIT_CRITICAL(); + taskEXIT_CRITICAL(); } }; From 0a757e191419f28c3df96e0870f2363c79b03122 Mon Sep 17 00:00:00 2001 From: suiauthon Date: Thu, 2 Jun 2016 15:42:51 +0200 Subject: [PATCH 10/12] removed unnecessary includes --- libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp index 1fc697d09b..c2d1b7d20e 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp @@ -17,8 +17,6 @@ #elif UAVCAN_STM32_BAREMETAL #include #elif UAVCAN_STM32_FREERTOS -#include -#include #else # error "Unknown OS" #endif From ea8e8cd89267b269a3c6b1cc13d8502ad99c7846 Mon Sep 17 00:00:00 2001 From: suiauthon Date: Thu, 2 Jun 2016 15:43:43 +0200 Subject: [PATCH 11/12] removed unnecessary include --- libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp index 33ff54f575..cc287c5211 100644 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp +++ b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp @@ -18,7 +18,6 @@ # include #elif UAVCAN_STM32_BAREMETAL #elif UAVCAN_STM32_FREERTOS -# include # include #else # error "Unknown OS" From 6b74f21fba96a9cc4bd4ae305029716f1f9aed38 Mon Sep 17 00:00:00 2001 From: suiauthon Date: Thu, 2 Jun 2016 17:31:37 +0200 Subject: [PATCH 12/12] fixed spacing and variable notation --- .../stm32/driver/include/uavcan_stm32/thread.hpp | 2 +- libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp | 2 +- libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp | 2 +- libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp index cc287c5211..ee18eea0ae 100644 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp +++ b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp @@ -168,7 +168,7 @@ public: class BusEvent { SemaphoreHandle_t sem_; - BaseType_t xHigherPriorityTaskWoken; + BaseType_t higher_priority_task_woken; public: BusEvent(CanDriver& can_driver) diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp index c2d1b7d20e..27a5c24967 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp @@ -879,7 +879,7 @@ uavcan::int16_t CanDriver::select(uavcan::CanSelectMasks& inout_masks, static void nvicEnableVector(IRQn_Type irq, uint8_t prio) { - #if !defined (USE_HAL_DRIVER) + #if !defined (USE_HAL_DRIVER) NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = irq; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = prio; diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp index d67f1c7c1f..42a51da079 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp @@ -85,7 +85,7 @@ uavcan::uint64_t time_utc = 0; static void nvicEnableVector(IRQn_Type irq, uint8_t prio) { - #if !defined (USE_HAL_DRIVER) + #if !defined (USE_HAL_DRIVER) NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = irq; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = prio; diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp index 10befb184a..9b9a0d2d79 100644 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp +++ b/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp @@ -109,14 +109,14 @@ void BusEvent::signal() void BusEvent::signalFromInterrupt() { - xHigherPriorityTaskWoken = pdFALSE; + higher_priority_task_woken = pdFALSE; - xSemaphoreGiveFromISR( sem_, &xHigherPriorityTaskWoken ); + xSemaphoreGiveFromISR( sem_, &higher_priority_task_woken ); } void BusEvent::yieldFromISR() { - portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); + portYIELD_FROM_ISR( higher_priority_task_woken ); } /*