From 75f745ba745e717017ea08497a2b63a54ecfc813 Mon Sep 17 00:00:00 2001 From: "Paul A. Patience" Date: Thu, 12 Nov 2015 12:47:23 -0500 Subject: [PATCH] canutils/uavcan: Make global static can a local static in getCanDriver() --- canutils/uavcan/platform_stm32.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/canutils/uavcan/platform_stm32.cpp b/canutils/uavcan/platform_stm32.cpp index 596b3eb69..026bbafc2 100644 --- a/canutils/uavcan/platform_stm32.cpp +++ b/canutils/uavcan/platform_stm32.cpp @@ -44,30 +44,31 @@ #include /**************************************************************************** - * Private Data + * Configuration ****************************************************************************/ -#if CONFIG_UAVCAN_RX_QUEUE_CAPACITY > 0 -static uavcan_stm32::CanInitHelper can; -#else -static uavcan_stm32::CanInitHelper<> can; +#if CONFIG_UAVCAN_RX_QUEUE_CAPACITY == 0 +# undef CONFIG_UAVCAN_RX_QUEUE_CAPACITY +# define CONFIG_UAVCAN_RX_QUEUE_CAPACITY #endif /**************************************************************************** * Private Functions ****************************************************************************/ -static void delay_callable() +static void delay(void) { - std::usleep(can.getRecommendedListeningDelay().toUSec()); + std::usleep(uavcan_stm32::CanInitHelper:: + getRecommendedListeningDelay().toUSec()); } /**************************************************************************** * Public Functions ****************************************************************************/ -uavcan::ICanDriver& getCanDriver() +uavcan::ICanDriver &getCanDriver(void) { + static uavcan_stm32::CanInitHelper can; static bool initialized = false; if (!initialized) @@ -78,7 +79,7 @@ uavcan::ICanDriver& getCanDriver() int retries = 0; #endif - while (can.init(delay_callable, bitrate) < 0) + while (can.init(delay, bitrate) < 0) { #if CONFIG_UAVCAN_INIT_RETRIES > 0 retries++; @@ -95,7 +96,7 @@ uavcan::ICanDriver& getCanDriver() return can.driver; } -uavcan::ISystemClock& getSystemClock() +uavcan::ISystemClock &getSystemClock(void) { return uavcan_stm32::SystemClock::instance(); }