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

Test/renode can app #211

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
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
74 changes: 35 additions & 39 deletions Core/Src/can_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ void can1_callback(CAN_HandleTypeDef *hcan)
new_msg.len = rx_header.DLC;
new_msg.id = rx_header.StdId;

queue_and_set_flag(can_inbound_queue, &new_msg, can_receive_thread,
NEW_CAN_MSG_FLAG);
//queue_and_set_flag(can_inbound_queue, &new_msg, can_receive_thread,
// NEW_CAN_MSG_FLAG);

/* Print Callback Messages */
if (new_msg.id == 2)
printf("Callback: %s", new_msg.data);
}

int8_t queue_can_msg(can_msg_t msg)
Expand All @@ -102,32 +106,35 @@ void vCanDispatch(void *pv_params)
fault_data_t fault_data = { .id = CAN_DISPATCH_FAULT,
.severity = DEFCON1 };

can_msg_t msg_from_queue;
HAL_StatusTypeDef msg_status;
can_msg_t msg_from_queue = {
.id = 0x002,
.len = 4,
.data = { 69 }
};

HAL_StatusTypeDef msg_status;
CAN_HandleTypeDef *hcan = (CAN_HandleTypeDef *)pv_params;

for (;;) {
osThreadFlagsWait(CAN_DISPATCH_FLAG, osFlagsWaitAny,
osWaitForever);
/* Send CAN message */
while (osMessageQueueGet(can_outbound_queue, &msg_from_queue,
NULL, 0U) == osOK) {
/* Wait if CAN outbound queue is full */
while (HAL_CAN_GetTxMailboxesFreeLevel(hcan) == 0) {
osDelay(1);
}

msg_status = can_send_msg(can1, &msg_from_queue);

if (msg_status == HAL_ERROR) {
fault_data.diag = "Failed to send CAN message";
queue_fault(&fault_data);
} else if (msg_status == HAL_BUSY) {
fault_data.diag = "Outbound mailbox full!";
queue_fault(&fault_data);
}
osDelay(500);

/* Wait if CAN outbound queue is full */
while (HAL_CAN_GetTxMailboxesFreeLevel(hcan) == 0) {
osDelay(1);
}

msg_status = can_send_msg(can1, &msg_from_queue);

if (msg_status == HAL_ERROR) {
fault_data.diag = "Failed to send CAN message";
queue_fault(&fault_data);
} else if (msg_status == HAL_BUSY) {
fault_data.diag = "Outbound mailbox full!";
queue_fault(&fault_data);
}

/* Print Dispatch Messages */
printf("Dispatch: %s", msg_from_queue.data);
}
}

Expand All @@ -140,26 +147,15 @@ const osThreadAttr_t can_receive_attributes = {

void vCanReceive(void *pv_params)
{
dti_t *mc = (dti_t *)pv_params;
//dti_t *mc = (dti_t *)pv_params;

can_msg_t msg;

for (;;) {
osThreadFlagsWait(NEW_CAN_MSG_FLAG, osFlagsWaitAny,
osWaitForever);
while (osOK ==
osMessageQueueGet(can_inbound_queue, &msg, 0U, 0U)) {
switch (msg.id) {
/* Messages Relevant to Motor Controller */
case DTI_CANID_ERPM:
dti_record_rpm(mc, msg);
break;
case BMS_DCL_MSG:
handle_dcl_msg();
break;
default:
break;
}
osThreadFlagsWait(NEW_CAN_MSG_FLAG, osFlagsWaitAny, osWaitForever);
while (osOK == osMessageQueueGet(can_inbound_queue, &msg, 0U, 0U)) {
/* Print Receive Messages */
printf("Recieve: %s", msg.data);
}
}
}
Loading
Loading