Skip to content

Commit 5e5f0ff

Browse files
committed
fix(dronecan): address sensei-hacker review feedback on PR #11560
- Replace empty switch cases in handle_NodeStatus with (void)nodeStatus + TODO - Remove volatile from main-loop-only canTxDropped/canTxQueueHWM - Use __HAL_CAN_DISABLE_IT() instead of HAL_CAN_DeactivateNotification() in canTxDrainQueue (ISR context safety)
1 parent caa6d63 commit 5e5f0ff

2 files changed

Lines changed: 9 additions & 31 deletions

File tree

src/main/drivers/dronecan/dronecan.c

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -391,34 +391,8 @@ static void handle_NodeStatus(CanardInstance *ins, CanardRxTransfer *transfer) {
391391
}
392392

393393

394-
switch (nodeStatus.health) {
395-
case UAVCAN_PROTOCOL_NODESTATUS_HEALTH_OK:
396-
break;
397-
case UAVCAN_PROTOCOL_NODESTATUS_HEALTH_WARNING:
398-
break;
399-
case UAVCAN_PROTOCOL_NODESTATUS_HEALTH_ERROR:
400-
break;
401-
case UAVCAN_PROTOCOL_NODESTATUS_HEALTH_CRITICAL:
402-
break;
403-
default:
404-
break;
405-
}
406-
407-
408-
switch(nodeStatus.mode) {
409-
case UAVCAN_PROTOCOL_NODESTATUS_MODE_OPERATIONAL:
410-
break;
411-
case UAVCAN_PROTOCOL_NODESTATUS_MODE_INITIALIZATION:
412-
break;
413-
case UAVCAN_PROTOCOL_NODESTATUS_MODE_MAINTENANCE:
414-
break;
415-
case UAVCAN_PROTOCOL_NODESTATUS_MODE_SOFTWARE_UPDATE:
416-
break;
417-
case UAVCAN_PROTOCOL_NODESTATUS_MODE_OFFLINE:
418-
break;
419-
default:
420-
break;
421-
}
394+
// TODO: NodeStatus health/mode monitoring — currently no action taken
395+
(void)nodeStatus;
422396
}
423397

424398
static void handle_GNSSAuxiliary(CanardInstance *ins, CanardRxTransfer *transfer) {

src/main/drivers/dronecan/libcanard/canard_stm32f7xx_driver.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ static CAN_HandleTypeDef hcan1;
5454
// canTxDropped and canTxQueueHWM are written by main loop (canTxQueuePush), read by main loop only.
5555
// canRxBufferHWM is written by ISR (rxBufferPushFrame), read by main loop only.
5656
// All are uint8/uint16 so reads are single-instruction atomic on Cortex-M.
57-
static volatile uint16_t canTxDropped = 0;
58-
static volatile uint8_t canTxQueueHWM = 0;
57+
// Only canRxBufferHWM needs volatile (ISR vs main loop sharing).
58+
static uint16_t canTxDropped = 0;
59+
static uint8_t canTxQueueHWM = 0;
5960
static volatile uint8_t canRxBufferHWM = 0;
6061

6162
/* --- Initialization --- */
@@ -509,7 +510,10 @@ static void canTxDrainQueue(CAN_HandleTypeDef *hcan) {
509510
canTxQueueConsume();
510511
}
511512
if (canTxQueueIsEmpty()) {
512-
HAL_CAN_DeactivateNotification(hcan, CAN_IT_TX_MAILBOX_EMPTY);
513+
// Use the register-level macro instead of HAL_CAN_DeactivateNotification:
514+
// this function is called from ISR context (TX mailbox complete callbacks)
515+
// where HAL functions using __HAL_LOCK() may not be safe to call.
516+
__HAL_CAN_DISABLE_IT(hcan, CAN_IT_TX_MAILBOX_EMPTY);
513517
}
514518
}
515519

0 commit comments

Comments
 (0)