From 534114395ee9164db241b8ccfb5f731f675559f1 Mon Sep 17 00:00:00 2001 From: zhaohaiyang1 Date: Mon, 17 Jun 2024 23:03:59 +0800 Subject: [PATCH] char driver CAN: add tx_confirm function in upperCAN driver. add tx_confirm function in upperCAN driver1 Signed-off-by: zhaohaiyang1 --- arch/arm/src/at32/at32_can.c | 4 ++-- arch/arm/src/lpc17xx_40xx/lpc17_40_can.c | 2 +- arch/arm/src/sama5/sam_can.c | 2 +- arch/arm/src/sama5/sam_mcan.c | 14 +++++++------- arch/arm/src/samv7/sam_mcan.c | 6 +++--- arch/arm/src/stm32/stm32_can.c | 4 ++-- arch/arm/src/stm32/stm32_fdcan.c | 4 ++-- arch/arm/src/stm32f7/stm32_can.c | 2 +- arch/arm/src/stm32l4/stm32l4_can.c | 2 +- drivers/can/Kconfig | 11 +++++++++++ drivers/can/can.c | 13 ++++++++++--- drivers/can/mcp2515.c | 4 ++-- include/nuttx/can/can.h | 4 ++-- 13 files changed, 45 insertions(+), 27 deletions(-) diff --git a/arch/arm/src/at32/at32_can.c b/arch/arm/src/at32/at32_can.c index 3470111a7d938..3bb5e0a4c30c5 100644 --- a/arch/arm/src/at32/at32_can.c +++ b/arch/arm/src/at32/at32_can.c @@ -1586,7 +1586,7 @@ static int at32can_rxinterrupt(struct can_dev_s *dev, int rxmb) #ifdef CONFIG_CAN_ERRORS hdr.ch_error = 0; /* Error reporting not supported */ #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* Extract the RTR bit */ @@ -1895,7 +1895,7 @@ static int at32can_sceinterrupt(int irq, void *context, void *arg) #ifdef CONFIG_CAN_EXTID hdr.ch_extid = 0; #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* And provide the error report to the upper half logic */ diff --git a/arch/arm/src/lpc17xx_40xx/lpc17_40_can.c b/arch/arm/src/lpc17xx_40xx/lpc17_40_can.c index 66035bb04216e..f1611e69d9059 100644 --- a/arch/arm/src/lpc17xx_40xx/lpc17_40_can.c +++ b/arch/arm/src/lpc17xx_40xx/lpc17_40_can.c @@ -1356,7 +1356,7 @@ static void can_interrupt(struct lpc17_40_can_s *dev) #ifdef CONFIG_CAN_EXTID hdr.ch_extid = ((rfs & CAN_RFS_FF) != 0); #else - hdr.ch_unused = 0; + hdr.ch_tcf = 0; if ((rfs & CAN_RFS_FF) != 0) { diff --git a/arch/arm/src/sama5/sam_can.c b/arch/arm/src/sama5/sam_can.c index 0ba5ba53c9d25..d114fe809d9ae 100644 --- a/arch/arm/src/sama5/sam_can.c +++ b/arch/arm/src/sama5/sam_can.c @@ -1318,7 +1318,7 @@ static inline void can_rxinterrupt(struct can_dev_s *dev, int mbndx, #ifdef CONFIG_CAN_ERRORS hdr.ch_error = 0; /* Error reporting not supported */ #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* And provide the CAN message to the upper half logic */ diff --git a/arch/arm/src/sama5/sam_mcan.c b/arch/arm/src/sama5/sam_mcan.c index 6a65dce1f8d3a..9ebdcd780e439 100644 --- a/arch/arm/src/sama5/sam_mcan.c +++ b/arch/arm/src/sama5/sam_mcan.c @@ -3459,14 +3459,14 @@ static void mcan_error(struct can_dev_s *dev, uint32_t status) { /* Format the CAN header for the error report. */ - hdr.ch_id = errbits; - hdr.ch_dlc = CAN_ERROR_DLC; - hdr.ch_rtr = 0; - hdr.ch_error = 1; + hdr.ch_id = errbits; + hdr.ch_dlc = CAN_ERROR_DLC; + hdr.ch_rtr = 0; + hdr.ch_error = 1; #ifdef CONFIG_CAN_EXTID - hdr.ch_extid = 0; + hdr.ch_extid = 0; #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* And provide the error report to the upper half logic */ @@ -3628,7 +3628,7 @@ static void mcan_receive(struct can_dev_s *dev, uint32_t *rxbuffer, #ifdef CONFIG_CAN_ERRORS hdr.ch_error = 0; #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; if ((regval & BUFFER_R0_RTR) != 0) { diff --git a/arch/arm/src/samv7/sam_mcan.c b/arch/arm/src/samv7/sam_mcan.c index 3a5d8062ddbe1..92eb30763b4e4 100644 --- a/arch/arm/src/samv7/sam_mcan.c +++ b/arch/arm/src/samv7/sam_mcan.c @@ -3483,7 +3483,7 @@ static void mcan_error(struct can_dev_s *dev, uint32_t status) #ifdef CONFIG_CAN_EXTID hdr.ch_extid = 0; #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* And provide the error report to the upper half logic */ @@ -3535,9 +3535,9 @@ static void mcan_receive(struct can_dev_s *dev, uint32_t *rxbuffer, reginfo("R0: %08" PRIx32 "\n", regval); #ifdef CONFIG_CAN_ERRORS - hdr.ch_error = 0; + hdr.ch_error = 0; #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; if ((regval & BUFFER_R0_RTR) != 0) { diff --git a/arch/arm/src/stm32/stm32_can.c b/arch/arm/src/stm32/stm32_can.c index 9e9d8e08fb365..89480b88c2dc7 100644 --- a/arch/arm/src/stm32/stm32_can.c +++ b/arch/arm/src/stm32/stm32_can.c @@ -1581,7 +1581,7 @@ static int stm32can_rxinterrupt(struct can_dev_s *dev, int rxmb) #ifdef CONFIG_CAN_ERRORS hdr.ch_error = 0; /* Error reporting not supported */ #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* Extract the RTR bit */ @@ -1890,7 +1890,7 @@ static int stm32can_sceinterrupt(int irq, void *context, void *arg) #ifdef CONFIG_CAN_EXTID hdr.ch_extid = 0; #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* And provide the error report to the upper half logic */ diff --git a/arch/arm/src/stm32/stm32_fdcan.c b/arch/arm/src/stm32/stm32_fdcan.c index 8d573c976a78d..ef51fe710898e 100644 --- a/arch/arm/src/stm32/stm32_fdcan.c +++ b/arch/arm/src/stm32/stm32_fdcan.c @@ -2801,7 +2801,7 @@ static void fdcan_error(struct can_dev_s *dev, uint32_t status) #ifdef CONFIG_CAN_EXTID hdr.ch_extid = 0; #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* And provide the error report to the upper half logic */ @@ -2846,7 +2846,7 @@ static void fdcan_receive(struct can_dev_s *dev, #ifdef CONFIG_CAN_ERRORS hdr.ch_error = 0; #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* Extract the RTR bit */ diff --git a/arch/arm/src/stm32f7/stm32_can.c b/arch/arm/src/stm32f7/stm32_can.c index f65755efd42bf..4dad6cf795707 100644 --- a/arch/arm/src/stm32f7/stm32_can.c +++ b/arch/arm/src/stm32f7/stm32_can.c @@ -1518,7 +1518,7 @@ static int stm32can_rxinterrupt(struct can_dev_s *dev, int rxmb) #ifdef CONFIG_CAN_ERRORS hdr.ch_error = 0; /* Error reporting not supported */ #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* Extract the RTR bit */ diff --git a/arch/arm/src/stm32l4/stm32l4_can.c b/arch/arm/src/stm32l4/stm32l4_can.c index 48796dbf4c9e0..c9939ae91fad0 100644 --- a/arch/arm/src/stm32l4/stm32l4_can.c +++ b/arch/arm/src/stm32l4/stm32l4_can.c @@ -1445,7 +1445,7 @@ static int stm32l4can_rxinterrupt(int irq, void *context, int rxmb) #ifdef CONFIG_CAN_ERRORS hdr.ch_error = 0; /* Error reporting not supported */ #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* Extract the RTR bit */ diff --git a/drivers/can/Kconfig b/drivers/can/Kconfig index 2379a9c81a090..ff303d8713941 100644 --- a/drivers/can/Kconfig +++ b/drivers/can/Kconfig @@ -59,6 +59,17 @@ config CAN_NPENDINGRTR ---help--- The size of the list of pending RTR requests. Default: 4 +config CAN_TXCONFIRM + bool "can txconfirm ability" + default n + ---help--- + this section enables the can txconfirm ability. + + Enabling this feature adds support for the can txconfirm + ability, the ability is used from CAN interrupt handler + when the transfer is complete, the ability will notify all + readers that the canid has been transferred. + config CAN_TXREADY bool "can_txready interface" default n diff --git a/drivers/can/can.c b/drivers/can/can.c index fd74f571c3add..111ee38cca4ad 100644 --- a/drivers/can/can.c +++ b/drivers/can/can.c @@ -408,7 +408,7 @@ static ssize_t can_read(FAR struct file *filep, FAR char *buffer, #ifdef CONFIG_CAN_EXTID msg->cm_hdr.ch_extid = 0; #endif - msg->cm_hdr.ch_unused = 0; + msg->cm_hdr.ch_tcf = 0; memset(&(msg->cm_data), 0, CAN_ERROR_DLC); msg->cm_data[5] = fifo->rx_error; @@ -1219,7 +1219,11 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, memcpy(&waitmsg->cm_hdr, hdr, sizeof(struct can_hdr_s)); nbytes = can_dlc2bytes(hdr->ch_dlc); - memcpy(waitmsg->cm_data, data, nbytes); + if (nbytes) + { + memcpy(waitmsg->cm_data, data, nbytes); + } + dev->cd_npendrtr--; /* Restart the waiting thread and mark the entry unused */ @@ -1260,7 +1264,10 @@ int can_receive(FAR struct can_dev_s *dev, FAR struct can_hdr_s *hdr, sizeof(struct can_hdr_s)); nbytes = can_dlc2bytes(hdr->ch_dlc); - memcpy(fifo->rx_buffer[fifo->rx_tail].cm_data, data, nbytes); + if (nbytes) + { + memcpy(fifo->rx_buffer[fifo->rx_tail].cm_data, data, nbytes); + } /* Increment the tail of the circular buffer */ diff --git a/drivers/can/mcp2515.c b/drivers/can/mcp2515.c index f413f2da58892..af636d162d8d3 100644 --- a/drivers/can/mcp2515.c +++ b/drivers/can/mcp2515.c @@ -2031,7 +2031,7 @@ static void mcp2515_error(FAR struct can_dev_s *dev, uint8_t status, #ifdef CONFIG_CAN_EXTID hdr.ch_extid = 0; #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* And provide the error report to the upper half logic */ @@ -2141,7 +2141,7 @@ static void mcp2515_receive(FAR struct can_dev_s *dev, uint8_t offset) #ifdef CONFIG_CAN_ERRORS hdr.ch_error = 0; /* Error reporting not supported */ #endif - hdr.ch_unused = 0; + hdr.ch_tcf = 0; /* Extract the RTR bit */ diff --git a/include/nuttx/can/can.h b/include/nuttx/can/can.h index cf3f8ec1f5b8f..afc6522189048 100644 --- a/include/nuttx/can/can.h +++ b/include/nuttx/can/can.h @@ -589,7 +589,7 @@ begin_packed_struct struct can_hdr_s uint8_t ch_brs : 1; /* Bit Rate Switch */ uint8_t ch_esi : 1; /* Error State Indicator */ #endif - uint8_t ch_unused : 1; /* FIXME: This field is useless, kept for backward compatibility */ + uint8_t ch_tcf : 1; /* Tx confirmation flag */ } end_packed_struct; #else @@ -606,7 +606,7 @@ begin_packed_struct struct can_hdr_s uint8_t ch_brs : 1; /* Bit Rate Switch */ uint8_t ch_esi : 1; /* Error State Indicator */ #endif - uint8_t ch_unused : 1; /* FIXME: This field is useless, kept for backward compatibility */ + uint8_t ch_tcf : 1; /* Tx confirmation flag */ } end_packed_struct; #endif