Skip to content

Commit

Permalink
chardriver upperCAN: support to independent set TX/RX FIFO size.
Browse files Browse the repository at this point in the history
support to independent set TX/RX FIFO size.

Signed-off-by: zhaohaiyang1 <[email protected]>
  • Loading branch information
OceanfromXiaomi authored and xiaoxiang781216 committed Oct 1, 2024
1 parent 7044b10 commit 32b2584
Show file tree
Hide file tree
Showing 16 changed files with 101 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,8 @@ MCAN1 Loopback Test

Device Drivers -> CAN Driver support
CONFIG_CAN=y # Enable the upper-half CAN driver
CONFIG_CAN_FIFOSIZE=8
CONFIG_CAN_TXFIFOSIZE=8
CONFIG_CAN_RXFIFOSIZE=8
CONFIG_CAN_NPENDINGRTR=4

System Type -> SAMV7 Peripheral Selections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,8 @@ MCAN1 Loopback Test

Device Drivers -> CAN Driver support
CONFIG_CAN=y # Enable the upper-half CAN driver
CONFIG_CAN_FIFOSIZE=8
CONFIG_CAN_TXFIFOSIZE=8
CONFIG_CAN_RXFIFOSIZE=8
CONFIG_CAN_NPENDINGRTR=4

System Type -> SAMV7 Peripheral Selections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,11 @@ Cloudctrl-specific Configuration Options

CONFIG_CAN - Enables CAN support (one or both of CONFIG_STM32_CAN1 or
CONFIG_STM32_CAN2 must also be defined)
CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
of CAN messages.
Default: 8
CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
of CAN messages.
Default: 8
CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Default: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,11 @@ M3 Wildfire-specific Configuration Options
CONFIG_STM32_CAN2 must also be defined)
CONFIG_CAN_EXTID - Enables support for the 29-bit extended ID. Default
Standard 11-bit IDs.
CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
of CAN messages.
Default: 8
CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
of CAN messages.
Default: 8
CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Default: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ HY-Mini specific Configuration Options
CONFIG_STM32_CAN2 must also be defined)
CONFIG_CAN_EXTID - Enables support for the 29-bit extended ID. Default
Standard 11-bit IDs.
CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
of CAN messages.
Default: 8
CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
of CAN messages.
Default: 8
CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Default: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,11 @@ Shenzhou-specific Configuration Options

CONFIG_CAN - Enables CAN support (one or both of CONFIG_STM32_CAN1 or
CONFIG_STM32_CAN2 must also be defined)
CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
of CAN messages.
Default: 8
CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
of CAN messages.
Default: 8
CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Default: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ STM3210E-EVAL-specific Configuration Options
CONFIG_STM32_CAN2 must also be defined)
CONFIG_CAN_EXTID - Enables support for the 29-bit extended ID. Default
Standard 11-bit IDs.
CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
of CAN messages.
Default: 8
CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
of CAN messages.
Default: 8
CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Default: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@ STM32 Tiny - specific Configuration Options
CONFIG_STM32_CAN2 must also be defined)
CONFIG_CAN_EXTID - Enables support for the 29-bit extended ID. Default
Standard 11-bit IDs.
CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
of CAN messages.
Default: 8
CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
of CAN messages.
Default: 8
CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Default: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,11 @@ STM32F103 Minimum - specific Configuration Options
CONFIG_STM32_CAN2 must also be defined)
CONFIG_CAN_EXTID - Enables support for the 29-bit extended ID. Default
Standard 11-bit IDs.
CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
of CAN messages.
Default: 8
CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
of CAN messages.
Default: 8
CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Default: 4
Expand Down
7 changes: 6 additions & 1 deletion Documentation/platforms/arm/stm32f2/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ CAN
- CONFIG_CAN_EXTID - Enables support for the 29-bit extended ID.
Default Standard 11-bit IDs.

- CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
- CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
of CAN messages.
Default: 8

- CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
of CAN messages.
Default: 8

- CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Expand Down
7 changes: 6 additions & 1 deletion Documentation/platforms/arm/stm32f3/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,12 @@ CAN character device
- CONFIG_CAN_EXTID - Enables support for the 29-bit extended ID. Default
Standard 11-bit IDs.

- CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
- CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
of CAN messages.
Default: 8

- CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
of CAN messages.
Default: 8

- CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Expand Down
7 changes: 6 additions & 1 deletion Documentation/platforms/arm/stm32f4/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,12 @@ CAN
- CONFIG_CAN_EXTID - Enables support for the 29-bit extended ID. Default
Standard 11-bit IDs.

- CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
- CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
of CAN messages.
Default: 8

- CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
of CAN messages.
Default: 8

- CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
Expand Down
8 changes: 7 additions & 1 deletion Documentation/platforms/arm/stm32f7/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,13 @@ CAN

- CONFIG_CAN_EXTID - Enables support for the 29-bit extended ID. Default Standard 11-bit IDs.

- CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages. Default: 8
- CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
of CAN messages.
Default: 8

- CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
of CAN messages.
Default: 8

- CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests. Default: 4

Expand Down
14 changes: 11 additions & 3 deletions drivers/can/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,19 @@ config CAN_FD
---help---
Enables support for the CAN_FD mode.

config CAN_FIFOSIZE
int "CAN driver I/O buffer size"
config CAN_TXFIFOSIZE
int "CAN driver I/O tx buffer size"
default 8
range 1 255
---help---
The size of the circular buffer of CAN messages. Default: 8
The size of the circular tx buffer of CAN messages. Default: 8

config CAN_RXFIFOSIZE
int "CAN driver I/O rx buffer size"
default 8
range 1 255
---help---
The size of the circular rx buffer of CAN messages. Default: 8

