]> rtime.felk.cvut.cz Git - arc.git/blob - communication/PduR/PduR_If.c
Added missing header to mpc5606s.h
[arc.git] / communication / PduR / PduR_If.c
1 /* -------------------------------- Arctic Core ------------------------------\r
2  * Arctic Core - the open source AUTOSAR platform http://arccore.com\r
3  *\r
4  * Copyright (C) 2009  ArcCore AB <contact@arccore.com>\r
5  *\r
6  * This source code is free software; you can redistribute it and/or modify it\r
7  * under the terms of the GNU General Public License version 2 as published by the\r
8  * Free Software Foundation; See <http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt>.\r
9  *\r
10  * This program is distributed in the hope that it will be useful, but\r
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License\r
13  * for more details.\r
14  * -------------------------------- Arctic Core ------------------------------*/\r
15 \r
16 \r
17 \r
18 \r
19 \r
20 \r
21 \r
22 \r
23 #include "PduR.h"\r
24 \r
25 #if (PDUR_ZERO_COST_OPERATION == STD_OFF)\r
26 \r
27 #include <string.h>\r
28 #include "debug.h"\r
29 #if defined(USE_DEM)\r
30 #include "Dem.h"\r
31 #endif\r
32 \r
33 /**\r
34  * Helper function for the PduR_<LO>IfRxIndication functions. This helper performs the actions specified by PDUR255 and PDUR258.\r
35  * @param LinRxPduId - The id of the PDU to be routed.\r
36  * @param LinSduPtr - The payload of the PDU.\r
37  * @param LoIf_Transmit\r
38  */\r
39 void PduR_LoIfRxIndication(PduIdType PduId, const uint8* SduPtr) {\r
40 \r
41         // Perform routing lookup.\r
42         PduRRoutingPath_type *route = &PduRConfig->PduRRoutingTable->PduRRoutingPath[PduId];\r
43 \r
44         if (route->PduR_GatewayMode == 0) {\r
45                 // This is an ordinary request.\r
46                 // 534 PC-Lint (ignoring return value) ticket #134:\r
47                 route->FctPtrs.TargetIndicationFctPtr(route->PduRDestPdu.DestPduId, SduPtr); // Send PDU to next receptor.\r
48 \r
49 \r
50         } else if ( (route->PduR_GatewayMode == 1) && (route->PduRDestPdu.DataProvision == PDUR_NO_PROVISION) ) {\r
51                 // This is a gateway request, but without any data provision (buffer usage).\r
52                 PduInfoType PduInfo = {\r
53                         .SduDataPtr = (uint8 *)SduPtr, // 926, 960 PC-Lint: Beror på att funktion PduR_LoIfRxIndication(...) fel-definerad TICKET 130\r
54                         .SduLength = route->SduLength\r
55                 };\r
56                 // 534 PC-Lint (ignoring return value) ticket #134:\r
57                 route->FctPtrs.TargetTransmitFctPtr(route->PduRDestPdu.DestPduId, &PduInfo); // Send PDU to next receptor.\r
58 \r
59 \r
60         } else if ( (route->PduR_GatewayMode == 1) && (route->PduRDestPdu.DataProvision == PDUR_TRIGGER_TRANSMIT) ) {\r
61                 // Ths is a gateway request which uses trigger transmit data provision. PDUR255\r
62                 DEBUG(DEBUG_LOW,"\tUsing gateway mode with trigger transmit provision\n");\r
63 \r
64                 if (route->PduRDestPdu.TxBufferRef->TxConfP) { // Transfer confirmation pending.\r
65                         // Enqueue the new I-PDU. This will flush the buffer if it is full according to the buffer specification.\r
66                         PduR_BufferQueue(route->PduRDestPdu.TxBufferRef, SduPtr);\r
67                         // TODO report PDUR_E_PDU_INSTANCE_LOST to DEM if needed.\r
68                 }\r
69 \r
70                 if (!route->PduRDestPdu.TxBufferRef->TxConfP) { // No transfer confirmation pending (anymore).\r
71                         uint8 val[route->SduLength];\r
72                         PduInfoType PduInfo = {\r
73                                 .SduDataPtr = val,\r
74                                 .SduLength = route->SduLength\r
75                         };\r
76                         PduR_BufferDeQueue(route->PduRDestPdu.TxBufferRef, val);\r
77                         PduR_BufferQueue(route->PduRDestPdu.TxBufferRef, SduPtr);\r
78                         if (route->FctPtrs.TargetTransmitFctPtr(route->PduRDestPdu.DestPduId, &PduInfo) == E_OK) {\r
79                                 setTxConfP(route);\r
80                         }\r
81                 }\r
82 \r
83         } else if ( (route->PduR_GatewayMode == 1) && (route->PduRDestPdu.DataProvision == PDUR_DIRECT) ) {\r
84                 // This is a gateway request using a direct data provision fifo. PDUR258\r
85                 DEBUG(DEBUG_LOW,"\tUsing gateway mode with direct provision\n");\r
86 \r
87                 if (route->PduRDestPdu.TxBufferRef->TxConfP) { // Transfer confirmation pending.\r
88                         DEBUG(DEBUG_LOW,"\tTransfer confirmation pending.\n");\r
89                         PduR_BufferQueue(route->PduRDestPdu.TxBufferRef, SduPtr);\r
90                         // TODO report PDUR_E_PDU_INSTANCE_LOST to DEM if needed.\r
91 \r
92                 }\r
93 \r
94                 if (!route->PduRDestPdu.TxBufferRef->TxConfP) { // No transfer confirmation pending (anymore)\r
95                         // TODO: Shall this function create a new I-PDU from LinSduPtr?\r
96 \r
97                         // Make new PduInfoPackage\r
98                         DEBUG(DEBUG_LOW,"\tNo transfer confirmation pending. Forwarding packet.\n");\r
99                         PduInfoType PduInfoPtr = {\r
100                                         .SduDataPtr = (uint8 *)SduPtr, // 926, 960 PC-Lint: Beror på att funktion PduR_LoIfRxIndication(...) fel-definerad TICKET 130\r
101                                         .SduLength = route->SduLength\r
102                         };\r
103                         if (route->FctPtrs.TargetTransmitFctPtr(route->PduRDestPdu.DestPduId, &PduInfoPtr) == E_OK) {\r
104                                 setTxConfP(route);\r
105 \r
106 \r
107                         } else {\r
108 #if defined(USE_DEM)\r
109                                 Dem_ReportErrorStatus(PDUR_E_PDU_INSTANCE_LOST, DEM_EVENT_STATUS_FAILED);\r
110 #endif\r
111                                 DEBUG(DEBUG_LOW,"\tTransmission failed. PDUR_E_PDU_INSTANCE_LOST\n");\r
112                         }\r
113                 }\r
114         } else {\r
115                 // Nothing to be done.\r
116         }\r
117 }\r
118 \r
119 // void PduR_LoIfTxConfirmation(PduIdType PduId, Std_ReturnType (*LoIf_Transmit)(PduIdType, const PduInfoType*)) {\r
120 \r
121 void PduR_LoIfTxConfirmation(PduIdType PduId) {\r
122 \r
123         // Perform routing lookup.\r
124         PduRRoutingPath_type *route = &PduRConfig->PduRRoutingTable->PduRRoutingPath[PduId];\r
125 \r
126         // Find out if this is a gateway or ordinary confirmation.\r
127 \r
128         if (route->PduR_GatewayMode == 0) {\r
129                 // This is an ordinary request.\r
130                 route->FctPtrs.TargetConfirmationFctPtr(route->PduRDestPdu.DestPduId); // Forward confirmation\r
131 \r
132         } else if ( (route->PduR_GatewayMode == 1) && (route->PduRDestPdu.DataProvision == PDUR_NO_PROVISION) ) {\r
133                 // A gateway request without provision. Just forward confirmation.\r
134                 route->FctPtrs.TargetConfirmationFctPtr(route->PduRDestPdu.DestPduId); // Forward confirmation\r
135 \r
136 \r
137         } else if ( (route->PduR_GatewayMode == 1) && (route->PduRDestPdu.DataProvision == PDUR_TRIGGER_TRANSMIT) ) {\r
138                 // The route is using gateway mode and trigger transmit data provision. PDUR256\r
139                 DEBUG(DEBUG_LOW,"\tUsing gateway mode with trigger transmit data provision.\n", PduId);\r
140 \r
141                 while (1) {\r
142 \r
143                         // If TxConfP is set process confirmation, ignore otherwise.\r
144                         if (!route->PduRDestPdu.TxBufferRef->TxConfP) { // TxConfP not set, ignore!\r
145                                 DEBUG(DEBUG_LOW,"\tTxConfP was not set, ignoring confirmation.\n");\r
146                                 break;\r
147 \r
148 \r
149                         } else { // TxConfP is set\r
150                                 if (route->PduRDestPdu.TxBufferRef->NrItems == 1) { // Only one entry in buffer.\r
151                                         clearTxConfP(route); // Clear TxConfP\r
152                                         DEBUG(DEBUG_LOW,"\tOnly one entry in buffer and TxConfP set, cleared TxConfP.\n");\r
153                                         break;\r
154 \r
155 \r
156                                 } else { // Buffer is not empty\r
157                                         // Dequeue the first fifo item.\r
158                                         DEBUG(DEBUG_LOW,"\tMore than one entry in buffer and TxConfP set, transmitting the next fifo entry.\n");\r
159                                         uint8 val[route->SduLength];\r
160                                         PduR_BufferDeQueue(route->PduRDestPdu.TxBufferRef, val);\r
161 \r
162                                         // TODO Does this need to be static?\r
163                                         PduInfoType PduInfo = {\r
164                                                 .SduDataPtr = val,\r
165                                                 .SduLength = route->SduLength\r
166                                         };\r
167                                         // Transmit this item.\r
168                                         if (route->FctPtrs.TargetTransmitFctPtr(route->PduRDestPdu.DestPduId, &PduInfo) == E_OK) {\r
169                                                 DEBUG(DEBUG_LOW,"\tTransmit succeeded.\n");\r
170                                                 break;\r
171 \r
172 \r
173                                         } else {\r
174                                                 DEBUG(DEBUG_LOW,"\tTransmit failed. Retrying with the next fifo entry.\n");\r
175                                         }\r
176                                 }\r
177                         }\r
178                 }\r
179 \r
180 \r
181         } else if ( (route->PduR_GatewayMode == 1) && (route->PduRDestPdu.DataProvision == PDUR_DIRECT) ) {\r
182                 // The route is using a direct data provision fifo. PDUR259\r
183                 DEBUG(DEBUG_LOW,"\tUsing gateway mode with direct data provision.\n", PduId);\r
184 \r
185                 while (1) {\r
186 \r
187                         // If TxConfP is set process confirmation, ignore otherwise.\r
188                         if (!route->PduRDestPdu.TxBufferRef->TxConfP) { // TxConfP not set, ignore!\r
189                                 DEBUG(DEBUG_LOW,"\tTxConfP was not set, ignoring confirmation.\n");\r
190                                 break;\r
191 \r
192 \r
193                         } else { // TxConfP is set\r
194                                 if (route->PduRDestPdu.TxBufferRef->NrItems == 0) { // Buffer is empty\r
195                                         clearTxConfP(route); // Clear TxConfP\r
196                                         DEBUG(DEBUG_LOW,"\tBuffer was empty and TxConfP set, cleared TxConfP.\n");\r
197                                         break;\r
198 \r
199 \r
200                                 } else { // Buffer is not empty\r
201                                         // Dequeue the first fifo item.\r
202                                         DEBUG(DEBUG_LOW,"\tBuffer was not empty and TxConfP set, transmitting the next fifo entry.\n");\r
203                                         uint8 val[route->SduLength];\r
204                                         PduR_BufferDeQueue(route->PduRDestPdu.TxBufferRef, val);\r
205 \r
206                                         // TODO Does this need to be static?\r
207                                         PduInfoType PduInfo = {\r
208                                                 .SduDataPtr = val,\r
209                                                 .SduLength = route->SduLength\r
210                                         };\r
211                                         // Transmit this item.\r
212                                         if (route->FctPtrs.TargetTransmitFctPtr(route->PduRDestPdu.DestPduId, &PduInfo) == E_OK) {\r
213                                                 DEBUG(DEBUG_LOW,"\tTransmit succeeded.\n");\r
214                                                 break;\r
215 \r
216 \r
217                                         } else {\r
218                                                 DEBUG(DEBUG_LOW,"\tTransmit failed. Retrying with the next fifo entry.\n");\r
219                                         }\r
220                                 }\r
221                         }\r
222                 }\r
223         } else {\r
224                 // Nothing to be done.\r
225         }\r
226 }\r
227 \r
228 void PduR_LoIfTriggerTransmit(PduIdType PduId, uint8* SduPtr) {\r
229         // Perform routing lookup.\r
230         PduRRoutingPath_type *route = &PduRConfig->PduRRoutingTable->PduRRoutingPath[PduId];\r
231 \r
232         // Find out if this is a gateway or ordinary trigger.\r
233         //if (route->PduRDestPdu.DataProvision == PDUR_NO_PROVISION) { // This is an ordinary trigger.\r
234         if (route->PduR_GatewayMode == 0) { // This is an ordinary trigger.\r
235                 // 534 PC-Lint (ignoring return value) ticket #134:\r
236                 route->FctPtrs.TargetTriggerTransmitFctPtr(route->PduRDestPdu.DestPduId, SduPtr);\r
237 \r
238         } else if ( (route->PduR_GatewayMode == 1) && (route->PduRDestPdu.DataProvision == PDUR_TRIGGER_TRANSMIT) ) { // The route is using a trigger transmit fifo. PDUR256\r
239                 DEBUG(DEBUG_LOW,"\tUsing gateway mode with trigger transmit data provision.\n", PduId);\r
240                 memcpy((void *)SduPtr, (void *)route->PduRDestPdu.TxBufferRef->First, sizeof(uint8) * route->SduLength);\r
241 \r
242         } else {\r
243                 // Nothing to be done.\r
244         }\r
245 }\r
246 \r
247 #endif\r