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
40 changes: 40 additions & 0 deletions .github/workflows/release_artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Include Submodules in Release

on:
release:
types: [published]

jobs:
flatten-release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
submodules: recursive
fetch-depth: 0

- name: Remove submodule metadata
run: |
git submodule foreach --quiet '
echo "Flattening $name at $path..."
git rm --cached -r "$path" || true
rm -rf ".git/modules/$path"
'
rm -f .gitmodules

- name: Create release zip
run: |
REPO_NAME=${{ github.event.repository.name }}
TAG_NAME=${{ github.event.release.tag_name }}
ZIP_NAME="${REPO_NAME}-${TAG_NAME}.zip"
echo "Creating zip: $ZIP_NAME"
zip -r "$ZIP_NAME" . -x ".git/*" -x ".github/*"
echo "ZIP created: $ZIP_NAME"

- name: Upload zip to release
uses: softprops/action-gh-release@v2
with:
files: "${{ github.event.repository.name }}-${{ github.event.release.tag_name }}.zip"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 0 additions & 15 deletions .vscode/launch.json

This file was deleted.

55 changes: 24 additions & 31 deletions Firmware/Drivers/Inc/ADC_Sense.h
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
#pragma once

#include "inits.h"
#include "queue.h"
#include "UART.h"
#include "ADC.h"
#include "ADC_Battery_LUT.h"
#include "ADC_Motor_LUT.h"
#include "FaultBits.h"
#include "UART.h"
#include "queue.h"

// ADC Channel 11 (Motor Voltage) and 12 (Battery Voltage) are GPIOB 12 and 2
#define ADC1_CHANNEL ADC_CHANNEL_11
#define ADC2_CHANNEL ADC_CHANNEL_12
#define ADC_QUEUE_LENGTH 4
#define ADC1_CHANNEL ADC_CHANNEL_11
#define ADC2_CHANNEL ADC_CHANNEL_12
#define ADC_QUEUE_LENGTH 4
#define ADC_QUEUE_ITEM_SIZE sizeof(uint16_t)
#define ADC_SAMPLING_TIME ADC_SAMPLETIME_2CYCLES_5
#define ADC_SAMPLING_TIME ADC_SAMPLETIME_2CYCLES_5

/**
* @brief ADC Initialization Function
* @param adcHandle Pointer to ADC handle struct
* @retval None
*/
void HAL_ADC_MspInit(ADC_HandleTypeDef *adcHandle);

