Skip to content

Commit

Permalink
Update PR comments, remove pedal/steering projects
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellostler committed May 4, 2024
1 parent 1c0cede commit e34c274
Show file tree
Hide file tree
Showing 24 changed files with 80 additions and 565 deletions.
8 changes: 4 additions & 4 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ if PLATFORM == 'arm' and TARGET:
# flash the MCU using openocd
def flash_run_target(target, source, env):
serialData = flash_run(project_bin)
while True:
line: str = serialData.readline().decode("utf-8")
print(line, end='')
#while True:
# line: str = serialData.readline().decode("utf-8")
# print(line, end='')

AlwaysBuild(Command('#/flash', project_bin, flash_run_target))
AlwaysBuild(Command('#/flash', project_bin, flash_run_target))
8 changes: 4 additions & 4 deletions libraries/ms-drivers/src/seg_display.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ StatusCode seg_displays_init(SegDisplay *display) {
gpio_init_pin(&display->A2, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW);
gpio_init_pin(&display->B2, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW);
gpio_init_pin(&display->C2, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW);
// gpio_init_pin(&display->D2, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_HIGH);
gpio_init_pin(&display->D2, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_HIGH);
gpio_init_pin(&display->A3, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW);
gpio_init_pin(&display->B3, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW);
gpio_init_pin(&display->C3, GPIO_OUTPUT_PUSH_PULL, GPIO_STATE_LOW);
Expand All @@ -38,7 +38,7 @@ void seg_displays_reset(SegDisplay *display) {
gpio_set_state(&display->A2, GPIO_STATE_LOW);
gpio_set_state(&display->B2, GPIO_STATE_LOW);
gpio_set_state(&display->C2, GPIO_STATE_LOW);
// gpio_set_state(&display->D2, GPIO_STATE_LOW);
gpio_set_state(&display->D2, GPIO_STATE_LOW);
gpio_set_state(&display->A3, GPIO_STATE_LOW);
gpio_set_state(&display->B3, GPIO_STATE_LOW);
gpio_set_state(&display->C3, GPIO_STATE_LOW);
Expand All @@ -65,8 +65,8 @@ static void prv_set_seg_displays(SegDisplay *display, uint16_t val1, uint16_t va
state = ((val1 & 1) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW;
gpio_set_state(&display->A1, state);

// state = ((val2 & 8) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW;
// gpio_set_state(&display->D2, state);
state = ((val2 & 8) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW;
gpio_set_state(&display->D2, state);

state = ((val2 & 4) != 0) ? GPIO_STATE_HIGH : GPIO_STATE_LOW;
gpio_set_state(&display->C2, state);
Expand Down
2 changes: 2 additions & 0 deletions projects/bms_carrier/inc/fault_bps.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ StatusCode fault_bps_init(BpsStorage *storage);
StatusCode fault_bps_set(uint8_t fault_bitmask);

StatusCode fault_bps_clear(uint8_t fault_bitmask);

uint8_t fault_bps_get(void);
16 changes: 13 additions & 3 deletions projects/bms_carrier/inc/relays.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@
#include "status.h"
#include "task.h"

#define BMS_CLOSE_RELAYS_DELAY 300
typedef enum RelayType { NO_RELAYS = 0, POS_RELAY, NEG_RELAY, SOLAR_RELAY } RelayType;
#define BMS_CLOSE_RELAYS_DELAY_MS 300

void bms_relay_fault(void);
// Enumerated set of relays to be closed
typedef enum RelayType {
NO_RELAYS = 0,
POS_RELAY,
NEG_RELAY,
SOLAR_RELAY,
RELAY_CHECK,
} RelayType;

// Closes relays in sequence
StatusCode init_bms_relays(void);

// Turns off GPIOs to open relays
void bms_relay_fault(void);
7 changes: 5 additions & 2 deletions projects/bms_carrier/src/fault_bps.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ StatusCode fault_bps_init(BpsStorage *storage) {
return STATUS_CODE_OK;
}

// TODO: These faulting mechanism will be changing substantially
// Fault BPS and open relays
StatusCode fault_bps_set(uint8_t fault_bitmask) {
// NOTE(Mitch): adding log statements in this function may cause hardfault
s_bps_storage->fault_bitset |= (1 << fault_bitmask);
LOG_DEBUG("FAULT_BITMASK: %d\n", fault_bitmask);
if (s_bps_storage->fault_bitset & 0x7) {
s_bps_storage->fault_bitset |= (1 << 15);
} else {
Expand All @@ -27,3 +26,7 @@ StatusCode fault_bps_clear(uint8_t fault_bitmask) {
s_bps_storage->fault_bitset &= ~(1 << fault_bitmask);
return STATUS_CODE_OK;
}

uint8_t fault_bps_get(void) {
return s_bps_storage->fault_bitset;
}
4 changes: 4 additions & 0 deletions projects/bms_carrier/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ void run_medium_cycle() {

void run_slow_cycle() {
cell_discharge(&bms_storage.ltc_afe_storage);

if (fault_bps_get()) {
LOG_DEBUG("FAULT_BITMASK: %d\n", fault_bps_get());
}
}

int main() {
Expand Down
26 changes: 24 additions & 2 deletions projects/bms_carrier/src/relays.c
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
#include "relays.h"

#include "bms.h"

static RelayType relay_toggle = NO_RELAYS;
static SoftTimer relays_timer;

static const GpioAddress pos_relay_en = { .port = GPIO_PORT_B, .pin = 8 };
static const GpioAddress pos_relay_sense = { .port = GPIO_PORT_B, .pin = 5 };
// TODO(mitch) below address does not match schematic but is set when pos relay is on
static const GpioAddress pos_relay_sense = { .port = GPIO_PORT_B, .pin = 7 };

static const GpioAddress neg_relay_en = { .port = GPIO_PORT_B, .pin = 4 };
static const GpioAddress neg_relay_sense = { .port = GPIO_PORT_B, .pin = 3 };

static const GpioAddress solar_relay_en = { .port = GPIO_PORT_C, .pin = 13 };
static const GpioAddress solar_relay_sense = { .port = GPIO_PORT_B, .pin = 9 };

#define NUM_BMS_RELAYS 3
static const GpioAddress s_relays_sense[NUM_BMS_RELAYS] = { pos_relay_sense, neg_relay_sense,
solar_relay_sense };

static void prv_close_relays(SoftTimerId id) {
// 200 MS GAP BETWEEN EACH RELAY BC OF CURRENT DRAW
switch (relay_toggle) {
Expand All @@ -30,14 +37,29 @@ static void prv_close_relays(SoftTimerId id) {
case NEG_RELAY: {
gpio_set_state(&solar_relay_en, GPIO_STATE_HIGH);
relay_toggle = SOLAR_RELAY;
soft_timer_start(&relays_timer);
break;
}
case SOLAR_RELAY: {
GpioState sense_state;
gpio_get_state(&pos_relay_sense, &sense_state);
gpio_get_state(&neg_relay_sense, &sense_state);
gpio_get_state(&solar_relay_sense, &sense_state);
relay_toggle = RELAY_CHECK;
soft_timer_start(&relays_timer);
break;
}
case RELAY_CHECK: {
GpioState sense_state;
for (uint8_t i = 0; i < NUM_BMS_RELAYS; i++) {
gpio_get_state(&s_relays_sense[i], &sense_state);
if (sense_state != GPIO_STATE_HIGH) {
fault_bps_set(BMS_FAULT_RELAY_CLOSE_FAILED);
}
}
break;
}

default:
// FAULT? SHOULD NEVER BE DEFAULT
break;
Expand All @@ -62,7 +84,7 @@ StatusCode init_bms_relays() {
gpio_init_pin(&neg_relay_sense, GPIO_INPUT_FLOATING, GPIO_STATE_LOW);
gpio_init_pin(&solar_relay_sense, GPIO_INPUT_FLOATING, GPIO_STATE_LOW);

soft_timer_init(BMS_CLOSE_RELAYS_DELAY, prv_close_relays, &relays_timer);
soft_timer_init(BMS_CLOSE_RELAYS_DELAY_MS, prv_close_relays, &relays_timer);
set_battery_relay_info_state(EE_RELAY_STATE_CLOSE);
soft_timer_start(&relays_timer);
return STATUS_CODE_OK;
Expand Down
15 changes: 14 additions & 1 deletion projects/centre_console/inc/cc_hw_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,23 @@
{ .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO1_7 }
#define POWER_LED_ADDR \
{ .i2c_address = CC_IO_EXP_ADDR, .pin = PCA9555_PIN_IO0_2 }

#define BPS_LED_ADDR \
{ .port = GPIO_PORT_A, .pin = 10 }

// Steering GPIOs
#define TURN_SIGNAL_GPIO \
{ .port = GPIO_PORT_A, .pin = 6 }
#define CC_CHANGE_GPIO \
{ .port = GPIO_PORT_A, .pin = 7 }
#define CC_TOGGLE_GPIO \
{ .port = GPIO_PORT_B, .pin = 12 }

// Pedal GPIOs
#define BRAKE_LIMIT_SWITCH \
{ .port = GPIO_PORT_B, .pin = 13 }
#define ADC_HALL_SENSOR \
{ .port = GPIO_PORT_A, .pin = 0 }

// Seven Segment display GPIO Addresses
// Aux Batt
#define AUX_DISP1 \
Expand Down
10 changes: 4 additions & 6 deletions projects/centre_console/inc/pedal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@

#include "adc.h"
#include "calib.h"
#include "cc_hw_defs.h"
#include "interrupt.h"
#include "log.h"
#include "pedal_calib.h"
#include "status.h"

#define BRAKE_LIMIT_SWITCH \
{ .port = GPIO_PORT_B, .pin = 13 }

#define ADC_HALL_SENSOR \
{ .port = GPIO_PORT_A, .pin = 0 }

// Runs a pedal cycle to update throttle and brake values
void pedal_run();

// Initializes pedal peripherals
// Must be called before adc_init
StatusCode pedal_init(PedalCalibBlob *calib_blob);
12 changes: 3 additions & 9 deletions projects/centre_console/inc/steering.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "adc.h"
#include "can.h"
#include "cc_hw_defs.h"
#include "gpio.h"
#include "gpio_it.h"
#include "gpio_mcu.h"
Expand All @@ -18,15 +19,6 @@
#define CRUISE_CONTROl_STALK_SPEED_DECREASE_VOLTAGE_MV 775
#define CRUISE_CONTROl_STALK_NEUTRAL_VOLTAGE_MV 3300

#define TURN_SIGNAL_GPIO \
{ .port = GPIO_PORT_A, .pin = 6 }

#define CC_CHANGE_GPIO \
{ .port = GPIO_PORT_A, .pin = 7 }

#define CC_TOGGLE_GPIO \
{ .port = GPIO_PORT_B, .pin = 12 }

#define CC_TOGGLE_EVENT 0x0

// TurnSignal Values for each state
Expand All @@ -42,9 +34,11 @@ typedef enum {
CC_INCREASE_MASK = 0x02,
CC_TOGGLE_MASK = 0x04,
} CruiseControlMask;

// Initializes the ADC input for the ctrl stalk as well as the gpio interrupt for the toggle
// Must be called before adc_init()
StatusCode steering_init();

// Reads the analog input, determines a light state, and sets the requisite value in the can message
// Also reads the toggle notification state and sets the requisite value in the can message
void steering_input();
3 changes: 2 additions & 1 deletion projects/centre_console/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ int main() {
LOG_DEBUG("Welcome to TEST! \n");

init_master_task();
// display_init();
// display_ini();
tasks_start();
display_init();

LOG_DEBUG("exiting main? \n");
return 0;
Expand Down
16 changes: 0 additions & 16 deletions projects/pedal/README.md

This file was deleted.

14 changes: 0 additions & 14 deletions projects/pedal/config.json

This file was deleted.

24 changes: 0 additions & 24 deletions projects/pedal/inc/pedal.h

This file was deleted.

52 changes: 0 additions & 52 deletions projects/pedal/src/main.c

This file was deleted.

Loading

0 comments on commit e34c274

Please sign in to comment.