Skip to content

Commit

Permalink
merge conflict resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
IshDeshpa committed Sep 26, 2023
1 parent de426c5 commit 6f69ba9
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Apps/Inc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@
#define XSTR(STRING) GENERATE_STRING(STRING)
#define INDIRECT(VAL) VAL

// Length of array
#define LENOF(ARR) (sizeof(ARR)/sizeof(ARR[0]))

typedef void (*callback_t)(void);

void print_float(char *str, float f);
void print_bin(char *str, uint32_t i);

#endif
74 changes: 56 additions & 18 deletions Apps/Src/SendCarCAN.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#include "common.h"
#include "os_cfg_app.h"

#include "Tasks.h"
#include "SendCarCAN.h"

#include "CANbus.h"
#include "Minions.h"
#include "Contactors.h"
Expand All @@ -11,22 +15,54 @@
#define FIFO_TYPE CANDATA_t
#define FIFO_SIZE 256
#define FIFO_NAME SendCarCAN_Q
#include "fifo_protected.h"
#include "fifo.h"

static SendCarCAN_Q_t CANFifo;

static OS_SEM CarCAN_Sem4;
static OS_MUTEX CarCAN_Mtx;

static OS_SEM CarCAN_Sem4;
static OS_MUTEX CarCAN_Mtx;

#define IO_STATE_TMR_DLY_MS 250u
#define IO_STATE_TMR_DLY_TS ((IO_STATE_TMR_DLY_MS * OS_CFG_TMR_TASK_RATE_HZ) / (1000u))
static OS_TMR IOStateTmr;

static void putIOState(void *p_tmr, void *p_arg);

/**
* @brief Initialize SendCarCAN
* @brief Wrapper to put new message in the CAN queue
*/
void SendCarCAN_Init(){
void SendCarCAN_Put(CANDATA_t message){
OS_ERR err;
CPU_TS ticks;

OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err);
assertOSError(OS_SEND_CAN_LOC, err);

bool success = SendCarCAN_Q_put(&CANFifo, message);

OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err);
assertOSError(OS_SEND_CAN_LOC, err);

if(success) OSSemPost(&CarCAN_Sem4, OS_OPT_POST_1, &err);
assertOSError(OS_SEND_CAN_LOC, err);
}

/**
* @brief Grabs the latest messages from the queue and sends over CarCAN
*/
void Task_SendCarCAN(void *p_arg){
OS_ERR err;
CPU_TS ticks;

OSMutexCreate(&CarCAN_Mtx, "CarCAN_Mtx", &err);
assertOSError(OS_SEND_CAN_LOC, err);

OSSemCreate(&CarCAN_Sem4, "CarCAN_Sem4", 0, &err);
assertOSError(OS_SEND_CAN_LOC, err);

SendCarCAN_Q_renew(&CANFifo);

// Set up timer to put car data message every IO_STATE_TMR_DLY_MS ms
Expand All @@ -39,25 +75,27 @@ void SendCarCAN_Init(){
NULL,
&err
);
}
assertOSError(OS_SEND_CAN_LOC, err);

/**
* @brief Wrapper to put new message in the CAN queue
*/
void SendCarCAN_Put(CANDATA_t message){
SendCarCAN_Q_put(&CANFifo, message);
}
OSTmrStart(&IOStateTmr, &err);
assertOSError(OS_SEND_CAN_LOC, err);

/**
* @brief Grabs the latest messages from the queue and sends over CarCAN
*/
void Task_SendCarCAN(void *p_arg){
CANDATA_t message;
memset(&message, 0, sizeof(CANDATA_t));

while (1) {
SendCarCAN_Q_get(&CANFifo, &message);
CANbus_Send(message, true, CARCAN);

OSSemPend(&CarCAN_Sem4, 0, OS_OPT_PEND_BLOCKING, &ticks, &err);
assertOSError(OS_SEND_CAN_LOC, err);

OSMutexPend(&CarCAN_Mtx, 0, OS_OPT_PEND_BLOCKING, &ticks, &err);
assertOSError(OS_SEND_CAN_LOC, err);

bool res = SendCarCAN_Q_get(&CANFifo, &message);
assertOSError(OS_SEND_CAN_LOC, err);

OSMutexPost(&CarCAN_Mtx, OS_OPT_POST_NONE, &err);

if(res) CANbus_Send(message, true, CARCAN);
}
}

