Skip to content

Commit

Permalink
changing display modes, can interrupt, updated submod, codegen for CA…
Browse files Browse the repository at this point in the history
…N RX it, switch monitor task
  • Loading branch information
Sabramz committed Apr 13, 2024
1 parent 194c080 commit 23fbda8
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 29 deletions.
3 changes: 2 additions & 1 deletion Charger-FW.ioc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ MxCube.Version=6.10.0
MxDb.Version=DB.6.0.100
NVIC.BusFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
NVIC.DebugMonitor_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
NVIC.FDCAN1_IT0_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true
NVIC.ForceEnableDMAVector=true
NVIC.HardFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
NVIC.MemoryManagement_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false
Expand Down Expand Up @@ -129,7 +130,7 @@ ProjectManager.ToolChainLocation=
ProjectManager.UAScriptAfterPath=
ProjectManager.UAScriptBeforePath=
ProjectManager.UnderRoot=false
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_I2C2_Init-I2C2-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_I2C2_Init-I2C2-false-HAL-true,4-MX_USART2_UART_Init-USART2-false-HAL-true,5-MX_FDCAN1_Init-FDCAN1-false-HAL-true
RCC.AHBFreq_Value=16000000
RCC.APB1Freq_Value=16000000
RCC.APB1TimFreq_Value=16000000
Expand Down
7 changes: 6 additions & 1 deletion Core/Inc/iroh_tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@ void vDisplayBmsData(void* pv_params);
extern osThreadId_t send_bms_data_handle;
extern const osThreadAttr_t send_bms_data_attributes;

void vButtonMonitor(void* pv_params);
extern osThreadId_t button_monitor_handle;
extern const osThreadAttr_t button_monitor_attributes;

/*
void vSendChargerState(void* pv_params);
extern osThreadId_t send_charger_state_handle;
extern const osThreadAttr_t send_charger_state_attributes;
extern const osThreadAttr_t send_charger_state_attributes; */

#endif
1 change: 1 addition & 0 deletions Core/Inc/stm32g4xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void BusFault_Handler(void);
void UsageFault_Handler(void);
void DebugMon_Handler(void);
void SysTick_Handler(void);
void FDCAN1_IT0_IRQHandler(void);
/* USER CODE BEGIN EFP */

/* USER CODE END EFP */
Expand Down
8 changes: 0 additions & 8 deletions Core/Src/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
void receive_msg(FDCAN_HandleTypeDef *hfdcan)
{
iroh_error_t e;

if (HAL_FDCAN_GetRxFifoFillLevel(hfdcan, FDCAN_RX_FIFO0) != HAL_OK) {
e.code = 1;
strcpy(e.msg, "No msg Recieved");
osMessageQueuePut(error_queue, &e, 0, 2000);
return;
}

FDCAN_RxHeaderTypeDef rx_header;
bms_data_t bms_data;

Expand Down
45 changes: 35 additions & 10 deletions Core/Src/iroh_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "iroh_tasks.h"
#include "queues.h"
#include "seven_segment.h"
#include "switch.h"

static I2C_HandleTypeDef *hi2c;

Expand All @@ -11,6 +12,10 @@ typedef enum
CURRENT_AND_SOC,
VOLTAGE,
} display_state_t;
int display_state_count = 2;
display_state_t states[] = {CURRENT_AND_SOC, VOLTAGE};
int state_idx = 0;


osThreadId_t send_bms_data_handle;
const osThreadAttr_t send_bms_data_attributes = {
Expand All @@ -23,28 +28,48 @@ void vDisplayBmsData(void *pv_params)

hi2c = (I2C_HandleTypeDef *)pv_params;
bms_data_t bms_data;
display_state_t state = CURRENT_AND_SOC;

for (;;)
{

// testing code
// write_current(hi2c, 2);
// write_charge(hi2c, 90);

if (osMessageQueueGet(bms_data_queue, &bms_data, NULL, 0U) == osOK)
{
if (state == CURRENT_AND_SOC)
if (states[state_idx] == CURRENT_AND_SOC)
{
write_current_and_soc(hi2c, &bms_data);
} else if (state == VOLTAGE) {
}
else if (states[state_idx] == VOLTAGE)
{
write_voltage(hi2c, &bms_data);
}
}
}
}

osThreadId_t send_charger_state_handle;
osThreadId_t button_monitor_handle;
const osThreadAttr_t button_monitor_attributes = {
.name = "DisplayBmsData",
.stack_size = 128 * 8,
.priority = (osPriority_t)osPriorityAboveNormal4};

void vButtonMonitor(void *pv_params)
{

GPIO_TypeDef* gpio = (GPIO_TypeDef*) pv_params;

for (;;)
{
if (get_switch(gpio, SWITCH_PIN_1) == 0) {
if (state_idx + 1 == display_state_count) {
state_idx = 0;
} else {
state_idx += 1;
}
}
vTaskDelay(50);
}
}