Expand All @@ -27,40 +26,36 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef *adcHandle);
*
* Contains scaled motor and battery voltages in millivolts.
*/
typedef struct
{
uint32_t Motor_Voltage;
uint32_t Battery_Voltage;
typedef struct {
uint32_t Motor_Voltage;
uint32_t Battery_Voltage;
} ADC_Sense_Result;

/**
* @brief ADC sense function return status
*/
typedef enum
{
ADC_SENSE_OK = 0, // Operation successful
ADC_QUEUE_ERR, // Queue creation failed
ADC_1_INIT_ERR, // ADC1 initialization failed
ADC_2_INIT_ERR, // ADC2 initialization failed
ADC_1_READ_ERR, // ADC1 read failed
ADC_2_READ_ERR, // ADC2 read failed
ADC_SENSE_INIT_ERR, // Initialization not called or failed
READ_ADC_BAD_PARAM_ERR, // Bad result parameter
MOTOR_QUEUE_RECEIVE_ERR, // ADC values not received from motor ADC queue
BATTERY_QUEUE_RECEIVE_ERR // ADC values not received from battery ADC queue
typedef enum {
ADC_SENSE_OK = 0, // Operation successful
ADC_QUEUE_ERR, // Queue creation failed
ADC_1_INIT_ERR, // ADC1 initialization failed
ADC_2_INIT_ERR, // ADC2 initialization failed
ADC_1_READ_ERR, // ADC1 read failed
ADC_2_READ_ERR, // ADC2 read failed
ADC_SENSE_INIT_ERR, // Initialization not called or failed
READ_ADC_BAD_PARAM_ERR, // Bad result parameter
MOTOR_QUEUE_RECEIVE_ERR, // ADC values not received from motor ADC queue
BATTERY_QUEUE_RECEIVE_ERR // ADC values not received from battery ADC queue
} ADC_Sense_Status_t;

/**
* @brief Initialize ADC1 struct and calls the wrapper adc_init function to initialize ADC1 peripheral
* @param None
* @retval None
* @brief Initialize ADC1 struct and calls the wrapper adc_init function to initialize ADC1
* peripheral
*/
ADC_Sense_Status_t ADC_1_Init(void);

/**
* @brief Initialize ADC2 struct and calls the wrapper adc_init function to initialize ADC2 peripheral
* @param None
* @retval None
* @brief Initialize ADC2 struct and calls the wrapper adc_init function to initialize ADC2
* peripheral
*/
ADC_Sense_Status_t ADC_2_Init(void);

Expand Down Expand Up @@ -89,13 +84,11 @@ ADC_Sense_Status_t Read_ADC(uint32_t Timeout_MS, ADC_Sense_Result *Result);
/**
* @brief ADC1 Initialization Function
* @param None
* @retval None
*/
void MX_ADC1_Init(void);

/**
* @brief ADC2 Initialization Function
* @param None
* @retval None
*/
void MX_ADC2_Init(void);
52 changes: 32 additions & 20 deletions Firmware/Drivers/Inc/CANbus.h
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
#pragma once

#include "stm32xx_hal.h"
#include "CAN_FD.h"

extern FDCAN_HandleTypeDef *hfdcan1;
extern FDCAN_HandleTypeDef *hfdcan3;
#include "stm32xx_hal.h"
#include "MotorCAN_can_msgs.h"
#include "BPSCAN_can_msgs.h"
#include "CarCAN_can_msgs.h"
#include "SteeringCAN_can_msgs.h"

extern FDCAN_HandleTypeDef *motorfdcan;
extern FDCAN_HandleTypeDef *carfdcan;

can_status_t CAN_Init(void);

can_status_t Motor_CANBus_Send(FDCAN_TxHeaderTypeDef *header,
uint8_t data[],
TickType_t delay_ticks);
can_status_t MotorCAN_Init(void);
can_status_t MotorCAN_Send(FDCAN_TxHeaderTypeDef *header, uint8_t data[], TickType_t delay_ticks);
can_status_t MotorCAN_Recv(uint32_t id, FDCAN_RxHeaderTypeDef *header, uint8_t data[],
TickType_t delay_ticks);

can_status_t Motor_CANBus_Receive(uint16_t id,
FDCAN_RxHeaderTypeDef *header,
uint8_t data[],
TickType_t delay_ticks);
can_status_t MotorCAN_Recv_Status(mc_status_t *out, TickType_t delay);
can_status_t MotorCAN_Recv_Velocity(mc_velocitymeasurement_t *out, TickType_t delay);
can_status_t MotorCAN_Recv_Control_Src(set_motor_cmd_src_t *out, TickType_t delay);

can_status_t Car_CANBus_Send(FDCAN_TxHeaderTypeDef *header,
uint8_t data[],
TickType_t delay_ticks);
can_status_t MotorCAN_Send_Drive_Cmd(float velocity, float current, TickType_t delay);
can_status_t MotorCAN_Send_Power_Cmd(float current, TickType_t delay);

can_status_t Car_CANBus_Receive(uint16_t id,
FDCAN_RxHeaderTypeDef *header,
uint8_t data[],
can_status_t CarCAN_Init(void);
can_status_t CarCAN_Send(FDCAN_TxHeaderTypeDef *header, uint8_t data[], TickType_t delay_ticks);
can_status_t CarCAN_Recv(uint32_t id, FDCAN_RxHeaderTypeDef *header, uint8_t data[],
TickType_t delay_ticks);

can_status_t CarCAN_Recv_BPS_Status(bps_status_t *out, TickType_t delay);
can_status_t CarCAN_Recv_LWS(lws_standard_t *out, TickType_t delay);
can_status_t CarCAN_Recv_Driver_Input(driver_input_status_t *out, TickType_t delay);
can_status_t CarCAN_Recv_Pedals_Position(pedal_status_t *out, TickType_t delay);
can_status_t CarCAN_Recv_Brake_Pressure1(brake_pressure_1_t *out, TickType_t delay);
can_status_t CarCAN_Recv_Brake_Pressure2(brake_pressure_2_t *out, TickType_t delay);
can_status_t CarCAN_Recv_Controls_Status(controls_status_t *out, TickType_t delay);
can_status_t CarCAN_Send_Precharge_Voltages(uint32_t motor_mv, uint32_t battery_mv,
TickType_t delay);
can_status_t CarCAN_Send_Drive_Cmd(float velocity, float current, TickType_t delay);

can_status_t CAN_Send_Drive_Cmd(float velocity, float current, TickType_t delay);


/* HAL MSP hooks implemented in CANbus.c */
void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *fdcanHandle);
void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle);
void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *fdcanHandle);
39 changes: 21 additions & 18 deletions Firmware/Drivers/Inc/Contactors.h
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
#pragma once
#pragma once

