diff --git a/Core/Inc/control.h b/Core/Inc/control.h new file mode 100644 index 0000000..d6c349e --- /dev/null +++ b/Core/Inc/control.h @@ -0,0 +1,16 @@ +#ifndef CONTROL_H +#define CONTROL_H + +#include "pdu.h" +#include "can.h" + +#define CONTROL_CANID_FANBATTBOX 0x4A1 + +extern osThreadId_t control_handle; +extern const osThreadAttr_t control_attributes; + +void vControl(void *param); + +void control_fanbattbox_record(can_msg_t args); + +#endif \ No newline at end of file diff --git a/Core/Src/can_handler.c b/Core/Src/can_handler.c index 6c362ef..22dca6c 100644 --- a/Core/Src/can_handler.c +++ b/Core/Src/can_handler.c @@ -9,6 +9,7 @@ #include "dti.h" #include "fault.h" #include "steeringio.h" +#include "control.h" #define CAN_MSG_QUEUE_SIZE 50 /* messages */ @@ -153,6 +154,9 @@ void vCanReceive(void *pv_params) case STEERING_CANID_IO: steeringio_update(msg); break; + case CONTROL_CANID_FANBATTBOX: + control_fanbattbox_record(msg); + break; default: break; } diff --git a/Core/Src/control.c b/Core/Src/control.c new file mode 100644 index 0000000..b934abf --- /dev/null +++ b/Core/Src/control.c @@ -0,0 +1,31 @@ +#include "control.h" +#include "pdu.h" + +osThreadId_t control_handle; +const osThreadAttr_t control_attributes = { + .name = "Control", + .stack_size = 128 * 8, + .priority = (osPriority_t)osPriorityRealtime, +}; + +static int fanBattBoxState = 0; + +void vControl(void *param) +{ + pdu_t *pdu = (pdu_t *)param; + + for (;;) { + write_fan_battbox(pdu, fanBattBoxState); + + osDelay(1000); + } +} + +void control_fanbattbox_record(can_msg_t msg) +{ + if (msg.data[0] > 0) { + fanBattBoxState = 1; + } else { + fanBattBoxState = 0; + } +} diff --git a/Core/Src/main.c b/Core/Src/main.c index a17fd52..c7b8748 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -37,6 +37,7 @@ #include "dti.h" #include "steeringio.h" #include "pedals.h" +#include "control.h" #include "monitor.h" #include "state_machine.h" /* USER CODE END Includes */ @@ -248,6 +249,11 @@ int main(void) sm_args->mpu = mpu; sm_director_handle = osThreadNew(vStateMachineDirector, sm_args, &sm_director_attributes); assert(sm_director_handle); + + /* Control File Thread */ + control_handle = osThreadNew(vControl, pdu, &control_attributes); + assert(control_handle); + /* USER CODE END RTOS_THREADS */ /* USER CODE BEGIN RTOS_EVENTS */ @@ -764,7 +770,7 @@ void StartDefaultTask(void *argument) // refresh the external watchdog so the car doesnt fault pet_watchdog(mpu); - + /* Send NERO state data continuously */ send_git_version_message(); osDelay(500); diff --git a/Makefile b/Makefile index 7c0b05b..78bac7e 100644 --- a/Makefile +++ b/Makefile @@ -82,6 +82,7 @@ Core/Src/state_machine.c \ Core/Src/bms.c \ Core/Src/pdu.c \ Core/Src/mpu.c \ +Core/Src/control.c \ Core/Src/steeringio.c \ Core/Src/pedals.c \ Core/Src/cerb_utils.c \