Expand All @@ -81,7 +119,7 @@ static void putIOState(void *p_tmr, void *p_arg){
// Get contactor info
message.data[3] = 0;
for(contactor_t contactor = 0; contactor < NUM_CONTACTORS; contactor++){
bool contactorState = Contactors_Get(contactor) == ON ? true : false;
bool contactorState = (Contactors_Get(contactor) == ON) ? true : false;
message.data[3] |= contactorState << contactor;
}

Expand Down
8 changes: 8 additions & 0 deletions Apps/Src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ void print_float(char * str, float f) {
int32_t d = (f<0)?-f:f;
printf("%d.%02d\n\r", (int)n, (int)d);
}

void print_bin(char * str, uint32_t i){
if(str) printf(str);

for(uint32_t mask=0x80000000L; mask > 0L; mask >>= 1){
printf("%d",(mask & i)?1:0);
}
}
3 changes: 1 addition & 2 deletions Apps/Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ void Task_Init(void *p_arg){
CANbus_Init(MOTORCAN, NULL, NUM_MOTORCAN_FILTERS);
Contactors_Init();
Display_Init();
Minion_Init();
Minions_Init();

// Initialize applications
UpdateDisplay_Init();
SendCarCAN_Init();

// Initialize FaultState
OSTaskCreate(
Expand Down
5 changes: 1 addition & 4 deletions Drivers/Inc/CANConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
#define CAN_CONFIG
#include "CANbus.h"




/**
* Filter Lists for CarCAN and MotorCAN
*/
#define NUM_CARCAN_FILTERS 4
#define NUM_CARCAN_FILTERS 6
#define NUM_MOTORCAN_FILTERS 0
extern CANId_t carCANFilterList[NUM_CARCAN_FILTERS];
extern CANId_t motorCANFilterList[NUM_MOTORCAN_FILTERS];
Expand Down
2 changes: 1 addition & 1 deletion Drivers/Inc/Minions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// used to index into lookup table
// if changed, PINS_LOOKARR should be changed in Minions.c
#define FOREACH_MinionPin(PIN) \
#define FOREACH_PIN(PIN) \
PIN(IGN_1), \
PIN(IGN_2), \
PIN(REGEN_SW), \
Expand Down
8 changes: 5 additions & 3 deletions Drivers/Src/CANConfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const CANLUT_T CANLUT[NUM_CAN_IDS] = {
[MOTOR_POWER] = {NOIDX, DOUBLE}, /** MOTOR_POWER **/
[MOTOR_RESET] = {NOIDX, DOUBLE}, /** MOTOR_RESET **/
[MOTOR_STATUS] = {NOIDX, DOUBLE}, /** MOTOR_STATUS **/
[CONTROL_MODE] = {NOIDX, DOUBLE}, /** IO_STATE **/
[IO_STATE] = {NOIDX, BYTE }, /** CONTROL_MODE **/
[IO_STATE] = {NOIDX, DOUBLE}, /** IO_STATE **/
[CONTROL_MODE] = {NOIDX, BYTE }, /** CONTROL_MODE **/
};

/**
Expand All @@ -43,6 +43,8 @@ CANId_t carCANFilterList[NUM_CARCAN_FILTERS] = {
BPS_TRIP,
STATE_OF_CHARGE,
SUPPLEMENTAL_VOLTAGE,
CHARGE_ENABLE
CHARGE_ENABLE,
IO_STATE,
CONTROL_MODE
};
CANId_t motorCANFilterList[NUM_MOTORCAN_FILTERS] = {};

0 comments on commit 6f69ba9

Please sign in to comment.