Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport all CAN-related changes from upstream NuttX #186

Draft
wants to merge 43 commits into
base: px4_firmware_nuttx-10.1.0+
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
eaab3a2
[BACKPORT] arch/stm32h7: Add FDCAN SocketCAN driver
JacobCrabill Apr 15, 2022
c29b742
[BACKPORT] boards/stm32h7: Add socketcan config to nucleo-h743zi2
JacobCrabill Apr 15, 2022
b4b9542
[BACKPORT] net/netdev: Add CONFIG_NETDEV_CAN_FILTER_IOCTL
JacobCrabill Apr 15, 2022
101663f
[BACKPORT] net/can: Fix CONFIG errors in can_recvmsg
JacobCrabill Apr 15, 2022
6d7fea1
[BACKPORT] stm32h7: Add FDCAN3_BASE to memorymap.h
JacobCrabill Apr 11, 2022
7406377
[BACKPORT] net: Fix typos, update comments in Kconfigs
JacobCrabill Mar 30, 2022
c7d4b23
nucleo-h743zi2: Fix socketcan backport (CONFIG renames)
JacobCrabill May 24, 2022
de18616
[BACKPORT] include: can: move error.h to apps/canutils
jerpelea Aug 16, 2021
c4ceffb
[BACKPORT] arch/arm/src/imxrt/imxrt_flexcan.c: use SW control to chec…
michallenc Aug 29, 2021
9e0c61b
[BACKPORT] boards/arm/imxrt/teensy-4.x: add option to have CAN3 as can0
michallenc Aug 29, 2021
6cd67d6
[BACKPORT] Fixed imxrt flexcan driver compilation error due to incorr…
pbrier Sep 21, 2021
d3f889f
[BACKPORT] net/can,icmp,icmpv6,tcp,tcp_timer,udp: device should poll …
a-lunev Oct 2, 2021
323cc48
[BACKPORT] can: WIP: Cleanup usage of soft fifo semaphore
MTres19 Jan 2, 2021
42f912f
[BACKPORT] include/nuttx/can.h: include nuttx/config.h
raiden00pl Dec 30, 2021
334e7ca
[BACKPORT] net/devif/devif_cansend.c: fix assertion for max data len
raiden00pl Jan 3, 2022
248efed
[BACKPORT] include/nuttx/can/can.h: fix typo
raiden00pl Jan 5, 2022
6ef0905
[BACKPORT] SocketCAN: add CAN error definitions
raiden00pl Jan 5, 2022
3dea2bd
[BACKPORT] stm32: add CAN error support
raiden00pl Jan 5, 2022
c0b5f3e
[BACKPORT] stm32: add SocketCAN support, based on stm32_can.c
raiden00pl Jan 5, 2022
5950e63
[BACKPORT] boards/stm32: register CAN character device if configured
raiden00pl Jan 5, 2022
5e41aff
[BACKPORT] boards/nucleo-f302r8: add CAN and SocketCAN examples
raiden00pl Jan 15, 2022
3086179
[BACKPORT] boards/nucleo-f446re: add SocketCAN example
raiden00pl Jan 15, 2022
3a8a220
[BACKPORT] stm32: add FDCAN support
raiden00pl Jan 11, 2022
a406270
[BACKPORT] arch/stm32: fdcan cosmetics
raiden00pl Jan 15, 2022
f1b5c76
[BACKPORT] boards/b-g431b-esc1: add CAN example
raiden00pl Jan 15, 2022
39f09f1
[BACKPORT] boards/nucleo-g431rb: add CAN example
raiden00pl Jan 15, 2022
de03f43
[BACKPORT] include/nuttx/can.h: make SocketCAN error definitions alwa…
raiden00pl Jan 22, 2022
e263e0e
[BACKPORT] include/nuttx/can.h: rename CAN_ERR_CTRL to CAN_ERR_CRTL f…
raiden00pl Jan 22, 2022
fb88aa8
[BACKPORT] arch/stm32: add FDCAN SocketCAN support
raiden00pl Jan 22, 2022
0889493
[BACKPORT] boards/arm/stm32g4: normalize CAN configs
raiden00pl Feb 5, 2022
57b627f
[BACKPORT] net/can: add an option to control CAN EXTID support
raiden00pl Feb 5, 2022
c625824
[BACKPORT] boards/b-g431b-esc1: add SocketCAN example
raiden00pl Jan 22, 2022
1aa879c
[BACKPORT] boards/nucleo-g431rb: add SocketCAN example
raiden00pl Jan 22, 2022
0e12b3c
[BACKPORT] net/can: remove psock reference from can connect
anchao Feb 11, 2022
1bf174d
[BACKPORT] net/can/can_setsockopt.c: fix assertion, value can be NULL
raiden00pl Feb 12, 2022
e21e4f9
[BACKPORT] stm32/fdcan: use array indexes when accessing RX/TX FIFO
raiden00pl Feb 12, 2022
79a623a
[BACKPORT] stm32/fdcan: add CAN FD frames support
raiden00pl Feb 12, 2022
a0c05c2
[BACKPORT] arch/arm/src/stm32f7/stm32_can.c: fix CAN3 receiving
lukegluke Mar 3, 2022
e596450
[BACKPORT] drivers/can: optimize can driver reader side
pkarashchenko Mar 11, 2022
74f1170
Revert "[BACKPORT] net/can: remove psock reference from can connect"
JacobCrabill May 25, 2022
98a3962
stm32: Add definition of 'arm_netinitialize()' for SocketCAN
JacobCrabill Jul 28, 2022
67ad6ab
stm32: Fix unused variable in can_netdev_ioctl
JacobCrabill Jul 28, 2022
601722d
SocketCAN: add non-blocking write
jarivanewijk Jul 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 17 additions & 44 deletions arch/arm/src/imxrt/imxrt_flexcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,9 +470,6 @@ static void imxrt_setfreeze(uint32_t base, uint32_t freeze);
static uint32_t imxrt_waitmcr_change(uint32_t base,
uint32_t mask,
uint32_t target_state);
static uint32_t imxrt_waitesr2_change(uint32_t base,
uint32_t mask,
uint32_t target_state);
static struct mb_s *flexcan_get_mb(FAR struct imxrt_driver_s *priv,
uint32_t mbi);

