RTE_CAN.c 6.71 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
#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"
hu's avatar
hu committed
15
#include "UDS_CFG.H"
hu's avatar
hu committed
16 17

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

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
42 43 44
    RSCAN0_Config_st_t CANLLCCh0Filter;

    CANLLCCh0Filter.stRSCANCh0.u32RSCANChEn = 1u;       /*通道是否使能*/
45 46 47 48 49 50 51 52
    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
53
    CANLLCCh0Filter.stRSCANCh0.u32RSCANChRuleSize = CANFD0_CH0_RX_RULE_SIZE; /*通道接收规则条数*/
hu's avatar
hu committed
54
    CANLLCCh0Filter.stRSCANCh0.pfnRSCANConfirmCallBack = Can_Confirm;  /*发送确认*/
hu's avatar
hu committed
55
    CANLLCCh0Filter.stRSCANCh0.pfnRSCANAbortConfirmCallBack = 0u; /*发送中止确认*/
56
    CANLLCCh0Filter.stRSCANCh0.pfnRSCANReadMsgCallBack = Can_Read_Msg; /*接收完成*/
hu's avatar
hu committed
57 58 59 60 61 62 63 64 65 66 67

    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
68
    CANLLCCh0Filter.stRSCANCh2.pfnRSCANConfirmCallBack = Can_Confirm2;  /*发送确认*/
hu's avatar
hu committed
69
    CANLLCCh0Filter.stRSCANCh2.pfnRSCANAbortConfirmCallBack = 0u; /*发送中止确认*/
hu's avatar
hu committed
70
    CANLLCCh0Filter.stRSCANCh2.pfnRSCANReadMsgCallBack = Can_Read_Msg2; /*接收完成*/
hu's avatar
hu committed
71

72 73
    CANSTB_OUT  = 1U; /*CANSTB_OUT*/
    CANSTB2_OUT = 1U; /*CANSTB2_OUT*/
hu's avatar
hu committed
74 75

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

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

hu's avatar
hu committed
81 82 83
void Can_DeInit(void)
{
}
hu's avatar
hu committed
84

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

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

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


hu's avatar
hu committed
100 101 102
    if (Msg->MsgPro < RSCAN_CHANNEL_BUF_2)
    {
        RSCAN0_CH2_Set_TXBUF_Data(Msg->MsgPro, &CANFrame);
hu's avatar
hu committed
103
    }
hu's avatar
hu committed
104 105 106 107 108 109 110 111 112
    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
113
    {
hu's avatar
hu committed
114
        RSCAN0_CH0_Set_FIFO0_Data(&CANFrame);
hu's avatar
hu committed
115
    }
hu's avatar
hu committed
116

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

void Can_Sleep_Fun(void)
{
}

void Can_SleepController_Fun(void)
{
}

void Can_Wakeup_Fun(void)
{
}

hu's avatar
hu committed
132
/*诊断发送终止----20220320----*/
hu's avatar
hu committed
133 134
void Can_Uds_Abort(void)
{
hu's avatar
hu committed
135 136 137
    //CANFD_SetTX_Abort();
    RSCAN0_CH2_Abort(RSCAN_CHANNEL_BUF_0);
    RSCAN0_CH2_Abort(RSCAN_CHANNEL_BUF_1);
hu's avatar
hu committed
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);

hu's avatar
hu committed
149 150 151 152 153 154 155
    if (
        (m_id == 0x18DAF003u) ||
        (m_id == 0x18DAF00Bu) ||
        (m_id == 0x18DAF010u) ||
        (m_id == 0x18DAF0A0u) ||
        (m_id == 0x18DAF0E8u)
    )
hu's avatar
hu committed
156 157 158 159
    {
        Common_Set_UdsCanIDSta(m_id);
        LK_Link_main(m_id, (uint8_t*)m_Msg, (m_dlc & 0x0f));
    }
hu's avatar
hu committed
160 161

    Co_Can_Buff_Set(Co_Can_ConvertSubID(m_id), m_dlc, m_Msg);
hu's avatar
hu committed
162 163 164 165
}

void Can_Read_Msg2(uint32_t m_id, uint8_t m_dlc, uint8_t m_Msg[])
{
hu's avatar
hu committed
166
    if (m_id == ID_BCM_ResAddr)
hu's avatar
hu committed
167
    {
hu's avatar
hu committed
168 169
        Common_Set_UdsCanIDSta(m_id);
        LK_Link_main(m_id, (uint8_t*)m_Msg, (m_dlc & 0x0f));
hu's avatar
hu committed
170
    }
hu's avatar
hu committed
171 172 173 174
    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
175 176 177 178
}

void Can_Confirm(uint32_t Identifier, uint8_t TransferStatus)
{
hu's avatar
hu committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
    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
212 213
}

hu's avatar
hu committed
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 241 242 243 244 245 246 247 248 249 250
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
251 252 253

void CAN_BUSOFF_Recover(void)
{
hu's avatar
hu committed
254 255
    //CH0_BusOff_Recovery();
    RSCAN0_CH0_Busoff_Recover();
256
    RSCAN0_CH2_Busoff_Recover();
hu's avatar
hu committed
257
}