can: Merge netpacket/can.h into nuttx/can.h

To align with the layout of Linux can header file.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2024-04-06 00:49:46 +08:00 committed by Petro Karashchenko
parent 7abd460131
commit fcb3e84c24
17 changed files with 188 additions and 208 deletions

View file

@ -38,10 +38,8 @@
#include <nuttx/arch.h>
#include <nuttx/wqueue.h>
#include <nuttx/can.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/can.h>
#include <netpacket/can.h>
#include "arm_internal.h"
#include "chip.h"

View file

@ -33,7 +33,6 @@
#include <debug.h>
#include <errno.h>
#include <nuttx/can.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/wqueue.h>
@ -857,9 +856,11 @@ static void imxrt_receive(struct imxrt_driver_s *priv,
/* Read the frame contents */
#ifdef CONFIG_NET_CAN_CANFD
if (rf->cs.edl) /* CAN FD frame */
if (rf->cs.edl)
{
struct canfd_frame *frame = (struct canfd_frame *)priv->rxdesc_fd;
/* CAN FD frame */
struct canfd_frame *frame = (struct canfd_frame *)priv->rxdesc_fd;
if (rf->cs.ide)
{
@ -897,10 +898,12 @@ static void imxrt_receive(struct imxrt_driver_s *priv,
priv->dev.d_len = sizeof(struct canfd_frame);
priv->dev.d_buf = (uint8_t *)frame;
}
else /* CAN 2.0 Frame */
else
#endif
{
struct can_frame *frame = (struct can_frame *)priv->rxdesc;
/* CAN 2.0 Frame */
struct can_frame *frame = (struct can_frame *)priv->rxdesc;
if (rf->cs.ide)
{

View file

@ -33,7 +33,6 @@
#include <debug.h>
#include <errno.h>
#include <nuttx/can.h>
#include <nuttx/wdog.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
@ -857,9 +856,11 @@ static void kinetis_receive(struct kinetis_driver_s *priv,
/* Read the frame contents */
#ifdef CONFIG_NET_CAN_CANFD
if (rf->cs.edl) /* CAN FD frame */
if (rf->cs.edl)
{
struct canfd_frame *frame = (struct canfd_frame *)priv->rxdesc;
/* CAN FD frame */
struct canfd_frame *frame = (struct canfd_frame *)priv->rxdesc;
if (rf->cs.ide)
{
@ -897,10 +898,12 @@ static void kinetis_receive(struct kinetis_driver_s *priv,
priv->dev.d_len = sizeof(struct canfd_frame);
priv->dev.d_buf = (uint8_t *)frame;
}
else /* CAN 2.0 Frame */
else
#endif
{
struct can_frame *frame = (struct can_frame *)priv->rxdesc;
/* CAN 2.0 Frame */
struct can_frame *frame = (struct can_frame *)priv->rxdesc;
if (rf->cs.ide)
{

View file

@ -76,7 +76,6 @@
#endif
#if defined(SOCKET_CAN)
# include <nuttx/can.h>
# include <nuttx/net/netdev.h>
# include <nuttx/net/can.h>
# include <nuttx/wqueue.h>

View file

@ -33,7 +33,6 @@
#include <debug.h>
#include <errno.h>
#include <nuttx/can.h>
#include <nuttx/wdog.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
@ -861,9 +860,11 @@ static void s32k1xx_receive(struct s32k1xx_driver_s *priv,
/* Read the frame contents */
#ifdef CONFIG_NET_CAN_CANFD
if (rf->cs.edl) /* CAN FD frame */
if (rf->cs.edl)
{
struct canfd_frame *frame = (struct canfd_frame *)priv->rxdesc;
/* CAN FD frame */
struct canfd_frame *frame = (struct canfd_frame *)priv->rxdesc;
if (rf->cs.ide)
{
@ -901,10 +902,12 @@ static void s32k1xx_receive(struct s32k1xx_driver_s *priv,
priv->dev.d_len = sizeof(struct canfd_frame);
priv->dev.d_buf = (uint8_t *)frame;
}
else /* CAN 2.0 Frame */
else
#endif
{
struct can_frame *frame = (struct can_frame *)priv->rxdesc;
/* CAN 2.0 Frame */
struct can_frame *frame = (struct can_frame *)priv->rxdesc;
if (rf->cs.ide)
{

View file

@ -35,7 +35,6 @@
#include <debug.h>
#include <errno.h>
#include <nuttx/can.h>
#include <nuttx/wdog.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
@ -1021,9 +1020,11 @@ static void s32k3xx_receive(struct s32k3xx_driver_s *priv, uint32_t flags)
/* Read the frame contents */
#ifdef CONFIG_NET_CAN_CANFD
if (rf->cs.edl) /* CAN FD frame */
if (rf->cs.edl)
{
struct canfd_frame *frame = (struct canfd_frame *)priv->rxdesc;
/* CAN FD frame */
struct canfd_frame *frame = (struct canfd_frame *)priv->rxdesc;
if (rf->cs.ide)
{

View file

@ -38,10 +38,8 @@
#include <nuttx/arch.h>
#include <nuttx/wqueue.h>
#include <nuttx/can.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/can.h>
#include <netpacket/can.h>
#include "arm_internal.h"
#include "chip.h"

View file

@ -38,10 +38,8 @@
#include <nuttx/arch.h>
#include <nuttx/wqueue.h>
#include <nuttx/can.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/can.h>
#include <netpacket/can.h>
#include "arm_internal.h"
#include "stm32_fdcan.h"

View file

@ -38,10 +38,8 @@
#include <nuttx/arch.h>
#include <nuttx/wqueue.h>
#include <nuttx/can.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/can.h>
#include <netpacket/can.h>
#include "arm_internal.h"
#include "chip.h"

View file

@ -33,7 +33,6 @@
#include <debug.h>
#include <errno.h>
#include <nuttx/can.h>
#include <nuttx/wdog.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
@ -41,7 +40,6 @@
#include <nuttx/signal.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/can.h>
#include <netpacket/can.h>
#if defined(CONFIG_NET_CAN_RAW_TX_DEADLINE) || defined(CONFIG_NET_TIMESTAMP)
#include <sys/time.h>
@ -1142,8 +1140,10 @@ static void fdcan_receive_work(void *arg)
/* Read the frame contents */
#ifdef CONFIG_NET_CAN_CANFD
if (rf->header.fdf) /* CAN FD frame */
if (rf->header.fdf)
{
/* CAN FD frame */
struct canfd_frame *frame = (struct canfd_frame *)priv->rx_pool;
if (rf->header.id.xtd)
@ -1181,9 +1181,11 @@ static void fdcan_receive_work(void *arg)
priv->dev.d_len = sizeof(struct canfd_frame);
priv->dev.d_buf = (uint8_t *)frame;
}
else /* CAN 2.0 Frame */
else
#endif
{
/* CAN 2.0 Frame */
struct can_frame *frame = (struct can_frame *)priv->rx_pool;
if (rf->header.id.xtd)

View file

@ -41,10 +41,8 @@
#include <nuttx/arch.h>
#include <nuttx/wqueue.h>
#include <nuttx/can.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/can.h>
#include <netpacket/can.h>
#include "arm_internal.h"
#include "chip.h"

View file

@ -39,7 +39,6 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <nuttx/can.h>
#include <netpacket/can.h>
#include <nuttx/signal.h>
#include "s32k3xx_pin.h"

View file

@ -1,160 +0,0 @@
/****************************************************************************
* include/netpacket/can.h
* Definitions for use with AF_PACKET sockets
*
* 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.
*
****************************************************************************/
#ifndef __INCLUDE_NETPACKET_CAN_H
#define __INCLUDE_NETPACKET_CAN_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Special address description flags for the CAN_ID */
#define CAN_EFF_FLAG 0x80000000 /* EFF/SFF is set in the MSB */
#define CAN_RTR_FLAG 0x40000000 /* Remote transmission request */
#define CAN_ERR_FLAG 0x20000000 /* Error message frame */
/* Valid bits in CAN ID for frame formats */
#define CAN_SFF_MASK 0x000007ff /* Standard frame format (SFF) */
#define CAN_EFF_MASK 0x1fffffff /* Extended frame format (EFF) */
#define CAN_ERR_MASK 0x1fffffff /* Omit EFF, RTR, ERR flags */
#define CAN_MTU (sizeof(struct can_frame))
#define CANFD_MTU (sizeof(struct canfd_frame))
/* PF_CAN protocols */
#define CAN_RAW 1 /* RAW sockets */
#define CAN_BCM 2 /* Broadcast Manager */
#define CAN_TP16 3 /* VAG Transport Protocol v1.6 */
#define CAN_TP20 4 /* VAG Transport Protocol v2.0 */
#define CAN_MCNET 5 /* Bosch MCNet */
#define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */
#define CAN_J1939 7 /* SAE J1939 */
#define CAN_NPROTO 8
#define SOL_CAN_BASE 100
#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
/* CAN_RAW socket options */
#define CAN_RAW_FILTER (__SO_PROTOCOL + 0)
/* set 0 .. n can_filter(s) */
#define CAN_RAW_ERR_FILTER (__SO_PROTOCOL + 1)
/* set filter for error frames */
#define CAN_RAW_LOOPBACK (__SO_PROTOCOL + 2)
/* local loopback (default:on) */
#define CAN_RAW_RECV_OWN_MSGS (__SO_PROTOCOL + 3)
/* receive my own msgs (default:off) */
#define CAN_RAW_FD_FRAMES (__SO_PROTOCOL + 4)
/* allow CAN FD frames (default:off) */
#define CAN_RAW_JOIN_FILTERS (__SO_PROTOCOL + 5)
/* all filters must match to trigger */
#define CAN_RAW_TX_DEADLINE (__SO_PROTOCOL + 6)
/* Abort frame when deadline passed */
/* CAN filter support (Hardware level filtering) ****************************/
/* Some CAN hardware supports a notion of prioritizing messages that match
* filters. Only two priority levels are currently supported and are encoded
* as defined below:
*/
#define CAN_MSGPRIO_LOW 0
#define CAN_MSGPRIO_HIGH 1
/* Filter type. Not all CAN hardware will support all filter types. */
#define CAN_FILTER_MASK 0 /* Address match under a mask */
#define CAN_FILTER_DUAL 1 /* Dual address match */
#define CAN_FILTER_RANGE 2 /* Match a range of addresses */
/****************************************************************************
* Public Types
****************************************************************************/
/* Controller Area Network Identifier structure
*
* Bit 0-28: CAN identifier (11/29 bit)
* Bit 29: Error message frame flag (0 = data frame, 1 = error message)
* Bit 30: Remote transmission request flag (1 = rtr frame)
* Bit 31: Frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
*/
typedef uint32_t canid_t;
/* The sockaddr structure for CAN sockets
*
* can_family: Address family number AF_CAN.
* can_ifindex: CAN network interface index.
* can_addr: Protocol specific address information
*/
struct sockaddr_can
{
sa_family_t can_family;
int16_t can_ifindex;
union
{
/* Transport protocol class address information */
struct
{
canid_t rx_id;
canid_t tx_id;
} tp;
/* J1939 address information */
struct
{
/* 8 byte name when using dynamic addressing */
uint64_t name;
/* pgn:
* 8 bit: PS in PDU2 case, else 0
* 8 bit: PF
* 1 bit: DP
* 1 bit: reserved
*/
uint32_t pgn;
/* 1 byte address */
uint8_t addr;
} j1939;
} can_addr;
};
#endif /* __INCLUDE_NETPACKET_CAN_H */

View file

@ -27,6 +27,8 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdint.h>
#ifdef CONFIG_NET_CAN
@ -35,6 +37,25 @@
* Pre-processor Definitions
****************************************************************************/
/* Special address description flags for the CAN_ID */
#define CAN_EFF_FLAG 0x80000000 /* EFF/SFF is set in the MSB */
#define CAN_RTR_FLAG 0x40000000 /* Remote transmission request */
#define CAN_ERR_FLAG 0x20000000 /* Error message frame */
#define CAN_EVT_FLAG 0x10000000 /* Lower_half use this flags to report state switch event */
/* Valid bits in CAN ID for frame formats */
#define CAN_SFF_MASK 0x000007ff /* Standard frame format (SFF) */
#define CAN_EFF_MASK 0x1fffffff /* Extended frame format (EFF) */
#define CAN_ERR_MASK 0x1fffffff /* Omit EFF, RTR, ERR flags */
#define CAN_SFF_ID_BITS 11
#define CAN_EFF_ID_BITS 29
#define CAN_MTU (sizeof(struct can_frame))
#define CANFD_MTU (sizeof(struct canfd_frame))
/* CAN payload length and DLC definitions according to ISO 11898-1 */
#define CAN_MAX_DLC 8
@ -63,10 +84,58 @@
* frames.
*/
#define CANFD_BRS 0x01 /* bit rate switch (second bitrate for payload data) */
#define CANFD_ESI 0x02 /* error state indicator of the transmitting node */
#define CANFD_BRS 0x01 /* Bit rate switch (second bitrate for payload data) */
#define CANFD_ESI 0x02 /* Error state indicator of the transmitting node */
#define CANFD_FDF 0x04 /* Mark CAN FD for dual use of struct canfd_frame */
#define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
#define CAN_INV_FILTER 0x20000000u /* To be set in can_filter.can_id */
/* PF_CAN protocols */
#define CAN_RAW 1 /* RAW sockets */
#define CAN_BCM 2 /* Broadcast Manager */
#define CAN_TP16 3 /* VAG Transport Protocol v1.6 */
#define CAN_TP20 4 /* VAG Transport Protocol v2.0 */
#define CAN_MCNET 5 /* Bosch MCNet */
#define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */
#define CAN_J1939 7 /* SAE J1939 */
#define CAN_NPROTO 8
#define SOL_CAN_BASE 100
#define SOL_CAN_RAW (SOL_CAN_BASE + CAN_RAW)
/* CAN_RAW socket options */
#define CAN_RAW_FILTER (__SO_PROTOCOL + 0)
/* Set 0 .. n can_filter(s) */
#define CAN_RAW_ERR_FILTER (__SO_PROTOCOL + 1)
/* Set filter for error frames */
#define CAN_RAW_LOOPBACK (__SO_PROTOCOL + 2)
/* Local loopback (default:on) */
#define CAN_RAW_RECV_OWN_MSGS (__SO_PROTOCOL + 3)
/* Receive my own msgs (default:off) */
#define CAN_RAW_FD_FRAMES (__SO_PROTOCOL + 4)
/* Allow CAN FD frames (default:off) */
#define CAN_RAW_JOIN_FILTERS (__SO_PROTOCOL + 5)
/* All filters must match to trigger */
#define CAN_RAW_TX_DEADLINE (__SO_PROTOCOL + 6)
/* Abort frame when deadline passed */
/* CAN filter support (Hardware level filtering) ****************************/
/* Some CAN hardware supports a notion of prioritizing messages that match
* filters. Only two priority levels are currently supported and are encoded
* as defined below:
*/
#define CAN_MSGPRIO_LOW 0
#define CAN_MSGPRIO_HIGH 1
/* Filter type. Not all CAN hardware will support all filter types. */
#define CAN_FILTER_MASK 0 /* Address match under a mask */
#define CAN_FILTER_DUAL 1 /* Dual address match */
#define CAN_FILTER_RANGE 2 /* Match a range of addresses */
/* CAN Error Indications ****************************************************/
@ -143,12 +212,43 @@
/* Data[4]: Error status of CAN-transceiver */
#define CAN_ERR_TRX_UNSPEC 0x00 /* Unspecified error */
#define CAN_ERR_TRX_UNSPEC 0x00 /* Unspecified error */
#define CAN_ERR_TRX_CANH_NO_WIRE 0x04
#define CAN_ERR_TRX_CANH_SHORT_TO_BAT 0x05
#define CAN_ERR_TRX_CANH_SHORT_TO_VCC 0x06
#define CAN_ERR_TRX_CANH_SHORT_TO_GND 0x07
#define CAN_ERR_TRX_CANL_NO_WIRE 0x40
#define CAN_ERR_TRX_CANL_SHORT_TO_BAT 0x50
#define CAN_ERR_TRX_CANL_SHORT_TO_VCC 0x60
#define CAN_ERR_TRX_CANL_SHORT_TO_GND 0x70
#define CAN_ERR_TRX_CANL_SHORT_TO_CANH 0x80
/* CAN state thresholds
*
* Error counter Error state
* -----------------------------------
* 0 - 95 Error-active
* 96 - 127 Error-warning
* 128 - 255 Error-passive
* 256 and greater Bus-off
*/
#define CAN_ERROR_WARNING_THRESHOLD 96
#define CAN_ERROR_PASSIVE_THRESHOLD 128
#define CAN_BUS_OFF_THRESHOLD 256
/****************************************************************************
* Public Types
****************************************************************************/
/* Controller Area Network Identifier structure
*
* bit 0-28: CAN identifier (11/29 bit)
* bit 29: error message frame flag (0 = data frame, 1 = error message)
* bit 30: remote transmission request flag (1 = rtr frame)
* bit 31: frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
*/
typedef uint32_t canid_t;
/* Controller Area Network Error Message Frame Mask structure
@ -199,8 +299,53 @@ struct canfd_frame
uint8_t data[CANFD_MAX_DLEN];
};
/* The sockaddr structure for CAN sockets
*
* can_family: Address family number AF_CAN.
* can_ifindex: CAN network interface index.
* can_addr: Protocol specific address information
*/
struct sockaddr_can
{
sa_family_t can_family;
int16_t can_ifindex;
union
{
/* Transport protocol class address information */
struct
{
canid_t rx_id;
canid_t tx_id;
} tp;
/* J1939 address information */
struct
{
/* 8 byte name when using dynamic addressing */
uint64_t name;
/* pgn:
* 8 bit: PS in PDU2 case, else 0
* 8 bit: PF
* 1 bit: DP
* 1 bit: reserved
*/
uint32_t pgn;
/* 1 byte address */
uint8_t addr;
} j1939;
} can_addr;
};
/* struct can_filter - CAN ID based filter in can_register().
* can_id: relevant bits of CAN ID which are not masked out.
* can_id: Relevant bits of CAN ID which are not masked out.
* can_mask: CAN mask (see description)
*
* Description:

View file

@ -30,7 +30,6 @@
#include <sys/types.h>
#include <poll.h>
#include <netpacket/can.h>
#include <nuttx/semaphore.h>
#include <nuttx/can.h>
#include <nuttx/net/net.h>
@ -374,7 +373,7 @@ void can_readahead_signal(FAR struct can_conn_s *conn);
* 'option' argument to the value pointed to by the 'value' argument for
* the socket specified by the 'psock' argument.
*
* See <netinet/can.h> for the a complete list of values of CAN protocol
* See <nuttx/can.h> for the a complete list of values of CAN protocol
* options.
*
* Input Parameters:
@ -409,7 +408,7 @@ int can_setsockopt(FAR struct socket *psock, int level, int option,
*
* See <sys/socket.h> a complete list of values for the socket-level
* 'option' argument. Protocol-specific options are are protocol specific
* header files (such as netpacket/can.h for the case of the CAN protocol).
* header files (such as nuttx/can.h for the case of the CAN protocol).
*
* Input Parameters:
* psock Socket structure of the socket to query

View file

@ -30,8 +30,6 @@
#include <assert.h>
#include <debug.h>
#include <netpacket/can.h>
#include <nuttx/net/net.h>
#include <nuttx/net/can.h>
@ -58,7 +56,7 @@
*
* See <sys/socket.h> a complete list of values for the socket-level
* 'option' argument. Protocol-specific options are are protocol specific
* header files (such as netpacket/can.h for the case of the CAN protocol).
* header files (such as nuttx/can.h for the case of the CAN protocol).
*
* Input Parameters:
* psock Socket structure of the socket to query

View file

@ -30,8 +30,6 @@
#include <assert.h>
#include <debug.h>
#include <netpacket/can.h>
#include <nuttx/net/net.h>
#include <nuttx/net/can.h>
@ -53,7 +51,7 @@
* 'option' argument to the value pointed to by the 'value' argument for
* the socket specified by the 'psock' argument.
*
* See <netinet/can.h> for the a complete list of values of CAN protocol
* See <nuttx/can.h> for the a complete list of values of CAN protocol
* options.
*
* Input Parameters: