#include "J1939Tp.h" /** @req J1939TP0003*/\r
#include "CanIf.h" /** @req J1939TP0172 */\r
#include "J1939Tp_Internal.h"\r
-\r
-\r
-\r
-#define J1939TP_PACKET_SIZE 7\r
-\r
-/** @req J1939TP0019 */\r
-typedef enum {\r
- J1939TP_ON,\r
- J1939TP_OFF\r
-} J1939Tp_GlobalStateType;\r
-\r
-/** @req J1939TP0180 */\r
-Std_ReturnType J1939Tp_ChangeParameterRequest(PduIdType SduId, TPParameterType Parameter, uint16 value) {\r
- return E_NOT_OK; /** @req J1939TP0181 */\r
-}\r
+#include "PdurR_J1939Tp.h"\r
\r
/** @req J1939TP0019 */\r
static J1939Tp_GlobalStateType globalState = J1939TP_OFF;\r
+static const J1939Tp_ConfigType* J1939Tp_ConfigPtr;\r
\r
/** @req J1939TP0087 */\r
void J1939Tp_Init(const J1939Tp_ConfigType* ConfigPtr) {\r
- #if J1939TP_DEV_ERROR_DETECT\r
- if (globalState == J11939TP_ON) {\r
+ #if (J1939TP_DEV_ERROR_DETECT == STD_ON)\r
+ if (globalState == J1939TP_ON) {\r
/** @req J1939TP0026 */\r
- J1939TP_DET_REPORTERROR(J1939_INIT_ID, J1939TP_E_REINIT);\r
+ J1939Tp_Internal_ReportError(J1939TP_INIT_ID, J1939TP_E_REINIT);\r
return;\r
}\r
#endif\r
+ J1939Tp_ConfigPtr = ConfigPtr;\r
globalState = J1939TP_ON; /** @req J1939TP0022 */\r
-\r
}\r
+void J1939Tp_RxIndication(PduIdType RxPduId, PduInfoType* PduInfoPtr) {\r
\r
-#define RTS_SIZE 8\r
-\r
-#define RTS_BYTE_CONTROL 0\r
-#define RTS_BYTE_LENGTH_1 1\r
-#define RTS_BYTE_LENGTH_2 2\r
-#define RTS_BYTE_NUM_PACKETS 3\r
-#define RTS_BYTE_SAE_ASSIGN 4\r
-#define RTS_BYTE_PGN_1 5\r
-#define RTS_BYTE_PGN_2 6\r
-#define RTS_BYTE_PGN_3 7\r
+}\r
\r
-#define RTS_PGN_VALUE_1 0x00\r
-#define RTS_PGN_VALUE_2 0xCE\r
-#define RTS_PGN_VALUE_3 0x00\r
+/** @req J1939TP0180 */\r
+Std_ReturnType J1939Tp_ChangeParameterRequest(PduIdType SduId, TPParameterType Parameter, uint16 value) {\r
+ return E_NOT_OK; /** @req J1939TP0181 */\r
+}\r
\r
/** @req J1939TP0096 */\r
Std_ReturnType J1939Tp_Transmit(PduIdType TxSduId, const PduInfoType* TxInfoPtr) {\r
#if J1939TP_DEV_ERROR_DETECT\r
if (globalState == J1939TP_OFF) {\r
- J1939TP_DET_REPORTERROR(J1939_TRANSMIT_ID,J1939_E_UNINIT);\r
+ J1939Tp_Internal_ReportError(J1939TP_TRANSMIT_ID,J1939TP_E_UNINIT);\r
}\r
#endif\r
- uint8 cmRtsData[RTS_SIZE];\r
+ if (TxInfoPtr->SduLength <= 8) {\r
+ PduR_J1939TpProvideTxBuffer(TxSduId, &TxInfoPtr,0);\r
+ if (CanIf_Transmit(TxSduId,TxInfoPtr) == E_OK) {\r
+ PduR_J1939TpTxConfirmation(TxSduId, NTFRSLT_OK);\r
+ } else {\r
+ PduR_J1939TpTxConfirmation(TxSduId, NTFRSLT_E_NOT_OK);\r
+ }\r
+ } else {\r
+ uint32 pgn = J1939Tp_Internal_ConfGetTxPg(TxSduId)->Pgn;\r
+ uint8 pf = J1939Tp_Internal_GetPf(pgn);\r
+ J1939Tp_ProtocolType protocol = J1939Tp_Internal_GetProtocol(pf);\r
+ switch (protocol) { /** @req J1939TP0039*/\r
+ case J1939TP_PROTOCOL_BAM:\r
+ break;\r
+ case J1939TP_PROTOCOL_CMDT:\r
+ J1939Tp_Internal_SendRts(TxSduId,TxInfoPtr);\r
+ break;\r
+ }\r
+ }\r
+ return E_OK;\r
+}\r
+\r
+\r
+static inline const J1939Tp_PgType* J1939Tp_Internal_ConfGetTxPg(uint32 txPduId) {\r
+ return &(J1939Tp_ConfigPtr->TxPgs[txPduId]);\r
+}\r
+static inline const J1939Tp_ChannelType* J1939Tp_Internal_ConfGetTxChannel(uint32 txPduId) {\r
+ return J1939Tp_ConfigPtr->TxPgs[txPduId].Channel;\r
+}\r
\r
+static void J1939Tp_Internal_SendRts(PduIdType TxSduId, const PduInfoType* TxInfoPtr) {\r
+ uint8 cmRtsData[RTS_SIZE];\r
cmRtsData[RTS_BYTE_CONTROL] = 16;\r
cmRtsData[RTS_BYTE_LENGTH_1] = TxInfoPtr->SduLength >> 8;\r
cmRtsData[RTS_BYTE_LENGTH_2] = TxInfoPtr->SduLength << 8;\r
- cmRtsData[RTS_BYTE_NUM_PACKETS] = TxInfoPtr->SduLength / J1939TP_PACKET_SIZE;\r
+ uint8 reminder = 0;\r
+ if (TxInfoPtr->SduLength % J1939TP_PACKET_SIZE == 0) {\r
+ reminder = 1;\r
+ }\r
+ cmRtsData[RTS_BYTE_NUM_PACKETS] = (TxInfoPtr->SduLength / J1939TP_PACKET_SIZE) + reminder;\r
cmRtsData[RTS_BYTE_SAE_ASSIGN] = 0xFF;\r
cmRtsData[RTS_BYTE_PGN_1] = RTS_PGN_VALUE_1;\r
cmRtsData[RTS_BYTE_PGN_2] = RTS_PGN_VALUE_2;\r
PduInfoType cmRtsPdu;\r
cmRtsPdu.SduLength = RTS_SIZE;\r
cmRtsPdu.SduDataPtr = cmRtsData;\r
- CanIf_Transmit(TxSduId,&cmRtsPdu);\r
+ CanIf_Transmit(J1939Tp_Internal_ConfGetTxChannel(TxSduId)->CmNPdu,&cmRtsPdu);\r
+}\r
\r
+\r
+static uint8 J1939Tp_Internal_GetPf(uint32 pgn) {\r
+ return (pgn && 0x0000FF00) >> 8;\r
+}\r
+static J1939Tp_ProtocolType J1939Tp_Internal_GetProtocol(uint8 pf) {\r
+ if (pf < 240) {\r
+ return J1939TP_PROTOCOL_CMDT;\r
+ } else {\r
+ return J1939TP_PROTOCOL_BAM;\r
+ }\r
+}\r
+static inline void J1939Tp_Internal_ReportError(uint8 ApiId, uint8 ErrorId) {\r
+#if (CANSM_DEV_ERROR_DETECT == STD_ON)\r
+ Det_ReportError(MODULE_ID_J1939TP, 0, ApiId, ApiId);\r
+#endif\r
}\r
#ifndef J1939TP_INTERNAL_H_\r
#define J1939TP_INTERNAL_H_\r
\r
-#include "J1939Tp.h"\r
-\r
/** Service Ids */\r
-#define J1939_TRANSMIT_ID 0x05\r
-#define J1939_INIT_ID 0x01\r
+#define J1939TP_TRANSMIT_ID 0x05\r
+#define J1939TP_INIT_ID 0x01\r
\r
/** Error Codes */\r
#define J1939TP_E_PARAM_ID 0x01\r
#define J1939TP_E_UNINIT 0x20\r
#define J1939TP_E_REINIT 0x21\r
\r
+#define J1939TP_PACKET_SIZE 7\r
\r
-#if (CANSM_DEV_ERROR_DETECT == STD_ON)\r
-#define J1939TP_DET_REPORTERROR(serviceId, errorId) \\r
- Det_ReportError(MODULE_ID_J1939TP, 0, serviceId, errorId)\r
-#endif\r
+/** Rts message */\r
+#define RTS_SIZE 8\r
+\r
+#define RTS_BYTE_CONTROL 0\r
+#define RTS_BYTE_LENGTH_1 1\r
+#define RTS_BYTE_LENGTH_2 2\r
+#define RTS_BYTE_NUM_PACKETS 3\r
+#define RTS_BYTE_SAE_ASSIGN 4\r
+#define RTS_BYTE_PGN_1 5\r
+#define RTS_BYTE_PGN_2 6\r
+#define RTS_BYTE_PGN_3 7\r
+\r
+#define RTS_PGN_VALUE_1 0x00\r
+#define RTS_PGN_VALUE_2 0xCE\r
+#define RTS_PGN_VALUE_3 0x00\r
+\r
+/** @req J1939TP0019 */\r
+typedef enum {\r
+ J1939TP_ON,\r
+ J1939TP_OFF\r
+} J1939Tp_GlobalStateType;\r
+\r
+typedef struct {\r
+ boolean waitingForCts;\r
+} J1939Tp_Internal_TxPduStateType;\r
\r
+static inline const J1939Tp_PgType* J1939Tp_Internal_ConfGetTxPg(uint32 txPduId);\r
+static void J1939Tp_Internal_SendRts(PduIdType TxSduId, const PduInfoType* TxInfoPtr);\r
+static uint8 J1939Tp_Internal_GetPf(uint32 pgn);\r
+static J1939Tp_ProtocolType J1939Tp_Internal_GetProtocol(uint8 pf);\r
+static inline void J1939Tp_Internal_ReportError(uint8 ApiId, uint8 ErrorId);\r
#endif\r
* for a J1939 transport protocol session using CMDT. TP.CM in reverse direction\r
* is used for intermediate and final ack of received data and to abort the connection
*/\r
-typedef struct {\r
- const PduIdType Pdu;\r
-} J1939Tp_FcNPduType;\r
\r
-typedef struct {\r
- const PduIdType Pdu;\r
-} J1939Tp_CmNPduType;\r
\r
-typedef struct {\r
- const PduIdType Pdu;\r
-}J1939Tp_DtNPduType;\r
-\r
-typedef struct {\r
- const PduIdType Pdu;\r
-} J1939Tp_NSduType;\r
+typedef struct J1939Tp_ChannelType_ J1939Tp_ChannelType;\r
+typedef struct J1939Tp_PgType_ J1939Tp_PgType;\r
\r
-typedef struct {\r
- const PduIdType Pdu;\r
-} J1939Tp_DirectNPduType;\r
-\r
-typedef struct {\r
+struct J1939Tp_PgType_ {\r
const boolean DynLength;\r
const uint32 Pgn;\r
- const J1939Tp_DirectNPduType DirectNPdu; /** only set when DynLength = true */\r
- const J1939Tp_NSduType NSdu;\r
-} J1939Tp_PgType;\r
+ const PduIdType DirectNPdu; /** only set when DynLength = true */\r
+ const PduIdType NSdu;\r
+ const J1939Tp_ChannelType* Channel;\r
+};\r
\r
-typedef struct {\r
+struct J1939Tp_ChannelType_ {\r
const J1939Tp_ProtocolType Protocol;\r
- const J1939Tp_DtNPduType DtNPdu;\r
- const J1939Tp_CmNPduType CmNPdu;\r
- const J1939Tp_PgType *Pgs;\r
- const J1939Tp_FcNPduType FcNPdu; /** only set when Protocol == J1939TP_PROTOCOL_CMDT */\r
-} J1939Tp_ChannelType;\r
+ const PduIdType DtNPdu;\r
+ const PduIdType CmNPdu;\r
+ const PduIdType FcNPdu; /** only set when Protocol == J1939TP_PROTOCOL_CMDT */\r
+} ;\r
\r
/** @req J1939TP0175 */\r
typedef struct {\r
- const J1939Tp_RxChannelType *RxChannels;\r
- const J1939Tp_TxChannelType *TxChannels;\r
+ const J1939Tp_PgType* RxPgs;\r
+ const J1939Tp_PgType* TxPgs;\r
} J1939Tp_ConfigType;\r
\r
#endif\r
--- /dev/null
+/* -------------------------------- Arctic Core ------------------------------\r
+ * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
+ *\r
+ * Copyright (C) 2009 ArcCore AB <contact@arccore.com>\r
+ *\r
+ * This source code is free software; you can redistribute it and/or modify it\r
+ * under the terms of the GNU General Public License version 2 as published by the\r
+ * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
+ *\r
+ * This program is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License\r
+ * for more details.\r
+ * -------------------------------- Arctic Core ------------------------------*/\r
+\r
+\r
+\r
+#ifndef PDUR_J1939TP_H_\r
+#define PDUR_J1939TP_H_\r
+\r
+#include "PduR.h"\r
+\r
+#if PDUR_ZERO_COST_OPERATION == STD_OFF\r
+\r
+BufReq_ReturnType PduR_J1939TpProvideTxBuffer(PduIdType J1939TpTxId,PduInfoType** PduInfoPtr, uint16 Length);\r
+void PduR_J1939TpTxConfirmation(PduIdType CanTpTxPduId, NotifResultType Result);\r
+\r
+#endif\r
+\r
+#endif /* PDUR_CANTP_H_ */\r