Rscan.h 4.39 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5 6 7 8

#ifndef RSCAN_H__
#define RSCAN_H__


/*-----------------use for RH850_D1M1A_1441 --------------------*/
#include "RSCAN_Table.h"

9 10
typedef enum
{
hu's avatar
hu committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24
    RSCAN_CHANNEL_BUF_0 = 0U,
    RSCAN_CHANNEL_BUF_1,
    RSCAN_CHANNEL_BUF_2,
    RSCAN_CHANNEL_BUF_3,
    RSCAN_CHANNEL_BUF_4,
    RSCAN_CHANNEL_BUF_5,
    RSCAN_CHANNEL_BUF_6,
    RSCAN_CHANNEL_BUF_7,
    RSCAN_CHANNEL_BUF_8,
    RSCAN_CHANNEL_BUF_9,
    RSCAN_CHANNEL_BUF_10,
    RSCAN_CHANNEL_BUF_11,
    RSCAN_CHANNEL_BUF_12,
    RSCAN_CHANNEL_BUF_13,
hu's avatar
hu committed
25
   
hu's avatar
hu committed
26 27 28
    RSCAN_CHANNEL_BUF_MAX,

} RSCAN_Channel_Buf_en_t;
29 30 31

typedef enum
{
hu's avatar
hu committed
32 33 34 35
    RSCAN_BUS_IDLE = 0U,
    RSCAN_BUS_OFF,
    RSCAN_BUS_TX,
    RSCAN_BUS_RX,
36

hu's avatar
hu committed
37
} RSCAN_Com_Status_en_t;
38

hu's avatar
hu committed
39
typedef enum
40
{
hu's avatar
hu committed
41 42 43
    RSCAN_Baud_Rate_500K = 0U,
    RSCAN_Baud_Rate_250K,
    RSCAN_Baud_Rate_125K,
44

hu's avatar
hu committed
45 46 47 48 49
} RSCAN_Baud_Rate_en_t;
typedef enum
{
    RSCAN_FRAME_STANDARD = 0U,
    RSCAN_FRAME_EXTEND,
50

hu's avatar
hu committed
51
} RSCAN_Frame_en_t;
52

hu's avatar
hu committed
53 54 55
typedef void (*RSCAN_Confirm)(uint32_t Identifier, uint8_t TransferStatus);
typedef void (*RSCAN_AbortConfirm)(uint32_t Identifier);
typedef void (*RSCAN_Read_Msg)(uint32_t m_id, uint8_t m_dlc, uint8_t m_Msg []);
56

hu's avatar
hu committed
57 58 59 60 61 62 63 64
typedef struct
{
    uint32_t             u32RSCANChEn;       /*通道是否使能*/
    RSCAN_Baud_Rate_en_t enRSCANChBps;       /*通道波特率*/
    uint32_t             u32RSCANChRuleSize; /*通道接收规则条数*/
    RSCAN_Confirm        pfnRSCANConfirmCallBack;
    RSCAN_AbortConfirm   pfnRSCANAbortConfirmCallBack;
    RSCAN_Read_Msg       pfnRSCANReadMsgCallBack;
65

hu's avatar
hu committed
66
} RSCAN_Channel_Config_st_t;
67 68 69 70

typedef struct
{

hu's avatar
hu committed
71 72 73 74
    RSCAN_Channel_Config_st_t stRSCANCh0;
    RSCAN_Channel_Config_st_t stRSCANCh1;
    RSCAN_Channel_Config_st_t stRSCANCh2;
} RSCAN0_Config_st_t;
75

hu's avatar
hu committed
76
typedef enum
77
{
hu's avatar
hu committed
78 79 80
    RSCAN_SET_COMPLETE = 0,
    RSCAN_SET_ERROR_PARAMETER,
    RSCAN_SET_ERROR_MSGFULL,
81

hu's avatar
hu committed
82
} RSCAN_SetState;
83

hu's avatar
hu committed
84
typedef union
85
{
hu's avatar
hu committed
86 87 88
    uint32_t u32CANData [ 2U ];
    uint8_t  u8CANData [ 8U ];
} CAN_Data_un_t;
89

