mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-28 19:32:36 +08:00
This commit is contained in:
committed by
Lorenz Meier
parent
7398164fcc
commit
ef343dc452
@@ -550,25 +550,33 @@ int UavcanNode::start(uavcan::NodeID node_id, uint32_t bitrate)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* CAN driver init
|
* CAN driver init
|
||||||
|
* Note that we instantiate and initialize CanInitHelper only once, because the STM32's bxCAN driver
|
||||||
|
* shipped with libuavcan does not support deinitialization.
|
||||||
*/
|
*/
|
||||||
static CanInitHelper can;
|
static CanInitHelper* can = nullptr;
|
||||||
static bool can_initialized = false;
|
|
||||||
|
|
||||||
if (!can_initialized) {
|
if (can == nullptr) {
|
||||||
const int can_init_res = can.init(bitrate);
|
warnx("CAN driver init...");
|
||||||
|
|
||||||
|
can = new CanInitHelper();
|
||||||
|
|
||||||
|
if (can == nullptr) { // We don't have exceptions so bad_alloc cannot be thrown
|
||||||
|
warnx("Out of memory");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int can_init_res = can->init(bitrate);
|
||||||
|
|
||||||
if (can_init_res < 0) {
|
if (can_init_res < 0) {
|
||||||
warnx("CAN driver init failed %i", can_init_res);
|
warnx("CAN driver init failed %i", can_init_res);
|
||||||
return can_init_res;
|
return can_init_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
can_initialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Node init
|
* Node init
|
||||||
*/
|
*/
|
||||||
_instance = new UavcanNode(can.driver, uavcan_stm32::SystemClock::instance());
|
_instance = new UavcanNode(can->driver, uavcan_stm32::SystemClock::instance());
|
||||||
|
|
||||||
if (_instance == nullptr) {
|
if (_instance == nullptr) {
|
||||||
warnx("Out of memory");
|
warnx("Out of memory");
|
||||||
|
|||||||
Reference in New Issue
Block a user