main: can_parse_error_status(): move last_err into can_data_t

This is a preparation patch to support more then 1 channel.
This commit is contained in:
Marc Kleine-Budde 2022-11-13 17:27:53 +01:00 committed by Marc Kleine-Budde
parent 226afd795d
commit 5b9c788ac6
3 changed files with 8 additions and 7 deletions

View File

@ -34,6 +34,7 @@ THE SOFTWARE.
typedef struct {
CAN_TypeDef *instance;
uint32_t reg_esr_old;
uint16_t brp;
uint8_t phase_seg1;
uint8_t phase_seg2;
@ -58,6 +59,7 @@ uint32_t can_get_error_status(can_data_t *hcan);
/** parse status value returned by can_get_error_status().
* @param frame : will hold the generated error frame
* @param err : holds the contents of the ESR register
* @return 1 when status changes (if any) need a new error frame sent
*/
bool can_parse_error_status(uint32_t err, uint32_t last_err, can_data_t *hcan, struct gs_host_frame *frame);
bool can_parse_error_status(can_data_t *hcan, struct gs_host_frame *frame, uint32_t err);

View File

@ -260,13 +260,15 @@ static bool status_is_active(uint32_t err)
return !(err & (CAN_ESR_BOFF | CAN_ESR_EPVF));
}
bool can_parse_error_status(uint32_t err, uint32_t last_err, can_data_t *hcan, struct gs_host_frame *frame)
bool can_parse_error_status(can_data_t *hcan, struct gs_host_frame *frame, uint32_t err)
{
uint32_t last_err = hcan->reg_esr_old;
/* We build up the detailed error information at the same time as we decide
* whether there's anything worth sending. This variable tracks that final
* result. */
bool should_send = false;
(void) hcan;
hcan->reg_esr_old = err;
frame->echo_id = 0xFFFFFFFF;
frame->can_id = CAN_ERR_FLAG;

View File

@ -55,7 +55,6 @@ static led_data_t hLED = {0};
int main(void)
{
can_data_t *channel = &hGS_CAN.channels[0];
uint32_t last_can_error_status = 0;
HAL_Init();
SystemClock_Config();
@ -174,10 +173,8 @@ int main(void)
restore_irq(was_irq_enabled);
frame->timestamp_us = timer_get();
if (can_parse_error_status(can_err, last_can_error_status, channel, frame)) {
if (can_parse_error_status(channel, frame, can_err)) {
list_add_tail_locked(&frame_object->list, &hGS_CAN.list_to_host);
last_can_error_status = can_err;
} else {
list_add_tail_locked(&frame_object->list, &hGS_CAN.list_frame_pool);
}