RTE_CAN.c 6.47 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5
#include "GPIO.h"
#include "dr7f701441.dvf.h"

#include "RTE_CAN.h"
#include "CAN_Communication_Matrix.h"
hu's avatar
hu committed
6
#include "CAN_FUNC.h"
hu's avatar
hu committed
7 8 9 10 11 12 13 14 15 16
#include "CAN_Lib.h"
//#include "CAN_Signal_Tx.h"
#include "AlarmGeneralFilie.h"
#include "Diag_ID_Def.h"
#include "DoCAN_ISO15765.h"

#include "PowerManagement.h"
#include "UDS_Common.h"

#include "Watchdog.h"
hu's avatar
hu committed
17
#include "RSCAN.h"
hu's avatar
hu committed
18
#include "Link_Layer.h"
hu's avatar
hu committed
19
#include "kwp2000_service.h"
hu's avatar
hu committed
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

static uint16_t Can_Init_Lock = 0U;

void Can_Lock_Clr(void)
{
    Can_Init_Lock = 0u;
}

/***Middle***/
void Can_Init(void)
{
    /* filter 变量声明 */
    uint32_t IDFilterNum;

    uint8_t CH0_IDFilterNum;
    uint32_t CANLLCCh0NMIDRange[2];
    uint32_t CANLLCCh0MsgIDList[ID_TOTAL_MAX + 2u];
    uint32_t CANLLCCh0OwnIDList[4];

    uint32_t i;
hu's avatar
hu committed
40 41 42
    RSCAN0_Config_st_t CANLLCCh0Filter;

    CANLLCCh0Filter.stRSCANCh0.u32RSCANChEn = 1u;       /*通道是否使能*/
43 44 45 46 47 48 49 50
    if (K_Line_Set.K_Line_LID52 == 0x00u)
    {
        CANLLCCh0Filter.stRSCANCh0.enRSCANChBps = RSCAN_Baud_Rate_500K;       /*通道波特率*/
    }
    else if (K_Line_Set.K_Line_LID52 == 0x01u)
    {
        CANLLCCh0Filter.stRSCANCh0.enRSCANChBps = RSCAN_Baud_Rate_250K;       /*通道波特率*/
    }
hu's avatar
hu committed
51
    CANLLCCh0Filter.stRSCANCh0.u32RSCANChRuleSize = CANFD0_CH0_RX_RULE_SIZE; /*通道接收规则条数*/
hu's avatar
hu committed
52
    CANLLCCh0Filter.stRSCANCh0.pfnRSCANConfirmCallBack = Can_Confirm;  /*发送确认*/
hu's avatar
hu committed
53
    CANLLCCh0Filter.stRSCANCh0.pfnRSCANAbortConfirmCallBack = 0u; /*发送中止确认*/
54
    CANLLCCh0Filter.stRSCANCh0.pfnRSCANReadMsgCallBack = Can_Read_Msg; /*接收完成*/
hu's avatar
hu committed
55 56 57 58 59 60 61 62 63 64 65

    CANLLCCh0Filter.stRSCANCh1.u32RSCANChEn = 0u;       /*通道是否使能*/
    CANLLCCh0Filter.stRSCANCh1.enRSCANChBps = RSCAN_Baud_Rate_500K;       /*通道波特率*/
    CANLLCCh0Filter.stRSCANCh1.u32RSCANChRuleSize = CANFD0_CH1_RX_RULE_SIZE; /*通道接收规则条数*/
    CANLLCCh0Filter.stRSCANCh1.pfnRSCANConfirmCallBack = 0u;  /*发送确认*/
    CANLLCCh0Filter.stRSCANCh1.pfnRSCANAbortConfirmCallBack = 0u; /*发送中止确认*/
    CANLLCCh0Filter.stRSCANCh1.pfnRSCANReadMsgCallBack = 0u; /*接收完成*/

    CANLLCCh0Filter.stRSCANCh2.u32RSCANChEn = 1u;       /*通道是否使能*/
    CANLLCCh0Filter.stRSCANCh2.enRSCANChBps = RSCAN_Baud_Rate_500K;       /*通道波特率*/
    CANLLCCh0Filter.stRSCANCh2.u32RSCANChRuleSize = CANFD0_CH2_RX_RULE_SIZE; /*通道接收规则条数*/
hu's avatar
hu committed
66
    CANLLCCh0Filter.stRSCANCh2.pfnRSCANConfirmCallBack = Can_Confirm2;  /*发送确认*/
hu's avatar
hu committed
67
    CANLLCCh0Filter.stRSCANCh2.pfnRSCANAbortConfirmCallBack = 0u; /*发送中止确认*/
hu's avatar
hu committed
68
    CANLLCCh0Filter.stRSCANCh2.pfnRSCANReadMsgCallBack = Can_Read_Msg2; /*接收完成*/
hu's avatar
hu committed
69

70 71
    CANSTB_OUT  = 1U; /*CANSTB_OUT*/
    CANSTB2_OUT = 1U; /*CANSTB2_OUT*/
hu's avatar
hu committed
72 73

    RSCAN0_CH_Init(CANFD_RX_RULE_TABLE_LIST, &CANLLCCh0Filter);
hu's avatar
hu committed
74

75 76
    CANSTB_OUT  = 0U; /*CANSTB_OUT*/
    CANSTB2_OUT = 0U; /*CANSTB2_OUT*/
hu's avatar
hu committed
77
}
hu's avatar
hu committed
78

