Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d42e5fce46 | |||
| 8ef0980510 | |||
| dc3688d3d7 | |||
| 34553af0a7 | |||
| 2cce753716 | |||
| 19eaee2674 |
@@ -24,6 +24,10 @@
|
|||||||
|
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
/* Decladerations for queues */
|
||||||
|
extern osMessageQueueId_t xCAN1RxQueue;
|
||||||
|
extern osMessageQueueId_t xCAN2RxQueue;
|
||||||
|
|
||||||
/* Decladerations for thread handles and attributes */
|
/* Decladerations for thread handles and attributes */
|
||||||
extern osThreadId_t vCAN1_rx;
|
extern osThreadId_t vCAN1_rx;
|
||||||
extern osThreadId_t vCAN2_rx;
|
extern osThreadId_t vCAN2_rx;
|
||||||
@@ -41,6 +45,7 @@ extern const osThreadAttr_t vLED_CAN2_Heartbeat_attributes;
|
|||||||
* @param hcan2 Pointer to the CAN2 handle
|
* @param hcan2 Pointer to the CAN2 handle
|
||||||
*/
|
*/
|
||||||
void vCANLoggerInit(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2);
|
void vCANLoggerInit(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2);
|
||||||
|
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan);
|
||||||
void vCANLoggerListen(void *argument);
|
void vCANLoggerListen(void *argument);
|
||||||
void vLEDHeartbeat(void *argument);
|
void vLEDHeartbeat(void *argument);
|
||||||
|
|
||||||
|
|||||||
+46
-3
@@ -55,9 +55,43 @@ void CAN_Logger_Init(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2)
|
|||||||
|
|
||||||
if (HAL_CAN_Start(hcan1) != HAL_OK) Error_Handler();
|
if (HAL_CAN_Start(hcan1) != HAL_OK) Error_Handler();
|
||||||
if (HAL_CAN_Start(hcan2) != HAL_OK) Error_Handler();
|
if (HAL_CAN_Start(hcan2) != HAL_OK) Error_Handler();
|
||||||
|
|
||||||
|
if (HAL_CAN_ActivateNotification(hcan1, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK) Error_Handler();
|
||||||
|
if (HAL_CAN_ActivateNotification(hcan2, CAN_IT_RX_FIFO0_MSG_PENDING) != HAL_OK) Error_Handler();
|
||||||
}
|
}
|
||||||
/* END CAN_Logger_Init */
|
/* END CAN_Logger_Init */
|
||||||
|
|
||||||
|
/* BEGIN HAL_CAN_RxFifo0MsgPendingCallback */
|
||||||
|
/**
|
||||||
|
* @brief ISR for CAN message pending in FIFO0
|
||||||
|
* @param argument: Can handle hcan (hcan1 or hcan2)
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
||||||
|
{
|
||||||
|
/* CODE BEGIN */
|
||||||
|
CanMessage_t message;
|
||||||
|
CAN_RxHeaderTypeDef rxHeader;
|
||||||
|
uint8_t data[8];
|
||||||
|
|
||||||
|
if (HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &rxHeader, data) != HAL_OK) Error_Handler();
|
||||||
|
|
||||||
|
message.id = rxHeader.ExtId;
|
||||||
|
message.dlc = rxHeader.DLC;
|
||||||
|
message.isExtended = (rxHeader.IDE == CAN_ID_EXT);
|
||||||
|
memcpy(message.payload, data, rxHeader.DLC);
|
||||||
|
|
||||||
|
osMessageQueueId_t queue = (hcan->Instance == CAN1) ? xCAN1RxQueue : xCAN2RxQueue;
|
||||||
|
if (osMessageQueuePut(queue, &message, 0U, 0U) != osOK) Error_Handler();
|
||||||
|
// TODO: better handling: flash error_led on osTimeout, call Error_Handler() when other errors
|
||||||
|
|
||||||
|
// Issue #1: set an event flag for led task
|
||||||
|
// osEventFlagsSet(xCanEventFlags, (hcan->Instance == CAN1) ? 0x01 : 0x02);
|
||||||
|
|
||||||
|
/* CODE END */
|
||||||
|
}
|
||||||
|
/* END HAL_CAN_RxFifo0MsgPendingCallback */
|
||||||
|
|
||||||
/* BEGIN vCANLoggerListen */
|
/* BEGIN vCANLoggerListen */
|
||||||
/**
|
/**
|
||||||
* @brief Log incoming CAN bus traffic in FIFO buffer
|
* @brief Log incoming CAN bus traffic in FIFO buffer
|
||||||
@@ -67,10 +101,19 @@ void CAN_Logger_Init(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2)
|
|||||||
void vCANLoggerListen(void *argument)
|
void vCANLoggerListen(void *argument)
|
||||||
{
|
{
|
||||||
/* CODE BEGIN */
|
/* CODE BEGIN */
|
||||||
/* Infinite loop */
|
CAN_HandleTypeDef *hcan = (CAN_HandleTypeDef*)argument;
|
||||||
for(;;)
|
osMessageQueueId_t queue;
|
||||||
|
CanMessage_t message;
|
||||||
|
|
||||||
|
queue = (hcan->Instance == CAN1) ? xCAN1RxQueue : xCAN2RxQueue;
|
||||||
|
|
||||||
|
for (;;)
|
||||||
{
|
{
|
||||||
osDelay(1);
|
if (osMessageQueueGet(queue, &msg, NULL, osWaitForever) == osOK)
|
||||||
|
{
|
||||||
|
// TODO: parse message send message to serial/uart
|
||||||
|
// TODO: add rtos semaphore to blink the LED with the timer already set
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* CODE END */
|
/* CODE END */
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-6
@@ -79,8 +79,6 @@ static void MX_CAN2_Init(void);
|
|||||||
static void MX_SDIO_SD_Init(void);
|
static void MX_SDIO_SD_Init(void);
|
||||||
|
|
||||||
/* USER CODE BEGIN PFP */
|
/* USER CODE BEGIN PFP */
|
||||||
void vCANLoggerListen(void *argument);
|
|
||||||
void vLEDHeartbeat(void *argument);
|
|
||||||
/* USER CODE END PFP */
|
/* USER CODE END PFP */
|
||||||
|
|
||||||
/* Private user code ---------------------------------------------------------*/
|
/* Private user code ---------------------------------------------------------*/
|
||||||
@@ -154,15 +152,22 @@ int main(void)
|
|||||||
|
|
||||||
/* USER CODE BEGIN RTOS_TIMERS */
|
/* USER CODE BEGIN RTOS_TIMERS */
|
||||||
xHeartbeatTimerCAN1 = osTimerNew(vLEDHeartbeat, osTimerPeriodic, &led_can1, NULL);
|
xHeartbeatTimerCAN1 = osTimerNew(vLEDHeartbeat, osTimerPeriodic, &led_can1, NULL);
|
||||||
if (xHeartbeatTimerCAN1 != NULL) osTimerStart(xHeartbeatTimerCAN1, 250U);
|
osTimerStart(xHeartbeatTimerCAN1, 250U);
|
||||||
|
|
||||||
xHeartbeatTimerCAN2 = osTimerNew(vLEDHeartbeat, osTimerPeriodic, &led_can2, NULL);
|
xHeartbeatTimerCAN2 = osTimerNew(vLEDHeartbeat, osTimerPeriodic, &led_can2, NULL);
|
||||||
if (xHeartbeatTimerCAN2 != NULL) osTimerStart(xHeartbeatTimerCAN2, 250U);
|
osTimerStart(xHeartbeatTimerCAN2, 250U);
|
||||||
|
|
||||||
|
if (xHeartbeatTimerCAN1 == NULL || xHeartbeatTimerCAN2 == NULL) Error_Handler();
|
||||||
/* USER CODE END RTOS_TIMERS */
|
/* USER CODE END RTOS_TIMERS */
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_QUEUES */
|
/* USER CODE BEGIN RTOS_QUEUES */
|
||||||
QueueHandle_t xCAN1rxQueue;
|
osMessageQueueId_t xCAN1RxQueue;
|
||||||
QueueHandle_t xCAN2rxQueue;
|
xCAN1RxQueue = osMessageQueueNew(32, sizeof(CanMessage_t), NULL);
|
||||||
|
|
||||||
|
osMessageQueueId_t xCAN2RxQueue;
|
||||||
|
xCAN2RxQueue = osMessageQueueNew(32, sizeof(CanMessage_t), NULL);
|
||||||
|
|
||||||
|
if (xCAN1RxQueue == NULL || xCAN2RxQueue == NULL) Error_Handler();
|
||||||
/* USER CODE END RTOS_QUEUES */
|
/* USER CODE END RTOS_QUEUES */
|
||||||
|
|
||||||
/* USER CODE BEGIN RTOS_THREADS */
|
/* USER CODE BEGIN RTOS_THREADS */
|
||||||
|
|||||||
Reference in New Issue
Block a user