RTE_CAN.c 7.05 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include "Rscan.h"
#include "GPIO.h"
#include "dr7f701441.dvf.h"

#include "RTE_CAN.h"
#include "CAN_Communication_Matrix.h"
#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 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37

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
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
    RSCAN0_Config_st_t CANLLCCh0Filter;

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

    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; /*通道接收规则条数*/
    CANLLCCh0Filter.stRSCANCh2.pfnRSCANConfirmCallBack = 0u;  /*发送确认*/
    CANLLCCh0Filter.stRSCANCh2.pfnRSCANAbortConfirmCallBack = 0u; /*发送中止确认*/
    CANLLCCh0Filter.stRSCANCh2.pfnRSCANReadMsgCallBack = 0u; /*接收完成*/

    CANSTB_OUT = 1U; //CANSTB_OUT
    CANSTB_OUT = 1U; //CANSTB_OUT

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

hu's avatar
hu committed
66 67 68
    CANSTB_OUT = 0U; //CANSTB_OUT
    CANSTB_OUT = 0U; //CANSTB_OUT
}
hu's avatar
hu committed
69

hu's avatar
hu committed
70 71 72
void Can_DeInit(void)
{
}
hu's avatar
hu committed
73

hu's avatar
hu committed
74 75 76
uint8_t Can_Write(_CAN_Msg *Msg)
{
    CAN_Frame_st_t CANFrame;
hu's avatar
hu committed
77

hu's avatar
hu committed
78 79 80 81 82 83 84 85
    CANFrame.unCANData.u8CANData[0] = Msg->Msg[0];
    CANFrame.unCANData.u8CANData[1] = Msg->Msg[1];
    CANFrame.unCANData.u8CANData[2] = Msg->Msg[2];
    CANFrame.unCANData.u8CANData[3] = Msg->Msg[3];
    CANFrame.unCANData.u8CANData[4] = Msg->Msg[4];
    CANFrame.unCANData.u8CANData[5] = Msg->Msg[5];
    CANFrame.unCANData.u8CANData[6] = Msg->Msg[6];
    CANFrame.unCANData.u8CANData[7] = Msg->Msg[7];
hu's avatar
hu committed
86

hu's avatar
hu committed
87 88 89
    CANFrame.u32CANID = Msg->MsgID;
    CANFrame.u8CANLEN = 8;
    CANFrame.u8CANFrameIDE = 1u;
hu's avatar
hu committed
90 91


hu's avatar
hu committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
    switch (Msg->MsgPro)
    {
    case 0x00u : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_0, &CANFrame);  break;
    case 0x01u : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_1, &CANFrame);  break;
    case 0x02u : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_2, &CANFrame);  break;
    case 0x03u : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_3, &CANFrame);  break;
    case 0x04u : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_4, &CANFrame);  break;
    case 0x05u : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_5, &CANFrame);  break;
    case 0x06u : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_6, &CANFrame);  break;
    case 0x07u : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_7, &CANFrame);  break;
    case 0x08u : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_8, &CANFrame);  break;
    case 0x09u : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_9, &CANFrame);  break;
    case 0x0Au : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_10, &CANFrame);  break;
    case 0x0Bu : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_11, &CANFrame);  break;
    case 0x0Cu : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_12, &CANFrame);  break;
    case 0x0Du : RSCAN0_CH0_Set_TXBUF_Data(RSCAN_CHANNEL_BUF_13, &CANFrame);  break;
hu's avatar
hu committed
108

hu's avatar
hu committed
109 110
    default:
        break;
hu's avatar
hu committed
111 112 113

    }

hu's avatar
hu committed
114
    /*
hu's avatar
hu committed
115 116 117
    switch (Msg->MsgPro)
    {
    case 0:
hu's avatar
hu committed
118 119
      RSCAN0_SendCH0_TxBuf0(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
120
    case 1:
hu's avatar
hu committed
121 122
      RSCAN0_SendCH0_TxBuf1(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
123
    case 2:
hu's avatar
hu committed
124 125
      RSCAN0_SendCH0_TxBuf2(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
126
    case 3:
hu's avatar
hu committed
127 128
      RSCAN0_SendCH0_TxBuf3(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
129
    case 4:
hu's avatar
hu committed
130 131
      RSCAN0_SendCH0_TxBuf4(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
132
    case 5:
hu's avatar
hu committed
133 134
      RSCAN0_SendCH0_TxBuf5(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
135
    case 6:
hu's avatar
hu committed
136 137
      RSCAN0_SendCH0_TxBuf6(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
138
    case 7:
hu's avatar
hu committed
139 140
      RSCAN0_SendCH0_TxBuf7(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
141
    case 8:
hu's avatar
hu committed
142 143
      RSCAN0_SendCH0_TxBuf8(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
144
    case 9:
hu's avatar
hu committed
145 146
      RSCAN0_SendCH0_TxBuf9(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
147
    case 10:
hu's avatar
hu committed
148 149
      RSCAN0_SendCH0_TxBuf10(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
150
    case 11:
hu's avatar
hu committed
151 152
      RSCAN0_SendCH0_TxBuf11(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
153
    case 12:
hu's avatar
hu committed
154 155
      RSCAN0_SendCH0_TxBuf12(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
156
    case 13:
hu's avatar
hu committed
157 158
      RSCAN0_SendCH0_TxBuf13(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
159
    case 14:
hu's avatar
hu committed
160 161
      RSCAN0_SendCH0_TxBuf14(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
162
    case 15:
hu's avatar
hu committed
163 164
      RSCAN0_SendCH0_TxBuf15(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
      break;
hu's avatar
hu committed
165
    default:
hu's avatar
hu committed
166 167
      CAN_CH0_Data_Request(Msg->MsgID, Msg->MsgStd, Msg->MsgRTR, Msg->MsgDLC, Msg->Msg);
      break;
hu's avatar
hu committed
168
    }
hu's avatar
hu committed
169
    */
hu's avatar
hu committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
    return 0;
}

void Can_Sleep_Fun(void)
{
}

void Can_SleepController_Fun(void)
{
}

void Can_Wakeup_Fun(void)
{
}

hu's avatar
hu committed
185
/*诊断发送终止----20220320----*/
hu's avatar
hu committed
186 187
void Can_Uds_Abort(void)
{
hu's avatar
hu committed
188 189 190
    //CANFD_SetTX_Abort();
    RSCAN0_CH2_Abort(RSCAN_CHANNEL_BUF_0);
    RSCAN0_CH2_Abort(RSCAN_CHANNEL_BUF_1);
hu's avatar
hu committed
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
}

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);

    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_Confirm(uint32_t Identifier, uint8_t TransferStatus)
{
}


void CAN_BUSOFF_Recover(void)
{
hu's avatar
hu committed
217 218
    //CH0_BusOff_Recovery();
    RSCAN0_CH0_Busoff_Recover();
hu's avatar
hu committed
219
}