Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mc integration test #230

Merged
merged 40 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
bc14764
add test file
ShiCheng-Lu Sep 23, 2023
387b741
add integration test
ShiCheng-Lu Sep 24, 2023
c3f8fd0
add tests
ShiCheng-Lu Oct 5, 2023
c117f82
add mcp2515 can rx test template
ShiCheng-Lu Oct 6, 2023
ab834b1
add motor can rx tests
ShiCheng-Lu Oct 6, 2023
d8d3d70
remove unused can msgs
ShiCheng-Lu Oct 7, 2023
b67732d
improve mcp2515_hw
ShiCheng-Lu Oct 10, 2023
78f106c
mcp2515 use rx buffer full interrupt pins
ShiCheng-Lu Oct 29, 2023
3753f70
Merge branch 'main' into mc-integration-test
ShiCheng-Lu Nov 4, 2023
9fcf3d3
update spi test
mitchellostler Nov 5, 2023
c034d00
add test for mcp2515 init
ShiCheng-Lu Nov 5, 2023
7298d05
use spi_tx in mcp2515 transmit where rx is not needed
ShiCheng-Lu Nov 5, 2023
2905cc7
change mcp2515 id regs
ShiCheng-Lu Nov 5, 2023
999c1e5
add test for rx message
ShiCheng-Lu Nov 6, 2023
7a6631e
remove unused logs
ShiCheng-Lu Nov 6, 2023
59226ff
remove debugging code
ShiCheng-Lu Nov 6, 2023
9ad1375
add back precharged_completed message
ShiCheng-Lu Nov 6, 2023
8cc1583
tmp
mitchellostler Nov 11, 2023
b650f17
spi working
ShiCheng-Lu Nov 11, 2023
e237eaa
spi_tx as wrapper for spi_exchange
ShiCheng-Lu Nov 11, 2023
9bc99ab
fix test mock functions
ShiCheng-Lu Nov 12, 2023
f393a13
Merge branch 'main' into mc-integration-test
ShiCheng-Lu Nov 12, 2023
0567e98
change x86 implementation of spi to match arm version
ShiCheng-Lu Nov 12, 2023
6f30724
Merge branch 'mci_validation' into mc-integration-test
ShiCheng-Lu Nov 12, 2023
37c9806
validate mcp2515
ShiCheng-Lu Nov 12, 2023
1670a3b
only allow cruise in drive state
ShiCheng-Lu Dec 16, 2023
5b8d736
working spi mode 3?
ShiCheng-Lu Jan 14, 2024
50217f2
spi mode 0 and 3 working
ShiCheng-Lu Jan 14, 2024
261a45c
broken
ShiCheng-Lu Jan 24, 2024
75c9744
working
ShiCheng-Lu Jan 24, 2024
ce08c2a
working precharge
ShiCheng-Lu Jan 24, 2024
10c0edd
add can.py to git ignore
ShiCheng-Lu Jan 24, 2024
9027e4b
Merge branch 'main' into mc-integration-test
ShiCheng-Lu Jan 24, 2024
ee34e7f
cleanup
ShiCheng-Lu Jan 24, 2024
aeb3acb
fixed spi x86 test code
ShiCheng-Lu Jan 26, 2024
bef99bb
cleanup
ShiCheng-Lu Jan 26, 2024
d410c22
Merge branch 'main' into mc-integration-test
ShiCheng-Lu Feb 7, 2024
bdaaf41
Mc on motor (#267)
ShiCheng-Lu Mar 29, 2024
beb34bf
revert led test, remove #define SPI_QUEUE_DELAY_MS 10
ShiCheng-Lu Apr 11, 2024
58be33e
remove trains track
ShiCheng-Lu Apr 11, 2024
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ __pycache__
*can_board_ids.h
*system_can.dbc
x86_flash

py/can/can.py
py/can/messages.py
24 changes: 2 additions & 22 deletions libraries/codegen/boards/motor_controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@
velocity_r:
length: 16

motor_status:
id: 37
target:
centre_console:
watchdog: 0
signals:
motor_status_l:
length: 32
motor_status_r:
length: 32

motor_sink_temps:
id: 38
target:
Expand All @@ -69,9 +58,9 @@
watchdog: 0
signals:
dsp_temp_l:
length: 32
length: 16
dsp_temp_r:
length: 32
length: 16

mc_status:
id: 40
Expand All @@ -95,12 +84,3 @@
length: 8
precharge_status:
length: 8

precharge_completed:
id: 16
target:
centre_console:
watchdog: 0
signals:
notification:
length: 8
6 changes: 5 additions & 1 deletion libraries/codegen/boards/steering.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Message Definitions in plaintext are on the wiki at:
# https://uwmidsun.atlassian.net/l/cp/Pxn8Xhm8
# https://uwmidsun.atlassian.net/wiki/spaces/ELEC/pages/50003973/CAN+Message+Definitions
#
# If you are making changes to this file please update the corresponding entry
# on the wiki. If you need to add a new message use a reasonable
Expand All @@ -24,3 +24,7 @@ Messages:
length: 8 # (cc_toggle | cc_increade | cc_decrease)
input_lights:
length: 8
digital_input:
length: 8
analog_input:
length: 8
12 changes: 7 additions & 5 deletions libraries/master/src/master_task.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "master_task.h"

static uint32_t MASTER_MS_CYCLE_TIME = 100;
static uint32_t MASTER_MS_CYCLE_TIME = 50;

#define MASTER_TASK_PRIORITY (configMAX_PRIORITIES - 2)
#define MAX_CYCLES_OVER 5
Expand All @@ -26,10 +26,12 @@ uint8_t get_cycles_over() {
}
#endif

void run_fast_cycle();
void run_medium_cycle();
void run_slow_cycle();
void pre_loop_init();
void master_no_op() {}

void run_fast_cycle() __attribute__((weak, alias("master_no_op")));
void run_medium_cycle() __attribute__((weak, alias("master_no_op")));
void run_slow_cycle() __attribute__((weak, alias("master_no_op")));
void pre_loop_init() __attribute__((weak, alias("master_no_op")));

void check_late_cycle(BaseType_t delay) {
if (delay != pdTRUE) {
Expand Down
6 changes: 3 additions & 3 deletions libraries/ms-common/inc/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ StatusCode spi_init(SpiPort spi, const SpiSettings *settings);
StatusCode spi_exchange(SpiPort spi, uint8_t *tx_data, size_t tx_len, uint8_t *rx_data,
size_t rx_len);

#ifdef x86
#ifdef MS_PLATFORM_X86
// Reads data from the tx buffer into data
StatusCode spi_get_tx(uint8_t *data, uint8_t len);
StatusCode spi_get_tx(SpiPort spi, uint8_t *data, uint8_t len);

// Writes from data into the rx buffer
StatusCode spi_set_rx(uint8_t *data, uint8_t len);
StatusCode spi_set_rx(SpiPort spi, uint8_t *data, uint8_t len);
#endif
9 changes: 4 additions & 5 deletions libraries/ms-common/src/callback_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ Event prv_find_next_event() {
}
// Gets index of least significant 0 bit (first available event)
Event event = __builtin_ctz(~s_registered_callbacks);

return event;
}

Expand Down Expand Up @@ -96,13 +95,13 @@ Event register_callback(CallbackFn cb, void *context) {
TASK(callback_task, TASK_STACK_512) {
uint32_t notification = 0;
Event event = 0;
StatusCode notification_status;
while (true) {
notify_wait(&notification, BLOCK_INDEFINITELY);

do {
notification_status = event_from_notification(&notification, &event);
event_from_notification(&notification, &event);
while (event != INVALID_EVENT) {
prv_trigger_callback(event);
} while (notification_status != STATUS_CODE_OK);
event_from_notification(&notification, &event);
}
ShiCheng-Lu marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion libraries/ms-common/src/x86/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ StatusCode gpio_set_state(const GpioAddress *address, GpioState state) {
}
GpioMode mode = s_gpio_pin_modes[prv_get_index(address)];
if (mode != GPIO_OUTPUT_OPEN_DRAIN && mode != GPIO_OUTPUT_PUSH_PULL) {
LOG_WARN("Attempting to set an output pin, check your configuration");
LOG_WARN("Attempting to set an input pin, check your configuration");
ShiCheng-Lu marked this conversation as resolved.
Show resolved Hide resolved
return status_code(STATUS_CODE_INVALID_ARGS);
}

Expand Down
17 changes: 6 additions & 11 deletions libraries/ms-common/src/x86/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "spi_mcu.h"

#define SPI_BUF_SIZE 32
#define SPI_QUEUE_DELAY_MS 0

typedef struct {
uint8_t tx_buf[SPI_BUF_SIZE];
Expand Down Expand Up @@ -89,31 +88,27 @@ StatusCode spi_exchange(SpiPort spi, uint8_t *tx_data, size_t tx_len, uint8_t *r
}

StatusCode spi_get_tx(SpiPort spi, uint8_t *data, uint8_t len) {
status_ok_or_return(mutex_lock(&s_port[spi].spi_buf.mutex, SPI_TIMEOUT_MS));

uint8_t dummy = 0;
for (size_t tx = 0; tx < len; tx++) {
if (queue_receive(&s_port[spi].spi_buf.tx_queue, &data[tx], SPI_QUEUE_DELAY_MS)) {
if (queue_receive(&s_port[spi].spi_buf.tx_queue, &data[tx], SPI_TIMEOUT_MS)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this change, didnt you update SPI_QUEUE_DELAY_MS earlier? from 0 to 10

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match arm impl

queue_reset(&s_port[spi].spi_buf.tx_queue);
mutex_unlock(&s_port[spi].spi_buf.mutex);
return STATUS_CODE_EMPTY;
}
queue_send(&s_port[spi].spi_buf.rx_queue, &dummy, SPI_TIMEOUT_MS);
}

mutex_unlock(&s_port[spi].spi_buf.mutex);
return STATUS_CODE_OK;
}

StatusCode spi_set_rx(SpiPort spi, uint8_t *data, uint8_t len) {
status_ok_or_return(mutex_lock(&s_port[spi].spi_buf.mutex, SPI_TIMEOUT_MS));

uint8_t dummy = 0;
for (size_t rx = 0; rx < len; rx++) {
if (queue_send(&s_port[spi].spi_buf.rx_queue, &data[rx], SPI_QUEUE_DELAY_MS)) {
if (queue_receive(&s_port[spi].spi_buf.tx_queue, &dummy, SPI_TIMEOUT_MS)) {
queue_reset(&s_port[spi].spi_buf.rx_queue);
mutex_unlock(&s_port[spi].spi_buf.mutex);
return STATUS_CODE_RESOURCE_EXHAUSTED;
}
queue_send(&s_port[spi].spi_buf.rx_queue, &data[rx], SPI_TIMEOUT_MS);
}

mutex_unlock(&s_port[spi].spi_buf.mutex);
return STATUS_CODE_OK;
}
8 changes: 6 additions & 2 deletions projects/motor_controller/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@
"ms-common",
"master"
],
"can": true
}
"can": true,
"mocks": {
"motor_can_tx": ["mcp2515_hw_transmit", "mcp2515_hw_init"],
"motor_can_rx": ["mcp2515_hw_transmit", "mcp2515_hw_init"]
}
}
11 changes: 9 additions & 2 deletions projects/motor_controller/inc/mcp2515_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@
#define MCP2515_TXBNDLC_DLC_MASK 0x0F

// RXB0CTRL: Register 4-1
#define MCP2515_RXB0CTRL_BUKT_MASK 0x4
#define MCP2515_RXB0CTRL_BUKT_ROLLOVER 0x4
#define MCP2515_RXB0CTRL_BUKT 0x4

#define MCP2515_MAX_WRITE_BUFFER_LEN 10
#define MCP2515_STANDARD_ID_LEN 11
Expand All @@ -143,3 +142,11 @@

#define MCP2515_NUM_MASK_REGISTERS_STANDARD 2
#define MCP2515_NUM_MASK_REGISTERS_EXTENDED 4

// BFPCTRL: Register 4-3
#define MCP2515_BFPCTRL_B1BFS 0x20
#define MCP2515_BFPCTRL_B2BFS 0x10
#define MCP2515_BFPCTRL_B1BFE 0x08
#define MCP2515_BFPCTRL_B2BFE 0x04
#define MCP2515_BFPCTRL_B1BFM 0x02
#define MCP2515_BFPCTRL_B2BFM 0x01
6 changes: 4 additions & 2 deletions projects/motor_controller/inc/mcp2515_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ typedef struct Mcp2515Settings {
SpiSettings spi_settings;

GpioAddress interrupt_pin;
GpioAddress RX0BF;
GpioAddress RX1BF;

// same can settings except MCP2515 does not support 1000kbps bitrate
CanSettings can_settings;
Expand All @@ -28,12 +30,12 @@ typedef struct Mcp2515Storage {
} Mcp2515Storage;

// Initializes CAN using the specified settings.
StatusCode mcp2515_hw_init(const CanQueue *rx_queue, const Mcp2515Settings *settings);
StatusCode mcp2515_hw_init(Mcp2515Storage *rx_queue, const Mcp2515Settings *settings);

// StatusCode mcp2515_hw_add_filter_in(uint32_t mask, uint32_t filter, bool extended);

StatusCode mcp2515_hw_set_filter(CanMessageId *filters, bool loopback);

CanHwBusStatus mcp2515_hw_bus_status(void);

StatusCode mcp2515_hw_transmit(uint32_t id, bool extended, const uint64_t data, size_t len);
StatusCode mcp2515_hw_transmit(uint32_t id, bool extended, uint8_t *data, size_t len);
11 changes: 7 additions & 4 deletions projects/motor_controller/inc/motor_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@
#define VELOCITY_SCALE 100
#define TEMP_SCALE 100

// also used as the current for regen braking, might need to be seperated
#define ACCERLATION_FORCE 1
#define CRUISE_THROTTLE_THRESHOLD 0
#define TORQUE_CONTROL_VEL 20000 // unobtainable rpm for current control
#define VEL_TO_RPM_RATIO 1.0 // TODO: set actual ratio, m/s to motor rpm
#define VEL_TO_RPM_RATIO 0.57147 // TODO: set actual ratio, m/s to motor (rpm for m/s)
// wheel diameter 557mm
// 1000 / (557 * pi) = 0.57147

#define DRIVER_CONTROL_BASE 0x1
#define MOTOR_CONTROLLER_BASE_L 0x40
#define MOTOR_CONTROLLER_BASE_R 0x80
#define DRIVER_CONTROL_BASE 0x500
#define MOTOR_CONTROLLER_BASE_L 0x400
#define MOTOR_CONTROLLER_BASE_R 0x80 // TODO: set to actual values

void init_motor_controller_can();
17 changes: 17 additions & 0 deletions projects/motor_controller/inc/precharge.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <stdbool.h>

#include "gpio.h"
#include "notify.h"
#include "status.h"

// Requires GPIO to be initialized
// Requires GPIO interrupts to be initialized

typedef struct PrechargeSettings {
GpioAddress precharge_control;
GpioAddress precharge_monitor;
} PrechargeSettings;

StatusCode precharge_init(const PrechargeSettings *settings, Event event, const Task *task);
27 changes: 0 additions & 27 deletions projects/motor_controller/inc/precharge_control.h

This file was deleted.

Loading
Loading