/** * Function that finds the Hoh( HardwareObjectHandle ) from a Hth * A HTH may connect to one or several HOH's. Just find the first one. * * @param hth The transmit handle * @returns Ptr to the Hoh */ static const Can_HardwareObjectType * Can_FindHoh( Can_Arc_HTHType hth , uint32* controller) { const Can_HardwareObjectType *hohObj; const Can_ObjectHOHMapType *map; //const Can_ControllerConfigType *canHwConfig; map = &Can_Global.CanHTHMap[hth]; // Verify that this is the correct map if (map->CanHOHRef->CanObjectId != hth) { DET_REPORTERROR(MODULE_ID_CAN, 0, 0x6, CAN_E_PARAM_HANDLE); } //canHwConfig= CAN_GET_CONTROLLER_CONFIG(Can_Global.channelMap[map->CanControllerRef]); hohObj = map->CanHOHRef; // Verify that this is the correct Hoh type if ( hohObj->CanObjectType == CAN_OBJECT_TYPE_TRANSMIT) { *controller = map->CanControllerRef; return hohObj; } DET_REPORTERROR(MODULE_ID_CAN, 0, 0x6, CAN_E_PARAM_HANDLE); return NULL; }
/** @req SOAD093 */ void SoAd_Init(void) { sint16 i, j; // Initiate the socket administration list for (i = 0; i < SOAD_SOCKET_COUNT; i++) { SocketAdminList[i].SocketNr = i; SocketAdminList[i].SocketState = SOCKET_INIT; SocketAdminList[i].SocketConnectionRef = &SoAd_Config.SocketConnection[i]; SocketAdminList[i].RemoteIpAddress = inet_addr(SoAd_Config.SocketConnection[i].SocketRemoteIpAddress); SocketAdminList[i].RemotePort = htons(SoAd_Config.SocketConnection[i].SocketRemotePort); SocketAdminList[i].SocketHandle = -1; SocketAdminList[i].ConnectionHandle = -1; SocketAdminList[i].SocketProtocolIsTcp = FALSE; if (SoAd_Config.SocketConnection[i].SocketProtocol == SOAD_SOCKET_PROT_TCP) { SocketAdminList[i].SocketProtocolIsTcp = TRUE; } else if (SoAd_Config.SocketConnection[i].SocketProtocol != SOAD_SOCKET_PROT_UDP) { // Configuration error!!! DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_INIT_ID, SOAD_E_CONFIG_INVALID); } // Check if several connections are expected on this port. for (j = 0; j < i; j++) { if ((SoAd_Config.SocketConnection[i].SocketProtocol == SoAd_Config.SocketConnection[j].SocketProtocol) && (SoAd_Config.SocketConnection[i].SocketLocalPort == SoAd_Config.SocketConnection[j].SocketLocalPort)) { SocketAdminList[i].SocketState = SOCKET_DUPLICATE; break; } } } // Cross reference from SocketAdminList to SocketRoute for (i = 0; i < SOAD_SOCKET_ROUTE_COUNT; i++) { if (SoAd_Config.SocketRoute[i].SourceSocketRef != NULL) { if (SoAd_Config.SocketRoute[i].SourceSocketRef->SocketId < SOAD_SOCKET_COUNT) { SocketAdminList[SoAd_Config.SocketRoute[i].SourceSocketRef->SocketId].SocketRouteRef = &SoAd_Config.SocketRoute[i]; } else { DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_INIT_ID, SOAD_E_CONFIG_INVALID); } } else { DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_INIT_ID, SOAD_E_CONFIG_INVALID); } } // Initialize PduStatus of PduAdminList for (i = 0; i < SOAD_PDU_ROUTE_COUNT; i++) { PduAdminList[i].PduStatus = PDU_IDLE; } DoIp_Init(); TcpIp_Init(); ModuleStatus = SOAD_INITIALIZED; }
static CanIf_Arc_ChannelIdType CanIf_Arc_FindHrhChannel( Can_Arc_HRHType hrh ) { const CanIf_InitHohConfigType *hohConfig; const CanIf_HrhConfigType *hrhConfig; // foreach(hoh){ foreach(hrh in hoh) {} } hohConfig = CanIf_ConfigPtr->InitConfig->CanIfHohConfigPtr; hohConfig--; do { hohConfig++; hrhConfig = hohConfig->CanIfHrhConfig; hrhConfig--; do { hrhConfig++; if (hrhConfig->CanIfHrhIdSymRef == hrh){ return hrhConfig->CanIfCanControllerHrhIdRef; } } while(!hrhConfig->CanIf_Arc_EOL); } while(!hohConfig->CanIf_Arc_EOL); DET_REPORTERROR(MODULE_ID_CANIF, 0, CANIF_RXINDICATION_ID, CANIF_E_PARAM_HRH); return (CanIf_Arc_ChannelIdType) -1; }
BufReq_ReturnType Com_CopyRxData(PduIdType PduId, const PduInfoType* PduInfoPtr, PduLengthType* RxBufferSizePtr) { /* !req COM782 */ /* If pdu group stopped -> return BUFREQ_E_NOT_OK */ imask_t state; BufReq_ReturnType r = BUFREQ_OK; uint8 remainingBytes; boolean sizeOk; boolean dirOk; boolean lockOk; if(COM_INIT != initStatus) { DET_REPORTERROR(COM_COPYRXDATA_ID, COM_E_UNINIT); return BUFREQ_NOT_OK; } Irq_Save(state); /* @req COM658 */ /* Interrupts disabled */ remainingBytes = GET_IPdu(PduId)->ComIPduSize - Com_BufferPduState[PduId].currentPosition; sizeOk = remainingBytes >= PduInfoPtr->SduLength; dirOk = GET_IPdu(PduId)->ComIPduDirection == RECEIVE; lockOk = isPduBufferLocked(PduId); if (dirOk && lockOk && sizeOk) { memcpy((void *)((uint8 *)GET_ArcIPdu(PduId)->ComIPduDataPtr+Com_BufferPduState[PduId].currentPosition), PduInfoPtr->SduDataPtr, PduInfoPtr->SduLength); Com_BufferPduState[PduId].currentPosition += PduInfoPtr->SduLength; *RxBufferSizePtr = GET_IPdu(PduId)->ComIPduSize - Com_BufferPduState[PduId].currentPosition; } else { r = BUFREQ_NOT_OK; } Irq_Restore(state); return r; }
const CanIf_HthConfigType* CanIf_Arc_GetTransmitHandler(CanIf_Arc_ChannelIdType Channel) { const CanIf_InitHohConfigType *hohConfig; const CanIf_HthConfigType *hthConfig; // foreach(hoh){ foreach(hrh in hoh) {} } hohConfig = CanIf_ConfigPtr->InitConfig->CanIfHohConfigPtr; hohConfig--; do { hohConfig++; hthConfig = hohConfig->CanIfHthConfig; hthConfig--; do { hthConfig++; if (hthConfig->CanIfCanControllerIdRef == Channel) return hthConfig; } while(!hthConfig->CanIf_Arc_EOL); } while(!hohConfig->CanIf_Arc_EOL); DET_REPORTERROR(MODULE_ID_CANIF, 0, 0xFF, CANIF_E_PARAM_HTH); return NULL; }
/** * * @param PduId * @param PduInfoPtr * @param RetryInfoPtr not supported * @param TxDataCntPtr * @return */ BufReq_ReturnType Com_CopyTxData(PduIdType PduId, PduInfoType* PduInfoPtr, RetryInfoType* RetryInfoPtr, PduLengthType* TxDataCntPtr) { /* TODO: Validate PduId, etc? */ /* !req COM663*/ /* !req COM783*/ /* Do not copy any data and return BUFREQ_E_NOT_OK if pdu group stopped */ imask_t state; BufReq_ReturnType r = BUFREQ_OK; if(COM_INIT != initStatus) { DET_REPORTERROR(COM_COPYTXDATA_ID, COM_E_UNINIT); return BUFREQ_NOT_OK; } const ComIPdu_type *IPdu = GET_IPdu(PduId); boolean dirOk = ComConfig->ComIPdu[PduId].ComIPduDirection == SEND; boolean sizeOk; (void)RetryInfoPtr; // get rid of compiler warning Irq_Save(state); sizeOk = IPdu->ComIPduSize >= Com_BufferPduState[PduId].currentPosition + PduInfoPtr->SduLength; Com_BufferPduState[PduId].locked = true; if (dirOk && sizeOk) { void* source = (void *)GET_ArcIPdu(PduId)->ComIPduDataPtr; memcpy(PduInfoPtr->SduDataPtr,(uint8 *)source + Com_BufferPduState[PduId].currentPosition, PduInfoPtr->SduLength); Com_BufferPduState[PduId].currentPosition += PduInfoPtr->SduLength; *TxDataCntPtr = IPdu->ComIPduSize - Com_BufferPduState[PduId].currentPosition; } else { r = BUFREQ_NOT_OK; } Irq_Restore(state); return r; }
void Com_ClearIpduGroupVector(Com_IpduGroupVector ipduGroupVector) { if(COM_INIT != initStatus) { DET_REPORTERROR(COM_CLEARIPDUGROUPVECTOR_ID, COM_E_UNINIT); return; } memset(ipduGroupVector, 0, sizeof(Com_IpduGroupVector)); }
void Com_DeInit( void ) { if(COM_INIT != initStatus) { DET_REPORTERROR(COM_DEINIT_ID, COM_E_UNINIT); return; } /* @req COM129 */ for (uint16 i = 0; !ComConfig->ComIPdu[i].Com_Arc_EOL; i++) { Com_Arc_Config.ComIPdu[i].Com_Arc_IpduStarted = 0; } initStatus = COM_UNINIT; }
// // This function implements the requirement DCM139 when // transition from one session to another. // static void changeDiagnosticSession(Dcm_DslRunTimeProtocolParametersType *runtime, Dcm_SesCtrlType newSession) { /** @req DCM139 */ switch (runtime->sessionControl) { case DCM_DEFAULT_SESSION: // "default". /* to set the dsp buffer to default*/ DspInit(); break; case DCM_PROGRAMMING_SESSION: case DCM_EXTENDED_DIAGNOSTIC_SESSION: case DCM_SAFTEY_SYSTEM_DIAGNOSTIC_SESSION: case DCM_ALL_SESSION_LEVEL: runtime->securityLevel = DCM_SEC_LEV_LOCKED; // "0x00". break; default: DET_REPORTERROR(MODULE_ID_DCM, 0, DCM_CHANGE_DIAGNOSTIC_SESSION_ID, DCM_E_PARAM); DEBUG(DEBUG_MEDIUM, "Old session invalid"); break; } switch (newSession) { case DCM_DEFAULT_SESSION: // "default". case DCM_PROGRAMMING_SESSION: case DCM_EXTENDED_DIAGNOSTIC_SESSION: case DCM_SAFTEY_SYSTEM_DIAGNOSTIC_SESSION: case DCM_ALL_SESSION_LEVEL: runtime->sessionControl = newSession; break; default: DET_REPORTERROR(MODULE_ID_DCM, 0, DCM_CHANGE_DIAGNOSTIC_SESSION_ID, DCM_E_PARAM); DEBUG(DEBUG_MEDIUM, "New session invalid"); break; } }
const Dcm_DspSessionRowType *getActiveSessionRow(Dcm_DslRunTimeProtocolParametersType *runtime) { const Dcm_DspSessionRowType *sessionRow = DCM_Config.Dsp->DspSession->DspSessionRow; while ((sessionRow->DspSessionLevel != runtime->sessionControl) && (!sessionRow->Arc_EOL) ) { sessionRow++; } if( TRUE == sessionRow->Arc_EOL ) { /* Since we are in a session with no configuration - take any session configuration and report error */ DET_REPORTERROR(MODULE_ID_DCM, 0, DCM_CHANGE_DIAGNOSTIC_SESSION_ID, DCM_E_CONFIG_INVALID); sessionRow = DCM_Config.Dsp->DspSession->DspSessionRow; } return sessionRow; }
void Com_SetIpduGroup(Com_IpduGroupVector ipduGroupVector, Com_IpduGroupIdType ipduGroupId, boolean bitval) { if(COM_INIT != initStatus) { DET_REPORTERROR(COM_SETIPDUGROUP_ID, COM_E_UNINIT); return; } uint8 byteIndex; uint8 bitIndex; byteIndex = ipduGroupId / 8; bitIndex = ipduGroupId % 8; /* @req COM623 */ if( bitval ) { ipduGroupVector[byteIndex] |= (1u<<bitIndex); } else { ipduGroupVector[byteIndex] &= ~(1u<<bitIndex); } }
static void scanSockets(void) { uint16 i; for (i = 0; i < SOAD_SOCKET_COUNT; i++) { // pi_printf("infor: scan sockets "); mini_uart_sendDec(i); pi_printf(" \r\n"); switch (SocketAdminList[i].SocketState) { case SOCKET_INIT: socketCreate(i); // pi_printf("infor: socket create"); mini_uart_sendDec(i); pi_printf(" \r\n"); break; case SOCKET_TCP_LISTENING: socketAccept(i); // pi_printf("infor: socket accept"); mini_uart_sendDec(i); pi_printf(" \r\n"); break; case SOCKET_TCP_READY: // pi_printf("infor: socket read "); mini_uart_sendDec(i); pi_printf(" \r\n"); socketTcpRead(i); break; case SOCKET_UDP_READY: socketUdpRead(i); break; case SOCKET_DUPLICATE: /* Do nothing */ break; default: /* This should never happen! */ DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_SCAN_SOCKETS_ID, SOAD_E_SHALL_NOT_HAPPEN); break; } /* End of switch */ } /* End of for */ }
void SoAd_SocketClose(uint16 sockNr) { uint16 i; switch (SocketAdminList[sockNr].SocketState) { case SOCKET_UDP_READY: case SOCKET_TCP_LISTENING: lwip_close(SocketAdminList[sockNr].SocketHandle); SocketAdminList[sockNr].SocketHandle = -1; SocketAdminList[sockNr].SocketState = SOCKET_INIT; break; case SOCKET_TCP_READY: lwip_close(SocketAdminList[sockNr].ConnectionHandle); SocketAdminList[sockNr].ConnectionHandle = -1; SocketAdminList[sockNr].RemoteIpAddress = inet_addr(SoAd_Config.SocketConnection[sockNr].SocketRemoteIpAddress); SocketAdminList[sockNr].RemotePort = htons(SoAd_Config.SocketConnection[sockNr].SocketRemotePort); SocketAdminList[sockNr].SocketState = SOCKET_TCP_LISTENING; for (i = 0; i < SOAD_SOCKET_COUNT; i++) { if (i == sockNr) continue; if (SocketAdminList[sockNr].SocketHandle == SocketAdminList[i].SocketHandle) { if (SocketAdminList[i].SocketState == SOCKET_TCP_LISTENING) { SocketAdminList[sockNr].SocketState = SOCKET_DUPLICATE; break; } } } break; default: /* This should never happen! */ DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_SOCKET_CLOSE_ID, SOAD_E_SHALL_NOT_HAPPEN); break; } }
void Com_IpduGroupControl(Com_IpduGroupVector ipduGroupVector, boolean Initialize) { /* !req COM614 */ /* Starting groups */ /* @req COM114 */ /* !req COM787 */ /* !req COM222 */ /* !req COM733 */ /* !req COM740 */ /* Stopping groups */ /* !req COM479 */ /* !req COM713 */ /* !req COM714 */ (void)Initialize; // Nothing to be done. This is just to avoid Lint warning. if(COM_INIT != initStatus) { DET_REPORTERROR(COM_IPDUGROUPCONTROL_ID, COM_E_UNINIT); return; } for (uint16 i = 0; !ComConfig->ComIPdu[i].Com_Arc_EOL; i++) { const ComIPduGroup_type *const groupRefs = ComConfig->ComIPdu[i].ComIPduGroupRefs; uint8 started = FALSE; for(uint32 gri=0; (!groupRefs[gri].Com_Arc_EOL && !started); gri++) { uint8 byteIndex; uint8 bitIndex; byteIndex = groupRefs[gri].ComIPduGroupHandleId / 8; bitIndex = groupRefs[gri].ComIPduGroupHandleId % 8; /* @req COM771 */ started |= ((ipduGroupVector[byteIndex] >> bitIndex) & 1u); } /* @req COM612 */ /* @req COM613 */ /* @req COM615 */ Com_Arc_Config.ComIPdu[i].Com_Arc_IpduStarted = started; } }
BufReq_ReturnType Com_StartOfReception(PduIdType ComRxPduId, PduLengthType TpSduLength, PduLengthType* RxBufferSizePtr) { /* TODO: Validate ComRxPduId? */ PduLengthType ComIPduSize; imask_t state; BufReq_ReturnType r = BUFREQ_OK; if(COM_INIT != initStatus) { DET_REPORTERROR(COM_STARTOFRECEPTION_ID, COM_E_UNINIT); return BUFREQ_NOT_OK; } Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(ComRxPduId); Irq_Save(state); if (Arc_IPdu->Com_Arc_IpduStarted) { if (GET_IPdu(ComRxPduId)->ComIPduDirection == RECEIVE) { /* !req COM657 */ if (!Com_BufferPduState[ComRxPduId].locked) { ComIPduSize = GET_IPdu(ComRxPduId)->ComIPduSize; if (ComIPduSize >= TpSduLength) { Com_BufferPduState[ComRxPduId].locked = true; *RxBufferSizePtr = ComIPduSize; /* @req COM656 */ Com_SetDynSignalLength(ComRxPduId,TpSduLength); } else { /* @req COM654 */ /* @req COM655 */ r = BUFREQ_OVFL; } } else { r = BUFREQ_BUSY; } } } else { /* @req COM721 */ r = BUFREQ_NOT_OK; } Irq_Restore(state); return r; }
void CanIf_RxIndication(uint8 Hrh, Can_IdType CanId, uint8 CanDlc, const uint8 *CanSduPtr) { VALIDATE_NO_RV(CanIf_Global.initRun, CANIF_RXINDICATION_ID, CANIF_E_UNINIT); VALIDATE_NO_RV(CanSduPtr != NULL, CANIF_RXINDICATION_ID, CANIF_E_PARAM_POINTER); /* Check PDU mode before continue processing */ CanIf_ChannelGetModeType mode; CanIf_Arc_ChannelIdType channel = CanIf_Arc_FindHrhChannel( (Can_Arc_HRHType) Hrh); if (channel == -1) // Invalid HRH { return; } if (CanIf_GetPduMode(channel, &mode) == E_OK) { if ( (mode == CANIF_GET_OFFLINE) || (mode == CANIF_GET_TX_ONLINE) || (mode == CANIF_GET_OFFLINE_ACTIVE) ) { // Receiver path is disabled so just drop it return; } } else { return; // No mode so just return } const CanIf_RxPduConfigType *entry = CanIf_ConfigPtr->InitConfig->CanIfRxPduConfigPtr; /* Find the CAN id in the RxPduList */ for (uint16 i = 0; i < CanIf_ConfigPtr->InitConfig->CanIfNumberOfCanRxPduIds; i++) { if (entry->CanIfCanRxPduHrhRef->CanIfHrhIdSymRef == Hrh) { // Software filtering if (entry->CanIfCanRxPduHrhRef->CanIfHrhType == CAN_ARC_HANDLE_TYPE_BASIC) { if (entry->CanIfCanRxPduHrhRef->CanIfSoftwareFilterHrh) { if (entry->CanIfSoftwareFilterType == CANIF_SOFTFILTER_TYPE_MASK) { if ((CanId & entry->CanIfCanRxPduCanIdMask ) == ( entry->CanIfCanRxPduCanId & entry->CanIfCanRxPduCanIdMask)) { // We found a pdu so call higher layers } else { entry++; continue; // Go to next entry } } else { DET_REPORTERROR(MODULE_ID_CAN, 0, CANIF_RXINDICATION_ID, CANIF_E_PARAM_HRH); continue; // Not a supported filter type, so just drop the frame } } } #if (CANIF_DLC_CHECK == STD_ON) if (CanDlc < entry->CanIfCanRxPduDlc) { VALIDATE_NO_RV(FALSE, CANIF_RXINDICATION_ID, CANIF_E_PARAM_DLC); return; } #endif switch (entry->CanIfRxUserType) { case CANIF_USER_TYPE_CAN_SPECIAL: { ( (CanIf_FuncTypeCanSpecial)(entry->CanIfUserRxIndication) )( entry->CanIfCanRxPduHrhRef->CanIfCanControllerHrhIdRef, entry->CanIfCanRxPduId, CanSduPtr, CanDlc, CanId); return; } break; case CANIF_USER_TYPE_CAN_NM: #if defined(USE_CANNM) CanNm_RxIndication(entry->CanIfCanRxPduId,CanSduPtr); return; #endif break; case CANIF_USER_TYPE_CAN_PDUR: // Send Can frame to PDU router #if defined(USE_PDUR) { PduInfoType pduInfo; pduInfo.SduLength = CanDlc; pduInfo.SduDataPtr = (uint8 *)CanSduPtr; PduR_CanIfRxIndication(entry->CanIfCanRxPduId,&pduInfo); } return; #endif break; case CANIF_USER_TYPE_CAN_TP: // Send Can frame to CAN TP #if defined(USE_CANTP) { PduInfoType CanTpRxPdu; CanTpRxPdu.SduLength = CanDlc; CanTpRxPdu.SduDataPtr = (uint8 *)CanSduPtr; CanTp_RxIndication(entry->CanIfCanRxPduId, &CanTpRxPdu); } return; #endif break; case CANIF_USER_TYPE_J1939TP: // Send Can frame to CAN TP #if defined(USE_J1939TP) { PduInfoType J1939TpRxPdu; J1939TpRxPdu.SduLength = CanDlc; J1939TpRxPdu.SduDataPtr = (uint8 *)CanSduPtr; J1939Tp_RxIndication(entry->CanIfCanRxPduId, &J1939TpRxPdu); } return; #endif break; } } entry++; } // Did not find the PDU, something is wrong VALIDATE_NO_RV(FALSE, CANIF_RXINDICATION_ID, CANIF_E_PARAM_LPDU); }
static void socketUdpRead(uint16 sockNr) { BufReq_ReturnType result; switch (SocketAdminList[sockNr].SocketConnectionRef->AutosarConnectorType) { case SOAD_AUTOSAR_CONNECTOR_PDUR: if (SocketAdminList[sockNr].SocketRouteRef != NULL) { struct sockaddr_in fromAddr; socklen_t fromAddrLen = sizeof(fromAddr); int nBytes; PduInfoType pduInfo; if (SoAd_BufferGet(SOAD_RX_BUFFER_SIZE, &pduInfo.SduDataPtr)) { nBytes = lwip_recvfrom(SocketAdminList[sockNr].SocketHandle, pduInfo.SduDataPtr, SOAD_RX_BUFFER_SIZE, MSG_PEEK, (struct sockaddr*)&fromAddr, &fromAddrLen); SoAd_SocketStatusCheck(sockNr, SocketAdminList[sockNr].SocketHandle); if (nBytes > 0){ if(nBytes >= SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength) { if (!SocketAdminList[sockNr].SocketConnectionRef->PduProvideBufferEnable) { // IF-type pduInfo.SduLength = lwip_recvfrom(SocketAdminList[sockNr].SocketHandle, pduInfo.SduDataPtr, SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength,0, (struct sockaddr*)&fromAddr, &fromAddrLen); SocketAdminList[sockNr].RemotePort = fromAddr.sin_port; SocketAdminList[sockNr].RemoteIpAddress = fromAddr.sin_addr.s_addr; /* TODO Find out how autosar connector and user really shall be used. This is just one interpretation * support for XCP, CDD will have to be added later when supported */ switch(SocketAdminList[sockNr].SocketRouteRef->UserRxIndicationUL){ #if defined(USE_UDPNM) case SOAD_UL_UDPNM: (void)UdpNm_SoAdIfRxIndication(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, &pduInfo); break; #endif default: (void)PduR_SoAdIfRxIndication(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, &pduInfo); break; } } else { // TP-type PduLengthType len; result = PduR_SoAdTpStartOfReception(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength, &len); if (result == BUFREQ_OK && len > 0) { pduInfo.SduLength = SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength; nBytes = lwip_recvfrom(SocketAdminList[sockNr].SocketHandle, pduInfo.SduDataPtr, SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength,0, (struct sockaddr*)&fromAddr, &fromAddrLen); SocketAdminList[sockNr].RemotePort = fromAddr.sin_port; SocketAdminList[sockNr].RemoteIpAddress = fromAddr.sin_addr.s_addr; /* Let pdur copy received data */ if(len < SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength) { PduInfoType pduInfoChunk; PduLengthType lenToSend = SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength; /* We need to copy in smaller parts */ pduInfoChunk.SduDataPtr = pduInfo.SduDataPtr; while(lenToSend > 0) { if(lenToSend >= len){ PduR_SoAdTpCopyRxData(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, &pduInfoChunk, &len); lenToSend -= len; }else{ PduR_SoAdTpCopyRxData(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, &pduInfoChunk, &lenToSend); lenToSend = 0; } } }else{ PduR_SoAdTpCopyRxData(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, &pduInfo, &len); } /* Finished reception */ (void)PduR_SoAdTpRxIndication(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, NTFRSLT_OK); } else if (result != BUFREQ_BUSY) { DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_SOCKET_UDP_READ_ID, SOAD_E_UL_RXBUFF); (void)PduR_SoAdTpRxIndication(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, NTFRSLT_E_NO_BUFFER); } } } } SoAd_BufferFree(pduInfo.SduDataPtr); } else { // No buffer available: continue poll() Report error SOAD_E_UPPERBUFF to DEM // DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_SOCKET_UDP_READ_ID, SOAD_E_UPPERBUFF); (void)PduR_SoAdTpRxIndication(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, NTFRSLT_E_NO_BUFFER); } } else { DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_SOCKET_UDP_READ_ID, SOAD_E_CONFIG_INVALID); } break; // SOAD_AUTOSAR_CONNECTOR_PDUR case SOAD_AUTOSAR_CONNECTOR_DOIP: DoIp_HandleUdpRx(sockNr); break; // SOAD_AUTOSAR_CONNECTOR_DOIP default: DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_SOCKET_UDP_READ_ID, SOAD_E_NOCONNECTOR); break; } }
static void socketTcpRead(uint16 sockNr) { BufReq_ReturnType result; switch (SocketAdminList[sockNr].SocketConnectionRef->AutosarConnectorType) { case SOAD_AUTOSAR_CONNECTOR_PDUR: if (SocketAdminList[sockNr].SocketRouteRef != NULL) { int nBytes; PduInfoType pduInfo; // pi_printf("infor: tcp read\r\n"); if (SoAd_BufferGet(SOAD_RX_BUFFER_SIZE, &pduInfo.SduDataPtr)) { nBytes = lwip_recv(SocketAdminList[sockNr].ConnectionHandle, pduInfo.SduDataPtr, SOAD_RX_BUFFER_SIZE, MSG_PEEK); // pi_printf("infor: peek data "); mini_uart_sendDec(nBytes); pi_printf("\r\n"); SoAd_SocketStatusCheck(sockNr, SocketAdminList[sockNr].ConnectionHandle); if ((nBytes > 0) && (nBytes >= SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength)) { if (!SocketAdminList[sockNr].SocketConnectionRef->PduProvideBufferEnable) { // IF-type // pi_printf(" infor: plan to read\r\n"); pduInfo.SduLength = lwip_recv(SocketAdminList[sockNr].ConnectionHandle, pduInfo.SduDataPtr, SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength, 0); // pi_printf(" infor: value = "); mini_uart_sendDec(*pduInfo.SduDataPtr); pi_printf("\r\n"); New_Data_Flag = true; (void)PduR_SoAdIfRxIndication(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, &pduInfo); } else { // TP-type PduLengthType len; result = PduR_SoAdTpStartOfReception(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength, &len); if (result == BUFREQ_OK && len>0) { pduInfo.SduLength = SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength; nBytes = lwip_recv(SocketAdminList[sockNr].SocketHandle, pduInfo.SduDataPtr, SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength,0); /* Let pdur copy received data */ if(len < SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength) { PduInfoType pduInfoChunk; PduLengthType lenToSend = SocketAdminList[sockNr].SocketRouteRef->DestinationSduLength; /* We need to copy in smaller parts */ pduInfoChunk.SduDataPtr = pduInfo.SduDataPtr; while(lenToSend > 0) { if(lenToSend >= len){ PduR_SoAdTpCopyRxData(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, &pduInfoChunk, &len); lenToSend -= len; }else{ PduR_SoAdTpCopyRxData(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, &pduInfoChunk, &lenToSend); lenToSend = 0; } } }else{ PduR_SoAdTpCopyRxData(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, &pduInfo, &len); } /* Finished reception */ (void)PduR_SoAdTpRxIndication(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, NTFRSLT_OK); } else if (result != BUFREQ_BUSY) { DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_SOCKET_TCP_READ_ID, SOAD_E_UL_RXBUFF); } } } SoAd_BufferFree(pduInfo.SduDataPtr); } else { // No buffer available: continue poll() Report error SOAD_E_UPPERBUFF to DEM // DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_SOCKET_TCP_READ_ID, SOAD_E_UPPERBUFF); (void)PduR_SoAdTpRxIndication(SocketAdminList[sockNr].SocketRouteRef->DestinationPduId, NTFRSLT_E_NO_BUFFER); } } else { DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_SOCKET_TCP_READ_ID, SOAD_E_CONFIG_INVALID); } break; // SOAD_AUTOSAR_CONNECTOR_PDUR case SOAD_AUTOSAR_CONNECTOR_DOIP: DoIp_HandleTcpRx(sockNr); break; // SOAD_AUTOSAR_CONNECTOR_DOIP default: DET_REPORTERROR(MODULE_ID_SOAD, 0, SOAD_SOCKET_TCP_READ_ID, SOAD_E_NOCONNECTOR); break; } }
void Com_Init(const Com_ConfigType *config ) { DEBUG(DEBUG_LOW, "--Initialization of COM--\n"); /* !req COM328 */ /* Shall not enable inter-ECU communication */ /* !req COM483 */ /* @req COM128 */ /* @req COM217 */ /* @req COM444 */ /* @req COM772 */ // If timeout set to 0 uint8 failure = 0; /* @req COM433 */ if( NULL == config ) { DET_REPORTERROR(COM_INIT_ID, COM_E_PARAM_POINTER); return; } ComConfig = config; uint32 firstTimeout; boolean dataChanged = FALSE; //lint --e(928) PC-Lint exception Misra 11.4, Must be like this. /tojo uint8 endiannessByte = *(const uint8 *)&endianness_test; if ( endiannessByte == 0xef ) { Com_SystemEndianness = COM_LITTLE_ENDIAN; } else if ( endiannessByte == 0xde ) { Com_SystemEndianness = COM_BIG_ENDIAN; } else { // No other endianness supported //lint --e(506) PC-Lint exception Misra 13.7, 14.1, Allow boolean to always be false. assert(0); } // Initialize each IPdu //ComIPdu_type *IPdu; //Com_Arc_IPdu_type *Arc_IPdu; const ComSignal_type *Signal; const ComGroupSignal_type *GroupSignal; uint16 bufferIndex = 0; for (uint16 i = 0; !ComConfig->ComIPdu[i].Com_Arc_EOL; i++) { boolean pduHasGroupSignal = FALSE; const ComIPdu_type *IPdu = GET_IPdu(i); Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(i); Arc_IPdu->Com_Arc_DynSignalLength = 0; if (i >= ComConfig->ComNofIPdus) { DET_REPORTERROR(COM_INIT_ID ,COM_E_TOO_MANY_IPDU); failure = 1; break; } /* Set the data ptr for this Pdu */ Arc_IPdu->ComIPduDataPtr = (void *)&Com_Arc_Buffer[bufferIndex]; bufferIndex += IPdu->ComIPduSize; // If this is a TX and cyclic IPdu, configure the first deadline. if ( (IPdu->ComIPduDirection == SEND) && ( (IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeMode == PERIODIC) || (IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeMode == MIXED) )) { //IPdu->Com_Arc_TxIPduTimers.ComTxModeTimePeriodTimer = IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeTimeOffsetFactor; Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeTimePeriodTimer = IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeTimeOffsetFactor; } // Reset firstTimeout. firstTimeout = 0xffffffffu; // Initialize the memory with the default value. /* @req COM015 */ if (IPdu->ComIPduDirection == SEND) { memset((void *)Arc_IPdu->ComIPduDataPtr, IPdu->ComTxIPdu.ComTxIPduUnusedAreasDefault, IPdu->ComIPduSize); } // For each signal in this PDU. //Arc_IPdu->NComIPduSignalRef = 0; for (uint16 j = 0; (IPdu->ComIPduSignalRef != NULL) && (IPdu->ComIPduSignalRef[j] != NULL) ; j++) { Signal = IPdu->ComIPduSignalRef[j]; Com_Arc_Signal_type * Arc_Signal = GET_ArcSignal(Signal->ComHandleId); // Configure signal deadline monitoring if used. /* @req COM333 */ // If timeout set to 0 if (Signal->ComTimeoutFactor > 0) { if (Signal->ComSignalArcUseUpdateBit) { // This signal uses an update bit, and hence has its own deadline monitoring. /* @req COM292 */ Arc_Signal->Com_Arc_DeadlineCounter = Signal->ComFirstTimeoutFactor; // Configure the deadline counter } else { // This signal does not use an update bit, and should therefore use per I-PDU deadline monitoring. if (firstTimeout > Signal->ComFirstTimeoutFactor) { firstTimeout = Signal->ComFirstTimeoutFactor; } } } // Clear update bits /* @req COM117 */ if (Signal->ComSignalArcUseUpdateBit) { CLEARBIT(Arc_IPdu->ComIPduDataPtr, Signal->ComUpdateBitPosition); } // If this signal is a signal group if (Signal->Com_Arc_IsSignalGroup) { pduHasGroupSignal = TRUE; Arc_Signal->Com_Arc_ShadowBuffer = (void *)&Com_Arc_Buffer[bufferIndex]; // For each group signal of this signal group. for(uint8 h = 0; Signal->ComGroupSignal[h] != NULL; h++) { GroupSignal = Signal->ComGroupSignal[h]; Com_Arc_GroupSignal_type *Arc_GroupSignal = GET_ArcGroupSignal(GroupSignal->ComHandleId); // Set pointer to shadow buffer Arc_GroupSignal->Com_Arc_ShadowBuffer = (void *)Arc_Signal->Com_Arc_ShadowBuffer; // Initialize shadowbuffer. /* @req COM484 */ Com_Internal_UpdateShadowSignal(GroupSignal->ComHandleId, GroupSignal->ComSignalInitValue); } // Initialize group signal data from shadowbuffer. /* @req COM098 */ Com_CopySignalGroupDataFromShadowBufferToPdu(Signal->ComHandleId, false, &dataChanged); } else { // Initialize signal data. /* @req COM098 */ Com_WriteSignalDataToPdu(Signal->ComHandleId, Signal->ComSignalInitValue, &dataChanged); } } if( pduHasGroupSignal ) { /* This pdu has includes group signals. Means that a shodow buffer was set up. * Increment index. */ bufferIndex += IPdu->ComIPduSize; } if (IPdu->ComIPduDirection == RECEIVE && IPdu->ComIPduSignalProcessing == DEFERRED) { /* Set pointer to the deferred buffer */ Arc_IPdu->ComIPduDeferredDataPtr = (void *)&Com_Arc_Buffer[bufferIndex]; bufferIndex += IPdu->ComIPduSize; // Copy the initialized pdu to deferred buffer memcpy(Arc_IPdu->ComIPduDeferredDataPtr,Arc_IPdu->ComIPduDataPtr,IPdu->ComIPduSize); } // Configure per I-PDU based deadline monitoring. for (uint16 j = 0; (IPdu->ComIPduSignalRef != NULL) && (IPdu->ComIPduSignalRef[j] != NULL); j++) { Signal = IPdu->ComIPduSignalRef[j]; Com_Arc_Signal_type * Arc_Signal = GET_ArcSignal(Signal->ComHandleId); /* @req COM333 */ // If timeout set to 0 if ( (Signal->ComTimeoutFactor > 0) && (!Signal->ComSignalArcUseUpdateBit) ) { /* @req COM290 */ Arc_Signal->Com_Arc_DeadlineCounter = firstTimeout; } } } for (uint16 i = 0; i < ComConfig->ComNofIPdus; i++) { Com_BufferPduState[i].currentPosition = 0; Com_BufferPduState[i].locked = false; } // An error occurred. if (failure) { DEBUG(DEBUG_LOW, "--Initialization of COM failed--\n"); //DET_REPORTERROR(COM_MODULE_ID, COM_INSTANCE_ID, 0x01, COM_E_INVALID_FILTER_CONFIGURATION); } else { initStatus = COM_INIT; DEBUG(DEBUG_LOW, "--Initialization of COM completed--\n"); } }
void Com_Init(const Com_ConfigType *config ) { uint8 failure = 0; uint32 firstTimeout; uint8 endiannessByte; uint16 i; uint16 j; //ComIPdu_type *IPdu; //Com_Arc_IPdu_type *Arc_IPdu; const ComSignal_type *Signal; const ComGroupSignal_type *GroupSignal; DEBUG_PRINT0(DEBUG_LOW, "--Initialization of COM--\n"); ComConfig = config; //lint --e(928) PC-Lint exception Misra 11.4, Must be like this. /tojo endiannessByte = *(const uint8 *)&endianness_test; if ( endiannessByte == 0xef ) { Com_SystemEndianness = COM_LITTLE_ENDIAN; } else if ( endiannessByte == 0xde ) { Com_SystemEndianness = COM_BIG_ENDIAN; } else { // No other endianness supported //lint --e(506) PC-Lint exception Misra 13.7, 14.1, Allow boolean to always be false. AR_ASSERT(0); } // Initialize each IPdu #if 0 //F*****g bad code as always need a dummy ComIPdu config with Com_Arc_EOL equal to TRUE. for (i = 0; !ComConfig->ComIPdu[i].Com_Arc_EOL; i++) { #else /*So I changed it to ...*/ for(i = 0;i < COM_N_IPDUS;i++){ #endif const ComIPdu_type *IPdu = GET_IPdu(i); Com_Arc_IPdu_type *Arc_IPdu = GET_ArcIPdu(i); Arc_IPdu->Com_Arc_DynSignalLength = 0; if (i >= COM_N_IPDUS) { DET_REPORTERROR(COM_MODULE_ID, COM_INSTANCE_ID, 0x01, COM_E_TOO_MANY_IPDU); failure = 1; break; } // If this is a TX and cyclic IPdu, configure the first deadline. if ( (IPdu->ComIPduDirection == SEND) && ( (IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeMode == PERIODIC) || (IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeMode == MIXED) )) { //IPdu->Com_Arc_TxIPduTimers.ComTxModeTimePeriodTimer = IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeTimeOffsetFactor; Arc_IPdu->Com_Arc_TxIPduTimers.ComTxModeTimePeriodTimer = IPdu->ComTxIPdu.ComTxModeTrue.ComTxModeTimeOffsetFactor; } // Reset firstTimeout. firstTimeout = 0xffffffffu; // Initialize the memory with the default value. if (IPdu->ComIPduDirection == SEND) { memset((void *)IPdu->ComIPduDataPtr, IPdu->ComTxIPdu.ComTxIPduUnusedAreasDefault, IPdu->ComIPduSize); } // For each signal in this PDU. //Arc_IPdu->NComIPduSignalRef = 0; for (j = 0; (IPdu->ComIPduSignalRef != NULL) && (IPdu->ComIPduSignalRef[j] != NULL) ; j++) { Com_Arc_Signal_type * Arc_Signal; Signal = IPdu->ComIPduSignalRef[j]; Arc_Signal = GET_ArcSignal(Signal->ComHandleId); // Configure signal deadline monitoring if used. if (Signal->ComTimeoutFactor > 0) { if (Signal->ComSignalArcUseUpdateBit) { // This signal uses an update bit, and hence has its own deadline monitoring. Arc_Signal->Com_Arc_DeadlineCounter = Signal->ComFirstTimeoutFactor; // Configure the deadline counter } else { // This signal does not use an update bit, and should therefore use per I-PDU deadline monitoring. if (firstTimeout > Signal->ComFirstTimeoutFactor) { firstTimeout = Signal->ComFirstTimeoutFactor; } } } // Clear update bits if (Signal->ComSignalArcUseUpdateBit) { CLEARBIT(IPdu->ComIPduDataPtr, Signal->ComUpdateBitPosition); } // If this signal is a signal group if (Signal->Com_Arc_IsSignalGroup) { uint8 h; // For each group signal of this signal group. for(h = 0; Signal->ComGroupSignal[h] != NULL; h++) { Com_Arc_GroupSignal_type *Arc_GroupSignal; GroupSignal = Signal->ComGroupSignal[h]; Arc_GroupSignal = GET_ArcGroupSignal(GroupSignal->ComHandleId); // Set pointer to shadow buffer Arc_GroupSignal->Com_Arc_ShadowBuffer = (void *)Signal->Com_Arc_ShadowBuffer; // Initialize group signal data. Com_WriteGroupSignalDataToPdu(Signal->ComHandleId, GroupSignal->ComHandleId, GroupSignal->ComSignalInitValue); } } else { // Initialize signal data. Com_WriteSignalDataToPdu(Signal->ComHandleId, Signal->ComSignalInitValue); } } if (IPdu->ComIPduDirection == RECEIVE && IPdu->ComIPduSignalProcessing == DEFERRED) { // Copy the initialized pdu to deferred buffer memcpy(IPdu->ComIPduDeferredDataPtr,IPdu->ComIPduDataPtr,IPdu->ComIPduSize); } // Configure per I-PDU based deadline monitoring. for (j = 0; (IPdu->ComIPduSignalRef != NULL) && (IPdu->ComIPduSignalRef[j] != NULL); j++) { Com_Arc_Signal_type * Arc_Signal; Signal = IPdu->ComIPduSignalRef[j]; Arc_Signal = GET_ArcSignal(Signal->ComHandleId); if ( (Signal->ComTimeoutFactor > 0) && (!Signal->ComSignalArcUseUpdateBit) ) { Arc_Signal->Com_Arc_DeadlineCounter = firstTimeout; } } } for (i = 0; i < COM_N_IPDUS; i++) { Com_BufferPduState[i].currentPosition = 0; Com_BufferPduState[i].locked = FALSE; } // An error occurred. if (failure) { DEBUG_PRINT0(DEBUG_LOW, "--Initialization of COM failed--\n"); //DET_REPORTERROR(COM_MODULE_ID, COM_INSTANCE_ID, 0x01, COM_E_INVALID_FILTER_CONFIGURATION); } else { DEBUG_PRINT0(DEBUG_LOW, "--Initialization of COM completed--\n"); } } void Com_DeInit( void ) { } void Com_IpduGroupStart(Com_PduGroupIdType IpduGroupId,boolean Initialize) { uint16 i; (void)Initialize; // Nothing to be done. This is just to avoid Lint warning. #if 0 for (i = 0; !ComConfig->ComIPdu[i].Com_Arc_EOL; i++) { #else /*So I changed it to ...*/ for(i = 0;i < COM_N_IPDUS;i++){ #endif if (ComConfig->ComIPdu[i].ComIPduGroupRef == IpduGroupId) { Com_Arc_Config.ComIPdu[i].Com_Arc_IpduStarted = 1; } } } void Com_IpduGroupStop(Com_PduGroupIdType IpduGroupId) { uint16 i; #if 0 for (i = 0; !ComConfig->ComIPdu[i].Com_Arc_EOL; i++) { #else /*So I changed it to ...*/ for(i = 0;i < COM_N_IPDUS;i++){ #endif if (ComConfig->ComIPdu[i].ComIPduGroupRef == IpduGroupId) { Com_Arc_Config.ComIPdu[i].Com_Arc_IpduStarted = 0; } } } /** * * @param PduId * @param PduInfoPtr * @param RetryInfoPtr not supported * @param TxDataCntPtr * @return */ BufReq_ReturnType Com_CopyTxData(PduIdType PduId, PduInfoType* PduInfoPtr, RetryInfoType* RetryInfoPtr, PduLengthType* TxDataCntPtr) { imask_t state; BufReq_ReturnType r = BUFREQ_OK; const ComIPdu_type *IPdu = GET_IPdu(PduId); boolean dirOk = ComConfig->ComIPdu[PduId].ComIPduDirection == SEND; boolean sizeOk; (void)RetryInfoPtr; // get rid of compiler warning Irq_Save(state); sizeOk = IPdu->ComIPduSize >= Com_BufferPduState[PduId].currentPosition + PduInfoPtr->SduLength; Com_BufferPduState[PduId].locked = TRUE; if (dirOk && sizeOk) { void* source = (void *)(IPdu->ComIPduDataPtr); memcpy((void *)PduInfoPtr->SduDataPtr,(void *)((uint8*)source + Com_BufferPduState[PduId].currentPosition), PduInfoPtr->SduLength); Com_BufferPduState[PduId].currentPosition += PduInfoPtr->SduLength; *TxDataCntPtr = IPdu->ComIPduSize - Com_BufferPduState[PduId].currentPosition; } else { r = BUFREQ_NOT_OK; } Irq_Restore(state); return r; }