config CAN_NPENDINGRTR
int "Number of pending RTRs"
Expand Down
14 changes: 7 additions & 7 deletions drivers/can/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer,

/* Increment the head of the circular message buffer */

if (++fifo->rx_head >= CONFIG_CAN_FIFOSIZE)
if (++fifo->rx_head >= CONFIG_CAN_RXFIFOSIZE)
{
fifo->rx_head = 0;
}
Expand Down Expand Up @@ -549,7 +549,7 @@ static int can_xmit(FAR struct can_dev_s *dev)
*/

tmpndx = dev->cd_xmit.tx_queue;
if (++dev->cd_xmit.tx_queue >= CONFIG_CAN_FIFOSIZE)
if (++dev->cd_xmit.tx_queue >= CONFIG_CAN_TXFIFOSIZE)
{
dev->cd_xmit.tx_queue = 0;
}
Expand Down Expand Up @@ -615,7 +615,7 @@ static ssize_t can_write(FAR struct file *filep, FAR const char *buffer,
*/

nexttail = fifo->tx_tail + 1;
if (nexttail >= CONFIG_CAN_FIFOSIZE)
if (nexttail >= CONFIG_CAN_TXFIFOSIZE)
{
nexttail = 0;
}
Expand Down Expand Up @@ -885,7 +885,7 @@ static int can_ioctl(FAR struct file *filep, int cmd, unsigned long arg)

case FIONWRITE:
{
*(FAR uint8_t *)arg = CONFIG_CAN_FIFOSIZE - 1 -
*(FAR uint8_t *)arg = CONFIG_CAN_TXFIFOSIZE - 1 -
(dev->cd_xmit.tx_tail - dev->cd_xmit.tx_head);
}
break;
Expand Down Expand Up @@ -997,7 +997,7 @@ static int can_poll(FAR struct file *filep, FAR struct pollfd *fds,
*/

ndx = dev->cd_xmit.tx_tail + 1;
if (ndx >= CONFIG_CAN_FIFOSIZE)
if (ndx >= CONFIG_CAN_TXFIFOSIZE)
{
ndx = 0;
}
Expand Down Expand Up @@ -1188,7 +1188,7 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr,
fifo = &reader->fifo;

nexttail = fifo->rx_tail + 1;
if (nexttail >= CONFIG_CAN_FIFOSIZE)
if (nexttail >= CONFIG_CAN_RXFIFOSIZE)
{
nexttail = 0;
}
Expand Down Expand Up @@ -1358,7 +1358,7 @@ int can_txdone(FAR struct can_dev_s *dev)

/* Remove the message at the head of the xmit FIFO */

if (++dev->cd_xmit.tx_head >= CONFIG_CAN_FIFOSIZE)
if (++dev->cd_xmit.tx_head >= CONFIG_CAN_TXFIFOSIZE)
{
dev->cd_xmit.tx_head = 0;
}
Expand Down
27 changes: 19 additions & 8 deletions include/nuttx/can/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@
* CONFIG_CAN_FD - Enable support for CAN FD mode.
* For the upper half driver, this just means handling encoded DLC values
* (for values of DLC > 9).
* CONFIG_CAN_FIFOSIZE - The size of the circular buffer of CAN messages.
* CONFIG_CAN_TXFIFOSIZE - The size of the circular tx buffer
* of CAN messages.
* Default: 8
* CONFIG_CAN_RXFIFOSIZE - The size of the circular rx buffer
* of CAN messages.
* Default: 8
* CONFIG_CAN_NPENDINGRTR - The size of the list of pending RTR requests.
* Default: 4
Expand All @@ -81,11 +85,18 @@
* The configured size is limited to 255 to fit into a uint8_t.
*/

#if !defined(CONFIG_CAN_FIFOSIZE)
# define CONFIG_CAN_FIFOSIZE 8
#elif CONFIG_CAN_FIFOSIZE > 255
# undef CONFIG_CAN_FIFOSIZE
# define CONFIG_CAN_FIFOSIZE 255
#if !defined(CONFIG_CAN_TXFIFOSIZE)
# define CONFIG_CAN_TXFIFOSIZE 8
#elif CONFIG_CAN_TXFIFOSIZE > 255
# undef CONFIG_CAN_TXFIFOSIZE
# define CONFIG_CAN_TXFIFOSIZE 255
#endif

#if !defined(CONFIG_CAN_RXFIFOSIZE)
# define CONFIG_CAN_RXFIFOSIZE 8
#elif CONFIG_CAN_RXFIFOSIZE > 255
# undef CONFIG_CAN_RXFIFOSIZE
# define CONFIG_CAN_RXFIFOSIZE 255
#endif

#if !defined(CONFIG_CAN_NPENDINGRTR)
Expand Down Expand Up @@ -554,7 +565,7 @@ struct can_rxfifo_s
uint8_t rx_head; /* Index to the head [IN] in the circular buffer */
uint8_t rx_tail; /* Index to the tail [OUT] in the circular buffer */
/* Circular buffer of CAN messages */
struct can_msg_s rx_buffer[CONFIG_CAN_FIFOSIZE];
struct can_msg_s rx_buffer[CONFIG_CAN_RXFIFOSIZE];
};

struct can_txfifo_s
Expand All @@ -564,7 +575,7 @@ struct can_txfifo_s
uint8_t tx_queue; /* Index to next message to send */
uint8_t tx_tail; /* Index to the tail [OUT] in the circular buffer */
/* Circular buffer of CAN messages */
struct can_msg_s tx_buffer[CONFIG_CAN_FIFOSIZE];
struct can_msg_s tx_buffer[CONFIG_CAN_TXFIFOSIZE];
};

/* The following structure define the logic to handle
Expand Down

0 comments on commit 32b2584

Please sign in to comment.