]> rtime.felk.cvut.cz Git - arc.git/blob - communication/PduR/PduR.h
Initial commit.
[arc.git] / communication / PduR / PduR.h
1 /* -------------------------------- Arctic Core ------------------------------
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com
3  *
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>
5  *
6  * This source code is free software; you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License version 2 as published by the
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14  * -------------------------------- Arctic Core ------------------------------*/
15
16
17
18
19
20
21
22
23 #ifndef _PDUR_H_\r
24 #define _PDUR_H_\r
25 \r
26 #define PDUR_VENDOR_ID                      1\r
27 #define PDUR_AR_MAJOR_VERSION  2\r
28 #define PDUR_AR_MINOR_VERSION   2\r
29 #define PDUR_AR_PATCH_VERSION   2\r
30 #define PDUR_SW_MAJOR_VERSION  3\r
31 #define PDUR_SW_MINOR_VERSION   0\r
32 #define PDUR_SW_PATCH_VERSION   2\r
33 \r
34 #include "PduR_Cfg.h"\r
35 #include "PduR_Types.h"\r
36 \r
37 #ifndef PDUR_ZERO_COST_OPERATION\r
38 #include "PduR_PbCfg.h"\r
39 #endif\r
40 \r
41 #include "PduR_Com.h"\r
42 #include "PduR_CanIf.h"\r
43 #include "PduR_LinIf.h"\r
44 \r
45 /* Contain the current state of the PDU router. The router is uninitialized\r
46  * until PduR_Init has been run.\r
47  */\r
48 PduR_StateType PduRState;\r
49 \r
50 extern const PduR_PBConfigType *PduRConfig;\r
51 \r
52 #ifdef PDUR_PRINT_DEBUG_STATEMENTS\r
53 /* A simple debug macro to be used instead of printf(). This way all print\r
54  * statements are turned off if PDUR_PRINT_DEBUG_STATEMENTS is undefined.\r
55  */\r
56 //#include <stdio.h>\r
57 #define debug(...) simple_printf(__VA_ARGS__)\r
58 \r
59 #else\r
60 #define debug(...)\r
61 \r
62 #endif\r
63 \r
64 #ifdef PDUR_REENTRANCY_CHECK\r
65 /*\r
66  * The macros Enter and Exit performs the ReEntrancy check of the PDU router functions.\r
67  * Enter shall be called at the beginning of the function with the current PduId and the wanted\r
68  * return value (possibly nothing for void methods).\r
69  * Exit should be called at the end of the function where reentrancy is desirable.\r
70  */\r
71 #define Enter(PduId,...) \\r
72         static uint8 entered;\\r
73         static PduIdType enteredId;\\r
74         if (entered && enteredId == PduId) { \\r
75                 debug("Function already entered. EnteredId: %d, CurrentId: %d. Exiting.\n", enteredId, PduId); \\r
76                 return __VA_ARGS__; \\r
77         } else { \\r
78                 entered = 1; \\r
79                 enteredId = PduId; \\r
80         } \\r
81 \r
82 \r
83 #define Exit() \\r
84         entered = 0; \\r
85 \r
86 #else\r
87 #define Enter(...)\r
88 #define Exit()\r
89 #endif\r
90 \r
91 #ifdef PDUR_DEV_ERROR_DETECT\r
92 \r
93 #undef DET_REPORTERROR\r
94 #define DET_REPORTERROR(_x,_y,_z,_q) Det_ReportError(_x,_y,_z,_q)\r
95 \r
96 // Define macro for state, parameter and data pointer checks.\r
97 // TODO Implement data range check if needed.\r
98 #define DevCheck(PduId,PduPtr,ApiId,...) \\r
99         if (PduRState == PDUR_UNINIT || PduRState == PDUR_REDUCED) { \\r
100                 DET_REPORTERROR(PDUR_MODULE_ID, PDUR_INSTANCE_ID, ApiId, PDUR_E_INVALID_REQUEST); \\r
101                 DEBUG(DEBUG_LOW,"PDU Router not initialized. Routing request ignored.\n"); \\r
102                 Exit(); \\r
103                 return __VA_ARGS__; \\r
104         } \\r
105         if (PduPtr == 0 && PDUR_DEV_ERROR_DETECT) { \\r
106                 DET_REPORTERROR(PDUR_MODULE_ID, PDUR_INSTANCE_ID, ApiId, PDUR_E_DATA_PTR_INVALID); \\r
107                 Exit(); \\r
108                 return __VA_ARGS__; \\r
109         } \\r
110         if ((PduId >= PduRConfig->PduRRoutingTable->NRoutingPaths) && PDUR_DEV_ERROR_DETECT) { \\r
111                 DET_REPORTERROR(PDUR_MODULE_ID, PDUR_INSTANCE_ID, ApiId, PDUR_E_PDU_ID_INVALID); \\r
112                 Exit(); \\r
113                 return __VA_ARGS__; \\r
114         } \\r
115 \r
116 \r
117 #else\r
118 #undef DET_REPORTERROR\r
119 #define DET_REPORTERROR(_x,_y,_z,_q)\r
120 #define DevCheck(...)\r
121 \r
122 #endif\r
123 \r
124 Std_ReturnType PduR_CancelTransmitRequest(\r
125                 PduR_CancelReasonType PduCancelReason, PduIdType PduId);\r
126 void PduR_ChangeParameterRequest(PduR_ParameterValueType PduParameterValue,\r
127                 PduIdType PduId);\r
128 \r
129 /* Zero Cost Operation function definitions\r
130  * These macros replaces the original functions if zero cost\r
131  * operation is desired. */\r
132 #ifdef PDUR_ZERO_COST_OPERATION\r
133 \r
134 #define PduR_Init(...)\r
135 #define PduR_GetVersionInfo(...)\r
136 #define PduR_GetConfigurationId(...) 0\r
137 \r
138 #else // Not zero cost operation\r
139 void PduR_Init(const PduR_PBConfigType* ConfigPtr);\r
140 void PduR_GetVersionInfo(Std_VersionInfoType* versionInfo);\r
141 uint32 PduR_GetConfigurationId();\r
142 \r
143 void PduR_BufferQueue(PduRTxBuffer_type *Buffer, const uint8 * SduPtr);\r
144 void PduR_BufferDeQueue(PduRTxBuffer_type *Buffer, uint8 *SduPtr);\r
145 void PduR_BufferFlush(PduRTxBuffer_type *Buffer);\r
146 uint8 PduR_BufferIsFull(PduRTxBuffer_type *Buffer);\r
147 \r
148 /*\r
149  * Macros\r
150  */\r
151 #define setTxConfP(R) R->PduRDestPdu.TxBufferRef->TxConfP = 1\r
152 #define clearTxConfP(R) R->PduRDestPdu.TxBufferRef->TxConfP = 0\r
153 \r
154 #endif\r
155 \r
156 extern PduR_FctPtrType PduR_StdCanFctPtrs;\r
157 extern PduR_FctPtrType PduR_StdLinFctPtrs;\r
158 \r
159 #endif /* _PDUR_H_ */\r