hu's avatar
hu committed
79 80 81
void Can_DeInit(void)
{
}
hu's avatar
hu committed
82

hu's avatar
hu committed
83 84
uint8_t Can_Write(_CAN_Msg *Msg)
{
hu's avatar
hu committed
85
    uint8_t i = 0u;
hu's avatar
hu committed
86
    CAN_Frame_st_t CANFrame;
hu's avatar
hu committed
87

hu's avatar
hu committed
88 89 90 91
    for (i = 0; i < 8u; i++)
    {
        CANFrame.unCANData.u8CANData[i] = Msg->Msg[i];
    }
hu's avatar
hu committed
92

hu's avatar
hu committed
93
    CANFrame.u32CANID = Msg->MsgID;
hu's avatar
hu committed
94
    CANFrame.u8CANLEN = Msg->MsgDLC;
hu's avatar
hu committed
95
    CANFrame.u8CANFrameIDE = Msg->MsgStd;
hu's avatar
hu committed
96 97


hu's avatar
hu committed
98 99 100
    if (Msg->MsgPro < RSCAN_CHANNEL_BUF_2)
    {
        RSCAN0_CH2_Set_TXBUF_Data(Msg->MsgPro, &CANFrame);
hu's avatar
hu committed
101
    }
hu's avatar
hu committed
102 103 104 105 106 107 108 109 110
    else if (Msg->MsgPro < RSCAN_CHANNEL_BUF_MAX)
    {
        RSCAN0_CH0_Set_TXBUF_Data(Msg->MsgPro, &CANFrame);
    }
    else if ((Msg->MsgPro >= 25u) && (Msg->MsgPro <= 27u))
    {
        RSCAN0_CH2_Set_FIFO0_Data(&CANFrame);
    }
    else
hu's avatar
hu committed
111
    {
hu's avatar
hu committed
112
        RSCAN0_CH0_Set_FIFO0_Data(&CANFrame);
hu's avatar
hu committed
113
    }
hu's avatar
hu committed
114

hu's avatar
hu committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
    return 0;
}

void Can_Sleep_Fun(void)
{
}

void Can_SleepController_Fun(void)
{
}

void Can_Wakeup_Fun(void)
{
}

hu's avatar
hu committed
130
/*诊断发送终止----20220320----*/
hu's avatar
hu committed
131 132
void Can_Uds_Abort(void)
{
hu's avatar
hu committed
133 134 135
    //CANFD_SetTX_Abort();
    RSCAN0_CH2_Abort(RSCAN_CHANNEL_BUF_0);
    RSCAN0_CH2_Abort(RSCAN_CHANNEL_BUF_1);
hu's avatar
hu committed
136 137 138 139 140 141 142 143 144 145 146 147 148
}

void Can_Abort_All(void)
{
}