#include "inits.h"

/* Timing Definitions */
/** Time to wait for the physical contactor to settle before reading feedback */
#define CONTACTOR_SENSE_DELAY pdMS_TO_TICKS(250)
#define CONTACTOR_SENSE_DELAY pdMS_TO_TICKS(250)
/** Maximum time allowed for callback execution to prevent task starvation */
#define CALLBACK_BLOCKING_TIME pdMS_TO_TICKS(20)

/**
* @brief Represents the logical and physical state of a contactor.
*/
typedef enum
{
typedef enum {
OPEN = 0, /**< Circuit is disconnected */
CLOSED = 1 /**< Circuit is connected */
} contactor_state_t;

/**
* @brief Identification for specific contactors within the HV system.
*/
typedef enum
{
typedef enum {
MOTOR_PRE_CONTACTOR, /**< Battery to Motor Contactor */
MOTOR_CONTACTOR, /**< Post-Precharge Bypass Contactor */
NUM_CONTACTORS /**< Total count helper */
Expand All @@ -30,36 +28,41 @@ typedef enum
/**
* @brief Contactor hardware abstraction object.
*/
typedef struct
{
contactor_state_t state; /**< Current state */
GpioPin_t sense_pin; /**< Digital input for auxiliary feedback loop */
GpioPin_t control_pin; /**< Digital output to coil driver/relay */
typedef struct {
contactor_state_t state; /* Current state */
GpioPin_t sense_pin; /* Digital input for auxiliary feedback loop */
GpioPin_t control_pin; /* Digital output to coil driver/relay */

/* RTOS Resources */
TimerHandle_t senseTimer; /**< Handle for non-blocking state verification */
StaticTimer_t senseTimerBuffer; /**< Memory buffer for static timer allocation */
TimerHandle_t senseTimer; /* Handle for non-blocking state verification */
StaticTimer_t senseTimerBuffer; /* Memory buffer for static timer allocation */
} contactor_t;

/** @brief Hardware/RTOS init for all contactors, timers, and mutexes. */
/**
* @brief Hardware/RTOS init for all contactors, timers, and mutexes.
*/
void contactor_init(void);

/** * @brief Reads the physical sense pin for a specific contactor.
/**
* @brief Reads the physical sense pin for a specific contactor.
* @return 1 if CLOSED, 0 if OPEN.
*/
contactor_state_t contactor_get_sense(contactor_num_t contactor_num);

/** * @brief Reads the current logical state for a specific contactor.
/**
* @brief Reads the current logical state for a specific contactor.
* @return 1 if CLOSED, 0 if OPEN.
*/
contactor_state_t contactor_get_commanded_state(contactor_num_t contactor_num);

/** * @brief Commands a contactor state change with safety verification via callback function.
/**
* @brief Commands a contactor state change with safety verification via callback function.
* @param wait_ms Wait time for sense delay before returning.
* @param emergency Immediate execution; bypasses safety callbacks.
* @return SUCCESS or hardware ERROR code.
*/
ErrorStatus contactor_set(contactor_num_t contactor_num, contactor_state_t state, uint32_t wait_ms, fault_state_t emergency);
ErrorStatus contactor_set(contactor_num_t contactor_num, contactor_state_t state, uint32_t wait_ms,
fault_state_t emergency);

/** @brief When fault is detected, opens all contactors. */
void contactor_emergency_open_all();
Loading
Loading