#include "uds_config.h" #include "bsp_can.h" #if BOOTLOADER_CODE_FLAG == 0 //#include "nm_can.h" #endif _QueueCan0Tx QueueCan0Tx; _QueueCan0Rx UdsQueueData; INT8U gAppCanTxErrFlg=0; INT8U gUdsBusOffCanOutBak=0; bool bCan0InitOkFlg; extern void HAL_UDS_Tx_Callback(void); extern xchrTime ign1; extern xchrTime ign3; INT32U TestCanRxCnt=0,TestCanRxCntBak=0; INT32U ParseCanRxCnt=0; void DealCanProc(void) { bCan0InitOkFlg=true; return; } void DealCanProc_bussoff(void) { } void ParseUdsCan(can_msg_t pCanMsg) { UdsService.IsUdsFlg=true; UdsService.SessionTimer=0; //Debug("Can Bus Off 00\r\n"); switch(pCanMsg.id) { case UDS_PHY_TX_ID://NAMS Request 0x787 Response 0x78F UdsService.CanID = UDS_PHY_TX_ID; HAL_UDS_PHY_Rx_Callback(pCanMsg.data,pCanMsg.dlc); break; case UDS_FUN_TX_ID: UdsService.CanID = UDS_FUN_TX_ID; HAL_UDS_FUN_Rx_Callback(pCanMsg.data,pCanMsg.dlc); break; default: break; } } INT8U checkPin(INT8U bcheck,xchrTime *pt,INT8U g) { if((bcheck==0)&&(pt->state!='L')) { pt->Time1++; if(pt->Time1>=g) // { pt->state='L'; return('L'); } } else if((bcheck==1)&&(pt->state!='H')) { pt->Time2++; if(pt->Time2>=g) // { pt->state='H'; return('H'); } } else { pt->Time1=pt->Time2=0; } return(0); } void UdsQueueCanIn(can_msg_t RxCanMsg) { #if BOOTLOADER_CODE_FLAG == 0 //if(CAN_Status == DisableTxAndRx) return; #endif if(RxCanMsg.id == UDS_FUN_TX_ID || RxCanMsg.id == UDS_PHY_TX_ID ) { if(UdsQueueData.In>=CAN0_MAX_RX) UdsQueueData.In=0; UdsQueueData.CanMsg[UdsQueueData.In].id = RxCanMsg.id; UdsQueueData.CanMsg[UdsQueueData.In].dlc = RxCanMsg.dlc; UdsQueueData.CanMsg[UdsQueueData.In].flag = RxCanMsg.flag; memcpy((void *)&UdsQueueData.CanMsg[UdsQueueData.In].data[0],(void *)&RxCanMsg.data[0],8); UdsQueueData.In++; } return; } void TxQueueCan0In(can_msg_t TxCanMsg) { //if(('L' == ign1.state)&&(acc_status == _ACC_NORMAL)) // if((('L' == ign3.state)||('L' == ign1.state))) { if(QueueCan0Tx.In>=CAN0_MAX_RX) QueueCan0Tx.In=0; QueueCan0Tx.CanMsg[QueueCan0Tx.In].id = TxCanMsg.id; QueueCan0Tx.CanMsg[QueueCan0Tx.In].dlc = TxCanMsg.dlc; QueueCan0Tx.CanMsg[QueueCan0Tx.In].flag = TxCanMsg.flag; memcpy((void *)&QueueCan0Tx.CanMsg[QueueCan0Tx.In].data[0],(void *)&TxCanMsg.data[0],8); QueueCan0Tx.In++; } return; } can_msg_t TxCan0Bak; void TxQueueCan0Out(void) { // can_msg_t canmsg = {0}; //if(UdsService.EnRxAndTx) return; if(g_ulCanStatus) return; if(TRUE != CanRxConStatus()) return; while( QueueCan0Tx.In != QueueCan0Tx.Out ) { if(QueueCan0Tx.Out >= CAN0_MAX_RX) { QueueCan0Tx.Out=0; } // canmsg.id = QueueCan0Tx.CanMsg[QueueCan0Tx.Out].id; // canmsg.dlc = QueueCan0Tx.CanMsg[QueueCan0Tx.Out].dlc; // memcpy(canmsg.data,QueueCan0Tx.CanMsg[QueueCan0Tx.Out].data,8); UdsApi_MsgQueueOut(QueueCan0Tx.CanMsg[QueueCan0Tx.Out]); UdsService.UdsTxCompFlg=true; UdsService.TxUdsChann=0; QueueCan0Tx.Out++; break; } } extern void DTC_SignalInit(void); extern void DID_SignalInit(void); extern void UDS_ServiceInit(void); void UdsProcTask(void) { // static INT8U Timer10MsCnt = 0; static INT16U Timer1000MsCnt = 0; static INT16U Timer200MsCnt = 0; static INT16U Timer20MsCnt = 0; static INT8U InitFlag = 0; if(InitFlag == 0) { UdsApi_ParaInit(); // DID_SignalInit(); // DTC_SignalInit(); UDS_ServiceInit(); InitFlag = 1; } //等待复位,不处理UDS其他任务 if (UdsService.ResetMcuFlg) { if(UdsService.RstTimer) { UdsService.RstTimer--; } else { UdsService.ResetMcuFlg = false; NVIC_SystemReset(); } return; } if(++Timer1000MsCnt >= 4) { Timer1000MsCnt = 0; UDS_Demo_Services_Start(); UdsService.StartFlg=true; UdsService.FrameType=0; UdsQueueCanOut(); Timer20MsCnt = 0; } if (++Timer200MsCnt >= CALL_RATE_TP) { Timer200MsCnt = 0; UDS_Demo_Services_Sequence(); HAL_UDS_Periodic_Task(); if((FIRST_FRAME == UdsService.FrameType)||((CONSECUTIVE_FRAME == UdsService.FrameType))) { if(++Timer20MsCnt>=CALL_RATE_TP) { Timer20MsCnt=0; UdsQueueCanOut(); } } } TxQueueCan0Out(); GotoDefaultSession(); CheckDtcHsCanError(); UDS_Nrc78PostProcessing(); return; } //"${workspace_loc:/${ProjName}/SDK}"