168 lines
4.2 KiB
C
168 lines
4.2 KiB
C
|
#include "r_cg_macrodriver.h"
|
|||
|
#include "r_cg_userdefine.h"
|
|||
|
#include "r_rl78_can_sfr.h"
|
|||
|
#include "r_rl78_can_drv.h"
|
|||
|
#include "appTask.h"
|
|||
|
#include "can_user.h"
|
|||
|
#include "CanNw.h"
|
|||
|
#include "PINdef.h"
|
|||
|
#include "extern.h"
|
|||
|
#include "hwCtrl.h"
|
|||
|
|
|||
|
|
|||
|
#define C_50MS_1MS 50
|
|||
|
|
|||
|
uint8_t rolling = 0;
|
|||
|
unsigned char App28sTxRxStatus = 3;
|
|||
|
unsigned char Nw28sTxRxStatus = 3;
|
|||
|
|
|||
|
Can_Msg_Type_188 CAN_188;
|
|||
|
|
|||
|
can_frame_t TxCanMessage;
|
|||
|
can_frame_t TxCanMessage1;
|
|||
|
can_frame_t RxCanMessage;
|
|||
|
|
|||
|
unsigned char CAN_SEND_COMPLETE;
|
|||
|
uint16_t air_req_timer = C_50MS_1MS;
|
|||
|
|
|||
|
unsigned char BusOff_flag = 0;
|
|||
|
unsigned char BusOff_IGN_cycle_count = 0;
|
|||
|
unsigned int BusOff_Detect_delay_count = 2000;
|
|||
|
|
|||
|
unsigned char Engine_Temperature, Engine_Temperature_temp;
|
|||
|
unsigned int Vehicle_Speed, Vehicle_Speed_temp;
|
|||
|
unsigned char Engine_Temperature_already, Vehicle_Speed_already;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
unsigned char DiagnosticSession_Present = 1; //
|
|||
|
unsigned char Tx_Rx_Enable = 3; // 0:none 1:Tx 2:Rx 3:Tx Rx
|
|||
|
|
|||
|
|
|||
|
extern uint16_t g_adval[12];
|
|||
|
|
|||
|
|
|||
|
void Copy_Array_to_Array(unsigned char *dest, unsigned char *src, unsigned char count)
|
|||
|
{
|
|||
|
unsigned char i = 0;
|
|||
|
|
|||
|
while (i < count)
|
|||
|
{
|
|||
|
i++;
|
|||
|
*dest++ = *src++;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void Can_Msg_Change_Bcm(void)
|
|||
|
{
|
|||
|
//CAN_45A.Msg_Part.SCM_MsgCounter = rolling;
|
|||
|
Copy_Array_to_Array(TxCanMessage.DB, CAN_188.Msg_Byte, 8);
|
|||
|
}
|
|||
|
|
|||
|
void CAN_TX_MESSAGE_INIT(void)
|
|||
|
{
|
|||
|
CAN_STB = 0;
|
|||
|
TxCanMessage.IDE = 0; /* IDE 0:Standard 1:Extend */
|
|||
|
TxCanMessage.RTR = 0; /* RTR 0:Data 1:Remote */
|
|||
|
TxCanMessage.THDSE = 0; /* Transmit History Data Store Enable */
|
|||
|
TxCanMessage.IDL = 0x188; /* ID Data (low) */
|
|||
|
TxCanMessage.IDH = 0; /* ID Data (high) */
|
|||
|
TxCanMessage.DLC = 8; /* DLC Data */
|
|||
|
TxCanMessage.LBL = 0; /* Label Data */
|
|||
|
TxCanMessage.TS = 0; /* Timestamp Data */
|
|||
|
rolling = 0;
|
|||
|
Can_Msg_Change_Bcm();
|
|||
|
}
|
|||
|
|
|||
|
//extern uint8_t flagOverCurrentKB,flagOverCurrentZY;
|
|||
|
uint8 txbuf1[8]={0},txbuf2[8],txbuf3[8];
|
|||
|
void TxTestMsg(void)
|
|||
|
{
|
|||
|
//uint8 i;
|
|||
|
//uint16_t temp;
|
|||
|
|
|||
|
if ((App28sTxRxStatus & DCM28S_MASK_TX_DISABLE) == 0)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
//txbuf1[0] = 0xff;
|
|||
|
|
|||
|
TransmitCAN_Message(0x333,8,txbuf1);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
void TxServe(void)
|
|||
|
{
|
|||
|
//Can_RtnType re_flag;
|
|||
|
static unsigned char sucNwSendCnt = 0;
|
|||
|
|
|||
|
////////////////////////////////////////////////////////////////////////
|
|||
|
if ((ucNwSendPduType == SEND_NWAPP_PDU) || (ucNwSendPduType == SEND_APP_PDU))
|
|||
|
{
|
|||
|
if (ucNwSendPduType == SEND_NWAPP_PDU)
|
|||
|
{
|
|||
|
if (uiNwPduCycCnt == 0)
|
|||
|
{
|
|||
|
uiNwPduCycCnt = uiSetNwPduCycVal;
|
|||
|
if ((Nw28sTxRxStatus & DCM28S_MASK_TX_DISABLE) != 0)
|
|||
|
{
|
|||
|
//R_CAN_TrmByTRFIFO0_CH0(&TxCanNwPdu_436);
|
|||
|
if (ImmediateNM_count < 5)
|
|||
|
ImmediateNM_count++;
|
|||
|
}
|
|||
|
}
|
|||
|
sucNwSendCnt = 0;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (sucNwSendCnt > 0)
|
|||
|
{
|
|||
|
if (uiNwPduCycCnt == 0)
|
|||
|
{
|
|||
|
sucNwSendCnt--;
|
|||
|
uiNwPduCycCnt = uiSetNwPduCycVal;
|
|||
|
if ((Nw28sTxRxStatus & DCM28S_MASK_TX_DISABLE) != 0)
|
|||
|
{
|
|||
|
R_CAN_TrmByTRFIFO0_CH0(&TxCanNwPdu_436);
|
|||
|
if (ImmediateNM_count < 5)
|
|||
|
ImmediateNM_count++;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
; /*sotp can transmit*/
|
|||
|
}
|
|||
|
//CAN_STB = 0;
|
|||
|
if ((air_req_timer == 0) && ((App28sTxRxStatus & DCM28S_MASK_TX_DISABLE) != 0))//
|
|||
|
{
|
|||
|
|
|||
|
Can_Msg_Change_Bcm();
|
|||
|
//re_flag = R_CAN_TrmByTRFIFO0_CH0(&TxCanMessage);
|
|||
|
R_CAN_TrmByTRFIFO0_CH0(&TxCanMessage);
|
|||
|
rolling++;
|
|||
|
if (rolling > 0x0F)
|
|||
|
{
|
|||
|
rolling = 0;
|
|||
|
}
|
|||
|
|
|||
|
//TxTestMsg();
|
|||
|
air_req_timer = C_50MS_1MS;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
void Can_init_id(can_frame_t *TxMessage, unsigned int canid)
|
|||
|
{
|
|||
|
TxMessage->IDE = 0;
|
|||
|
TxMessage->RTR = 0;
|
|||
|
TxMessage->THDSE = 0;
|
|||
|
TxMessage->IDL = canid;
|
|||
|
TxMessage->IDH = 0x0000;
|
|||
|
TxMessage->DLC = 8;
|
|||
|
TxMessage->LBL = 0;
|
|||
|
TxMessage->TS = 0;
|
|||
|
}
|