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
17 * General requirements
\r
25 #include "Dcm_Internal.h"
\r
28 #include "ComM_Dcm.h"
\r
29 #include "PduR_Dcm.h"
\r
30 #include "ComStack_Types.h"
\r
31 //#define USE_DEBUG_PRINTF
\r
34 #define DECREMENT(timer) { if (timer > 0) timer--; }
\r
35 #define DCM_CONVERT_MS_TO_MAIN_CYCLES(x) ((x)/DCM_MAIN_FUNCTION_PERIOD_TIME_MS)
\r
42 const Dcm_DslProtocolRxType *protocolRx;
\r
43 const Dcm_DslMainConnectionType *mainConnection;
\r
44 const Dcm_DslConnectionType *connection;
\r
45 const Dcm_DslProtocolRowType *protocolRow;
\r
46 } DcmDsl_ProtocolConfigurationType;
\r
48 #define MAX_PARALLEL_PROTOCOLS_ALLOWED 1
\r
52 //boolean diagnosticRequestPending; // This is a "semaphore" because DSD and DCM can handle multiple/parallel request at the moment.
\r
53 const Dcm_DslProtocolRowType *preemptedProtocol; // Points to the currently active protocol.
\r
54 const Dcm_DslProtocolRowType *activeProtocol; // Points to the currently active protocol.
\r
55 Dcm_DslRunTimeProtocolParametersType
\r
56 protocolList[MAX_PARALLEL_PROTOCOLS_ALLOWED];
\r
57 } DcmDsl_RunTimeDataType;
\r
59 static DcmDsl_RunTimeDataType DcmDslRunTimeData = {
\r
61 .preemptedProtocol = NULL,
\r
62 .activeProtocol = NULL };
\r
64 // ################# DUMMIES START #################
\r
70 void ComM_DCM_ActivateDiagnostic() {
\r
74 void ComM_DCM_InactivateDiagnostic() {
\r
78 // ################# HELPER FUNCTIONS START #################
\r
81 // This function reset/stars the session (S3) timer. See requirement
\r
82 // DCM141 when that action should be taken.
\r
84 static inline void startS3SessionTimer(Dcm_DslRunTimeProtocolParametersType *runtime, const Dcm_DslProtocolRowType *protocolRow) {
\r
85 const Dcm_DslProtocolTimingRowType *timeParams;
\r
86 timeParams = protocolRow->DslProtocolTimeLimit;
\r
87 runtime->S3ServerTimeoutCount = DCM_CONVERT_MS_TO_MAIN_CYCLES(timeParams->TimStrS3Server);
\r
90 // - - - - - - - - - - -
\r
93 // This function reset/stars the session (S3) timer. See requirement
\r
94 // DCM141 when that action should be taken.
\r
96 static inline void stopS3SessionTimer(Dcm_DslRunTimeProtocolParametersType *runtime) {
\r
97 runtime->S3ServerTimeoutCount = 0;
\r
100 // - - - - - - - - - - -
\r
103 // This function implements the requirement DCM139 when
\r
104 // transition from one session to another.
\r
106 static void changeDiagnosticSession(Dcm_DslRunTimeProtocolParametersType *runtime,
\r
107 Dcm_SesCtrlType newSession) {
\r
111 switch (runtime->sessionControl) {
\r
112 case DCM_DEFAULT_SESSION: // "default".
\r
115 case DCM_PROGRAMMING_SESSION:
\r
116 case DCM_EXTENDED_DIAGNOSTIC_SESSION:
\r
117 case DCM_SAFTEY_SYSTEM_DIAGNOSTIC_SESSION:
\r
118 case DCM_ALL_SESSION_LEVEL:
\r
119 runtime->securityLevel = DCM_SEC_LEV_LOCKED; // "0x00".
\r
123 // TODO: Log this error.
\r
124 DEBUG(DEBUG_MEDIUM, "Old session invalid");
\r
128 switch (newSession) {
\r
129 case DCM_DEFAULT_SESSION: // "default".
\r
130 case DCM_PROGRAMMING_SESSION:
\r
131 case DCM_EXTENDED_DIAGNOSTIC_SESSION:
\r
132 case DCM_SAFTEY_SYSTEM_DIAGNOSTIC_SESSION:
\r
133 case DCM_ALL_SESSION_LEVEL:
\r
134 runtime->sessionControl = newSession;
\r
138 // TODO: Log this error.
\r
139 DEBUG(DEBUG_MEDIUM, "New session invalid");
\r
144 // - - - - - - - - - - -
\r
146 void DslResetSessionTimeoutTimer() {
\r
147 const Dcm_DslProtocolRowType *activeProtocol = NULL;
\r
148 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
149 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
150 runtime = activeProtocol->DslRunTimeProtocolParameters;
\r
151 startS3SessionTimer(runtime, activeProtocol); /** @req DCM141 */
\r
154 // - - - - - - - - - - -
\r
156 void DslGetCurrentServiceTable(const Dcm_DsdServiceTableType **currentServiceTable) { /** @req DCM195 */
\r
157 const Dcm_DslProtocolRowType *activeProtocol = NULL;
\r
158 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
159 if (activeProtocol != NULL) {
\r
160 *currentServiceTable = activeProtocol->DslProtocolSIDTable;
\r
164 // - - - - - - - - - - -
\r
166 Std_ReturnType DslGetActiveProtocol(Dcm_ProtocolType *protocolId) { /** @req DCM340 */
\r
167 Std_ReturnType ret = E_NOT_OK;
\r
168 const Dcm_DslProtocolRowType *activeProtocol = NULL;
\r
169 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
170 if (activeProtocol != NULL) {
\r
171 *protocolId = activeProtocol->DslProtocolID;
\r
177 // - - - - - - - - - - -
\r
179 void DslSetSecurityLevel(Dcm_SecLevelType secLevel) { /** @req DCM020 */
\r
180 const Dcm_DslProtocolRowType *activeProtocol = NULL;
\r
181 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
182 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
183 runtime = activeProtocol->DslRunTimeProtocolParameters;
\r
184 runtime->securityLevel = secLevel;
\r
187 // - - - - - - - - - - -
\r
189 Std_ReturnType DslGetSecurityLevel(Dcm_SecLevelType *secLevel) { /** @req DCM020 *//** @req DCM338 */
\r
190 Std_ReturnType ret = E_NOT_OK;
\r
191 const Dcm_DslProtocolRowType *activeProtocol = NULL;
\r
192 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
193 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
194 if (activeProtocol != NULL) {
\r
195 runtime = activeProtocol->DslRunTimeProtocolParameters;
\r
196 *secLevel = runtime->securityLevel;
\r
202 // - - - - - - - - - - -
\r
204 void DslSetSesCtrlType(Dcm_SesCtrlType sesCtrl) { /** @req DCM022 */
\r
205 const Dcm_DslProtocolRowType *activeProtocol = NULL;
\r
206 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
207 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
208 if (activeProtocol != NULL) {
\r
209 runtime = activeProtocol->DslRunTimeProtocolParameters;
\r
210 if (runtime->sessionControl != sesCtrl) {
\r
211 changeDiagnosticSession(runtime, sesCtrl);
\r
212 DslResetSessionTimeoutTimer();
\r
217 // - - - - - - - - - - -
\r
219 Std_ReturnType DslGetSesCtrlType(Dcm_SesCtrlType *sesCtrlType) { /** @req DCM022 *//** @req DCM339 */
\r
220 Std_ReturnType ret = E_NOT_OK;
\r
221 const Dcm_DslProtocolRowType *activeProtocol = NULL;
\r
222 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
223 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
224 if (activeProtocol != NULL) {
\r
225 runtime = activeProtocol->DslRunTimeProtocolParameters;
\r
226 *sesCtrlType = runtime->sessionControl;
\r
232 // - - - - - - - - - - -
\r
234 static boolean findRxPduIdParentConfigurationLeafs(PduIdType dcmRxPduId,
\r
235 const Dcm_DslProtocolRxType **protocolRx,
\r
236 const Dcm_DslMainConnectionType **mainConnection,
\r
237 const Dcm_DslConnectionType **connection,
\r
238 const Dcm_DslProtocolRowType **protocolRow,
\r
239 Dcm_DslRunTimeProtocolParametersType **runtime) {
\r
241 boolean ret = FALSE;
\r
242 if (dcmRxPduId < DCM_DSL_RX_PDU_ID_LIST_LENGTH) {
\r
243 *protocolRx = &DCM_Config.Dsl->DslProtocol->DslProtocolRxGlobalList[dcmRxPduId];
\r
244 *mainConnection = (*protocolRx)->DslMainConnectionParent;
\r
245 *connection = (*mainConnection)->DslConnectionParent;
\r
246 *protocolRow = (*connection)->DslProtocolRow;
\r
247 *runtime = (*protocolRow)->DslRunTimeProtocolParameters;
\r
253 // - - - - - - - - - - -
\r
255 static boolean findTxPduIdParentConfigurationLeafs(PduIdType dcmTxPduId,
\r
256 const Dcm_DslProtocolTxType **protocolTx,
\r
257 const Dcm_DslMainConnectionType **mainConnection,
\r
258 const Dcm_DslConnectionType **connection,
\r
259 const Dcm_DslProtocolRowType **protocolRow,
\r
260 Dcm_DslRunTimeProtocolParametersType **runtime) {
\r
262 boolean ret = FALSE;
\r
263 if (dcmTxPduId < DCM_DSL_TX_PDU_ID_LIST_LENGTH) {
\r
264 *protocolTx = &DCM_Config.Dsl->DslProtocol->DslProtocolTxGlobalList[dcmTxPduId];
\r
265 *mainConnection = (*protocolTx)->DslMainConnectionParent;
\r
266 *connection = (*mainConnection)->DslConnectionParent;
\r
267 *protocolRow = (*connection)->DslProtocolRow;
\r
268 *runtime = (*protocolRow)->DslRunTimeProtocolParameters;
\r
274 // - - - - - - - - - - -
\r
276 static inline void releaseExternalRxTxBuffers(const Dcm_DslProtocolRowType *protocolRow,
\r
277 Dcm_DslRunTimeProtocolParametersType *runtime) {
\r
279 protocolRow->DslProtocolTxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
280 protocolRow->DslProtocolRxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
281 runtime->externalTxBufferStatus = NOT_IN_USE; // We are waiting for DSD to return the buffer. qqq.
\r
282 runtime->externalRxBufferStatus = NOT_IN_USE; // We are waiting for DSD to return the buffer. qqq.
\r
285 // - - - - - - - - - - -
\r
288 static inline void releaseExternalRxTxBuffersHelper(PduIdType rxPduIdRef) {
\r
289 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
290 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
291 const Dcm_DslConnectionType *connection = NULL;
\r
292 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
293 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
295 if (findRxPduIdParentConfigurationLeafs(rxPduIdRef, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
296 releaseExternalRxTxBuffers(protocolRow, runtime);
\r
300 // - - - - - - - - - - -
\r
303 * This function is called from the DSD module to the DSL when
\r
304 * a response to a diagnostic request has been copied into the
\r
305 * given TX-buffer and is ready for transmission.
\r
307 void DslDsdProcessingDone(PduIdType rxPduIdRef, DsdProcessingDoneResultType responseResult) {
\r
308 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
309 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
310 const Dcm_DslConnectionType *connection = NULL;
\r
311 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
312 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
314 DEBUG( DEBUG_MEDIUM, "DslDsdProcessingDone rxPduIdRef=%d\n", rxPduIdRef);
\r
316 if (findRxPduIdParentConfigurationLeafs(rxPduIdRef, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
317 imask_t state = McuE_EnterCriticalSection();
\r
318 switch (responseResult) {
\r
319 case DSD_TX_RESPONSE_READY:
\r
320 runtime->externalTxBufferStatus = DSD_PENDING_RESPONSE_SIGNALED; /** @req DCM114 */
\r
322 case DSD_TX_RESPONSE_SUPPRESSED: /** @req DCM238 */
\r
323 DEBUG( DEBUG_MEDIUM, "DslDsdProcessingDone called with DSD_TX_RESPONSE_SUPPRESSED.\n");
\r
324 releaseExternalRxTxBuffersHelper(rxPduIdRef);
\r
327 DEBUG( DEBUG_MEDIUM, "Unknown response result from DslDsdProcessingDone!\n");
\r
330 McuE_ExitCriticalSection(state);
\r
334 // - - - - - - - - - - -
\r
337 * This function preparing transmission of response
\r
338 * pending message to tester.
\r
340 static void sendResponse(const Dcm_DslProtocolRowType *protocol,
\r
341 Dcm_NegativeResponseCodeType responseCode) {
\r
342 //Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
343 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
344 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
345 const Dcm_DslConnectionType *connection = NULL;
\r
346 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
347 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
350 imask_t state = McuE_EnterCriticalSection();
\r
351 if (findRxPduIdParentConfigurationLeafs(protocol->DslRunTimeProtocolParameters->diagReqestRxPduId, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
352 if (runtime->localTxBuffer.status == NOT_IN_USE) {
\r
353 runtime->localTxBuffer.status = PROVIDED_TO_DSD;
\r
354 runtime->localTxBuffer.buffer[0] = SID_NEGATIVE_RESPONSE;
\r
355 runtime->localTxBuffer.buffer[1] = protocol->DslProtocolRxBufferID->pduInfo.SduDataPtr[2];
\r
356 runtime->localTxBuffer.buffer[2] = responseCode;
\r
357 runtime->localTxBuffer.PduInfo.SduDataPtr = runtime->localTxBuffer.buffer;
\r
358 runtime->localTxBuffer.PduInfo.SduLength = 3;
\r
359 runtime->localTxBuffer.status = DCM_TRANSMIT_SIGNALED; // In the DslProvideTxBuffer 'callback' this state signals it is the local buffer we are interested in sending.
\r
360 PduR_DcmTransmit(mainConnection->DslProtocolTx->DcmDslProtocolTxPduId, &(runtime->localTxBuffer.PduInfo));/** @req DCM115.Partially */ /* The P2ServerMin has not been implemented. */
\r
363 McuE_ExitCriticalSection(state);
\r
366 // - - - - - - - - - - -
\r
368 static Std_ReturnType StartProtocolHelper(Dcm_ProtocolType protocolId) {
\r
369 Std_ReturnType ret = E_NOT_OK;
\r
372 for (i = 0; !DCM_Config.Dsl->DslCallbackDCMRequestService[i].Arc_EOL; i++) {
\r
373 if (DCM_Config.Dsl->DslCallbackDCMRequestService[i].StartProtocol != NULL) {
\r
374 ret = DCM_Config.Dsl->DslCallbackDCMRequestService[i]. StartProtocol(protocolId);
\r
383 // - - - - - - - - - - -
\r
385 static boolean isTesterPresentCommand(const PduInfoType *rxPdu) {
\r
386 boolean ret = FALSE;
\r
387 if ((rxPdu->SduDataPtr[0] == SID_TESTER_PRESENT) && (rxPdu->SduDataPtr[1] & SUPPRESS_POS_RESP_BIT)) {
\r
393 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
394 // Implements 'void Dcm_Init(void)' for DSL.
\r
395 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
396 void DslInit(void) {
\r
397 const Dcm_DslProtocolRowType *listEntry = NULL;
\r
398 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
400 listEntry = DCM_Config.Dsl->DslProtocol->DslProtocolRowList;
\r
401 while (listEntry->Arc_EOL == FALSE) {
\r
402 runtime = listEntry->DslRunTimeProtocolParameters;
\r
403 runtime->externalRxBufferStatus = DCM_IDLE;
\r
404 runtime->externalTxBufferStatus = DCM_IDLE;
\r
405 runtime->localRxBuffer.status = DCM_IDLE;
\r
406 runtime->localTxBuffer.status = DCM_IDLE;
\r
407 runtime->securityLevel = DCM_SEC_LEV_LOCKED; /** @req DCM033 */
\r
408 runtime->sessionControl = DCM_DEFAULT_SESSION; /** @req DCM034 */
\r
409 listEntry->DslProtocolRxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
410 listEntry->DslProtocolRxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
413 //DcmDslRunTimeData.diagnosticRequestPending = FALSE;
\r
414 DcmDslRunTimeData.initRun = TRUE;
\r
417 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
418 // Implements 'void Dcm_MainFunction(void)' for DSL.
\r
419 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
421 void DslMain(void) {
\r
422 const Dcm_DslProtocolRowType *protocolRowEntry = NULL;
\r
423 const Dcm_DslProtocolTimingRowType *timeParams = NULL;
\r
424 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
425 int debug_count = 0;
\r
427 protocolRowEntry = DCM_Config.Dsl->DslProtocol->DslProtocolRowList;
\r
428 while (protocolRowEntry->Arc_EOL == FALSE) {
\r
429 runtime = protocolRowEntry->DslRunTimeProtocolParameters;
\r
430 if (runtime != NULL) {
\r
431 // #### HANDLE THE TESTER PRESENT PRESENCE ####
\r
432 if (runtime->sessionControl != DCM_DEFAULT_SESSION) { // Timeout if tester present is lost.
\r
433 DECREMENT(runtime->S3ServerTimeoutCount);
\r
434 if (runtime->S3ServerTimeoutCount == 0) {
\r
435 changeDiagnosticSession(runtime, DCM_DEFAULT_SESSION); /** @req DCM140 */
\r
438 switch (runtime->externalTxBufferStatus) { // #### TX buffer state. ####
\r
440 //DEBUG( DEBUG_MEDIUM, "state NOT_IN_USE!\n");
\r
442 case PROVIDED_TO_DSD: {
\r
443 DEBUG( DEBUG_MEDIUM, "debug_count=%d\n", debug_count);
\r
444 DECREMENT(runtime->stateTimeoutCount);
\r
445 if (runtime->stateTimeoutCount == 0) {
\r
446 DEBUG( DEBUG_MEDIUM, "State PROVIDED_TO_DSD timed out!", debug_count);
\r
447 timeParams = protocolRowEntry->DslProtocolTimeLimit;
\r
448 runtime->stateTimeoutCount = DCM_CONVERT_MS_TO_MAIN_CYCLES(timeParams->TimStrP2ServerMax); /* Reinitiate timer, see 9.2.2. */
\r
449 if (DCM_Config.Dsl->DslDiagResp != NULL) {
\r
450 if (DCM_Config.Dsl->DslDiagResp->DslDiagRespForceRespPendEn == TRUE) {
\r
451 if (runtime->responsePendingCount != 0) {
\r
452 sendResponse(protocolRowEntry, DCM_E_RESPONSEPENDING); /** @req DCM024 */
\r
453 DECREMENT( runtime->responsePendingCount );
\r
455 sendResponse(protocolRowEntry, DCM_E_GENERALREJECT); /** @req DCM120 */
\r
456 releaseExternalRxTxBuffers(protocolRowEntry, runtime);
\r
459 DEBUG( DEBUG_MEDIUM, "Not configured to send response pending, now sending general reject!\n");
\r
460 sendResponse(protocolRowEntry, DCM_E_GENERALREJECT);
\r
461 releaseExternalRxTxBuffers(protocolRowEntry, runtime);
\r
467 case DSD_PENDING_RESPONSE_SIGNALED:
\r
468 // The DSD has signaled to DSL that the diagnostic response is available in the Tx buffer.
\r
469 // Make sure that response pending or general reject have not been issued,
\r
470 // if so we can not transmit to PduR because we would not know from where
\r
471 // the Tx confirmation resides later.
\r
472 DEBUG( DEBUG_MEDIUM, "state DSD_PENDING_RESPONSE_SIGNALED!\n");
\r
473 if (runtime->localTxBuffer.status == NOT_IN_USE) { // Make sure that no TxConfirm could be sent by the local buffer and mixed up with this transmission.
\r
474 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
475 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
476 const Dcm_DslConnectionType *connection = NULL;
\r
477 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
478 if (findRxPduIdParentConfigurationLeafs(runtime->diagReqestRxPduId, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
479 const uint32 txPduId = mainConnection->DslProtocolTx->DcmDslProtocolTxPduId;
\r
480 DEBUG( DEBUG_MEDIUM, "runtime->externalTxBufferStatus enter state DCM_TRANSMIT_SIGNALED.\n" );
\r
481 runtime->externalTxBufferStatus = DCM_TRANSMIT_SIGNALED;
\r
482 PduR_DcmTransmit(txPduId, &runtime->diagnosticResponseFromDsd); /** @req DCM237 *//* Will trigger PduR (CanTP) to call DslProvideTxBuffer(). */
\r
484 DEBUG( DEBUG_MEDIUM, "***** WARNING, THIS IS UNEXPECTED !!! ********.\n" );
\r
485 const uint32 txPduId = protocolRowEntry->DslConnection->DslMainConnection->DslProtocolTx->DcmDslProtocolTxPduId;
\r
486 DEBUG( DEBUG_MEDIUM, "runtime->externalTxBufferStatus enter state DSD_PENDING_RESPONSE_SIGNALED.\n", txPduId);
\r
487 runtime->externalTxBufferStatus = DCM_TRANSMIT_SIGNALED;
\r
488 DEBUG( DEBUG_MEDIUM, "Calling PduR_DcmTransmit with txPduId = %d from DslMain\n", txPduId);
\r
489 PduR_DcmTransmit(txPduId, &runtime->diagnosticResponseFromDsd); /** @req DCM237 *//* Will trigger PduR (CanTP) to call DslProvideTxBuffer(). */
\r
493 case DCM_TRANSMIT_SIGNALED:
\r
494 //DEBUG( DEBUG_MEDIUM, "state DSD_PENDING_RESPONSE_SIGNALED!\n");
\r
496 case PROVIDED_TO_PDUR: // The valid data is being transmitted by TP-layer.
\r
497 //DEBUG( DEBUG_MEDIUM, "state DSD_PENDING_RESPONSE_SIGNALED!\n");
\r
503 protocolRowEntry++;
\r
508 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
509 // Implements 'BufReq_ReturnType Dcm_ProvideRxBuffer(PduIdType dcmRxPduId,
\r
510 // PduLengthType tpSduLength, PduInfoType **pduInfoPtr)'.
\r
511 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
512 // This function is called called by the PduR typically when CanTp has
\r
513 // received a FF or a single frame and needs to obtain a buffer from the
\r
514 // receiver so that received data can be forwarded.
\r
516 BufReq_ReturnType DslProvideRxBufferToPdur(PduIdType dcmRxPduId,
\r
517 PduLengthType tpSduLength, const PduInfoType **pduInfoPtr) {
\r
518 BufReq_ReturnType ret = BUFREQ_NOT_OK;
\r
519 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
520 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
521 const Dcm_DslConnectionType *connection = NULL;
\r
522 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
523 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
525 DEBUG( DEBUG_MEDIUM, "DslProvideRxBufferToPdur(dcmRxPduId=%d) called!\n", dcmRxPduId);
\r
526 imask_t state = McuE_EnterCriticalSection();
\r
527 if (findRxPduIdParentConfigurationLeafs(dcmRxPduId, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
528 const Dcm_DslBufferType *externalRxBuffer = protocolRow->DslProtocolRxBufferID;
\r
529 if (externalRxBuffer->pduInfo.SduLength >= tpSduLength) { /** @req DCM443 */
\r
530 if ((runtime->externalRxBufferStatus == NOT_IN_USE) && (externalRxBuffer->externalBufferRuntimeData->status == BUFFER_AVAILABLE)) {
\r
531 DEBUG( DEBUG_MEDIUM, "External buffer available!\n");
\r
532 // ### EXTERNAL BUFFER IS AVAILABLE; GRAB IT AND REMEBER THAT WE OWN IT! ###
\r
533 externalRxBuffer->externalBufferRuntimeData->status = BUFFER_BUSY;
\r
534 runtime->diagnosticRequestFromTester.SduDataPtr = externalRxBuffer->pduInfo.SduDataPtr;
\r
535 runtime->diagnosticRequestFromTester.SduLength = tpSduLength;
\r
536 *pduInfoPtr = &(runtime->diagnosticRequestFromTester);
\r
537 runtime->externalRxBufferStatus = PROVIDED_TO_PDUR; /** @req DCM342 */
\r
540 DEBUG( DEBUG_MEDIUM, "Local buffer available!\n");
\r
541 if (runtime->externalRxBufferStatus == PROVIDED_TO_DSD) {
\r
542 // ### EXTERNAL BUFFER IS IN USE BY THE DSD, TRY TO USE LOCAL BUFFER! ###
\r
543 if (runtime->localRxBuffer.status == NOT_IN_USE) {
\r
544 if (tpSduLength < DCM_DSL_LOCAL_BUFFER_LENGTH) {
\r
545 runtime->localRxBuffer.status = PROVIDED_TO_PDUR;
\r
546 runtime->localRxBuffer.PduInfo.SduDataPtr = runtime->localRxBuffer.buffer;
\r
547 runtime->localRxBuffer.PduInfo.SduLength = tpSduLength;
\r
548 *pduInfoPtr = &(runtime->localRxBuffer.PduInfo);
\r
555 // The buffer is in use by the PduR, we can not help this because then
\r
556 // we would have two different Rx-indications with same PduId but we
\r
557 // will not know which buffer the indication should free.
\r
558 ret = BUFREQ_BUSY; /** @req DCM445 */
\r
562 ret = BUFREQ_OVFL; /** @req DCM444 */
\r
564 if (ret == BUFREQ_OK) {
\r
565 stopS3SessionTimer(runtime); /** @req DCM141 */
\r
568 McuE_ExitCriticalSection(state);
\r
572 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
573 // Implements 'void Dcm_RxIndication(PduIdType dcmRxPduId, NotifResultType result)'.
\r
574 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
575 // This function is called called by the PduR typically when CanTp has
\r
576 // received the diagnostic request, copied it to the provided buffer and need to indicate
\r
577 // this to the DCM (DSL) module via proprietary API.
\r
579 void DslRxIndicationFromPduR(PduIdType dcmRxPduId, NotifResultType result) {
\r
580 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
581 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
582 const Dcm_DslConnectionType *connection = NULL;
\r
583 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
584 const Dcm_DslProtocolTimingRowType *timeParams = NULL;
\r
585 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
586 Std_ReturnType higherLayerResp;
\r
589 /** @req DCM345, this needs to be verified when connection to CanIf works. */
\r
591 if (findRxPduIdParentConfigurationLeafs(dcmRxPduId, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
592 timeParams = protocolRow->DslProtocolTimeLimit;
\r
593 // We need to find out in what buffer we can find our Rx data (it can
\r
594 // be either in the normal RX-buffer or the 'extra' buffer for implementing
\r
595 // the Concurrent "Test Present" functionality.
\r
596 state = McuE_EnterCriticalSection();
\r
597 if (runtime->externalRxBufferStatus == PROVIDED_TO_PDUR) {
\r
598 if ( result == NTFRSLT_OK ) { /** @req DCM111 */
\r
599 if (isTesterPresentCommand(&(protocolRow->DslProtocolRxBufferID->pduInfo))) {
\r
600 startS3SessionTimer(runtime, protocolRow); /** @req DCM141 *//** @req DCM112 *//** @req DCM113 */
\r
601 runtime->externalRxBufferStatus = NOT_IN_USE;
\r
602 protocolRow->DslProtocolRxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
604 if (runtime->protocolStarted == FALSE) {
\r
605 higherLayerResp = StartProtocolHelper(protocolRow->DslProtocolID); /** @req DCM036 */
\r
606 if (higherLayerResp == E_OK) {
\r
607 runtime->protocolStarted = TRUE;
\r
608 DcmDslRunTimeData.activeProtocol = protocolRow;
\r
611 if (runtime->protocolStarted == TRUE) {
\r
612 if (runtime->diagnosticActiveComM == FALSE) {
\r
613 ComM_DCM_ActivateDiagnostic(); /** @req DCM163 */
\r
614 runtime->diagnosticActiveComM = TRUE;
\r
616 timeParams = protocolRow->DslProtocolTimeLimit;
\r
617 runtime->stateTimeoutCount = DCM_CONVERT_MS_TO_MAIN_CYCLES(timeParams->TimStrP2ServerMax); /* See 9.2.2. */
\r
618 runtime->externalRxBufferStatus = PROVIDED_TO_DSD; /** @req DCM241 */
\r
619 if (runtime->externalTxBufferStatus == NOT_IN_USE) {
\r
620 DEBUG( DEBUG_MEDIUM, "External Tx buffer available, we can pass it to DSD.\n");
\r
622 DEBUG( DEBUG_MEDIUM, "External buffer not available, a response is being transmitted?\n");
\r
624 runtime->externalTxBufferStatus = PROVIDED_TO_DSD; /** @req DCM241 */
\r
625 runtime->responsePendingCount = DCM_Config.Dsl->DslDiagResp->DslDiagRespMaxNumRespPend;
\r
626 runtime->diagnosticResponseFromDsd.SduDataPtr = protocolRow->DslProtocolTxBufferID->pduInfo.SduDataPtr;
\r
627 runtime->diagnosticResponseFromDsd.SduLength = protocolRow->DslProtocolTxBufferID->pduInfo.SduLength;
\r
628 DEBUG( DEBUG_MEDIUM, "DsdDslDataIndication(DcmDslProtocolTxPduId=%d, dcmRxPduId=%d)\n", mainConnection->DslProtocolTx->DcmDslProtocolTxPduId, dcmRxPduId);
\r
629 runtime->diagReqestRxPduId = dcmRxPduId;
\r
630 DsdDslDataIndication( // qqq: We are inside a critical section.
\r
631 &(runtime->diagnosticRequestFromTester),
\r
632 protocolRow->DslProtocolSIDTable, /** @req DCM035 */
\r
633 protocolRx->DslProtocolAddrType,
\r
634 mainConnection->DslProtocolTx->DcmDslProtocolTxPduId,
\r
635 &(runtime->diagnosticResponseFromDsd),
\r
639 } else { /** @req DCM344 */
\r
640 // The indication was not equal to NTFRSLT_OK, release the resources and no forward to DSD.
\r
641 runtime->externalRxBufferStatus = NOT_IN_USE;
\r
642 protocolRow->DslProtocolRxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
645 // It is the local buffer that was provided to the PduR, that buffer
\r
646 // is only used for tester present reception in parallel to diagnostic
\r
648 if (runtime->localRxBuffer.status == PROVIDED_TO_PDUR) {
\r
649 if ( result == NTFRSLT_OK ) { // Make sure that the data in buffer is valid.
\r
650 if (isTesterPresentCommand(&(runtime->localRxBuffer.PduInfo))) {
\r
651 startS3SessionTimer(runtime, protocolRow); /** @req DCM141 *//** @req DCM112 *//** @req DCM113 */
\r
654 runtime->localRxBuffer.status = NOT_IN_USE;
\r
657 McuE_ExitCriticalSection(state);
\r
661 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
662 // Implements 'BufReq_ReturnType Dcm_ProvideTxBuffer(PduIdType dcmTxPduId,
\r
663 // PduInfoType **pduInfoPtr, PduLengthType length)'.
\r
664 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
665 // This TX-buffer request is likely triggered by the transport layer (i.e. CanTp)
\r
666 // after PduR_DcmTransmit() has been called (via PduR to CanTp) indicating that something
\r
667 // is to be sent. The PduR_DcmTransmit() call is done from the DSL main function when
\r
668 // it has detected that the pending request has been answered by DSD
\r
669 // (or any other module?).
\r
671 BufReq_ReturnType DslProvideTxBuffer(PduIdType dcmTxPduId, const PduInfoType **pduInfoPtr, PduLengthType length) {
\r
672 BufReq_ReturnType ret = BUFREQ_NOT_OK;
\r
673 const Dcm_DslProtocolTxType *protocolTx = NULL;
\r
674 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
675 const Dcm_DslConnectionType *connection = NULL;
\r
676 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
677 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
679 DEBUG( DEBUG_MEDIUM, "DslProvideTxBuffer=%d\n", dcmTxPduId);
\r
680 if (findTxPduIdParentConfigurationLeafs(dcmTxPduId, &protocolTx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
681 switch (runtime->externalTxBufferStatus) { // ### EXTERNAL TX BUFFER ###
\r
682 case DCM_TRANSMIT_SIGNALED: {
\r
683 /** @req DCM346 */ /* Length verification is already done if this state is reached. */
\r
684 *pduInfoPtr = &(protocolRow->DslProtocolTxBufferID->pduInfo);
\r
685 runtime->externalTxBufferStatus = PROVIDED_TO_PDUR; /** @req DCM349 */
\r
690 DEBUG( DEBUG_MEDIUM, "DCM_TRANSMIT_SIGNALED was not signaled in the external buffer\n");
\r
691 ret = BUFREQ_NOT_OK;
\r
694 if (ret == BUFREQ_NOT_OK) {
\r
695 switch (runtime->localTxBuffer.status) { // ### LOCAL TX BUFFER ###
\r
696 case DCM_TRANSMIT_SIGNALED: {
\r
697 runtime->localTxBuffer.PduInfo.SduDataPtr = runtime->localTxBuffer.buffer;
\r
698 runtime->localTxBuffer.PduInfo.SduLength = runtime->localTxBuffer.messageLenght;
\r
699 *pduInfoPtr = &runtime->localTxBuffer.PduInfo;
\r
700 runtime->localTxBuffer.status = PROVIDED_TO_PDUR; // Now the DSL should not touch this Tx-buffer anymore.
\r
705 DEBUG( DEBUG_MEDIUM, "DCM_TRANSMIT_SIGNALED was not signaled for the local buffer either\n");
\r
706 ret = BUFREQ_NOT_OK;
\r
714 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
715 // Implements 'void Dcm_TxConfirmation(PduIdType dcmTxPduId, NotifResultType result))'.
\r
716 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
717 // This function is called by the PduR (which has been trigged by i.e. CanTp)
\r
718 // when a transmission has been successfully finished, have had errors or
\r
719 // is even stopped.
\r
721 void DslTxConfirmation(PduIdType dcmTxPduId, NotifResultType result) {
\r
722 const Dcm_DslProtocolTxType *protocolTx = NULL;
\r
723 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
724 const Dcm_DslConnectionType *connection = NULL;
\r
725 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
726 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
729 DEBUG( DEBUG_MEDIUM, "DslTxConfirmation=%d, result=%d\n", dcmTxPduId, result);
\r
730 if (findTxPduIdParentConfigurationLeafs(dcmTxPduId, &protocolTx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
731 boolean externalBufferReleased = FALSE;
\r
733 // Free the buffer and free the Pdu runtime data buffer.
\r
734 state = McuE_EnterCriticalSection();
\r
735 switch (runtime->externalTxBufferStatus) { // ### EXTERNAL TX BUFFER ###
\r
736 case PROVIDED_TO_PDUR: {
\r
737 ComM_DCM_InactivateDiagnostic(); /** @req DCM164 */
\r
738 startS3SessionTimer(runtime, protocolRow); /** @req DCM141 */
\r
739 releaseExternalRxTxBuffers(protocolRow, runtime); /** @req DCM118 *//** @req DCM352 *//** @req DCM353 *//** @req DCM354 */
\r
740 externalBufferReleased = TRUE;
\r
741 DEBUG( DEBUG_MEDIUM, "Released external buffer OK!\n");
\r
742 DsdDataConfirmation(mainConnection->DslProtocolTx->DcmDslProtocolTxPduId, result); /** @req DCM117 *//** @req DCM235 */
\r
748 if (externalBufferReleased == FALSE) {
\r
749 switch (runtime->localTxBuffer.status) { // ### LOCAL TX BUFFER ###
\r
750 case PROVIDED_TO_PDUR:
\r
751 DEBUG( DEBUG_MEDIUM, "Released local buffer buffer OK!\n");
\r
752 runtime->localTxBuffer.status = DCM_IDLE;
\r
755 DEBUG( DEBUG_MEDIUM, "WARNING! DslTxConfirmation could not release external or local buffer!\n");
\r
759 McuE_ExitCriticalSection(state);
\r