1 /* -------------------------------- Arctic Core ------------------------------
\r
2 * Arctic Core - the open source AUTOSAR platform http://arccore.com
\r
4 * Copyright (C) 2009 ArcCore AB <contact@arccore.com>
\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
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
14 * -------------------------------- Arctic Core ------------------------------*/
\r
25 #if (PDUR_ZERO_COST_OPERATION == STD_OFF)
\r
29 #if defined(USE_DEM)
\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
39 void PduR_LoIfRxIndication(PduIdType PduId, const uint8* SduPtr) {
\r
41 // Perform routing lookup.
\r
42 PduRRoutingPath_type *route = &PduRConfig->PduRRoutingTable->PduRRoutingPath[PduId];
\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
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
56 // 534 PC-Lint (ignoring return value) ticket #134:
\r
57 route->FctPtrs.TargetTransmitFctPtr(route->PduRDestPdu.DestPduId, &PduInfo); // Send PDU to next receptor.
\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
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
70 if (!route->PduRDestPdu.TxBufferRef->TxConfP) { // No transfer confirmation pending (anymore).
\r
71 uint8 val[route->SduLength];
\r
72 PduInfoType PduInfo = {
\r
74 .SduLength = route->SduLength
\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
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
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
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
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
103 if (route->FctPtrs.TargetTransmitFctPtr(route->PduRDestPdu.DestPduId, &PduInfoPtr) == E_OK) {
\r
108 #if defined(USE_DEM)
\r
109 Dem_ReportErrorStatus(PDUR_E_PDU_INSTANCE_LOST, DEM_EVENT_STATUS_FAILED);
\r
111 DEBUG(DEBUG_LOW,"\tTransmission failed. PDUR_E_PDU_INSTANCE_LOST\n");
\r
115 // Nothing to be done.
\r
119 // void PduR_LoIfTxConfirmation(PduIdType PduId, Std_ReturnType (*LoIf_Transmit)(PduIdType, const PduInfoType*)) {
\r
121 void PduR_LoIfTxConfirmation(PduIdType PduId) {
\r
123 // Perform routing lookup.
\r
124 PduRRoutingPath_type *route = &PduRConfig->PduRRoutingTable->PduRRoutingPath[PduId];
\r
126 // Find out if this is a gateway or ordinary confirmation.
\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
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
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
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
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
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
162 // TODO Does this need to be static?
\r
163 PduInfoType PduInfo = {
\r
165 .SduLength = route->SduLength
\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
174 DEBUG(DEBUG_LOW,"\tTransmit failed. Retrying with the next fifo entry.\n");
\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
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
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
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
206 // TODO Does this need to be static?
\r
207 PduInfoType PduInfo = {
\r
209 .SduLength = route->SduLength
\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
218 DEBUG(DEBUG_LOW,"\tTransmit failed. Retrying with the next fifo entry.\n");
\r
224 // Nothing to be done.
\r
228 void PduR_LoIfTriggerTransmit(PduIdType PduId, uint8* SduPtr) {
\r
229 // Perform routing lookup.
\r
230 PduRRoutingPath_type *route = &PduRConfig->PduRRoutingTable->PduRRoutingPath[PduId];
\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
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
243 // Nothing to be done.
\r