From 8a89660a3c9c5883559bf7917f8f725e2d8f985a Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Sun, 20 Nov 2022 00:25:23 +0100 Subject: [PATCH] can-common: remove some levels of indention --- src/can-common.c | 100 ++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 45 deletions(-) diff --git a/src/can-common.c b/src/can-common.c index 284dff21..5d508e12 100644 --- a/src/can-common.c +++ b/src/can-common.c @@ -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 @@ -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); } }