Expand Down Expand Up @@ -531,10 +528,10 @@ static void imxrt_reset(struct imxrt_driver_s *priv);

static bool imxrt_txringfull(FAR struct imxrt_driver_s *priv)
{
uint32_t mbi = RXMBCOUNT;
uint32_t mbi = RXMBCOUNT + 1;
struct mb_s *mb;

while (mbi < TXMBCOUNT)
while (mbi < TOTALMBCOUNT)
{
mb = flexcan_get_mb(priv, mbi);
if (mb->cs.code != CAN_TXMB_DATAORREMOTE)
Expand Down Expand Up @@ -583,18 +580,13 @@ static int imxrt_transmit(FAR struct imxrt_driver_s *priv)
int32_t timeout;
#endif

if ((getreg32(priv->base + IMXRT_CAN_ESR2_OFFSET) &
(CAN_ESR2_IMB | CAN_ESR2_VPS)) ==
(CAN_ESR2_IMB | CAN_ESR2_VPS))
{
mbi = ((getreg32(priv->base + IMXRT_CAN_ESR2_OFFSET) &
CAN_ESR2_LPTM_MASK) >> CAN_ESR2_LPTM_SHIFT);
}

mbi = RXMBCOUNT + 1;
mb_bit = 1 << mbi;

while (mbi < TOTALMBCOUNT)
{
/* Check whether message buffer is not currently transmitting */

struct mb_s *mb = flexcan_get_mb(priv, mbi);
if (mb->cs.code != CAN_TXMB_DATAORREMOTE)
{
Expand Down Expand Up @@ -771,11 +763,14 @@ static int imxrt_txpoll(struct net_driver_s *dev)
{
FAR struct imxrt_driver_s *priv =
(FAR struct imxrt_driver_s *)dev->d_private;
irqstate_t flags;

/* If the polling resulted in data that should be sent out on the network,
* the field d_len is set to a value > 0.
*/

flags = spin_lock_irqsave(NULL);

if (priv->dev.d_len > 0)
{
if (!devif_loopback(&priv->dev))
Expand All @@ -790,15 +785,16 @@ static int imxrt_txpoll(struct net_driver_s *dev)
* not, return a non-zero value to terminate the poll.
*/

if (!((getreg32(priv->base + IMXRT_CAN_ESR2_OFFSET) &
(CAN_ESR2_IMB | CAN_ESR2_VPS)) ==
(CAN_ESR2_IMB | CAN_ESR2_VPS)) || (imxrt_txringfull(priv)))
{
return -EBUSY;
}
if (imxrt_txringfull(priv))
{
spin_unlock_irqrestore(NULL, flags);
return -EBUSY;
}
}
}

spin_unlock_irqrestore(NULL, flags);

/* If zero is returned, the polling will continue until all connections
* have been examined.
*/
Expand Down Expand Up @@ -1268,26 +1264,6 @@ static uint32_t imxrt_waitfreezeack_change(uint32_t base,
return imxrt_waitmcr_change(base, CAN_MCR_FRZACK, target_state);
}

static uint32_t imxrt_waitesr2_change(uint32_t base, uint32_t mask,
uint32_t target_state)
{
const uint32_t timeout = 1000;
uint32_t wait_ack;

for (wait_ack = 0; wait_ack < timeout; wait_ack++)
{
uint32_t state = (getreg32(base + IMXRT_CAN_ESR2_OFFSET) & mask);
if (state == target_state)
{
return true;
}

up_udelay(10);
}

return false;
}

static struct mb_s *flexcan_get_mb(FAR struct imxrt_driver_s *priv,
uint32_t mbi)
{
Expand Down Expand Up @@ -1401,9 +1377,7 @@ static void imxrt_txavail_work(FAR void *arg)
* packet.
*/

if (imxrt_waitesr2_change(priv->base,
(CAN_ESR2_IMB | CAN_ESR2_VPS),
(CAN_ESR2_IMB | CAN_ESR2_VPS)))
if (!imxrt_txringfull(priv))
{
/* No, there is space for another transfer. Poll the network for
* new XMIT data.
Expand Down Expand Up @@ -1479,7 +1453,7 @@ static int imxrt_ioctl(struct net_driver_s *dev, int cmd,
{
FAR struct imxrt_driver_s *priv =
(FAR struct imxrt_driver_s *)dev->d_private;

struct flexcan_timeseg data_timing;
int ret;

switch (cmd)
Expand Down Expand Up @@ -1525,7 +1499,6 @@ static int imxrt_ioctl(struct net_driver_s *dev, int cmd,

if (priv->canfd_capable)
{
struct flexcan_timeseg data_timing;
data_timing.bitrate = req->data_bitrate * 1000;
data_timing.samplep = req->data_samplep;

Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/lpc43xx/lpc43_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ static int can_bittiming(struct up_dev_s *priv);
static const struct can_ops_s g_canops =
{
.co_reset = can_reset,
.co_setup = can_setup,
.co_setup = can_setup,
.co_shutdown = can_shutdown,
.co_rxint = can_rxint,
.co_txint = can_txint,
Expand Down
Loading