/*****Lower*******/
void Can_Read_Msg(uint32_t m_id, uint8_t m_dlc, uint8_t m_Msg[])
{
    ReceivedMsg(m_id, m_dlc);

    Co_Can_Buff_Set(Co_Can_ConvertSubID(m_id), m_dlc, m_Msg);

hu's avatar
hu committed
149 150 151 152 153 154 155 156
    //if ((m_id == DIAG_ID_Rx_FUN) || (m_id == DIAG_ID_Rx_PHY))
    //{
    //    DoCAN_L_Data_Indication(m_id, m_dlc, m_Msg);
    //}
}

void Can_Read_Msg2(uint32_t m_id, uint8_t m_dlc, uint8_t m_Msg[])
{
hu's avatar
hu committed
157
    if (m_id == DIAG_ID_Rx_PHY)
hu's avatar
hu committed
158
    {
hu's avatar
hu committed
159
        LK_Link_main(DIAG_ID_Rx_PHY, (uint8_t*)m_Msg, (m_dlc & 0x0f));
hu's avatar
hu committed
160
    }
hu's avatar
hu committed
161 162 163 164
    if ((m_id == DIAG_ID_Rx_FUN) || (m_id == DIAG_ID_Rx_PHY))
    {
        DoCAN_L_Data_Indication(m_id, m_dlc, m_Msg);
    }
hu's avatar
hu committed
165 166 167 168
}

void Can_Confirm(uint32_t Identifier, uint8_t TransferStatus)
{
hu's avatar
hu committed
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
    switch (Identifier)
    {
    case RSCAN_CHANNEL_BUF_0:
        break;
    case RSCAN_CHANNEL_BUF_1:
        break;
    case RSCAN_CHANNEL_BUF_2:
        break;
    case RSCAN_CHANNEL_BUF_3:
        break;
    case RSCAN_CHANNEL_BUF_4:
        break;
    case RSCAN_CHANNEL_BUF_5:
        break;
    case RSCAN_CHANNEL_BUF_6:
        break;
    case RSCAN_CHANNEL_BUF_7:
        break;
    case RSCAN_CHANNEL_BUF_8:
        break;
    case RSCAN_CHANNEL_BUF_9:
        break;
    case RSCAN_CHANNEL_BUF_10:
        break;
    case RSCAN_CHANNEL_BUF_11:
        break;
    case RSCAN_CHANNEL_BUF_12:  Can_Msg_TX_SUCCESS(MSGID_18FFE517);
        break;
    case RSCAN_CHANNEL_BUF_13:
        break;
    default :
        break;
    }
hu's avatar
hu committed
202 203
}

hu's avatar
hu committed
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
void Can_Confirm2(uint32_t Identifier, uint8_t TransferStatus)
{
    switch (Identifier)
    {
    case RSCAN_CHANNEL_BUF_0: DoCAN_L_Data_Confirm(DIAG_ID_Tx, 1u);
        break;
    case RSCAN_CHANNEL_BUF_1: DoCAN_L_Data_Confirm(DIAG_ID_Tx, 1u);
        break;
    case RSCAN_CHANNEL_BUF_2: DoCAN_L_Data_Confirm(DIAG_ID_Tx, 1u);
        break;
    case RSCAN_CHANNEL_BUF_3:
        break;
    case RSCAN_CHANNEL_BUF_4:
        break;
    case RSCAN_CHANNEL_BUF_5:
        break;
    case RSCAN_CHANNEL_BUF_6:
        break;
    case RSCAN_CHANNEL_BUF_7:
        break;
    case RSCAN_CHANNEL_BUF_8:
        break;
    case RSCAN_CHANNEL_BUF_9:
        break;
    case RSCAN_CHANNEL_BUF_10:
        break;
    case RSCAN_CHANNEL_BUF_11:
        break;
    case RSCAN_CHANNEL_BUF_12:
        break;
    case RSCAN_CHANNEL_BUF_13:
        break;
    default :
        break;
    }
}

hu's avatar
hu committed
241 242 243

void CAN_BUSOFF_Recover(void)
{
hu's avatar
hu committed
244 245
    //CH0_BusOff_Recovery();
    RSCAN0_CH0_Busoff_Recover();
246
    RSCAN0_CH2_Busoff_Recover();
hu's avatar
hu committed
247
}