Skip to content

Commit

Permalink
Updates from hardware testing: added counter array to reduce frequenc…
Browse files Browse the repository at this point in the history
…y at which we forwared motor messages onto CarCAN, moved init functions in test file, added Renode independent watchdog fix.
  • Loading branch information
KnockbackNemo committed Nov 11, 2023
1 parent 77dbc2a commit ff4bf0a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
21 changes: 19 additions & 2 deletions Apps/Src/SendCarCAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
#include "SendTritium.h"

#define IO_STATE_DLY_MS 250u
#define SENDCARCAN_LOOP_DLY_MS 5u // 50How often we should check the CAN queue (in ms delay). Must send faster than queue messages get put in
#define IO_STATE_DLY_COUNT (IO_STATE_DLY_MS / SENDCARCAN_LOOP_DLY_MS) // The number of periods to wait before sending IO state message

// Task_PutIOState
OS_TCB putIOState_TCB;
Expand All @@ -32,11 +30,19 @@ CPU_STK putIOState_Stk[TASK_SEND_CAR_CAN_STACK_SIZE];
#define FIFO_NAME SendCarCAN_Q
#include "fifo.h"

// Motor message
#define NUM_MOTOR_MSGS 15 // Messages received from the motor controller
#define MOTOR_MSG_BASE_ADDRESS 0x240

static SendCarCAN_Q_t CANFifo;

static OS_SEM CarCAN_Sem4;
static OS_MUTEX CarCAN_Mtx;

// Counter array to reduce the frequency at which we send out messages
static uint8_t motorMsgCount[NUM_MOTOR_MSGS] = {0};
static uint8_t motorMsgThreshold[NUM_MOTOR_MSGS] = {5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5};

static void Task_PutIOState(void *p_arg);

/**
Expand All @@ -55,6 +61,17 @@ void print_SendCarCAN_Q(void) {
void SendCarCAN_Put(CANDATA_t message){
OS_ERR err;
CPU_TS ticks;

// Reduce the frequency at which we forward motor messages to CarCAN
uint8_t msgIdx = message.ID - MOTOR_MSG_BASE_ADDRESS;

if (msgIdx >= 0 && msgIdx < NUM_MOTOR_MSGS) { // Check if the message is from the motor controller
if (++motorMsgCount[msgIdx] < motorMsgThreshold[msgIdx]) {
return;
} else {
motorMsgCount[msgIdx] = 0; // Reset counter and continue sending
}
}

OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err);
assertOSError(err);
Expand Down
2 changes: 1 addition & 1 deletion Simulator/stm32f413.repl
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ spi2i2s2: SPI.STM32SPI @ sysbus 0x40003800

i2s2ext: SPI.STM32SPI @ sysbus 0x40003400

iwdg: Timers.STM32F4_IndependentWatchdog @ sysbus 0x40003000
iwdg: Timers.STM32_IndependentWatchdog @ sysbus 0x40003000
frequency: 32000
// windowOption: false
// defaultPrescaler: 0x4
Expand Down
21 changes: 12 additions & 9 deletions Tests/Test_App_SendCarCAN.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,6 @@ void Task1(void *arg)
{
OS_ERR err;

OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U)OSCfg_TickRate_Hz);
CPU_Init();
BSP_UART_Init(UART_2);
Pedals_Init();
CANbus_Init(CARCAN, (CANId_t*)carCANFilterList, NUM_CARCAN_FILTERS); // Set filter list to NULL to receive all messages
CANbus_Init(MOTORCAN, NULL, NUM_MOTORCAN_FILTERS);
SendCarCAN_Init();
Minions_Init();
Display_Init();
UpdateDisplay_Init();

// Initialize SendCarCAN
Expand Down Expand Up @@ -222,6 +213,18 @@ int main(void)
OS_ERR err;
OSInit(&err);

OS_CPU_SysTickInit(SystemCoreClock / (CPU_INT32U)OSCfg_TickRate_Hz);

CPU_Init();
BSP_UART_Init(UART_2);
Pedals_Init();
CANbus_Init(CARCAN, NULL, NUM_CARCAN_FILTERS); // Set filter list to (CANId_t*)carCANFilterList to receive filtered messages
CANbus_Init(MOTORCAN, NULL, NUM_MOTORCAN_FILTERS);
SendCarCAN_Init();
Minions_Init();
Display_Init();
TaskSwHook_Init();

OSTaskCreate(
(OS_TCB *)&Task1TCB,
(CPU_CHAR *)"Task 1",
Expand Down

0 comments on commit ff4bf0a

Please sign in to comment.