Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
[submodule "src/Middlewares/SUFST/can-defs"]
path = src/Middlewares/SUFST/can-defs
url = https://github.com/sufst/can-defs
branch = feat/vcu-power-save-mode
60 changes: 56 additions & 4 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,54 @@
{
"configurations": [
{
"name": "arm-none-eabi-gcc (Linux)",
"compileCommands": [
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/compile_commands.json"
],
"includePath": [
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/SUFST/Inc",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/SUFST/Inc/Functions",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Core/Inc",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Drivers/STM32F7xx_HAL_Driver/Inc",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Drivers/CMSIS/Device/ST/STM32F7xx/Include",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Drivers/CMSIS/**",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Middlewares/ST/threadx/common/inc",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Middlewares/ST/threadx/ports/cortex_m7/gnu/inc",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Drivers/STM32F7xx_HAL_Driver/Inc"
],
"defines": [
"TX_INCLUDE_USER_DEFINE_FILE",
"USE_HAL_DRIVER",
"STM32F746xx"
],
"cStandard": "gnu11",
"intelliSenseMode": "gcc-arm",
"configurationProvider": "ms-vscode.makefile-tools",
"compileCommandsInCppPropertiesJson": [
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/compile_commands.json"
],
"configurationProviderInCppPropertiesJson": "ms-vscode.makefile-tools",
"mergeConfigurations": false,
"browse": {
"path": [
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/SUFST/Inc",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Core/Inc",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Drivers/STM32F7xx_HAL_Driver/Inc",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Drivers/CMSIS/Device/ST/STM32F7xx/Include",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Drivers/CMSIS/**",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Middlewares/ST/threadx/common/inc",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Middlewares/ST/threadx/ports/cortex_m7/gnu/inc",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu/src/Drivers/STM32F7xx_HAL_Driver/Inc",
"/home/r_kirkbride/Documents/GitHub/sufst/vcu"
],
"limitSymbolsToIncludedHeaders": true
},
"compilerPath": "/usr/bin/arm-none-eabi-gcc",
"compilerPathInCppPropertiesJson": "/usr/bin/arm-none-eabi-gcc"
},
{
"name": "arm-none-eabi-gcc (macOS)",
"compileCommands": "${workspaceFolder}/compile_commands.json",
"compileCommands": ["${workspaceFolder}/compile_commands.json"],
"includePath": [
"${workspaceFolder}/src/SUFST/Inc",
"${workspaceFolder}/src/Core/Inc",
Expand All @@ -12,7 +58,12 @@
"${workspaceFolder}/src/Middlewares/ST/threadx/common/inc",
"${workspaceFolder}/src/Middlewares/ST/threadx/ports/cortex_m7/gnu/inc",
"${workspaceFolder}/src/SUFST/Inc/CAN",
"${workspaceFolder}/src/Drivers/STM32F7xx_HAL_Driver/Inc"
"${workspaceFolder}/src/Drivers/STM32F7xx_HAL_Driver/Inc",
"${workspaceFolder}/src/Middlewares/SUFST/rtcan/inc",
"${workspaceFolder}/src/SUFST/Inc/Interfaces",
"${workspaceFolder}/src/SUFST/Inc/Functions",
"${workspaceFolder}/src/SUFST/Inc/Services",
"${workspaceFolder}/src/Middlewares/SUFST/can-defs/out"
],
"defines": [
"TX_INCLUDE_USER_DEFINE_FILE",
Expand All @@ -21,11 +72,12 @@
],
"cStandard": "gnu11",
"intelliSenseMode": "gcc-arm",
"configurationProvider": "ms-vscode.makefile-tools"
"configurationProvider": "ms-vscode.makefile-tools",
"compilerPath": "/usr/bin/arm-none-eabi-gcc"
},
{
"name": "arm-none-eabi-gcc (Windows)",
"compileCommands": "${workspaceFolder}/compile_commands.json",
"compileCommands": ["${workspaceFolder}/compile_commands.json"],
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/src/Drivers/**"
Expand Down
8 changes: 5 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@
"status.h": "c",
"torque_map_funcs.h": "c",
"rtds.h": "c",
"pm100.h": "c"
"pm100.h": "c",
"canrx.h": "c"
},
"cortex-debug.variableUseNaturalFormat": true,
"C_Cpp.errorSquiggles": "Enabled",
"mcu-debug.rtos-views.showRTOS": false
"C_Cpp.errorSquiggles": "enabled",
"mcu-debug.rtos-views.showRTOS": false,
"C_Cpp.default.compilerPath": "arm-none-eabi-gcc"
}
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ src/SUFST/Src/Interfaces/rtds.c \
src/SUFST/Src/Interfaces/scs.c \
src/SUFST/Src/Interfaces/trc.c \
src/SUFST/Src/Services/canbc.c \
src/SUFST/Src/Services/canrx.c \
src/SUFST/Src/Services/ctrl.c \
src/SUFST/Src/Services/dash.c \
src/SUFST/Src/Services/pm100.c \
Expand Down
2 changes: 1 addition & 1 deletion src/Middlewares/SUFST/can-defs
10 changes: 9 additions & 1 deletion src/SUFST/Inc/Functions/torque_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ typedef struct _torque_map_t
uint16_t deadzone_end; // end of deadzone
float deadzone_scale; // scale factor for inputs
const config_torque_map_t* config_ptr; // configuration
uint16_t output_max;
uint16_t
limit_min; // minimum Torque request at the end of the limit (Nm *10)
uint8_t limit_start; // BMS temp to start limiting torque (Celcius)
uint8_t limit_end; // BMS temp for maximum toque limiting (Celcius)
} torque_map_t;

/*
* public functions
*/
status_t torque_map_init(torque_map_t* map_ptr,
const config_torque_map_t* config_ptr);
uint16_t torque_map_apply(torque_map_t* map_ptr, uint16_t input);
uint16_t torque_map_apply(torque_map_t* map_ptr,
uint16_t input,
uint8_t bms_temp,
bool* power_saving);

#endif
2 changes: 1 addition & 1 deletion src/SUFST/Inc/Interfaces/scs.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef struct
uint32_t max_bounds_diff; // cached bounds difference for validation
const config_scs_t* config_ptr; // configuration
status_t status;
status_t status_verbose;
scs_status_t status_verbose;
} scs_t;

/*
Expand Down
56 changes: 56 additions & 0 deletions src/SUFST/Inc/Services/canrx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/******************************************************************************
* @file canrx.h
* @author Robert Kirkbride (@r-kirkbride, rgak1g24@soton.ac.uk)
* @brief Can Listener Service
* @details This service is responsible for listening for CAN messages required
* by other services
*****************************************************************************/

#ifndef CANRX_H
#define CANRX_H

#include <can_s.h>
#include <rtcan.h>
#include <stdint.h>
#include <tx_api.h>

#include "config.h"
#include "log.h"
#include "status.h"

#define CANRX_QUEUE_SIZE 10 // 10 items

#define CANRX_ERROR_NONE 0x00 // no errors
#define CANRX_ERROR_INIT 0x01 // initialisation error
#define CANRX_ERROR_BROADCAST_TIMEOUT 0x02 // no broadcasts received
#define CANRX_ERROR_POST_FAULT 0x04 // power-on self-test fault
#define CANRX_ERROR_RUN_FAULT 0x08 // runtime fault

/**
* @brief CANRX context
*/
typedef struct
{
TX_THREAD thread;
rtcan_handle_t* rtcan_c_ptr;
rtcan_handle_t* rtcan_s_ptr;
TX_QUEUE can_c_rx_queue;
TX_QUEUE can_s_rx_queue;
ULONG can_rx_queue_mem[CANRX_QUEUE_SIZE];
TX_MUTEX state_mutex;
bool broadcasts_valid;
struct can_s_msgid_0_x202_t msgid_x202;
uint16_t error;
const config_canrx_t* config_ptr;
} canrx_context_t;

/*
* public functions
*/
status_t canrx_init(canrx_context_t* canrx_ptr,
rtcan_handle_t* rtcan_c_ptr,
rtcan_handle_t* rtcan_s_ptr,
TX_BYTE_POOL* stack_pool_ptr,
const config_canrx_t* config_ptr);

#endif
5 changes: 5 additions & 0 deletions src/SUFST/Inc/Services/ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "apps.h"
#include "bps.h"
#include "canbc.h"
#include "canrx.h"
#include "config.h"
#include "dash.h"
#include "log.h"
Expand Down Expand Up @@ -67,10 +68,12 @@ typedef struct
int16_t motor_temp;
int16_t inv_temp;
int8_t max_temp;
uint8_t bms_temp;

bool inverter_pwr;
bool pump_pwr;
bool fan_pwr;
bool power_saving;

uint32_t neg_air_start;
uint32_t precharge_start; // precharge start time in ticks
Expand All @@ -80,6 +83,7 @@ typedef struct
dash_context_t* dash_ptr; // dash service
pm100_context_t* pm100_ptr; // PM100 service
canbc_context_t* canbc_ptr; // CANBC service
canrx_context_t* canrx_ptr; // CANRX service
tick_context_t* tick_ptr; // tick thread (reads certain sensors)
torque_map_t torque_map; // torque map (APPS -> torque request)

Expand All @@ -98,6 +102,7 @@ status_t ctrl_init(ctrl_context_t* ctrl_ptr,
pm100_context_t* pm100_ptr,
tick_context_t* tick_ptr,
canbc_context_t* canbc_ptr,
canrx_context_t* canrx_ptr,
TX_BYTE_POOL* stack_pool_ptr,
const config_ctrl_t* config_ptr,
const config_rtds_t* rtds_config_ptr,
Expand Down
12 changes: 12 additions & 0 deletions src/SUFST/Inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ typedef struct {
uint16_t input_max; // maximum input value (range must be zero to max)
uint16_t output_max; // maximum output value (Nm * 10)
float deadzone_fraction; // fraction of input range for deadzone
uint16_t limit_min; // minimum Torque request at the end of the limit (Nm *10)
uint8_t limit_start; // BMS temp to start limiting torque (Celcius)
uint8_t limit_end; // BMS temp for maximum toque limiting (Celcius)
} config_torque_map_t;

/**
Expand All @@ -128,6 +131,14 @@ typedef struct {
uint32_t broadcast_period_ticks; // ticks between broadcasts
} config_canbc_t;

/**
* @brief CAN recieving service
*/
typedef struct {
config_thread_t thread; // CANRX thread config
uint32_t broadcast_timeout_ticks; // maximum number of ticks to wait for a broadcast
} config_canrx_t;

typedef struct
{
config_thread_t thread; // thread config
Expand Down Expand Up @@ -197,6 +208,7 @@ typedef struct {
config_pm100_t pm100;
config_tick_t tick;
config_canbc_t canbc;
config_canrx_t canrx;
config_heartbeat_t heartbeat;
config_log_t log;
config_rtos_t rtos;
Expand Down
25 changes: 13 additions & 12 deletions src/SUFST/Inc/vcu.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#include "heartbeat.h"
#include "log.h"
#include "pm100.h"
#include "tick.h"
#include "status.h"
#include "tick.h"

/**
* @brief VCU context
Expand All @@ -30,17 +30,18 @@
*/
typedef struct
{
rtcan_handle_t rtcan_s; // RTCAN service for sensors CAN bus
rtcan_handle_t rtcan_c; // RTCAN service for critical systems CAN bus
canbc_context_t canbc; // CAN broadcasting service instance
dash_context_t dash; // dash service
ctrl_context_t ctrl; // control service
pm100_context_t pm100; // PM100 service
tick_context_t tick;
heartbeat_context_t heartbeat; // heartbeat service
log_context_t log; // logging service
uint32_t err; // current error code
const config_t* config_ptr; // pointer to global VCU configuration
rtcan_handle_t rtcan_s; // RTCAN service for sensors CAN bus
rtcan_handle_t rtcan_c; // RTCAN service for critical systems CAN bus
canbc_context_t canbc; // CAN broadcasting service instance
canrx_context_t canrx; // CAN recieving service instance
dash_context_t dash; // dash service
ctrl_context_t ctrl; // control service
pm100_context_t pm100; // PM100 service
tick_context_t tick;
heartbeat_context_t heartbeat; // heartbeat service
log_context_t log; // logging service
uint32_t err; // current error code
const config_t* config_ptr; // pointer to global VCU configuration

} vcu_context_t;

Expand Down
Loading