Skip to content

Commit 37c113d

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 efa2576 commit 37c113d

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
@@ -389,34 +389,8 @@ static void handle_NodeStatus(CanardInstance *ins, CanardRxTransfer *transfer) {
389389
}
390390

391391

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

422396
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)