diff --git a/Core/Inc/canlog.h b/Core/Inc/canlog.h new file mode 100644 index 0000000..0636e2c --- /dev/null +++ b/Core/Inc/canlog.h @@ -0,0 +1,13 @@ +#ifndef CANLOG_H +#define CANLOG_H + +#include "main.h" + +/** + * @brief Initializes the CAN logger modules, OS threads, queues, and hardware. + * @param hcan1 Pointer to the CAN1 handle + * @param hcan2 Pointer to the CAN2 handle + */ +void CAN_Logger_Init(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2); + +#endif /* CANLOG_H */ diff --git a/Core/Src/canlog.c b/Core/Src/canlog.c new file mode 100644 index 0000000..8efc726 --- /dev/null +++ b/Core/Src/canlog.c @@ -0,0 +1,40 @@ +#include "canlog.h" +#include "cmsis_os.h" +#include + +/* Definitions for canBus1Listen */ +osThreadId_t canBus1ListenHandle; +const osThreadAttr_t canBus1Listen_attributes = { + .name = "canBus1Listen", + .stack_size = 128 * 4, + .priority = (osPriority_t) osPriorityRealtime1, +}; +/* Definitions for canBus2Listen */ +osThreadId_t canBus2ListenHandle; +const osThreadAttr_t canBus2Listen_attributes = { + .name = "canBus2Listen", + .stack_size = 128 * 4, + .priority = (osPriority_t) osPriorityRealtime, +}; + +/* Private function prototypes -----------------------------------------------*/ +void CAN_Logger_Init(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2){} +static void CAN_Listen(void *argument){} + +/* BEGIN Header_CAN_Listen */ +/** + * @brief Function implementing the canBus0Listen thread. + * @param argument: Not used + * @retval None + */ +/* END Header_CAN_Listen */ +void CAN_Listen(void *argument) +{ + /* CODE BEGIN */ + /* Infinite loop */ + for(;;) + { + osDelay(1); + } + /* CODE END */ +} diff --git a/Core/Src/main.c b/Core/Src/main.c index 62d3832..51368a2 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -18,6 +18,7 @@ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" +#include "canlog.h" #include "cmsis_os.h" /* Private includes ----------------------------------------------------------*/ @@ -48,20 +49,6 @@ SD_HandleTypeDef hsd; DMA_HandleTypeDef hdma_sdio_rx; DMA_HandleTypeDef hdma_sdio_tx; -/* Definitions for canBus1Listen */ -osThreadId_t canBus1ListenHandle; -const osThreadAttr_t canBus1Listen_attributes = { - .name = "canBus1Listen", - .stack_size = 128 * 4, - .priority = (osPriority_t) osPriorityRealtime1, -}; -/* Definitions for canBus2Listen */ -osThreadId_t canBus2ListenHandle; -const osThreadAttr_t canBus2Listen_attributes = { - .name = "canBus2Listen", - .stack_size = 128 * 4, - .priority = (osPriority_t) osPriorityRealtime, -}; /* USER CODE BEGIN PV */ /* USER CODE END PV */ @@ -73,7 +60,6 @@ static void MX_DMA_Init(void); static void MX_CAN1_Init(void); static void MX_CAN2_Init(void); static void MX_SDIO_SD_Init(void); -void can_listen(void *argument); /* USER CODE BEGIN PFP */ @@ -119,6 +105,9 @@ int main(void) MX_SDIO_SD_Init(); /* USER CODE BEGIN 2 */ + // Initialize CAN1 and CAN2 + CAN_Logger_Init(&hcan1, &hcan2); + /* USER CODE END 2 */ /* Init scheduler */ @@ -140,13 +129,6 @@ int main(void) /* add queues, ... */ /* USER CODE END RTOS_QUEUES */ - /* Create the thread(s) */ - /* creation of canBus1Listen */ - canBus1ListenHandle = osThreadNew(can_listen, (void*) &hcan1, &canBus1Listen_attributes); - - /* creation of canBus2Listen */ - canBus2ListenHandle = osThreadNew(can_listen, (void*) &hcan2, &canBus2Listen_attributes); - /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ /* USER CODE END RTOS_THREADS */ @@ -422,23 +404,7 @@ static void MX_GPIO_Init(void) /* USER CODE END 4 */ -/* USER CODE BEGIN Header_can_listen */ -/** - * @brief Function implementing the canBus0Listen thread. - * @param argument: Not used - * @retval None - */ -/* USER CODE END Header_can_listen */ -void can_listen(void *argument) -{ - /* USER CODE BEGIN 5 */ - /* Infinite loop */ - for(;;) - { - osDelay(1); - } - /* USER CODE END 5 */ -} + /** * @brief Period elapsed callback in non blocking mode diff --git a/can_logger.ioc b/can_logger.ioc index 59d20cb..26a8acf 100644 --- a/can_logger.ioc +++ b/can_logger.ioc @@ -49,7 +49,7 @@ Dma.SDIO_TX.1.Priority=DMA_PRIORITY_LOW Dma.SDIO_TX.1.RequestParameters=Instance,Direction,PeriphInc,MemInc,PeriphDataAlignment,MemDataAlignment,Mode,Priority,FIFOMode,FIFOThreshold,MemBurst,PeriphBurst FREERTOS.FootprintOK=true FREERTOS.IPParameters=Tasks01,configUSE_NEWLIB_REENTRANT,FootprintOK -FREERTOS.Tasks01=canBus1Listen,49,128,can_listen,Default,&hcan1,Dynamic,NULL,NULL;canBus2Listen,48,128,can_listen,Default,&hcan2,Dynamic,NULL,NULL +FREERTOS.Tasks01=DefaultTask,49,128,can_listen,Default,NULL,Dynamic,NULL,NULL FREERTOS.configUSE_NEWLIB_REENTRANT=1 File.Version=6 GPIO.groupedBy=