Skip to content

Commit

Permalink
FSM Setup for Quadruna (#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
liam-ilan authored Jan 30, 2024
1 parent fa1219c commit e79ee1f
Show file tree
Hide file tree
Showing 35 changed files with 4,409 additions and 3 deletions.
48 changes: 46 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
},
{
"name": "Debug Embedded: FSM",
"name": "Debug Embedded: FSM (Thruna)",
"cwd": "${workspaceRoot}",
"executable": "build_fw_deploy/firmware/thruna/FSM/FSM.hex",
"symbolFiles": [
Expand Down Expand Up @@ -91,6 +91,36 @@
]
},
},
{
"name": "Debug Embedded: FSM (Quadruna)",
"cwd": "${workspaceRoot}",
"executable": "build_fw_deploy/firmware/quadruna/FSM/FSM.hex",
"symbolFiles": [
// This order matters, or RTT won't work! (app has to be last)
"build_fw_deploy/firmware/boot/f4boot/FSM_boot.elf",
"build_fw_deploy/firmware/quadruna/FSM/FSM_app.elf",
],
"request": "launch",
"type": "cortex-debug",
"servertype": "openocd",
"configFiles": [
"tools/openocd/stm32f4x.cfg"
],
"showDevDebugOutput": "none",
"preLaunchTask": "Build: FSM",
"rttConfig": {
"enabled": true,
"address": "auto",
"clearSearch": false, // Required for OpenOCD
"decoders": [
{
"label": "Debug logs: FSM",
"port": 0,
"type": "console"
}
]
},
},
{
"name": "Debug Embedded: PDM",
"cwd": "${workspaceRoot}",
Expand Down Expand Up @@ -248,7 +278,7 @@
}
},
{
"name": "Debug Tests: FSM",
"name": "Debug Tests: FSM (Thruna)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/build_fw_test/firmware/thruna/FSM/FSM_test",
Expand All @@ -261,6 +291,20 @@
"MIMode": "lldb"
}
},
{
"name": "Debug Tests: FSM (Quadruna)",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/build_fw_test/firmware/quadruna/FSM/FSM_test",
"cwd": "${workspaceRoot}",
"preLaunchTask": "Build: FSM_test",
"linux": {
"MIMode": "gdb"
},
"osx": {
"MIMode": "lldb"
}
},
{
"name": "Debug Tests: PDM",
"type": "cppdbg",
Expand Down
19 changes: 19 additions & 0 deletions can_bus/quadruna/FSM/FSM_alerts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"warnings_id": 303,
"faults_id": 304,
"warnings_counts_id": 305,
"faults_counts_id": 306,
"warnings": [
"WatchdogTimeout",
"TxOverflow",
"RxOverflow",
"StackWaterMarkHighTask1Hz",
"StackWaterMarkHighTask100Hz",
"StackWaterMarkHighTask1kHz",
"StackWaterMarkHighTaskCanRx",
"StackWaterMarkHighTaskCanTx"
],
"faults": [
"DummyFault"
]
}
6 changes: 6 additions & 0 deletions can_bus/quadruna/FSM/FSM_enum.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"FSMState": {
"FSM_INIT_STATE": 0,
"FSM_DRIVE_STATE": 1
}
}
4 changes: 4 additions & 0 deletions can_bus/quadruna/FSM/FSM_rx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"messages": [
]
}
47 changes: 47 additions & 0 deletions can_bus/quadruna/FSM/FSM_tx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"Vitals": {
"msg_id": 300,
"cycle_time": 100,
"description": "FSM vitals message.",
"signals": {
"Heartbeat": {
"bits": 1
},
"State": {
"enum": "FSMState"
}
}
},
"AlertsContext": {
"msg_id": 301,
"cycle_time": 1000,
"description": "Context info for FSM alerts",
"signals": {
"WatchdogTimeout": {
"bits": 1
},
"WatchdogTimeoutTaskName": {
"enum": "RtosTaskName"
},
"TxOverflowCount": {
"bits": 8
},
"RxOverflowCount": {
"bits": 8
}
}
},
"CommitInfo": {
"msg_id": 302,
"cycle_time": 100,
"description": "FSM Current Running Git Commit Info",
"signals": {
"Hash": {
"bits": 32
},
"Clean": {
"bits": 1
}
}
}
}
2 changes: 1 addition & 1 deletion firmware/quadruna/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# add_subdirectory(BMS)
# add_subdirectory(FSM)
add_subdirectory(FSM)
add_subdirectory(VC)
# add_subdirectory(DIM)
146 changes: 146 additions & 0 deletions firmware/quadruna/FSM/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
set(ARM_CORE "cm4")
set(IOC_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/cubemx/FSM.ioc")
set(LINKER_SCRIPT "${LINKER_DIR}/stm32f412rgtx/stm32f412rgtx_app.ld")

# app
file(GLOB_RECURSE APP_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/app/*.c")
list(APPEND APP_SRCS
"${SHARED_APP_INCLUDE_DIR}/app_stateMachine.c"
"${SHARED_APP_INCLUDE_DIR}/app_heartbeatMonitor.c"
"${SHARED_APP_INCLUDE_DIR}/app_rangeCheck.c"
"${SHARED_APP_INCLUDE_DIR}/app_signal.c"
"${SHARED_APP_INCLUDE_DIR}/app_timer.c"
)
set(APP_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src/app" "${SHARED_APP_INCLUDE_DIR}")

# io
file(GLOB_RECURSE IO_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/src/io/*.c")
list(APPEND IO_SRCS
"${SHARED_IO_INCLUDE_DIR}/io_can.c"
"${SHARED_IO_INCLUDE_DIR}/io_jsoncan.c"
"${SHARED_IO_INCLUDE_DIR}/io_time.c"
)
set(IO_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src/io" "${SHARED_IO_INCLUDE_DIR}")

# hw
file(GLOB_RECURSE HW_SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/src/hw/*.c"
"${CMAKE_CURRENT_SOURCE_DIR}/src/*.c"
"${CMAKE_CURRENT_SOURCE_DIR}/src/cubemx/Src/*.c"
)
list(APPEND HW_SRCS
"${SHARED_HW_INCLUDE_DIR}/hw_hardFaultHandler.c"
"${SHARED_HW_INCLUDE_DIR}/hw_adcConversions.c"
"${SHARED_HW_INCLUDE_DIR}/hw_can.c"
"${SHARED_HW_INCLUDE_DIR}/hw_bootup.c"
"${SHARED_HW_INCLUDE_DIR}/hw_pwmInputFreqOnly.c"
"${SHARED_HW_INCLUDE_DIR}/hw_watchdog.c"
"${SHARED_HW_INCLUDE_DIR}/hw_stackWaterMark.c"
# "${SHARED_EMBEDDED_DIR}/hw/hw_uart.c" # TODO: add back when uart finalized
)
set(HW_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src/hw" "${CMAKE_CURRENT_SOURCE_DIR}/src" "${SHARED_HW_INCLUDE_DIR}")

# tests
file(GLOB_RECURSE TEST_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/test/*.cpp")
set(TEST_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/test")
list(APPEND TEST_INCLUDE_DIRS "${SHARED_TEST_UTILS_INCLUDE_DIRS}")

# commit info
set(COMMIT_INFO_HEADER_PATH "${CMAKE_CURRENT_BINARY_DIR}/app/app_commitInfo.h")
set(COMMIT_INFO_SRC_PATH "${CMAKE_CURRENT_BINARY_DIR}/app/app_commitInfo.c")

if("${TARGET}" STREQUAL "deploy")
jsoncan_library(
"FSM_can"
"FSM"
"${CMAKE_CURRENT_BINARY_DIR}"
TRUE
"quadruna"
)
embedded_library(
FSM_can
"${CAN_SRCS}"
"${CAN_INCLUDE_DIRS}"
"${ARM_CORE}"
TRUE
)
generate_stm32cube_code(
"FSM"
"${IOC_PATH}"
)

set(STM32_HAL_SRCS
"stm32f4xx_hal_adc_ex.c"
"stm32f4xx_hal_adc.c"
"stm32f4xx_hal_cortex.c"
"stm32f4xx_hal_dma_ex.c"
"stm32f4xx_hal_dma.c"
"stm32f4xx_hal_exti.c"
"stm32f4xx_hal_can.c"
"stm32f4xx_hal_gpio.c"
"stm32f4xx_hal_iwdg.c"
"stm32f4xx_hal_pwr_ex.c"
"stm32f4xx_hal_rcc_ex.c"
"stm32f4xx_hal_rcc.c"
"stm32f4xx_hal_tim_ex.c"
"stm32f4xx_hal_tim.c"
# "stm32f4xx_hal_uart_ex.c" # TODO: add back when uart finalized
"stm32f4xx_hal_uart.c"
"stm32f4xx_hal.c"
)

# Pass syscalls to the cube library so we can build without warnings.
set(SYSCALLS "${CMAKE_CURRENT_SOURCE_DIR}/src/cubemx/Src/syscalls.c")
stm32f412rx_cube_library(
"FSM_stm32cube"
"${CMAKE_CURRENT_SOURCE_DIR}/src/cubemx/Inc"
"${STM32_HAL_SRCS}"
"${SYSCALLS}"
"${IOC_PATH}.md5"
)

set(SRCS ${APP_SRCS} ${IO_SRCS} ${HW_SRCS} ${TASKS_SRCS})
set(INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${IO_INCLUDE_DIRS} ${HW_INCLUDE_DIRS})
embedded_binary(
"FSM"
"${SRCS}"
"${INCLUDE_DIRS}"
"${LINKER_SCRIPT}"
"${ARM_CORE}"
)

commit_info_library(
"FSM.elf"
"FSM_commit_info"
"${COMMIT_INFO_HEADER_PATH}"
"${COMMIT_INFO_SRC_PATH}"
"${ARM_CORE}"
)

target_link_libraries("FSM_can" "FSM_stm32cube")
target_link_libraries("FSM.elf" "FSM_stm32cube" "FSM_can" "FSM_commit_info")

# TODO: embedded_image for boot

elseif("${TARGET}" STREQUAL "test")
jsoncan_library(
"FSM_can"
"FSM"
"${CMAKE_CURRENT_BINARY_DIR}"
FALSE
"quadruna"
)
add_library(FSM_can STATIC "${CAN_SRCS}")
target_include_directories(FSM_can PUBLIC "${CAN_INCLUDE_DIRS}")

# TODO: fake libraries

set(SRCS ${APP_SRCS} ${TEST_SRCS})
set(INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${IO_INCLUDE_DIRS} ${TEST_INCLUDE_DIRS})
compile_gtest_executable(
"FSM_test"
"${SRCS}"
"${INCLUDE_DIRS}"
)
target_link_libraries("FSM_test" "FSM_can" "shared_fakes") # TODO: add fakes here
endif()
4 changes: 4 additions & 0 deletions firmware/quadruna/FSM/src/app/app_globals.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#include "app_globals.h"

Globals fsm_globals;
Globals *const globals = &fsm_globals;
8 changes: 8 additions & 0 deletions firmware/quadruna/FSM/src/app/app_globals.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once

typedef struct
{
int unused;
} Globals;

extern Globals *const globals;
23 changes: 23 additions & 0 deletions firmware/quadruna/FSM/src/app/states/app_driveState.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "states/app_driveState.h"
#include "app_stateMachine.h"

static void driveStateRunOnEntry(void) {}

static void driveStateRunOnTick1Hz(void) {}

static void driveStateRunOnTick100Hz(void) {}

static void driveStateRunOnExit(void) {}

const State *app_driveState_get()
{
static State drive_state = {
.name = "DRIVE",
.run_on_entry = driveStateRunOnEntry,
.run_on_tick_1Hz = driveStateRunOnTick1Hz,
.run_on_tick_100Hz = driveStateRunOnTick100Hz,
.run_on_exit = driveStateRunOnExit,
};

return &drive_state;
}
9 changes: 9 additions & 0 deletions firmware/quadruna/FSM/src/app/states/app_driveState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "app_stateMachine.h"

/**
* Get a pointer to the Drive State.
* @return A pointer to the Drive State. THIS SHOULD NOT BE MODIFIED.
*/
const State *app_driveState_get(void);
Loading

0 comments on commit e79ee1f

Please sign in to comment.