diff --git a/VCU/.cproject b/VCU/.cproject
index 5d34c6db..91431fdf 100644
--- a/VCU/.cproject
+++ b/VCU/.cproject
@@ -264,6 +264,7 @@
-
diff --git a/VCU/.gitignore b/VCU/.gitignore
index 2627492f..b3a4ed01 100644
--- a/VCU/.gitignore
+++ b/VCU/.gitignore
@@ -9,3 +9,4 @@
RemoteSystemsTempFiles/
BuildConfig_*/
/SIM_MODE_VCU_REV2/
+/Debug/
diff --git a/VCU/.settings/org.eclipse.core.resources.prefs b/VCU/.settings/org.eclipse.core.resources.prefs
index 607341fb..c54bebf6 100644
--- a/VCU/.settings/org.eclipse.core.resources.prefs
+++ b/VCU/.settings/org.eclipse.core.resources.prefs
@@ -48,6 +48,8 @@ encoding//BuildConfig_VCU-REV2/Phantom/Drivers/RTD_Buzzer/subdir_rules.mk=UTF-8
encoding//BuildConfig_VCU-REV2/Phantom/Drivers/RTD_Buzzer/subdir_vars.mk=UTF-8
encoding//BuildConfig_VCU-REV2/Phantom/Drivers/RTOS/subdir_rules.mk=UTF-8
encoding//BuildConfig_VCU-REV2/Phantom/Drivers/RTOS/subdir_vars.mk=UTF-8
+encoding//BuildConfig_VCU-REV2/Phantom/Drivers/STATE_MACHINE/subdir_rules.mk=UTF-8
+encoding//BuildConfig_VCU-REV2/Phantom/Drivers/STATE_MACHINE/subdir_vars.mk=UTF-8
encoding//BuildConfig_VCU-REV2/Phantom/Drivers/UART/subdir_rules.mk=UTF-8
encoding//BuildConfig_VCU-REV2/Phantom/Drivers/UART/subdir_vars.mk=UTF-8
encoding//BuildConfig_VCU-REV2/Phantom/data_structures/subdir_rules.mk=UTF-8
@@ -124,6 +126,8 @@ encoding//SIM_MODE_VCU_REV2/Phantom/Drivers/RTD_Buzzer/subdir_rules.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/Phantom/Drivers/RTD_Buzzer/subdir_vars.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/Phantom/Drivers/RTOS/subdir_rules.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/Phantom/Drivers/RTOS/subdir_vars.mk=UTF-8
+encoding//SIM_MODE_VCU_REV2/Phantom/Drivers/STATE_MACHINE/subdir_rules.mk=UTF-8
+encoding//SIM_MODE_VCU_REV2/Phantom/Drivers/STATE_MACHINE/subdir_vars.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/Phantom/Drivers/UART/subdir_rules.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/Phantom/Drivers/UART/subdir_vars.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/Phantom/data_structures/subdir_rules.mk=UTF-8
@@ -132,39 +136,8 @@ encoding//SIM_MODE_VCU_REV2/Phantom/subdir_rules.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/Phantom/subdir_vars.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/Phantom/tasks/source/subdir_rules.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/Phantom/tasks/source/subdir_vars.mk=UTF-8
-encoding//SIM_MODE_VCU_REV2/Phantom/test_eeprom/subdir_rules.mk=UTF-8
-encoding//SIM_MODE_VCU_REV2/Phantom/test_eeprom/subdir_vars.mk=UTF-8
-encoding//SIM_MODE_VCU_REV2/Simulation_Mode_VCU_REV2/subdir_rules.mk=UTF-8
-encoding//SIM_MODE_VCU_REV2/Simulation_Mode_VCU_REV2/subdir_vars.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/halcogen_vcu/source/subdir_rules.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/halcogen_vcu/source/subdir_vars.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/makefile=UTF-8
encoding//SIM_MODE_VCU_REV2/objects.mk=UTF-8
encoding//SIM_MODE_VCU_REV2/sources.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/DAC_SPI/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/DAC_SPI/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/EEPROM/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/EEPROM/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/RGB_LED/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/RGB_LED/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/RTD_Buzzer/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/RTD_Buzzer/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/RTOS/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/RTOS/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/UART/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/Drivers/UART/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/data_structures/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/data_structures/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/tasks/source/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/tasks/source/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/test_eeprom/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/Phantom/test_eeprom/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/halcogen_launchpad/source/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/halcogen_launchpad/source/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/halcogen_vcu/source/subdir_rules.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/halcogen_vcu/source/subdir_vars.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/makefile=UTF-8
-encoding//Simulation_Mode_VCU_REV2/objects.mk=UTF-8
-encoding//Simulation_Mode_VCU_REV2/sources.mk=UTF-8
diff --git a/VCU/Debug/Phantom/tasks/source/subdir_vars.mk b/VCU/Debug/Phantom/tasks/source/subdir_vars.mk
index b66cfe6e..1da18bf0 100644
--- a/VCU/Debug/Phantom/tasks/source/subdir_vars.mk
+++ b/VCU/Debug/Phantom/tasks/source/subdir_vars.mk
@@ -12,7 +12,7 @@ C_SRCS += \
../Phantom/tasks/source/task_statemachine.c \
../Phantom/tasks/source/task_test.c \
../Phantom/tasks/source/task_throttle_actor.c \
-../Phantom/tasks/source/task_throttle_agent.c \
+../Phantom/tasks/source/task_pedal_readings.c \
../Phantom/tasks/source/task_watchdog.c
C_DEPS += \
@@ -22,7 +22,7 @@ C_DEPS += \
./Phantom/tasks/source/task_statemachine.d \
./Phantom/tasks/source/task_test.d \
./Phantom/tasks/source/task_throttle_actor.d \
-./Phantom/tasks/source/task_throttle_agent.d \
+./Phantom/tasks/source/task_pedal_readings.d \
./Phantom/tasks/source/task_watchdog.d
OBJS += \
@@ -32,7 +32,7 @@ OBJS += \
./Phantom/tasks/source/task_statemachine.obj \
./Phantom/tasks/source/task_test.obj \
./Phantom/tasks/source/task_throttle_actor.obj \
-./Phantom/tasks/source/task_throttle_agent.obj \
+./Phantom/tasks/source/task_pedal_readings.obj \
./Phantom/tasks/source/task_watchdog.obj
OBJS__QUOTED += \
@@ -42,7 +42,7 @@ OBJS__QUOTED += \
"Phantom\tasks\source\task_statemachine.obj" \
"Phantom\tasks\source\task_test.obj" \
"Phantom\tasks\source\task_throttle_actor.obj" \
-"Phantom\tasks\source\task_throttle_agent.obj" \
+"Phantom\tasks\source\task_pedal_readings.obj" \
"Phantom\tasks\source\task_watchdog.obj"
C_DEPS__QUOTED += \
@@ -52,7 +52,7 @@ C_DEPS__QUOTED += \
"Phantom\tasks\source\task_statemachine.d" \
"Phantom\tasks\source\task_test.d" \
"Phantom\tasks\source\task_throttle_actor.d" \
-"Phantom\tasks\source\task_throttle_agent.d" \
+"Phantom\tasks\source\task_pedal_readings.d" \
"Phantom\tasks\source\task_watchdog.d"
C_SRCS__QUOTED += \
@@ -62,7 +62,7 @@ C_SRCS__QUOTED += \
"../Phantom/tasks/source/task_statemachine.c" \
"../Phantom/tasks/source/task_test.c" \
"../Phantom/tasks/source/task_throttle_actor.c" \
-"../Phantom/tasks/source/task_throttle_agent.c" \
+"../Phantom/tasks/source/task_pedal_readings.c" \
"../Phantom/tasks/source/task_watchdog.c"
diff --git a/VCU/Debug/ccsObjs.opt b/VCU/Debug/ccsObjs.opt
index f2e3c03d..6b75a253 100644
--- a/VCU/Debug/ccsObjs.opt
+++ b/VCU/Debug/ccsObjs.opt
@@ -1 +1 @@
-"./Phantom/Drivers/DAC_SPI/MCP48FV_DAC_SPI.obj" "./Phantom/Drivers/EEPROM/eeprom_driver.obj" "./Phantom/Drivers/RGB_LED/RGB_LED.obj" "./Phantom/Drivers/RTD_Buzzer/RTD_Buzzer.obj" "./Phantom/Drivers/RTOS/phantom_queue.obj" "./Phantom/Drivers/RTOS/phantom_task.obj" "./Phantom/Drivers/RTOS/phantom_timer.obj" "./Phantom/Drivers/UART/Phantom_sci.obj" "./Phantom/data_structures/vcu_data.obj" "./Phantom/main.obj" "./Phantom/tasks/source/task_eeprom.obj" "./Phantom/tasks/source/task_interrupt.obj" "./Phantom/tasks/source/task_receive.obj" "./Phantom/tasks/source/task_statemachine.obj" "./Phantom/tasks/source/task_test.obj" "./Phantom/tasks/source/task_throttle_actor.obj" "./Phantom/tasks/source/task_throttle_agent.obj" "./Phantom/tasks/source/task_watchdog.obj" "./Phantom/test_eeprom/testEeprom.obj" "./halcogen_launchpad/source/Device_TMS570LS12.obj" "./halcogen_launchpad/source/Fapi_UserDefinedFunctions.obj" "./halcogen_launchpad/source/adc.obj" "./halcogen_launchpad/source/dabort.obj" "./halcogen_launchpad/source/errata_SSWF021_45.obj" "./halcogen_launchpad/source/esm.obj" "./halcogen_launchpad/source/gio.obj" "./halcogen_launchpad/source/het.obj" "./halcogen_launchpad/source/i2c.obj" "./halcogen_launchpad/source/mibspi.obj" "./halcogen_launchpad/source/notification.obj" "./halcogen_launchpad/source/os_croutine.obj" "./halcogen_launchpad/source/os_event_groups.obj" "./halcogen_launchpad/source/os_heap.obj" "./halcogen_launchpad/source/os_list.obj" "./halcogen_launchpad/source/os_mpu_wrappers.obj" "./halcogen_launchpad/source/os_port.obj" "./halcogen_launchpad/source/os_portasm.obj" "./halcogen_launchpad/source/os_queue.obj" "./halcogen_launchpad/source/os_tasks.obj" "./halcogen_launchpad/source/os_timer.obj" "./halcogen_launchpad/source/pinmux.obj" "./halcogen_launchpad/source/rti.obj" "./halcogen_launchpad/source/sci.obj" "./halcogen_launchpad/source/svc.obj" "./halcogen_launchpad/source/sys_core.obj" "./halcogen_launchpad/source/sys_dma.obj" "./halcogen_launchpad/source/sys_intvecs.obj" "./halcogen_launchpad/source/sys_main.obj" "./halcogen_launchpad/source/sys_mpu.obj" "./halcogen_launchpad/source/sys_pcr.obj" "./halcogen_launchpad/source/sys_phantom.obj" "./halcogen_launchpad/source/sys_pmm.obj" "./halcogen_launchpad/source/sys_pmu.obj" "./halcogen_launchpad/source/sys_selftest.obj" "./halcogen_launchpad/source/sys_startup.obj" "./halcogen_launchpad/source/sys_vim.obj" "./halcogen_launchpad/source/system.obj" "./halcogen_launchpad/source/ti_fee_Info.obj" "./halcogen_launchpad/source/ti_fee_cancel.obj" "./halcogen_launchpad/source/ti_fee_cfg.obj" "./halcogen_launchpad/source/ti_fee_eraseimmediateblock.obj" "./halcogen_launchpad/source/ti_fee_format.obj" "./halcogen_launchpad/source/ti_fee_ini.obj" "./halcogen_launchpad/source/ti_fee_invalidateblock.obj" "./halcogen_launchpad/source/ti_fee_main.obj" "./halcogen_launchpad/source/ti_fee_read.obj" "./halcogen_launchpad/source/ti_fee_readSync.obj" "./halcogen_launchpad/source/ti_fee_shutdown.obj" "./halcogen_launchpad/source/ti_fee_util.obj" "./halcogen_launchpad/source/ti_fee_writeAsync.obj" "./halcogen_launchpad/source/ti_fee_writeSync.obj" "./halcogen_vcu/source/Device_TMS570LS12.obj" "./halcogen_vcu/source/Fapi_UserDefinedFunctions.obj" "./halcogen_vcu/source/adc.obj" "./halcogen_vcu/source/dabort.obj" "./halcogen_vcu/source/errata_SSWF021_45.obj" "./halcogen_vcu/source/esm.obj" "./halcogen_vcu/source/gio.obj" "./halcogen_vcu/source/het.obj" "./halcogen_vcu/source/i2c.obj" "./halcogen_vcu/source/mibspi.obj" "./halcogen_vcu/source/notification.obj" "./halcogen_vcu/source/os_croutine.obj" "./halcogen_vcu/source/os_event_groups.obj" "./halcogen_vcu/source/os_heap.obj" "./halcogen_vcu/source/os_list.obj" "./halcogen_vcu/source/os_mpu_wrappers.obj" "./halcogen_vcu/source/os_port.obj" "./halcogen_vcu/source/os_portasm.obj" "./halcogen_vcu/source/os_queue.obj" "./halcogen_vcu/source/os_tasks.obj" "./halcogen_vcu/source/os_timer.obj" "./halcogen_vcu/source/pinmux.obj" "./halcogen_vcu/source/rti.obj" "./halcogen_vcu/source/sci.obj" "./halcogen_vcu/source/sys_core.obj" "./halcogen_vcu/source/sys_dma.obj" "./halcogen_vcu/source/sys_intvecs.obj" "./halcogen_vcu/source/sys_mpu.obj" "./halcogen_vcu/source/sys_pcr.obj" "./halcogen_vcu/source/sys_phantom.obj" "./halcogen_vcu/source/sys_pmm.obj" "./halcogen_vcu/source/sys_pmu.obj" "./halcogen_vcu/source/sys_selftest.obj" "./halcogen_vcu/source/sys_startup.obj" "./halcogen_vcu/source/sys_vim.obj" "./halcogen_vcu/source/system.obj" "./halcogen_vcu/source/ti_fee_Info.obj" "./halcogen_vcu/source/ti_fee_cancel.obj" "./halcogen_vcu/source/ti_fee_cfg.obj" "./halcogen_vcu/source/ti_fee_eraseimmediateblock.obj" "./halcogen_vcu/source/ti_fee_format.obj" "./halcogen_vcu/source/ti_fee_ini.obj" "./halcogen_vcu/source/ti_fee_invalidateblock.obj" "./halcogen_vcu/source/ti_fee_main.obj" "./halcogen_vcu/source/ti_fee_read.obj" "./halcogen_vcu/source/ti_fee_readSync.obj" "./halcogen_vcu/source/ti_fee_shutdown.obj" "./halcogen_vcu/source/ti_fee_util.obj" "./halcogen_vcu/source/ti_fee_writeAsync.obj" "./halcogen_vcu/source/ti_fee_writeSync.obj" "../halcogen_launchpad/source/sys_link.cmd" "../halcogen_vcu/source/sys_linker_freeRTOS.cmd" -llibc.a
\ No newline at end of file
+"./Phantom/Drivers/DAC_SPI/MCP48FV_DAC_SPI.obj" "./Phantom/Drivers/EEPROM/eeprom_driver.obj" "./Phantom/Drivers/RGB_LED/RGB_LED.obj" "./Phantom/Drivers/RTD_Buzzer/RTD_Buzzer.obj" "./Phantom/Drivers/RTOS/phantom_queue.obj" "./Phantom/Drivers/RTOS/phantom_task.obj" "./Phantom/Drivers/RTOS/phantom_timer.obj" "./Phantom/Drivers/UART/Phantom_sci.obj" "./Phantom/data_structures/vcu_data.obj" "./Phantom/main.obj" "./Phantom/tasks/source/task_eeprom.obj" "./Phantom/tasks/source/task_interrupt.obj" "./Phantom/tasks/source/task_receive.obj" "./Phantom/tasks/source/task_statemachine.obj" "./Phantom/tasks/source/task_test.obj" "./Phantom/tasks/source/task_throttle_actor.obj" "./Phantom/tasks/source/task_pedal_readings.obj" "./Phantom/tasks/source/task_watchdog.obj" "./Phantom/test_eeprom/testEeprom.obj" "./halcogen_launchpad/source/Device_TMS570LS12.obj" "./halcogen_launchpad/source/Fapi_UserDefinedFunctions.obj" "./halcogen_launchpad/source/adc.obj" "./halcogen_launchpad/source/dabort.obj" "./halcogen_launchpad/source/errata_SSWF021_45.obj" "./halcogen_launchpad/source/esm.obj" "./halcogen_launchpad/source/gio.obj" "./halcogen_launchpad/source/het.obj" "./halcogen_launchpad/source/i2c.obj" "./halcogen_launchpad/source/mibspi.obj" "./halcogen_launchpad/source/notification.obj" "./halcogen_launchpad/source/os_croutine.obj" "./halcogen_launchpad/source/os_event_groups.obj" "./halcogen_launchpad/source/os_heap.obj" "./halcogen_launchpad/source/os_list.obj" "./halcogen_launchpad/source/os_mpu_wrappers.obj" "./halcogen_launchpad/source/os_port.obj" "./halcogen_launchpad/source/os_portasm.obj" "./halcogen_launchpad/source/os_queue.obj" "./halcogen_launchpad/source/os_tasks.obj" "./halcogen_launchpad/source/os_timer.obj" "./halcogen_launchpad/source/pinmux.obj" "./halcogen_launchpad/source/rti.obj" "./halcogen_launchpad/source/sci.obj" "./halcogen_launchpad/source/svc.obj" "./halcogen_launchpad/source/sys_core.obj" "./halcogen_launchpad/source/sys_dma.obj" "./halcogen_launchpad/source/sys_intvecs.obj" "./halcogen_launchpad/source/sys_main.obj" "./halcogen_launchpad/source/sys_mpu.obj" "./halcogen_launchpad/source/sys_pcr.obj" "./halcogen_launchpad/source/sys_phantom.obj" "./halcogen_launchpad/source/sys_pmm.obj" "./halcogen_launchpad/source/sys_pmu.obj" "./halcogen_launchpad/source/sys_selftest.obj" "./halcogen_launchpad/source/sys_startup.obj" "./halcogen_launchpad/source/sys_vim.obj" "./halcogen_launchpad/source/system.obj" "./halcogen_launchpad/source/ti_fee_Info.obj" "./halcogen_launchpad/source/ti_fee_cancel.obj" "./halcogen_launchpad/source/ti_fee_cfg.obj" "./halcogen_launchpad/source/ti_fee_eraseimmediateblock.obj" "./halcogen_launchpad/source/ti_fee_format.obj" "./halcogen_launchpad/source/ti_fee_ini.obj" "./halcogen_launchpad/source/ti_fee_invalidateblock.obj" "./halcogen_launchpad/source/ti_fee_main.obj" "./halcogen_launchpad/source/ti_fee_read.obj" "./halcogen_launchpad/source/ti_fee_readSync.obj" "./halcogen_launchpad/source/ti_fee_shutdown.obj" "./halcogen_launchpad/source/ti_fee_util.obj" "./halcogen_launchpad/source/ti_fee_writeAsync.obj" "./halcogen_launchpad/source/ti_fee_writeSync.obj" "./halcogen_vcu/source/Device_TMS570LS12.obj" "./halcogen_vcu/source/Fapi_UserDefinedFunctions.obj" "./halcogen_vcu/source/adc.obj" "./halcogen_vcu/source/dabort.obj" "./halcogen_vcu/source/errata_SSWF021_45.obj" "./halcogen_vcu/source/esm.obj" "./halcogen_vcu/source/gio.obj" "./halcogen_vcu/source/het.obj" "./halcogen_vcu/source/i2c.obj" "./halcogen_vcu/source/mibspi.obj" "./halcogen_vcu/source/notification.obj" "./halcogen_vcu/source/os_croutine.obj" "./halcogen_vcu/source/os_event_groups.obj" "./halcogen_vcu/source/os_heap.obj" "./halcogen_vcu/source/os_list.obj" "./halcogen_vcu/source/os_mpu_wrappers.obj" "./halcogen_vcu/source/os_port.obj" "./halcogen_vcu/source/os_portasm.obj" "./halcogen_vcu/source/os_queue.obj" "./halcogen_vcu/source/os_tasks.obj" "./halcogen_vcu/source/os_timer.obj" "./halcogen_vcu/source/pinmux.obj" "./halcogen_vcu/source/rti.obj" "./halcogen_vcu/source/sci.obj" "./halcogen_vcu/source/sys_core.obj" "./halcogen_vcu/source/sys_dma.obj" "./halcogen_vcu/source/sys_intvecs.obj" "./halcogen_vcu/source/sys_mpu.obj" "./halcogen_vcu/source/sys_pcr.obj" "./halcogen_vcu/source/sys_phantom.obj" "./halcogen_vcu/source/sys_pmm.obj" "./halcogen_vcu/source/sys_pmu.obj" "./halcogen_vcu/source/sys_selftest.obj" "./halcogen_vcu/source/sys_startup.obj" "./halcogen_vcu/source/sys_vim.obj" "./halcogen_vcu/source/system.obj" "./halcogen_vcu/source/ti_fee_Info.obj" "./halcogen_vcu/source/ti_fee_cancel.obj" "./halcogen_vcu/source/ti_fee_cfg.obj" "./halcogen_vcu/source/ti_fee_eraseimmediateblock.obj" "./halcogen_vcu/source/ti_fee_format.obj" "./halcogen_vcu/source/ti_fee_ini.obj" "./halcogen_vcu/source/ti_fee_invalidateblock.obj" "./halcogen_vcu/source/ti_fee_main.obj" "./halcogen_vcu/source/ti_fee_read.obj" "./halcogen_vcu/source/ti_fee_readSync.obj" "./halcogen_vcu/source/ti_fee_shutdown.obj" "./halcogen_vcu/source/ti_fee_util.obj" "./halcogen_vcu/source/ti_fee_writeAsync.obj" "./halcogen_vcu/source/ti_fee_writeSync.obj" "../halcogen_launchpad/source/sys_link.cmd" "../halcogen_vcu/source/sys_linker_freeRTOS.cmd" -llibc.a
\ No newline at end of file
diff --git a/VCU/Debug/makefile b/VCU/Debug/makefile
index 89b6d6bf..66e41032 100644
--- a/VCU/Debug/makefile
+++ b/VCU/Debug/makefile
@@ -26,7 +26,7 @@ ORDERED_OBJS += \
"./Phantom/tasks/source/task_statemachine.obj" \
"./Phantom/tasks/source/task_test.obj" \
"./Phantom/tasks/source/task_throttle_actor.obj" \
-"./Phantom/tasks/source/task_throttle_agent.obj" \
+"./Phantom/tasks/source/task_pedal_readings.obj" \
"./Phantom/tasks/source/task_watchdog.obj" \
"./Phantom/test_eeprom/testEeprom.obj" \
"./halcogen_launchpad/source/Device_TMS570LS12.obj" \
@@ -298,12 +298,12 @@ VCU.hex: $(EXE_OUTPUTS)
# Other Targets
clean:
-$(RM) $(BIN_OUTPUTS__QUOTED)$(EXE_OUTPUTS__QUOTED)
- -$(RM) "Phantom\Drivers\DAC_SPI\MCP48FV_DAC_SPI.obj" "Phantom\Drivers\EEPROM\eeprom_driver.obj" "Phantom\Drivers\RGB_LED\RGB_LED.obj" "Phantom\Drivers\RTD_Buzzer\RTD_Buzzer.obj" "Phantom\Drivers\RTOS\phantom_queue.obj" "Phantom\Drivers\RTOS\phantom_task.obj" "Phantom\Drivers\RTOS\phantom_timer.obj" "Phantom\Drivers\UART\Phantom_sci.obj" "Phantom\data_structures\vcu_data.obj" "Phantom\main.obj" "Phantom\tasks\source\task_eeprom.obj" "Phantom\tasks\source\task_interrupt.obj" "Phantom\tasks\source\task_receive.obj" "Phantom\tasks\source\task_statemachine.obj" "Phantom\tasks\source\task_test.obj" "Phantom\tasks\source\task_throttle_actor.obj" "Phantom\tasks\source\task_throttle_agent.obj" "Phantom\tasks\source\task_watchdog.obj" "Phantom\test_eeprom\testEeprom.obj" "halcogen_launchpad\source\Device_TMS570LS12.obj" "halcogen_launchpad\source\Fapi_UserDefinedFunctions.obj" "halcogen_launchpad\source\adc.obj" "halcogen_launchpad\source\dabort.obj" "halcogen_launchpad\source\errata_SSWF021_45.obj" "halcogen_launchpad\source\esm.obj"
+ -$(RM) "Phantom\Drivers\DAC_SPI\MCP48FV_DAC_SPI.obj" "Phantom\Drivers\EEPROM\eeprom_driver.obj" "Phantom\Drivers\RGB_LED\RGB_LED.obj" "Phantom\Drivers\RTD_Buzzer\RTD_Buzzer.obj" "Phantom\Drivers\RTOS\phantom_queue.obj" "Phantom\Drivers\RTOS\phantom_task.obj" "Phantom\Drivers\RTOS\phantom_timer.obj" "Phantom\Drivers\UART\Phantom_sci.obj" "Phantom\data_structures\vcu_data.obj" "Phantom\main.obj" "Phantom\tasks\source\task_eeprom.obj" "Phantom\tasks\source\task_interrupt.obj" "Phantom\tasks\source\task_receive.obj" "Phantom\tasks\source\task_statemachine.obj" "Phantom\tasks\source\task_test.obj" "Phantom\tasks\source\task_throttle_actor.obj" "Phantom\tasks\source\task_pedal_readings.obj" "Phantom\tasks\source\task_watchdog.obj" "Phantom\test_eeprom\testEeprom.obj" "halcogen_launchpad\source\Device_TMS570LS12.obj" "halcogen_launchpad\source\Fapi_UserDefinedFunctions.obj" "halcogen_launchpad\source\adc.obj" "halcogen_launchpad\source\dabort.obj" "halcogen_launchpad\source\errata_SSWF021_45.obj" "halcogen_launchpad\source\esm.obj"
-$(RM) "halcogen_launchpad\source\gio.obj" "halcogen_launchpad\source\het.obj" "halcogen_launchpad\source\i2c.obj" "halcogen_launchpad\source\mibspi.obj" "halcogen_launchpad\source\notification.obj" "halcogen_launchpad\source\os_croutine.obj" "halcogen_launchpad\source\os_event_groups.obj" "halcogen_launchpad\source\os_heap.obj" "halcogen_launchpad\source\os_list.obj" "halcogen_launchpad\source\os_mpu_wrappers.obj" "halcogen_launchpad\source\os_port.obj" "halcogen_launchpad\source\os_portasm.obj" "halcogen_launchpad\source\os_queue.obj" "halcogen_launchpad\source\os_tasks.obj" "halcogen_launchpad\source\os_timer.obj" "halcogen_launchpad\source\pinmux.obj" "halcogen_launchpad\source\rti.obj" "halcogen_launchpad\source\sci.obj" "halcogen_launchpad\source\svc.obj" "halcogen_launchpad\source\sys_core.obj" "halcogen_launchpad\source\sys_dma.obj" "halcogen_launchpad\source\sys_intvecs.obj" "halcogen_launchpad\source\sys_main.obj" "halcogen_launchpad\source\sys_mpu.obj" "halcogen_launchpad\source\sys_pcr.obj"
-$(RM) "halcogen_launchpad\source\sys_phantom.obj" "halcogen_launchpad\source\sys_pmm.obj" "halcogen_launchpad\source\sys_pmu.obj" "halcogen_launchpad\source\sys_selftest.obj" "halcogen_launchpad\source\sys_startup.obj" "halcogen_launchpad\source\sys_vim.obj" "halcogen_launchpad\source\system.obj" "halcogen_launchpad\source\ti_fee_Info.obj" "halcogen_launchpad\source\ti_fee_cancel.obj" "halcogen_launchpad\source\ti_fee_cfg.obj" "halcogen_launchpad\source\ti_fee_eraseimmediateblock.obj" "halcogen_launchpad\source\ti_fee_format.obj" "halcogen_launchpad\source\ti_fee_ini.obj" "halcogen_launchpad\source\ti_fee_invalidateblock.obj" "halcogen_launchpad\source\ti_fee_main.obj" "halcogen_launchpad\source\ti_fee_read.obj" "halcogen_launchpad\source\ti_fee_readSync.obj" "halcogen_launchpad\source\ti_fee_shutdown.obj" "halcogen_launchpad\source\ti_fee_util.obj" "halcogen_launchpad\source\ti_fee_writeAsync.obj" "halcogen_launchpad\source\ti_fee_writeSync.obj" "halcogen_vcu\source\Device_TMS570LS12.obj" "halcogen_vcu\source\Fapi_UserDefinedFunctions.obj"
-$(RM) "halcogen_vcu\source\adc.obj" "halcogen_vcu\source\dabort.obj" "halcogen_vcu\source\errata_SSWF021_45.obj" "halcogen_vcu\source\esm.obj" "halcogen_vcu\source\gio.obj" "halcogen_vcu\source\het.obj" "halcogen_vcu\source\i2c.obj" "halcogen_vcu\source\mibspi.obj" "halcogen_vcu\source\notification.obj" "halcogen_vcu\source\os_croutine.obj" "halcogen_vcu\source\os_event_groups.obj" "halcogen_vcu\source\os_heap.obj" "halcogen_vcu\source\os_list.obj" "halcogen_vcu\source\os_mpu_wrappers.obj" "halcogen_vcu\source\os_port.obj" "halcogen_vcu\source\os_portasm.obj" "halcogen_vcu\source\os_queue.obj" "halcogen_vcu\source\os_tasks.obj" "halcogen_vcu\source\os_timer.obj" "halcogen_vcu\source\pinmux.obj" "halcogen_vcu\source\rti.obj" "halcogen_vcu\source\sci.obj" "halcogen_vcu\source\sys_core.obj" "halcogen_vcu\source\sys_dma.obj" "halcogen_vcu\source\sys_intvecs.obj" "halcogen_vcu\source\sys_mpu.obj" "halcogen_vcu\source\sys_pcr.obj" "halcogen_vcu\source\sys_phantom.obj" "halcogen_vcu\source\sys_pmm.obj"
-$(RM) "halcogen_vcu\source\sys_pmu.obj" "halcogen_vcu\source\sys_selftest.obj" "halcogen_vcu\source\sys_startup.obj" "halcogen_vcu\source\sys_vim.obj" "halcogen_vcu\source\system.obj" "halcogen_vcu\source\ti_fee_Info.obj" "halcogen_vcu\source\ti_fee_cancel.obj" "halcogen_vcu\source\ti_fee_cfg.obj" "halcogen_vcu\source\ti_fee_eraseimmediateblock.obj" "halcogen_vcu\source\ti_fee_format.obj" "halcogen_vcu\source\ti_fee_ini.obj" "halcogen_vcu\source\ti_fee_invalidateblock.obj" "halcogen_vcu\source\ti_fee_main.obj" "halcogen_vcu\source\ti_fee_read.obj" "halcogen_vcu\source\ti_fee_readSync.obj" "halcogen_vcu\source\ti_fee_shutdown.obj" "halcogen_vcu\source\ti_fee_util.obj" "halcogen_vcu\source\ti_fee_writeAsync.obj" "halcogen_vcu\source\ti_fee_writeSync.obj"
- -$(RM) "Phantom\Drivers\DAC_SPI\MCP48FV_DAC_SPI.d" "Phantom\Drivers\EEPROM\eeprom_driver.d" "Phantom\Drivers\RGB_LED\RGB_LED.d" "Phantom\Drivers\RTD_Buzzer\RTD_Buzzer.d" "Phantom\Drivers\RTOS\phantom_queue.d" "Phantom\Drivers\RTOS\phantom_task.d" "Phantom\Drivers\RTOS\phantom_timer.d" "Phantom\Drivers\UART\Phantom_sci.d" "Phantom\data_structures\vcu_data.d" "Phantom\main.d" "Phantom\tasks\source\task_eeprom.d" "Phantom\tasks\source\task_interrupt.d" "Phantom\tasks\source\task_receive.d" "Phantom\tasks\source\task_statemachine.d" "Phantom\tasks\source\task_test.d" "Phantom\tasks\source\task_throttle_actor.d" "Phantom\tasks\source\task_throttle_agent.d" "Phantom\tasks\source\task_watchdog.d" "Phantom\test_eeprom\testEeprom.d" "halcogen_launchpad\source\Device_TMS570LS12.d" "halcogen_launchpad\source\Fapi_UserDefinedFunctions.d" "halcogen_launchpad\source\adc.d" "halcogen_launchpad\source\errata_SSWF021_45.d" "halcogen_launchpad\source\esm.d" "halcogen_launchpad\source\gio.d" "halcogen_launchpad\source\het.d"
+ -$(RM) "Phantom\Drivers\DAC_SPI\MCP48FV_DAC_SPI.d" "Phantom\Drivers\EEPROM\eeprom_driver.d" "Phantom\Drivers\RGB_LED\RGB_LED.d" "Phantom\Drivers\RTD_Buzzer\RTD_Buzzer.d" "Phantom\Drivers\RTOS\phantom_queue.d" "Phantom\Drivers\RTOS\phantom_task.d" "Phantom\Drivers\RTOS\phantom_timer.d" "Phantom\Drivers\UART\Phantom_sci.d" "Phantom\data_structures\vcu_data.d" "Phantom\main.d" "Phantom\tasks\source\task_eeprom.d" "Phantom\tasks\source\task_interrupt.d" "Phantom\tasks\source\task_receive.d" "Phantom\tasks\source\task_statemachine.d" "Phantom\tasks\source\task_test.d" "Phantom\tasks\source\task_throttle_actor.d" "Phantom\tasks\source\task_pedal_readings.d" "Phantom\tasks\source\task_watchdog.d" "Phantom\test_eeprom\testEeprom.d" "halcogen_launchpad\source\Device_TMS570LS12.d" "halcogen_launchpad\source\Fapi_UserDefinedFunctions.d" "halcogen_launchpad\source\adc.d" "halcogen_launchpad\source\errata_SSWF021_45.d" "halcogen_launchpad\source\esm.d" "halcogen_launchpad\source\gio.d" "halcogen_launchpad\source\het.d"
-$(RM) "halcogen_launchpad\source\i2c.d" "halcogen_launchpad\source\mibspi.d" "halcogen_launchpad\source\notification.d" "halcogen_launchpad\source\os_croutine.d" "halcogen_launchpad\source\os_event_groups.d" "halcogen_launchpad\source\os_heap.d" "halcogen_launchpad\source\os_list.d" "halcogen_launchpad\source\os_mpu_wrappers.d" "halcogen_launchpad\source\os_port.d" "halcogen_launchpad\source\os_queue.d" "halcogen_launchpad\source\os_tasks.d" "halcogen_launchpad\source\os_timer.d" "halcogen_launchpad\source\pinmux.d" "halcogen_launchpad\source\rti.d" "halcogen_launchpad\source\sci.d" "halcogen_launchpad\source\sys_dma.d" "halcogen_launchpad\source\sys_main.d" "halcogen_launchpad\source\sys_pcr.d" "halcogen_launchpad\source\sys_phantom.d" "halcogen_launchpad\source\sys_pmm.d" "halcogen_launchpad\source\sys_selftest.d" "halcogen_launchpad\source\sys_startup.d" "halcogen_launchpad\source\sys_vim.d" "halcogen_launchpad\source\system.d" "halcogen_launchpad\source\ti_fee_Info.d" "halcogen_launchpad\source\ti_fee_cancel.d"
-$(RM) "halcogen_launchpad\source\ti_fee_cfg.d" "halcogen_launchpad\source\ti_fee_eraseimmediateblock.d" "halcogen_launchpad\source\ti_fee_format.d" "halcogen_launchpad\source\ti_fee_ini.d" "halcogen_launchpad\source\ti_fee_invalidateblock.d" "halcogen_launchpad\source\ti_fee_main.d" "halcogen_launchpad\source\ti_fee_read.d" "halcogen_launchpad\source\ti_fee_readSync.d" "halcogen_launchpad\source\ti_fee_shutdown.d" "halcogen_launchpad\source\ti_fee_util.d" "halcogen_launchpad\source\ti_fee_writeAsync.d" "halcogen_launchpad\source\ti_fee_writeSync.d" "halcogen_vcu\source\Device_TMS570LS12.d" "halcogen_vcu\source\Fapi_UserDefinedFunctions.d" "halcogen_vcu\source\adc.d" "halcogen_vcu\source\errata_SSWF021_45.d" "halcogen_vcu\source\esm.d" "halcogen_vcu\source\gio.d" "halcogen_vcu\source\het.d" "halcogen_vcu\source\i2c.d" "halcogen_vcu\source\mibspi.d" "halcogen_vcu\source\notification.d" "halcogen_vcu\source\os_croutine.d" "halcogen_vcu\source\os_event_groups.d" "halcogen_vcu\source\os_heap.d" "halcogen_vcu\source\os_list.d"
-$(RM) "halcogen_vcu\source\os_mpu_wrappers.d" "halcogen_vcu\source\os_port.d" "halcogen_vcu\source\os_queue.d" "halcogen_vcu\source\os_tasks.d" "halcogen_vcu\source\os_timer.d" "halcogen_vcu\source\pinmux.d" "halcogen_vcu\source\rti.d" "halcogen_vcu\source\sci.d" "halcogen_vcu\source\sys_dma.d" "halcogen_vcu\source\sys_pcr.d" "halcogen_vcu\source\sys_phantom.d" "halcogen_vcu\source\sys_pmm.d" "halcogen_vcu\source\sys_selftest.d" "halcogen_vcu\source\sys_startup.d" "halcogen_vcu\source\sys_vim.d" "halcogen_vcu\source\system.d" "halcogen_vcu\source\ti_fee_Info.d" "halcogen_vcu\source\ti_fee_cancel.d" "halcogen_vcu\source\ti_fee_cfg.d" "halcogen_vcu\source\ti_fee_eraseimmediateblock.d" "halcogen_vcu\source\ti_fee_format.d" "halcogen_vcu\source\ti_fee_ini.d" "halcogen_vcu\source\ti_fee_invalidateblock.d" "halcogen_vcu\source\ti_fee_main.d" "halcogen_vcu\source\ti_fee_read.d" "halcogen_vcu\source\ti_fee_readSync.d" "halcogen_vcu\source\ti_fee_shutdown.d" "halcogen_vcu\source\ti_fee_util.d" "halcogen_vcu\source\ti_fee_writeAsync.d"
diff --git a/VCU/Phantom/Drivers/RTOS/phantom_queue.c b/VCU/Phantom/Drivers/RTOS/phantom_queue.c
deleted file mode 100644
index 9c572ea5..00000000
--- a/VCU/Phantom/Drivers/RTOS/phantom_queue.c
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * phantom_queue.h
- *
- * Created on: July 15, 2022
- * Author: Josh Guo
- *
- * Light-weight wrapper for freertos queue API
- */
-
-#include "phantom_queue.h"
-
-QueueHandle_t Phantom_createQueue(UBaseType_t queue_length, UBaseType_t item_size)
-{
- QueueHandle_t qHandle = xQueueCreate(queue_length, item_size);
- return qHandle;
-}
-
-QueueSetHandle_t Phantom_createQueueSet(UBaseType_t combined_queue_size)
-{
- QueueSetHandle_t qSetHandle = xQueueCreateSet(combined_queue_size);
- return qSetHandle;
-}
-
-void Phantom_addToQueueSet(QueueSetHandle_t queue_set_handle, QueueHandle_t queue_handle)
-{
- BaseType_t result = xQueueAddToSet(queue_handle, queue_set_handle);
-}
diff --git a/VCU/Phantom/Drivers/RTOS/phantom_queue.h b/VCU/Phantom/Drivers/RTOS/phantom_queue.h
deleted file mode 100644
index 28a5caea..00000000
--- a/VCU/Phantom/Drivers/RTOS/phantom_queue.h
+++ /dev/null
@@ -1,50 +0,0 @@
-#ifndef PHANTOM_QUEUE_H_
-#define PHANTOM_QUEUE_H_
-
-/*
- * phantom_queue.h
- *
- * Created on: July 15, 2022
- * Author: Josh Guo
- *
- * Light-weight wrapper for freertos queue API
- */
-
-#include "FreeRTOS.h"
-#include "FreeRTOSConfig.h"
-#include "os_queue.h"
-
-QueueHandle_t Phantom_createQueue(UBaseType_t queue_length, UBaseType_t item_size);
-QueueSetHandle_t Phantom_createQueueSet(UBaseType_t combined_queue_size);
-void Phantom_addToQueueSet(QueueSetHandle_t queue_set_handle, QueueHandle_t queue_handle);
-
-#define Phantom_createMailBox(item_size) Phantom_createQueue(1, (item_size))
-#define Phantom_overwrite xQueueOverwrite
-#define Phantom_overwriteISR xQueueOverwriteFromISR
-
-#define Phantom_queueSize(queue_handle) (uxQueueMessagesWaiting(queue_handle) + uxQueueSpacesAvailable(queue_handle))
-#define Phantom_queueSizeISR(queue_handle) (uxQueueMessagesWaitingFromISR(queue_handle) + uxQueueSpacesAvailable(queue_handle))
-
-#define Phantom_isQueueEmptyISR xQueueIsQueueEmptyFromISR
-#define Phantom_isQueueFullISR xQueueIsQueueFullFromISR
-#define Phantom_itemsInQueue uxQueueMessagesWaiting
-#define Phantom_itemsInQueueISR uxQueueMessagesWaitingFromISR
-#define Phantom_spaceInQueue uxQueueSpacesAvailable
-
-#define Phantom_peek(queue_handle, buffer_ptr, wait_time_ms) xQueuePeek((queue_handle), (buffer_ptr), pdMS_TO_TICKS(wait_time_ms))
-#define Phantom_peekISR xQueuePeekFromISR
-
-#define Phantom_send(queue_handle, item_ptr, wait_time_ms) xQueueSendToBack((queue_handle), (item_ptr), pdMS_TO_TICKS(wait_time_ms))
-#define Phantom_sendISR(queue_handle, item_ptr, WokenHigherPriorityTask) xQueueSendFromISR((queue_handle), (item_ptr), WokenHigherPriorityTask)
-#define Phantom_sendFront(queue_handle, item_ptr, wait_time_ms) xQueueSendToFront((queue_handle), (item_ptr), pdMS_TO_TICKS(wait_time_ms))
-#define Phantom_sendFrontISR(queue_handle, item_ptr, WokenHigherPriorityTask)
-
-#define Phantom_receive(queue_handle, buffer_ptr, wait_time_ms) xQueueReceive((queue_handle), (buffer_ptr), pdMS_TO_TICKS(wait_time_ms))
-#define Phantom_receiveISR xQueueReceiveFromISR
-
-#define Phantom_resetQueue xQueueReset
-
-#define Phantom_selectFromQueueSet(qset_handle, wait_time_ms) xQueueSelectFromSet((qset_handle), pdMS_TO_TICKS(wait_time_ms))
-#define Phantom_selectFromQueueSetISR xQueueSelectFromSetFromISR
-
-#endif
diff --git a/VCU/Phantom/Drivers/RTOS/phantom_task.c b/VCU/Phantom/Drivers/RTOS/phantom_task.c
deleted file mode 100644
index e3758920..00000000
--- a/VCU/Phantom/Drivers/RTOS/phantom_task.c
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * phantom_task.c
- *
- * Created on: Aug. 25, 2021
- * Author: Josh Guo
- */
-#include "sys_common.h"
-#include "FreeRTOS.h"
-#include "FreeRTOSConfig.h"
-#include "os_task.h"
-
-#include "phantom_task.h"
-
-static void periodicTaskSkeleton(void* task);
-static void continuousTaskSkeleton(void* task);
-
-TaskHandle_t Phantom_createTask(Task* task,
- char* const taskName,
- uint16 stackSize,
- uint32 taskPriority)
-{
- TaskHandle_t taskHandle = NULL;
-
- TaskFunction_t taskSkeleton = periodicTaskSkeleton;
- if (task->frequencyMs == 0) {
- taskSkeleton = continuousTaskSkeleton;
- }
-
- xTaskCreate(taskSkeleton, taskName, stackSize, task, taskPriority, &taskHandle);
-
- return taskHandle;
-}
-
-void Phantom_startTaskScheduler(void)
-{
- vTaskStartScheduler();
-}
-
-void Phantom_endTaskScheduler(void)
-{
- vTaskEndScheduler();
-}
-
-void Phantom_suspendTask(TaskHandle_t taskHandle)
-{
- vTaskSuspend(taskHandle);
-}
-
-void Phantom_resumeTask(TaskHandle_t taskHandle)
-{
- vTaskResume(taskHandle);
-}
-
-static void periodicTaskSkeleton(void* task)
-{
- const TaskFunction_t taskFnPtr = ((Task*) task)->functionPtr;
- const TickType_t xFrequency = pdMS_TO_TICKS(((Task*) task)->frequencyMs);
-
- TickType_t xLastWakeTime = xTaskGetTickCount();
- while (1) {
- vTaskDelayUntil(&xLastWakeTime, xFrequency);
-
- taskFnPtr(NULL);
- }
-}
-
-static void continuousTaskSkeleton(void* task)
-{
- const TaskFunction_t taskFnPtr = ((Task*) task)->functionPtr;
-
- while (1) {
- taskFnPtr(NULL);
- }
-}
diff --git a/VCU/Phantom/Drivers/RTOS/phantom_task.h b/VCU/Phantom/Drivers/RTOS/phantom_task.h
deleted file mode 100644
index 7651226d..00000000
--- a/VCU/Phantom/Drivers/RTOS/phantom_task.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * phantom_task.h
- *
- * Created on: Aug. 25, 2021
- * Author: Josh Guo
- */
-#ifndef PHANTOM_TASK_H_
-#define PHANTOM_TASK_H_
-
-#include "hal_stdtypes.h"
-#include "os_projdefs.h"
-
-typedef void* TaskHandle_t;
-
-typedef struct {
- TaskFunction_t functionPtr;
- uint32 frequencyMs;
-} Task;
-
-TaskHandle_t Phantom_createTask(Task* task, char* const taskName, uint16 stackSize, uint32 taskPriority);
-
-/* Phantom_startTaskScheduler is Blocking */
-void Phantom_startTaskScheduler(void);
-void Phantom_endTaskScheduler(void);
-
-#endif
-
diff --git a/VCU/Phantom/Drivers/RTOS/phantom_timer.c b/VCU/Phantom/Drivers/RTOS/phantom_timer.c
index cfcd983e..ae4aa027 100644
--- a/VCU/Phantom/Drivers/RTOS/phantom_timer.c
+++ b/VCU/Phantom/Drivers/RTOS/phantom_timer.c
@@ -4,14 +4,11 @@
* Created on: Aug. 25, 2021
* Author: Josh Guo
*/
-#include "FreeRTOS.h"
-#include "FreeRTOSConfig.h"
-// this needs to be here because os_timer.h does not include this despite trying to reference it
-typedef void *TaskHandle_t;
-#include "os_timer.h"
#include "phantom_timer.h"
+#include "task_logger.h"
+#include "state_machine.h"
// #define DEBUG // uncomment this line for ASSERT statements to work
@@ -23,13 +20,13 @@ static int numOfTimers = 0;
timerName: Just a text name, not used by the RTOS kernel.
periodMS: The timer period in ticks, must be greater than 0.
isAutoReloading: If true, the timer will auto-reload itself when they expire.
- counterPtr: Pointer to a number which increments whenever the timer expires, initialized to 0.
+ timerID: Pointer to a number which increments whenever the timer expires, initialized to 0.
callbackFunction: Callback function that is called when the timer expires.
*/
TimerHandle_t Phantom_createTimer(char* const timerName,
uint32 periodMS,
bool isAutoReloading,
- void* counterPtr,
+ TimerID_t timerID,
TimerCallbackFunction_t callbackFunction)
{
if (numOfTimers >= MAX_NUMBER_OF_TIMERS) {
@@ -40,7 +37,7 @@ TimerHandle_t Phantom_createTimer(char* const timerName,
timerName,
pdMS_TO_TICKS(periodMS),
isAutoReloading,
- counterPtr,
+ (void*)timerID,
callbackFunction
);
@@ -48,14 +45,24 @@ TimerHandle_t Phantom_createTimer(char* const timerName,
return newTimer;
}
-uint8 Phantom_startTimer(TimerHandle_t timer, uint32 waitTimeMs)
+static uint8 LogTimerInfo(TimerHandle_t timer, char* str)
{
- return xTimerStart(timer, pdMS_TO_TICKS(waitTimeMs));
+ char buffer[32];
+ snprintf(buffer, 32, "(%s) %s", pcTimerGetName(timer), str);
+
+ return Log(buffer);
}
uint8 Phantom_stopTimer(TimerHandle_t timer, uint32 waitTimeMs)
{
- return xTimerStop(timer, pdMS_TO_TICKS(waitTimeMs));
+ uint8_t ret = xTimerStop(timer, pdMS_TO_TICKS(waitTimeMs)) == pdPASS;
+
+ if (!ret)
+ {
+ LogTimerInfo(timer, "Failed to stop timer");
+ }
+
+ return ret;
}
uint8 Phantom_deleteTimer(TimerHandle_t timer, uint32 waitTimeMs)
@@ -72,5 +79,26 @@ int Phantom_getNumberOfTimers(void)
bool Phantom_isTimerActive(TimerHandle_t timer)
{
- return xTimerIsTimerActive(timer);
+ uint8_t ret = xTimerIsTimerActive(timer) == pdPASS;
+
+ return ret;
+}
+
+uint8 Phantom_startTimer(TimerHandle_t timer, uint32 waitTimeMs)
+{
+ uint8_t started = true;
+
+ if (!Phantom_isTimerActive(timer))
+ {
+ started = xTimerStart(timer, pdMS_TO_TICKS(waitTimeMs)) != pdFALSE;
+ }
+
+
+ if (!started)
+ {
+ LogTimerInfo(timer, "Timer not started");
+ }
+
+ return started;
+
}
diff --git a/VCU/Phantom/Drivers/RTOS/phantom_timer.h b/VCU/Phantom/Drivers/RTOS/phantom_timer.h
index 20b1f281..1f04a412 100644
--- a/VCU/Phantom/Drivers/RTOS/phantom_timer.h
+++ b/VCU/Phantom/Drivers/RTOS/phantom_timer.h
@@ -7,16 +7,17 @@
#ifndef PHANTOM_TIMER_H_
#define PHANTOM_TIMER_H_
-#include "hal_stdtypes.h"
+#include "vcu_common.h"
-#define MAX_WAIT_TIME_MS (((uint32_t) ~0) >> 10)
+#include "hal_stdtypes.h"
-typedef void *TimerHandle_t;
-typedef void (*TimerCallbackFunction_t)(TimerHandle_t xTimer);
+#include "os_timer.h"
#define AUTO_RELOAD true
#define NO_RELOAD false
+typedef uint16_t TimerID_t;
+
/*
timerName: Just a text name, not used by the RTOS kernel.
periodMS: The timer period in ticks, must be greater than 0.
@@ -27,7 +28,7 @@ typedef void (*TimerCallbackFunction_t)(TimerHandle_t xTimer);
TimerHandle_t Phantom_createTimer(char* const timerName,
uint32 periodMS,
bool isAutoReloading,
- void* counterPtr,
+ TimerID_t timerID,
TimerCallbackFunction_t callbackFunction);
uint8 Phantom_startTimer(TimerHandle_t timer, uint32 waitTimeMs);
diff --git a/VCU/Phantom/Drivers/STATE_MACHINE/state_machine.c b/VCU/Phantom/Drivers/STATE_MACHINE/state_machine.c
new file mode 100644
index 00000000..841bee66
--- /dev/null
+++ b/VCU/Phantom/Drivers/STATE_MACHINE/state_machine.c
@@ -0,0 +1,190 @@
+/*
+ * state_machine.c
+ *
+ * Created on: Feb 12, 2023
+ * Author: rafgu
+ */
+
+#include "state_machine.h"
+
+/* Phantom modules */
+#include "ansi_colors.h"
+
+/* Phantom tasks */
+#include "task_event_handler.h"
+#include "task_throttle.h"
+#include "task_logger.h"
+
+static void UpdateStateMachine(void* data);
+static State VariousStates(State state, eCarEvents event);
+static State TractiveOff(eCarEvents event);
+static State TractiveOn(eCarEvents event);
+static State Running(eCarEvents event);
+static State SevereFault(eCarEvents event);
+
+
+static SystemTasks_t system_tasks;
+
+
+/* Public API */
+
+void StateMachineInit(SystemTasks_t tasks)
+{
+ system_tasks.PedalReadings = tasks.PedalReadings;
+ system_tasks.Throttle = tasks.Throttle;
+ system_tasks.EventHandler = tasks.EventHandler;
+ system_tasks.Logger = tasks.Logger;
+}
+
+void NotifyStateMachine(eCarEvents event)
+{
+ HandleEvent(UpdateStateMachine, event);
+}
+
+void NotifyStateMachineFromISR(eCarEvents event)
+{
+ HandleEventFromISR(UpdateStateMachine, event);
+}
+
+void NotifyStateMachineFromTimer(TimerHandle_t timer)
+{
+ TimerID_t event = (TimerID_t)pvTimerGetTimerID(timer);
+
+ static char buffer[64];
+ snprintf(buffer, 64, "(%s:%d): Expired after %dms", pcTimerGetTimerName(timer), event, xTimerGetPeriod(timer));
+ LogColor(YEL, buffer);
+
+ HandleEvent(UpdateStateMachine, event);
+}
+
+
+/* Internal implementation */
+
+/* Event callback */
+static void UpdateStateMachine(void* data)
+{
+ #ifdef VCU_SIM_MODE
+ LogColor(YEL, "VCU is in Simulation Mode. Events do not affect the state machine.");
+ return;
+ #endif
+
+ /* static cached values */
+ static State state = TRACTIVE_OFF;
+
+ eCarEvents event = *(uint16_t*) data;
+
+ /* Events that have an effect on multiple states */
+ State new_state = VariousStates(state, event);
+
+ // no state change occurred; let's try normal state specific events
+ if (new_state == state)
+ {
+ switch(state)
+ {
+ case TRACTIVE_OFF:
+
+ new_state = TractiveOff(event);
+
+ break;
+
+ case TRACTIVE_ON:
+
+ new_state = TractiveOn(event);
+
+ break;
+
+ case RUNNING:
+
+ new_state = Running(event);
+
+ break;
+
+ case SEVERE_FAULT:
+
+ new_state = SevereFault(event);
+
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ // update state
+ state = new_state;
+}
+
+
+/* State handlers */
+
+static State VariousStates(State state, eCarEvents event)
+{
+ bool faults = any(6,
+ event == EVENT_APPS1_RANGE_FAULT,
+ event == EVENT_APPS2_RANGE_FAULT,
+ event == EVENT_BRAKE_PLAUSIBILITY_FAULT,
+ event == EVENT_BSE_RANGE_FAULT,
+ event == EVENT_FP_DIFF_FAULT,
+ event == EVENT_UNRESPONSIVE_APPS
+ );
+
+ if (faults && state != SEVERE_FAULT)
+ {
+ SuspendThrottle(system_tasks.Throttle);
+
+ LogColor(RED, "Moving to SevereFault state");
+
+ FlushLogger(20); // highly likely a lot of events happened. No rush since we 've already done everything. Let's log
+
+ return SEVERE_FAULT;
+ }
+
+ return state;
+}
+
+static State TractiveOff(eCarEvents event)
+{
+ if (event == EVENT_TRACTIVE_ON)
+ {
+ LogColor(BLU, "Moving from TractiveOff to TractiveOn");
+ return TRACTIVE_ON;
+ }
+
+ return TRACTIVE_OFF;
+}
+
+static State TractiveOn(eCarEvents event)
+{
+ if (event == EVENT_READY_TO_DRIVE)
+ {
+ LogColor(GRN, "Moving from TractiveOn to Running");
+
+ LogColor(GRN, "Resuming throttle task.");
+ vTaskResume(system_tasks.Throttle);
+
+ return RUNNING;
+ }
+
+ return TRACTIVE_ON;
+}
+
+static State Running(eCarEvents event)
+{
+ if (false)
+ {
+ // ...
+ }
+
+ return RUNNING;
+}
+
+static State SevereFault(eCarEvents event)
+{
+ if (event == EVENT_RESET_CAR)
+ {
+ LogColor(CYN, "Moving from SevereFault to TractiveOff");
+ return TRACTIVE_OFF;
+ }
+
+ return SEVERE_FAULT;
+}
diff --git a/VCU/Phantom/Drivers/STATE_MACHINE/state_machine.h b/VCU/Phantom/Drivers/STATE_MACHINE/state_machine.h
new file mode 100644
index 00000000..73878e59
--- /dev/null
+++ b/VCU/Phantom/Drivers/STATE_MACHINE/state_machine.h
@@ -0,0 +1,23 @@
+/*
+ * state_machine.h
+ *
+ * Created on: Feb 12, 2023
+ * Author: rafgu
+ */
+
+#ifndef PHANTOM_DRIVERS_STATE_MACHINE_STATE_MACHINE_H_
+#define PHANTOM_DRIVERS_STATE_MACHINE_STATE_MACHINE_H_
+
+#include "vcu_common.h"
+#include "phantom_timer.h"
+
+
+void StateMachineInit(SystemTasks_t tasks);
+
+void NotifyStateMachine(eCarEvents event);
+void NotifyStateMachineFromISR(eCarEvents event);
+void NotifyStateMachineFromTimer(TimerHandle_t timer);
+
+
+#endif /* PHANTOM_DRIVERS_STATE_MACHINE_STATE_MACHINE_H_ */
+
diff --git a/VCU/Phantom/Drivers/UART/Phantom_sci.c b/VCU/Phantom/Drivers/UART/Phantom_sci.c
index 9b71fb28..4798b574 100644
--- a/VCU/Phantom/Drivers/UART/Phantom_sci.c
+++ b/VCU/Phantom/Drivers/UART/Phantom_sci.c
@@ -10,23 +10,27 @@
#include "FreeRTOS.h"
#include "os_task.h"
+#include "task_logger.h"
+#include "task_event_handler.h"
+#include "state_machine.h"
#define NUMBER_OF_SIMULATION_MESSAGES 3
static volatile uint8_t messageCounter = 0;
static volatile uint32_t serialData = 0; // there is 24 bit standard type so when we cast, we have to cast to 32 bit hence 4 bytes
-extern volatile unsigned long ulHighFrequencyTimerTicks;
-static char ptrTaskList[500];
+#define TASK_LIST_SIZE 512
enum eCommands{
-
ECHO_THROTTLE='1',
ECHO_APPS1='2',
ECHO_APPS2='3',
ECHO_BSE='4',
STAT_RUN='5', // vTaskGetRunTimeStats
STAT_START='6', // xTaskGetTickCount
- TASK_LIST='7'// vTaskList
+ TASK_LIST='7', // vTaskList
+ RESET_CAR='r',
+ START_ENGINE='s',
+ TURN_TRACTIVE_ON='o',
};
@@ -90,7 +94,6 @@ void UARTprintln(const char *_format, ...)
}
}
-
uint32_t getSimData()
{
while(messageCounter < NUMBER_OF_SIMULATION_MESSAGES);
@@ -106,6 +109,19 @@ uint32_t getSimData()
return ret;
}
+void GetRuntimeStatistics(void* x)
+{
+ // TODO: not configured!
+ // vTaskGetRunTimeStats(ptrTaskList);
+
+ char ptrTaskList[TASK_LIST_SIZE];
+ vTaskList(ptrTaskList);
+
+ UARTprintln("\n");
+ UARTSend(PC_UART, ptrTaskList);
+ UARTprintln("\r");
+}
+
void sciReceiveCallback(sciBASE_t *sci, uint32 flags, uint8 data)
{
@@ -118,41 +134,58 @@ void sciReceiveCallback(sciBASE_t *sci, uint32 flags, uint8 data)
}
#else
+ char buffer[16];
+
switch(data){
case TASK_LIST:
-
- // TODO: use interrupt task (this aborts because it's too many chars to send in an IRQ)
- // vTaskGetRunTimeStats(ptrTaskList);
- // UARTSend(PC_UART, ptrTaskList);
- // vTaskList(ptrTaskList);
- // UARTSend(PC_UART, ptrTaskList);
-
+ HandleEventFromISR(GetRuntimeStatistics, 0);
break;
+
case ECHO_THROTTLE:
- UARTSend(PC_UART, "No data available yet.");
- UARTSend(PC_UART, "\r");
+ LogFromISR(UWHT, "No data available yet.");
+
break;
case ECHO_APPS1:
- UARTSend(PC_UART, "No data available yet.");
- UARTSend(PC_UART, "\r");
+ LogFromISR(UWHT, "No data available yet.");
break;
case ECHO_APPS2:
- UARTSend(PC_UART, "No data available yet.");
- UARTSend(PC_UART, "\r");
+ LogFromISR(UWHT, "No data available yet.");
break;
case ECHO_BSE:
- UARTSend(PC_UART, "No data available yet.");
- UARTSend(PC_UART, "\r");
+ LogFromISR(UWHT, "No data available yet.");
break;
case STAT_START:
- UARTprintf("%d", xTaskGetTickCount());
- UARTSend(PC_UART, "\r");
+ {
+ snprintf(buffer, 16, "%dms", xTaskGetTickCountFromISR());
+
+ LogFromISR(UWHT, buffer);
+ break;
+ }
+ case TURN_TRACTIVE_ON:
+ {
+ NotifyStateMachineFromISR(EVENT_TRACTIVE_ON);
+
break;
+ }
+ case START_ENGINE:
+ {
+ NotifyStateMachineFromISR(EVENT_READY_TO_DRIVE);
+
+ break;
+ }
+ case RESET_CAR:
+ {
+ NotifyStateMachineFromISR(EVENT_RESET_CAR);
+
+ break;
+ }
default:
- UARTprintln("Unknown command: %c", data);
- putchar(data);
+ {
+ LogFromISR(UWHT, "Unknown: ");
+
break;
+ }
}
#endif
diff --git a/VCU/Phantom/Drivers/UART/Phantom_sci.h b/VCU/Phantom/Drivers/UART/Phantom_sci.h
index 06445850..6a83ebc0 100644
--- a/VCU/Phantom/Drivers/UART/Phantom_sci.h
+++ b/VCU/Phantom/Drivers/UART/Phantom_sci.h
@@ -14,14 +14,11 @@
extern "C" {
#endif
-#define START_SIM_DATA 's'
-#define END_SIM_DATA '\n'
-
void UARTInit(sciBASE_t *sci, uint32 baud);
void UARTSend(sciBASE_t *sci, char data[]);
void UARTprintf(const char *_format, ...);
void UARTprintln(const char *_format, ...);
-void split(char* str, const char* delimeter, char* buffer, int buffer_size);
+
void sciReceiveCallback(sciBASE_t *sci, uint32 flags, uint8 data);
uint32_t getSimData();
diff --git a/VCU/Phantom/data_structures/ansi_colors.h b/VCU/Phantom/data_structures/ansi_colors.h
new file mode 100644
index 00000000..106865c3
--- /dev/null
+++ b/VCU/Phantom/data_structures/ansi_colors.h
@@ -0,0 +1,88 @@
+/*
+ * This is free and unencumbered software released into the public domain.
+ *
+ * For more information, please refer to
+ */
+
+#ifndef PHANTOM_DATA_STRUCTURES_ANSI_COLORS_H_
+#define PHANTOM_DATA_STRUCTURES_ANSI_COLORS_H_
+
+//Regular text
+#define BLK "\e[0;30m"
+#define RED "\e[0;31m"
+#define GRN "\e[0;32m"
+#define YEL "\e[0;33m"
+#define BLU "\e[0;34m"
+#define MAG "\e[0;35m"
+#define CYN "\e[0;36m"
+#define WHT "\e[0;37m"
+
+//Regular bold text
+#define BBLK "\e[1;30m"
+#define BRED "\e[1;31m"
+#define BGRN "\e[1;32m"
+#define BYEL "\e[1;33m"
+#define BBLU "\e[1;34m"
+#define BMAG "\e[1;35m"
+#define BCYN "\e[1;36m"
+#define BWHT "\e[1;37m"
+
+//Regular underline text
+#define UBLK "\e[4;30m"
+#define URED "\e[4;31m"
+#define UGRN "\e[4;32m"
+#define UYEL "\e[4;33m"
+#define UBLU "\e[4;34m"
+#define UMAG "\e[4;35m"
+#define UCYN "\e[4;36m"
+#define UWHT "\e[4;37m"
+
+//Regular background
+#define BLKB "\e[40m"
+#define REDB "\e[41m"
+#define GRNB "\e[42m"
+#define YELB "\e[43m"
+#define BLUB "\e[44m"
+#define MAGB "\e[45m"
+#define CYNB "\e[46m"
+#define WHTB "\e[47m"
+
+//High intensty background
+#define BLKHB "\e[0;100m"
+#define REDHB "\e[0;101m"
+#define GRNHB "\e[0;102m"
+#define YELHB "\e[0;103m"
+#define BLUHB "\e[0;104m"
+#define MAGHB "\e[0;105m"
+#define CYNHB "\e[0;106m"
+#define WHTHB "\e[0;107m"
+
+//High intensty text
+#define HBLK "\e[0;90m"
+#define HRED "\e[0;91m"
+#define HGRN "\e[0;92m"
+#define HYEL "\e[0;93m"
+#define HBLU "\e[0;94m"
+#define HMAG "\e[0;95m"
+#define HCYN "\e[0;96m"
+#define HWHT "\e[0;97m"
+
+//Bold high intensity text
+#define BHBLK "\e[1;90m"
+#define BHRED "\e[1;91m"
+#define BHGRN "\e[1;92m"
+#define BHYEL "\e[1;93m"
+#define BHBLU "\e[1;94m"
+#define BHMAG "\e[1;95m"
+#define BHCYN "\e[1;96m"
+#define BHWHT "\e[1;97m"
+
+//Reset
+#define reset "\e[0m"
+#define CRESET "\e[0m"
+#define COLOR_RESET "\e[0m"
+
+
+
+
+#endif /* PHANTOM_DATA_STRUCTURES_ANSI_COLORS_H_ */
diff --git a/VCU/Phantom/data_structures/vcu_common.c b/VCU/Phantom/data_structures/vcu_common.c
new file mode 100644
index 00000000..f5fa9773
--- /dev/null
+++ b/VCU/Phantom/data_structures/vcu_common.c
@@ -0,0 +1,45 @@
+/*
+ * vcu_common.c
+ *
+ * Created on: Feb 13, 2023
+ * Author: rafgu
+ */
+
+#include "vcu_common.h"
+#include "Phantom_sci.h"
+
+bool any(uint8_t num, ...)
+{
+ va_list valist;
+ bool result = 0;
+
+ va_start(valist, num);
+
+ int i;
+ for (i = 0; i < num; i++)
+ {
+ result = result || va_arg(valist, int);
+ }
+
+ va_end(valist);
+
+ return result;
+}
+
+bool all(uint8_t num, ...)
+{
+ va_list valist;
+ bool result = 1;
+
+ va_start(valist, num);
+
+ int i;
+ for (i = 0; i < num; i++)
+ {
+ result = result && va_arg(valist, int);
+ }
+
+ va_end(valist);
+
+ return result;
+}
diff --git a/VCU/Phantom/data_structures/vcu_common.h b/VCU/Phantom/data_structures/vcu_common.h
index 571bd15a..d27cf31f 100644
--- a/VCU/Phantom/data_structures/vcu_common.h
+++ b/VCU/Phantom/data_structures/vcu_common.h
@@ -1,9 +1,47 @@
#ifndef _PHANTOM_VCU_COMMON_DEFINES_H_
#define _PHANTOM_VCU_COMMON_DEFINES_H_
-#include "phantom_task.h"
#include "FreeRTOS.h"
+#include "FreeRTOSConfig.h"
#include "os_queue.h"
+#include "os_task.h"
+#include "task_config.h"
+
+#include "stdarg.h"
+#include "hal_stdtypes.h"
+
+
+bool any(uint8_t num, ...);
+bool all(uint8_t num, ...);
+
+typedef struct SystemTasks_t{
+ TaskHandle_t PedalReadings;
+ TaskHandle_t Throttle;
+ TaskHandle_t Logger;
+ TaskHandle_t EventHandler;
+}SystemTasks_t;
+
+typedef enum eCarEvents{
+ BEGIN_OF_EVENTS=0,
+
+ EVENT_APPS1_RANGE_FAULT,
+ EVENT_APPS2_RANGE_FAULT,
+ EVENT_BSE_RANGE_FAULT,
+ EVENT_FP_DIFF_FAULT,
+ EVENT_RESET_CAR,
+ EVENT_READY_TO_DRIVE,
+ EVENT_TRACTIVE_ON,
+ EVENT_TRACTIVE_OFF,
+ EVENT_BRAKE_PLAUSIBILITY_CLEARED,
+ EVENT_BRAKE_PLAUSIBILITY_FAULT,
+ EVENT_UNRESPONSIVE_APPS,
+
+ END_OF_EVENTS
+} eCarEvents;
+typedef enum eSource{
+ FROM_ISR,
+ FROM_SCHEDULER
+} eSource;
/**
* @brief Machine states for the VCU.
@@ -37,6 +75,11 @@ typedef struct _pedal_reading {
uint16_t fp1;
} pedal_reading_t;
+typedef struct {
+ TaskFunction_t functionPtr;
+ uint32 frequencyMs;
+} Task;
+
typedef struct {
Task task;
TaskHandle_t taskHandle;
diff --git a/VCU/Phantom/hardware/launchpad_hw/board_hardware.h b/VCU/Phantom/hardware/launchpad_hw/board_hardware.h
index 1e0ca888..eaaa6d90 100644
--- a/VCU/Phantom/hardware/launchpad_hw/board_hardware.h
+++ b/VCU/Phantom/hardware/launchpad_hw/board_hardware.h
@@ -55,6 +55,7 @@
#define BRAKING_THRESHOLD 1500 // threshold for turning on brake light
#define BRAKE_LIGHT_PORT hetPORT1
#define BRAKE_LIGHT_PIN 12
+#define BRAKE_LIGHT BRAKE_LIGHT_PORT, BRAKE_LIGHT_PIN
/********* UART PORTS ****************/
#define PC_UART scilinREG
diff --git a/VCU/Phantom/hardware/vcu_hw/board_hardware.h b/VCU/Phantom/hardware/vcu_hw/board_hardware.h
index 5afa08a3..7d0052fe 100644
--- a/VCU/Phantom/hardware/vcu_hw/board_hardware.h
+++ b/VCU/Phantom/hardware/vcu_hw/board_hardware.h
@@ -54,6 +54,7 @@
#define BRAKING_THRESHOLD 2000 // threshold for turning on brake light
#define BRAKE_LIGHT_PORT hetPORT1
#define BRAKE_LIGHT_PIN 12
+#define BRAKE_LIGHT BRAKE_LIGHT_PORT, BRAKE_LIGHT_PIN
/********* UART PORTS ****************/
#define PC_UART sciREG
diff --git a/VCU/Phantom/main.c b/VCU/Phantom/main.c
index 8aa99dfa..26963fcb 100644
--- a/VCU/Phantom/main.c
+++ b/VCU/Phantom/main.c
@@ -20,20 +20,16 @@
#include "board_hardware.h" // contains hardware defines for specific board used (i.e. VCU or launchpad)
#include "vcu_data.h" // VCU Data structure interface written by Joshua Guo (DEPRECATED)
-#include "phantom_queue.h" // os_queue wrapper written by Joshua Guo
-#include "phantom_task.h" // os_task wrapper written by Joshua Guo
#include "Phantom_sci.h" // UART wrapper written by Mahmoud Kamaleldin
+#include "state_machine.h"
#include "execution_timer.h"
-#include "task_test.h"
-#include "task_interrupt.h"
-#include "task_receive.h"
-#include "task_throttle_actor.h"
-#include "task_throttle_agent.h"
-#include "task_statemachine.h"
-#include "task_watchdog.h"
-#include "task_eeprom.h"
+
+#include "task_throttle.h"
+#include "task_pedal_readings.h"
+#include "task_event_handler.h"
+#include "task_logger.h"
/* USER CODE END */
@@ -61,33 +57,38 @@ void phantomDriversInit()
VCUData_init(); // Initialize VCU Data Structure
RTD_Buzzer_Init(); // Initialize Ready to Drive buzzer
RGB_init(); // Initialize RGB LEDs to start off
+
+// rtiInit();
+// rtiEnableNotification(rtiNOTIFICATION_COMPARE1);
+// _enable_IRQ();
+// rtiStartCounter(rtiNOTIFICATION_COUNTER1);
+// uint32 x= rtiGetPeriod(rtiNOTIFICATION_COMPARE1);
}
void phantomTasksInit()
{
- #ifndef VCU_SIM_MODE
- ReceiveTaskInit();
- #else
- UARTprintln("Entering VCU Simulation Mode...");
- #endif
-
- ThrottleInit();
-
- InterruptInit();
-
- if (!throttleAgentInit())
+ SystemTasks_t t = {
+ .EventHandler=EventHandlerInit(),
+ .Logger=LoggerInit(),
+ .Throttle=ThrottleInit(),
+ .PedalReadings=PedalReadingsInit()
+ };
+
+ if (!all(4, t.EventHandler, t.Logger, t.Throttle, t.PedalReadings))
{
- while(1) UARTprintf("Throttle not initialized\r\n");
+ while(1) UARTprintln("Some tasks not initialized: %d, %d, %d, %d", t.EventHandler, t.Logger, t.Throttle, t.PedalReadings);
}
+ StateMachineInit(t);
}
volatile unsigned long ulHighFrequencyTimerTicks;
+// TODO: Never actually triggered
void rtiNotification(uint32 notification)
{
ulHighFrequencyTimerTicks++;
- // should probably add a check to see if the right timer
+ // should probably add a check to see if the right timer
// was called but VCU only has one active hardware timer atm
}
/* USER CODE END */
@@ -97,20 +98,20 @@ void rtiNotification(uint32 notification)
void main(void)
{
/* USER CODE BEGIN (3) */
- rtiInit();
- rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
- _enable_IRQ();
halcogenInit();
+
phantomDriversInit();
- UARTInit(PC_UART, 9600); // something up above overwrites the configuration set here. Make sure this goes last!
+ UARTInit(PC_UART, 460800); // something up above overwrites the configuration set here. Make sure this goes last!
phantomTasksInit();
- // Phantom_startTaskScheduler is Blocking
- Phantom_startTaskScheduler();
- while(1);
+ UARTprintln("Starting scheduler!");
+
+ vTaskStartScheduler();
+
+ while(1) UARTprintf("Scheduler exited!");
/* USER CODE END */
}
diff --git a/VCU/Phantom/tasks/headers/task_event_handler.h b/VCU/Phantom/tasks/headers/task_event_handler.h
new file mode 100644
index 00000000..db47a591
--- /dev/null
+++ b/VCU/Phantom/tasks/headers/task_event_handler.h
@@ -0,0 +1,20 @@
+/*
+ * task_event_handler.h
+ *
+ * Created on: Feb 11, 2023
+ * Author: rafgu
+ */
+
+#ifndef PHANTOM_TASKS_HEADERS_TASK_EVENT_HANDLER_H_
+#define PHANTOM_TASKS_HEADERS_TASK_EVENT_HANDLER_H_
+
+#include "vcu_common.h"
+
+typedef void (*event_handler_t)(void*);
+
+TaskHandle_t EventHandlerInit();
+
+bool HandleEvent(event_handler_t callback, uint16_t data);
+bool HandleEventFromISR(event_handler_t callback, uint16_t data);
+
+#endif /* PHANTOM_TASKS_HEADERS_TASK_EVENT_HANDLER_H_ */
diff --git a/VCU/Phantom/tasks/headers/task_interrupt.h b/VCU/Phantom/tasks/headers/task_interrupt.h
deleted file mode 100644
index e29b05f5..00000000
--- a/VCU/Phantom/tasks/headers/task_interrupt.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef PHANTOM_TASKS_INTERRUPT_ACTOR_H_
-#define PHANTOM_TASKS_INTERRUPT_ACTOR_H_
-
-#include
-
-void InterruptInit(void);
-uint8_t receiveIntEvent(uint32_t delay);
-
-#endif
diff --git a/VCU/Phantom/tasks/headers/task_logger.h b/VCU/Phantom/tasks/headers/task_logger.h
new file mode 100644
index 00000000..c8fb1387
--- /dev/null
+++ b/VCU/Phantom/tasks/headers/task_logger.h
@@ -0,0 +1,28 @@
+/*
+ * task_logger.h
+ *
+ * Created on: Feb 11, 2023
+ * Author: rafgu
+ */
+
+#ifndef PHANTOM_TASKS_HEADERS_TASK_LOGGER_H_
+#define PHANTOM_TASKS_HEADERS_TASK_LOGGER_H_
+
+#include "vcu_common.h"
+
+// all modules that use logger WILL need these
+#include "string.h"
+#include "stdio.h"
+#include "ansi_colors.h"
+
+TaskHandle_t LoggerInit();
+
+uint8_t Log(const char* str);
+uint8_t LogColor(const char* color, const char* str);
+uint8_t LogFromISR(const char* color, const char* str);
+
+void FlushLogger(uint16_t waitms);
+void GetLogHeader(eSource source, const char* color, char* str);
+
+
+#endif /* PHANTOM_TASKS_HEADERS_TASK_LOGGER_H_ */
diff --git a/VCU/Phantom/tasks/headers/task_pedal_readings.h b/VCU/Phantom/tasks/headers/task_pedal_readings.h
new file mode 100644
index 00000000..3bb1d229
--- /dev/null
+++ b/VCU/Phantom/tasks/headers/task_pedal_readings.h
@@ -0,0 +1,18 @@
+/*
+ * task_throttle.h
+ *
+ * Created on: July 15, 2022
+ * Author: josh
+ */
+
+#ifndef PHANTOM_TASKS_task_pedal_readings_H_
+#define PHANTOM_TASKS_task_pedal_readings_H_
+
+#include "vcu_common.h"
+
+#define HYSTERESIS 200U
+
+TaskHandle_t PedalReadingsInit(void);
+uint8_t ReceivePedalReadings(pedal_reading_t* pdreading, TickType_t wait_time_ms);
+
+#endif
diff --git a/VCU/Phantom/tasks/headers/task_receive.h b/VCU/Phantom/tasks/headers/task_receive.h
deleted file mode 100644
index 269d54f6..00000000
--- a/VCU/Phantom/tasks/headers/task_receive.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * task_receive.h
- *
- * Created on: Jun 16, 2022
- * Author: Rafael
- */
-
-#ifndef PHANTOM_TASKS_HEADERS_TASK_RECEIVE_H_
-#define PHANTOM_TASKS_HEADERS_TASK_RECEIVE_H_
-
-
-void ReceiveTaskInit(void);
-
-
-#endif /* PHANTOM_TASKS_HEADERS_TASK_RECEIVE_H_ */
diff --git a/VCU/Phantom/tasks/headers/task_statemachine.h b/VCU/Phantom/tasks/headers/task_statemachine.h
deleted file mode 100644
index f0f63453..00000000
--- a/VCU/Phantom/tasks/headers/task_statemachine.h
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * task_statemachine.h
- *
- * Created on: Apr 16, 2020
- * Author: gabriel, jjkhan, josh
- *
- *
- * Last Modified on: Dec 30, 2020 -> By jjkhan
- */
-
-#ifndef PHANTOM_TASKS_TASK_STATEMACHINE_H_
-#define PHANTOM_TASKS_TASK_STATEMACHINE_H_
-
-#include "vcu_common.h"
-
-State StateMachine_getState();
-
-/* Task */
-void Task_StateMachineInit(void);
-
-#endif /* PHANTOM_TASKS_TASK_STATEMACHINE_H_ */
diff --git a/VCU/Phantom/tasks/headers/task_statemachine_backup.h b/VCU/Phantom/tasks/headers/task_statemachine_backup.h
deleted file mode 100644
index a59855a9..00000000
--- a/VCU/Phantom/tasks/headers/task_statemachine_backup.h
+++ /dev/null
@@ -1,65 +0,0 @@
-// /*
-// * task_statemachine.h
-// *
-// * Created on: Apr 16, 2020
-// * Author: gabriel
-// *
-// *
-// * Last Modified on: Dec 30, 2020 -> By jjkhan
-// */
-
-// #ifndef PHANTOM_TASKS_TASK_STATEMACHINE_H_
-// #define PHANTOM_TASKS_TASK_STATEMACHINE_H_
-
-// /*
-// * Header files used by state machine task.
-// */
-// #include "board_hardware.h" // contains hardware defines for specific board used (i.e. VCU or launchpad)
-
-
-
-// #define NOFAULT 0U
-// #define FAULT 1U
-
-// /*
-// * Possible Fault Locations - Bit Number
-// *
-// */
-// #define SDC_FAULT 0U
-// #define BSE_APPS_FAULT 1U
-// #define HV_LV_FAULT 2U
-// #define CAN_FAULT 3U
-// #define IMD_SYSTEM_FAULT 4U
-// #define TSAL_FAULTS 5U
-
-
-
-// /* SET RESET */
-// #define SET 1U
-// #define ON SET
-
-// extern State state; // Moved it from task_statemachine source file - jjkhan
-
-// // Defined in main.c, used in the task for HV Current and Voltage Out of range sensors.
-// extern TimerHandle_t xTimers[];
-// extern volatile bool HV_VOLTAGE_TIMER_EXPIRED;
-// extern volatile bool HV_CURRENT_TIMER_EXPIRED;
-
-// /* Task Helper Functions. */
-
-// int checkSDC(void);
-// int checkIMD(void);
-// int checkBSE_APPS(void);
-// int CheckHVLVSensor(void);
-// int checkCAN(void);
-// int checkTSAL_FAULTS(void);
-// uint16_t faultLocation(void);
-
-// /* Task */
-// void vStateMachineTask(void *);
-
-
-
-
-
-// #endif /* PHANTOM_TASKS_TASK_STATEMACHINE_H_ */
diff --git a/VCU/Phantom/tasks/headers/task_test.h b/VCU/Phantom/tasks/headers/task_test.h
deleted file mode 100644
index 560f1837..00000000
--- a/VCU/Phantom/tasks/headers/task_test.h
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * task_test.h
- *
- * Test Task for Testing
- *
- * Created on: Sept. 3, 2021
- * Author: Joshua Guo
- */
-#ifndef PHANTOM_TASKS_TASK_TEST_H_
-#define PHANTOM_TASKS_TASK_TEST_H_
-
-
-
-void Task_testInit(void);
-
-
-#endif
diff --git a/VCU/Phantom/tasks/headers/task_throttle.h b/VCU/Phantom/tasks/headers/task_throttle.h
new file mode 100644
index 00000000..0c3cd12a
--- /dev/null
+++ b/VCU/Phantom/tasks/headers/task_throttle.h
@@ -0,0 +1,14 @@
+/*
+ * task_throttle.h
+ *
+ * Created on: July 15, 2022
+ * Author: josh
+ */
+
+#ifndef PHANTOM_TASKS_throttle_H_
+#define PHANTOM_TASKS_throttle_H_
+
+TaskHandle_t ThrottleInit(void);
+void SuspendThrottle(TaskHandle_t);
+
+#endif
diff --git a/VCU/Phantom/tasks/headers/task_throttle_actor.h b/VCU/Phantom/tasks/headers/task_throttle_actor.h
deleted file mode 100644
index 40ecf153..00000000
--- a/VCU/Phantom/tasks/headers/task_throttle_actor.h
+++ /dev/null
@@ -1,13 +0,0 @@
-/*
- * task_throttle_actor.h
- *
- * Created on: July 15, 2022
- * Author: josh
- */
-
-#ifndef PHANTOM_TASKS_TASK_THROTTLE_ACTOR_H_
-#define PHANTOM_TASKS_TASK_THROTTLE_ACTOR_H_
-
-void ThrottleInit(void);
-
-#endif
diff --git a/VCU/Phantom/tasks/headers/task_throttle_agent.h b/VCU/Phantom/tasks/headers/task_throttle_agent.h
deleted file mode 100644
index bfe0c131..00000000
--- a/VCU/Phantom/tasks/headers/task_throttle_agent.h
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
- * task_throttle_actor.h
- *
- * Created on: July 15, 2022
- * Author: josh
- */
-
-#ifndef PHANTOM_TASKS_TASK_THROTTLE_AGENT_H_
-#define PHANTOM_TASKS_TASK_THROTTLE_AGENT_H_
-
-#include "vcu_common.h"
-
-
-uint8_t throttleAgentInit(void);
-uint8_t receivePedalReadings(pedal_reading_t* pdreading, TickType_t wait_time_ms);
-
-
-#endif
diff --git a/VCU/Phantom/tasks/source/task_event_handler.c b/VCU/Phantom/tasks/source/task_event_handler.c
new file mode 100644
index 00000000..f67929fb
--- /dev/null
+++ b/VCU/Phantom/tasks/source/task_event_handler.c
@@ -0,0 +1,84 @@
+/*
+ * task_event_handler.c
+ *
+ * Created on: Feb 11, 2023
+ * Author: rafgu
+ */
+
+#include "task_event_handler.h"
+
+/* Phantom tasks */
+#include "task_config.h"
+#include "task_logger.h"
+
+typedef struct event_t
+{
+ event_handler_t callback;
+ uint16_t data;
+}event_t;
+
+
+static PipeTask_t rtos_handles;
+
+static void ThreadEventHandler(void* pvParams);
+
+
+/* Public API */
+
+TaskHandle_t EventHandlerInit()
+{
+ BaseType_t ret = xTaskCreate(
+ ThreadEventHandler,
+ "EventHandler",
+ EVENT_HANDLER_STACK_SIZE,
+ NULL,
+ EVENT_HANDLER_PRIORITY,
+ &rtos_handles.taskHandle
+ );
+
+ rtos_handles.q = xQueueCreate(16, sizeof(event_t));
+
+ return ret == pdPASS && rtos_handles.q ? rtos_handles.taskHandle : NULL;
+}
+
+
+bool HandleEvent(event_handler_t callback, uint16_t data)
+{
+ event_t event;
+ event.callback = callback;
+ event.data = data;
+
+ return xQueueSendToBack(rtos_handles.q, &event, 1) == pdPASS;
+}
+
+
+bool HandleEventFromISR(event_handler_t callback, uint16_t data)
+{
+ BaseType_t xHigherPriorityTaskWoken;
+
+ event_t event;
+ event.callback = callback;
+ event.data = data;
+
+ return xQueueSendToBackFromISR(rtos_handles.q, &event, &xHigherPriorityTaskWoken) == pdPASS;
+}
+
+
+/* Internal Implementation */
+
+static void ThreadEventHandler(void* pvParams)
+{
+ static event_t event;
+
+ Log("Starting thread");
+
+ while(1)
+ {
+ if (xQueueReceive(rtos_handles.q, &event, portMAX_DELAY) == pdFALSE)
+ {
+ continue;
+ }
+
+ event.callback(&event.data);
+ }
+}
diff --git a/VCU/Phantom/tasks/source/task_interrupt.c b/VCU/Phantom/tasks/source/task_interrupt.c
deleted file mode 100644
index e6773e86..00000000
--- a/VCU/Phantom/tasks/source/task_interrupt.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Task Template made by Joshua Guo
- *
- * Created on:
- * Author: Joshua Guo,
- */
-#include "phantom_task.h"
-#include "phantom_queue.h"
-
-#include "task_interrupt.h"
-#include "task_statemachine.h"
-
-#include "vcu_common.h"
-#include "os_portmacro.h"
-#include "stdarg.h"
-
-#include "vcu_common.h"
-
-#include "sys_common.h"
-#include "sys_vim.h"
-#include "gio.h"
-#include "board_hardware.h"
-
-
-/* Static members */
-static const int NUM_INTERRUPTS = 4; // Not a macro to keep this scoped to the file
-static PipeTask_t actorTask;
-static QueueHandle_t agentISR_Q;
-
-static void vInterruptActorTask(void* arg);
-static uint8_t sendFromISR(isr_action_t data);
-static void receiveFromISR(isr_action_t* data_ptr);
-
-/* Public API */
-uint8_t receiveIntEvent(uint32_t delay)
-{
- uint8_t event;
-
- Phantom_receive(actorTask.q, &event, delay);
-
- return event;
-}
-
-void InterruptInit(void)
-{
- /* Actor initialization */
-
- actorTask.task = (Task) {vInterruptActorTask, 0};
-
- actorTask.taskHandle = Phantom_createTask(&actorTask.task, "InterruptActorTask", 150, 5);
-
- actorTask.q = NULL;
-
- /* Agent initialization */
-
- agentISR_Q = Phantom_createQueue(NUM_INTERRUPTS, sizeof(isr_action_t));
-
- vimInit();
-}
-
-/* Task thread */
-static void vInterruptActorTask(void* arg)
-{
- isr_action_t buffer;
-
- receiveFromISR(&buffer);
-
- buffer.isr_func(-1, actorTask.q); // TODO: and any other params?
-}
-
-/* Agent Interrupt Handler */
-static uint8_t sendFromISR(isr_action_t data){
-
- BaseType_t WokenHigherPriorityTask = pdFALSE;
-
- Phantom_sendISR(agentISR_Q, &data, &WokenHigherPriorityTask);
-
- return WokenHigherPriorityTask == pdTRUE;
-}
-
-void gioNotification(gioPORT_t* port, uint32 bit)
-{
- isr_action_t interruptAction = {ISR_ID_ERROR, NULL};
-
- if (port == READY_TO_DRIVE_PORT && bit == READY_TO_DRIVE_PIN) {
- interruptAction.id = RTDS_INTERRUPT;
- interruptAction.isr_func = NULL; // TODO: Write function handler
- }
-
- if (interruptAction.id != ISR_ID_ERROR) {
-
-
- }
-
- sendFromISR(interruptAction);
-}
-
-static void receiveFromISR(isr_action_t* data_ptr)
-{
- Phantom_receive(agentISR_Q, data_ptr, portMAX_DELAY);
-}
\ No newline at end of file
diff --git a/VCU/Phantom/tasks/source/task_logger.c b/VCU/Phantom/tasks/source/task_logger.c
new file mode 100644
index 00000000..7431cd11
--- /dev/null
+++ b/VCU/Phantom/tasks/source/task_logger.c
@@ -0,0 +1,195 @@
+/*
+ * task_logger.c
+ *
+ * Created on: Feb 11, 2023
+ * Author: rafgu
+ */
+
+#include "task_logger.h"
+
+/* C standard libs */
+#include "math.h"
+
+/* Phantom modules */
+#include "Phantom_sci.h"
+
+#include "task_event_handler.h"
+
+typedef uint64_t segment_t;
+#define SEGMENT_SIZE sizeof(segment_t)
+
+static PipeTask_t rtos_handles;
+
+static void LoggerThread(void* pvParams);
+static uint8_t LogMessage(const char* color, const char* str, eSource source);
+static uint8_t AsyncPrint(eSource source, const char* str);
+
+
+/* Public API */
+
+TaskHandle_t LoggerInit()
+{
+ BaseType_t ret = xTaskCreate(
+ LoggerThread,
+ "LoggerThread",
+ LOGGER_STACK_SIZE,
+ 0,
+ LOGGER_PRIORITY,
+ &rtos_handles.taskHandle
+ );
+
+ rtos_handles.q = xQueueCreate(128, sizeof(segment_t));
+
+ return ret == pdPASS && rtos_handles.q ? rtos_handles.taskHandle : NULL;
+}
+
+
+uint8_t Log(const char* str)
+{
+ return LogMessage(WHT, str, FROM_SCHEDULER);
+}
+
+
+uint8_t LogColor(const char* color, const char* str)
+{
+ return LogMessage(color, str, FROM_SCHEDULER);
+}
+
+
+uint8_t LogFromISR(const char* color, const char* str)
+{
+ return LogMessage(color, str, FROM_ISR);
+}
+
+
+void FlushLogger(uint16_t waitms)
+{
+ vTaskPrioritySet(rtos_handles.taskHandle, configMAX_PRIORITIES-1);
+
+ vTaskDelay(pdMS_TO_TICKS(waitms));
+
+ vTaskPrioritySet(rtos_handles.taskHandle, LOGGER_PRIORITY);
+}
+
+
+void GetLogHeader(eSource source, const char* color, char* str)
+{
+ switch (source)
+ {
+ case FROM_ISR:
+ sprintf(str, "\r%s[FromISR:%.2f] ", color, (float)xTaskGetTickCountFromISR()/configTICK_RATE_HZ);
+ break;
+
+ case FROM_SCHEDULER:
+ sprintf(str, "\r%s[%s:%.2f] ", color, pcTaskGetName(NULL), (float)xTaskGetTickCount()/configTICK_RATE_HZ);
+ break;
+
+ default:
+ break;
+ }
+}
+
+
+/* Internal Implementation*/
+
+static void LoggerThread(void* pvParams)
+{
+ segment_t segment;
+
+ Log("Starting thread");
+
+ while(1)
+ {
+ if (xQueueReceive(rtos_handles.q, &segment, portMAX_DELAY) == pdFALSE)
+ {
+ continue;
+ }
+
+ vTaskPrioritySet(rtos_handles.taskHandle, configMAX_PRIORITIES-1);
+
+ UARTprintf((char*)&segment);
+
+ vTaskPrioritySet(rtos_handles.taskHandle, LOGGER_PRIORITY);
+ }
+}
+
+static uint8_t LogMessage(const char* color, const char* str, eSource source)
+{
+ // prepare timestamp
+ char header[64];
+ GetLogHeader(source, color, header);
+ AsyncPrint(source, header);
+
+ // queue user string
+ AsyncPrint(source, str);
+
+ // queue strings to reset console position and format
+ char buffer[16];
+ sprintf(buffer, "%s\n\r", reset);
+
+ return AsyncPrint(source, buffer);
+}
+
+
+uint8_t QueueSegment(eSource source, segment_t segment)
+{
+ uint8_t ret;
+
+ switch(source)
+ {
+ case FROM_ISR:
+ {
+ BaseType_t xHigherPriorityTaskWoken;
+
+ ret = xQueueSendToBackFromISR(rtos_handles.q, &segment, &xHigherPriorityTaskWoken) == pdPASS;
+
+ break;
+ }
+ case FROM_SCHEDULER:
+ {
+ ret = xQueueSendToBack(rtos_handles.q, &segment, 1) == pdPASS;
+
+ break;
+ }
+ default:
+ {
+ ret = false;
+ break;
+ }
+ }
+
+ return ret;
+}
+
+uint8_t AsyncPrint(eSource source, const char* str)
+{
+ /* Initialize tmp to copy segments into */
+ segment_t tmp;
+ memset(&tmp, '\0', SEGMENT_SIZE);
+
+ uint16_t total_num_bytes = strlen(str);
+ uint8_t num_segments = total_num_bytes/SEGMENT_SIZE;
+
+ uint8_t segment_index = 0;
+
+ /* Copy all full segments */
+ for (segment_index = 0; segment_index < num_segments; segment_index++)
+ {
+ memcpy(&tmp, str + (segment_index*SEGMENT_SIZE), SEGMENT_SIZE);
+
+ QueueSegment(source, tmp);
+ }
+
+ uint16_t bytes_left = total_num_bytes - (segment_index*SEGMENT_SIZE);
+
+ /* Queue remaining segments */
+ if (bytes_left != 0)
+ {
+ memset(&tmp, '\0', SEGMENT_SIZE);
+ memcpy(&tmp, str + (segment_index*SEGMENT_SIZE), bytes_left);
+
+ QueueSegment(source, tmp);
+ }
+
+ return 1;
+}
diff --git a/VCU/Phantom/tasks/source/task_pedal_readings.c b/VCU/Phantom/tasks/source/task_pedal_readings.c
new file mode 100644
index 00000000..8794014a
--- /dev/null
+++ b/VCU/Phantom/tasks/source/task_pedal_readings.c
@@ -0,0 +1,146 @@
+/*
+ * task_pedal_readings.c
+ *
+ * Created on: July 15, 2022
+ * Author: Joshua Guo
+ */
+
+#include "vcu_common.h"
+
+/* C standard libs */
+#include "stdlib.h"
+#include "string.h"
+#include "sci.h"
+#include "stdio.h"
+#include "math.h"
+
+/* Halcogen drivers */
+#include "sys_common.h"
+#include "adc.h"
+#include "gio.h"
+
+/* Phantom modules */
+#include "Phantom_sci.h"
+#include "board_hardware.h"
+
+/* Phantom tasks */
+#include "task_pedal_readings.h"
+#include "task_logger.h"
+#include "task_event_handler.h"
+
+
+typedef struct PedalReadings_t{
+ PipeTask_t pipeline;
+ pedal_reading_t readings;
+ pedal_reading_t prevReadings;
+}PedalReadings_t;
+
+static PedalReadings_t footPedals;
+
+static void vPedalReadingsTask(void* arg);
+static pedal_reading_t ReadPedals();
+static void SetBrakeLight(uint8_t value);
+
+/* Public API */
+uint8_t ReceivePedalReadings(pedal_reading_t* pdreading, TickType_t wait_time_ms)
+{
+ if (footPedals.pipeline.q)
+ {
+ return xQueueReceive(footPedals.pipeline.q, pdreading, wait_time_ms) == pdTRUE;
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+TaskHandle_t PedalReadingsInit(void)
+{
+ BaseType_t ret = xTaskCreate(
+ vPedalReadingsTask,
+ "PedalReadings",
+ THROTTLE_AGT_STACK_SIZE,
+ NULL,
+ 1,
+ &footPedals.pipeline.taskHandle
+ );
+
+ footPedals.pipeline.q = xQueueCreate(10, sizeof(pedal_reading_t));
+
+ footPedals.prevReadings = (pedal_reading_t) {0, 0 ,0};
+
+ return ret == pdPASS && footPedals.pipeline.q ? footPedals.pipeline.taskHandle : NULL;
+}
+
+/* Internal Implementation */
+
+static void vPedalReadingsTask(void* arg)
+{
+ Log("Starting thread");
+
+ while(true)
+ {
+ footPedals.readings = ReadPedals();
+
+ // apply a low pass filter with ALPHA of 0.5
+ footPedals.readings.fp1 = (footPedals.readings.fp1 + footPedals.prevReadings.fp1) >> 1;
+ footPedals.readings.fp2 = (footPedals.readings.fp2 + footPedals.prevReadings.fp2) >> 1;
+ footPedals.readings.bse = (footPedals.readings.bse + footPedals.prevReadings.bse) >> 1;
+
+ uint8_t brakelight_value = footPedals.readings.bse > (BRAKING_THRESHOLD + HYSTERESIS);
+ SetBrakeLight(brakelight_value);
+
+ // send to throttle
+ xQueueSend(footPedals.pipeline.q, &footPedals.readings, 1);
+
+ footPedals.prevReadings = footPedals.readings;
+ }
+}
+
+
+static pedal_reading_t ReadPedals()
+{
+
+ #ifndef VCU_SIM_MODE
+ // delay must occur here because sim mode has no delay (frequency determined by incoming serial data)
+ vTaskDelay(pdMS_TO_TICKS(20));
+
+ // Get pedal readings from ADC
+ adcData_t FP_data[3];
+ adcStartConversion(adcREG1, adcGROUP1);
+ while (!adcIsConversionComplete(adcREG1, adcGROUP1)); // prefer another method of waiting, maybe an interrupt with TaskSuspend/Resume/YIELD?
+ adcGetData(adcREG1, adcGROUP1, FP_data);
+
+ // must map each value explicitly because compiler may not have the same mem packing rules for struct as arrays
+
+ return (pedal_reading_t) {FP_data[0].value, FP_data[1].value, FP_data[2].value};
+
+ #else
+ uint32_t data = getSimData();
+
+ /* extract and parse the byte message. See VCU Firmware Simulation document */
+ uint16_t apps1 = (data & 0b111111111111) + 1500;
+ uint16_t apps2 = ((data & 0b1111111111 << 12) >> 12) + 500;
+ // TODO: Add the rest of the direct VCU inputs to the encoding scheme
+
+ pedal_reading_t throttleData = {
+ .bse=1300,
+ .fp1=apps1,
+ .fp2=apps2
+ };
+
+ return throttleData;
+ #endif
+}
+
+static void SetBrakeLight(uint8_t value)
+{
+ if (gioGetBit(BRAKE_LIGHT) != value)
+ {
+ char buffer[32];
+ sprintf(buffer, "Setting brakelight: %d", value);
+ Log(buffer);
+
+ gioSetBit(BRAKE_LIGHT, value);
+ }
+}
diff --git a/VCU/Phantom/tasks/source/task_receive.c b/VCU/Phantom/tasks/source/task_receive.c
deleted file mode 100644
index b7f21860..00000000
--- a/VCU/Phantom/tasks/source/task_receive.c
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * task_receive.c
- *
- * Created on: Jun 16, 2022
- * Author: Rafael Guveara
- */
-
-
-#include "phantom_task.h"
-#include "Phantom_sci.h"
-#include "FreeRTOS.h"
-#include "os_task.h"
-#include "board_hardware.h"
-#include "stdlib.h"
-#include "vcu_data.h"
-
-// (int)((ceil(log10(2^32))+1)*sizeof(char)) -stack overflow
-static char float_str[11];
-extern volatile unsigned long ulHighFrequencyTimerTicks;
-
-static Task task;
-static TaskHandle_t taskHandle;
-
-static void vReceiveTask(void* arg);
-
-void ReceiveTaskInit(void)
-{
- task = (Task) {vReceiveTask, 0};
-
- // blocks indefinitely if task creation failed
- taskHandle = Phantom_createTask(&task, "VCU_CLI", 512, 0);
-}
-
-static void vReceiveTask(void* arg)
-{
-
-
-}
diff --git a/VCU/Phantom/tasks/source/task_statemachine.c b/VCU/Phantom/tasks/source/task_statemachine.c
deleted file mode 100644
index 37410b2a..00000000
--- a/VCU/Phantom/tasks/source/task_statemachine.c
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Task Template made by Joshua Guo
- *
- * Created on:
- * Author: gabriel, jjkhan, joshua guo
- */
-#include "phantom_task.h"
-#include "phantom_timer.h" // if you need to use timers
-#include "phantom_queue.h"
-
-// #include your_task_header_file
-// Any other .h files you need goes here...
-#include "task_config.h"
-#include "board_hardware.h" // contains hardware defines for specific board used (i.e. VCU or launchpad)
-#include "vcu_data.h" // deprecated
-#include "vcu_common.h"
-#include "RGB_LED.h"
-
-static Task task;
-static TaskHandle_t taskHandle;
-static QueueHandle_t queueHandle;
-
-// Any other module-scope variables goes here... (make sure they have the 'static' keyword)
-static State currentState;
-
-static TimerHandle_t HV_CurrentTimerHandle;
-static TimerHandle_t HV_VoltageTimerHandle;
-static bool HV_VOLTAGE_TIMER_EXPIRED;
-static bool HV_CURRENT_TIMER_EXPIRED;
-
-// Pre-define your static functions here...
-static void vStateMachineTask(void* arg);
-static bool isSevereFault(uint32 faults, State currentState);
-static bool isMinorFault(uint32 faults);
-static void HV_CurrentTimerCallback(TimerHandle_t timer);
-static void HV_VoltageTimerCallback(TimerHandle_t timer);
-
-State StateMachine_getState()
-{
- return currentState;
-}
-
-void Task_StateMachineInit(void)
-{
- task = (Task) {vStateMachineTask, STATE_MACHINE_TASK_PERIOD_MS};
-
- // Phantom_createTask should block infinitely if task creation failed
- taskHandle = Phantom_createTask(&task, "StateMachineTask", STATE_MACHINE_TASK_STACK_SIZE, STATE_MACHINE_TASK_PRIORITY);
-
- // create your timers here...
- HV_CurrentTimerHandle = Phantom_createTimer("HV_Current_OutOfRange_T", 10000, NO_RELOAD, NULL, HV_CurrentTimerCallback);
- HV_VoltageTimerHandle = Phantom_createTimer("HV_Voltage_OutOfRange_T", 10000, NO_RELOAD, NULL, HV_VoltageTimerCallback);
-
- // any other init code you want to put goes here...
- HV_VOLTAGE_TIMER_EXPIRED = false;
- HV_CURRENT_TIMER_EXPIRED = false;
-}
-
-static void vStateMachineTask(void* arg)
-{
- // arg will always be NULL, so ignore it.
-
- // your task stuff goes in here...
- State newState = currentState;
-
- bool TSAL_signal = VCUData_getTSALSignal();
- bool RTDS_signal = VCUData_getRTDSignal();
- uint32 faults = VCUData_readFaults(ALL_FAULTS);
-
- switch(newState)
- {
- case TRACTIVE_OFF:
- RGB_drive(RGB_CYAN);
-
- if (RTDS_signal || faults) {
- newState = SEVERE_FAULT;
- } else if (TSAL_signal) {
- newState = TRACTIVE_ON; //No faults AND TSAL is on AND RTDS not set
- }
- break;
-
- case TRACTIVE_ON:
- RGB_drive(RGB_MAGENTA);
-
- if (faults) {
- newState = isSevereFault(faults, newState) ? SEVERE_FAULT : isMinorFault(faults) ? MINOR_FAULT : newState;
- } else if (!TSAL_signal) {
- newState = TRACTIVE_OFF;
- } else if (RTDS_signal) {
- newState = RUNNING;
- }
- break;
-
- case RUNNING:
- RGB_drive(RGB_GREEN);
-
- if (faults) {
- // Update state depending on severity of fault
- newState = isSevereFault(faults, newState) ? SEVERE_FAULT : isMinorFault(faults) ? MINOR_FAULT : newState;
- } else if(!TSAL_signal) {
- newState= SEVERE_FAULT;
- } else if(!RTDS_signal) {
- newState = TRACTIVE_ON;
- }
- break;
-
- case MINOR_FAULT:
- RGB_drive(RGB_YELLOW);
- if (faults && isSevereFault(faults, newState)) {
- newState = SEVERE_FAULT;
- } else if (RTDS_signal && TSAL_signal) {
- newState = RUNNING;
- } else if (!RTDS_signal && TSAL_signal){
- newState = TRACTIVE_ON;
- } else if (!RTDS_signal) {
- newState = TRACTIVE_OFF;
- }
-
- // Reset the HV timer_started flags as the HV fault was fixed before timeout
- if (newState != MINOR_FAULT) {
- Phantom_stopTimer(HV_CurrentTimerHandle, 5);
- Phantom_stopTimer(HV_VoltageTimerHandle, 5);
- }
- break;
-
- case SEVERE_FAULT:
- RGB_drive(RGB_RED);
-
- if (!(faults || RTDS_signal))
- {
- newState = TRACTIVE_OFF;
- }
- break;
- }
-
- currentState = newState;
-}
-
-static bool isSevereFault(uint32 faults, State currentState)
-{
- if (!faults) {
- return false;
- }
-
- // Shutdown Circuit Fault or IMD Fault -> its Severe so don't need to check other faults
- if (faults & (SHUTDOWN_CIRCUIT_FAULT_GROUP | IMD_FAULT_GROUP))
- {
- return true;
- }
-
- // Check BSE APPS Faults
- if (faults & (BSE_APPS_FAULT_GROUP & ~BSE_APPS_SIMULTANEOUS_MINOR_FAULT))
- {
- // if the fault isn't the Minor Fault, then set SEVERE_FAULT, don't need to check for minor
- return true;
- }
-
- // Check HV Range Faults and set flags iff this isnt the first time (i.e. timers already started.)
- // Check for SEVERE Faults Right now
- if ((faults & HV_VOLTAGE_OUT_OF_RANGE_MINOR_FAULT) && HV_VOLTAGE_TIMER_EXPIRED)
- {
- // Timer expired
- HV_VOLTAGE_TIMER_EXPIRED = false;
- return true;
- }
-
- if ((faults & HV_CURRENT_OUT_OF_RANGE_MINOR_FAULT) && HV_CURRENT_TIMER_EXPIRED)
- {
- //timer Expired
- HV_CURRENT_TIMER_EXPIRED = false;
- return true;
- }
-
- if((faults & HV_APPS_PROPORTION_SEVERE_ERROR) && currentState==RUNNING)
- {
- return true;
- }
-
- if((faults & TSAL_FAULT_GROUP) && (currentState==RUNNING || currentState==TRACTIVE_ON)){
- return true;
- }
-
- // Check CAN Severe Faults
- // Either CAN Message indicates a severe fault (TYPE1 ERROR) or a minor fault (TYPE2 ERROR)
- if (faults & CAN_ERROR_TYPE1)
- { // Severe Fault message from CAN, so don't need to check other faults, change currentState and yield task
- return true;
- }
-
- return false;
-}
-
-static bool isMinorFault(uint32 faults)
-{
- if (!faults) {
- return false;
- }
-
- // Check for MINOR Faults
- if (faults & HV_VOLTAGE_OUT_OF_RANGE_MINOR_FAULT)
- {
- if(!Phantom_isTimerActive(HV_VoltageTimerHandle)){
- // Start Timer
- HV_VOLTAGE_TIMER_EXPIRED = false;
- Phantom_startTimer(HV_VoltageTimerHandle, 0);
- }
- return true;
- }
- if (faults & HV_CURRENT_OUT_OF_RANGE_MINOR_FAULT)
- {
- if(!Phantom_isTimerActive(HV_CurrentTimerHandle)){
- // Start Timer
- HV_CURRENT_TIMER_EXPIRED = false;
- Phantom_startTimer(HV_CurrentTimerHandle, 0);
- }
- return true;
- }
-
- if (faults & (LV_CURRENT_OUT_OF_RANGE_MINOR_FAULT |
- LV_VOLTAGE_OUT_OF_RANGE_MINOR_FAULT |
- BSE_APPS_SIMULTANEOUS_MINOR_FAULT |
- CAN_ERROR_TYPE2))
- {
- return true;
- }
-
- return false;
-}
-
-// Other helper functions and callbacks goes here...
-static void HV_CurrentTimerCallback(TimerHandle_t timer)
-{
- HV_CURRENT_TIMER_EXPIRED = true;
-}
-
-static void HV_VoltageTimerCallback(TimerHandle_t timer)
-{
- HV_VOLTAGE_TIMER_EXPIRED = true;
-}
diff --git a/VCU/Phantom/tasks/source/task_test.c b/VCU/Phantom/tasks/source/task_test.c
deleted file mode 100644
index aa2b2a49..00000000
--- a/VCU/Phantom/tasks/source/task_test.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * task_test.c
- *
- * Test Task for Testing
- *
- * Created on: Sept. 3, 2021
- * Author: Joshua Guo
- */
-#include "phantom_task.h"
-#include "phantom_timer.h"
-#include "vcu_data.h"
-#include "RGB_LED.h"
-
-#include "task_config.h"
-#include "task_test.h"
-
-// pre-define static functions first
-static void vTestTask(void* arg);
-static void testTimerCallback(TimerHandle_t timer);
-
-static Task testTask;
-// static TaskHandle_t taskHandle;
-
-static TimerHandle_t testTimer;
-static long testTimerCounter = 0;
-
-void Task_testInit(void)
-{
- testTask = (Task) {vTestTask, TEST_TASK_PERIOD_MS};
- // Phantom_createTask should block infinitely if task creation failed
- /*taskHandle = */Phantom_createTask(&testTask, "TestTask", TEST_TASK_STACK_SIZE, TEST_TASK_PRIORITY);
-
- // create recurring timers here...
- testTimer = Phantom_createTimer("testTimer", 1000, AUTO_RELOAD, &testTimerCounter, testTimerCallback);
- Phantom_startTimer(testTimer, 0);
-
- // so compiler won't complain about unused variables
- // taskHandle;
- // testTimer;
-}
-
-static void vTestTask(void* arg)
-{
- uint8 faults = VCUData_readFaults(ALL_FAULTS);
-
- if (faults) {
- RGB_drive(RGB_YELLOW);
- } else {
- RGB_drive(RGB_OFF);
- }
-}
-
-static void testTimerCallback(TimerHandle_t timer)
-{
- uint8 faults = VCUData_readFaults(ALL_FAULTS);
- if (!faults) { // prefer to avoid anything with mutexes in a timer callback
- VCUData_turnOnFaults(BMS_GPIO_SEVERE_FAULT | BSPD_SEVERE_FAULT | BSE_APPS_FAULT_GROUP);
- } else {
- VCUData_turnOffFaults(BMS_GPIO_SEVERE_FAULT | BSPD_SEVERE_FAULT | BSE_APPS_FAULT_GROUP);
- }
-}
diff --git a/VCU/Phantom/tasks/source/task_throttle.c b/VCU/Phantom/tasks/source/task_throttle.c
new file mode 100644
index 00000000..84524809
--- /dev/null
+++ b/VCU/Phantom/tasks/source/task_throttle.c
@@ -0,0 +1,232 @@
+/*
+ * task_task_throttle.c
+ * refactored for 2022
+ *
+ * Created on: Sept 18, 2021
+ * Author: jaypacamarra, Joshua Guo
+ */
+
+#include "vcu_common.h"
+
+/* C standard libs */
+#include "math.h"
+
+/* Halcogen drivers */
+#include "hal_stdtypes.h"
+#include "gio.h"
+#include "adc.h"
+
+/* Phantom modules*/
+#include "board_hardware.h"
+#include "MCP48FV_DAC_SPI.h"
+#include "phantom_timer.h"
+#include "Phantom_sci.h"
+
+/* Phantom tasks */
+#include "task_pedal_readings.h"
+#include "task_throttle.h"
+#include "state_machine.h"
+#include "task_logger.h"
+
+
+/* For calculating throttle padding */
+/* Padding will eliminate unintended range faults at 0% or 100% pedal presses */
+#define PADDING_PERCENT (0.08f) // Must be between 0.0 and 1.0
+#define PADDED_BSE_MIN_VALUE (BSE_MIN_VALUE * (1U + PADDING_PERCENT))
+#define PADDED_BSE_MAX_VALUE (BSE_MAX_VALUE * (1U - PADDING_PERCENT))
+#define PADDED_APPS1_MIN_VALUE (APPS1_MIN_VALUE * (1U + PADDING_PERCENT))
+#define PADDED_APPS1_MAX_VALUE (APPS1_MAX_VALUE * (1U - PADDING_PERCENT))
+#define PADDED_APPS2_MIN_VALUE (APPS2_MIN_VALUE * (1U + PADDING_PERCENT))
+#define PADDED_APPS2_MAX_VALUE (APPS2_MAX_VALUE * (1U - PADDING_PERCENT))
+
+#define APPS_SENSOR_TIMEOUT 1000
+
+// ^ this equation may need to be modified for the curtis voltage lower limit and upper limit
+// i.e. map from 0.6V (60) to 4.5V (450) or something like that, instead of 0->500 (0V -> 5V)
+#define MAP_PERCENT_TO_VOLTAGE(x) 390 * apps_percent_avg + 60 // equation mapping the averaged signals to 0->500 for the DAC driver
+
+typedef struct FaultTimers_t{
+ TimerHandle_t APPS1Range;
+ TimerHandle_t APPS2Range;
+ TimerHandle_t BSERange;
+ TimerHandle_t FPDiff;
+ TimerHandle_t RTDS;
+} FaultTimers_t;
+
+static FaultTimers_t faultTimers;
+static TaskHandle_t taskHandle;
+
+
+static void vThrottleTask(void* arg);
+static void CheckFaultConditions(const pedal_reading_t* pedalReadings, float apps1_percent, float apps2_percent);
+static float CalculatePedalPercent(uint32_t pedalValue, float minValue, float maxValue);
+static bool UpdatePedalRangeFaultTimer(uint32_t pedalValue, uint32_t minValue, uint32_t maxValue, TimerHandle_t faultTimer);
+static bool UpdateAPPS10PercentFaultTimer(float Percent_APPS1_Pressed, float Percent_APPS2_Pressed);
+static void CheckBrakePlausibility(uint32_t BSE_sensor_sum, float Percent_APPS1_Pressed, float Percent_APPS2_Pressed);
+
+
+/* Public API*/
+
+TaskHandle_t ThrottleInit(void)
+{
+ BaseType_t ret = xTaskCreate(
+ vThrottleTask,
+ "Throttle",
+ THROTTLE_ACT_STACK_SIZE,
+ 0,
+ THROTTLE_ACT_PRIORITY,
+ &taskHandle
+ );
+
+ faultTimers.APPS1Range = Phantom_createTimer("Apps1RangeCheck", 100, NO_RELOAD, EVENT_APPS1_RANGE_FAULT, NotifyStateMachineFromTimer);
+ faultTimers.APPS2Range = Phantom_createTimer("Apps2RangeCheck", 100, NO_RELOAD, EVENT_APPS2_RANGE_FAULT, NotifyStateMachineFromTimer);
+ faultTimers.BSERange = Phantom_createTimer("BseRangeCheck", 100, NO_RELOAD, EVENT_BSE_RANGE_FAULT, NotifyStateMachineFromTimer);
+ faultTimers.FPDiff = Phantom_createTimer("FpDiffCheck", 100, NO_RELOAD, EVENT_FP_DIFF_FAULT, NotifyStateMachineFromTimer);
+ faultTimers.RTDS = Phantom_createTimer("RTDSSwitch", 2000, NO_RELOAD, 0, NotifyStateMachineFromTimer);
+
+ MCP48FV_Init();
+
+ return ret == pdPASS ? taskHandle : NULL;
+}
+
+
+void SuspendThrottle(TaskHandle_t self)
+{
+ #ifndef VCU_SIM_MODE
+ if (self == taskHandle)
+ {
+ MCP48FV_Set_Value(0); // send throttle value to DAC driver
+ LogColor(RED, "Turning off throttle");
+
+ LogColor(RED, "Suspending throttle task.");
+ vTaskSuspend(self);
+ }
+ #else
+ LogColor(GRN, "Cannot suspend throttle in VCU Sim Mode.");
+ #endif
+}
+
+
+/* Internal implementation */
+
+static void vThrottleTask(void* arg)
+{
+ // suspend on startup
+ SuspendThrottle(taskHandle);
+
+ static pedal_reading_t pedalReadings;
+
+ while(true)
+ {
+ if (!ReceivePedalReadings(&pedalReadings, APPS_SENSOR_TIMEOUT))
+ {
+ SuspendThrottle(taskHandle);
+
+ continue;
+ }
+
+ float apps1PedalPercent = CalculatePedalPercent(pedalReadings.fp1, PADDED_APPS1_MIN_VALUE, PADDED_APPS2_MAX_VALUE);
+ float apps2PedalPercent = CalculatePedalPercent(pedalReadings.fp2, PADDED_APPS2_MIN_VALUE, PADDED_APPS2_MAX_VALUE);
+
+ CheckFaultConditions(&pedalReadings, apps1PedalPercent, apps2PedalPercent);
+
+ /* Set throttle voltage value */
+ float apps_percent_avg = (apps1PedalPercent + apps2PedalPercent) / 2;
+ int16_t throttle = MAP_PERCENT_TO_VOLTAGE(apps_percent_avg);
+
+ MCP48FV_Set_Value(throttle);
+
+ #ifdef VCU_SIM_MODE
+ char buffer[32];
+ snprintf(buffer, 32, "throttle=%d", throttle);
+ Log(buffer);
+ #endif
+ }
+}
+
+
+static void CheckFaultConditions(const pedal_reading_t* pedalReadings, float apps1_percent, float apps2_percent)
+{
+ // check for short to GND/VCC on APPS sensor 1
+ UpdatePedalRangeFaultTimer(pedalReadings->fp1, APPS1_MIN_VALUE, APPS1_MAX_VALUE, faultTimers.APPS1Range);
+
+ // check for short to GND/VCC on APPS sensor 2
+ UpdatePedalRangeFaultTimer(pedalReadings->fp2, APPS2_MIN_VALUE, APPS2_MAX_VALUE, faultTimers.APPS2Range);
+
+ // check for short to GND/VCC on BSE
+ UpdatePedalRangeFaultTimer(pedalReadings->bse, BSE_MIN_VALUE, BSE_MAX_VALUE, faultTimers.BSERange);
+
+ // check if APPS1 and APPS2 are within 10% of each other
+ UpdateAPPS10PercentFaultTimer(apps1_percent, apps2_percent);
+
+ // check if brakes are pressed and accelerator pedal is pressed greater than or equal to 25%
+ CheckBrakePlausibility(pedalReadings->bse, apps1_percent, apps2_percent);
+}
+
+
+static float CalculatePedalPercent(uint32_t pedalValue, float minValue, float maxValue) {
+ if (pedalValue < minValue)
+ return 0.0F;
+ else if (pedalValue > maxValue)
+ return 1.0F;
+ else
+ return (pedalValue - minValue) / (maxValue - minValue);
+}
+
+
+static bool UpdatePedalRangeFaultTimer(uint32_t pedalValue, uint32_t minValue, uint32_t maxValue, TimerHandle_t faultTimer) {
+
+ bool ret = false;
+
+ if (pedalValue < minValue || pedalValue > maxValue) // BSE assumed shorted to GND or shorted to VCC
+ {
+ Phantom_startTimer(faultTimer, 50); // start software timer for bse range fault
+
+ ret = true;
+ }
+ else
+ {
+ Phantom_stopTimer(faultTimer, 50);
+ }
+
+ return ret;
+}
+
+
+static bool UpdateAPPS10PercentFaultTimer(float Percent_APPS1_Pressed, float Percent_APPS2_Pressed) {
+
+ bool ret = false;
+
+ float FP_sensor_diff = fabsf(Percent_APPS2_Pressed - Percent_APPS1_Pressed);
+
+ if (FP_sensor_diff > 0.10)
+ {
+ Phantom_startTimer(faultTimers.FPDiff, 50);
+
+ ret = true;
+ }
+ else
+ {
+ Phantom_stopTimer(faultTimers.FPDiff, portMAX_DELAY);
+ }
+
+ return ret;
+}
+
+
+static void CheckBrakePlausibility(uint32_t BSE_sensor_sum, float Percent_APPS1_Pressed, float Percent_APPS2_Pressed) {
+
+ if (BSE_sensor_sum >= BRAKING_THRESHOLD + HYSTERESIS &&
+ Percent_APPS1_Pressed >= 0.25 && Percent_APPS2_Pressed >= 0.25)
+ {
+ // brakes and accelerator are both pressed
+ NotifyStateMachine(EVENT_BRAKE_PLAUSIBILITY_FAULT);
+ }
+ else if (Percent_APPS1_Pressed < 0.05 && Percent_APPS2_Pressed < 0.05)
+ {
+ // APPS/Brake plausibility fault only clears if APPS returns to less than 5% pedal position
+ // with or without brake operation (see EV.5.7.2) - jaypacamarra
+ NotifyStateMachine(EVENT_BRAKE_PLAUSIBILITY_CLEARED);
+ }
+}
+
diff --git a/VCU/Phantom/tasks/source/task_throttle_actor.c b/VCU/Phantom/tasks/source/task_throttle_actor.c
deleted file mode 100644
index 5eeed065..00000000
--- a/VCU/Phantom/tasks/source/task_throttle_actor.c
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * task_throttle.c
- * refactored for 2022
- *
- * Created on: Sept 18, 2021
- * Author: jaypacamarra, Joshua Guo
- */
-#include "phantom_task.h"
-#include "phantom_timer.h"
-#include "phantom_queue.h"
-
-#include // for fabsf function
-#include "hal_stdtypes.h"
-#include "gio.h"
-#include
-#include "MCP48FV_DAC_SPI.h"
-
-// #include "vcu_data.h" // deprecated
-#include "vcu_common.h"
-#include "board_hardware.h"
-#include "Phantom_sci.h"
-
-#include "task_config.h"
-
-#include "task_throttle_agent.h" // for access to mailbox
-#include "task_throttle_actor.h" // for access to mailbox
-#include "task_statemachine.h" // for access to mailbox & queue
-
-static Task task;
-static TaskHandle_t taskHandle;
-
-static TimerHandle_t APPS1RangeFaultTimer;
-static TimerHandle_t APPS2RangeFaultTimer;
-static TimerHandle_t BSERangeFaultTimer;
-static TimerHandle_t FPDiffFaultTimer;
-static TimerHandle_t RTDSTimer;
-
-/* For calculating throttle padding */
-/* Padding will eliminate unintended range faults at 0% or 100% pedal presses */
-#define PADDING_PERCENT (0.08f) // Must be between 0.0 and 1.0
-#define PADDED_BSE_MIN_VALUE (BSE_MIN_VALUE * (1U + PADDING_PERCENT))
-#define PADDED_BSE_MAX_VALUE (BSE_MAX_VALUE * (1U - PADDING_PERCENT))
-#define PADDED_APPS1_MIN_VALUE (APPS1_MIN_VALUE * (1U + PADDING_PERCENT))
-#define PADDED_APPS1_MAX_VALUE (APPS1_MAX_VALUE * (1U - PADDING_PERCENT))
-#define PADDED_APPS2_MIN_VALUE (APPS2_MIN_VALUE * (1U + PADDING_PERCENT))
-#define PADDED_APPS2_MAX_VALUE (APPS2_MAX_VALUE * (1U - PADDING_PERCENT))
-
-#define HYSTERESIS (200U)
-
-#define THROTTLE_FAULTS_MASK (APPS1_RANGE_SEVERE_FAULT | APPS2_RANGE_SEVERE_FAULT | BSE_RANGE_SEVERE_FAULT | APPS_10DIFF_SEVERE_FAULT | BSE_APPS_SIMULTANEOUS_MINOR_FAULT)
-static bool APPS1_RANGE_FAULT_TIMER_EXPIRED = false; //added by jaypacamarra
-static bool APPS2_RANGE_FAULT_TIMER_EXPIRED = false; //added by jaypacamarra
-static bool BSE_RANGE_FAULT_TIMER_EXPIRED = false; //added by jaypacamarra
-static bool FP_DIFF_FAULT_TIMER_EXPIRED = false; //added by jaypacamarra
-
-/* Brake Light readability */
-#define BRAKE_LIGHT_ON 0
-#define BRAKE_LIGHT_OFF 1
-static bool brake_light_state = BRAKE_LIGHT_ON;
-
-static bool isThrottleAvailable = false;
-static uint32_t faultCode = 0;
-
-static void vThrottleActorTask(void* arg);
-
-static float calculatePedalPercent(uint32_t pedalValue, float minValue, float maxValue);
-static bool check_Pedal_Range_Fault(uint32_t pedalValue, uint32_t minValue, uint32_t maxValue, TimerHandle_t faultTimer, bool* timerFlag);
-static bool check_10PercentAPPS_Fault(float Percent_APPS1_Pressed, float Percent_APPS2_Pressed);
-static bool check_Brake_Plausibility_Fault(uint32_t BSE_sensor_sum, float Percent_APPS1_Pressed, float Percent_APPS2_Pressed);
-
-static void RTDS_CALLBACK(TimerHandle_t xTimers);
-static void APPS1_SEVERE_RANGE_FAULT_CALLBACK(TimerHandle_t xTimers);
-static void APPS2_SEVERE_RANGE_FAULT_CALLBACK(TimerHandle_t xTimers);
-static void BSE_SEVERE_RANGE_FAULT_CALLBACK(TimerHandle_t xTimers);
-static void FP_DIFF_SEVERE_FAULT_CALLBACK(TimerHandle_t xTimers);
-
-void ThrottleInit(void)
-{
- task = (Task) {vThrottleActorTask, 0};
-
- // blocks indefinitely if task creation failed
- taskHandle = Phantom_createTask(&task, "ThrottleActorTask", THROTTLE_ACT_STACK_SIZE, THROTTLE_ACT_PRIORITY);
-
- /*
- APPS1RangeFaultTimer = Phantom_createTimer("APPS1_RANGE_FAULT_Timer", 100, NO_RELOAD, NULL, APPS1_SEVERE_RANGE_FAULT_CALLBACK);
- APPS2RangeFaultTimer = Phantom_createTimer("APPS2_RANGE_FAULT_Timer", 100, NO_RELOAD, NULL, APPS2_SEVERE_RANGE_FAULT_CALLBACK);
- BSERangeFaultTimer = Phantom_createTimer("BSE_RANGE_FAULT_Timer", 100, NO_RELOAD, NULL, BSE_SEVERE_RANGE_FAULT_CALLBACK);
- FPDiffFaultTimer = Phantom_createTimer("FP_DIFF_FAULT_Timer", 100, NO_RELOAD, NULL, FP_DIFF_SEVERE_FAULT_CALLBACK);
- RTDSTimer = Phantom_createTimer("RTDS_Timer", 2000, NO_RELOAD, NULL, RTDS_CALLBACK);
- */
-
- (void) taskHandle;
-
- MCP48FV_Init();
-}
-
-static void vThrottleActorTask(void* arg)
-{
- pedal_reading_t pedalReadings;
-
- if (!receivePedalReadings(&pedalReadings, portMAX_DELAY))
- {
- return; // this is logically a continue
- }
-
- float apps1PedalPercent = calculatePedalPercent(pedalReadings.fp1, PADDED_APPS1_MIN_VALUE, PADDED_APPS2_MAX_VALUE);
- float apps2PedalPercent = calculatePedalPercent(pedalReadings.fp2, PADDED_APPS2_MIN_VALUE, PADDED_APPS2_MAX_VALUE);
- float bsePedalPercent = calculatePedalPercent(pedalReadings.bse, PADDED_BSE_MIN_VALUE, PADDED_BSE_MAX_VALUE);
-
- // TODO: Add range fault checks
-
- // // check for short to GND/VCC on APPS sensor 1
- // bool apps1Fault = check_Pedal_Range_Fault(pedalReadings.fp1, APPS1_MIN_VALUE, APPS1_MAX_VALUE, APPS1RangeFaultTimer, &APPS1_RANGE_FAULT_TIMER_EXPIRED);
- // // check for short to GND/VCC on APPS sensor 2
- // bool apps2Fault = check_Pedal_Range_Fault(pedalReadings.fp2, APPS2_MIN_VALUE, APPS2_MAX_VALUE, APPS2RangeFaultTimer, &APPS2_RANGE_FAULT_TIMER_EXPIRED);
- // // check for short to GND/VCC on BSE
- // bool bseFault = check_Pedal_Range_Fault(pedalReadings.bse, BSE_MIN_VALUE, BSE_MAX_VALUE, BSERangeFaultTimer, &BSE_RANGE_FAULT_TIMER_EXPIRED);
- // // Check if APPS1 and APPS2 are within 10% of each other
- // bool diffFault = check_10PercentAPPS_Fault(apps1PedalPercent, apps2PedalPercent);
- // // Check if brakes are pressed and accelerator pedal is pressed greater than or equal to 25%
- // bool simulFault = check_Brake_Plausibility_Fault(pedalReadings.bse, apps1PedalPercent, apps2PedalPercent);
-
- // // Fill the unrelevant bits with flags from vcu data
- // uint32_t currentFaults = 0;
-
- // currentFaults |= ((apps1Fault && 1) * APPS1_RANGE_SEVERE_FAULT);
- // currentFaults |= (apps2Fault && 1) * APPS2_RANGE_SEVERE_FAULT;
- // currentFaults |= (bseFault && 1) * BSE_RANGE_SEVERE_FAULT;
- // currentFaults |= (diffFault && 1) * APPS_10DIFF_SEVERE_FAULT;
- // currentFaults |= (simulFault && 1) * BSE_APPS_SIMULTANEOUS_MINOR_FAULT;
-
- // faultCode = currentFaults;
-
- /*********************************************************************************
- brake light
- *********************************************************************************/
- uint32_t BSESensorSum = pedalReadings.bse;
- if (brake_light_state == BRAKE_LIGHT_OFF && BSESensorSum > (BRAKING_THRESHOLD + HYSTERESIS))
- {
-
- gioSetBit(BRAKE_LIGHT_PORT, BRAKE_LIGHT_PIN, BRAKE_LIGHT_ON);
-
- // update brake light enable in the vcu data structure
- brake_light_state = BRAKE_LIGHT_ON;
- }
- else if (brake_light_state == BRAKE_LIGHT_ON && BSESensorSum < (BRAKING_THRESHOLD - HYSTERESIS))
- {
-
- gioSetBit(BRAKE_LIGHT_PORT, BRAKE_LIGHT_PIN, BRAKE_LIGHT_OFF);
-
- // update brake light enable in the vcu data structure
- brake_light_state = BRAKE_LIGHT_OFF;
- }
-
-
-
- /*********************************************************************************
- Set Throttle
- *********************************************************************************/
- State state = StateMachine_getState();
-
- // debugging - jaypacamarra
- // manually setting state to RUNNING and setting THROTTLE_AVAILABLE to true to test DAC - jaypacamarra
- state = RUNNING;
- isThrottleAvailable = true;
-
- if (state == RUNNING && isThrottleAvailable)
- {
-
- float apps_percent_avg = (apps1PedalPercent + apps2PedalPercent) / 2;
-
-
- // send DAC to inverter
- int16_t throttle = 390 * apps_percent_avg + 60; // equation mapping the averaged signals to 0->500 for the DAC driver
- // ^ this equation may need to be modified for the curtis voltage lower limit and upper limit
- // i.e. map from 0.6V (60) to 4.5V (450) or something like that, instead of 0->500 (0V -> 5V)
- MCP48FV_Set_Value(throttle); // send throttle value to DAC driver
-
- #ifdef VCU_SIM_MODE
- UARTprintln("%d", throttle);
- #endif
- }
- else
- {
- // send 0 to DAC
- MCP48FV_Set_Value(0);
-
- #ifdef VCU_SIM_MODE
- UARTprintln("0");
- #endif
-
- isThrottleAvailable = false;
- }
-}
-
-/** @fn void calculatePedalPercents(void)
-* @brief Calculates the percent pressed of the brake pedal
-* and the accelerator pedal
-* @Return This function does not return anything, it only
-* updates the VCU data structure
-*/
-static float calculatePedalPercent(uint32_t pedalValue, float minValue, float maxValue) {
- if (pedalValue < minValue)
- return 0.0F;
- else if (pedalValue > maxValue)
- return 1.0F;
- else
- return (pedalValue - minValue) / (maxValue - minValue);
-}
-
-/** @fn bool check_Pedal_Range_Fault(void)
-* @brief Checks if the Pedal is in the right voltage range
-* @Return This function returns:
-* True -> Fault
-* False -> No Fault
-*/
-static bool check_Pedal_Range_Fault(uint32_t pedalValue, uint32_t minValue, uint32_t maxValue, TimerHandle_t faultTimer, bool* timerFlag) {
- bool is_there_pedal_range_fault = false;
-
- if (pedalValue < minValue || pedalValue > maxValue) // BSE assumed shorted to GND or shorted to VCC
- {
- if(!Phantom_isTimerActive(faultTimer))
- {
- if(!Phantom_startTimer(faultTimer, 50)) // start software timer for bse range fault
- {
- for(;;); // TODO: when watchdog is worked on, remember to also change this
- }
- }
- is_there_pedal_range_fault = *timerFlag;
- }
- else
- {
- // Stop fault timer
- Phantom_stopTimer(faultTimer, MAX_WAIT_TIME_MS);
- *timerFlag = false;
- }
-
- return is_there_pedal_range_fault;
-}
-
-/** @fn bool check10PercentAPPS(void)
-* @brief Checks if APPS1 and APPS2 are within 10% of each other.
-* A fault means they are not within 10% of each other.
-* @Return This function returns:
-* True -> Fault
-* False -> No Fault
-*/
-static bool check_10PercentAPPS_Fault(float Percent_APPS1_Pressed, float Percent_APPS2_Pressed) {
- bool is_there_10DIFF_fault = false;
- float FP_sensor_diff = fabsf(Percent_APPS2_Pressed - Percent_APPS1_Pressed); // Calculate absolute difference between APPS1 and APPS2 readings
-
- if (FP_sensor_diff > 0.10)
- {
- if(!Phantom_isTimerActive(FPDiffFaultTimer))
- {
- if(!Phantom_startTimer(FPDiffFaultTimer, 50)) // start software timer for apps1 range fault
- {
- for(;;); // TODO: when watchdog is worked on, remember to also change this
- }
- }
- is_there_10DIFF_fault = FP_DIFF_FAULT_TIMER_EXPIRED;
- }
- else
- {
- // Stop the fault timer
- Phantom_stopTimer(FPDiffFaultTimer, MAX_WAIT_TIME_MS);
- FP_DIFF_FAULT_TIMER_EXPIRED = false;
- }
-
- return is_there_10DIFF_fault;
-}
-
-/** @fn bool check_Brake_Plausibility_Fault(void)
-* @brief Checks if the brakes and accelerator are pressed at the same time.
-* A fault means the brake is pressed and the APPS reads 25% or higher.
-* @Return This function returns:
-* True -> Fault
-* False -> No Fault
-*/
-static bool check_Brake_Plausibility_Fault(uint32_t BSE_sensor_sum, float Percent_APPS1_Pressed, float Percent_APPS2_Pressed) {
- static bool is_there_brake_plausibility_fault = false;
-
- if (BSE_sensor_sum >= BRAKING_THRESHOLD + HYSTERESIS &&
- Percent_APPS1_Pressed >= 0.25 && Percent_APPS2_Pressed >= 0.25)
- {
- // Set fault
- is_there_brake_plausibility_fault = true;
- }
- else if (Percent_APPS1_Pressed < 0.05 && Percent_APPS2_Pressed < 0.05)
- {
- // APPS/Brake plausibility fault only clears if APPS returns to less than 5% pedal position
- // with or without brake operation (see EV.5.7.2) - jaypacamarra
-
- // No fault
- is_there_brake_plausibility_fault = false;
- }
-
- return is_there_brake_plausibility_fault;
-}
-
-static void RTDS_CALLBACK(TimerHandle_t xTimers)
-{
- isThrottleAvailable = true;
-}
-
-//++ Added by Jay Pacamarra
-/* Timer callback when APPS1 Range fault occurs for 100 ms*/
-static void APPS1_SEVERE_RANGE_FAULT_CALLBACK(TimerHandle_t xTimers)
-{
- APPS1_RANGE_FAULT_TIMER_EXPIRED = true;
-}
-/* Timer callback when APPS2 Range fault occurs for 100 ms*/
-static void APPS2_SEVERE_RANGE_FAULT_CALLBACK(TimerHandle_t xTimers)
-{
- APPS2_RANGE_FAULT_TIMER_EXPIRED = true;
-}
-/* Timer callback when BSE Range fault occurs for 100 ms*/
-static void BSE_SEVERE_RANGE_FAULT_CALLBACK(TimerHandle_t xTimers)
-{
- BSE_RANGE_FAULT_TIMER_EXPIRED = true;
-}
-/* Timer callback when APPS1 and APPS2 differ by 10% or more for 100 ms*/
-static void FP_DIFF_SEVERE_FAULT_CALLBACK(TimerHandle_t xTimers)
-{
- FP_DIFF_FAULT_TIMER_EXPIRED = true;
-}
-//++ Added by Jay Pacamarra
diff --git a/VCU/Phantom/tasks/source/task_throttle_agent.c b/VCU/Phantom/tasks/source/task_throttle_agent.c
deleted file mode 100644
index 4e9d61fa..00000000
--- a/VCU/Phantom/tasks/source/task_throttle_agent.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * task_throttle_agent.c
- *
- * Created on: July 15, 2022
- * Author: Joshua Guo
- */
-#include "phantom_task.h"
-#include "phantom_queue.h"
-
-#include "task_throttle_agent.h"
-#include "task_config.h"
-
-#include "vcu_common.h"
-#include "board_hardware.h"
-#include "adc.h"
-
-#include "Phantom_sci.h"
-
-#include
-#include "sys_common.h"
-#include "string.h"
-#include "sci.h"
-#include "stdio.h"
-#include "math.h"
-
-typedef struct ThrottleAgent_t{
- PipeTask_t pipeline;
- pedal_reading_t readings;
- pedal_reading_t prevReadings;
-}ThrottleAgent_t;
-
-static ThrottleAgent_t footPedals;
-
-static void vThrottleAgentTask(void* arg);
-
-static pedal_reading_t readPedals();
-
-
-/* Public API */
-uint8_t receivePedalReadings(pedal_reading_t* pdreading, TickType_t wait_time_ms)
-{
- return xQueueReceive(footPedals.pipeline.q, pdreading, wait_time_ms) == pdTRUE;
-}
-
-uint8_t throttleAgentInit(void)
-{
- footPedals.pipeline.task = (Task) {vThrottleAgentTask, 0};
-
- // blocks indefinitely if task creation failed
- footPedals.pipeline.taskHandle = Phantom_createTask(&footPedals.pipeline.task, "ThrottleAgentTask", THROTTLE_AGT_STACK_SIZE, THROTTLE_AGT_PRIORITY);
-
- footPedals.pipeline.q = xQueueCreate(50, sizeof(pedal_reading_t));
-
- footPedals.prevReadings = (pedal_reading_t) {0, 0 ,0};
-
- return footPedals.pipeline.q && footPedals.pipeline.taskHandle;
-}
-
-static void vThrottleAgentTask(void* arg)
-{
- footPedals.readings = readPedals();
-
- // apply a low pass filter with ALPHA of 0.5
- footPedals.readings.bse = (footPedals.readings.bse + footPedals.prevReadings.bse) >> 1;
- footPedals.readings.fp1 = (footPedals.readings.fp1 + footPedals.prevReadings.fp1) >> 1;
- footPedals.readings.fp2 = (footPedals.readings.fp2 + footPedals.prevReadings.fp2) >> 1;
-
- // update prev filtered values
- footPedals.prevReadings = footPedals.readings;
-
- // send filtered values to mailbox (task_throttle_actor.c)
- xQueueSend(footPedals.pipeline.q, &footPedals.readings, 1000);
-}
-
-static pedal_reading_t readPedals()
-{
-
- #ifndef VCU_SIM_MODE
- // Get pedal readings from ADC
- adcData_t FP_data[3];
- adcStartConversion(adcREG1, adcGROUP1);
- while (!adcIsConversionComplete(adcREG1, adcGROUP1)); // prefer another method of waiting, maybe an interrupt with TaskSuspend/Resume/YIELD?
- adcGetData(adcREG1, adcGROUP1, FP_data);
-
- // must map each value explicitly because compiler may not have the same mem packing rules for struct as arrays
- return (pedal_reading_t) {FP_data[0].value, FP_data[1].value, FP_data[2].value};
-
- #else
- uint32_t data = getSimData();
-
- /* extract and parse the byte message. See VCU Firmware Simulation document */
- uint16_t apps1 = (data & 0b111111111111) + 1500;
- uint16_t apps2 = ((data & 0b1111111111 << 12) >> 12) + 500;
- // TODO: Add the rest of the direct VCU inputs to the encoding scheme
-
- pedal_reading_t throttleData = {
- .bse=1300,
- .fp1=apps1,
- .fp2=apps2
- };
-
- return throttleData;
- #endif
-}
diff --git a/VCU/Phantom/tasks/task_config.h b/VCU/Phantom/tasks/task_config.h
index c01f0497..c8c1b2d2 100644
--- a/VCU/Phantom/tasks/task_config.h
+++ b/VCU/Phantom/tasks/task_config.h
@@ -23,30 +23,24 @@
/*********************************************************************************
* TASK PRIORITIES
*********************************************************************************/
-#define THROTTLE_AGT_PRIORITY 4
-#define THROTTLE_AGT_SIM_PRIORITY THROTTLE_AGT_PRIORITY
-#define THROTTLE_ACT_PRIORITY 5
-#define STATE_MACHINE_TASK_PRIORITY 2
-#define EEPROM_TASK_PRIORITY 0
-#define WATCHDOG_TASK_PRIORITY 0 // same as idle task
+#define PEDAL_READINGS_PRIORITY 2
+#define THROTTLE_ACT_PRIORITY 4
+#define EVENT_HANDLER_PRIORITY 5
+#define LOGGER_PRIORITY 1
-#define TEST_TASK_PRIORITY 1
+// #define EEPROM_TASK_PRIORITY 0
+// #define WATCHDOG_TASK_PRIORITY 0 // same as idle task
-// there may also be interrupt/ISR priorities for:
-// CAN messages
-// GPIOs (ready to drive, shutdown circuit GPIOs..)
/*********************************************************************************
* TASK STACK SIZES
*********************************************************************************/
-#define THROTTLE_AGT_STACK_SIZE 150
-#define THROTTLE_AGT_SIM_STACK_SIZE 150
-#define THROTTLE_ACT_STACK_SIZE 150
-#define STATE_MACHINE_TASK_STACK_SIZE 150
-#define EEPROM_TASK_STACK_SIZE 150
-#define WATCHDOG_TASK_STACK_SIZE 150 // same as idle task
-
-#define TEST_TASK_STACK_SIZE 150
+#define THROTTLE_AGT_STACK_SIZE 200
+#define THROTTLE_ACT_STACK_SIZE 500
+#define LOGGER_STACK_SIZE 700
+#define EVENT_HANDLER_STACK_SIZE 128
+// #define EEPROM_TASK_STACK_SIZE 750
+// #define WATCHDOG_TASK_STACK_SIZE 750 // same as idle task
#endif /* TASKS_PRIORITIES_H_ */
diff --git a/VCU/Phantom/tasks/task_template b/VCU/Phantom/tasks/task_template
deleted file mode 100644
index d7026bb2..00000000
--- a/VCU/Phantom/tasks/task_template
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Task Template made by Joshua Guo
- *
- * Created on:
- * Author: Joshua Guo,
- */
-#include "phantom_task.h"
-// #include "phantom_timer.h" // if you need to use timers
-
-// #include your_task_header_file
-// Any other .h files you need goes here...
-
-static Task task;
-static TaskHandle_t taskHandle;
-
-// Any other module-scope variables goes here... (make sure they have the 'static' keyword)
-// static TimerHandle_t yourTimerHandle;
-// static long yourTimerCounter;
-
-// Pre-define your static functions here...
-static void vYourTaskFunction(void* arg);
-// static void yourTimerCallbackFunc(TimerHandle_t timer);
-
-// this function should be in your header file (aside from include guards and other comments ofc)
-void YourTaskInit(void)
-{
- task = (Task) {vYourTaskFunction, YOUR_TASK_PERIOD_MS};
-
- // Phantom_createTask should block infinitely if task creation failed
- taskHandle = Phantom_createTask(&task, TASK_NAME, YOUR_TASK_STACK_SIZE, YOUR_TASK_PRIORITY);
-
- // create your persistent timers here...
- // yourTimerHandle = Phantom_createTimer(YOUR_TIMER_NAME, YOUR_TIMER_PERIOD_MS, AUTO_RELOAD, &yourTimerCounter, yourTimerCallbackFunc);
- // Phantom_startTimer(yourTimerHandle);
-
- // any other init code you want to put goes here...
-}
-
-static void vYourTaskFunction(void* arg)
-{
- // arg will always be NULL, so ignore it.
-
- // your task stuff goes in here...
-}
-
-// Other helper functions and callbacks goes here...
-// static void yourTimerCallbackFunc(TimerHandle_t timer) {}
\ No newline at end of file
diff --git a/VCU/Phantom/test_eeprom/testEeprom.c b/VCU/Phantom/test_eeprom/testEeprom.c
deleted file mode 100644
index 30db9846..00000000
--- a/VCU/Phantom/test_eeprom/testEeprom.c
+++ /dev/null
@@ -1,59 +0,0 @@
-// /*
-// * testEeprom.c
-// *
-// * Created on: Mar 7, 2021
-// * Author: junaidkhan
-// */
-// #include "phantom_freertos.h"
-// #include "testEeprom.h"
-// #include "os_queue.h"
-// #include "vcu_data.h"
-
-// extern QueueHandle_t eepromMessages;
-// extern volatile uint8_t initializationOccured;
-// void testEeprom(void *p){
-
-// // Create a variable to be able to set a breakpoint to read rxBuffer Message each time in Memory Browser
-// uint8_t forBreakPoint =0;
-
-// // A buffer that will hold messages received from eepromTask - Don't need to print it.
-// char rxBuffer[60];
-
-// TickType_t mylastTickCount;
-// mylastTickCount = xTaskGetTickCount();
-
-// while(1){
-
-// if(initializationOccured){
-
-// unsigned long numberOfMessages = uxQueueMessagesWaiting(eepromMessages);
-// if(numberOfMessages){
-
-// if (xQueueReceive(eepromMessages,rxBuffer,pdMS_TO_TICKS(0))==pdPASS){ // Don't block if no message in the Queue
-// forBreakPoint =1;
-// }
-// }
-// // Block for 500ms
-// vTaskDelayUntil(&mylastTickCount,pdMS_TO_TICKS(100));
-
-// }else{
-
-// // Block for 500ms
-// vTaskDelayUntil(&mylastTickCount,pdMS_TO_TICKS(100));
-// }
-// }
-// }
-
-// /* This will test if the eeprom bank is being updated.
-// void testEeprom(void *p){
-// TickType_t mylastTickCount;
-// mylastTickCount = xTaskGetTickCount();
-// while(1){
-// if(xSemaphoreTake(vcuKey, pdMS_TO_TICKS(10))){
-// VCUDataPtr->DigitalVal.TSAL_FAULT ^= (1<<0); // Toggle Bit-0
-// xSemaphoreGive(vcuKey);
-// }
-// vTaskDelayUntil(&mylastTickCount,pdMS_TO_TICKS(500));
-// }
-// }
-// */
diff --git a/VCU/Phantom/test_eeprom/testEeprom.h b/VCU/Phantom/test_eeprom/testEeprom.h
deleted file mode 100644
index 5f1aba2b..00000000
--- a/VCU/Phantom/test_eeprom/testEeprom.h
+++ /dev/null
@@ -1,20 +0,0 @@
-// /*
-// * testEeprom.h
-// *
-// * Created on: Mar 7, 2021
-// * Author: junaidkhan
-// */
-
-// #ifndef PHANTOM_TEST_EEPROM_TESTEEPROM_H_
-// #define PHANTOM_TEST_EEPROM_TESTEEPROM_H_
-
-// #include "vcu_data.h"
-// #include "FreeRTOS.h"
-// #include "os_semphr.h"
-
-// extern SemaphoreHandle_t vcuKey;
-// extern data* VCUDataPtr;
-// void testEeprom(void *p);
-
-
-// #endif /* PHANTOM_TEST_EEPROM_TESTEEPROM_H_ */
diff --git a/VCU/Simulation_Mode_VCU_REV2/.gitignore b/VCU/Simulation_Mode_VCU_REV2/.gitignore
deleted file mode 100644
index 265cd11e..00000000
--- a/VCU/Simulation_Mode_VCU_REV2/.gitignore
+++ /dev/null
@@ -1,6 +0,0 @@
-/Phantom/
-/halcogen_launchpad/
-/halcogen_vcu/
-/makefile
-/objects.mk
-/sources.mk
diff --git a/VCU/Simulation_Mode_VCU_REV2/ccsObjs.opt b/VCU/Simulation_Mode_VCU_REV2/ccsObjs.opt
deleted file mode 100644
index f2e3c03d..00000000
--- a/VCU/Simulation_Mode_VCU_REV2/ccsObjs.opt
+++ /dev/null
@@ -1 +0,0 @@
-"./Phantom/Drivers/DAC_SPI/MCP48FV_DAC_SPI.obj" "./Phantom/Drivers/EEPROM/eeprom_driver.obj" "./Phantom/Drivers/RGB_LED/RGB_LED.obj" "./Phantom/Drivers/RTD_Buzzer/RTD_Buzzer.obj" "./Phantom/Drivers/RTOS/phantom_queue.obj" "./Phantom/Drivers/RTOS/phantom_task.obj" "./Phantom/Drivers/RTOS/phantom_timer.obj" "./Phantom/Drivers/UART/Phantom_sci.obj" "./Phantom/data_structures/vcu_data.obj" "./Phantom/main.obj" "./Phantom/tasks/source/task_eeprom.obj" "./Phantom/tasks/source/task_interrupt.obj" "./Phantom/tasks/source/task_receive.obj" "./Phantom/tasks/source/task_statemachine.obj" "./Phantom/tasks/source/task_test.obj" "./Phantom/tasks/source/task_throttle_actor.obj" "./Phantom/tasks/source/task_throttle_agent.obj" "./Phantom/tasks/source/task_watchdog.obj" "./Phantom/test_eeprom/testEeprom.obj" "./halcogen_launchpad/source/Device_TMS570LS12.obj" "./halcogen_launchpad/source/Fapi_UserDefinedFunctions.obj" "./halcogen_launchpad/source/adc.obj" "./halcogen_launchpad/source/dabort.obj" "./halcogen_launchpad/source/errata_SSWF021_45.obj" "./halcogen_launchpad/source/esm.obj" "./halcogen_launchpad/source/gio.obj" "./halcogen_launchpad/source/het.obj" "./halcogen_launchpad/source/i2c.obj" "./halcogen_launchpad/source/mibspi.obj" "./halcogen_launchpad/source/notification.obj" "./halcogen_launchpad/source/os_croutine.obj" "./halcogen_launchpad/source/os_event_groups.obj" "./halcogen_launchpad/source/os_heap.obj" "./halcogen_launchpad/source/os_list.obj" "./halcogen_launchpad/source/os_mpu_wrappers.obj" "./halcogen_launchpad/source/os_port.obj" "./halcogen_launchpad/source/os_portasm.obj" "./halcogen_launchpad/source/os_queue.obj" "./halcogen_launchpad/source/os_tasks.obj" "./halcogen_launchpad/source/os_timer.obj" "./halcogen_launchpad/source/pinmux.obj" "./halcogen_launchpad/source/rti.obj" "./halcogen_launchpad/source/sci.obj" "./halcogen_launchpad/source/svc.obj" "./halcogen_launchpad/source/sys_core.obj" "./halcogen_launchpad/source/sys_dma.obj" "./halcogen_launchpad/source/sys_intvecs.obj" "./halcogen_launchpad/source/sys_main.obj" "./halcogen_launchpad/source/sys_mpu.obj" "./halcogen_launchpad/source/sys_pcr.obj" "./halcogen_launchpad/source/sys_phantom.obj" "./halcogen_launchpad/source/sys_pmm.obj" "./halcogen_launchpad/source/sys_pmu.obj" "./halcogen_launchpad/source/sys_selftest.obj" "./halcogen_launchpad/source/sys_startup.obj" "./halcogen_launchpad/source/sys_vim.obj" "./halcogen_launchpad/source/system.obj" "./halcogen_launchpad/source/ti_fee_Info.obj" "./halcogen_launchpad/source/ti_fee_cancel.obj" "./halcogen_launchpad/source/ti_fee_cfg.obj" "./halcogen_launchpad/source/ti_fee_eraseimmediateblock.obj" "./halcogen_launchpad/source/ti_fee_format.obj" "./halcogen_launchpad/source/ti_fee_ini.obj" "./halcogen_launchpad/source/ti_fee_invalidateblock.obj" "./halcogen_launchpad/source/ti_fee_main.obj" "./halcogen_launchpad/source/ti_fee_read.obj" "./halcogen_launchpad/source/ti_fee_readSync.obj" "./halcogen_launchpad/source/ti_fee_shutdown.obj" "./halcogen_launchpad/source/ti_fee_util.obj" "./halcogen_launchpad/source/ti_fee_writeAsync.obj" "./halcogen_launchpad/source/ti_fee_writeSync.obj" "./halcogen_vcu/source/Device_TMS570LS12.obj" "./halcogen_vcu/source/Fapi_UserDefinedFunctions.obj" "./halcogen_vcu/source/adc.obj" "./halcogen_vcu/source/dabort.obj" "./halcogen_vcu/source/errata_SSWF021_45.obj" "./halcogen_vcu/source/esm.obj" "./halcogen_vcu/source/gio.obj" "./halcogen_vcu/source/het.obj" "./halcogen_vcu/source/i2c.obj" "./halcogen_vcu/source/mibspi.obj" "./halcogen_vcu/source/notification.obj" "./halcogen_vcu/source/os_croutine.obj" "./halcogen_vcu/source/os_event_groups.obj" "./halcogen_vcu/source/os_heap.obj" "./halcogen_vcu/source/os_list.obj" "./halcogen_vcu/source/os_mpu_wrappers.obj" "./halcogen_vcu/source/os_port.obj" "./halcogen_vcu/source/os_portasm.obj" "./halcogen_vcu/source/os_queue.obj" "./halcogen_vcu/source/os_tasks.obj" "./halcogen_vcu/source/os_timer.obj" "./halcogen_vcu/source/pinmux.obj" "./halcogen_vcu/source/rti.obj" "./halcogen_vcu/source/sci.obj" "./halcogen_vcu/source/sys_core.obj" "./halcogen_vcu/source/sys_dma.obj" "./halcogen_vcu/source/sys_intvecs.obj" "./halcogen_vcu/source/sys_mpu.obj" "./halcogen_vcu/source/sys_pcr.obj" "./halcogen_vcu/source/sys_phantom.obj" "./halcogen_vcu/source/sys_pmm.obj" "./halcogen_vcu/source/sys_pmu.obj" "./halcogen_vcu/source/sys_selftest.obj" "./halcogen_vcu/source/sys_startup.obj" "./halcogen_vcu/source/sys_vim.obj" "./halcogen_vcu/source/system.obj" "./halcogen_vcu/source/ti_fee_Info.obj" "./halcogen_vcu/source/ti_fee_cancel.obj" "./halcogen_vcu/source/ti_fee_cfg.obj" "./halcogen_vcu/source/ti_fee_eraseimmediateblock.obj" "./halcogen_vcu/source/ti_fee_format.obj" "./halcogen_vcu/source/ti_fee_ini.obj" "./halcogen_vcu/source/ti_fee_invalidateblock.obj" "./halcogen_vcu/source/ti_fee_main.obj" "./halcogen_vcu/source/ti_fee_read.obj" "./halcogen_vcu/source/ti_fee_readSync.obj" "./halcogen_vcu/source/ti_fee_shutdown.obj" "./halcogen_vcu/source/ti_fee_util.obj" "./halcogen_vcu/source/ti_fee_writeAsync.obj" "./halcogen_vcu/source/ti_fee_writeSync.obj" "../halcogen_launchpad/source/sys_link.cmd" "../halcogen_vcu/source/sys_linker_freeRTOS.cmd" -llibc.a
\ No newline at end of file
diff --git a/VCU/halcogen_vcu/include/FreeRTOSConfig.h b/VCU/halcogen_vcu/include/FreeRTOSConfig.h
index ffbc60b8..11c03c50 100644
--- a/VCU/halcogen_vcu/include/FreeRTOSConfig.h
+++ b/VCU/halcogen_vcu/include/FreeRTOSConfig.h
@@ -136,7 +136,7 @@
/* Timers */
#define configUSE_TIMERS 1
-#define configTIMER_TASK_PRIORITY (1)
+#define configTIMER_TASK_PRIORITY (3)
#define configTIMER_QUEUE_LENGTH 10 // We have two timer tasks - added by jjkhan
#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE*2) // Fixed by jjkhan -> Without Task Stack Depth, no task will be created.
diff --git a/command-line/test_phantom_encode.py b/command-line/test_phantom_encode.py
index 5f4d97ca..42a93a52 100644
--- a/command-line/test_phantom_encode.py
+++ b/command-line/test_phantom_encode.py
@@ -23,7 +23,7 @@ def latency_checker(a1, a2, response, sleep_ms):
def test_throttle_output(i=320, latency_checker=lambda *args: None):
ret = []
- board = serial.Serial(port=sys.argv[1])
+ board = serial.Serial(port=sys.argv[1], baudrate=460800)
n = 0
while True:
@@ -43,7 +43,7 @@ def test_throttle_output(i=320, latency_checker=lambda *args: None):
response = board.read_all().decode()
ret.append(response)
- assert throttle_output_on_startup[n] in response, f'{throttle_output_on_startup[n]=} not in {response=}'
+ assert f'throttle={throttle_output_on_startup[n]}' in response, f'throttle={throttle_output_on_startup[n]} not in {response=}'
latency_checker(a1, a2, response)
@@ -106,6 +106,6 @@ def send_output(apps1: Iterable, apps2: Iterable):
if __name__ == '__main__':
- print(test_throttle_output())
+ print('\n'.join(test_throttle_output()))
# print(send_output(APPS_RANGES[0], APPS_RANGES[1]))
\ No newline at end of file