nuttx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gn...@apache.org
Subject [incubator-nuttx] 14/31: SocketCAN recfrom added non-blocking behavior support FlexCAN support sending extended CAN id
Date Wed, 08 Apr 2020 14:21:44 GMT
This is an automated email from the ASF dual-hosted git repository.

gnutt pushed a commit to branch SocketCAN
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit c9ca494463964780944a88b7770e5f8c26547022
Author: Peter van der Perk <peter.vanderperk@nxp.com>
AuthorDate: Fri Mar 6 15:20:15 2020 +0100

    SocketCAN recfrom added non-blocking behavior support
    FlexCAN support sending extended CAN id
---
 arch/arm/src/s32k1xx/s32k1xx_flexcan.c |  5 +++--
 net/can/can_recvfrom.c                 | 25 ++++++++++++++++++++++---
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/arch/arm/src/s32k1xx/s32k1xx_flexcan.c b/arch/arm/src/s32k1xx/s32k1xx_flexcan.c
index f394a20..2e73dc9 100644
--- a/arch/arm/src/s32k1xx/s32k1xx_flexcan.c
+++ b/arch/arm/src/s32k1xx/s32k1xx_flexcan.c
@@ -113,6 +113,7 @@
 #define CAN_FIFO_NE                 (1 << 5)
 #define CAN_FIFO_OV                 (1 << 6)
 #define CAN_FIFO_WARN               (1 << 7)
+#define CAN_EFF_FLAG                0x80000000 /* EFF/SFF is set in the MSB */
 
 #define POOL_SIZE                   1
 
@@ -463,7 +464,7 @@ static int s32k1xx_transmit(FAR struct s32k1xx_driver_s *priv)
     {
 	  struct can_frame *frame = (struct can_frame *)priv->dev.d_buf;
 
-	  if (0) /* FIXME detect Std or Ext id */
+	  if (frame->can_id & CAN_EFF_FLAG)
 	    {
 	      cs.ide = 1;
 	      mb->id.ext = frame->can_id & MASKEXTID;
@@ -489,7 +490,7 @@ static int s32k1xx_transmit(FAR struct s32k1xx_driver_s *priv)
 
   	  cs.edl = 1; /* CAN FD Frame */
 
-  	  if (0) /* FIXME detect Std or Ext id */
+  	  if (frame->can_id & CAN_EFF_FLAG)
   	    {
   	      cs.ide = 1;
   	      mb->id.ext = frame->can_id & MASKEXTID;
diff --git a/net/can/can_recvfrom.c b/net/can/can_recvfrom.c
index f83d07c..c23af93 100644
--- a/net/can/can_recvfrom.c
+++ b/net/can/can_recvfrom.c
@@ -231,6 +231,8 @@ static inline int can_readahead(struct can_recvfrom_s *pstate)
   /* Check there is any CAN data already buffered in a read-ahead
    * buffer.
    */
+  
+  pstate->pr_recvlen = -1;
 
   if ((iob = iob_peek_queue(&conn->readahead)) != NULL &&
       pstate->pr_buflen > 0)
@@ -463,10 +465,27 @@ ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf,
 
   ret = can_readahead(&state);
   if (ret > 0)
+    {      
+      goto errout_with_state;
+    }
+    
+  ret = state.pr_recvlen;
+
+  /* Handle non-blocking CAN sockets */
+
+  if (_SS_ISNONBLOCK(psock->s_flags) || (flags & MSG_DONTWAIT) != 0)
     {
-      net_unlock();
-      nxsem_destroy(&state.pr_sem);
-      return ret;
+      /* Return the number of bytes read from the read-ahead buffer if
+       * something was received (already in 'ret'); EAGAIN if not.
+       */
+
+      if (ret < 0)
+        {
+          /* Nothing was received */
+
+          ret = -EAGAIN;          
+          goto errout_with_state;
+        }
     }
 
   /* Get the device driver that will service this transfer */


Mime
View raw message