void ex1DefineDDDByID(void) { uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_FF | 0; sduData[1] = 8; sduData[2] = 0x2c; sduData[3] = 0x01; sduData[4] = 0xF2; //Id sduData[5] = 0x01; sduData[6] = 0x09; // Src Id sduData[7] = 0x99; pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 8; /* Send FF */ CanIf_Transmit(vCanIf_Channel_0, &pduinfo); WaitEvent(0x01); //Wait Flow Control ClearEvent(0x01); sduData[0] = ISO15765_TPCI_CF | 1; sduData[1] = 1; //position sduData[2] = 5; //size pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 3; /* Send CF */ CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
static void ex1RoutineControl(void) { uint8 sduData[8]; static uint8 callcnt = 0; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_SF | 4; sduData[1] = 0x31; callcnt++; switch(callcnt) { case 1: sduData[2] = 0x01; //start routine break; case 2: sduData[2] = 0x02; //stop routine break; case 3: sduData[2] = 0x03; //request routine result break; default: callcnt = 3; return; break; } sduData[3] = 0x08; //id = 0x0888; sduData[4] = 0x88; pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 5; CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
/* Dcm Example Main Function Routine. * 这个API必须被周期性的调用,建议每 5ms 一次*/ void DcmEx1MainFunction(void) { CanTp_MainFunction(); Dcm_MainFunction(); } #define ISO15765_TPCI_SF 0x00 /* Single Frame */ #define ISO15765_TPCI_FF 0x10 /* First Frame */ #define ISO15765_TPCI_CF 0x20 /* Consecutive Frame */ #define ISO15765_TPCI_FC 0x30 /* Flow Control */ #define ISO15765_TPCI_DL 0x7 /* Single frame data length mask */ #define ISO15765_TPCI_FS_MASK 0x0F /* Flowcontrol status mask */ static void ex1DiagnosticSessionControl(void) { static uint8 callcnt = 0; uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_SF | 2; sduData[1] = 0x10; callcnt++; switch(callcnt) { case 1: sduData[2] = 0x01; //default Session break; case 2: sduData[2] = 0x02; //program Session break; case 3: sduData[2] = 0x03; //extended Session break; case 4: sduData[2] = 0x04; //safety system Session break; default: callcnt = 0; break; } pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 3; CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
Inline void CanNm_Internal_TransmitMessage( const CanNm_ChannelType* ChannelConf, CanNm_Internal_ChannelType* ChannelInternal ) { PduInfoType pdu; Std_ReturnType status; pdu.SduDataPtr = ChannelInternal->TxMessageSdu; pdu.SduLength = ChannelConf->PduLength; status = CanIf_Transmit(ChannelConf->CanIfPduId, &pdu); (void)status; // TODO: what to do if Transmit fails? }
static void ex1TesterPresent(void) { uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_SF | 2; sduData[1] = 0x3e; sduData[2] = 0x00; pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 3; CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
static void ex1SecurityAccess_RequestSeed(void) { uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_SF|2; sduData[1] = 0x27; sduData[2] = 0x01|(1<<1); //requestSeed,want to set level 1 pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 3; CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
static void ex1SendFC(void) { uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = 0x30; /* Flow Control */ sduData[1] = 3; //BS sduData[2] = 10; //stmin pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 3; CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
static void ex1ReadScalingDataById(void) { uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_SF | 3; sduData[1] = 0x24; sduData[2] = 0x09; //id = 0x0999; sduData[3] = 0x99; pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 4; CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
static void ex1ReadDataById(uint16 id) { uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_SF | 3; sduData[1] = 0x22; sduData[2] = (uint8)(id>>8)&0xFFU; //id = ; sduData[3] = (uint8)(id)&0xFFU; pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 4; CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
static void ex1ReadDatabyIdPeriodStop(uint16 id) { uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_SF | 3; sduData[1] = 0x2A; sduData[2] = DCM_PERIODICTRANSMIT_STOPSENDING_MODE; sduData[3] = (uint8)(id)&0xFFU; pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 4; CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
static void ex1SecurityAccess_SendKey(void) { uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_SF | 3; sduData[1] = 0x27; sduData[2] = 0x02; //sendKey,want to set level 1 sduData[3] = 0xEF; pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 4; CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
static void ex1ClearDefineDDDByID(void) { uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_SF | 4; sduData[1] = 0x2c; sduData[2] = 0x03; sduData[3] = 0xF2; //Id sduData[4] = 0x01; pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 5; /* Send SF */ CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
static void ex1IoControl(void) { uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_SF | 4; sduData[1] = 0x2F; sduData[2] = 0x09; //Id sduData[3] = 0x99; sduData[4] = 0x01; //option pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 5; /* Send SF */ CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
static void ex1WriteDataById(void) { uint8 sduData[8]; PduInfoType pduinfo; sduData[0] = ISO15765_TPCI_SF | 7; sduData[1] = 0x2E; sduData[2] = 0x09; //id = 0x0999; sduData[3] = 0x99; sduData[4] = 0x11; sduData[5] = 0x22; sduData[6] = 0x33; sduData[7] = 0x44; pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 8; CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
Std_ReturnType PduR_ARC_RouteTransmit(const PduRDestPdu_type * destination, const PduInfoType * pduInfo) { Std_ReturnType retVal = E_NOT_OK; switch (destination->DestModule) { case ARC_PDUR_CANIF: #if PDUR_CANIF_SUPPORT == STD_ON retVal = CanIf_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_COM: #if PDUR_COM_SUPPORT == STD_ON Com_RxIndication(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_LINIF: #if PDUR_LINIF_SUPPORT == STD_ON retVal = LinIf_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_CANTP: #if PDUR_CANTP_SUPPORT == STD_ON retVal = CanTp_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_SOADIF: #if PDUR_SOAD_SUPPORT == STD_ON retVal = SoAdIf_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_SOADTP: #if PDUR_SOAD_SUPPORT == STD_ON retVal = SoAdTp_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_J1939TP: #if PDUR_J1939TP_SUPPORT == STD_ON retVal = J1939Tp_Transmit(destination->DestPduId, pduInfo); #endif break; default: retVal = E_NOT_OK; break; } // TODO error reporting here. return retVal; }
static void ex1EcuReset(void) { uint8 sduData[8]; PduInfoType pduinfo; static uint8 callcnt = 0; sduData[0] = ISO15765_TPCI_SF | 2; sduData[1] = 0x11; callcnt++; switch(callcnt) { case 1: sduData[2] = 0x01; //hard reset,infact only this sub function was supported. // But as Mcu was not integrated,So this API has no effect. break; case 2: sduData[2] = 0x02; //key off on reset break; case 3: sduData[2] = 0x03; //soft reset break; case 4: sduData[2] = 0x04; break; case 5: sduData[2] = 0x05; break; default: callcnt = 5; return; break; } pduinfo.SduDataPtr = sduData; pduinfo.SduLength = 3; CanIf_Transmit(vCanIf_Channel_0, &pduinfo); }
Std_ReturnType PduR_ARC_RouteTransmit(const PduRDestPdu_type * destination, const PduInfoType * pduInfo) { /* @req PDUR160 */ /* @req PDUR629 */ /* @req PDUR0745 */ /* @req PDUR625 */ Std_ReturnType retVal = E_NOT_OK; switch (destination->DestModule) { case ARC_PDUR_CANIF: #if PDUR_CANIF_SUPPORT == STD_ON retVal = CanIf_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_COM: #if PDUR_COM_SUPPORT == STD_ON Com_RxIndication(destination->DestPduId, (PduInfoType *)pduInfo); #endif break; case ARC_PDUR_LINIF: #if PDUR_LINIF_SUPPORT == STD_ON retVal = LinIf_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_CANTP: #if PDUR_CANTP_SUPPORT == STD_ON retVal = CanTp_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_SOADIF: #if PDUR_SOAD_SUPPORT == STD_ON retVal = SoAdIf_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_SOADTP: #if PDUR_SOAD_SUPPORT == STD_ON retVal = SoAdTp_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_J1939TP: #if PDUR_J1939TP_SUPPORT == STD_ON retVal = J1939Tp_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_IPDUM: #if PDUR_IPDUM_SUPPORT == STD_ON retVal = IpduM_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_FRIF: #if PDUR_FRIF_SUPPORT == STD_ON retVal = FrIf_Transmit(destination->DestPduId, pduInfo); #endif break; case ARC_PDUR_FRTP: #if PDUR_FRTP_SUPPORT == STD_ON retVal = FrTp_Transmit(destination->DestPduId, pduInfo); #endif break; default: retVal = E_NOT_OK; break; } return retVal; }
void CAN_InterfaceTest(const char* driverName, int sendcountmax, int baud, int config) { int cnt; sendcount = 0; recvcount = 0; time_t t_start, t_end; Std_ReturnType std_ret; /* CanIf_ConfigTypeはAUTOSARの仕様に準拠したため、本バージョンでは未使用。NULLを指定する */ CanIf_Init(NULL); /* AUTOSARの仕様に準拠し、各種設定は静的なデータとしてコンパイル時に確定させる。 本サンプルプログラムでは、テストのため内部設定を直接書き換える。 CanIfConfigurationsは、CanIf_Initの実行後に修正する必要がある */ /* ドライバ名の設定 */ CanIfConfigurations.initConfiguration[RECVCFG].ConfigSet.driverName = driverName; CanIfConfigurations.initConfiguration[SENDCFG].ConfigSet.driverName = driverName; /* ボーレートの設定 */ CanIfConfigurations.initConfiguration[RECVCFG].ConfigSet.baudRate = baud; CanIfConfigurations.initConfiguration[SENDCFG].ConfigSet.baudRate = baud; /* Acceptフィルタの設定 */ CanIfConfigurations.initConfiguration[RECVCFG].ConfigSet.acceptCode = 0x00000000; CanIfConfigurations.initConfiguration[RECVCFG].ConfigSet.acceptMask = 0xffffffff; CanIfConfigurations.initConfiguration[SENDCFG].ConfigSet.acceptCode = 0x00000000; CanIfConfigurations.initConfiguration[SENDCFG].ConfigSet.acceptMask = 0xffffffff; /* PDU-IDの登録 */ CanIfConfigurations.initConfiguration[RECVCFG].CanIfNumberOfCanRxPduIds = 1; CanIfConfigurations.initConfiguration[RECVCFG].CanIfRxPduConfigList[0].CanIfCanRxPduCanId = RECV_PDUID; CanIfConfigurations.initConfiguration[RECVCFG].CanIfRxPduConfigList[0].CanIfCanRxPduId = RECV_PDUID; CanIfConfigurations.initConfiguration[RECVCFG].CanIfNumberOfCanTxPduIds = 0; CanIfConfigurations.initConfiguration[RECVCFG].CanIfNumberOfDynamicCanTxPduIds = 0; CanIfConfigurations.initConfiguration[SENDCFG].CanIfNumberOfCanTxPduIds = 1; CanIfConfigurations.initConfiguration[SENDCFG].CanIfTxPduConfigList[0].CanIfTxPduIdCanId = SEND_PDUID; CanIfConfigurations.initConfiguration[SENDCFG].CanIfTxPduConfigList[0].CanIfCanTxPduId = SEND_PDUID; CanIfConfigurations.initConfiguration[SENDCFG].CanIfNumberOfCanRxPduIds = 0; CanIfConfigurations.initConfiguration[SENDCFG].CanIfNumberOfDynamicCanTxPduIds = 0; /* 受信コールバックの設定 */ CanIfConfigurations.initConfiguration[RECVCFG].CanIfRxPduConfigList[0].CanIfRxUserType = CANIF_CAN_NM; if(config == 0) { CanIfConfigurations.initConfiguration[RECVCFG].CanIfRxPduConfigList[0].CanIfUserRxIndication = CanRxCallback; CanIfConfigurations.initConfiguration[SENDCFG].CanIfTxPduConfigList[0].CanIfUserTxConfirmtion = CanTxCallback; } else { CanIfConfigurations.initConfiguration[RECVCFG].CanIfRxPduConfigList[0].CanIfUserRxIndication = NULL; CanIfConfigurations.initConfiguration[SENDCFG].CanIfTxPduConfigList[0].CanIfUserTxConfirmtion = NULL; } /* コントローラの初期化 */ CanIf_InitController(sendController, SENDCFG); CanIf_InitController(recvController, RECVCFG); if (CanIf_SetControllerMode(sendController, CANIF_CS_STARTED) != E_OK) { printf("CanIf_SetControllerMode(0, CANIF_CS_STARTED) failed\n"); return; } if (CanIf_SetControllerMode(recvController, CANIF_CS_STARTED) != E_OK) { printf("CanIf_SetControllerMode(1, CANIF_CS_STARTED) failed\n"); return; } time(&t_start); for(cnt = 0; (cnt < (sendcountmax * 5) && recvcount < sendcountmax); ++cnt) { Dem_Sleep(1000); /* 送信テスト */ if(sub_loop_trg == 0 && sendcount < sendcountmax) { PduInfoType pduInfo; uint8 buf[8]; sprintf((char*)buf, "UU%4.4d*", cnt); buf[7] = 0x00; pduInfo.SduDataPtr = buf; pduInfo.SduLength = 8; do{ /* エラーの時はリトライして待つ */ std_ret = CanIf_Transmit(SEND_PDUID, &pduInfo); printf("CanIf_Transmit std_ret = %d, cnt = %d\n",std_ret ,cnt); }while(std_ret != E_OK); printf("Transmit ch:%d to ch:%d: ID:%x '%8.8s'\n", sendController, recvController, SEND_PDUID, pduInfo.SduDataPtr); ++sendcount; } // ヒステリシスを持った、送信の制御 if(sub_loop_trg == 0) { if((sendcount - recvcount) >= sub_loop_limit) sub_loop_trg = 1; } else { if((sendcount - recvcount) < (sub_loop_limit / 4)) sub_loop_trg = 0; } if (config == 1) { /* 受信テスト */ if (CanIf_ReadRxPduData(RECV_PDUID, &recvData) == E_OK) { /* 受信データあり */ printf("Receive ch:%d ID:%x '%8.8s'\n", recvController, RECV_PDUID, recvData.SduDataPtr); ++recvcount; } } } if (recvcount == sendcountmax) { printf("All data received. (%d/%d)\n", recvcount, sendcountmax); } else { printf("%d data lost.(%d/%d)\n", sendcountmax - recvcount, recvcount, sendcountmax); } time(&t_end); printf("Total time: %d [Sec]\n", (t_end - t_start)); /* 終了処理の追加 */ CanIf_Deinit(); }