Skip to content

Commit

Permalink
can-common: remove some levels of indention
Browse files Browse the repository at this point in the history
  • Loading branch information
marckleinebudde committed Nov 20, 2022
1 parent a390079 commit 8a89660
Showing 1 changed file with 55 additions and 45 deletions.
100 changes: 55 additions & 45 deletions src/can-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,46 +36,53 @@ void CAN_SendFrame(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel)
frame_object = list_first_entry_or_null_locked(&channel->list_from_host,
struct gs_host_frame_object,
list);
if (frame_object) { // send CAN message from host
struct gs_host_frame *frame = &frame_object->frame;

if (can_send(channel, frame)) {
// Echo sent frame back to host
frame->flags = 0x0;
frame->reserved = 0x0;
frame->timestamp_us = timer_get();
list_move_tail_locked(&frame_object->list, &hcan->list_to_host);

led_indicate_trx(&channel->leds, led_tx);
}
if (!frame_object) {
return;
}

struct gs_host_frame *frame = &frame_object->frame;
if (!can_send(channel, frame)) {
return;
}

// Echo sent frame back to host
frame->flags = 0x0;
frame->reserved = 0x0;
frame->timestamp_us = timer_get();
list_move_tail_locked(&frame_object->list, &hcan->list_to_host);

led_indicate_trx(&channel->leds, led_tx);
}

void CAN_ReceiveFrame(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel)
{
if (can_is_rx_pending(channel)) {
struct gs_host_frame_object *frame_object;
struct gs_host_frame_object *frame_object;

frame_object = list_first_entry_or_null_locked(&hcan->list_frame_pool,
struct gs_host_frame_object,
list);
if (frame_object) {
struct gs_host_frame *frame = &frame_object->frame;
if (!can_is_rx_pending(channel)) {
return;
}

if (can_receive(channel, frame)) {
frame_object = list_first_entry_or_null_locked(&hcan->list_frame_pool,
struct gs_host_frame_object,
list);
if (!frame_object) {
return;
}

frame->timestamp_us = timer_get();
frame->echo_id = 0xFFFFFFFF; // not a echo frame
frame->channel = 0;
frame->flags = 0;
frame->reserved = 0;
struct gs_host_frame *frame = &frame_object->frame;
if (!can_receive(channel, frame)) {
return;
}

list_move_tail_locked(&frame_object->list, &hcan->list_to_host);
frame->timestamp_us = timer_get();
frame->echo_id = 0xFFFFFFFF; // not a echo frame
frame->channel = 0;
frame->flags = 0;
frame->reserved = 0;

led_indicate_trx(&channel->leds, led_rx);
}
}
}
list_move_tail_locked(&frame_object->list, &hcan->list_to_host);

led_indicate_trx(&channel->leds, led_rx);
}

// If there are frames to receive, don't report any error frames. The
Expand All @@ -84,20 +91,23 @@ void CAN_ReceiveFrame(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel)
// to report even if multiple pass by.
void CAN_HandleError(USBD_GS_CAN_HandleTypeDef *hcan, can_data_t *channel)
{
if (!can_is_rx_pending(channel)) {
struct gs_host_frame_object *frame_object;
uint32_t can_err = can_get_error_status(channel);

frame_object = list_first_entry_or_null_locked(&hcan->list_frame_pool,
struct gs_host_frame_object,
list);
if (frame_object) {
struct gs_host_frame *frame = &frame_object->frame;

frame->timestamp_us = timer_get();
if (can_parse_error_status(channel, frame, can_err)) {
list_move_tail_locked(&frame_object->list, &hcan->list_to_host);
}
}
struct gs_host_frame_object *frame_object;
struct gs_host_frame *frame;

if (can_is_rx_pending(channel))
return;

uint32_t can_err = can_get_error_status(channel);
frame_object = list_first_entry_or_null_locked(&hcan->list_frame_pool,
struct gs_host_frame_object,
list);
if (!frame_object)
return;

frame = &frame_object->frame;
frame->timestamp_us = timer_get();

if (can_parse_error_status(channel, frame, can_err)) {
list_move_tail_locked(&frame_object->list, &hcan->list_to_host);
}
}

0 comments on commit 8a89660

Please sign in to comment.