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
23 #include "McuExtensions.h"
\r
25 #include "Dcm_Internal.h"
\r
27 #if defined(USE_COMM)
\r
28 #include "ComM_Dcm.h"
\r
30 #include "PduR_Dcm.h"
\r
31 #include "ComStack_Types.h"
\r
32 //#define USE_DEBUG_PRINTF
\r
35 #define DECREMENT(timer) { if (timer > 0){timer--;} }
\r
36 #define DCM_CONVERT_MS_TO_MAIN_CYCLES(x) ((x)/DCM_MAIN_FUNCTION_PERIOD_TIME_MS)
\r
42 // #define MAX_PARALLEL_PROTOCOLS_ALLOWED 1
\r
46 //boolean diagnosticRequestPending; // This is a "semaphore" because DSD and DCM can handle multiple/parallel request at the moment.
\r
47 const Dcm_DslProtocolRowType *activeProtocol; // Points to the currently active protocol.
\r
48 // const Dcm_DslProtocolRowType *preemptedProtocol; // Points to the currently active protocol - reserved for future use
\r
49 // Dcm_DslRunTimeProtocolParametersType protocolList[MAX_PARALLEL_PROTOCOLS_ALLOWED]; // Reserved for future use
\r
50 } DcmDsl_RunTimeDataType;
\r
52 static DcmDsl_RunTimeDataType DcmDslRunTimeData = {
\r
54 .activeProtocol = NULL
\r
55 // .preemptedProtocol = NULL,
\r
56 // .protocolList = {}
\r
60 // ################# HELPER FUNCTIONS START #################
\r
63 // This function reset/stars the session (S3) timer. See requirement
\r
64 // DCM141 when that action should be taken.
\r
66 static inline void startS3SessionTimer(Dcm_DslRunTimeProtocolParametersType *runtime, const Dcm_DslProtocolRowType *protocolRow) {
\r
67 const Dcm_DslProtocolTimingRowType *timeParams;
\r
68 timeParams = protocolRow->DslProtocolTimeLimit;
\r
69 runtime->S3ServerTimeoutCount = DCM_CONVERT_MS_TO_MAIN_CYCLES(timeParams->TimStrS3Server);
\r
72 // - - - - - - - - - - -
\r
75 // This function reset/stars the session (S3) timer. See requirement
\r
76 // DCM141 when that action should be taken.
\r
78 static inline void stopS3SessionTimer(Dcm_DslRunTimeProtocolParametersType *runtime) {
\r
79 runtime->S3ServerTimeoutCount = 0;
\r
82 // - - - - - - - - - - -
\r
85 // This function implements the requirement DCM139 when
\r
86 // transition from one session to another.
\r
88 static void changeDiagnosticSession(Dcm_DslRunTimeProtocolParametersType *runtime, Dcm_SesCtrlType newSession) {
\r
92 switch (runtime->sessionControl) {
\r
93 case DCM_DEFAULT_SESSION: // "default".
\r
96 case DCM_PROGRAMMING_SESSION:
\r
97 case DCM_EXTENDED_DIAGNOSTIC_SESSION:
\r
98 case DCM_SAFTEY_SYSTEM_DIAGNOSTIC_SESSION:
\r
99 case DCM_ALL_SESSION_LEVEL:
\r
100 runtime->securityLevel = DCM_SEC_LEV_LOCKED; // "0x00".
\r
104 DET_REPORTERROR(MODULE_ID_DCM, 0, DCM_CHANGE_DIAGNOSTIC_SESSION_ID, DCM_E_PARAM);
\r
105 DEBUG(DEBUG_MEDIUM, "Old session invalid");
\r
109 switch (newSession) {
\r
110 case DCM_DEFAULT_SESSION: // "default".
\r
111 case DCM_PROGRAMMING_SESSION:
\r
112 case DCM_EXTENDED_DIAGNOSTIC_SESSION:
\r
113 case DCM_SAFTEY_SYSTEM_DIAGNOSTIC_SESSION:
\r
114 case DCM_ALL_SESSION_LEVEL:
\r
115 runtime->sessionControl = newSession;
\r
119 DET_REPORTERROR(MODULE_ID_DCM, 0, DCM_CHANGE_DIAGNOSTIC_SESSION_ID, DCM_E_PARAM);
\r
120 DEBUG(DEBUG_MEDIUM, "New session invalid");
\r
125 // - - - - - - - - - - -
\r
127 void DslResetSessionTimeoutTimer(void) {
\r
128 const Dcm_DslProtocolRowType *activeProtocol;
\r
129 Dcm_DslRunTimeProtocolParametersType *runtime;
\r
131 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
132 runtime = activeProtocol->DslRunTimeProtocolParameters;
\r
133 startS3SessionTimer(runtime, activeProtocol); /** @req DCM141 */
\r
136 // - - - - - - - - - - -
\r
138 void DslGetCurrentServiceTable(const Dcm_DsdServiceTableType **currentServiceTable) { /** @req DCM195 */
\r
139 const Dcm_DslProtocolRowType *activeProtocol;
\r
141 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
142 if (activeProtocol != NULL) {
\r
143 *currentServiceTable = activeProtocol->DslProtocolSIDTable;
\r
147 // - - - - - - - - - - -
\r
149 Std_ReturnType DslGetActiveProtocol(Dcm_ProtocolType *protocolId) { /** @req DCM340 */
\r
150 Std_ReturnType ret = E_NOT_OK;
\r
151 const Dcm_DslProtocolRowType *activeProtocol;
\r
153 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
154 if (activeProtocol != NULL) {
\r
155 *protocolId = activeProtocol->DslProtocolID;
\r
161 // - - - - - - - - - - -
\r
163 void DslSetSecurityLevel(Dcm_SecLevelType secLevel) { /** @req DCM020 */
\r
164 const Dcm_DslProtocolRowType *activeProtocol;
\r
165 Dcm_DslRunTimeProtocolParametersType *runtime;
\r
167 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
168 runtime = activeProtocol->DslRunTimeProtocolParameters;
\r
169 runtime->securityLevel = secLevel;
\r
172 // - - - - - - - - - - -
\r
174 Std_ReturnType DslGetSecurityLevel(Dcm_SecLevelType *secLevel) { /** @req DCM020 *//** @req DCM338 */
\r
175 Std_ReturnType ret = E_NOT_OK;
\r
176 const Dcm_DslProtocolRowType *activeProtocol;
\r
177 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
179 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
180 if (activeProtocol != NULL) {
\r
181 runtime = activeProtocol->DslRunTimeProtocolParameters;
\r
182 *secLevel = runtime->securityLevel;
\r
188 // - - - - - - - - - - -
\r
190 void DslSetSesCtrlType(Dcm_SesCtrlType sesCtrl) { /** @req DCM022 */
\r
191 const Dcm_DslProtocolRowType *activeProtocol;
\r
192 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
194 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
195 if (activeProtocol != NULL) {
\r
196 runtime = activeProtocol->DslRunTimeProtocolParameters;
\r
197 if (runtime->sessionControl != sesCtrl) {
\r
198 changeDiagnosticSession(runtime, sesCtrl);
\r
199 DslResetSessionTimeoutTimer();
\r
204 // - - - - - - - - - - -
\r
206 Std_ReturnType DslGetSesCtrlType(Dcm_SesCtrlType *sesCtrlType) { /** @req DCM022 *//** @req DCM339 */
\r
207 Std_ReturnType ret = E_NOT_OK;
\r
208 const Dcm_DslProtocolRowType *activeProtocol;
\r
209 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
211 activeProtocol = DcmDslRunTimeData.activeProtocol;
\r
212 if (activeProtocol != NULL) {
\r
213 runtime = activeProtocol->DslRunTimeProtocolParameters;
\r
214 *sesCtrlType = runtime->sessionControl;
\r
220 // - - - - - - - - - - -
\r
222 static boolean findRxPduIdParentConfigurationLeafs(PduIdType dcmRxPduId,
\r
223 const Dcm_DslProtocolRxType **protocolRx,
\r
224 const Dcm_DslMainConnectionType **mainConnection,
\r
225 const Dcm_DslConnectionType **connection,
\r
226 const Dcm_DslProtocolRowType **protocolRow,
\r
227 Dcm_DslRunTimeProtocolParametersType **runtime) {
\r
229 boolean ret = FALSE;
\r
230 if (dcmRxPduId < DCM_DSL_RX_PDU_ID_LIST_LENGTH) {
\r
231 *protocolRx = &DCM_Config.Dsl->DslProtocol->DslProtocolRxGlobalList[dcmRxPduId];
\r
232 *mainConnection = (*protocolRx)->DslMainConnectionParent;
\r
233 *connection = (*mainConnection)->DslConnectionParent;
\r
234 *protocolRow = (*connection)->DslProtocolRow;
\r
235 *runtime = (*protocolRow)->DslRunTimeProtocolParameters;
\r
241 // - - - - - - - - - - -
\r
243 static boolean findTxPduIdParentConfigurationLeafs(PduIdType dcmTxPduId,
\r
244 const Dcm_DslProtocolTxType **protocolTx,
\r
245 const Dcm_DslMainConnectionType **mainConnection,
\r
246 const Dcm_DslConnectionType **connection,
\r
247 const Dcm_DslProtocolRowType **protocolRow,
\r
248 Dcm_DslRunTimeProtocolParametersType **runtime) {
\r
250 boolean ret = FALSE;
\r
251 if (dcmTxPduId < DCM_DSL_TX_PDU_ID_LIST_LENGTH) {
\r
252 *protocolTx = &DCM_Config.Dsl->DslProtocol->DslProtocolTxGlobalList[dcmTxPduId];
\r
253 *mainConnection = (*protocolTx)->DslMainConnectionParent;
\r
254 *connection = (*mainConnection)->DslConnectionParent;
\r
255 *protocolRow = (*connection)->DslProtocolRow;
\r
256 *runtime = (*protocolRow)->DslRunTimeProtocolParameters;
\r
262 // - - - - - - - - - - -
\r
264 static inline void releaseExternalRxTxBuffers(const Dcm_DslProtocolRowType *protocolRow,
\r
265 Dcm_DslRunTimeProtocolParametersType *runtime) {
\r
267 protocolRow->DslProtocolTxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
268 protocolRow->DslProtocolRxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
269 runtime->externalTxBufferStatus = NOT_IN_USE; // We are waiting for DSD to return the buffer. qqq.
\r
270 runtime->externalRxBufferStatus = NOT_IN_USE; // We are waiting for DSD to return the buffer. qqq.
\r
273 // - - - - - - - - - - -
\r
276 static inline void releaseExternalRxTxBuffersHelper(PduIdType rxPduIdRef) {
\r
277 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
278 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
279 const Dcm_DslConnectionType *connection = NULL;
\r
280 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
281 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
283 if (findRxPduIdParentConfigurationLeafs(rxPduIdRef, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
284 releaseExternalRxTxBuffers(protocolRow, runtime);
\r
288 // - - - - - - - - - - -
\r
291 * This function is called from the DSD module to the DSL when
\r
292 * a response to a diagnostic request has been copied into the
\r
293 * given TX-buffer and is ready for transmission.
\r
295 void DslDsdProcessingDone(PduIdType rxPduIdRef, DsdProcessingDoneResultType responseResult) {
\r
296 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
297 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
298 const Dcm_DslConnectionType *connection = NULL;
\r
299 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
300 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
302 DEBUG( DEBUG_MEDIUM, "DslDsdProcessingDone rxPduIdRef=%d\n", rxPduIdRef);
\r
304 if (findRxPduIdParentConfigurationLeafs(rxPduIdRef, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
305 imask_t state = McuE_EnterCriticalSection();
\r
306 switch (responseResult) {
\r
307 case DSD_TX_RESPONSE_READY:
\r
308 runtime->externalTxBufferStatus = DSD_PENDING_RESPONSE_SIGNALED; /** @req DCM114 */
\r
310 case DSD_TX_RESPONSE_SUPPRESSED: /** @req DCM238 */
\r
311 DEBUG( DEBUG_MEDIUM, "DslDsdProcessingDone called with DSD_TX_RESPONSE_SUPPRESSED.\n");
\r
312 releaseExternalRxTxBuffersHelper(rxPduIdRef);
\r
315 DEBUG( DEBUG_MEDIUM, "Unknown response result from DslDsdProcessingDone!\n");
\r
318 McuE_ExitCriticalSection(state);
\r
322 // - - - - - - - - - - -
\r
325 * This function preparing transmission of response
\r
326 * pending message to tester.
\r
328 static void sendResponse(const Dcm_DslProtocolRowType *protocol,
\r
329 Dcm_NegativeResponseCodeType responseCode) {
\r
330 //Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
331 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
332 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
333 const Dcm_DslConnectionType *connection = NULL;
\r
334 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
335 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
336 Std_ReturnType transmitResult;
\r
339 imask_t state = McuE_EnterCriticalSection();
\r
340 if (findRxPduIdParentConfigurationLeafs(protocol->DslRunTimeProtocolParameters->diagReqestRxPduId, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
341 if (runtime->localTxBuffer.status == NOT_IN_USE) {
\r
342 runtime->localTxBuffer.status = PROVIDED_TO_DSD;
\r
343 runtime->localTxBuffer.buffer[0] = SID_NEGATIVE_RESPONSE;
\r
344 runtime->localTxBuffer.buffer[1] = protocol->DslProtocolRxBufferID->pduInfo.SduDataPtr[2];
\r
345 runtime->localTxBuffer.buffer[2] = responseCode;
\r
346 runtime->localTxBuffer.PduInfo.SduDataPtr = runtime->localTxBuffer.buffer;
\r
347 runtime->localTxBuffer.PduInfo.SduLength = 3;
\r
348 runtime->localTxBuffer.status = DCM_TRANSMIT_SIGNALED; // In the DslProvideTxBuffer 'callback' this state signals it is the local buffer we are interested in sending.
\r
349 transmitResult = PduR_DcmTransmit(mainConnection->DslProtocolTx->DcmDslProtocolTxPduId, &(runtime->localTxBuffer.PduInfo));/** @req DCM115.Partially */ /* The P2ServerMin has not been implemented. */
\r
350 if (transmitResult != E_OK) {
\r
351 // TODO: What to do here?
\r
355 McuE_ExitCriticalSection(state);
\r
358 // - - - - - - - - - - -
\r
360 static Std_ReturnType StartProtocolHelper(Dcm_ProtocolType protocolId) {
\r
361 Std_ReturnType ret = E_NOT_OK;
\r
364 for (i = 0; !DCM_Config.Dsl->DslCallbackDCMRequestService[i].Arc_EOL; i++) {
\r
365 if (DCM_Config.Dsl->DslCallbackDCMRequestService[i].StartProtocol != NULL) {
\r
366 ret = DCM_Config.Dsl->DslCallbackDCMRequestService[i]. StartProtocol(protocolId);
\r
375 // - - - - - - - - - - -
\r
377 static boolean isTesterPresentCommand(const PduInfoType *rxPdu) {
\r
378 boolean ret = FALSE;
\r
379 if ((rxPdu->SduDataPtr[0] == SID_TESTER_PRESENT) && (rxPdu->SduDataPtr[1] & SUPPRESS_POS_RESP_BIT)) {
\r
385 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
386 // Implements 'void Dcm_Init(void)' for DSL.
\r
387 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
388 void DslInit(void) {
\r
389 const Dcm_DslProtocolRowType *listEntry;
\r
390 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
392 listEntry = DCM_Config.Dsl->DslProtocol->DslProtocolRowList;
\r
393 while (listEntry->Arc_EOL == FALSE) {
\r
394 runtime = listEntry->DslRunTimeProtocolParameters;
\r
395 runtime->externalRxBufferStatus = DCM_IDLE;
\r
396 runtime->externalTxBufferStatus = DCM_IDLE;
\r
397 runtime->localRxBuffer.status = DCM_IDLE;
\r
398 runtime->localTxBuffer.status = DCM_IDLE;
\r
399 runtime->securityLevel = DCM_SEC_LEV_LOCKED; /** @req DCM033 */
\r
400 runtime->sessionControl = DCM_DEFAULT_SESSION; /** @req DCM034 */
\r
401 listEntry->DslProtocolRxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
402 listEntry->DslProtocolRxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
405 //DcmDslRunTimeData.diagnosticRequestPending = FALSE;
\r
406 DcmDslRunTimeData.initRun = TRUE;
\r
409 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
410 // Implements 'void Dcm_MainFunction(void)' for DSL.
\r
411 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
413 void DslMain(void) {
\r
414 const Dcm_DslProtocolRowType *protocolRowEntry;
\r
415 const Dcm_DslProtocolTimingRowType *timeParams = NULL;
\r
416 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
418 protocolRowEntry = DCM_Config.Dsl->DslProtocol->DslProtocolRowList;
\r
419 while (protocolRowEntry->Arc_EOL == FALSE) {
\r
420 runtime = protocolRowEntry->DslRunTimeProtocolParameters;
\r
421 if (runtime != NULL) {
\r
422 // #### HANDLE THE TESTER PRESENT PRESENCE ####
\r
423 if (runtime->sessionControl != DCM_DEFAULT_SESSION) { // Timeout if tester present is lost.
\r
424 DECREMENT(runtime->S3ServerTimeoutCount);
\r
425 if (runtime->S3ServerTimeoutCount == 0) {
\r
426 changeDiagnosticSession(runtime, DCM_DEFAULT_SESSION); /** @req DCM140 */
\r
429 switch (runtime->externalTxBufferStatus) { // #### TX buffer state. ####
\r
431 //DEBUG( DEBUG_MEDIUM, "state NOT_IN_USE!\n");
\r
433 case PROVIDED_TO_DSD: {
\r
434 DEBUG( DEBUG_MEDIUM, "debug_count=%d\n", debug_count);
\r
435 DECREMENT(runtime->stateTimeoutCount);
\r
436 if (runtime->stateTimeoutCount == 0) {
\r
437 DEBUG( DEBUG_MEDIUM, "State PROVIDED_TO_DSD timed out!", debug_count);
\r
438 timeParams = protocolRowEntry->DslProtocolTimeLimit;
\r
439 runtime->stateTimeoutCount = DCM_CONVERT_MS_TO_MAIN_CYCLES(timeParams->TimStrP2ServerMax); /* Reinitiate timer, see 9.2.2. */
\r
440 if (DCM_Config.Dsl->DslDiagResp != NULL) {
\r
441 if (DCM_Config.Dsl->DslDiagResp->DslDiagRespForceRespPendEn == TRUE) {
\r
442 if (runtime->responsePendingCount != 0) {
\r
443 sendResponse(protocolRowEntry, DCM_E_RESPONSEPENDING); /** @req DCM024 */
\r
444 DECREMENT( runtime->responsePendingCount );
\r
446 sendResponse(protocolRowEntry, DCM_E_GENERALREJECT); /** @req DCM120 */
\r
447 releaseExternalRxTxBuffers(protocolRowEntry, runtime);
\r
450 DEBUG( DEBUG_MEDIUM, "Not configured to send response pending, now sending general reject!\n");
\r
451 sendResponse(protocolRowEntry, DCM_E_GENERALREJECT);
\r
452 releaseExternalRxTxBuffers(protocolRowEntry, runtime);
\r
458 case DSD_PENDING_RESPONSE_SIGNALED:
\r
459 // The DSD has signaled to DSL that the diagnostic response is available in the Tx buffer.
\r
460 // Make sure that response pending or general reject have not been issued,
\r
461 // if so we can not transmit to PduR because we would not know from where
\r
462 // the Tx confirmation resides later.
\r
463 DEBUG( DEBUG_MEDIUM, "state DSD_PENDING_RESPONSE_SIGNALED!\n");
\r
464 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
465 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
466 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
467 const Dcm_DslConnectionType *connection = NULL;
\r
468 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
469 Std_ReturnType transmitResult;
\r
471 if (findRxPduIdParentConfigurationLeafs(runtime->diagReqestRxPduId, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
472 const PduIdType txPduId = mainConnection->DslProtocolTx->DcmDslProtocolTxPduId;
\r
473 DEBUG( DEBUG_MEDIUM, "runtime->externalTxBufferStatus enter state DCM_TRANSMIT_SIGNALED.\n" );
\r
474 runtime->externalTxBufferStatus = DCM_TRANSMIT_SIGNALED;
\r
475 transmitResult = PduR_DcmTransmit(txPduId, &runtime->diagnosticResponseFromDsd); /** @req DCM237 *//* Will trigger PduR (CanTP) to call DslProvideTxBuffer(). */
\r
476 if (transmitResult != E_OK) {
\r
477 // TODO: What to do here?
\r
480 DEBUG( DEBUG_MEDIUM, "***** WARNING, THIS IS UNEXPECTED !!! ********.\n" );
\r
481 const PduIdType txPduId = protocolRowEntry->DslConnection->DslMainConnection->DslProtocolTx->DcmDslProtocolTxPduId;
\r
482 DEBUG( DEBUG_MEDIUM, "runtime->externalTxBufferStatus enter state DSD_PENDING_RESPONSE_SIGNALED.\n", txPduId);
\r
483 runtime->externalTxBufferStatus = DCM_TRANSMIT_SIGNALED;
\r
484 DEBUG( DEBUG_MEDIUM, "Calling PduR_DcmTransmit with txPduId = %d from DslMain\n", txPduId);
\r
485 transmitResult = PduR_DcmTransmit(txPduId, &runtime->diagnosticResponseFromDsd); /** @req DCM237 *//* Will trigger PduR (CanTP) to call DslProvideTxBuffer(). */
\r
486 if (transmitResult != E_OK) {
\r
487 // TODO: What to do here?
\r
492 case DCM_TRANSMIT_SIGNALED:
\r
493 //DEBUG( DEBUG_MEDIUM, "state DSD_PENDING_RESPONSE_SIGNALED!\n");
\r
495 case PROVIDED_TO_PDUR: // The valid data is being transmitted by TP-layer.
\r
496 //DEBUG( DEBUG_MEDIUM, "state DSD_PENDING_RESPONSE_SIGNALED!\n");
\r
502 protocolRowEntry++;
\r
506 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
507 // Implements 'BufReq_ReturnType Dcm_ProvideRxBuffer(PduIdType dcmRxPduId,
\r
508 // PduLengthType tpSduLength, PduInfoType **pduInfoPtr)'.
\r
509 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
510 // This function is called called by the PduR typically when CanTp has
\r
511 // received a FF or a single frame and needs to obtain a buffer from the
\r
512 // receiver so that received data can be forwarded.
\r
514 BufReq_ReturnType DslProvideRxBufferToPdur(PduIdType dcmRxPduId, PduLengthType tpSduLength, const PduInfoType **pduInfoPtr) {
\r
515 BufReq_ReturnType ret = BUFREQ_NOT_OK;
\r
516 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
517 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
518 const Dcm_DslConnectionType *connection = NULL;
\r
519 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
520 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
522 DEBUG( DEBUG_MEDIUM, "DslProvideRxBufferToPdur(dcmRxPduId=%d) called!\n", dcmRxPduId);
\r
523 imask_t state = McuE_EnterCriticalSection();
\r
524 if (findRxPduIdParentConfigurationLeafs(dcmRxPduId, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
525 const Dcm_DslBufferType *externalRxBuffer = protocolRow->DslProtocolRxBufferID;
\r
526 if (externalRxBuffer->pduInfo.SduLength >= tpSduLength) { /** @req DCM443 */
\r
527 if ((runtime->externalRxBufferStatus == NOT_IN_USE) && (externalRxBuffer->externalBufferRuntimeData->status == BUFFER_AVAILABLE)) {
\r
528 DEBUG( DEBUG_MEDIUM, "External buffer available!\n");
\r
529 // ### EXTERNAL BUFFER IS AVAILABLE; GRAB IT AND REMEBER THAT WE OWN IT! ###
\r
530 externalRxBuffer->externalBufferRuntimeData->status = BUFFER_BUSY;
\r
531 runtime->diagnosticRequestFromTester.SduDataPtr = externalRxBuffer->pduInfo.SduDataPtr;
\r
532 runtime->diagnosticRequestFromTester.SduLength = tpSduLength;
\r
533 *pduInfoPtr = &(runtime->diagnosticRequestFromTester);
\r
534 runtime->externalRxBufferStatus = PROVIDED_TO_PDUR; /** @req DCM342 */
\r
537 DEBUG( DEBUG_MEDIUM, "Local buffer available!\n");
\r
538 if (runtime->externalRxBufferStatus == PROVIDED_TO_DSD) {
\r
539 // ### EXTERNAL BUFFER IS IN USE BY THE DSD, TRY TO USE LOCAL BUFFER! ###
\r
540 if (runtime->localRxBuffer.status == NOT_IN_USE) {
\r
541 if (tpSduLength < DCM_DSL_LOCAL_BUFFER_LENGTH) {
\r
542 runtime->localRxBuffer.status = PROVIDED_TO_PDUR;
\r
543 runtime->localRxBuffer.PduInfo.SduDataPtr = runtime->localRxBuffer.buffer;
\r
544 runtime->localRxBuffer.PduInfo.SduLength = tpSduLength;
\r
545 *pduInfoPtr = &(runtime->localRxBuffer.PduInfo);
\r
552 // The buffer is in use by the PduR, we can not help this because then
\r
553 // we would have two different Rx-indications with same PduId but we
\r
554 // will not know which buffer the indication should free.
\r
555 ret = BUFREQ_BUSY; /** @req DCM445 */
\r
559 ret = BUFREQ_OVFL; /** @req DCM444 */
\r
561 if (ret == BUFREQ_OK) {
\r
562 stopS3SessionTimer(runtime); /** @req DCM141 */
\r
565 McuE_ExitCriticalSection(state);
\r
569 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
570 // Implements 'void Dcm_RxIndication(PduIdType dcmRxPduId, NotifResultType result)'.
\r
571 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
572 // This function is called called by the PduR typically when CanTp has
\r
573 // received the diagnostic request, copied it to the provided buffer and need to indicate
\r
574 // this to the DCM (DSL) module via proprietary API.
\r
576 void DslRxIndicationFromPduR(PduIdType dcmRxPduId, NotifResultType result) {
\r
577 const Dcm_DslProtocolRxType *protocolRx = NULL;
\r
578 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
579 const Dcm_DslConnectionType *connection = NULL;
\r
580 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
581 const Dcm_DslProtocolTimingRowType *timeParams = NULL;
\r
582 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
583 Std_ReturnType higherLayerResp;
\r
586 /** @req DCM345, this needs to be verified when connection to CanIf works. */
\r
588 if (findRxPduIdParentConfigurationLeafs(dcmRxPduId, &protocolRx, &mainConnection, &connection, &protocolRow, &runtime)) {
\r
589 timeParams = protocolRow->DslProtocolTimeLimit;
\r
590 // We need to find out in what buffer we can find our Rx data (it can
\r
591 // be either in the normal RX-buffer or the 'extra' buffer for implementing
\r
592 // the Concurrent "Test Present" functionality.
\r
593 state = McuE_EnterCriticalSection();
\r
594 if (runtime->externalRxBufferStatus == PROVIDED_TO_PDUR) {
\r
595 if ( result == NTFRSLT_OK ) { /** @req DCM111 */
\r
596 if (isTesterPresentCommand(&(protocolRow->DslProtocolRxBufferID->pduInfo))) {
\r
597 startS3SessionTimer(runtime, protocolRow); /** @req DCM141 *//** @req DCM112 *//** @req DCM113 */
\r
598 runtime->externalRxBufferStatus = NOT_IN_USE;
\r
599 protocolRow->DslProtocolRxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
601 if (runtime->protocolStarted == FALSE) {
\r
602 higherLayerResp = StartProtocolHelper(protocolRow->DslProtocolID); /** @req DCM036 */
\r
603 if (higherLayerResp == E_OK) {
\r
604 runtime->protocolStarted = TRUE;
\r
605 DcmDslRunTimeData.activeProtocol = protocolRow;
\r
608 if (runtime->protocolStarted == TRUE) {
\r
609 if (runtime->diagnosticActiveComM == FALSE) {
\r
610 #if defined(USE_COMM)
\r
611 ComM_DCM_ActivateDiagnostic(); /** @req DCM163 */
\r
613 runtime->diagnosticActiveComM = TRUE;
\r
615 timeParams = protocolRow->DslProtocolTimeLimit;
\r
616 runtime->stateTimeoutCount = DCM_CONVERT_MS_TO_MAIN_CYCLES(timeParams->TimStrP2ServerMax); /* See 9.2.2. */
\r
617 runtime->externalRxBufferStatus = PROVIDED_TO_DSD; /** @req DCM241 */
\r
618 if (runtime->externalTxBufferStatus == NOT_IN_USE) {
\r
619 DEBUG( DEBUG_MEDIUM, "External Tx buffer available, we can pass it to DSD.\n");
\r
621 DEBUG( DEBUG_MEDIUM, "External buffer not available, a response is being transmitted?\n");
\r
623 runtime->externalTxBufferStatus = PROVIDED_TO_DSD; /** @req DCM241 */
\r
624 runtime->responsePendingCount = DCM_Config.Dsl->DslDiagResp->DslDiagRespMaxNumRespPend;
\r
625 runtime->diagnosticResponseFromDsd.SduDataPtr = protocolRow->DslProtocolTxBufferID->pduInfo.SduDataPtr;
\r
626 runtime->diagnosticResponseFromDsd.SduLength = protocolRow->DslProtocolTxBufferID->pduInfo.SduLength;
\r
627 DEBUG( DEBUG_MEDIUM, "DsdDslDataIndication(DcmDslProtocolTxPduId=%d, dcmRxPduId=%d)\n", mainConnection->DslProtocolTx->DcmDslProtocolTxPduId, dcmRxPduId);
\r
628 runtime->diagReqestRxPduId = dcmRxPduId;
\r
629 DsdDslDataIndication( // qqq: We are inside a critical section.
\r
630 &(runtime->diagnosticRequestFromTester),
\r
631 protocolRow->DslProtocolSIDTable, /** @req DCM035 */
\r
632 protocolRx->DslProtocolAddrType,
\r
633 mainConnection->DslProtocolTx->DcmDslProtocolTxPduId,
\r
634 &(runtime->diagnosticResponseFromDsd),
\r
638 } else { /** @req DCM344 */
\r
639 // The indication was not equal to NTFRSLT_OK, release the resources and no forward to DSD.
\r
640 runtime->externalRxBufferStatus = NOT_IN_USE;
\r
641 protocolRow->DslProtocolRxBufferID->externalBufferRuntimeData->status = BUFFER_AVAILABLE;
\r
644 // It is the local buffer that was provided to the PduR, that buffer
\r
645 // is only used for tester present reception in parallel to diagnostic
\r
647 if (runtime->localRxBuffer.status == PROVIDED_TO_PDUR) {
\r
648 if ( result == NTFRSLT_OK ) { // Make sure that the data in buffer is valid.
\r
649 if (isTesterPresentCommand(&(runtime->localRxBuffer.PduInfo))) {
\r
650 startS3SessionTimer(runtime, protocolRow); /** @req DCM141 *//** @req DCM112 *//** @req DCM113 */
\r
653 runtime->localRxBuffer.status = NOT_IN_USE;
\r
656 McuE_ExitCriticalSection(state);
\r
660 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
661 // Implements 'BufReq_ReturnType Dcm_ProvideTxBuffer(PduIdType dcmTxPduId,
\r
662 // PduInfoType **pduInfoPtr, PduLengthType length)'.
\r
663 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
\r
664 // This TX-buffer request is likely triggered by the transport layer (i.e. CanTp)
\r
665 // after PduR_DcmTransmit() has been called (via PduR to CanTp) indicating that something
\r
666 // is to be sent. The PduR_DcmTransmit() call is done from the DSL main function when
\r
667 // it has detected that the pending request has been answered by DSD
\r
668 // (or any other module?).
\r
670 BufReq_ReturnType DslProvideTxBuffer(PduIdType dcmTxPduId, const PduInfoType **pduInfoPtr, PduLengthType length) {
\r
671 BufReq_ReturnType ret = BUFREQ_NOT_OK;
\r
672 const Dcm_DslProtocolTxType *protocolTx = NULL;
\r
673 const Dcm_DslMainConnectionType *mainConnection = NULL;
\r
674 const Dcm_DslConnectionType *connection = NULL;
\r
675 const Dcm_DslProtocolRowType *protocolRow = NULL;
\r
676 Dcm_DslRunTimeProtocolParametersType *runtime = NULL;
\r
678 (void)length; // Currently not used, this is only to remove compilation warnings
\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 #if defined(USE_COMM)
\r
738 ComM_DCM_InactivateDiagnostic(); /** @req DCM164 */
\r
740 startS3SessionTimer(runtime, protocolRow); /** @req DCM141 */
\r
741 releaseExternalRxTxBuffers(protocolRow, runtime); /** @req DCM118 *//** @req DCM352 *//** @req DCM353 *//** @req DCM354 */
\r
742 externalBufferReleased = TRUE;
\r
743 DEBUG( DEBUG_MEDIUM, "Released external buffer OK!\n");
\r
744 DsdDataConfirmation(mainConnection->DslProtocolTx->DcmDslProtocolTxPduId, result); /** @req DCM117 *//** @req DCM235 */
\r
750 if (!externalBufferReleased) {
\r
751 switch (runtime->localTxBuffer.status) { // ### LOCAL TX BUFFER ###
\r
752 case PROVIDED_TO_PDUR:
\r
753 DEBUG( DEBUG_MEDIUM, "Released local buffer buffer OK!\n");
\r
754 runtime->localTxBuffer.status = DCM_IDLE;
\r
757 DEBUG( DEBUG_MEDIUM, "WARNING! DslTxConfirmation could not release external or local buffer!\n");
\r
761 McuE_ExitCriticalSection(state);
\r