You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/06/02 14:09:26 UTC
[incubator-nuttx] 08/31: PR350 Coding Standard Corrections
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 a84840881a26d431d43b004765649c948b8adfc0
Author: Gregory Nutt <gn...@nuttx.org>
AuthorDate: Fri Feb 21 11:17:10 2020 -0600
PR350 Coding Standard Corrections
Run all .c and .h files in PR350 through tools/nxstyle and correct all (relevant) errors reported by the tool. Somes files like arch/arm/src/s32k1xx/s32k1xx_flexcan.c did not following the coding standard and received substantial modification.
Nothing may enter the NuttX repositories that does not conform to the coding standard! See https://cwiki.apache.org/confluence/display/NUTTX/Coding+Standard
---
arch/arm/src/s32k1xx/s32k1xx_flexcan.c | 1027 ++++++++++++++++----------------
include/netpacket/can.h | 10 +-
include/nuttx/can.h | 150 ++---
include/nuttx/mm/iob.h | 1 +
include/sys/socket.h | 8 +-
net/can/can.h | 14 +-
net/can/can_callback.c | 80 +--
net/can/can_getsockopt.c | 73 +--
net/can/can_input.c | 50 +-
net/can/can_poll.c | 47 +-
net/can/can_recvfrom.c | 88 ++-
net/can/can_setsockopt.c | 70 +--
net/can/can_sockif.c | 135 +++--
net/socket/getsockopt.c | 2 +-
14 files changed, 829 insertions(+), 926 deletions(-)
diff --git a/arch/arm/src/s32k1xx/s32k1xx_flexcan.c b/arch/arm/src/s32k1xx/s32k1xx_flexcan.c
index 9c7a7d7..50a5c18 100644
--- a/arch/arm/src/s32k1xx/s32k1xx_flexcan.c
+++ b/arch/arm/src/s32k1xx/s32k1xx_flexcan.c
@@ -1,35 +1,20 @@
/****************************************************************************
* arch/arm/src/s32k1xx/s32k1xx_flexcan.c
*
- * Copyright (C) 2019 Gregory Nutt. All rights reserved.
- * Authors: Gregory Nutt <gn...@nuttx.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
*
****************************************************************************/
@@ -102,7 +87,8 @@
/* CONFIG_S32K1XX_FLEXCAN_NETHIFS determines the number of physical interfaces
* that will be supported.
*/
-/*
+
+#if 0
#if CONFIG_S32K1XX_FLEXCAN_NETHIFS != 1
# error "CONFIG_S32K1XX_FLEXCAN_NETHIFS must be one for now"
#endif
@@ -113,20 +99,22 @@
#if CONFIG_S32K1XX_FLEXCAN_NRXBUFFERS < 1
# error "Need at least one RX buffer"
-#endif*/
+#endif
+#endif
+
+#define MASKSTDID 0x000007ff
+#define MASKEXTID 0x1fffffff
+#define FLAGEFF (1 << 31) /* Extended frame format */
+#define FLAGRTR (1 << 30) /* Remote transmission request */
-#define MaskStdID 0x000007FF
-#define MaskExtID 0x1FFFFFFF
-#define FlagEFF (1 << 31) /* Extended frame format */
-#define FlagRTR (1 << 30) /* Remote transmission request */
+/* Fixme nice variables/constants */
-//Fixme nice variables/constants
-#define RxMBCount 6
-#define FilterCount 0
-#define RxandFilterMBCount (RxMBCount + FilterCount)
-#define TxMBCount 12 //???????????? why 12 idk it works
-#define TotalMBcount RxandFilterMBCount + TxMBCount
-#define TXMBMask (((1 << TxMBCount)-1) << RxandFilterMBCount)
+#define RXMBCOUNT 6
+#define FILTERCOUNT 0
+#define RXANDFILTERMBCOUNT (RXMBCOUNT + FILTERCOUNT)
+#define TXMBCOUNT 12 //???????????? why 12 idk it works
+#define TOTALMBCOUNT RXANDFILTERMBCOUNT + TXMBCOUNT
+#define TXMBMASK (((1 << TXMBCOUNT)-1) << RXANDFILTERMBCOUNT)
#define CAN_FIFO_NE (1 << 5)
#define CAN_FIFO_OV (1 << 6)
@@ -135,9 +123,6 @@
static int peak_tx_mailbox_index_ = 0;
-
-
-
/* Normally you would clean the cache after writing new values to the DMA
* memory so assure that the dirty cache lines are flushed to memory
* before the DMA occurs. And you would invalid the cache after a data is
@@ -208,82 +193,81 @@ static int peak_tx_mailbox_index_ = 0;
* Private Types
****************************************************************************/
-
-union TXcsType
+union txcs_e
{
- volatile uint32_t w;
- struct
- {
- volatile uint32_t time_stamp : 16;
- volatile uint32_t dlc : 4;
- volatile uint32_t rtr : 1;
- volatile uint32_t ide : 1;
- volatile uint32_t srr : 1;
- volatile uint32_t res : 1;
- volatile uint32_t code : 4;
- volatile uint32_t res2 : 4;
- };
+ volatile uint32_t w;
+ struct
+ {
+ volatile uint32_t time_stamp : 16;
+ volatile uint32_t dlc : 4;
+ volatile uint32_t rtr : 1;
+ volatile uint32_t ide : 1;
+ volatile uint32_t srr : 1;
+ volatile uint32_t res : 1;
+ volatile uint32_t code : 4;
+ volatile uint32_t res2 : 4;
+ };
};
-union RXcsType
+union rxcs_e
{
- volatile uint32_t cs;
- struct
- {
- volatile uint32_t time_stamp : 16;
- volatile uint32_t dlc : 4;
- volatile uint32_t rtr : 1;
- volatile uint32_t ide : 1;
- volatile uint32_t srr : 1;
- volatile uint32_t res : 9;
- };
+ volatile uint32_t cs;
+ struct
+ {
+ volatile uint32_t time_stamp : 16;
+ volatile uint32_t dlc : 4;
+ volatile uint32_t rtr : 1;
+ volatile uint32_t ide : 1;
+ volatile uint32_t srr : 1;
+ volatile uint32_t res : 9;
+ };
};
-union IDType
+union id_e
{
- volatile uint32_t w;
- struct
- {
- volatile uint32_t ext : 29;
- volatile uint32_t resex : 3;
- };
- struct
- {
- volatile uint32_t res : 18;
- volatile uint32_t std : 11;
- volatile uint32_t resstd : 3;
- };
+ volatile uint32_t w;
+ struct
+ {
+ volatile uint32_t ext : 29;
+ volatile uint32_t resex : 3;
+ };
+ struct
+ {
+ volatile uint32_t res : 18;
+ volatile uint32_t std : 11;
+ volatile uint32_t resstd : 3;
+ };
};
-union DataType
+union data_e
{
- volatile uint32_t l;
- volatile uint32_t h;
- struct
- {
- volatile uint32_t b3 : 8;
- volatile uint32_t b2 : 8;
- volatile uint32_t b1 : 8;
- volatile uint32_t b0 : 8;
- volatile uint32_t b7 : 8;
- volatile uint32_t b6 : 8;
- volatile uint32_t b5 : 8;
- volatile uint32_t b4 : 8;
- };
+ volatile uint32_t l;
+ volatile uint32_t h;
+ struct
+ {
+ volatile uint32_t b3 : 8;
+ volatile uint32_t b2 : 8;
+ volatile uint32_t b1 : 8;
+ volatile uint32_t b0 : 8;
+ volatile uint32_t b7 : 8;
+ volatile uint32_t b6 : 8;
+ volatile uint32_t b5 : 8;
+ volatile uint32_t b4 : 8;
+ };
};
-struct MbTx
+struct mbtx_s
{
- union TXcsType CS;
- union IDType ID;
- union DataType data;
+ union txcs_e cs;
+ union id_e id;
+ union data_e data;
};
-struct MbRx
+struct mbrx_s
{
- union RXcsType CS;
- union IDType ID;
- union DataType data;
+ union rxcs_e cs;
+ union id_e id;
+ union data_e data;
};
/* The s32k1xx_driver_s encapsulates all state information for a single
@@ -308,12 +292,10 @@ struct s32k1xx_driver_s
struct net_driver_s dev; /* Interface understood by the network */
- struct MbRx *rx;
- struct MbTx *tx;
-
+ struct mbrx_s *rx;
+ struct mbtx_s *tx;
};
-
/****************************************************************************
* Private Data
****************************************************************************/
@@ -323,7 +305,6 @@ static struct s32k1xx_driver_s g_flexcan[CONFIG_S32K1XX_ENET_NETHIFS];
static uint8_t g_desc_pool[2000]
__attribute__((aligned(ARMV7M_DCACHE_LINESIZE)));
-
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
@@ -350,10 +331,11 @@ static int s32k1xx_transmit(FAR struct s32k1xx_driver_s *priv);
static int s32k1xx_txpoll(struct net_driver_s *dev);
/* Helper functions */
+
static void s32k1xx_setenable(uint32_t enable);
static void s32k1xx_setfreeze(uint32_t freeze);
static uint32_t s32k1xx_waitmcr_change(uint32_t mask,
- uint32_t target_state);
+ uint32_t target_state);
/* Interrupt handling */
@@ -363,7 +345,7 @@ static void s32k1xx_txdone(FAR struct s32k1xx_driver_s *priv);
static void s32k1xx_flexcan_interrupt_work(FAR void *arg);
static int s32k1xx_flexcan_interrupt(int irq, FAR void *context,
- FAR void *arg);
+ FAR void *arg);
/* Watchdog timer expirations */
@@ -383,13 +365,13 @@ static int s32k1xx_txavail(struct net_driver_s *dev);
#ifdef CONFIG_NET_MCASTGROUP
static int s32k1xx_addmac(struct net_driver_s *dev,
- FAR const uint8_t *mac);
+ FAR const uint8_t *mac);
static int s32k1xx_rmmac(struct net_driver_s *dev, FAR const uint8_t *mac);
#endif
#ifdef CONFIG_NETDEV_IOCTL
static int s32k1xx_ioctl(struct net_driver_s *dev, int cmd,
- unsigned long arg);
+ unsigned long arg);
#endif
/* Initialization */
@@ -402,7 +384,6 @@ static void s32k1xx_reset(struct s32k1xx_driver_s *priv);
* Private Functions
****************************************************************************/
-
/****************************************************************************
* Function: s32k1xx_txringfull
*
@@ -428,7 +409,7 @@ static bool s32k1xx_txringfull(FAR struct s32k1xx_driver_s *priv)
*/
txnext = priv->txhead + 1;
-
+
return priv->txtail == txnext;
}
@@ -452,69 +433,79 @@ static bool s32k1xx_txringfull(FAR struct s32k1xx_driver_s *priv)
*
****************************************************************************/
-
static int s32k1xx_transmit(FAR struct s32k1xx_driver_s *priv)
{
#warning Missing logic
- struct can_frame *frame = (struct can_frame*)priv->dev.d_buf;
+ struct can_frame *frame = (struct can_frame *)priv->dev.d_buf;
- /*ninfo("CAN id: %i dlc: %i", frame->can_id, frame->can_dlc);
+#if 0
+ ninfo("CAN id: %i dlc: %i", frame->can_id, frame->can_dlc);
- for(int i = 0; i < frame->can_dlc; i++){
- ninfo(" %02X", frame->data[i]);
- }
- ninfo("\r\n");*/
+ for (int i = 0; i < frame->can_dlc; i++)
+ {
+ ninfo(" %02X", frame->data[i]);
+ }
+
+ ninfo("\r\n");
+#endif
/* Attempt to write frame */
+
uint32_t mbi = 0;
- if ((getreg32(S32K1XX_CAN0_ESR2) & (CAN_ESR2_IMB | CAN_ESR2_VPS)) == (CAN_ESR2_IMB | CAN_ESR2_VPS))
- {
- mbi = (getreg32(S32K1XX_CAN0_ESR2) & CAN_ESR2_LPTM_MASK) >> CAN_ESR2_LPTM_SHIFT;
- }
+ if ((getreg32(S32K1XX_CAN0_ESR2) & (CAN_ESR2_IMB | CAN_ESR2_VPS)) ==
+ (CAN_ESR2_IMB | CAN_ESR2_VPS))
+ {
+ mbi = (getreg32(S32K1XX_CAN0_ESR2) & CAN_ESR2_LPTM_MASK) >>
+ CAN_ESR2_LPTM_SHIFT;
+ }
- uint32_t mb_bit = 1 << (RxandFilterMBCount + mbi);
+ uint32_t mb_bit = 1 << (RXANDFILTERMBCOUNT + mbi);
- while (mbi < TxMBCount)
- {
+ while (mbi < TXMBCOUNT)
+ {
+ if (priv->tx[mbi].cs.code != CAN_TXMB_DATAORREMOTE)
+ {
+ putreg32(mb_bit, S32K1XX_CAN0_IFLAG1);
+ break;
+ }
- if (priv->tx[mbi].CS.code != CAN_TXMB_DATAORREMOTE)
- {
- putreg32(mb_bit, S32K1XX_CAN0_IFLAG1);
- break;
- }
- mb_bit <<= 1;
- mbi++;
- }
+ mb_bit <<= 1;
+ mbi++;
+ }
- if ((mbi-RxandFilterMBCount) == TxMBCount)
- {
- nwarn("No TX MB available mbi %i\r\n", mbi);
- return 0; // No transmission for you!
- }
+ if ((mbi - RXANDFILTERMBCOUNT) == TXMBCOUNT)
+ {
+ nwarn("No TX MB available mbi %i\r\n", mbi);
+ return 0; /* No transmission for you! */
+ }
- peak_tx_mailbox_index_ = (peak_tx_mailbox_index_ > mbi ? peak_tx_mailbox_index_ : mbi );
+ peak_tx_mailbox_index_ =
+ (peak_tx_mailbox_index_ > mbi ? peak_tx_mailbox_index_ : mbi);
- union TXcsType cs;
+ union txcs_e cs;
cs.code = CAN_TXMB_DATAORREMOTE;
- struct MbTx* mb = &priv->tx[mbi];
- mb->CS.code = CAN_TXMB_INACTIVE;
+ struct mbtx_s *mb = &priv->tx[mbi];
+ mb->cs.code = CAN_TXMB_INACTIVE;
- if (0) //FIXME detect Std or Ext id
- {
- cs.ide = 1;
- mb->ID.ext = frame->can_id & MaskExtID;
- }
+ if (0) /* FIXME detect Std or Ext id */
+ {
+ cs.ide = 1;
+ mb->id.ext = frame->can_id & MASKEXTID;
+ }
else
- {
- mb->ID.std = frame->can_id & MaskStdID;
- }
+ {
+ mb->id.std = frame->can_id & MASKSTDID;
+ }
- //cs.rtr = frame.isRemoteTransmissionRequest();
+#if 0
+ cs.rtr = frame.isRemoteTransmissionRequest();
+#endif
cs.dlc = frame->can_dlc;
- //FIXME endian swap instruction or somekind takes 1.5us right now
+ /* FIXME endian swap instruction or somekind takes 1.5us right now */
+
mb->data.b0 = frame->data[0];
mb->data.b1 = frame->data[1];
mb->data.b2 = frame->data[2];
@@ -524,20 +515,22 @@ static int s32k1xx_transmit(FAR struct s32k1xx_driver_s *priv)
mb->data.b6 = frame->data[6];
mb->data.b7 = frame->data[7];
- /*
- * Registering the pending transmission so we can track its deadline and loopback it as needed
+#if 0
+ /* Registering the pending transmission so we can track its deadline and
+ * loopback it as needed
*/
- /*TxItem& txi = pending_tx_[mbi];
+
+ txitem& txi = pending_tx_[mbi];
txi.deadline = tx_deadline;
txi.frame = frame;
txi.loopback = (flags & uavcan::CanIOFlagLoopback) != 0;
txi.abort_on_error = (flags & uavcan::CanIOFlagAbortOnError) != 0;
- txi.pending = TxItem::busy;*/
-
+ txi.pending = txitem::busy;
+#endif
s32k1xx_gpiowrite(PIN_PORTD | PIN31, 0);
- mb->CS = cs; // Go.
+ mb->cs = cs; /* Go. */
uint32_t regval;
regval = getreg32(S32K1XX_CAN0_IMASK1);
@@ -585,14 +578,15 @@ static int s32k1xx_txpoll(struct net_driver_s *dev)
if (priv->dev.d_len > 0)
{
-
if (!devif_loopback(&priv->dev))
{
/* Send the packet */
s32k1xx_transmit(priv);
- /*priv->dev.d_buf =
- (uint8_t *)s32k1xx_swap32((uint32_t)priv->txdesc[priv->txhead].data);*/
+#if 0
+ priv->dev.d_buf =
+ (uint8_t *)s32k1xx_swap32((uint32_t)priv->txdesc[priv->txhead].data);
+#endif
/* Check if there is room in the device to hold another packet. If
* not, return a non-zero value to terminate the poll.
@@ -632,7 +626,6 @@ static int s32k1xx_txpoll(struct net_driver_s *dev)
static inline void s32k1xx_dispatch(FAR struct s32k1xx_driver_s *priv)
{
-
#warning Missing logic
}
@@ -656,96 +649,90 @@ static inline void s32k1xx_dispatch(FAR struct s32k1xx_driver_s *priv)
static void s32k1xx_receive(FAR struct s32k1xx_driver_s *priv)
{
#warning Missing logic
- //ninfo("FLEXCAN: receive\r\n");
-
- s32k1xx_gpiowrite(PIN_PORTD | PIN31, 1);
-
- struct can_frame frame;
- uint32_t flags = getreg32(S32K1XX_CAN0_IFLAG1);
-
- if ((flags & FIFO_IFLAG1) == 0)
- {
- // Weird, IRQ is here but no data to read
- return;
- }
+ s32k1xx_gpiowrite(PIN_PORTD | PIN31, 1);
- if (flags & CAN_FIFO_OV)
- {
- //error_cnt_++;
- putreg32(CAN_FIFO_OV, S32K1XX_CAN0_IFLAG1);
- }
+ struct can_frame frame;
+ uint32_t flags = getreg32(S32K1XX_CAN0_IFLAG1);
- if (flags & CAN_FIFO_WARN)
- {
- //fifo_warn_cnt_++;
- putreg32(CAN_FIFO_WARN, S32K1XX_CAN0_IFLAG1);
- }
-
- if (flags & CAN_FIFO_NE)
- {
- struct MbRx *rf = priv->rx;
+ if ((flags & FIFO_IFLAG1) == 0)
+ {
+ /* Weird, IRQ is here but no data to read */
- /*
- * Read the frame contents
- */
+ return;
+ }
- if (rf->CS.ide)
- {
- frame.can_id = MaskExtID & rf->ID.ext;
- frame.can_id |= FlagEFF;
- }
- else
- {
- frame.can_id = MaskStdID & rf->ID.std;
- }
+ if (flags & CAN_FIFO_OV)
+ {
+#if 0
+ error_cnt_++;
+#endif
+ putreg32(CAN_FIFO_OV, S32K1XX_CAN0_IFLAG1);
+ }
- if (rf->CS.rtr)
- {
- frame.can_id |= FlagRTR;
- }
+ if (flags & CAN_FIFO_WARN)
+ {
+#if 0
+ fifo_warn_cnt_++;
+#endif
+ putreg32(CAN_FIFO_WARN, S32K1XX_CAN0_IFLAG1);
+ }
- frame.can_dlc = rf->CS.dlc;
+ if (flags & CAN_FIFO_NE)
+ {
+ struct mbrx_s *rf = priv->rx;
- frame.data[0] = rf->data.b0;
- frame.data[1] = rf->data.b1;
- frame.data[2] = rf->data.b2;
- frame.data[3] = rf->data.b3;
- frame.data[4] = rf->data.b4;
- frame.data[5] = rf->data.b5;
- frame.data[6] = rf->data.b6;
- frame.data[7] = rf->data.b7;
+ /* Read the frame contents */
+ if (rf->cs.ide)
+ {
+ frame.can_id = MASKEXTID & rf->id.ext;
+ frame.can_id |= FLAGEFF;
+ }
+ else
+ {
+ frame.can_id = MASKSTDID & rf->id.std;
+ }
- putreg32(CAN_FIFO_NE, S32K1XX_CAN0_IFLAG1);
+ if (rf->cs.rtr)
+ {
+ frame.can_id |= FLAGRTR;
+ }
- /* Copy the buffer pointer to priv->dev.d_buf. Set amount of data
- * in priv->dev.d_len
- */
+ frame.can_dlc = rf->cs.dlc;
- priv->dev.d_len = sizeof(struct can_frame);
- priv->dev.d_buf =
- (uint8_t *)s32k1xx_swap32((uint32_t)&frame); //FIXME
+ frame.data[0] = rf->data.b0;
+ frame.data[1] = rf->data.b1;
+ frame.data[2] = rf->data.b2;
+ frame.data[3] = rf->data.b3;
+ frame.data[4] = rf->data.b4;
+ frame.data[5] = rf->data.b5;
+ frame.data[6] = rf->data.b6;
+ frame.data[7] = rf->data.b7;
- /* Invalidate the buffer so that the correct packet will be re-read
- * from memory when the packet content is accessed.
- */
+ putreg32(CAN_FIFO_NE, S32K1XX_CAN0_IFLAG1);
- up_invalidate_dcache((uintptr_t)priv->dev.d_buf,
- (uintptr_t)priv->dev.d_buf + priv->dev.d_len);
+ /* Copy the buffer pointer to priv->dev.d_buf. Set amount of data
+ * in priv->dev.d_len
+ */
- /* Send to socket interface */
- NETDEV_RXPACKETS(&priv->dev);
+ priv->dev.d_len = sizeof(struct can_frame);
+ priv->dev.d_buf = (uint8_t *)s32k1xx_swap32((uint32_t)&frame); /* FIXME */
- can_input(&priv->dev);
+ /* Invalidate the buffer so that the correct packet will be re-read
+ * from memory when the packet content is accessed.
+ */
+ up_invalidate_dcache((uintptr_t)priv->dev.d_buf,
+ (uintptr_t)priv->dev.d_buf + priv->dev.d_len);
+ /* Send to socket interface */
+ NETDEV_RXPACKETS(&priv->dev);
- /*
- * Store with timeout into the FIFO buffer and signal update event
- */
+ can_input(&priv->dev);
- }
+ /* Store with timeout into the FIFO buffer and signal update event */
+ }
}
/****************************************************************************
@@ -771,24 +758,27 @@ static void s32k1xx_txdone(FAR struct s32k1xx_driver_s *priv)
#warning Missing logic
uint32_t tx_iflags;
- tx_iflags = getreg32(S32K1XX_CAN0_IFLAG1) & TXMBMask;
+ tx_iflags = getreg32(S32K1XX_CAN0_IFLAG1) & TXMBMASK;
- //FIXME process aborts
+ /* FIXME process aborts */
/* Process TX completions */
- uint32_t mb_bit = 1 << RxMBCount;
- for(uint32_t mbi = 0; tx_iflags && mbi < TxMBCount; mbi++)
- {
+ uint32_t mb_bit = 1 << RXMBCOUNT;
+ for (uint32_t mbi = 0; tx_iflags && mbi < TXMBCOUNT; mbi++)
+ {
if (tx_iflags & mb_bit)
- {
- putreg32(mb_bit, S32K1XX_CAN0_IFLAG1);
+ {
+ putreg32(mb_bit, S32K1XX_CAN0_IFLAG1);
tx_iflags &= ~mb_bit;
- //const bool txok = priv->tx[mbi].CS.code != CAN_TXMB_ABORT;
- //handleTxMailboxInterrupt(mbi, txok, utc_usec);
- }
+#if 0
+ const bool txok = priv->tx[mbi].cs.code != CAN_TXMB_ABORT;
+ handleTxMailboxInterrupt(mbi, txok, utc_usec);
+#endif
+ }
+
mb_bit <<= 1;
- }
+ }
}
/****************************************************************************
@@ -833,27 +823,26 @@ static void s32k1xx_flexcan_interrupt_work(FAR void *arg)
*
****************************************************************************/
-
static int s32k1xx_flexcan_interrupt(int irq, FAR void *context, FAR void *arg)
{
#warning Missing logic
- FAR struct s32k1xx_driver_s *priv = &g_flexcan[0];
- uint32_t flags;
- flags = getreg32(S32K1XX_CAN0_IFLAG1);
- flags &= FIFO_IFLAG1;
-
- if(flags)
- {
- s32k1xx_receive(priv);
- }
-
- flags = getreg32(S32K1XX_CAN0_IFLAG1);
- flags &= TXMBMask;
-
- if(flags)
- {
- s32k1xx_txdone(priv);
- }
+ FAR struct s32k1xx_driver_s *priv = &g_flexcan[0];
+ uint32_t flags;
+ flags = getreg32(S32K1XX_CAN0_IFLAG1);
+ flags &= FIFO_IFLAG1;
+
+ if (flags)
+ {
+ s32k1xx_receive(priv);
+ }
+
+ flags = getreg32(S32K1XX_CAN0_IFLAG1);
+ flags &= TXMBMASK;
+
+ if (flags)
+ {
+ s32k1xx_txdone(priv);
+ }
}
/****************************************************************************
@@ -875,7 +864,7 @@ static int s32k1xx_flexcan_interrupt(int irq, FAR void *context, FAR void *arg)
static void s32k1xx_txtimeout_work(FAR void *arg)
{
#warning Missing logic
- ninfo("FLEXCAN: tx timeout work\r\n");
+ ninfo("FLEXCAN: tx timeout work\r\n");
}
/****************************************************************************
@@ -900,7 +889,7 @@ static void s32k1xx_txtimeout_work(FAR void *arg)
static void s32k1xx_txtimeout_expiry(int argc, uint32_t arg, ...)
{
#warning Missing logic
- ninfo("FLEXCAN: tx timeout expiry\r\n");
+ ninfo("FLEXCAN: tx timeout expiry\r\n");
}
/****************************************************************************
@@ -923,32 +912,29 @@ static void s32k1xx_txtimeout_expiry(int argc, uint32_t arg, ...)
static void s32k1xx_poll_work(FAR void *arg)
{
#warning Missing logic
- //ninfo("FLEXCAN: poll work\r\n");
-
- FAR struct s32k1xx_driver_s *priv = (FAR struct s32k1xx_driver_s *)arg;
-
- /* Check if there is there is a transmission in progress. We cannot
- * perform the TX poll if he are unable to accept another packet for
- * transmission.
- */
+ FAR struct s32k1xx_driver_s *priv = (FAR struct s32k1xx_driver_s *)arg;
- net_lock();
- if (1) //!s32k1xx_txringfull(priv))
- {
- /* If so, update TCP timing states and poll the network for new XMIT
- * data. Hmmm.. might be bug here. Does this mean if there is a
- * transmit in progress, we will missing TCP time state updates?
- */
+ /* Check if there is there is a transmission in progress. We cannot
+ * perform the TX poll if he are unable to accept another packet for
+ * transmission.
+ */
- devif_timer(&priv->dev, S32K1XX_WDDELAY, s32k1xx_txpoll);
- }
+ net_lock();
+ if (1) /* !s32k1xx_txringfull(priv)) */
+ {
+ /* If so, update TCP timing states and poll the network for new XMIT
+ * data. Hmmm.. might be bug here. Does this mean if there is a
+ * transmit in progress, we will missing TCP time state updates?
+ */
- /* Setup the watchdog poll timer again in any case */
+ devif_timer(&priv->dev, S32K1XX_WDDELAY, s32k1xx_txpoll);
+ }
- wd_start(priv->txpoll, S32K1XX_WDDELAY, s32k1xx_polltimer_expiry,
- 1, (wdparm_t)priv);
- net_unlock();
+ /* Setup the watchdog poll timer again in any case */
+ wd_start(priv->txpoll, S32K1XX_WDDELAY, s32k1xx_polltimer_expiry,
+ 1, (wdparm_t)priv);
+ net_unlock();
}
/****************************************************************************
@@ -981,62 +967,67 @@ static void s32k1xx_polltimer_expiry(int argc, uint32_t arg, ...)
static void s32k1xx_setenable(uint32_t enable)
{
- uint32_t regval;
- if(enable)
- {
- regval = getreg32(S32K1XX_CAN0_MCR);
- regval &= ~(CAN_MCR_MDIS);
- putreg32(regval, S32K1XX_CAN0_MCR);
- }
- else
- {
- regval = getreg32(S32K1XX_CAN0_MCR);
- regval |= CAN_MCR_MDIS;
- putreg32(regval, S32K1XX_CAN0_MCR);
- }
- s32k1xx_waitmcr_change(CAN_MCR_LPMACK,1);
+ uint32_t regval;
+
+ if (enable)
+ {
+ regval = getreg32(S32K1XX_CAN0_MCR);
+ regval &= ~(CAN_MCR_MDIS);
+ putreg32(regval, S32K1XX_CAN0_MCR);
+ }
+ else
+ {
+ regval = getreg32(S32K1XX_CAN0_MCR);
+ regval |= CAN_MCR_MDIS;
+ putreg32(regval, S32K1XX_CAN0_MCR);
+ }
+
+ s32k1xx_waitmcr_change(CAN_MCR_LPMACK, 1);
}
static void s32k1xx_setfreeze(uint32_t freeze)
{
- uint32_t regval;
- if(freeze)
- {
- /* Enter freeze mode */
- regval = getreg32(S32K1XX_CAN0_MCR);
- regval |= (CAN_MCR_HALT | CAN_MCR_FRZ);
- putreg32(regval, S32K1XX_CAN0_MCR);
- }
- else
- {
- /* Exit freeze mode */
- regval = getreg32(S32K1XX_CAN0_MCR);
- regval &= ~(CAN_MCR_HALT | CAN_MCR_FRZ);
- putreg32(regval, S32K1XX_CAN0_MCR);
- }
+ uint32_t regval;
+ if (freeze)
+ {
+ /* Enter freeze mode */
+
+ regval = getreg32(S32K1XX_CAN0_MCR);
+ regval |= (CAN_MCR_HALT | CAN_MCR_FRZ);
+ putreg32(regval, S32K1XX_CAN0_MCR);
+ }
+ else
+ {
+ /* Exit freeze mode */
+
+ regval = getreg32(S32K1XX_CAN0_MCR);
+ regval &= ~(CAN_MCR_HALT | CAN_MCR_FRZ);
+ putreg32(regval, S32K1XX_CAN0_MCR);
+ }
}
static uint32_t s32k1xx_waitmcr_change(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(S32K1XX_CAN0_MCR) & mask) != 0;
- if (state == target_state)
- {
- return true;
- }
- up_udelay(10);
- }
- return false;
+ const unsigned timeout = 1000;
+ for (unsigned wait_ack = 0; wait_ack < timeout; wait_ack++)
+ {
+ const bool state = (getreg32(S32K1XX_CAN0_MCR) & mask) != 0;
+ if (state == target_state)
+ {
+ return true;
+ }
+
+ up_udelay(10);
+ }
+
+ return false;
}
static uint32_t s32k1xx_waitfreezeack_change(uint32_t target_state)
{
- return s32k1xx_waitmcr_change(CAN_MCR_FRZACK, target_state);
+ return s32k1xx_waitmcr_change(CAN_MCR_FRZACK, target_state);
}
-
/****************************************************************************
* Function: s32k1xx_ifup
*
@@ -1057,16 +1048,16 @@ static uint32_t s32k1xx_waitfreezeack_change(uint32_t target_state)
static int s32k1xx_ifup(struct net_driver_s *dev)
{
FAR struct s32k1xx_driver_s *priv =
- (FAR struct s32k1xx_driver_s *)dev->d_private;
+ (FAR struct s32k1xx_driver_s *)dev->d_private;
uint32_t regval;
#warning Missing logic
- if(!s32k1xx_initialize(priv))
- {
- nerr("initialize failed");
- return -1;
- }
+ if (!s32k1xx_initialize(priv))
+ {
+ nerr("initialize failed");
+ return -1;
+ }
/* Set and activate a timer process */
@@ -1078,6 +1069,7 @@ static int s32k1xx_ifup(struct net_driver_s *dev)
priv->dev.d_buf = &g_desc_pool;
/* Set interrupts */
+
up_enable_irq(S32K1XX_IRQ_CAN0_BUS);
up_enable_irq(S32K1XX_IRQ_CAN0_ERROR);
up_enable_irq(S32K1XX_IRQ_CAN0_LPRX);
@@ -1127,28 +1119,28 @@ static int s32k1xx_ifdown(struct net_driver_s *dev)
static void s32k1xx_txavail_work(FAR void *arg)
{
- FAR struct s32k1xx_driver_s *priv = (FAR struct s32k1xx_driver_s *)arg;
+ FAR struct s32k1xx_driver_s *priv = (FAR struct s32k1xx_driver_s *)arg;
- /* Ignore the notification if the interface is not yet up */
+ /* Ignore the notification if the interface is not yet up */
- net_lock();
- if (priv->bifup)
- {
- /* Check if there is room in the hardware to hold another outgoing
- * packet.
- */
+ net_lock();
+ if (priv->bifup)
+ {
+ /* Check if there is room in the hardware to hold another outgoing
+ * packet.
+ */
- if (!s32k1xx_txringfull(priv))
- {
- /* No, there is space for another transfer. Poll the network for
- * new XMIT data.
- */
+ if (!s32k1xx_txringfull(priv))
+ {
+ /* No, there is space for another transfer. Poll the network for
+ * new XMIT data.
+ */
- devif_poll(&priv->dev, s32k1xx_txpoll);
- }
- }
+ devif_poll(&priv->dev, s32k1xx_txpoll);
+ }
+ }
- net_unlock();
+ net_unlock();
}
/****************************************************************************
@@ -1183,8 +1175,9 @@ static int s32k1xx_txavail(struct net_driver_s *dev)
if (work_available(&priv->pollwork))
{
/* Schedule to serialize the poll on the worker thread. */
+
#ifdef WORK_QUEUE_BYPASS
- s32k1xx_txavail_work(priv);
+ s32k1xx_txavail_work(priv);
#else
work_queue(ETHWORK, &priv->pollwork, s32k1xx_txavail_work, priv, 0);
#endif
@@ -1193,7 +1186,6 @@ static int s32k1xx_txavail(struct net_driver_s *dev)
return OK;
}
-
/****************************************************************************
* Function: s32k1xx_ioctl
*
@@ -1247,119 +1239,131 @@ static int s32k1xx_ioctl(struct net_driver_s *dev, int cmd,
static int s32k1xx_initialize(struct s32k1xx_driver_s *priv)
{
- uint32_t regval;
- uint32_t i;
+ uint32_t regval;
+ uint32_t i;
- /* initialize CAN device */
- //FIXME we only support a single can device for now
+ /* initialize CAN device */
- //TEST GPIO tming
- s32k1xx_pinconfig(PIN_PORTD | PIN31 | GPIO_OUTPUT);
+ /* FIXME we only support a single can device for now */
+ /* TEST GPIO tming */
- s32k1xx_setenable(0);
+ s32k1xx_pinconfig(PIN_PORTD | PIN31 | GPIO_OUTPUT);
- /* Set SYS_CLOCK src */
- regval = getreg32(S32K1XX_CAN0_CTRL1);
- regval |= CAN_CTRL1_CLKSRC;
- putreg32(regval, S32K1XX_CAN0_CTRL1);
+ s32k1xx_setenable(0);
- s32k1xx_setenable(1);
+ /* Set SYS_CLOCK src */
- s32k1xx_reset(priv);
+ regval = getreg32(S32K1XX_CAN0_CTRL1);
+ regval |= CAN_CTRL1_CLKSRC;
+ putreg32(regval, S32K1XX_CAN0_CTRL1);
- /* Enter freeze mode */
- s32k1xx_setfreeze(1);
- if(!s32k1xx_waitfreezeack_change(1))
- {
- ninfo("FLEXCAN: freeze fail\r\n");
- return -1;
- }
+ s32k1xx_setenable(1);
- /*regval = getreg32(S32K1XX_CAN0_CTRL1);
- regval |= ((0 << CAN_CTRL1_PRESDIV_SHIFT) & CAN_CTRL1_PRESDIV_MASK)
- | ((46 << CAN_CTRL1_ROPSEG_SHIFT) & CAN_CTRL1_ROPSEG_MASK)
- | ((18 << CAN_CTRL1_PSEG1_SHIFT) & CAN_CTRL1_PSEG1_MASK)
- | ((12 << CAN_CTRL1_PSEG2_SHIFT) & CAN_CTRL1_PSEG2_MASK)
- | ((12 << CAN_CTRL1_RJW_SHIFT) & CAN_CTRL1_RJW_MASK)
- | CAN_CTRL1_ERRMSK
- | CAN_CTRL1_TWRNMSK
- | CAN_CTRL1_RWRNMSK;
+ s32k1xx_reset(priv);
- putreg32(regval, S32K1XX_CAN0_CTRL1);*/
+ /* Enter freeze mode */
+
+ s32k1xx_setfreeze(1);
+ if (!s32k1xx_waitfreezeack_change(1))
+ {
+ ninfo("FLEXCAN: freeze fail\r\n");
+ return -1;
+ }
+
+#if 0
+ regval = getreg32(S32K1XX_CAN0_CTRL1);
+ regval |= ((0 << CAN_CTRL1_PRESDIV_SHIFT) & CAN_CTRL1_PRESDIV_MASK) |
+ ((46 << CAN_CTRL1_ROPSEG_SHIFT) & CAN_CTRL1_ROPSEG_MASK) |
+ ((18 << CAN_CTRL1_PSEG1_SHIFT) & CAN_CTRL1_PSEG1_MASK) |
+ ((12 << CAN_CTRL1_PSEG2_SHIFT) & CAN_CTRL1_PSEG2_MASK) |
+ ((12 << CAN_CTRL1_RJW_SHIFT) & CAN_CTRL1_RJW_MASK) |
+ CAN_CTRL1_ERRMSK |
+ CAN_CTRL1_TWRNMSK |
+ CAN_CTRL1_RWRNMSK;
+
+ putreg32(regval, S32K1XX_CAN0_CTRL1);
+#endif
#define BIT_METHOD2
#ifdef BIT_METHOD2
- /* CAN Bit Timing (CBT) configuration for a nominal phase of 1 Mbit/s
- * with 80 time quantas,in accordance with Bosch 2012 specification,
- * sample point at 83.75% */
- regval = getreg32(S32K1XX_CAN0_CBT);
- regval |= CAN_CBT_BTF | /* Enable extended bit timing configurations for CAN-FD
- for setting up separetely nominal and data phase */
- CAN_CBT_EPRESDIV(0) | /* Prescaler divisor factor of 1 */
- CAN_CBT_EPROPSEG(46) | /* Propagation segment of 47 time quantas */
- CAN_CBT_EPSEG1(18) | /* Phase buffer segment 1 of 19 time quantas */
- CAN_CBT_EPSEG2(12) | /* Phase buffer segment 2 of 13 time quantas */
- CAN_CBT_ERJW(12); /* Resynchronization jump width same as PSEG2 */
- putreg32(regval, S32K1XX_CAN0_CBT);
+ /* CAN Bit Timing (CBT) configuration for a nominal phase of 1 Mbit/s
+ * with 80 time quantas,in accordance with Bosch 2012 specification,
+ * sample point at 83.75%
+ */
+
+ regval = getreg32(S32K1XX_CAN0_CBT);
+ regval |= CAN_CBT_BTF | /* Enable extended bit timing configurations
+ * for CAN-FD for setting up separately
+ * nominal and data phase */
+ CAN_CBT_EPRESDIV(0) | /* Prescaler divisor factor of 1 */
+ CAN_CBT_EPROPSEG(46) | /* Propagation segment of 47 time quantas */
+ CAN_CBT_EPSEG1(18) | /* Phase buffer segment 1 of 19 time quantas */
+ CAN_CBT_EPSEG2(12) | /* Phase buffer segment 2 of 13 time quantas */
+ CAN_CBT_ERJW(12); /* Resynchronization jump width same as PSEG2 */
+ putreg32(regval, S32K1XX_CAN0_CBT);
#endif
#ifdef CAN_FD
+ /* Enable CAN FD feature */
+
+ regval = getreg32(S32K1XX_CAN0_MCR);
+ regval |= CAN_MCR_FDEN;
+ putreg32(regval, S32K1XX_CAN0_MCR);
+
+ /* CAN-FD Bit Timing (FDCBT) for a data phase of 4 Mbit/s with 20 time quantas,
+ * in accordance with Bosch 2012 specification, sample point at 75%
+ */
+
+ regval = getreg32(S32K1XX_CAN0_FDCBT);
+ regval |= CAN_FDCBT_FPRESDIV(0) | /* Prescaler divisor factor of 1 */
+ CAN_FDCBT_FPROPSEG(7) | /* Propagation semgment of 7 time quantas
+ * (only register that doesn't add 1) */
+ CAN_FDCBT_FPSEG1(6) | /* Phase buffer segment 1 of 7 time quantas */
+ CAN_FDCBT_FPSEG2(4) | /* Phase buffer segment 2 of 5 time quantas */
+ CAN_FDCBT_FRJW(4); /* Resynchorinzation jump width same as PSEG2 */
+ putreg32(regval, S32K1XX_CAN0_FDCBT);
+
+ /* Additional CAN-FD configurations */
+
+ regval = getreg32(S32K1XX_CAN0_FDCTRL);
- /* Enable CAN FD feature */
- regval = getreg32(S32K1XX_CAN0_MCR);
- regval |= CAN_MCR_FDEN;
- putreg32(regval, S32K1XX_CAN0_MCR);
-
- /* CAN-FD Bit Timing (FDCBT) for a data phase of 4 Mbit/s with 20 time quantas,
- in accordance with Bosch 2012 specification, sample point at 75% */
- regval = getreg32(S32K1XX_CAN0_FDCBT);
- regval |= CAN_FDCBT_FPRESDIV(0) | /* Prescaler divisor factor of 1 */
- CAN_FDCBT_FPROPSEG(7) | /* Propagation semgment of 7 time quantas
- (only register that doesn't add 1) */
- CAN_FDCBT_FPSEG1(6) | /* Phase buffer segment 1 of 7 time quantas */
- CAN_FDCBT_FPSEG2(4) | /* Phase buffer segment 2 of 5 time quantas */
- CAN_FDCBT_FRJW(4); /* Resynchorinzation jump width same as PSEG2 */
- putreg32(regval, S32K1XX_CAN0_FDCBT);
-
- /* Additional CAN-FD configurations */
- regval = getreg32(S32K1XX_CAN0_FDCTRL);
- regval |= CAN_FDCTRL_FDRATE | /* Enable bit rate switch in data phase of frame */
- CAN_FDCTRL_TDCEN | /* Enable transceiver delay compensation */
- CAN_FDCTRL_TDCOFF(5) | /* Setup 5 cycles for data phase sampling delay */
- CAN_FDCTRL_MBDSR0(3); /* Setup 64 bytes per message buffer (7 MB's) */
- putreg32(regval, S32K1XX_CAN0_FDCTRL);
-
- regval = getreg32(S32K1XX_CAN0_CTRL2);
- regval |= CAN_CTRL2_ISOCANFDEN;
- putreg32(regval, S32K1XX_CAN0_CTRL2);
+ regval |= CAN_FDCTRL_FDRATE | /* Enable bit rate switch in data phase of frame */
+ CAN_FDCTRL_TDCEN | /* Enable transceiver delay compensation */
+ CAN_FDCTRL_TDCOFF(5) | /* Setup 5 cycles for data phase sampling delay */
+ CAN_FDCTRL_MBDSR0(3); /* Setup 64 bytes per message buffer (7 MB's) */
+ putreg32(regval, S32K1XX_CAN0_FDCTRL);
+
+ regval = getreg32(S32K1XX_CAN0_CTRL2);
+ regval |= CAN_CTRL2_ISOCANFDEN;
+ putreg32(regval, S32K1XX_CAN0_CTRL2);
#endif
- for(i = TxMBCount; i < TotalMBcount; i++)
- {
- priv->rx[i].ID.w = 0x0;
- }
+ for (i = TXMBCOUNT; i < TOTALMBCOUNT; i++)
+ {
+ priv->rx[i].id.w = 0x0;
+ }
- putreg32(0x0, S32K1XX_CAN0_RXFGMASK);
+ putreg32(0x0, S32K1XX_CAN0_RXFGMASK);
- for(i = 0; i < TotalMBcount; i++)
- {
- putreg32(0,S32K1XX_CAN0_RXIMR(i));
- }
+ for (i = 0; i < TOTALMBCOUNT; i++)
+ {
+ putreg32(0, S32K1XX_CAN0_RXIMR(i));
+ }
- putreg32(FIFO_IFLAG1 | TXMBMask, S32K1XX_CAN0_IFLAG1);
- putreg32(FIFO_IFLAG1, S32K1XX_CAN0_IMASK1);
+ putreg32(FIFO_IFLAG1 | TXMBMASK, S32K1XX_CAN0_IFLAG1);
+ putreg32(FIFO_IFLAG1, S32K1XX_CAN0_IMASK1);
+ /* Exit freeze mode */
- /* Exit freeze mode */
- s32k1xx_setfreeze(0);
- if(!s32k1xx_waitfreezeack_change(0))
- {
- ninfo("FLEXCAN: unfreeze fail\r\n");
- return -1;
- }
+ s32k1xx_setfreeze(0);
+ if (!s32k1xx_waitfreezeack_change(0))
+ {
+ ninfo("FLEXCAN: unfreeze fail\r\n");
+ return -1;
+ }
- return 1;
+ return 1;
}
/****************************************************************************
@@ -1401,57 +1405,57 @@ static void s32k1xx_initbuffers(struct s32k1xx_driver_s *priv)
static void s32k1xx_reset(struct s32k1xx_driver_s *priv)
{
- uint32_t regval;
- uint32_t i;
-
- regval = getreg32(S32K1XX_CAN0_MCR);
- regval |= CAN_MCR_SOFTRST;
- putreg32(regval, S32K1XX_CAN0_MCR);
-
- if(!s32k1xx_waitmcr_change(CAN_MCR_SOFTRST, 0))
- {
- nerr("Reset failed");
- return;
- }
-
- /* TODO calculate TASD */
-
-
- regval = getreg32(S32K1XX_CAN0_MCR);
- regval &= ~(CAN_MCR_SUPV);
- putreg32(regval, S32K1XX_CAN0_MCR);
-
- /* Initialize all MB rx and tx */
- for(i = 0; i < TotalMBcount; i++)
- {
- ninfo("MB %i %p\r\n", i, &priv->rx[i]);
- ninfo("MB %i %p\r\n", i, &priv->rx[i].ID.w);
- priv->rx[i].CS.cs = 0x0;
- priv->rx[i].ID.w = 0x0;
- priv->rx[i].data.l = 0x0;
- priv->rx[i].data.h = 0x0;
- }
-
- regval = getreg32(S32K1XX_CAN0_MCR);
- regval |= CAN_MCR_RFEN | CAN_MCR_SLFWAK | CAN_MCR_WRNEN | CAN_MCR_SRXDIS
- | CAN_MCR_IRMQ | CAN_MCR_AEN |
- (((TotalMBcount - 1) << CAN_MCR_MAXMB_SHIFT) & CAN_MCR_MAXMB_MASK);
- putreg32(regval, S32K1XX_CAN0_MCR);
-
- regval = CAN_CTRL2_RRS | CAN_CTRL2_EACEN | CAN_CTRL2_RFFN_16MB; //FIXME TASD
- putreg32(regval, S32K1XX_CAN0_CTRL2);
-
-
- for(i = 0; i < TotalMBcount; i++)
- {
- putreg32(0,S32K1XX_CAN0_RXIMR(i));
- }
-
- /* Filtering catchall */
- putreg32(0x3FFFFFFF, S32K1XX_CAN0_RX14MASK);
- putreg32(0x3FFFFFFF, S32K1XX_CAN0_RX15MASK);
- putreg32(0x3FFFFFFF, S32K1XX_CAN0_RXMGMASK);
- putreg32(0x0, S32K1XX_CAN0_RXFGMASK);
+ uint32_t regval;
+ uint32_t i;
+
+ regval = getreg32(S32K1XX_CAN0_MCR);
+ regval |= CAN_MCR_SOFTRST;
+ putreg32(regval, S32K1XX_CAN0_MCR);
+
+ if (!s32k1xx_waitmcr_change(CAN_MCR_SOFTRST, 0))
+ {
+ nerr("Reset failed");
+ return;
+ }
+
+ /* TODO calculate TASD */
+
+ regval = getreg32(S32K1XX_CAN0_MCR);
+ regval &= ~(CAN_MCR_SUPV);
+ putreg32(regval, S32K1XX_CAN0_MCR);
+
+ /* Initialize all MB rx and tx */
+
+ for (i = 0; i < TOTALMBCOUNT; i++)
+ {
+ ninfo("MB %i %p\r\n", i, &priv->rx[i]);
+ ninfo("MB %i %p\r\n", i, &priv->rx[i].id.w);
+ priv->rx[i].cs.cs = 0x0;
+ priv->rx[i].id.w = 0x0;
+ priv->rx[i].data.l = 0x0;
+ priv->rx[i].data.h = 0x0;
+ }
+
+ regval = getreg32(S32K1XX_CAN0_MCR);
+ regval |= CAN_MCR_RFEN | CAN_MCR_SLFWAK | CAN_MCR_WRNEN | CAN_MCR_SRXDIS |
+ CAN_MCR_IRMQ | CAN_MCR_AEN |
+ (((TOTALMBCOUNT - 1) << CAN_MCR_MAXMB_SHIFT) & CAN_MCR_MAXMB_MASK);
+ putreg32(regval, S32K1XX_CAN0_MCR);
+
+ regval = CAN_CTRL2_RRS | CAN_CTRL2_EACEN | CAN_CTRL2_RFFN_16MB; /* FIXME TASD */
+ putreg32(regval, S32K1XX_CAN0_CTRL2);
+
+ for (i = 0; i < TOTALMBCOUNT; i++)
+ {
+ putreg32(0, S32K1XX_CAN0_RXIMR(i));
+ }
+
+ /* Filtering catchall */
+
+ putreg32(0x3fffffff, S32K1XX_CAN0_RX14MASK);
+ putreg32(0x3fffffff, S32K1XX_CAN0_RX15MASK);
+ putreg32(0x3fffffff, S32K1XX_CAN0_RXMGMASK);
+ putreg32(0x0, S32K1XX_CAN0_RXFGMASK);
}
/****************************************************************************
@@ -1480,7 +1484,8 @@ int s32k1xx_netinitialize(int intf)
struct s32k1xx_driver_s *priv;
int ret;
- //FIXME dynamic board config
+ /* FIXME dynamic board config */
+
s32k1xx_pinconfig(PIN_CAN0_TX_4);
s32k1xx_pinconfig(PIN_CAN0_RX_4);
@@ -1490,10 +1495,10 @@ int s32k1xx_netinitialize(int intf)
/* Get the interface structure associated with this interface number. */
- #warning Missing logic
-
+#warning Missing logic
/* Attach the flexcan interrupt handler */
+
if (irq_attach(S32K1XX_IRQ_CAN0_BUS, s32k1xx_flexcan_interrupt, NULL))
{
/* We could not attach the ISR to the interrupt */
@@ -1501,6 +1506,7 @@ int s32k1xx_netinitialize(int intf)
nerr("ERROR: Failed to attach CAN bus IRQ\n");
return -EAGAIN;
}
+
if (irq_attach(S32K1XX_IRQ_CAN0_ERROR, s32k1xx_flexcan_interrupt, NULL))
{
/* We could not attach the ISR to the interrupt */
@@ -1508,6 +1514,7 @@ int s32k1xx_netinitialize(int intf)
nerr("ERROR: Failed to attach CAN error IRQ\n");
return -EAGAIN;
}
+
if (irq_attach(S32K1XX_IRQ_CAN0_LPRX, s32k1xx_flexcan_interrupt, NULL))
{
/* We could not attach the ISR to the interrupt */
@@ -1515,6 +1522,7 @@ int s32k1xx_netinitialize(int intf)
nerr("ERROR: Failed to attach CAN LPRX IRQ\n");
return -EAGAIN;
}
+
if (irq_attach(S32K1XX_IRQ_CAN0_0_15, s32k1xx_flexcan_interrupt, NULL))
{
/* We could not attach the ISR to the interrupt */
@@ -1526,20 +1534,21 @@ int s32k1xx_netinitialize(int intf)
/* Initialize the driver structure */
memset(priv, 0, sizeof(struct s32k1xx_driver_s));
- priv->dev.d_ifup = s32k1xx_ifup; /* I/F up (new IP address) callback */
- priv->dev.d_ifdown = s32k1xx_ifdown; /* I/F down callback */
- priv->dev.d_txavail = s32k1xx_txavail; /* New TX data callback */
+ priv->dev.d_ifup = s32k1xx_ifup; /* I/F up (new IP address) callback */
+ priv->dev.d_ifdown = s32k1xx_ifdown; /* I/F down callback */
+ priv->dev.d_txavail = s32k1xx_txavail; /* New TX data callback */
#ifdef CONFIG_NETDEV_IOCTL
- priv->dev.d_ioctl = s32k1xx_ioctl; /* Support PHY ioctl() calls */
+ priv->dev.d_ioctl = s32k1xx_ioctl; /* Support PHY ioctl() calls */
#endif
- priv->dev.d_private = (void *)g_flexcan; /* Used to recover private state from dev */
+ priv->dev.d_private = (void *)g_flexcan; /* Used to recover private state from dev */
/* Create a watchdog for timing polling for and timing of transmissions */
- priv->txpoll = wd_create(); /* Create periodic poll timer */
- priv->txtimeout = wd_create(); /* Create TX timeout timer */
- priv->rx = (struct MbRx *)(S32K1XX_CAN0_MB);
- priv->tx = (struct MbTx *)(S32K1XX_CAN0_MB + (sizeof(struct MbRx)
- * RxMBCount) );
+
+ priv->txpoll = wd_create(); /* Create periodic poll timer */
+ priv->txtimeout = wd_create(); /* Create TX timeout timer */
+ priv->rx = (struct mbrx_s *)(S32K1XX_CAN0_MB);
+ priv->tx = (struct mbtx_s *)(S32K1XX_CAN0_MB +
+ (sizeof(struct mbrx_s) * RXMBCOUNT));
/* Put the interface in the down state. This usually amounts to resetting
* the device and/or calling s32k1xx_ifdown().
@@ -1568,7 +1577,7 @@ int s32k1xx_netinitialize(int intf)
*
****************************************************************************/
-//FIXME CONFIG_S32K1XX_FLEXCAN_NETHIFS == 1 &&
+/* FIXME CONFIG_S32K1XX_FLEXCAN_NETHIFS == 1 && */
#if !defined(CONFIG_NETDEV_LATEINIT)
void up_netinitialize(void)
diff --git a/include/netpacket/can.h b/include/netpacket/can.h
index 45edab5..0b4c7b9 100644
--- a/include/netpacket/can.h
+++ b/include/netpacket/can.h
@@ -126,13 +126,13 @@ struct sockaddr_can
* 1 bit: reserved
*/
- uint32_t pgn;
+ uint32_t pgn;
- /* 1 byte address */
+ /* 1 byte address */
- uint8_t addr;
- } j1939;
- } can_addr;
+ uint8_t addr;
+ } j1939;
+ } can_addr;
};
#endif /* __INCLUDE_NETPACKET_CAN_H */
diff --git a/include/nuttx/can.h b/include/nuttx/can.h
index 02f80a8..7a66a65 100644
--- a/include/nuttx/can.h
+++ b/include/nuttx/can.h
@@ -53,7 +53,6 @@
* Pre-processor Definitions
************************************************************************************/
-
/* Ioctl Commands *******************************************************************/
/* Ioctl commands supported by the upper half CAN driver.
@@ -185,61 +184,17 @@
* CAN_B_NCMDS 77 <- Number of commands
*/
-/************************************************************************************
- * Public Types
- ************************************************************************************/
-
-typedef FAR void *CAN_HANDLE;
-
-struct can_response_s
-{
- sq_entry_t flink;
-
- /* Message-specific data may follow */
-}; //FIXME remvoe
-
-
-typedef uint32_t canid_t;
-
-/*
- * Controller Area Network Error Message Frame Mask structure
- *
- * bit 0-28 : error class mask (see include/uapi/linux/can/error.h)
- * bit 29-31 : set to zero
- */
-typedef uint32_t can_err_mask_t;
-
/* CAN payload length and DLC definitions according to ISO 11898-1 */
+
#define CAN_MAX_DLC 8
#define CAN_MAX_DLEN 8
/* CAN FD payload length and DLC definitions according to ISO 11898-7 */
+
#define CANFD_MAX_DLC 15
#define CANFD_MAX_DLEN 64
-
-/**
- * struct can_frame - basic CAN frame structure
- * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
- * @can_dlc: frame payload length in byte (0 .. 8) aka data length code
- * N.B. the DLC field from ISO 11898-1 Chapter 8.4.2.3 has a 1:1
- * mapping of the 'data length code' to the real payload length
- * @__pad: padding
- * @__res0: reserved / padding
- * @__res1: reserved / padding
- * @data: CAN frame payload (up to 8 byte)
- */
-struct can_frame {
- canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
- uint8_t can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
- uint8_t __pad; /* padding */
- uint8_t __res0; /* reserved / padding */
- uint8_t __res1; /* reserved / padding */
- uint8_t data[CAN_MAX_DLEN] __attribute__((aligned(8)));
-};
-
-/*
- * defined bits for canfd_frame.flags
+/* Defined bits for canfd_frame.flags
*
* The use of struct canfd_frame implies the Extended Data Length (EDL) bit to
* be set in the CAN frame bitstream on the wire. The EDL bit switch turns
@@ -254,48 +209,94 @@ struct can_frame {
* building a CAN FD frame for transmission. Setting the CANFD_ESI bit can make
* sense for virtual CAN interfaces to test applications with echoed frames.
*/
+
#define CANFD_BRS 0x01 /* bit rate switch (second bitrate for payload data) */
#define CANFD_ESI 0x02 /* error state indicator of the transmitting node */
-/**
- * struct canfd_frame - CAN flexible data rate frame structure
- * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
- * @len: frame payload length in byte (0 .. CANFD_MAX_DLEN)
- * @flags: additional flags for CAN FD
- * @__res0: reserved / padding
- * @__res1: reserved / padding
- * @data: CAN FD frame payload (up to CANFD_MAX_DLEN byte)
+#define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
+#define CAN_RAW_FILTER_MAX 512 /* maximum number of can_filter set via setsockopt() */
+
+/************************************************************************************
+ * Public Types
+ ************************************************************************************/
+
+typedef FAR void *CAN_HANDLE;
+
+struct can_response_s
+{
+ sq_entry_t flink;
+
+ /* Message-specific data may follow */
+}; /* FIXME remove */
+
+typedef uint32_t canid_t;
+
+/* Controller Area Network Error Message Frame Mask structure
+ *
+ * bit 0-28 : error class mask (see include/uapi/linux/can/error.h)
+ * bit 29-31 : set to zero
*/
-struct canfd_frame {
- canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
- uint8_t len; /* frame payload length in byte */
- uint8_t flags; /* additional flags for CAN FD */
- uint8_t __res0; /* reserved / padding */
- uint8_t __res1; /* reserved / padding */
- uint8_t data[CANFD_MAX_DLEN] __attribute__((aligned(8)));
+
+typedef uint32_t can_err_mask_t;
+
+/* struct can_frame - basic CAN frame structure
+ * can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
+ * can_dlc: frame payload length in byte (0 .. 8) aka data length code
+ * N.B. the DLC field from ISO 11898-1 Chapter 8.4.2.3 has a 1:1
+ * mapping of the 'data length code' to the real payload length
+ * __pad: padding
+ * __res0: reserved / padding
+ * __res1: reserved / padding
+ * data: CAN frame payload (up to 8 byte)
+ */
+
+struct can_frame
+{
+ canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
+ uint8_t can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
+ uint8_t __pad; /* padding */
+ uint8_t __res0; /* reserved / padding */
+ uint8_t __res1; /* reserved / padding */
+ uint8_t data[CAN_MAX_DLEN] __attribute__((aligned(8)));
};
+/* struct canfd_frame - CAN flexible data rate frame structure
+ * can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
+ * len: frame payload length in byte (0 .. CANFD_MAX_DLEN)
+ * flags: additional flags for CAN FD
+ * __res0: reserved / padding
+ * __res1: reserved / padding
+ * data: CAN FD frame payload (up to CANFD_MAX_DLEN byte)
+ */
+
+struct canfd_frame
+{
+ canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
+ uint8_t len; /* frame payload length in byte */
+ uint8_t flags; /* additional flags for CAN FD */
+ uint8_t __res0; /* reserved / padding */
+ uint8_t __res1; /* reserved / padding */
+ uint8_t data[CANFD_MAX_DLEN] __attribute__((aligned(8)));
+};
-/**
- * struct can_filter - CAN ID based filter in can_register().
- * @can_id: relevant bits of CAN ID which are not masked out.
- * @can_mask: CAN mask (see description)
+/* struct can_filter - CAN ID based filter in can_register().
+ * can_id: relevant bits of CAN ID which are not masked out.
+ * can_mask: CAN mask (see description)
*
* Description:
* A filter matches, when
*
- * <received_can_id> & mask == can_id & mask
+ * <received_can_id> & mask == can_id & mask
*
* The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can
* filter for error message frames (CAN_ERR_FLAG bit set in mask).
*/
-struct can_filter {
- canid_t can_id;
- canid_t can_mask;
-};
-#define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
-#define CAN_RAW_FILTER_MAX 512 /* maximum number of can_filter set via setsockopt() */
+struct can_filter
+{
+ canid_t can_id;
+ canid_t can_mask;
+};
/************************************************************************************
* Public Function Prototypes
@@ -310,7 +311,6 @@ extern "C"
#define EXTERN extern
#endif
-
#undef EXTERN
#if defined(__cplusplus)
}
diff --git a/include/nuttx/mm/iob.h b/include/nuttx/mm/iob.h
index cabd2ff..5903c50 100644
--- a/include/nuttx/mm/iob.h
+++ b/include/nuttx/mm/iob.h
@@ -54,6 +54,7 @@
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
+
/* Configuration ************************************************************/
/* I/O buffer allocation logic supports a throttle value for read-ahead
diff --git a/include/sys/socket.h b/include/sys/socket.h
index bc7cd26..4cf40a7 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -131,7 +131,7 @@
/* Protocol levels supported by get/setsockopt(): */
-#define SOL_SOCKET 0 /* Only socket-level options supported */
+#define SOL_SOCKET 0 /* Only socket-level options supported */
/* Socket-level options */
@@ -202,13 +202,13 @@
* return: int
*/
-
/* The options are unsupported but included for compatibility
* and portability
*/
+
#define SO_TIMESTAMP 29
-#define SO_SNDBUFFORCE 32
-#define SO_RCVBUFFORCE 33
+#define SO_SNDBUFFORCE 32
+#define SO_RCVBUFFORCE 33
#define SO_RXQ_OVFL 40
/* Protocol-level socket operations. */
diff --git a/net/can/can.h b/net/can/can.h
index 46c7425..67c8d6f 100644
--- a/net/can/can.h
+++ b/net/can/can.h
@@ -85,26 +85,25 @@ struct can_conn_s
FAR struct devif_callback_s *list; /* NetLink callbacks */
FAR struct net_driver_s *dev; /* Reference to CAN device */
-
+
/* Read-ahead buffering.
*
* readahead - A singly linked list of type struct iob_qentry_s
* where the CAN/IP read-ahead data is retained.
*/
- struct iob_queue_s readahead; /* remove Read-ahead buffering */
+ struct iob_queue_s readahead; /* remove Read-ahead buffering */
/* CAN-specific content follows */
uint8_t protocol; /* Selected CAN protocol */
int16_t crefs; /* Reference count */
-
/* The following is a list of poll structures of threads waiting for
* socket events.
*/
- struct can_poll_s pollinfo[4]; //FIXME make dynamic
+ struct can_poll_s pollinfo[4]; /* FIXME make dynamic */
};
/****************************************************************************
@@ -223,9 +222,9 @@ uint16_t can_datahandler(FAR struct can_conn_s *conn, FAR uint8_t *buffer,
* Name: can_recvfrom
*
* Description:
- * Implements the socket recvfrom interface pkt_recvfrom() receives messages from
- * a socket, and may be used to receive data on a socket whether or not it
- * is connection-oriented.
+ * Implements the socket recvfrom interface pkt_recvfrom() receives
+ * messages from a socket, and may be used to receive data on a socket
+ * whether or not it is connection-oriented.
*
* Input Parameters:
* psock A pointer to a NuttX-specific, internal socket structure
@@ -315,7 +314,6 @@ ssize_t psock_can_send(FAR struct socket *psock, FAR const void *buf,
void can_readahead_signal(FAR struct can_conn_s *conn);
#endif
-
#undef EXTERN
#ifdef __cplusplus
}
diff --git a/net/can/can_callback.c b/net/can/can_callback.c
index 6f3ae93..c61bdce 100644
--- a/net/can/can_callback.c
+++ b/net/can/can_callback.c
@@ -1,35 +1,20 @@
/****************************************************************************
* net/pkt/pkt_callback.c
*
- * Copyright (C) 2014 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <gn...@nuttx.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
*
****************************************************************************/
@@ -72,17 +57,15 @@ can_data_event(FAR struct net_driver_s *dev, FAR struct can_conn_s *conn,
uint16_t flags)
{
uint16_t ret;
- uint8_t *buffer = dev->d_appdata;
- int buflen = dev->d_len;
+ FAR uint8_t *buffer = dev->d_appdata;
+ int buflen = dev->d_len;
uint16_t recvlen;
ret = (flags & ~CAN_NEWDATA);
- //ninfo("No listener on connection\n");
-
- /* Save as the packet data as in the read-ahead buffer. NOTE that
- * partial packets will not be buffered.
- */
+ /* Save as the packet data as in the read-ahead buffer. NOTE that
+ * partial packets will not be buffered.
+ */
recvlen = can_datahandler(conn, buffer, buflen);
if (recvlen < buflen)
@@ -94,10 +77,11 @@ can_data_event(FAR struct net_driver_s *dev, FAR struct can_conn_s *conn,
ninfo("Dropped %d bytes\n", dev->d_len);
#ifdef CONFIG_NET_STATISTICS
- //g_netstats.tcp.drop++;
+ /* g_netstats.tcp.drop++; */
+
#endif
}
-
+
/* In any event, the new data has now been handled */
dev->d_len = 0;
@@ -132,15 +116,15 @@ uint16_t can_callback(FAR struct net_driver_s *dev,
/* Perform the callback */
flags = devif_conn_event(dev, conn, flags, conn->list);
-
- if ((flags & CAN_NEWDATA) != 0)
- {
- /* Data was not handled.. dispose of it appropriately */
-
- flags = can_data_event(dev, conn, flags);
- }
- }
-
+
+ if ((flags & CAN_NEWDATA) != 0)
+ {
+ /* Data was not handled.. dispose of it appropriately */
+
+ flags = can_data_event(dev, conn, flags);
+ }
+ }
+
return flags;
}
@@ -214,7 +198,7 @@ uint16_t can_datahandler(FAR struct can_conn_s *conn, FAR uint8_t *buffer,
iob_free_chain(iob, IOBUSER_NET_TCP_READAHEAD);
return 0;
}
-
+
#ifdef CONFIG_NET_CAN_NOTIFIER
/* Provide notification(s) that additional CAN read-ahead data is
* available.
diff --git a/net/can/can_getsockopt.c b/net/can/can_getsockopt.c
index d9e19f8..1fe8218 100644
--- a/net/can/can_getsockopt.c
+++ b/net/can/can_getsockopt.c
@@ -1,35 +1,20 @@
/****************************************************************************
* net/can/can_setsockopt.c
*
- * Copyright (C) 2018 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <gn...@nuttx.org>
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
*
****************************************************************************/
@@ -89,10 +74,9 @@
*
****************************************************************************/
-int can_getsockopt (FAR struct socket *psock, int option,
+int can_getsockopt(FAR struct socket *psock, int option,
FAR void *value, FAR socklen_t *value_len)
{
-
FAR struct can_conn_s *conn;
int ret;
int count = 0;
@@ -107,38 +91,37 @@ int can_getsockopt (FAR struct socket *psock, int option,
return -ENOTCONN;
}
-
switch (option)
{
-
case CAN_RAW_FILTER:
if (*value_len % sizeof(struct can_filter) != 0)
- {
- ret = -EINVAL;
- }
-
+ {
+ ret = -EINVAL;
+ }
+
if (value_len > CAN_RAW_FILTER_MAX * sizeof(struct can_filter))
- {
- ret = -EINVAL;
- }
+ {
+ ret = -EINVAL;
+ }
+
+ count = *value_len / sizeof(struct can_filter);
- count = *value_len / sizeof(struct can_filter);
-
/* FIXME pass filter to driver */
+
break;
-
+
case CAN_RAW_ERR_FILTER:
break;
-
+
case CAN_RAW_LOOPBACK:
break;
-
+
case CAN_RAW_RECV_OWN_MSGS:
break;
-
+
case CAN_RAW_FD_FRAMES:
break;
-
+
case CAN_RAW_JOIN_FILTERS:
break;
diff --git a/net/can/can_input.c b/net/can/can_input.c
index 32dcebf..30e2507 100644
--- a/net/can/can_input.c
+++ b/net/can/can_input.c
@@ -2,39 +2,20 @@
* net/can/can_input.c
* Handling incoming packet input
*
- * Copyright (C) 2014, 2020 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <gn...@nuttx.org>
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
*
- * Adapted for NuttX from logic in uIP which also has a BSD-like license:
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Original author Adam Dunkels <ad...@dunkels.com>
- * Copyright () 2001-2003, Adam Dunkels.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
*
****************************************************************************/
@@ -55,11 +36,6 @@
#include "can/can.h"
/****************************************************************************
- * Pre-processor Definitions
- ****************************************************************************/
-
-
-/****************************************************************************
* Public Functions
****************************************************************************/
@@ -88,7 +64,7 @@ int can_input(struct net_driver_s *dev)
FAR struct can_conn_s *conn;
int ret = OK;
- conn = can_nextconn(NULL); //FIXME
+ conn = can_nextconn(NULL); /* FIXME */
if (conn)
{
uint16_t flags;
diff --git a/net/can/can_poll.c b/net/can/can_poll.c
index 80e59a2..77fe24c 100644
--- a/net/can/can_poll.c
+++ b/net/can/can_poll.c
@@ -2,39 +2,20 @@
* net/pkt/pkt_poll.c
* Poll for the availability of packet TX data
*
- * Copyright (C) 2014 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <gn...@nuttx.org>
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
*
- * Adapted for NuttX from logic in uIP which also has a BSD-like license:
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Original author Adam Dunkels <ad...@dunkels.com>
- * Copyright () 2001-2003, Adam Dunkels.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
- * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
- * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
*
****************************************************************************/
@@ -88,13 +69,15 @@ void can_poll(FAR struct net_driver_s *dev, FAR struct can_conn_s *conn)
dev->d_sndlen = 0;
/* Perform the application callback */
+
can_callback(dev, conn, CAN_POLL);
/* Check if the application has data to send */
if (dev->d_sndlen > 0)
{
- //FIXME missing logic
+ /* FIXME missing logic */
+
return;
}
}
diff --git a/net/can/can_recvfrom.c b/net/can/can_recvfrom.c
index 990786d..d2f71a6 100644
--- a/net/can/can_recvfrom.c
+++ b/net/can/can_recvfrom.c
@@ -1,36 +1,20 @@
/****************************************************************************
* net/can/can_recvfrom.c
*
- * Copyright (C) 2007-2009, 2011-2017, 2020 Gregory Nutt. All rights
- * reserved.
- * Author: Gregory Nutt <gn...@nuttx.org>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
*
****************************************************************************/
@@ -146,7 +130,6 @@ static size_t can_recvfrom_newdata(FAR struct net_driver_s *dev,
/* Copy the new packet data into the user buffer */
memcpy(pstate->pr_buffer, dev->d_buf, recvlen);
- //ninfo("Received %d bytes (of %d)\n", (int)recvlen, (int)dev->d_len);
/* Update the accumulated size of the data read */
@@ -155,7 +138,6 @@ static size_t can_recvfrom_newdata(FAR struct net_driver_s *dev,
return recvlen;
}
-
/****************************************************************************
* Name: can_newdata
*
@@ -187,7 +169,8 @@ static inline void can_newdata(FAR struct net_driver_s *dev,
if (recvlen < dev->d_len)
{
- FAR struct can_conn_s *conn = (FAR struct can_conn_s *)pstate->pr_sock->s_conn;
+ FAR struct can_conn_s *conn =
+ (FAR struct can_conn_s *)pstate->pr_sock->s_conn;
FAR uint8_t *buffer = (FAR uint8_t *)dev->d_appdata + recvlen;
uint16_t buflen = dev->d_len - recvlen;
#ifdef CONFIG_DEBUG_NET
@@ -249,8 +232,8 @@ static inline int can_readahead(struct can_recvfrom_s *pstate)
* buffer.
*/
- if((iob = iob_peek_queue(&conn->readahead)) != NULL &&
- pstate->pr_buflen > 0)
+ if ((iob = iob_peek_queue(&conn->readahead)) != NULL &&
+ pstate->pr_buflen > 0)
{
DEBUGASSERT(iob->io_pktlen > 0);
@@ -292,9 +275,11 @@ static inline int can_readahead(struct can_recvfrom_s *pstate)
iob_trimhead_queue(&conn->readahead, recvlen,
IOBUSER_NET_CAN_READAHEAD);
}
- return recvlen;
+
+ return recvlen;
}
- return 0;
+
+ return 0;
}
static uint16_t can_recvfrom_eventhandler(FAR struct net_driver_s *dev,
@@ -303,8 +288,6 @@ static uint16_t can_recvfrom_eventhandler(FAR struct net_driver_s *dev,
{
struct can_recvfrom_s *pstate = (struct can_recvfrom_s *)pvpriv;
- //ninfo("flags: %04x\n", flags);
-
/* 'priv' might be null in some race conditions (?) */
if (pstate)
@@ -319,17 +302,17 @@ static uint16_t can_recvfrom_eventhandler(FAR struct net_driver_s *dev,
/* We are finished. */
- //ninfo("CAN done\n");
-
/* Don't allow any further call backs. */
pstate->pr_cb->flags = 0;
pstate->pr_cb->priv = NULL;
pstate->pr_cb->event = NULL;
+#if 0
/* Save the sender's address in the caller's 'from' location */
- //pkt_recvfrom_sender(dev, pstate);
+ pkt_recvfrom_sender(dev, pstate);
+#endif
/* indicate that the data has been consumed */
@@ -429,16 +412,15 @@ ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf,
(fromlen != NULL && *fromlen >= sizeof(struct sockaddr_can)));
conn = (FAR struct can_conn_s *)psock->s_conn;
-
+
if (psock->s_type != SOCK_RAW)
{
nerr("ERROR: Unsupported socket type: %d\n", psock->s_type);
ret = -ENOSYS;
}
-
-
+
net_lock();
-
+
/* Initialize the state structure. */
memset(&state, 0, sizeof(struct can_recvfrom_s));
@@ -453,19 +435,20 @@ ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf,
state.pr_buflen = len;
state.pr_buffer = buf;
state.pr_sock = psock;
-
+
/* Handle any any CAN data already buffered in a read-ahead buffer. NOTE
* that there may be read-ahead data to be retrieved even after the
* socket has been disconnected.
*/
+
ret = can_readahead(&state);
- if(ret > 0)
- {
+ if (ret > 0)
+ {
net_unlock();
nxsem_destroy(&state.pr_sem);
return ret;
- }
-
+ }
+
/* Get the device driver that will service this transfer */
dev = conn->dev;
@@ -474,7 +457,7 @@ ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf,
ret = -ENODEV;
goto errout_with_state;
}
-
+
/* Set up the callback in the connection */
state.pr_cb = can_callback_alloc(dev, conn);
@@ -502,7 +485,6 @@ ssize_t can_recvfrom(FAR struct socket *psock, FAR void *buf,
ret = -EBUSY;
}
-
errout_with_state:
net_unlock();
nxsem_destroy(&state.pr_sem);
diff --git a/net/can/can_setsockopt.c b/net/can/can_setsockopt.c
index db4cb76..2d117a8 100644
--- a/net/can/can_setsockopt.c
+++ b/net/can/can_setsockopt.c
@@ -1,35 +1,20 @@
/****************************************************************************
* net/can/can_setsockopt.c
*
- * Copyright (C) 2018, 2020 Gregory Nutt. All rights reserved.
- * Author: Gregory Nutt <gn...@nuttx.org>
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership. The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License. You may obtain a copy of the License at
*
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in
- * the documentation and/or other materials provided with the
- * distribution.
- * 3. Neither the name NuttX nor the names of its contributors may be
- * used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
- * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
*
****************************************************************************/
@@ -87,7 +72,6 @@
int can_setsockopt(FAR struct socket *psock, int option,
FAR const void *value, socklen_t value_len)
{
-
FAR struct can_conn_s *conn;
int ret;
int count = 0;
@@ -101,37 +85,37 @@ int can_setsockopt(FAR struct socket *psock, int option,
return -ENOTCONN;
}
-
switch (option)
{
case CAN_RAW_FILTER:
if (value_len % sizeof(struct can_filter) != 0)
- {
- ret = -EINVAL;
- }
-
+ {
+ ret = -EINVAL;
+ }
+
if (value_len > CAN_RAW_FILTER_MAX * sizeof(struct can_filter))
- {
- ret = -EINVAL;
- }
+ {
+ ret = -EINVAL;
+ }
+
+ count = value_len / sizeof(struct can_filter);
- count = value_len / sizeof(struct can_filter);
-
/* FIXME pass filter to driver */
+
break;
-
+
case CAN_RAW_ERR_FILTER:
break;
-
+
case CAN_RAW_LOOPBACK:
break;
-
+
case CAN_RAW_RECV_OWN_MSGS:
break;
-
+
case CAN_RAW_FD_FRAMES:
break;
-
+
case CAN_RAW_JOIN_FILTERS:
break;
diff --git a/net/can/can_sockif.c b/net/can/can_sockif.c
index 5c8415e..573ddd8 100644
--- a/net/can/can_sockif.c
+++ b/net/can/can_sockif.c
@@ -96,7 +96,6 @@ const struct sock_intf_s g_can_sockif =
can_close /* si_close */
};
-
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -149,12 +148,14 @@ static uint16_t can_poll_eventhandler(FAR struct net_driver_s *dev,
eventset |= (POLLHUP | POLLERR);
}
+#if 0
/* A poll is a sign that we are free to send data. */
- /* else if ((flags & CAN_POLL) != 0 && psock_udp_cansend(info->psock) >= 0)
+ else if ((flags & CAN_POLL) != 0 && psock_udp_cansend(info->psock) >= 0)
{
eventset |= (POLLOUT & info->fds->events);
- }*/
+ }
+#endif
/* Awaken the caller of poll() is requested event occurred. */
@@ -326,23 +327,23 @@ static void can_addref(FAR struct socket *psock)
****************************************************************************/
static int can_bind(FAR struct socket *psock,
- FAR const struct sockaddr *addr, socklen_t addrlen)
+ FAR const struct sockaddr *addr, socklen_t addrlen)
{
FAR struct sockaddr_can *canaddr;
FAR struct can_conn_s *conn;
+ char netdev_name[6];
DEBUGASSERT(psock != NULL && psock->s_conn != NULL && addr != NULL &&
addrlen >= sizeof(struct sockaddr_can));
/* Save the address information in the connection structure */
- canaddr = (FAR struct sockaddr_can *)addr;
- conn = (FAR struct can_conn_s *)psock->s_conn;
+ canaddr = (FAR struct sockaddr_can *)addr;
+ conn = (FAR struct can_conn_s *)psock->s_conn;
/* Bind CAN device to socket */
- //TODO better support for CONFIG_NETDEV_IFINDEX
- char netdev_name[6];
+ /* TODO better support for CONFIG_NETDEV_IFINDEX */
sprintf(netdev_name, "can%i", canaddr->can_ifindex);
@@ -374,8 +375,8 @@ static int can_bind(FAR struct socket *psock,
****************************************************************************/
static int can_getsockname(FAR struct socket *psock,
- FAR struct sockaddr *addr,
- FAR socklen_t *addrlen)
+ FAR struct sockaddr *addr,
+ FAR socklen_t *addrlen)
{
FAR struct sockaddr_can *canaddr;
@@ -430,8 +431,8 @@ static int can_getsockname(FAR struct socket *psock,
****************************************************************************/
static int can_getpeername(FAR struct socket *psock,
- FAR struct sockaddr *addr,
- FAR socklen_t *addrlen)
+ FAR struct sockaddr *addr,
+ FAR socklen_t *addrlen)
{
#warning Missing logic
return -EOPNOTSUPP; /* Or maybe return -EAFNOSUPPORT; */
@@ -488,8 +489,8 @@ static int can_listen(FAR struct socket *psock, int backlog)
****************************************************************************/
static int can_connect(FAR struct socket *psock,
- FAR const struct sockaddr *addr,
- socklen_t addrlen)
+ FAR const struct sockaddr *addr,
+ socklen_t addrlen)
{
#warning Missing logic
return -EOPNOTSUPP;
@@ -540,7 +541,7 @@ static int can_connect(FAR struct socket *psock,
****************************************************************************/
static int can_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
- FAR socklen_t *addrlen, FAR struct socket *newsock)
+ FAR socklen_t *addrlen, FAR struct socket *newsock)
{
#warning Missing logic
return -EOPNOTSUPP;
@@ -570,7 +571,7 @@ static int can_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
****************************************************************************/
static int can_poll_local(FAR struct socket *psock, FAR struct pollfd *fds,
- bool setup)
+ bool setup)
{
FAR struct can_conn_s *conn;
FAR struct can_poll_s *info;
@@ -580,18 +581,17 @@ static int can_poll_local(FAR struct socket *psock, FAR struct pollfd *fds,
DEBUGASSERT(psock != NULL && psock->s_conn != NULL);
conn = (FAR struct can_conn_s *)psock->s_conn;
info = conn->pollinfo;
-
- //FIXME add NETDEV_DOWN support
+
+ /* FIXME add NETDEV_DOWN support */
/* Check if we are setting up or tearing down the poll */
if (setup)
{
-
net_lock();
-
+
info->dev = conn->dev;
-
+
cb = can_callback_alloc(info->dev, conn);
if (cb == NULL)
{
@@ -600,82 +600,84 @@ static int can_poll_local(FAR struct socket *psock, FAR struct pollfd *fds,
}
/* Initialize the poll info container */
-
+
info->psock = psock;
info->fds = fds;
info->cb = cb;
-
+
/* Initialize the callback structure. Save the reference to the info
* structure as callback private data so that it will be available during
* callback processing.
*/
-
+
cb->flags = NETDEV_DOWN;
cb->priv = (FAR void *)info;
cb->event = can_poll_eventhandler;
-
+
if ((fds->events & POLLOUT) != 0)
{
cb->flags |= CAN_POLL;
}
-
+
if ((fds->events & POLLIN) != 0)
{
cb->flags |= CAN_NEWDATA;
}
-
+
/* Save the reference in the poll info structure as fds private as well
* for use during poll teardown as well.
*/
-
+
fds->priv = (FAR void *)info;
-
+
/* Check for read data availability now */
-
+
if (!IOB_QEMPTY(&conn->readahead))
{
/* Normal data may be read without blocking. */
-
+
fds->revents |= (POLLRDNORM & fds->events);
}
-
+
#if 0
if (psock_udp_cansend(psock) >= 0)
{
/* Normal data may be sent without blocking (at least one byte). */
-
+
fds->revents |= (POLLWRNORM & fds->events);
}
#endif
-
+
/* Check if any requested events are already in effect */
-
+
if (fds->revents != 0)
{
/* Yes.. then signal the poll logic */
+
nxsem_post(fds->sem);
}
-
+
errout_with_lock:
net_unlock();
}
- else
+ else
{
info = (FAR struct can_poll_s *)fds->priv;
-
+
if (info != NULL)
- {
- /* Cancel any response notifications */
- can_callback_free(info->dev, conn, info->cb);
+ {
+ /* Cancel any response notifications */
+
+ can_callback_free(info->dev, conn, info->cb);
- /* Release the poll/select data slot */
+ /* Release the poll/select data slot */
- info->fds->priv = NULL;
+ info->fds->priv = NULL;
- /* Then free the poll info container */
+ /* Then free the poll info container */
- info->psock = NULL;
- }
+ info->psock = NULL;
+ }
}
return ret;
@@ -702,27 +704,28 @@ errout_with_lock:
****************************************************************************/
static ssize_t can_send(FAR struct socket *psock, FAR const void *buf,
- size_t len, int flags)
+ size_t len, int flags)
{
- ssize_t ret;
+ ssize_t ret;
- /* Only SOCK_RAW is supported */
+ /* Only SOCK_RAW is supported */
- if (psock->s_type == SOCK_RAW)
- {
- /* Raw packet send */
- ret = psock_can_send(psock, buf, len);
- }
- else
- {
- /* EDESTADDRREQ. Signifies that the socket is not connection-mode and
- * no peer address is set.
- */
+ if (psock->s_type == SOCK_RAW)
+ {
+ /* Raw packet send */
- ret = -EDESTADDRREQ;
- }
+ ret = psock_can_send(psock, buf, len);
+ }
+ else
+ {
+ /* EDESTADDRREQ. Signifies that the socket is not connection-mode and
+ * no peer address is set.
+ */
+
+ ret = -EDESTADDRREQ;
+ }
- return ret;
+ return ret;
}
/****************************************************************************
@@ -750,11 +753,11 @@ static ssize_t can_send(FAR struct socket *psock, FAR const void *buf,
****************************************************************************/
static ssize_t can_sendto(FAR struct socket *psock, FAR const void *buf,
- size_t len, int flags,
- FAR const struct sockaddr *to, socklen_t tolen)
+ size_t len, int flags,
+ FAR const struct sockaddr *to, socklen_t tolen)
{
- nerr("ERROR: sendto() not supported for raw packet sockets\n");
- return -EAFNOSUPPORT;
+ nerr("ERROR: sendto() not supported for raw packet sockets\n");
+ return -EAFNOSUPPORT;
}
/****************************************************************************
diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c
index bc07a03..6d71106 100644
--- a/net/socket/getsockopt.c
+++ b/net/socket/getsockopt.c
@@ -376,7 +376,7 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option,
ret = can_getsockopt(psock, option, value, value_len);
#endif
break;
-
+
/* These levels are defined in sys/socket.h, but are not yet
* implemented.
*/