hu's avatar
hu committed
90
typedef struct
91
{
hu's avatar
hu committed
92 93 94 95
    CAN_Data_un_t unCANData;
    uint32_t      u32CANID;
    uint8_t       u8CANLEN;
    uint8_t       u8CANFrameIDE; /*0: Standard ID . 1: Extended ID */
96

hu's avatar
hu committed
97
} CAN_Frame_st_t;
98

hu's avatar
hu committed
99 100 101 102 103 104
/*
返回值:
0:设置失败
1:设置成功
*/
extern uint8_t RSCAN0_CH_Init(const RSCANFD_Filter_st_t pstRSCANFilter [], RSCAN0_Config_st_t *pstRSCANConfig);
105

hu's avatar
hu committed
106 107 108
extern void RSCAN0_CH0_Receive(CAN_Frame_st_t *pstCANFrame);
extern void RSCAN0_CH1_Receive(CAN_Frame_st_t *pstCANFrame);
extern void RSCAN0_CH2_Receive(CAN_Frame_st_t *pstCANFrame);
109 110


hu's avatar
hu committed
111 112 113
extern RSCAN_SetState RSCAN0_CH0_Set_FIFO0_Data(CAN_Frame_st_t *pstCANFrame);
extern RSCAN_SetState RSCAN0_CH1_Set_FIFO0_Data(CAN_Frame_st_t *pstCANFrame);
extern RSCAN_SetState RSCAN0_CH2_Set_FIFO0_Data(CAN_Frame_st_t *pstCANFrame);
114

hu's avatar
hu committed
115 116 117
extern RSCAN_SetState RSCAN0_CH0_Set_TXBUF_Data(RSCAN_Channel_Buf_en_t enBufIndex, CAN_Frame_st_t *pstCANFrame);
extern RSCAN_SetState RSCAN0_CH1_Set_TXBUF_Data(RSCAN_Channel_Buf_en_t enBufIndex, CAN_Frame_st_t *pstCANFrame);
extern RSCAN_SetState RSCAN0_CH2_Set_TXBUF_Data(RSCAN_Channel_Buf_en_t enBufIndex, CAN_Frame_st_t *pstCANFrame);
118

hu's avatar
hu committed
119 120 121
extern uint8_t RSCAN0_CH0_Get_Rec_Status(void);
extern uint8_t RSCAN0_CH1_Get_Rec_Status(void);
extern uint8_t RSCAN0_CH2_Get_Rec_Status(void);
122

hu's avatar
hu committed
123 124 125
extern uint8_t RSCAN0_CH0_Get_Busoff_Status(void);
extern uint8_t RSCAN0_CH1_Get_Busoff_Status(void);
extern uint8_t RSCAN0_CH2_Get_Busoff_Status(void);
126

hu's avatar
hu committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
extern void RSCAN0_CH0_Busoff_Recover(void);
extern void RSCAN0_CH1_Busoff_Recover(void);
extern void RSCAN0_CH2_Busoff_Recover(void);

extern void RSCAN0_CH0_Abort(RSCAN_Channel_Buf_en_t enBufIndex);
extern void RSCAN0_CH1_Abort(RSCAN_Channel_Buf_en_t enBufIndex);
extern void RSCAN0_CH2_Abort(RSCAN_Channel_Buf_en_t enBufIndex);

extern void RSCAN0_CH0_Sleep_Init(void);
extern void RSCAN0_CH1_Sleep_Init(void);
extern void RSCAN0_CH2_Sleep_Init(void);
extern void RSCAN0_Sleep_Init(void);

extern uint8_t RSCAN0_CH0_TX_Error_Count(void);
extern uint8_t RSCAN0_CH1_TX_Error_Count(void);
extern uint8_t RSCAN0_CH2_TX_Error_Count(void);

extern uint8_t RSCAN0_CH0_RX_Error_Count(void);
extern uint8_t RSCAN0_CH1_RX_Error_Count(void);
extern uint8_t RSCAN0_CH2_RX_Error_Count(void);

extern void RSCAN0_CH0_RX_ISR(void);
extern void RSCAN0_CH1_RX_ISR(void);
extern void RSCAN0_CH2_RX_ISR(void);

extern void RSCAN0_CH0_TX_ISR(void);
extern void RSCAN0_CH1_TX_ISR(void);
extern void RSCAN0_CH2_TX_ISR(void);
155 156

#endif