RTE_CAN.c 5.27 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 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
#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"

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;
    CANFD_Filter_Init_st_t CANLLCCh0Filter;
    if (Can_Init_Lock != 0x55AAu)
    {
        /* Sys_Startup_Init */
        /*50304*/
        /* Channel0 Filter Data */
        CANLLCCh0NMIDRange[0] = 0x680UL;
        CANLLCCh0NMIDRange[1] = 0x6FFUL;

        CANLLCCh0MsgIDList[0] = DIAG_ID_Rx_PHY;
        CANLLCCh0MsgIDList[1] = DIAG_ID_Rx_FUN;

        for (i = 2u; i < (ID_TOTAL_MAX + 2u); i++)
        {
            CANLLCCh0MsgIDList[i] = CAN_MSG_CONST_ARRAY[i - 2].MSG_Identifier;
        }

        CANLLCCh0OwnIDList[0] = 0x26DUL;
        CANLLCCh0OwnIDList[1] = 0x330UL;
        CANLLCCh0OwnIDList[2] = 0x331UL;
        CANLLCCh0OwnIDList[3] = 0x332UL;

        /* Channel0 Filter Data configeration */
        CANLLCCh0Filter.NM0StdFilter.CfgType = CANFD_FILTER_ID_RANGE;
        CANLLCCh0Filter.NM0StdFilter.IDNum = (DIM(CANLLCCh0NMIDRange) / 2U);
        CANLLCCh0Filter.NM0StdFilter.pIDs = CANLLCCh0NMIDRange;
        CANLLCCh0Filter.NM0ExtFilter.CfgType = CANFD_FILTER_N_A;

        CANLLCCh0Filter.Msg0StdFilter.CfgType = CANFD_FILTER_ID_LIST;
        CANLLCCh0Filter.Msg0StdFilter.IDNum = ID_TOTAL_MAX + 2u;
        CANLLCCh0Filter.Msg0StdFilter.pIDs = CANLLCCh0MsgIDList;
        CANLLCCh0Filter.Msg0ExtFilter.CfgType = CANFD_FILTER_N_A;

        CANLLCCh0Filter.Diag0StdFilter.CfgType = CANFD_FILTER_ID_LIST;
        CANLLCCh0Filter.Diag0StdFilter.IDNum = DIM(CANLLCCh0OwnIDList);
        CANLLCCh0Filter.Diag0StdFilter.pIDs = CANLLCCh0OwnIDList;
        CANLLCCh0Filter.Diag0ExtFilter.CfgType = CANFD_FILTER_N_A;

        CH0_IDFilterNum = CANLLCCh0Filter.NM0StdFilter.IDNum;
        CH0_IDFilterNum = CH0_IDFilterNum + CANLLCCh0Filter.Msg0StdFilter.IDNum;
        CH0_IDFilterNum = CH0_IDFilterNum + CANLLCCh0Filter.Diag0StdFilter.IDNum;

        IDFilterNum = (uint32_t)(CH0_IDFilterNum & 0xFFUL);
        IDFilterNum |= (uint32_t)((0 & 0xFFUL) << 8U);
        IDFilterNum |= (uint32_t)((0 & 0xFFUL) << 16U);

        CANLLCCh0Filter.pfCAN0DataIndCb = Can_Read_Msg;

        RSCAN0_CH_Init(&CANLLCCh0Filter, IDFilterNum);
        Can_Init_Lock = 0x55AAu;
    }
    GPIO_OUT_PORT00_PIN00 = 0U; //RSCAN0_CH0_STB
}

void Can_DeInit(void)
{
}

uint8_t Can_Write(_CAN_Msg *Msg)
{
    switch (Msg->MsgPro)
    {
    case 0:
        RSCAN0_SendCH0_TxBuf0(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 1:
        RSCAN0_SendCH0_TxBuf1(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 2:
        RSCAN0_SendCH0_TxBuf2(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 3:
        RSCAN0_SendCH0_TxBuf3(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 4:
        RSCAN0_SendCH0_TxBuf4(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 5:
        RSCAN0_SendCH0_TxBuf5(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 6:
        RSCAN0_SendCH0_TxBuf6(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 7:
        RSCAN0_SendCH0_TxBuf7(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 8:
        RSCAN0_SendCH0_TxBuf8(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 9:
        RSCAN0_SendCH0_TxBuf9(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 10:
        RSCAN0_SendCH0_TxBuf10(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 11:
        RSCAN0_SendCH0_TxBuf11(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 12:
        RSCAN0_SendCH0_TxBuf12(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 13:
        RSCAN0_SendCH0_TxBuf13(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 14:
        RSCAN0_SendCH0_TxBuf14(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    case 15:
        RSCAN0_SendCH0_TxBuf15(Msg->MsgID, Msg->MsgDLC, Msg->MsgStd, Msg->Msg);
        break;
    default:
        CAN_CH0_Data_Request(Msg->MsgID, Msg->MsgStd, Msg->MsgRTR, Msg->MsgDLC, Msg->Msg);
        break;
    }
    return 0;
}

void Can_Sleep_Fun(void)
{
}

void Can_SleepController_Fun(void)
{
}

void Can_Wakeup_Fun(void)
{
}

void Can_Uds_Abort(void)
{
    CANFD_SetTX_Abort();
}

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)
{
    CH0_BusOff_Recovery();
}