diff --git a/Core/Inc/CAN_Communication.h b/Core/Inc/CAN_Communication.h index b2cac6d..65997f3 100644 --- a/Core/Inc/CAN_Communication.h +++ b/Core/Inc/CAN_Communication.h @@ -33,6 +33,10 @@ typedef struct { extern canFrame framebuffer[CANFRAMEBUFFERSIZE]; +extern uint32_t framebufferwritepointer; +extern uint32_t framebufferreadpointer; +extern uint32_t frames_read; + void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef* handle, uint32_t interrupt_flags); diff --git a/Core/Src/CAN_Communication.c b/Core/Src/CAN_Communication.c index b65a946..748e229 100644 --- a/Core/Src/CAN_Communication.c +++ b/Core/Src/CAN_Communication.c @@ -11,6 +11,7 @@ #include "stm32g4xx_hal_fdcan.h" +#include #include // 3 should be programmed with CAN id 2 @@ -19,8 +20,9 @@ const uint16_t slave_CAN_id_to_slave_index[7] = { 0, 1, 2, 3, 4, 5, 6}; // TODO: Make this pretty pls canFrame framebuffer[CANFRAMEBUFFERSIZE] = {0}; -uint32_t framebufferwritepointer; -uint32_t framebufferreadpointer; +uint32_t framebufferwritepointer = 0; +uint32_t framebufferreadpointer = 0; +uint32_t frames_read = 0; void CAN_Init(FDCAN_HandleTypeDef* hcan) { HAL_FDCAN_Stop(hcan); @@ -51,6 +53,7 @@ void CAN_Init(FDCAN_HandleTypeDef* hcan) { } uint8_t CAN_Receive(FDCAN_HandleTypeDef* hcan) { + frames_read = 0; while (framebufferreadpointer != framebufferwritepointer) { framebufferreadpointer++; @@ -59,6 +62,7 @@ uint8_t CAN_Receive(FDCAN_HandleTypeDef* hcan) { } canFrame rxFrame = framebuffer[framebufferreadpointer]; + frames_read++; if ((rxFrame.FrameID & SLAVE_STATUS_BASE_ADDRESS) == SLAVE_STATUS_BASE_ADDRESS) { diff --git a/Core/Src/stm32g4xx_it.c b/Core/Src/stm32g4xx_it.c index ae27c25..714fb35 100644 --- a/Core/Src/stm32g4xx_it.c +++ b/Core/Src/stm32g4xx_it.c @@ -61,11 +61,6 @@ extern FDCAN_HandleTypeDef hfdcan1; extern SPI_HandleTypeDef hspi1; /* USER CODE BEGIN EV */ - - -extern uint8_t framebufferwritepointer; -extern uint8_t framebufferreadpointer; - /* USER CODE END EV */ /******************************************************************************/