Merged in paulpatience/nuttx-apps/uavcan (pull request #24)

Uavcan
This commit is contained in:
Gregory Nutt 2015-11-12 12:33:37 -06:00
commit 1dd862e574
2 changed files with 19 additions and 15 deletions

View File

@ -44,30 +44,31 @@
#include <uavcan_stm32/uavcan_stm32.hpp> #include <uavcan_stm32/uavcan_stm32.hpp>
/**************************************************************************** /****************************************************************************
* Private Data * Configuration
****************************************************************************/ ****************************************************************************/
#if CONFIG_UAVCAN_RX_QUEUE_CAPACITY > 0 #if CONFIG_UAVCAN_RX_QUEUE_CAPACITY == 0
static uavcan_stm32::CanInitHelper<CONFIG_UAVCAN_RX_QUEUE_CAPACITY> can; # undef CONFIG_UAVCAN_RX_QUEUE_CAPACITY
#else # define CONFIG_UAVCAN_RX_QUEUE_CAPACITY
static uavcan_stm32::CanInitHelper<> can;
#endif #endif
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
static void delay_callable() static void delay(void)
{ {
std::usleep(can.getRecommendedListeningDelay().toUSec()); std::usleep(uavcan_stm32::CanInitHelper<CONFIG_UAVCAN_RX_QUEUE_CAPACITY>::
getRecommendedListeningDelay().toUSec());
} }
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
uavcan::ICanDriver& getCanDriver() uavcan::ICanDriver &getCanDriver(void)
{ {
static uavcan_stm32::CanInitHelper<CONFIG_UAVCAN_RX_QUEUE_CAPACITY> can;
static bool initialized = false; static bool initialized = false;
if (!initialized) if (!initialized)
@ -78,7 +79,7 @@ uavcan::ICanDriver& getCanDriver()
int retries = 0; int retries = 0;
#endif #endif
while (can.init(delay_callable, bitrate) < 0) while (can.init(delay, bitrate) < 0)
{ {
#if CONFIG_UAVCAN_INIT_RETRIES > 0 #if CONFIG_UAVCAN_INIT_RETRIES > 0
retries++; retries++;
@ -95,7 +96,7 @@ uavcan::ICanDriver& getCanDriver()
return can.driver; return can.driver;
} }
uavcan::ISystemClock& getSystemClock() uavcan::ISystemClock &getSystemClock(void)
{ {
return uavcan_stm32::SystemClock::instance(); return uavcan_stm32::SystemClock::instance();
} }

View File

@ -42,14 +42,16 @@
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <nuttx/arch.h>
#include <uavcan/uavcan.hpp> #include <uavcan/uavcan.hpp>
/**************************************************************************** /****************************************************************************
* Public Function Prototypes * Public Function Prototypes
****************************************************************************/ ****************************************************************************/
uavcan::ICanDriver& getCanDriver(); extern uavcan::ICanDriver &getCanDriver(void);
uavcan::ISystemClock& getSystemClock(); extern uavcan::ISystemClock &getSystemClock(void);
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
@ -65,14 +67,15 @@ int main(int argc, FAR char *argv[])
extern "C" int uavcan_main(int argc, FAR char *argv[]) extern "C" int uavcan_main(int argc, FAR char *argv[])
#endif #endif
{ {
uavcan::Node<CONFIG_EXAMPLES_UAVCAN_NODE_MEM_POOL_SIZE> up_cxxinitialize();
static uavcan::Node<CONFIG_EXAMPLES_UAVCAN_NODE_MEM_POOL_SIZE>
node(getCanDriver(), getSystemClock()); node(getCanDriver(), getSystemClock());
int ret;
node.setNodeID(CONFIG_EXAMPLES_UAVCAN_NODE_ID); node.setNodeID(CONFIG_EXAMPLES_UAVCAN_NODE_ID);
node.setName(CONFIG_EXAMPLES_UAVCAN_NODE_NAME); node.setName(CONFIG_EXAMPLES_UAVCAN_NODE_NAME);
ret = node.start(); int ret = node.start();
if (ret < 0) if (ret < 0)
{ {
std::fprintf(stderr, "ERROR: node.start failed: %d\n", ret); std::fprintf(stderr, "ERROR: node.start failed: %d\n", ret);