mirror of
https://github.com/apache/nuttx.git
synced 2026-09-03 15:43:01 +00:00
net, arch: Fix nxstyle errors in files the CAN ioctl merge touches.
Whitespace only: blank lines after declarations, misindented switch bodies and brace alignment. nxstyle runs over the whole of any file a change touches, and merging the CAN ioctl options renames a config in every SocketCAN driver. Assisted-by: Claude:claude-fable-5 Signed-off-by: Jacob Dahl <dahl.jakejacob@gmail.com>
This commit is contained in:
parent
eb40eed248
commit
3e2f28ef68
9 changed files with 524 additions and 410 deletions
|
|
@ -628,6 +628,7 @@ static int imx9_transmit(struct imx9_driver_s *priv)
|
|||
/* Check whether message buffer is not currently transmitting */
|
||||
|
||||
struct mb_s *mb = flexcan_get_mb(priv, mbi);
|
||||
|
||||
if (mb->cs.code != CAN_TXMB_DATAORREMOTE)
|
||||
{
|
||||
putreg32(mb_bit, priv->base + IMX9_CAN_IFLAG1_OFFSET);
|
||||
|
|
@ -650,12 +651,14 @@ static int imx9_transmit(struct imx9_driver_s *priv)
|
|||
|
||||
#ifdef CONFIG_NET_CAN_RAW_TX_DEADLINE
|
||||
struct timespec ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
|
||||
if (priv->dev.d_sndlen > priv->dev.d_len)
|
||||
{
|
||||
struct timeval *tv =
|
||||
(struct timeval *)(priv->dev.d_buf + priv->dev.d_len);
|
||||
|
||||
priv->txmb[txmb].deadline = *tv;
|
||||
timeout = (tv->tv_sec - ts.tv_sec)*CLK_TCK
|
||||
+ ((tv->tv_usec - ts.tv_nsec / 1000)*CLK_TCK) / 1000000;
|
||||
|
|
@ -690,9 +693,11 @@ static int imx9_transmit(struct imx9_driver_s *priv)
|
|||
(peak_tx_mailbox_index_ > mbi ? peak_tx_mailbox_index_ : mbi);
|
||||
|
||||
union cs_e cs;
|
||||
|
||||
cs.cs = 0;
|
||||
cs.code = CAN_TXMB_DATAORREMOTE;
|
||||
struct mb_s *mb = flexcan_get_mb(priv, mbi);
|
||||
|
||||
mb->cs.code = CAN_TXMB_INACTIVE;
|
||||
|
||||
if (priv->dev.d_len == sizeof(struct can_frame))
|
||||
|
|
@ -755,6 +760,7 @@ static int imx9_transmit(struct imx9_driver_s *priv)
|
|||
*/
|
||||
|
||||
struct mb_s *buffer = flexcan_get_mb(priv, RXMBCOUNT);
|
||||
|
||||
buffer->cs.code = 0x3;
|
||||
buffer->cs.code = 0x3;
|
||||
|
||||
|
|
@ -878,11 +884,13 @@ static void imx9_receive(struct imx9_driver_s *priv,
|
|||
mbj = mbi = arm_lsb(f);
|
||||
rf = flexcan_get_mb(priv, mbi);
|
||||
uint32_t t = rf->cs.time_stamp;
|
||||
|
||||
while ((f &= ~(1 << mbj)) != 0)
|
||||
{
|
||||
mbj = arm_lsb(f);
|
||||
struct mb_s *rf_next = flexcan_get_mb(priv, mbj);
|
||||
uint16_t t_next = rf_next->cs.time_stamp;
|
||||
|
||||
if ((int16_t)(t - t_next) > 0)
|
||||
{
|
||||
t = t_next;
|
||||
|
|
@ -897,7 +905,7 @@ static void imx9_receive(struct imx9_driver_s *priv,
|
|||
#ifdef CONFIG_NET_CAN_CANFD
|
||||
if (rf->cs.edl) /* CAN FD frame */
|
||||
{
|
||||
struct canfd_frame *frame = (struct canfd_frame *)priv->rxdesc_fd;
|
||||
struct canfd_frame *frame = (struct canfd_frame *)priv->rxdesc_fd;
|
||||
|
||||
if (rf->cs.ide)
|
||||
{
|
||||
|
|
@ -938,7 +946,7 @@ static void imx9_receive(struct imx9_driver_s *priv,
|
|||
else /* CAN 2.0 Frame */
|
||||
#endif
|
||||
{
|
||||
struct can_frame *frame = (struct can_frame *)priv->rxdesc;
|
||||
struct can_frame *frame = (struct can_frame *)priv->rxdesc;
|
||||
|
||||
if (rf->cs.ide)
|
||||
{
|
||||
|
|
@ -1058,6 +1066,7 @@ static void imx9_txdone(struct imx9_driver_s *priv)
|
|||
|
||||
wd_cancel(&priv->txtimeout[txmb]);
|
||||
struct mb_s *mb = flexcan_get_mb(priv, mbi);
|
||||
|
||||
mb->cs.code = CAN_TXMB_INACTIVE;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1128,6 +1137,7 @@ static void imx9_flexcan_interrupt_work(void *arg)
|
|||
struct imx9_driver_s *priv = (struct imx9_driver_s *)arg;
|
||||
|
||||
uint32_t flags;
|
||||
|
||||
flags = getreg32(priv->base + IMX9_CAN_IFLAG1_OFFSET);
|
||||
flags &= IFLAG1_RX;
|
||||
|
||||
|
|
@ -1168,6 +1178,7 @@ static int imx9_flexcan_interrupt(int irq, void *context,
|
|||
if (irq == priv->config->irq)
|
||||
{
|
||||
uint32_t flags;
|
||||
|
||||
flags = getreg32(priv->base + IMX9_CAN_IFLAG1_OFFSET);
|
||||
flags &= IFLAG1_RX;
|
||||
|
||||
|
|
@ -1221,6 +1232,7 @@ static void imx9_txtimeout_work(void *arg)
|
|||
|
||||
struct timespec ts;
|
||||
struct timeval *now = (struct timeval *)&ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
now->tv_usec = ts.tv_nsec / 1000; /* timespec to timeval conversion */
|
||||
|
||||
|
|
@ -1246,6 +1258,7 @@ static void imx9_txtimeout_work(void *arg)
|
|||
}
|
||||
|
||||
struct mb_s *mb = flexcan_get_mb(priv, mbi + RXMBCOUNT);
|
||||
|
||||
mb->cs.code = CAN_TXMB_ABORT;
|
||||
priv->txmb[mbi].pending = TX_ABORT;
|
||||
}
|
||||
|
|
@ -1305,6 +1318,7 @@ static void imx9_setenable(uint32_t base, uint32_t enable)
|
|||
static void imx9_setfreeze(uint32_t base, uint32_t freeze)
|
||||
{
|
||||
uint32_t regval;
|
||||
|
||||
if (freeze)
|
||||
{
|
||||
/* Enter freeze mode */
|
||||
|
|
@ -1333,6 +1347,7 @@ static uint32_t imx9_waitmcr_change(uint32_t base, uint32_t mask,
|
|||
{
|
||||
const bool state = (getreg32(base + IMX9_CAN_MCR_OFFSET) & mask)
|
||||
!= 0;
|
||||
|
||||
if (state == target_state)
|
||||
{
|
||||
return true;
|
||||
|
|
@ -1549,6 +1564,7 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
|
|||
{
|
||||
struct can_ioctl_data_s *req =
|
||||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
req->arbi_bitrate = priv->arbi_timing.bitrate;
|
||||
req->arbi_samplep = priv->arbi_timing.samplep;
|
||||
if (priv->canfd_capable)
|
||||
|
|
@ -1572,6 +1588,7 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
|
|||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
struct flexcan_timeseg arbi_timing;
|
||||
|
||||
arbi_timing.bitrate = req->arbi_bitrate;
|
||||
arbi_timing.samplep = req->arbi_samplep;
|
||||
|
||||
|
|
@ -1585,19 +1602,19 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
|
|||
}
|
||||
|
||||
if (priv->canfd_capable)
|
||||
{
|
||||
data_timing.bitrate = req->data_bitrate;
|
||||
data_timing.samplep = req->data_samplep;
|
||||
{
|
||||
data_timing.bitrate = req->data_bitrate;
|
||||
data_timing.samplep = req->data_samplep;
|
||||
|
||||
if (ret == OK && imx9_bitratetotimeseg(&data_timing, 10, 1))
|
||||
{
|
||||
ret = OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -EINVAL;
|
||||
}
|
||||
}
|
||||
if (ret == OK && imx9_bitratetotimeseg(&data_timing, 10, 1))
|
||||
{
|
||||
ret = OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
if (ret == OK)
|
||||
{
|
||||
|
|
@ -1605,9 +1622,9 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
|
|||
|
||||
priv->arbi_timing = arbi_timing;
|
||||
if (priv->canfd_capable)
|
||||
{
|
||||
priv->data_timing = data_timing;
|
||||
}
|
||||
{
|
||||
priv->data_timing = data_timing;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -1782,12 +1799,14 @@ static int imx9_initialize(struct imx9_driver_s *priv)
|
|||
* transmitting the package, hence we write 0x3.
|
||||
*/
|
||||
|
||||
struct mb_s *buffer = flexcan_get_mb(priv, RXMBCOUNT);
|
||||
buffer->cs.code = 0x3;
|
||||
struct mb_s *buffer = flexcan_get_mb(priv, RXMBCOUNT);
|
||||
|
||||
buffer->cs.code = 0x3;
|
||||
|
||||
for (i = RXMBCOUNT + 1; i < TOTALMBCOUNT; i++)
|
||||
{
|
||||
struct mb_s *rx = flexcan_get_mb(priv, i);
|
||||
|
||||
rx->id.w = 0x0;
|
||||
|
||||
/* FIXME sometimes we get a hard fault here */
|
||||
|
|
@ -1803,6 +1822,7 @@ static int imx9_initialize(struct imx9_driver_s *priv)
|
|||
for (i = 0; i < RXMBCOUNT; i++)
|
||||
{
|
||||
struct mb_s *rx = flexcan_get_mb(priv, i);
|
||||
|
||||
ninfo("Set MB%" PRIi32 " to receive %p\n", i, rx);
|
||||
rx->cs.edl = 0x1;
|
||||
rx->cs.brs = 0x1;
|
||||
|
|
@ -1868,6 +1888,7 @@ static void imx9_reset(struct imx9_driver_s *priv)
|
|||
for (i = 0; i < TOTALMBCOUNT; i++)
|
||||
{
|
||||
struct mb_s *rx = flexcan_get_mb(priv, i);
|
||||
|
||||
ninfo("MB %" PRIi32 " %p\n", i, rx);
|
||||
ninfo("MB %" PRIi32 " %p\n", i, &rx->id.w);
|
||||
rx->cs.cs = 0x0;
|
||||
|
|
@ -1928,143 +1949,143 @@ int imx9_caninitialize(int intf)
|
|||
switch (intf)
|
||||
{
|
||||
#ifdef CONFIG_IMX9_FLEXCAN1
|
||||
case 1:
|
||||
priv = &g_flexcan1;
|
||||
memset(priv, 0, sizeof(struct imx9_driver_s));
|
||||
priv->base = IMX9_CAN1_BASE;
|
||||
priv->config = &imx9_flexcan1_config;
|
||||
case 1:
|
||||
priv = &g_flexcan1;
|
||||
memset(priv, 0, sizeof(struct imx9_driver_s));
|
||||
priv->base = IMX9_CAN1_BASE;
|
||||
priv->config = &imx9_flexcan1_config;
|
||||
# if defined(CONFIG_NET_CAN_CANFD)
|
||||
priv->canfd_capable = true;
|
||||
priv->mb_address_offset = 14;
|
||||
priv->canfd_capable = true;
|
||||
priv->mb_address_offset = 14;
|
||||
#endif
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# if defined(CONFIG_NET_CAN_CANFD)
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN1_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN1_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN1_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN1_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_IMX9_FLEXCAN2
|
||||
case 2:
|
||||
priv = &g_flexcan2;
|
||||
memset(priv, 0, sizeof(struct imx9_driver_s));
|
||||
priv->base = IMX9_CAN2_BASE;
|
||||
priv->config = &imx9_flexcan2_config;
|
||||
case 2:
|
||||
priv = &g_flexcan2;
|
||||
memset(priv, 0, sizeof(struct imx9_driver_s));
|
||||
priv->base = IMX9_CAN2_BASE;
|
||||
priv->config = &imx9_flexcan2_config;
|
||||
# if defined(CONFIG_NET_CAN_CANFD)
|
||||
priv->canfd_capable = true;
|
||||
priv->mb_address_offset = 14;
|
||||
priv->canfd_capable = true;
|
||||
priv->mb_address_offset = 14;
|
||||
# else
|
||||
priv->canfd_capable = false;
|
||||
priv->mb_address_offset = 0;
|
||||
priv->canfd_capable = false;
|
||||
priv->mb_address_offset = 0;
|
||||
# endif
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# if defined(CONFIG_NET_CAN_CANFD)
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN2_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN2_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN2_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN2_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_IMX9_FLEXCAN3
|
||||
case 3:
|
||||
priv = &g_flexcan3;
|
||||
memset(priv, 0, sizeof(struct imx9_driver_s));
|
||||
priv->base = IMX9_CAN3_BASE;
|
||||
priv->config = &imx9_flexcan3_config;
|
||||
case 3:
|
||||
priv = &g_flexcan3;
|
||||
memset(priv, 0, sizeof(struct imx9_driver_s));
|
||||
priv->base = IMX9_CAN3_BASE;
|
||||
priv->config = &imx9_flexcan3_config;
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->canfd_capable = true;
|
||||
priv->mb_address_offset = 14;
|
||||
priv->canfd_capable = true;
|
||||
priv->mb_address_offset = 14;
|
||||
# else
|
||||
priv->canfd_capable = false;
|
||||
priv->mb_address_offset = 0;
|
||||
priv->canfd_capable = false;
|
||||
priv->mb_address_offset = 0;
|
||||
# endif
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN3_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN3_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN3_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN3_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN3_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN3_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN3_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN3_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN3_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN3_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN3_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN3_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_IMX9_FLEXCAN4
|
||||
case 4:
|
||||
priv = &g_flexcan4;
|
||||
memset(priv, 0, sizeof(struct imx9_driver_s));
|
||||
priv->base = IMX9_CAN4_BASE;
|
||||
priv->config = &imx9_flexcan4_config;
|
||||
case 4:
|
||||
priv = &g_flexcan4;
|
||||
memset(priv, 0, sizeof(struct imx9_driver_s));
|
||||
priv->base = IMX9_CAN4_BASE;
|
||||
priv->config = &imx9_flexcan4_config;
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->canfd_capable = true;
|
||||
priv->mb_address_offset = 14;
|
||||
priv->canfd_capable = true;
|
||||
priv->mb_address_offset = 14;
|
||||
# else
|
||||
priv->canfd_capable = false;
|
||||
priv->mb_address_offset = 0;
|
||||
priv->canfd_capable = false;
|
||||
priv->mb_address_offset = 0;
|
||||
# endif
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN4_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN4_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN4_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN4_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN4_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN4_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN4_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN4_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN4_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN4_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN4_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN4_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_IMX9_FLEXCAN5
|
||||
case 5:
|
||||
priv = &g_flexcan5;
|
||||
memset(priv, 0, sizeof(struct imx9_driver_s));
|
||||
priv->base = IMX9_CAN5_BASE;
|
||||
priv->config = &imx9_flexcan5_config;
|
||||
case 5:
|
||||
priv = &g_flexcan5;
|
||||
memset(priv, 0, sizeof(struct imx9_driver_s));
|
||||
priv->base = IMX9_CAN5_BASE;
|
||||
priv->config = &imx9_flexcan5_config;
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->canfd_capable = true;
|
||||
priv->mb_address_offset = 14;
|
||||
priv->canfd_capable = true;
|
||||
priv->mb_address_offset = 14;
|
||||
# else
|
||||
priv->canfd_capable = false;
|
||||
priv->mb_address_offset = 0;
|
||||
priv->canfd_capable = false;
|
||||
priv->mb_address_offset = 0;
|
||||
# endif
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN5_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN5_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN5_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN5_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN5_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN5_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN5_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN5_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN5_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN5_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN5_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN5_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return -ENODEV;
|
||||
default:
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
imx9_configure_clock(priv->config->clk_root, true);
|
||||
|
|
|
|||
|
|
@ -643,12 +643,14 @@ static int kinetis_transmit(struct kinetis_driver_s *priv)
|
|||
|
||||
#ifdef CONFIG_NET_CAN_RAW_TX_DEADLINE
|
||||
struct timespec ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
|
||||
if (priv->dev.d_sndlen > priv->dev.d_len)
|
||||
{
|
||||
struct timeval *tv =
|
||||
(struct timeval *)(priv->dev.d_buf + priv->dev.d_len);
|
||||
|
||||
priv->txmb[mbi].deadline = *tv;
|
||||
timeout = (tv->tv_sec - ts.tv_sec)*CLK_TCK
|
||||
+ ((tv->tv_usec - ts.tv_nsec / 1000)*CLK_TCK) / 1000000;
|
||||
|
|
@ -683,9 +685,11 @@ static int kinetis_transmit(struct kinetis_driver_s *priv)
|
|||
(peak_tx_mailbox_index_ > mbi ? peak_tx_mailbox_index_ : mbi);
|
||||
|
||||
union cs_e cs;
|
||||
|
||||
cs.cs = 0;
|
||||
cs.code = CAN_TXMB_DATAORREMOTE;
|
||||
struct mb_s *mb = &priv->tx[mbi];
|
||||
|
||||
mb->cs.code = CAN_TXMB_INACTIVE;
|
||||
|
||||
if (priv->dev.d_len == sizeof(struct can_frame))
|
||||
|
|
@ -1015,6 +1019,7 @@ static void kinetis_txdone(struct kinetis_driver_s *priv)
|
|||
|
||||
wd_cancel(&priv->txtimeout[mbi]);
|
||||
struct mb_s *mb = &priv->tx[mbi];
|
||||
|
||||
mb->cs.code = CAN_TXMB_INACTIVE;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1084,6 +1089,7 @@ static int kinetis_flexcan_interrupt(int irq, void *context,
|
|||
if (irq == priv->config->mb_irq)
|
||||
{
|
||||
uint32_t flags;
|
||||
|
||||
flags = getreg32(priv->base + KINETIS_CAN_IFLAG1_OFFSET);
|
||||
flags &= IFLAG1_RX;
|
||||
|
||||
|
|
@ -1141,6 +1147,7 @@ static void kinetis_txtimeout_work(void *arg)
|
|||
|
||||
struct timespec ts;
|
||||
struct timeval *now = (struct timeval *)&ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
now->tv_usec = ts.tv_nsec / 1000; /* timespec to timeval conversion */
|
||||
|
||||
|
|
@ -1166,6 +1173,7 @@ static void kinetis_txtimeout_work(void *arg)
|
|||
}
|
||||
|
||||
struct mb_s *mb = &priv->tx[mbi];
|
||||
|
||||
mb->cs.code = CAN_TXMB_ABORT;
|
||||
priv->txmb[mbi].pending = TX_ABORT;
|
||||
}
|
||||
|
|
@ -1230,6 +1238,7 @@ static uint32_t kinetis_waitesr2_change(uint32_t base, uint32_t mask,
|
|||
for (wait_ack = 0; wait_ack < timeout; wait_ack++)
|
||||
{
|
||||
uint32_t state = (getreg32(base + KINETIS_CAN_ESR2_OFFSET) & mask);
|
||||
|
||||
if (state == target_state)
|
||||
{
|
||||
return true;
|
||||
|
|
@ -1244,6 +1253,7 @@ static uint32_t kinetis_waitesr2_change(uint32_t base, uint32_t mask,
|
|||
static void kinetis_setfreeze(uint32_t base, uint32_t freeze)
|
||||
{
|
||||
uint32_t regval;
|
||||
|
||||
if (freeze)
|
||||
{
|
||||
/* Enter freeze mode */
|
||||
|
|
@ -1272,6 +1282,7 @@ static uint32_t kinetis_waitmcr_change(uint32_t base, uint32_t mask,
|
|||
{
|
||||
const bool state = (getreg32(base + KINETIS_CAN_MCR_OFFSET) & mask)
|
||||
!= 0;
|
||||
|
||||
if (state == target_state)
|
||||
{
|
||||
return true;
|
||||
|
|
@ -1492,6 +1503,7 @@ static int kinetis_ioctl(struct net_driver_s *dev, int cmd,
|
|||
{
|
||||
struct can_ioctl_data_s *req =
|
||||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
req->arbi_bitrate = priv->arbi_timing.bitrate;
|
||||
req->arbi_samplep = priv->arbi_timing.samplep;
|
||||
#ifdef CONFIG_NET_CAN_CANFD
|
||||
|
|
@ -1511,6 +1523,7 @@ static int kinetis_ioctl(struct net_driver_s *dev, int cmd,
|
|||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
struct flexcan_timeseg arbi_timing;
|
||||
|
||||
arbi_timing.bitrate = req->arbi_bitrate;
|
||||
arbi_timing.samplep = req->arbi_samplep;
|
||||
|
||||
|
|
@ -1525,6 +1538,7 @@ static int kinetis_ioctl(struct net_driver_s *dev, int cmd,
|
|||
|
||||
#ifdef CONFIG_NET_CAN_CANFD
|
||||
struct flexcan_timeseg data_timing;
|
||||
|
||||
data_timing.bitrate = req->data_bitrate;
|
||||
data_timing.samplep = req->data_samplep;
|
||||
|
||||
|
|
@ -1803,76 +1817,76 @@ int kinetis_caninitialize(int intf)
|
|||
switch (intf)
|
||||
{
|
||||
#ifdef CONFIG_KINETIS_FLEXCAN0
|
||||
case 0:
|
||||
priv = &g_flexcan0;
|
||||
memset(priv, 0, sizeof(struct kinetis_driver_s));
|
||||
priv->base = KINETIS_CAN0_BASE;
|
||||
priv->config = &kinetis_flexcan0_config;
|
||||
case 0:
|
||||
priv = &g_flexcan0;
|
||||
memset(priv, 0, sizeof(struct kinetis_driver_s));
|
||||
priv->base = KINETIS_CAN0_BASE;
|
||||
priv->config = &kinetis_flexcan0_config;
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN0_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN0_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN0_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN0_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_SAMPLEP;
|
||||
# endif
|
||||
regval = getreg32(KINETIS_SIM_SCGC6);
|
||||
regval |= SIM_SCGC6_FLEXCAN0;
|
||||
putreg32(regval, KINETIS_SIM_SCGC6);
|
||||
break;
|
||||
regval = getreg32(KINETIS_SIM_SCGC6);
|
||||
regval |= SIM_SCGC6_FLEXCAN0;
|
||||
putreg32(regval, KINETIS_SIM_SCGC6);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_KINETIS_FLEXCAN1
|
||||
case 1:
|
||||
priv = &g_flexcan1;
|
||||
memset(priv, 0, sizeof(struct kinetis_driver_s));
|
||||
priv->base = KINETIS_CAN1_BASE;
|
||||
priv->config = &kinetis_flexcan1_config;
|
||||
case 1:
|
||||
priv = &g_flexcan1;
|
||||
memset(priv, 0, sizeof(struct kinetis_driver_s));
|
||||
priv->base = KINETIS_CAN1_BASE;
|
||||
priv->config = &kinetis_flexcan1_config;
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN1_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN1_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN1_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN1_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_SAMPLEP;
|
||||
# endif
|
||||
regval = getreg32(KINETIS_SIM_SCGC3);
|
||||
regval |= SIM_SCGC3_FLEXCAN1;
|
||||
putreg32(regval, KINETIS_SIM_SCGC3);
|
||||
break;
|
||||
regval = getreg32(KINETIS_SIM_SCGC3);
|
||||
regval |= SIM_SCGC3_FLEXCAN1;
|
||||
putreg32(regval, KINETIS_SIM_SCGC3);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_KINETIS_FLEXCAN2
|
||||
case 2:
|
||||
priv = &g_flexcan2;
|
||||
memset(priv, 0, sizeof(struct kinetis_driver_s));
|
||||
priv->base = KINETIS_CAN2_BASE;
|
||||
priv->config = &kinetis_flexcan2_config;
|
||||
case 2:
|
||||
priv = &g_flexcan2;
|
||||
memset(priv, 0, sizeof(struct kinetis_driver_s));
|
||||
priv->base = KINETIS_CAN2_BASE;
|
||||
priv->config = &kinetis_flexcan2_config;
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN2_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN2_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN2_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN2_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return -ENODEV;
|
||||
default:
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (!kinetis_bitratetotimeseg(&priv->arbi_timing, 1, 0))
|
||||
|
|
|
|||
|
|
@ -645,12 +645,14 @@ static int s32k1xx_transmit(struct s32k1xx_driver_s *priv)
|
|||
|
||||
#ifdef CONFIG_NET_CAN_RAW_TX_DEADLINE
|
||||
struct timespec ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
|
||||
if (priv->dev.d_sndlen > priv->dev.d_len)
|
||||
{
|
||||
struct timeval *tv =
|
||||
(struct timeval *)(priv->dev.d_buf + priv->dev.d_len);
|
||||
|
||||
priv->txmb[mbi].deadline = *tv;
|
||||
timeout = (tv->tv_sec - ts.tv_sec)*CLK_TCK
|
||||
+ ((tv->tv_usec - ts.tv_nsec / 1000)*CLK_TCK) / 1000000;
|
||||
|
|
@ -685,9 +687,11 @@ static int s32k1xx_transmit(struct s32k1xx_driver_s *priv)
|
|||
(peak_tx_mailbox_index_ > mbi ? peak_tx_mailbox_index_ : mbi);
|
||||
|
||||
union cs_e cs;
|
||||
|
||||
cs.cs = 0;
|
||||
cs.code = CAN_TXMB_DATAORREMOTE;
|
||||
struct mb_s *mb = &priv->tx[mbi];
|
||||
|
||||
mb->cs.code = CAN_TXMB_INACTIVE;
|
||||
|
||||
if (priv->dev.d_len <= sizeof(struct can_frame))
|
||||
|
|
@ -1019,6 +1023,7 @@ static void s32k1xx_txdone(struct s32k1xx_driver_s *priv)
|
|||
|
||||
wd_cancel(&priv->txtimeout[mbi]);
|
||||
struct mb_s *mb = &priv->tx[mbi];
|
||||
|
||||
mb->cs.code = CAN_TXMB_INACTIVE;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1088,6 +1093,7 @@ static int s32k1xx_flexcan_interrupt(int irq, void *context,
|
|||
if (irq == priv->config->mb_irq)
|
||||
{
|
||||
uint32_t flags;
|
||||
|
||||
flags = getreg32(priv->base + S32K1XX_CAN_IFLAG1_OFFSET);
|
||||
flags &= IFLAG1_RX;
|
||||
|
||||
|
|
@ -1145,6 +1151,7 @@ static void s32k1xx_txtimeout_work(void *arg)
|
|||
|
||||
struct timespec ts;
|
||||
struct timeval *now = (struct timeval *)&ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
now->tv_usec = ts.tv_nsec / 1000; /* timespec to timeval conversion */
|
||||
|
||||
|
|
@ -1170,6 +1177,7 @@ static void s32k1xx_txtimeout_work(void *arg)
|
|||
}
|
||||
|
||||
struct mb_s *mb = &priv->tx[mbi];
|
||||
|
||||
mb->cs.code = CAN_TXMB_ABORT;
|
||||
priv->txmb[mbi].pending = TX_ABORT;
|
||||
}
|
||||
|
|
@ -1229,6 +1237,7 @@ static void s32k1xx_setenable(uint32_t base, uint32_t enable)
|
|||
static void s32k1xx_setfreeze(uint32_t base, uint32_t freeze)
|
||||
{
|
||||
uint32_t regval;
|
||||
|
||||
if (freeze)
|
||||
{
|
||||
/* Enter freeze mode */
|
||||
|
|
@ -1257,6 +1266,7 @@ static uint32_t s32k1xx_waitmcr_change(uint32_t base, uint32_t mask,
|
|||
{
|
||||
const bool state = (getreg32(base + S32K1XX_CAN_MCR_OFFSET) & mask)
|
||||
!= 0;
|
||||
|
||||
if (state == target_state)
|
||||
{
|
||||
return true;
|
||||
|
|
@ -1475,6 +1485,7 @@ static int s32k1xx_ioctl(struct net_driver_s *dev, int cmd,
|
|||
{
|
||||
struct can_ioctl_data_s *req =
|
||||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
req->arbi_bitrate = priv->arbi_timing.bitrate;
|
||||
req->arbi_samplep = priv->arbi_timing.samplep;
|
||||
#ifdef CONFIG_NET_CAN_CANFD
|
||||
|
|
@ -1494,6 +1505,7 @@ static int s32k1xx_ioctl(struct net_driver_s *dev, int cmd,
|
|||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
struct flexcan_timeseg arbi_timing;
|
||||
|
||||
arbi_timing.bitrate = req->arbi_bitrate;
|
||||
arbi_timing.samplep = req->arbi_samplep;
|
||||
|
||||
|
|
@ -1508,6 +1520,7 @@ static int s32k1xx_ioctl(struct net_driver_s *dev, int cmd,
|
|||
|
||||
#ifdef CONFIG_NET_CAN_CANFD
|
||||
struct flexcan_timeseg data_timing;
|
||||
|
||||
data_timing.bitrate = req->data_bitrate;
|
||||
data_timing.samplep = req->data_samplep;
|
||||
|
||||
|
|
@ -1794,70 +1807,70 @@ int s32k1xx_caninitialize(int intf)
|
|||
switch (intf)
|
||||
{
|
||||
#ifdef CONFIG_S32K1XX_FLEXCAN0
|
||||
case 0:
|
||||
priv = &g_flexcan0;
|
||||
memset(priv, 0, sizeof(struct s32k1xx_driver_s));
|
||||
priv->base = S32K1XX_FLEXCAN0_BASE;
|
||||
priv->config = &s32k1xx_flexcan0_config;
|
||||
case 0:
|
||||
priv = &g_flexcan0;
|
||||
memset(priv, 0, sizeof(struct s32k1xx_driver_s));
|
||||
priv->base = S32K1XX_FLEXCAN0_BASE;
|
||||
priv->config = &s32k1xx_flexcan0_config;
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN0_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN0_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN0_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN0_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_S32K1XX_FLEXCAN1
|
||||
case 1:
|
||||
priv = &g_flexcan1;
|
||||
memset(priv, 0, sizeof(struct s32k1xx_driver_s));
|
||||
priv->base = S32K1XX_FLEXCAN1_BASE;
|
||||
priv->config = &s32k1xx_flexcan1_config;
|
||||
case 1:
|
||||
priv = &g_flexcan1;
|
||||
memset(priv, 0, sizeof(struct s32k1xx_driver_s));
|
||||
priv->base = S32K1XX_FLEXCAN1_BASE;
|
||||
priv->config = &s32k1xx_flexcan1_config;
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN1_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN1_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN1_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN1_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_S32K1XX_FLEXCAN2
|
||||
case 2:
|
||||
priv = &g_flexcan2;
|
||||
memset(priv, 0, sizeof(struct s32k1xx_driver_s));
|
||||
priv->base = S32K1XX_FLEXCAN2_BASE;
|
||||
priv->config = &s32k1xx_flexcan2_config;
|
||||
case 2:
|
||||
priv = &g_flexcan2;
|
||||
memset(priv, 0, sizeof(struct s32k1xx_driver_s));
|
||||
priv->base = S32K1XX_FLEXCAN2_BASE;
|
||||
priv->config = &s32k1xx_flexcan2_config;
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN2_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN2_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN2_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN2_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return -ENODEV;
|
||||
default:
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (!s32k1xx_bitratetotimeseg(&priv->arbi_timing, 1, 0))
|
||||
|
|
|
|||
|
|
@ -805,12 +805,14 @@ static int s32k3xx_transmit(struct s32k3xx_driver_s *priv)
|
|||
|
||||
#ifdef CONFIG_NET_CAN_RAW_TX_DEADLINE
|
||||
struct timespec ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
|
||||
if (priv->dev.d_sndlen > priv->dev.d_len)
|
||||
{
|
||||
struct timeval *tv =
|
||||
(struct timeval *)(priv->dev.d_buf + priv->dev.d_len);
|
||||
|
||||
priv->txmb[mbi].deadline = *tv;
|
||||
timeout = (tv->tv_sec - ts.tv_sec)*CLK_TCK
|
||||
+ ((tv->tv_usec - ts.tv_nsec / 1000)*CLK_TCK) / 1000000;
|
||||
|
|
@ -845,9 +847,11 @@ static int s32k3xx_transmit(struct s32k3xx_driver_s *priv)
|
|||
(peak_tx_mailbox_index_ > mbi ? peak_tx_mailbox_index_ : mbi);
|
||||
|
||||
union cs_e cs;
|
||||
|
||||
cs.cs = 0;
|
||||
cs.code = CAN_TXMB_DATAORREMOTE;
|
||||
struct mb_s *mb = &priv->tx[mbi];
|
||||
|
||||
mb->cs.code = CAN_TXMB_INACTIVE;
|
||||
|
||||
if (priv->dev.d_len <= sizeof(struct can_frame))
|
||||
|
|
@ -1067,7 +1071,7 @@ static void s32k3xx_receive(struct s32k3xx_driver_s *priv, uint32_t flags)
|
|||
else /* CAN 2.0 Frame */
|
||||
#endif
|
||||
{
|
||||
struct can_frame *frame = (struct can_frame *)priv->rxdesc;
|
||||
struct can_frame *frame = (struct can_frame *)priv->rxdesc;
|
||||
|
||||
if (rf->cs.ide)
|
||||
{
|
||||
|
|
@ -1175,6 +1179,7 @@ static void s32k3xx_txdone(struct s32k3xx_driver_s *priv)
|
|||
|
||||
wd_cancel(&priv->txtimeout[mbi]);
|
||||
struct mb_s *mb = &priv->tx[mbi];
|
||||
|
||||
mb->cs.code = CAN_TXMB_INACTIVE;
|
||||
#endif
|
||||
}
|
||||
|
|
@ -1243,6 +1248,7 @@ static int s32k3xx_flexcan_interrupt(int irq, void *context, void *arg)
|
|||
if (irq == priv->config->mb_irq)
|
||||
{
|
||||
uint32_t flags;
|
||||
|
||||
flags = getreg32(priv->base + S32K3XX_CAN_IFLAG1_OFFSET);
|
||||
flags &= IFLAG1_RX;
|
||||
|
||||
|
|
@ -1300,6 +1306,7 @@ static void s32k3xx_txtimeout_work(void *arg)
|
|||
|
||||
struct timespec ts;
|
||||
struct timeval *now = (struct timeval *)&ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
now->tv_usec = ts.tv_nsec / 1000; /* timespec to timeval conversion */
|
||||
|
||||
|
|
@ -1325,6 +1332,7 @@ static void s32k3xx_txtimeout_work(void *arg)
|
|||
}
|
||||
|
||||
struct mb_s *mb = &priv->tx[mbi];
|
||||
|
||||
mb->cs.code = CAN_TXMB_ABORT;
|
||||
priv->txmb[mbi].pending = TX_ABORT;
|
||||
}
|
||||
|
|
@ -1384,6 +1392,7 @@ static void s32k3xx_setenable(uint32_t base, uint32_t enable)
|
|||
static void s32k3xx_setfreeze(uint32_t base, uint32_t freeze)
|
||||
{
|
||||
uint32_t regval;
|
||||
|
||||
if (freeze)
|
||||
{
|
||||
/* Enter freeze mode */
|
||||
|
|
@ -1412,6 +1421,7 @@ static uint32_t s32k3xx_waitmcr_change(uint32_t base, uint32_t mask,
|
|||
{
|
||||
const bool state = (getreg32(base + S32K3XX_CAN_MCR_OFFSET) & mask)
|
||||
!= 0;
|
||||
|
||||
if (state == target_state)
|
||||
{
|
||||
return true;
|
||||
|
|
@ -1663,6 +1673,7 @@ static int s32k3xx_ioctl(struct net_driver_s *dev, int cmd,
|
|||
{
|
||||
struct can_ioctl_data_s *req =
|
||||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
req->arbi_bitrate = priv->arbi_timing.bitrate;
|
||||
req->arbi_samplep = priv->arbi_timing.samplep;
|
||||
#ifdef CONFIG_NET_CAN_CANFD
|
||||
|
|
@ -1682,6 +1693,7 @@ static int s32k3xx_ioctl(struct net_driver_s *dev, int cmd,
|
|||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
struct flexcan_timeseg arbi_timing;
|
||||
|
||||
arbi_timing.bitrate = req->arbi_bitrate;
|
||||
arbi_timing.samplep = req->arbi_samplep;
|
||||
|
||||
|
|
@ -1697,6 +1709,7 @@ static int s32k3xx_ioctl(struct net_driver_s *dev, int cmd,
|
|||
|
||||
#ifdef CONFIG_NET_CAN_CANFD
|
||||
struct flexcan_timeseg data_timing;
|
||||
|
||||
data_timing.bitrate = req->data_bitrate;
|
||||
data_timing.samplep = req->data_samplep;
|
||||
|
||||
|
|
@ -2019,139 +2032,139 @@ int s32k3xx_caninitialize(int intf)
|
|||
switch (intf)
|
||||
{
|
||||
#ifdef CONFIG_S32K3XX_FLEXCAN0
|
||||
case 0:
|
||||
priv = &g_flexcan0;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN0_BASE;
|
||||
priv->config = &s32k3xx_flexcan0_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN0_CLK);
|
||||
case 0:
|
||||
priv = &g_flexcan0;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN0_BASE;
|
||||
priv->config = &s32k3xx_flexcan0_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN0_CLK);
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN0_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN0_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN0_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN0_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN0_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN0_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_S32K3XX_FLEXCAN1
|
||||
case 1:
|
||||
priv = &g_flexcan1;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN1_BASE;
|
||||
priv->config = &s32k3xx_flexcan1_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN1_CLK);
|
||||
case 1:
|
||||
priv = &g_flexcan1;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN1_BASE;
|
||||
priv->config = &s32k3xx_flexcan1_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN1_CLK);
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN1_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN1_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN1_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN1_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN1_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN1_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_S32K3XX_FLEXCAN2
|
||||
case 2:
|
||||
priv = &g_flexcan2;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN2_BASE;
|
||||
priv->config = &s32k3xx_flexcan2_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN2_CLK);
|
||||
case 2:
|
||||
priv = &g_flexcan2;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN2_BASE;
|
||||
priv->config = &s32k3xx_flexcan2_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN2_CLK);
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN2_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN2_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN2_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN2_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN2_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN2_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_S32K3XX_FLEXCAN3
|
||||
case 3:
|
||||
priv = &g_flexcan3;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN3_BASE;
|
||||
priv->config = &s32k3xx_flexcan3_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN3_CLK);
|
||||
case 3:
|
||||
priv = &g_flexcan3;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN3_BASE;
|
||||
priv->config = &s32k3xx_flexcan3_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN3_CLK);
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN3_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN3_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN3_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN3_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN3_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN3_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN3_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN3_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN3_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN3_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN3_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN3_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_S32K3XX_FLEXCAN4
|
||||
case 4:
|
||||
priv = &g_flexcan4;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN4_BASE;
|
||||
priv->config = &s32k3xx_flexcan4_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN4_CLK);
|
||||
case 4:
|
||||
priv = &g_flexcan4;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN4_BASE;
|
||||
priv->config = &s32k3xx_flexcan4_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN4_CLK);
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN4_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN4_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN4_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN4_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN4_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN4_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN4_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN4_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN4_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN4_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN4_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN4_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_S32K3XX_FLEXCAN5
|
||||
case 5:
|
||||
priv = &g_flexcan5;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN5_BASE;
|
||||
priv->config = &s32k3xx_flexcan5_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN5_CLK);
|
||||
case 5:
|
||||
priv = &g_flexcan5;
|
||||
memset(priv, 0, sizeof(struct s32k3xx_driver_s));
|
||||
priv->base = S32K3XX_FLEXCAN5_BASE;
|
||||
priv->config = &s32k3xx_flexcan5_config;
|
||||
priv->clk_freq = s32k3xx_get_freq(FLEXCAN5_CLK);
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN5_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN5_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN5_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN5_DATA_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN5_ARBI_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN5_ARBI_SAMPLEP;
|
||||
priv->data_timing.bitrate = CONFIG_FLEXCAN5_DATA_BITRATE;
|
||||
priv->data_timing.samplep = CONFIG_FLEXCAN5_DATA_SAMPLEP;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN5_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN5_SAMPLEP;
|
||||
priv->arbi_timing.bitrate = CONFIG_FLEXCAN5_BITRATE;
|
||||
priv->arbi_timing.samplep = CONFIG_FLEXCAN5_SAMPLEP;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return -ENODEV;
|
||||
default:
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (!s32k3xx_bitratetotimeseg(&priv->arbi_timing, 1, 0, priv->clk_freq))
|
||||
|
|
@ -2187,7 +2200,7 @@ int s32k3xx_caninitialize(int intf)
|
|||
/* Attach the flexcan interrupt handler */
|
||||
|
||||
if (priv->config->bus_irq > 0)
|
||||
{
|
||||
{
|
||||
if (irq_attach(priv->config->bus_irq, s32k3xx_flexcan_interrupt, priv))
|
||||
{
|
||||
/* We could not attach the ISR to the interrupt */
|
||||
|
|
@ -2195,10 +2208,10 @@ int s32k3xx_caninitialize(int intf)
|
|||
nerr("ERROR: Failed to attach CAN bus IRQ\n");
|
||||
return -EAGAIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (priv->config->error_irq > 0)
|
||||
{
|
||||
{
|
||||
if (irq_attach(priv->config->error_irq,
|
||||
s32k3xx_flexcan_interrupt, priv))
|
||||
{
|
||||
|
|
@ -2207,7 +2220,7 @@ int s32k3xx_caninitialize(int intf)
|
|||
nerr("ERROR: Failed to attach CAN error IRQ\n");
|
||||
return -EAGAIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (priv->config->lprx_irq > 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -518,6 +518,7 @@ static void fdcan_dumpregs(struct fdcan_driver_s *priv)
|
|||
printf("CAN%d Base: 0x%lx\n", priv->iface_idx, priv->base);
|
||||
|
||||
uint32_t regval;
|
||||
|
||||
regval = getreg32(priv->base + STM32_FDCAN_CCCR_OFFSET);
|
||||
printf("CCCR = 0x%lx\n", regval);
|
||||
regval = getreg32(priv->base + STM32_FDCAN_ECR_OFFSET);
|
||||
|
|
@ -721,6 +722,7 @@ static bool fdcan_txringfull(struct fdcan_driver_s *priv)
|
|||
*/
|
||||
|
||||
uint32_t regval = getreg32(priv->base + STM32_FDCAN_TXBC_OFFSET);
|
||||
|
||||
if ((regval & FDCAN_TXBC_TFQS) == 0)
|
||||
{
|
||||
nerr("No Tx FIFO buffers assigned? Check your message RAM config\n");
|
||||
|
|
@ -765,6 +767,7 @@ static int fdcan_transmit(struct fdcan_driver_s *priv)
|
|||
/* First, check if there are any slots available in the queue */
|
||||
|
||||
uint32_t regval = getreg32(priv->base + STM32_FDCAN_TXFQS_OFFSET);
|
||||
|
||||
if ((regval & FDCAN_TXFQS_TFQF) == FDCAN_TXFQS_TFQF)
|
||||
{
|
||||
/* Tx FIFO / Queue is full */
|
||||
|
|
@ -795,6 +798,7 @@ static int fdcan_transmit(struct fdcan_driver_s *priv)
|
|||
#ifdef CONFIG_NET_CAN_RAW_TX_DEADLINE
|
||||
int32_t timeout = 0;
|
||||
struct timespec ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
|
||||
if (priv->dev.d_sndlen > priv->dev.d_len)
|
||||
|
|
@ -803,6 +807,7 @@ static int fdcan_transmit(struct fdcan_driver_s *priv)
|
|||
|
||||
struct timeval *tv =
|
||||
(struct timeval *)(priv->dev.d_buf + priv->dev.d_len);
|
||||
|
||||
priv->txmb[mbi].deadline = *tv;
|
||||
timeout = (tv->tv_sec - ts.tv_sec)*CLK_TCK
|
||||
+ ((tv->tv_usec - ts.tv_nsec / 1000)*CLK_TCK) / 1000000;
|
||||
|
|
@ -1251,13 +1256,13 @@ static void fdcan_receive_work(void *arg)
|
|||
fdcan_check_errors(priv);
|
||||
|
||||
#ifdef CONFIG_NET_CAN_ERRORS
|
||||
uint32_t regval;
|
||||
uint32_t regval;
|
||||
|
||||
/* Turning back on all configured RX error interrupts */
|
||||
/* Turning back on all configured RX error interrupts */
|
||||
|
||||
regval = getreg32(priv->base + STM32_FDCAN_IE_OFFSET);
|
||||
regval |= FDCAN_RXERR_INTS;
|
||||
putreg32(regval, priv->base + STM32_FDCAN_IE_OFFSET);
|
||||
regval = getreg32(priv->base + STM32_FDCAN_IE_OFFSET);
|
||||
regval |= FDCAN_RXERR_INTS;
|
||||
putreg32(regval, priv->base + STM32_FDCAN_IE_OFFSET);
|
||||
#endif
|
||||
|
||||
leave_critical_section(flags);
|
||||
|
|
@ -1285,6 +1290,7 @@ static void fdcan_txdone(struct fdcan_driver_s *priv)
|
|||
/* Read and reset the interrupt flag */
|
||||
|
||||
uint32_t ir = getreg32(priv->base + STM32_FDCAN_IR_OFFSET);
|
||||
|
||||
if (ir & FDCAN_IR_TC)
|
||||
{
|
||||
putreg32(FDCAN_IR_TC, priv->base + STM32_FDCAN_IR_OFFSET);
|
||||
|
|
@ -1524,6 +1530,7 @@ static void fdcan_txtimeout_work(void *arg)
|
|||
|
||||
struct timespec ts;
|
||||
struct timeval *now = (struct timeval *)&ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
now->tv_usec = ts.tv_nsec / 1000; /* timespec to timeval conversion */
|
||||
|
||||
|
|
@ -1697,9 +1704,11 @@ static bool fdcan_waitccr_change(uint32_t base, uint32_t mask,
|
|||
uint32_t target_state)
|
||||
{
|
||||
const unsigned timeout = 1000;
|
||||
|
||||
for (unsigned wait_ack = 0; wait_ack < timeout; wait_ack++)
|
||||
{
|
||||
const bool state = (getreg32(base + STM32_FDCAN_CCCR_OFFSET) & mask);
|
||||
|
||||
if (state == target_state)
|
||||
{
|
||||
return true;
|
||||
|
|
@ -1730,6 +1739,7 @@ static void fdcan_enable_interrupts(struct fdcan_driver_s *priv)
|
|||
/* Enable both interrupt lines at the device level */
|
||||
|
||||
const uint32_t ile = FDCAN_ILE_EINT0 | FDCAN_ILE_EINT1;
|
||||
|
||||
modifyreg32(priv->base + STM32_FDCAN_ILE_OFFSET, 0, ile);
|
||||
|
||||
/* Enable both lines at the NVIC level */
|
||||
|
|
@ -1762,6 +1772,7 @@ static void fdcan_disable_interrupts(struct fdcan_driver_s *priv)
|
|||
/* Disable both interrupt lines at the device level */
|
||||
|
||||
const uint32_t ile = FDCAN_ILE_EINT0 | FDCAN_ILE_EINT1;
|
||||
|
||||
modifyreg32(priv->base + STM32_FDCAN_ILE_OFFSET, ile, 0);
|
||||
}
|
||||
|
||||
|
|
@ -1961,6 +1972,7 @@ static int fdcan_netdev_ioctl(struct net_driver_s *dev, int cmd,
|
|||
{
|
||||
struct can_ioctl_data_s *req =
|
||||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
req->arbi_bitrate = priv->arbi_timing.bitrate;
|
||||
#ifdef CONFIG_NET_CAN_CANFD
|
||||
req->data_bitrate = priv->data_timing.bitrate;
|
||||
|
|
@ -2060,6 +2072,7 @@ int fdcan_initialize(struct fdcan_driver_s *priv)
|
|||
|
||||
#ifdef CONFIG_STM32_FDCAN_REGDEBUG
|
||||
const struct fdcan_bitseg *tim = &priv->arbi_timing;
|
||||
|
||||
ninfo("[fdcan][arbi] Timings: presc=%u sjw=%u bs1=%u bs2=%u\r\n",
|
||||
tim->prescaler, tim->sjw, tim->bs1, tim->bs2);
|
||||
#endif
|
||||
|
|
@ -2210,6 +2223,7 @@ int fdcan_initialize(struct fdcan_driver_s *priv)
|
|||
/* Standard ID Filters: Allow space for 128 filters (128 words) */
|
||||
|
||||
const uint8_t n_stdid = 128;
|
||||
|
||||
priv->message_ram.filt_stdid_addr = gl_ram_base + ram_offset * WORD_LENGTH;
|
||||
|
||||
regval = (n_stdid << FDCAN_SIDFC_LSS_SHIFT) & FDCAN_SIDFC_LSS_MASK;
|
||||
|
|
@ -2237,6 +2251,7 @@ int fdcan_initialize(struct fdcan_driver_s *priv)
|
|||
*/
|
||||
|
||||
const uint8_t n_extid = 128;
|
||||
|
||||
priv->message_ram.filt_extid_addr = gl_ram_base + ram_offset * WORD_LENGTH;
|
||||
|
||||
regval = (n_extid << FDCAN_XIDFC_LSE_SHIFT) & FDCAN_XIDFC_LSE_MASK;
|
||||
|
|
@ -2425,64 +2440,64 @@ int stm32_fdcansockinitialize(int intf)
|
|||
switch (intf)
|
||||
{
|
||||
#ifdef CONFIG_STM32_FDCAN1
|
||||
case 0:
|
||||
priv = &g_fdcan0;
|
||||
memset(priv, 0, sizeof(struct fdcan_driver_s));
|
||||
priv->base = STM32_FDCAN1_BASE;
|
||||
priv->iface_idx = 0;
|
||||
priv->config = &stm32_fdcan0_config;
|
||||
case 0:
|
||||
priv = &g_fdcan0;
|
||||
memset(priv, 0, sizeof(struct fdcan_driver_s));
|
||||
priv->base = STM32_FDCAN1_BASE;
|
||||
priv->iface_idx = 0;
|
||||
priv->config = &stm32_fdcan0_config;
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN1_ARBI_BITRATE;
|
||||
priv->data_timing.bitrate = CONFIG_FDCAN1_DATA_BITRATE;
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN1_ARBI_BITRATE;
|
||||
priv->data_timing.bitrate = CONFIG_FDCAN1_DATA_BITRATE;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN1_BITRATE;
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN1_BITRATE;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STM32_FDCAN2
|
||||
case 1:
|
||||
priv = &g_fdcan1;
|
||||
memset(priv, 0, sizeof(struct fdcan_driver_s));
|
||||
priv->base = STM32_FDCAN2_BASE;
|
||||
priv->iface_idx = 1;
|
||||
priv->config = &stm32_fdcan1_config;
|
||||
case 1:
|
||||
priv = &g_fdcan1;
|
||||
memset(priv, 0, sizeof(struct fdcan_driver_s));
|
||||
priv->base = STM32_FDCAN2_BASE;
|
||||
priv->iface_idx = 1;
|
||||
priv->config = &stm32_fdcan1_config;
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN2_ARBI_BITRATE;
|
||||
priv->data_timing.bitrate = CONFIG_FDCAN2_DATA_BITRATE;
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN2_ARBI_BITRATE;
|
||||
priv->data_timing.bitrate = CONFIG_FDCAN2_DATA_BITRATE;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN2_BITRATE;
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN2_BITRATE;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STM32_FDCAN3
|
||||
case 2:
|
||||
priv = &g_fdcan2;
|
||||
memset(priv, 0, sizeof(struct fdcan_driver_s));
|
||||
priv->base = STM32_FDCAN3_BASE;
|
||||
priv->iface_idx = 2;
|
||||
priv->config = &stm32_fdcan2_config;
|
||||
case 2:
|
||||
priv = &g_fdcan2;
|
||||
memset(priv, 0, sizeof(struct fdcan_driver_s));
|
||||
priv->base = STM32_FDCAN3_BASE;
|
||||
priv->iface_idx = 2;
|
||||
priv->config = &stm32_fdcan2_config;
|
||||
|
||||
/* Default bitrate configuration */
|
||||
/* Default bitrate configuration */
|
||||
|
||||
# ifdef CONFIG_NET_CAN_CANFD
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN3_ARBI_BITRATE;
|
||||
priv->data_timing.bitrate = CONFIG_FDCAN3_DATA_BITRATE;
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN3_ARBI_BITRATE;
|
||||
priv->data_timing.bitrate = CONFIG_FDCAN3_DATA_BITRATE;
|
||||
# else
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN3_BITRATE;
|
||||
priv->arbi_timing.bitrate = CONFIG_FDCAN3_BITRATE;
|
||||
# endif
|
||||
break;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return -ENODEV;
|
||||
default:
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (fdcan_bittiming(&priv->arbi_timing) != OK)
|
||||
|
|
|
|||
|
|
@ -594,6 +594,7 @@ static bool imx9_txringfull(struct imx9_driver_s *priv)
|
|||
for (mbi = RXMBCOUNT; mbi < TOTALMBCOUNT; mbi++)
|
||||
{
|
||||
volatile struct mb_s *mb = flexcan_get_mb(priv, mbi);
|
||||
|
||||
if (CAN_MB_CS_CODE(mb->cs) != CAN_TXMB_DATAORREMOTE)
|
||||
{
|
||||
return false;
|
||||
|
|
@ -662,6 +663,7 @@ static int imx9_transmit(struct imx9_driver_s *priv)
|
|||
|
||||
#ifdef CONFIG_NET_CAN_RAW_TX_DEADLINE
|
||||
struct timespec ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
|
||||
if (priv->dev.d_sndlen > priv->dev.d_len)
|
||||
|
|
@ -702,6 +704,7 @@ static int imx9_transmit(struct imx9_driver_s *priv)
|
|||
if (priv->dev.d_len == sizeof(struct can_frame))
|
||||
{
|
||||
struct can_frame *frame = (struct can_frame *)priv->dev.d_buf;
|
||||
|
||||
can_id = frame->can_id;
|
||||
len = 8;
|
||||
can_dlc = frame->can_dlc;
|
||||
|
|
@ -711,6 +714,7 @@ static int imx9_transmit(struct imx9_driver_s *priv)
|
|||
else
|
||||
{
|
||||
struct canfd_frame *frame = (struct canfd_frame *)priv->dev.d_buf;
|
||||
|
||||
cs |= CAN_MB_CS_EDL;
|
||||
cs |= frame->flags & CANFD_BRS ? CAN_MB_CS_BRS : 0;
|
||||
can_id = frame->can_id;
|
||||
|
|
@ -898,6 +902,7 @@ static void imx9_receive(struct imx9_driver_s *priv)
|
|||
size_t frame_len;
|
||||
|
||||
uint32_t flags = getreg32(priv->base + IMX9_CAN_IFLAG1_OFFSET);
|
||||
|
||||
flags &= IFLAG1_RX;
|
||||
|
||||
while (flags != 0)
|
||||
|
|
@ -1278,6 +1283,7 @@ static void imx9_txtimeout_work(void *arg)
|
|||
volatile struct mb_s *mb;
|
||||
struct timespec ts;
|
||||
struct timeval *now = (struct timeval *)&ts;
|
||||
|
||||
clock_systime_timespec(&ts);
|
||||
now->tv_usec = ts.tv_nsec / 1000; /* timespec to timeval conversion */
|
||||
|
||||
|
|
@ -1613,6 +1619,7 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
|
|||
struct imx9_driver_s *priv = (struct imx9_driver_s *)dev;
|
||||
struct can_ioctl_data_s *req =
|
||||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
req->arbi_bitrate = priv->arbi_timing.bitrate;
|
||||
req->arbi_samplep = priv->arbi_timing.samplep;
|
||||
if (priv->canfd_capable)
|
||||
|
|
@ -1654,9 +1661,9 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
|
|||
|
||||
priv->arbi_timing = arbi_timing;
|
||||
if (priv->canfd_capable)
|
||||
{
|
||||
priv->data_timing = data_timing;
|
||||
}
|
||||
{
|
||||
priv->data_timing = data_timing;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -1666,12 +1673,13 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
|
|||
struct imx9_driver_s *priv = (struct imx9_driver_s *)dev;
|
||||
struct can_ioctl_filter_s *req =
|
||||
(struct can_ioctl_filter_s *)((uintptr_t)arg);
|
||||
|
||||
if (!req)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = imx9_add_filter(priv, req->ftype, 0, req->fid1, req->fid2);
|
||||
ret = imx9_add_filter(priv, req->ftype, 0, req->fid1, req->fid2);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -1680,12 +1688,13 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
|
|||
struct imx9_driver_s *priv = (struct imx9_driver_s *)dev;
|
||||
struct can_ioctl_filter_s *req =
|
||||
(struct can_ioctl_filter_s *)((uintptr_t)arg);
|
||||
|
||||
if (!req)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = imx9_add_filter(priv, req->ftype, 1, req->fid1, req->fid2);
|
||||
ret = imx9_add_filter(priv, req->ftype, 1, req->fid1, req->fid2);
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
@ -1693,6 +1702,7 @@ static int imx9_ioctl(struct net_driver_s *dev, int cmd,
|
|||
case SIOCDCANEXTFILTER: /* Reset EXT ID CAN filter */
|
||||
{
|
||||
struct imx9_driver_s *priv = (struct imx9_driver_s *)dev;
|
||||
|
||||
ret = imx9_reset_filter(priv);
|
||||
}
|
||||
break;
|
||||
|
|
@ -2214,23 +2224,23 @@ int imx9_caninitialize(int intf)
|
|||
switch (intf)
|
||||
{
|
||||
#ifdef CONFIG_IMX9_FLEXCAN1
|
||||
case 1:
|
||||
imx9_ccm_configure_root_clock(CCM_CR_CAN1, SYS_PLL1PFD1DIV2, 5);
|
||||
imx9_ccm_gate_on(CCM_LPCG_CAN1, true);
|
||||
priv = &g_flexcan1;
|
||||
break;
|
||||
case 1:
|
||||
imx9_ccm_configure_root_clock(CCM_CR_CAN1, SYS_PLL1PFD1DIV2, 5);
|
||||
imx9_ccm_gate_on(CCM_LPCG_CAN1, true);
|
||||
priv = &g_flexcan1;
|
||||
break;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_IMX9_FLEXCAN2
|
||||
case 2:
|
||||
imx9_ccm_configure_root_clock(CCM_CR_CAN2, SYS_PLL1PFD1DIV2, 5);
|
||||
imx9_ccm_gate_on(CCM_LPCG_CAN2, true);
|
||||
priv = &g_flexcan2;
|
||||
break;
|
||||
case 2:
|
||||
imx9_ccm_configure_root_clock(CCM_CR_CAN2, SYS_PLL1PFD1DIV2, 5);
|
||||
imx9_ccm_gate_on(CCM_LPCG_CAN2, true);
|
||||
priv = &g_flexcan2;
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return -ENODEV;
|
||||
default:
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Get and store the clock (should be 80 MHz now) */
|
||||
|
|
|
|||
|
|
@ -1371,6 +1371,7 @@ static void mpfs_can_set_int_ebl(mpfs_can_instance_t *priv,
|
|||
uint32_t flag)
|
||||
{
|
||||
uint32_t reg = mpfs_can_get_int_ebl(priv);
|
||||
|
||||
putreg32(reg | flag, priv->reg_base + MPFS_CAN_INT_ENABLE_OFFSET);
|
||||
}
|
||||
|
||||
|
|
@ -1414,6 +1415,7 @@ static void mpfs_can_clear_int_ebl(mpfs_can_instance_t *priv,
|
|||
uint32_t flag)
|
||||
{
|
||||
uint32_t reg = mpfs_can_get_int_ebl(priv);
|
||||
|
||||
putreg32(reg & ~flag, priv->reg_base + MPFS_CAN_INT_ENABLE_OFFSET);
|
||||
}
|
||||
|
||||
|
|
@ -1530,6 +1532,7 @@ static uint32_t mpfs_can_get_int_status(mpfs_can_instance_t *priv)
|
|||
static uint8_t mpfs_can_get_error_status(mpfs_can_instance_t *priv)
|
||||
{
|
||||
uint32_t reg = getreg32(priv->reg_base + MPFS_CAN_ERROR_STATUS_OFFSET);
|
||||
|
||||
reg = ((reg & MPFS_CAN_ERROR_STATUS_ERROR_STATE)
|
||||
>> MPFS_CAN_ERROR_STATUS_ERROR_STATE_SHIFT);
|
||||
return (uint8_t)reg;
|
||||
|
|
@ -1760,12 +1763,14 @@ static uint8_t mpfs_can_set_bitrate(mpfs_can_instance_t *priv,
|
|||
static uint32_t mpfs_can_get_sample_point(mpfs_can_instance_t *priv)
|
||||
{
|
||||
uint32_t reg;
|
||||
|
||||
reg = getreg32(priv->reg_base + MPFS_CAN_CAN_CONFIG_OFFSET);
|
||||
uint32_t tseg1 = ((reg & MPFS_CAN_CAN_CONFIG_CFG_TSEG1) >>
|
||||
MPFS_CAN_CAN_CONFIG_CFG_TSEG1_SHIFT) + 1;
|
||||
uint32_t tseg2 = ((reg & MPFS_CAN_CAN_CONFIG_CFG_TSEG2) >>
|
||||
MPFS_CAN_CAN_CONFIG_CFG_TSEG2_SHIFT) + 1;
|
||||
const uint32_t sync_seg = 1;
|
||||
|
||||
return (sync_seg + tseg1) * 100 / (sync_seg + tseg1 + tseg2);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1838,7 +1843,7 @@ static uint8_t mpfs_can_config_buffer(mpfs_can_instance_t *priv)
|
|||
mpfs_can_config_buffer_n(priv, buffer_number, &canrxobj);
|
||||
}
|
||||
|
||||
success = CAN_OK;
|
||||
success = CAN_OK;
|
||||
}
|
||||
|
||||
return success;
|
||||
|
|
@ -1945,6 +1950,7 @@ mpfs_can_get_rx_buffer_status(mpfs_can_instance_t *priv)
|
|||
static uint32_t mpfs_can_get_rx_error_count(mpfs_can_instance_t *priv)
|
||||
{
|
||||
uint32_t reg = getreg32(priv->reg_base + MPFS_CAN_ERROR_STATUS_OFFSET);
|
||||
|
||||
reg = ((reg & MPFS_CAN_ERROR_STATUS_RX_ERR_CNT)
|
||||
>> MPFS_CAN_ERROR_STATUS_RX_ERR_CNT_SHIFT);
|
||||
return reg;
|
||||
|
|
@ -1976,6 +1982,7 @@ static uint32_t mpfs_can_get_rx_error_count(mpfs_can_instance_t *priv)
|
|||
static inline bool mpfs_can_get_rx_gte96(mpfs_can_instance_t *priv)
|
||||
{
|
||||
uint32_t reg = getreg32(priv->reg_base + MPFS_CAN_ERROR_STATUS_OFFSET);
|
||||
|
||||
reg &= MPFS_CAN_ERROR_STATUS_RXGTE96;
|
||||
return (bool)reg;
|
||||
}
|
||||
|
|
@ -2088,6 +2095,7 @@ static uint32_t mpfs_can_get_tx_buffer_status(mpfs_can_instance_t *priv)
|
|||
static uint32_t mpfs_can_get_tx_error_count(mpfs_can_instance_t *priv)
|
||||
{
|
||||
uint32_t reg = getreg32(priv->reg_base + MPFS_CAN_ERROR_STATUS_OFFSET);
|
||||
|
||||
reg = ((reg & MPFS_CAN_ERROR_STATUS_TX_ERR_CNT)
|
||||
>> MPFS_CAN_ERROR_STATUS_TX_ERR_CNT_SHIFT);
|
||||
return reg;
|
||||
|
|
@ -2119,6 +2127,7 @@ static uint32_t mpfs_can_get_tx_error_count(mpfs_can_instance_t *priv)
|
|||
static inline bool mpfs_can_get_tx_gte96(mpfs_can_instance_t *priv)
|
||||
{
|
||||
uint32_t reg = getreg32(priv->reg_base + MPFS_CAN_ERROR_STATUS_OFFSET);
|
||||
|
||||
reg &= MPFS_CAN_ERROR_STATUS_TXGTE96;
|
||||
return (bool)reg;
|
||||
}
|
||||
|
|
@ -2308,70 +2317,71 @@ static int mpfs_ioctl(struct netdev_lowerhalf_s *dev, int cmd,
|
|||
switch (cmd)
|
||||
{
|
||||
#ifdef CONFIG_NETDEV_CAN_IOCTL
|
||||
case SIOCGCANBITRATE:
|
||||
case SIOCGCANBITRATE:
|
||||
|
||||
/* Get bitrate from the CAN controller */
|
||||
/* Get bitrate from the CAN controller */
|
||||
|
||||
{
|
||||
struct can_ioctl_data_s *req =
|
||||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
req->arbi_bitrate = priv->bitrate_value;
|
||||
req->arbi_samplep = mpfs_can_get_sample_point(priv);
|
||||
ret = CAN_OK;
|
||||
}
|
||||
break;
|
||||
{
|
||||
struct can_ioctl_data_s *req =
|
||||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
case SIOCSCANBITRATE:
|
||||
req->arbi_bitrate = priv->bitrate_value;
|
||||
req->arbi_samplep = mpfs_can_get_sample_point(priv);
|
||||
ret = CAN_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
/* Set bitrate of the CAN controller */
|
||||
case SIOCSCANBITRATE:
|
||||
|
||||
{
|
||||
struct can_ioctl_data_s *req =
|
||||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
/* Set bitrate of the CAN controller */
|
||||
|
||||
if (CAN_OK != mpfs_can_set_bitrate(priv, req->arbi_bitrate))
|
||||
{
|
||||
nerr("CAN controller bitrate set failed");
|
||||
ret = -EAGAIN;
|
||||
break;
|
||||
}
|
||||
{
|
||||
struct can_ioctl_data_s *req =
|
||||
(struct can_ioctl_data_s *)((uintptr_t)arg);
|
||||
|
||||
ret = CAN_OK;
|
||||
}
|
||||
break;
|
||||
if (CAN_OK != mpfs_can_set_bitrate(priv, req->arbi_bitrate))
|
||||
{
|
||||
nerr("CAN controller bitrate set failed");
|
||||
ret = -EAGAIN;
|
||||
break;
|
||||
}
|
||||
|
||||
case SIOCACANSTDFILTER:
|
||||
case SIOCACANEXTFILTER:
|
||||
ret = CAN_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
{
|
||||
struct can_ioctl_filter_s *req =
|
||||
(struct can_ioctl_filter_s *)((uintptr_t)arg);
|
||||
case SIOCACANSTDFILTER:
|
||||
case SIOCACANEXTFILTER:
|
||||
|
||||
if (CAN_OK != mpfs_can_add_filter(priv, req->ftype,
|
||||
req->fid1, req->fid2))
|
||||
{
|
||||
nerr("CAN filter add failed");
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
{
|
||||
struct can_ioctl_filter_s *req =
|
||||
(struct can_ioctl_filter_s *)((uintptr_t)arg);
|
||||
|
||||
ret = CAN_OK;
|
||||
}
|
||||
break;
|
||||
if (CAN_OK != mpfs_can_add_filter(priv, req->ftype,
|
||||
req->fid1, req->fid2))
|
||||
{
|
||||
nerr("CAN filter add failed");
|
||||
ret = -EINVAL;
|
||||
break;
|
||||
}
|
||||
|
||||
case SIOCDCANSTDFILTER:
|
||||
case SIOCDCANEXTFILTER:
|
||||
ret = CAN_OK;
|
||||
}
|
||||
break;
|
||||
|
||||
{
|
||||
mpfs_can_reset_filter(priv);
|
||||
ret = CAN_OK;
|
||||
}
|
||||
break;
|
||||
case SIOCDCANSTDFILTER:
|
||||
case SIOCDCANEXTFILTER:
|
||||
|
||||
{
|
||||
mpfs_can_reset_filter(priv);
|
||||
ret = CAN_OK;
|
||||
}
|
||||
break;
|
||||
#endif /* CONFIG_NETDEV_CAN_IOCTL */
|
||||
|
||||
default:
|
||||
ret = -ENOTTY;
|
||||
break;
|
||||
default:
|
||||
ret = -ENOTTY;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -127,28 +127,28 @@ uint32_t can_callback(FAR struct net_driver_s *dev,
|
|||
if (conn)
|
||||
{
|
||||
#ifdef CONFIG_NET_TIMESTAMP
|
||||
/* TIMESTAMP sockopt is activated,
|
||||
* create timestamp and copy to iob
|
||||
*/
|
||||
/* TIMESTAMP sockopt is activated,
|
||||
* create timestamp and copy to iob
|
||||
*/
|
||||
|
||||
if (_SO_GETOPT(conn->sconn.s_options, SO_TIMESTAMP) &&
|
||||
(dev->d_iob != NULL))
|
||||
if (_SO_GETOPT(conn->sconn.s_options, SO_TIMESTAMP) &&
|
||||
(dev->d_iob != NULL))
|
||||
{
|
||||
struct timeval tv;
|
||||
FAR struct timespec *ts = (FAR struct timespec *)&tv;
|
||||
int len;
|
||||
|
||||
clock_systime_timespec(ts);
|
||||
tv.tv_usec = ts->tv_nsec / 1000;
|
||||
|
||||
len = iob_trycopyin(dev->d_iob, (FAR uint8_t *)&tv,
|
||||
sizeof(struct timeval),
|
||||
-CONFIG_NET_LL_GUARDSIZE, false);
|
||||
if (len == sizeof(struct timeval))
|
||||
{
|
||||
struct timeval tv;
|
||||
FAR struct timespec *ts = (FAR struct timespec *)&tv;
|
||||
int len;
|
||||
|
||||
clock_systime_timespec(ts);
|
||||
tv.tv_usec = ts->tv_nsec / 1000;
|
||||
|
||||
len = iob_trycopyin(dev->d_iob, (FAR uint8_t *)&tv,
|
||||
sizeof(struct timeval),
|
||||
-CONFIG_NET_LL_GUARDSIZE, false);
|
||||
if (len == sizeof(struct timeval))
|
||||
{
|
||||
dev->d_len += len;
|
||||
}
|
||||
dev->d_len += len;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
conn_lock(&conn->sconn);
|
||||
|
|
|
|||
|
|
@ -270,6 +270,7 @@ static void ioctl_get_ipv4addr(FAR struct sockaddr *outaddr,
|
|||
in_addr_t inaddr)
|
||||
{
|
||||
FAR struct sockaddr_in *dest = (FAR struct sockaddr_in *)outaddr;
|
||||
|
||||
dest->sin_family = AF_INET;
|
||||
dest->sin_port = 0;
|
||||
dest->sin_addr.s_addr = inaddr;
|
||||
|
|
@ -295,6 +296,7 @@ static void ioctl_get_ipv4broadcast(FAR struct sockaddr *outaddr,
|
|||
in_addr_t inaddr, in_addr_t netmask)
|
||||
{
|
||||
FAR struct sockaddr_in *dest = (FAR struct sockaddr_in *)outaddr;
|
||||
|
||||
dest->sin_family = AF_INET;
|
||||
dest->sin_port = 0;
|
||||
dest->sin_addr.s_addr = net_ipv4addr_broadcast(inaddr, netmask);
|
||||
|
|
@ -319,6 +321,7 @@ static void ioctl_get_ipv6addr(FAR struct sockaddr_storage *outaddr,
|
|||
FAR const net_ipv6addr_t inaddr)
|
||||
{
|
||||
FAR struct sockaddr_in6 *dest = (FAR struct sockaddr_in6 *)outaddr;
|
||||
|
||||
dest->sin6_family = AF_INET6;
|
||||
dest->sin6_port = 0;
|
||||
memcpy(dest->sin6_addr.in6_u.u6_addr8, inaddr, 16);
|
||||
|
|
@ -343,6 +346,7 @@ static void ioctl_set_ipv4addr(FAR in_addr_t *outaddr,
|
|||
FAR const struct sockaddr *inaddr)
|
||||
{
|
||||
FAR const struct sockaddr_in *src = (FAR const struct sockaddr_in *)inaddr;
|
||||
|
||||
*outaddr = src->sin_addr.s_addr;
|
||||
}
|
||||
#endif
|
||||
|
|
@ -366,6 +370,7 @@ static void ioctl_set_ipv6addr(FAR net_ipv6addr_t outaddr,
|
|||
{
|
||||
FAR const struct sockaddr_in6 *src =
|
||||
(FAR const struct sockaddr_in6 *)inaddr;
|
||||
|
||||
memcpy(outaddr, src->sin6_addr.in6_u.u6_addr8, 16);
|
||||
}
|
||||
#endif
|
||||
|
|
@ -854,6 +859,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
case SIOCSIFNAME: /* Set interface name */
|
||||
{
|
||||
FAR struct net_driver_s *tmpdev;
|
||||
|
||||
tmpdev = netdev_findbyindex(req->ifr_ifindex);
|
||||
if (tmpdev != NULL)
|
||||
{
|
||||
|
|
@ -869,6 +875,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
case SIOCGIFNAME: /* Get interface name */
|
||||
{
|
||||
FAR struct net_driver_s *tmpdev;
|
||||
|
||||
tmpdev = netdev_findbyindex(req->ifr_ifindex);
|
||||
if (tmpdev != NULL)
|
||||
{
|
||||
|
|
@ -898,6 +905,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
== (ssize_t)sizeof(struct in6_ifreq))
|
||||
{
|
||||
FAR struct in6_ifreq *ifr6 = (FAR struct in6_ifreq *)req;
|
||||
|
||||
dev = netdev_findbyindex(ifr6->ifr6_ifindex);
|
||||
}
|
||||
|
||||
|
|
@ -954,6 +962,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
case SIOCGLIFADDR: /* Get IP address */
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
|
||||
idx = MIN(idx, CONFIG_NETDEV_MAX_IPv6_ADDR - 1);
|
||||
ioctl_get_ipv6addr(&lreq->lifr_addr, dev->d_ipv6[idx].addr);
|
||||
}
|
||||
|
|
@ -962,6 +971,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
case SIOCSLIFADDR: /* Set IP address */
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
|
||||
idx = MIN(idx, CONFIG_NETDEV_MAX_IPv6_ADDR - 1);
|
||||
|
||||
netdev_ipv6_removemcastmac(dev, dev->d_ipv6[idx].addr);
|
||||
|
|
@ -976,6 +986,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
case SIOCGLIFDSTADDR: /* Get P-to-P address */
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
|
||||
ioctl_get_ipv6addr(&lreq->lifr_dstaddr, dev->d_ipv6draddr);
|
||||
}
|
||||
break;
|
||||
|
|
@ -983,6 +994,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
case SIOCSLIFDSTADDR: /* Set P-to-P address */
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
|
||||
ioctl_set_ipv6addr(dev->d_ipv6draddr, &lreq->lifr_dstaddr);
|
||||
}
|
||||
break;
|
||||
|
|
@ -995,6 +1007,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
case SIOCGLIFNETMASK: /* Get network mask */
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
|
||||
idx = MIN(idx, CONFIG_NETDEV_MAX_IPv6_ADDR - 1);
|
||||
ioctl_get_ipv6addr(&lreq->lifr_addr, dev->d_ipv6[idx].mask);
|
||||
}
|
||||
|
|
@ -1003,6 +1016,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
case SIOCSLIFNETMASK: /* Set network mask */
|
||||
{
|
||||
FAR struct lifreq *lreq = (FAR struct lifreq *)req;
|
||||
|
||||
idx = MIN(idx, CONFIG_NETDEV_MAX_IPv6_ADDR - 1);
|
||||
ioctl_set_ipv6addr(dev->d_ipv6[idx].mask, &lreq->lifr_addr);
|
||||
}
|
||||
|
|
@ -1176,6 +1190,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
if (psock->s_domain == PF_INET6)
|
||||
{
|
||||
FAR struct in6_ifreq *ifr6 = (FAR struct in6_ifreq *)req;
|
||||
|
||||
ret = netdev_ipv6_add(dev, ifr6->ifr6_addr.in6_u.u6_addr16,
|
||||
ifr6->ifr6_prefixlen);
|
||||
if (ret == OK)
|
||||
|
|
@ -1201,6 +1216,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
if (psock->s_domain == PF_INET6)
|
||||
{
|
||||
FAR struct in6_ifreq *ifr6 = (FAR struct in6_ifreq *)req;
|
||||
|
||||
ret = netdev_ipv6_del(dev, ifr6->ifr6_addr.in6_u.u6_addr16,
|
||||
ifr6->ifr6_prefixlen);
|
||||
if (ret == OK)
|
||||
|
|
@ -1219,6 +1235,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
{
|
||||
FAR struct mii_ioctl_notify_s *notify =
|
||||
&req->ifr_ifru.ifru_mii_notify;
|
||||
|
||||
ret = dev->d_ioctl(dev, cmd, (unsigned long)(uintptr_t)notify);
|
||||
}
|
||||
else
|
||||
|
|
@ -1235,6 +1252,7 @@ static int netdev_ifr_ioctl(FAR struct socket *psock, int cmd,
|
|||
{
|
||||
FAR struct mii_ioctl_data_s *mii_data =
|
||||
&req->ifr_ifru.ifru_mii_data;
|
||||
|
||||
ret = dev->d_ioctl(dev, cmd,
|
||||
(unsigned long)(uintptr_t)mii_data);
|
||||
}
|
||||
|
|
@ -1714,7 +1732,7 @@ static int netdev_ioctl(FAR struct socket *psock, int cmd,
|
|||
|
||||
break;
|
||||
|
||||
default:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue