]> rtime.felk.cvut.cz Git - arc.git/commitdiff
more work on j1939tp
authornier <devnull@localhost>
Fri, 9 Sep 2011 14:28:22 +0000 (16:28 +0200)
committernier <devnull@localhost>
Fri, 9 Sep 2011 14:28:22 +0000 (16:28 +0200)
boards/board_common.mk
communication/J1939Tp/J1939Tp.c
communication/J1939Tp/J1939Tp_Internal.h
include/J1939Tp.h
include/J1939Tp_ConfigTypes.h
include/PduR_J1939Tp.h [new file with mode: 0644]

index 8f87a5644afe2409ec3056cebdda1f6c7a48c56d..d0e0168993f262620dbde9ed767666484999b374 100644 (file)
@@ -99,6 +99,7 @@ obj-$(USE_ADC) += Adc_Cfg.o
 \r
 # J1939Tp\r
 obj-$(USE_J1939TP) += J1939Tp.o\r
+obj-$(USE_J1939TP) += J1939Tp_LCfg.o\r
 inc-$(USE_J1939TP) += $(ROOTDIR)/communication/J1939Tp\r
 vpath-$(USE_J1939TP) += $(ROOTDIR)/communication/J1939Tp\r
 \r
index 4797d91612298b2e190eb30a0b7def6225a9bf71..51a569519cec66b8762e04d288223622173c13eb 100644 (file)
@@ -1,66 +1,80 @@
 #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
@@ -69,6 +83,22 @@ Std_ReturnType J1939Tp_Transmit(PduIdType TxSduId, const PduInfoType* TxInfoPtr)
        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
index ef3972b29a9617374b070aeb17b1cbf22ac46045..9397f795105c51eb9dbf6ce798fb3ad1e3e801bd 100644 (file)
 #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
index 5c2dae1713a950dfbb4c6e954ff1b0b4e9875d83..2260b38b1c36e6b58cdc5c2cadc6eae590632513 100644 (file)
@@ -20,6 +20,8 @@
 #include "Std_Types.h"\r
 #include "ComStack_Types.h" /** @req J1939TP0016 */\r
 #include "J1939Tp_ConfigTypes.h"\r
+#include "J1939Tp_Cfg.h" /** @req J1939TP0009 */\r
+\r
 \r
 \r
 /** Global requirements */\r
index cda3c58023e54d28358503d3b83e4461822c1b83..59aaa429d8942bc1d6f21315a304db3932280c8b 100644 (file)
@@ -29,45 +29,30 @@ typedef enum {
  * 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
diff --git a/include/PduR_J1939Tp.h b/include/PduR_J1939Tp.h
new file mode 100644 (file)
index 0000000..2d3bd87
--- /dev/null
@@ -0,0 +1,30 @@
+/* -------------------------------- 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