/* osThreadId_t send_charger_state_handle;
const osThreadAttr_t send_charger_state_attributes = {
.name = "SendChargerState",
.stack_size = 128 * 8,
Expand All @@ -65,4 +90,4 @@ void vSendChargerState(void *pv_params)
{
can_send_msg(can, &penis_msg);
}
}
} */
7 changes: 3 additions & 4 deletions Core/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ I2C_HandleTypeDef hi2c2;

UART_HandleTypeDef huart2;

GPIO_InitTypeDef GPIO_InitStruct;

/* Definitions for defaultTask */
osThreadId_t defaultTaskHandle;
const osThreadAttr_t defaultTask_attributes = {
Expand Down Expand Up @@ -112,7 +110,7 @@ int main(void)
MX_USART2_UART_Init();
MX_FDCAN1_Init();
/* USER CODE BEGIN 2 */
can_t* iroh_can = init_iroh_can(&hfdcan1);
init_iroh_can(&hfdcan1);
/* USER CODE END 2 */

/* Init scheduler */
Expand Down Expand Up @@ -141,7 +139,7 @@ int main(void)

/* USER CODE BEGIN RTOS_THREADS */
send_bms_data_handle = osThreadNew(vDisplayBmsData, &hi2c2, &send_bms_data_attributes);
send_charger_state_handle = osThreadNew(vSendChargerState, &iroh_can, &send_charger_state_attributes);
button_monitor_handle = osThreadNew(vButtonMonitor, GPIOB, &button_monitor_attributes);
/* USER CODE END RTOS_THREADS */

/* USER CODE BEGIN RTOS_EVENTS */
Expand Down Expand Up @@ -349,6 +347,7 @@ static void MX_USART2_UART_Init(void)
*/
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
/* USER CODE BEGIN MX_GPIO_Init_1 */
/* USER CODE END MX_GPIO_Init_1 */

Expand Down
5 changes: 5 additions & 0 deletions Core/Src/stm32g4xx_hal_msp.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef* hfdcan)
GPIO_InitStruct.Alternate = GPIO_AF9_FDCAN1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* FDCAN1 interrupt Init */
HAL_NVIC_SetPriority(FDCAN1_IT0_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(FDCAN1_IT0_IRQn);
/* USER CODE BEGIN FDCAN1_MspInit 1 */

/* USER CODE END FDCAN1_MspInit 1 */
Expand Down Expand Up @@ -152,6 +155,8 @@ void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef* hfdcan)
*/
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_11|GPIO_PIN_12);

/* FDCAN1 interrupt DeInit */
HAL_NVIC_DisableIRQ(FDCAN1_IT0_IRQn);
/* USER CODE BEGIN FDCAN1_MspDeInit 1 */

/* USER CODE END FDCAN1_MspDeInit 1 */
Expand Down
17 changes: 16 additions & 1 deletion Core/Src/stm32g4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "stm32g4xx_it.h"
#include "FreeRTOS.h"
#include "task.h"
#include "can.h"
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
Expand Down Expand Up @@ -57,7 +58,7 @@
/* USER CODE END 0 */

/* External variables --------------------------------------------------------*/

extern FDCAN_HandleTypeDef hfdcan1;
/* USER CODE BEGIN EV */

/* USER CODE END EV */
Expand Down Expand Up @@ -182,6 +183,20 @@ void SysTick_Handler(void)
/* please refer to the startup file (startup_stm32g4xx.s). */
/******************************************************************************/

/**
* @brief This function handles FDCAN1 interrupt 0.
*/
void FDCAN1_IT0_IRQHandler(void)
{
/* USER CODE BEGIN FDCAN1_IT0_IRQn 0 */
receive_msg(&hfdcan1);
/* USER CODE END FDCAN1_IT0_IRQn 0 */
HAL_FDCAN_IRQHandler(&hfdcan1);
/* USER CODE BEGIN FDCAN1_IT0_IRQn 1 */

/* USER CODE END FDCAN1_IT0_IRQn 1 */
}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##########################################################################################################################
# File automatically-generated by tool: [projectgenerator] version: [4.2.0-B44] date: [Sat Feb 03 13:35:20 EST 2024]
# File automatically-generated by tool: [projectgenerator] version: [4.2.0-B44] date: [Sat Apr 13 19:34:13 EDT 2024]
##########################################################################################################################

# ------------------------------------------------
Expand All @@ -13,7 +13,7 @@
######################################
# target
######################################
TARGET = iroh
TARGET = Charger-FW


######################################
Expand Down Expand Up @@ -75,7 +75,7 @@ Middlewares/Third_Party/FreeRTOS/Source/tasks.c \
Middlewares/Third_Party/FreeRTOS/Source/timers.c \
Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.c \
Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.c \
Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c
Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c

# ASM sources
ASM_SOURCES = \
Expand Down

0 comments on commit 23fbda8

Please sign in to comment.