Skip to content

Commit

Permalink
add lin status changes the format of the reported frame and add the m…
Browse files Browse the repository at this point in the history
…acros that lin needs

Signed-off-by: wangxiaoxin <[email protected]>
  • Loading branch information
wangxiaoxin1 authored and GUIDINGLI committed Oct 15, 2024
1 parent d22ad37 commit 366ede9
Showing 1 changed file with 45 additions and 21 deletions.
66 changes: 45 additions & 21 deletions include/nuttx/lin.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <nuttx/config.h>
#include <nuttx/can.h>

#ifdef CONFIG_NET_CAN

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
Expand All @@ -38,37 +40,49 @@
#define LIN_ID_MASK ((1 << LIN_ID_BITS) - 1)
#define LIN_ID_MAX LIN_ID_MASK

#define LIN_CTRL_FRAME CAN_EFF_FLAG
#define LIN_CTRL_FLAG CAN_EFF_FLAG /* Describe control information(such as wirte et.) */
#define LIN_RTR_FLAG CAN_RTR_FLAG /* Describe the direction of sending and receiving */
#define LIN_ERR_FLAG CAN_ERR_FLAG /* The flag indicate this is LIN err_frame */

/* When slave response to master, slave node should send frame immediately
* which already be cached in last transmission in case of response interval
* over time;
/* Bit flags on can_frame.types
*
* Use can_frame.types to identify other special frame.
*
* LIN_TCF_FLAG : TxConfirmation message frame. Lower_half use this flag to
* confirm frame-transmit
*
* LIN_EVT_FLAG : Event message frame. Lower_half use this flag to report
* state switch event
*
* LIN_CACHE_RESP_FLAG: When slave response to master, slave node should send
* frame immediately which already be cached in last
* transmission in case of response interval over time.
*
* LIN_CHKSUM_EXT_FLAG: LIN checksum have two types, default type will be
* classic checksum
*
* LIN_SINGLE_RESP_FLAG: Cache LIN frame only work once, then will be cleared
*/

#define LIN_CACHE_RESPONSE (1 << (LIN_ID_BITS))

/* LIN checksum have two types, default type will be classic checksum */

#define LIN_CHECKSUM_EXTENDED (1 << (LIN_ID_BITS + 1))

/* Cache LIN frame only work once. then will be clear */

#define LIN_SINGLE_RESPONSE (1 << (LIN_ID_BITS + 2))
#define LIN_TCF_FLAG CAN_TCF_FLAG
#define LIN_EVT_FLAG CAN_EVT_FLAG
#define LIN_CACHE_RESP_FLAG (1 << (CANFD_FLAGS_BITS + 2))
#define LIN_CHKSUM_EXT_FLAG (1 << (CANFD_FLAGS_BITS + 3))
#define LIN_SINGLE_RESP_FLAG (1 << (CANFD_FLAGS_BITS + 4))

/* LIN Error Indications ****************************************************/

/* LIN_ERR_FLAG: Used to distinguish it from ordinary frames.
* The error frame consists of err_flag、err_class(defined in data[0])
* and err_reason(defined in data[1] to data[4]).
* The error frame consists of err_flag(LIN_ERR_FLAG)、err_class
* (defined in data[0]) and err_reason(defined in data[1] to data[4]).
* The error frame is described using the following structure:
* struct can_frame {
* canid_t can_id;
* uint8_t can_dlc;
* uint8_t __pad;
* uint8_t __res0;
* uint16_t flags;
* uint8_t __res1;
* uint8_t data[CAN_MAX_DLEN] __attribute__((aligned(8)));
* };
* }__attribute__((packed));
*
* Error frame description format:
*
Expand All @@ -85,8 +99,6 @@
* define in data[0] ~ data[4] in can_frame.
*/

#define LIN_ERR_FLAG CAN_ERR_FLAG /* The flag indicate this is LIN err_frame */

/* ERR_CLASS in data[0] */

#define LIN_ERR_UNSPEC 0x00 /* Unspecified error */
Expand Down Expand Up @@ -124,14 +136,25 @@
#define LIN_ERR_BUS_PID (1 << 0) /* Bit 0: Pid received back is not equal to the pid sent */
#define LIN_ERR_BUS_TXCKSUM (1 << 1) /* Bit 1: Checksum received back is not equal to checksum sent */
#define LIN_ERR_BUS_SYNC (1 << 2) /* Bit 2: Master send sync, but receive back sync is not 0x55 */
#define LIN_ERR_BUS_DATA (1 << 3) /* Bit 3: Data received back is not equal to the data sent */
#define LIN_ERR_BUS_DATA (1 << 3) /* Bit 3: Data received back is not equal to the data sent */

/* Data[4] error status of LIN-controller */

#define LIN_ERR_CRTL_UNSPEC 0x00 /* Unspecified error */
#define LIN_ERR_CRTL_RXOVERFLOW (1 << 0) /* Hardware controller receive overflow */
#define LIN_ERR_CTRL_FRAMEERROR (1 << 1) /* Hardware controller frame error */

/* LIN States Indications ***************************************************/

/* lower_half State switch events are defined in data[0] */

#define LIN_EVT_UNSPEC 0x00 /* Unspecified state event */
#define LIN_EVT_WAKEUP (1 << 0) /* Already send a wake-up command to lin_bus */
#define LIN_EVT_WAKEUP_PASSIVE (1 << 1) /* Wake up when detecte low level signal of bus a for a period of time(such as 250us-5ms) */
#define LIN_EVT_SLEEP (1 << 2) /* Send a sleep command(0x3c) to the bus, only Master */
#define LIN_EVT_SLEEP_PASSIVE (1 << 3) /* Receive a sleep command from bus */
#define LIN_EVT_SLEEP_IDLE (1 << 4) /* Go to sleep when bus keep in the inactive for a period of time(such as 4s) */

/****************************************************************************
* Public Function Prototypes
****************************************************************************/
Expand All @@ -150,4 +173,5 @@ extern "C"
}
#endif

#endif /* CONFIG_CAN */
#endif /* __INCLUDE_NUTTX_LIN_H */

0 comments on commit 366ede9

Please sign in to comment.