CAN: Reduce nesting level via code transformations.
This commit is contained in:
parent
06d1a5ca80
commit
571c4d37d0
@ -150,10 +150,10 @@ void sys_tick_handler(void)
|
||||
static int temp32 = 0;
|
||||
static u8 data[8] = {0, 1, 2, 0, 0, 0, 0, 0};
|
||||
|
||||
temp32++;
|
||||
|
||||
/* We call this handler every 1ms so 1000ms = 1s on/off. */
|
||||
if (temp32 == 1000) {
|
||||
if (++temp32 != 1000)
|
||||
return;
|
||||
|
||||
temp32 = 0;
|
||||
|
||||
/* Transmit CAN frame. */
|
||||
@ -171,7 +171,6 @@ void sys_tick_handler(void)
|
||||
gpio_set(GPIOB, GPIO1); /* LED3 off */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void usb_lp_can_rx0_isr(void)
|
||||
{
|
||||
|
21
lib/can.c
21
lib/can.c
@ -31,9 +31,8 @@ void can_reset(u32 canport)
|
||||
}
|
||||
}
|
||||
|
||||
int can_init(u32 canport,
|
||||
bool ttcm, bool abom, bool awum, bool nart, bool rflm, bool txfp,
|
||||
u32 sjw, u32 ts1, u32 ts2, u32 brp)
|
||||
int can_init(u32 canport, bool ttcm, bool abom, bool awum, bool nart,
|
||||
bool rflm, bool txfp, u32 sjw, u32 ts1, u32 ts2, u32 brp)
|
||||
{
|
||||
u32 wait_ack = 0x00000000;
|
||||
u32 can_msr_inak_timeout = 0x0000FFFF;
|
||||
@ -52,9 +51,9 @@ int can_init(u32 canport,
|
||||
}
|
||||
|
||||
/* Check the acknowledge. */
|
||||
if ((CAN_MSR(canport) & CAN_MSR_INAK) != CAN_MSR_INAK) {
|
||||
ret = 1;
|
||||
} else {
|
||||
if ((CAN_MSR(canport) & CAN_MSR_INAK) != CAN_MSR_INAK)
|
||||
return 1;
|
||||
|
||||
/* Set the automatic bus-off management. */
|
||||
if (ttcm)
|
||||
CAN_MCR(canport) |= CAN_MCR_TTCM;
|
||||
@ -102,7 +101,6 @@ int can_init(u32 canport,
|
||||
|
||||
if ((CAN_MSR(canport) & CAN_MSR_INAK) == CAN_MSR_INAK)
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
@ -209,7 +207,10 @@ int can_transmit(u32 canport, u32 id, bool ext, bool rtr, u8 length, u8 *data)
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
if (ret != -1) { /* Check if we have an empty mailbox. */
|
||||
/* Check if we have an empty mailbox. */
|
||||
if (ret == -1)
|
||||
return ret;
|
||||
|
||||
if (ext) {
|
||||
/* Set extended ID. */
|
||||
CAN_TIxR(canport, mailbox) |= id << CAN_TIxR_EXID_SHIFT;
|
||||
@ -238,12 +239,10 @@ int can_transmit(u32 canport, u32 id, bool ext, bool rtr, u8 length, u8 *data)
|
||||
for (i = 0; (i < 4) && (i < length); i++)
|
||||
CAN_TDLxR(canport, mailbox) |= (u32)data[i] << (8 * i);
|
||||
for (i = 4; (i < 8) && (i < length); i++)
|
||||
CAN_TDHxR(canport, mailbox)
|
||||
|= (u32)data[i] << (8 * (i - 4));
|
||||
CAN_TDHxR(canport, mailbox) |= (u32)data[i] << (8 * (i - 4));
|
||||
|
||||
/* Request transmission. */
|
||||
CAN_TIxR(canport, mailbox) |= CAN_TIxR_TXRQ;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user