uavcan_1:Fixed hardfault on stop

This commit is contained in:
David Sidrane
2021-08-03 08:56:01 -07:00
committed by Daniel Agar
parent 6aa4e12b5f
commit 8f64f7ce90
2 changed files with 16 additions and 9 deletions
+15 -8
View File
@@ -98,13 +98,14 @@ UavcanNode::~UavcanNode()
_task_should_exit.store(true); _task_should_exit.store(true);
ScheduleNow(); ScheduleNow();
unsigned i = 10; unsigned i = 1000;
do { do {
/* wait 5ms - it should wake every 10ms or so worst-case */ /* Wait for it to exit or timeout */
usleep(5000); usleep(5000);
if (--i == 0) { if (--i == 0) {
PX4_ERR("Failed to Stop Task - reboot needed");
break; break;
} }
@@ -112,11 +113,13 @@ UavcanNode::~UavcanNode()
} }
delete _can_interface; delete _can_interface;
_can_interface = nullptr;
perf_free(_cycle_perf); perf_free(_cycle_perf);
perf_free(_interval_perf); perf_free(_interval_perf);
//delete _uavcan_heap; delete static_cast<uint8_t *>(_uavcan_heap);
_uavcan_heap = nullptr;
} }
int UavcanNode::start(uint32_t node_id, uint32_t bitrate) int UavcanNode::start(uint32_t node_id, uint32_t bitrate)
@@ -163,7 +166,7 @@ void UavcanNode::Run()
{ {
pthread_mutex_lock(&_node_mutex); pthread_mutex_lock(&_node_mutex);
if (!_initialized) { if (_instance != nullptr && !_initialized) {
init(); init();
// return early if still not initialized // return early if still not initialized
@@ -216,7 +219,7 @@ void UavcanNode::Run()
CanardFrame received_frame{}; CanardFrame received_frame{};
received_frame.payload = &data; received_frame.payload = &data;
while (_can_interface->receive(&received_frame) > 0) { while (!_task_should_exit.load() && _can_interface->receive(&received_frame) > 0) {
CanardTransfer receive{}; CanardTransfer receive{};
CanardRxSubscription *subscription = NULL; CanardRxSubscription *subscription = NULL;
int32_t result = canardRxAccept2(&_canard_instance, &received_frame, 0, &receive, &subscription); int32_t result = canardRxAccept2(&_canard_instance, &received_frame, 0, &receive, &subscription);
@@ -253,10 +256,14 @@ void UavcanNode::Run()
perf_end(_cycle_perf); perf_end(_cycle_perf);
if (_task_should_exit.load()) { if (_instance && _task_should_exit.load()) {
_can_interface->close();
ScheduleClear(); ScheduleClear();
if (_initialized && _can_interface != nullptr) {
_can_interface->close();
_initialized = false;
}
_instance = nullptr; _instance = nullptr;
} }
+1 -1
View File
@@ -148,7 +148,7 @@ private:
void *_uavcan_heap{nullptr}; void *_uavcan_heap{nullptr};
CanardInterface *const _can_interface; CanardInterface *_can_interface;
CanardInstance _canard_instance; CanardInstance _canard_instance;