diff --git a/Core/Src/main.c b/Core/Src/main.c index d6ac9e5..f8c4c96 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -28,12 +28,28 @@ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ - +#define CAN_QUEUE_DEPTH 32 +#define CAN_TASK_STACK_WORDS 128 +#define CAN_QUEUE_CB_SIZE 128 +#define CAN_MSG_SIZE sizeof(CanMessage_t) /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ +//CCRAM: stack; control bank; queue memory +__attribute__((section(".ccmram"))) +StackType_t xCAN1_Stack[CAN_TASK_STACK_WORDS]; +__attribute__((section(".ccmram"), aligned(4))) +uint8_t can1_queue_cb[CAN_QUEUE_CB_SIZE]; +__attribute__((section(".ccmram"), aligned(4))) +uint8_t can1_queue_mq[CAN_QUEUE_DEPTH * CAN_MSG_SIZE]; +__attribute__((section(".ccmram"))) +StackType_t xCAN2_Stack[CAN_TASK_STACK_WORDS]; +__attribute__((section(".ccmram"), aligned(4))) +uint8_t can2_queue_cb[CAN_QUEUE_CB_SIZE]; +__attribute__((section(".ccmram"), aligned(4))) +uint8_t can2_queue_mq[CAN_QUEUE_DEPTH * CAN_MSG_SIZE]; /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ @@ -120,20 +136,26 @@ int main(void) osThreadId_t xCAN1rx; const osThreadAttr_t CAN1rxAttributes = { .name = "CAN1rx", - .stack_size = 128 * 4, + .stack_size = sizeof(xCAN1_Stack), .priority = (osPriority_t) osPriorityRealtime1, }; osThreadId_t xCAN2rx; const osThreadAttr_t CAN2rxAttributes = { .name = "CAN2rx", - .stack_size = 128 * 4, + .cb_mem = NULL, + .cb_size = 0U, + .stack_mem = xCAN2_Stack, + .stack_size = sizeof(xCAN2_Stack), .priority = (osPriority_t) osPriorityRealtime, }; osThreadId_t xLEDHeartbeatCAN1; const osThreadAttr_t LEDHeartbeatCAN1Attributes = { .name = "LED_HB_CAN1", + .cb_mem = NULL, + .cb_size = 0U, + .stack_mem = xCAN2_Stack, .stack_size = 128 * 4, .priority = (osPriority_t) osPriorityVeryLow1, }; @@ -151,8 +173,8 @@ int main(void) /* USER CODE END RTOS_MUTEX */ /* USER CODE BEGIN RTOS_SEMAPHORES */ - xSemaphoreCAN1 = osSemaphoreNew(32, 0, NULL); - xSemaphoreCAN2 = osSemaphoreNew(32, 0, NULL); + xSemaphoreCAN1 = osSemaphoreNew(CAN_QUEUE_DEPTH, 0, NULL); + xSemaphoreCAN2 = osSemaphoreNew(CAN_QUEUE_DEPTH, 0, NULL); if (xSemaphoreCAN1 == NULL || xSemaphoreCAN2 == NULL) Error_Handler(); @@ -167,8 +189,24 @@ int main(void) /* USER CODE END RTOS_TIMERS */ /* USER CODE BEGIN RTOS_QUEUES */ - xCAN1RxQueue = osMessageQueueNew(32, sizeof(CanMessage_t), NULL); - xCAN2RxQueue = osMessageQueueNew(32, sizeof(CanMessage_t), NULL); + const osMessageQueueAttr_t can1_queue_attr = { + .name = "CAN1_Q", + .cb_mem = can1_queue_cb, + .cb_size = sizeof(can1_queue_cb), + .mq_mem = can1_queue_mq, + .mq_size = sizeof(can1_queue_mq) + }; + + const osMessageQueueAttr_t can2_queue_attr = { + .name = "CAN2_Q", + .cb_mem = can2_queue_cb, + .cb_size = sizeof(can2_queue_cb), + .mq_mem = can2_queue_mq, + .mq_size = sizeof(can2_queue_mq) + }; + + xCAN1RxQueue = osMessageQueueNew(CAN_QUEUE_DEPTH, sizeof(CanMessage_t), &can1_queue_attr); + xCAN2RxQueue = osMessageQueueNew(CAN_QUEUE_DEPTH, sizeof(CanMessage_t), &can2_queue_attr); if (xCAN1RxQueue == NULL || xCAN2RxQueue == NULL) Error_Handler(); /* USER CODE END RTOS_QUEUES */