Advertisement
alexander_seredinov

Untitled

Jan 18th, 2022
816
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 140.30 KB
  1.  
  2. #pragma diag_suppress=Pa082 //supress Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement
  3.  
  4. /*****************************************************************************
  5. | Project Name:   XCP Protocol Layer
  6. |    File Name:   XcpBasic.c
  7. |
  8. |  Description:   Implementation of the XCP Protocol Layer
  9. |                 XCP V1.0 slave device driver
  10. |                 Basic Version (see feature list below)
  11. |
  12. |
  13. |     Limitations of the XCP basic version:
  14. |
  15. |     - Stimulation (Bypassing) is not available
  16. |         XCP_ENABLE_STIM
  17. |     - Bit stimulation is not available
  18. |         XCP_ENABLE_STIM_BIT
  19. |     - SHORT_DOWNLOAD is not available
  20. |         XCP_ENABLE_SHORT_DOWNLOAD
  21. |     - MODIFY_BITS is not available
  22. |         XCP_ENABLE_MODIFY_BITS
  23. |     - FLASH and EEPROM Programming is not available
  24. |         XCP_ENABLE_PROGRAM, XCP_ENABLE_BOOTLOADER_DOWNLOAD, XCP_ENABLE_READ_EEPROM, XCP_ENABLE_WRITE_EEPROM
  25. |     - Block mode for UPLOAD, DOWNLOAD and PROGRAM is not available
  26. |         XCP_ENABLE_BLOCK_UPLOAD, XCP_ENABLE_BLOCK_DOWNLOAD
  27. |     - Resume mode is not available
  28. |         XCP_ENABLE_DAQ_RESUME
  29. |     - Memory write and read protection is not supported
  30. |         XCP_ENABLE_WRITE_PROTECTION
  31. |         XCP_ENABLE_READ_PROTECTION
  32. |     - Checksum calculation with AUTOSAR CRC module is not supported
  33. |         XCP_ENABLE_AUTOSAR_CRC_MODULE
  34. |     - No support from Vector Generation Tool
  35. |
  36. |       All these feature are available in the full version.
  37. |       Please contact Vector Informatik GmbH for more information
  38. |
  39. |     General limitations:
  40. |
  41. |     - Daq and Event numbers are BYTE
  42. |     - Only dynamic DAQ list allocation supported
  43. |     - Max. checksum block size is 0xFFFF
  44. |     - CECKSUM_TYPE CRC16, CRC32 and 'user defined' are not supported
  45. |     - MAX_DTO is limited to max. 255
  46. |     - The resume bits in daq lists are not set
  47. |     - STORE_DAQ, CLEAR_DAQ and STORE_CAL will not send a event message
  48. |     - Entering resume mode will not send a event message
  49. |     - Overload indication by event is not supported
  50. |     - Page Info and Segment Info is not supported
  51. |     - DAQ does not support address extensions
  52. |     - DAQ-list and event channel prioritization is not supported
  53. |     - Event channels contain one DAQ-list
  54. |     - ODT optimization not supported
  55. |     - Interleaved communication mode is not supported
  56. |     - The seed size is equal or less MAX_CTO-2
  57. |     - The key size is equal or less MAX_CTO-2
  58. |     - Only default programming data format is supported
  59. |     - GET_SECTOR_INFO does not return sequence numbers
  60. |     - PROGRAM_VERIFY and PROGRAM_FORMAT are not supported
  61. |
  62. |-----------------------------------------------------------------------------
  63. |               D E M O
  64. |-----------------------------------------------------------------------------
  65. |
  66. |       Please note, that the demo and example programs
  67. |       only show special aspects of the software.
  68. |       With regard to the fact that these programs are meant
  69. |       for demonstration purposes only,
  70. |       Vector Informatik's liability shall be expressly excluded in cases
  71. |       of ordinary negligence, to the extent admissible by law or statute.
  72. |
  73. |-----------------------------------------------------------------------------
  74. |               C O P Y R I G H T
  75. |-----------------------------------------------------------------------------
  76. | Copyright (c) 2017 by Vector Informatik GmbH.           All rights reserved.
  77. |
  78. |       This software is copyright protected and
  79. |       proporietary to Vector Informatik GmbH.
  80. |       Vector Informatik GmbH grants to you only
  81. |       those rights as set out in the license conditions.
  82. |       All other rights remain with Vector Informatik GmbH.
  83. |
  84. |       Diese Software ist urheberrechtlich geschuetzt.
  85. |       Vector Informatik GmbH raeumt Ihnen an dieser Software nur
  86. |       die in den Lizenzbedingungen ausdruecklich genannten Rechte ein.
  87. |       Alle anderen Rechte verbleiben bei Vector Informatik GmbH.
  88. |
  89. |-----------------------------------------------------------------------------
  90. |               A U T H O R   I D E N T I T Y
  91. |-----------------------------------------------------------------------------
  92. | Initials     Name                      Company
  93. | --------     ---------------------     -------------------------------------
  94. | Ds           Sven Deckardt             Vector Informatik GmbH
  95. | Eta          Edgar Tongoona            Vector Informatik GmbH
  96. | Hr           Andreas Herkommer         Vector Informatik GmbH
  97. | Svh          Sven Hesselmann           Vector Informatik GmbH
  98. | Tri          Frank Triem               Vector Informatik GmbH
  99. | Za           Rainer Zaiser             Vector Informatik GmbH
  100. | Ore          Oliver Reineke            Vector Informatik GmbH
  101. | Bwr          Brandon Root              Vector CANtech
  102. |-----------------------------------------------------------------------------
  103. |               R E V I S I O N   H I S T O R Y
  104. |-----------------------------------------------------------------------------
  105. |  Date       Version  Author  Description
  106. | ----------  -------  ------  -----------------------------------------------
  107. | 2003-03-01  0.9.00    Ds     Created
  108. | 2003-05-01  0.9.10    Za     Still a lot of changes, no detailled history yet
  109. | 2003-06-31  1.0.00    Za     Released
  110. | 2003-09-19  1.0.00    Za     XCP_DAQ_TIMESTAMP_FIXED
  111. | 2003-10-22  1.0.01    Ds     Change #if def instruction
  112. | 2003-10-30  1.0.02    Ds     Bugfix in the loop of the ODT Entry
  113. | 2003-10-30  1.0.03    Ds     Rename xcp20.c to xcpProf.c
  114. | 2003-11-20  1.01.00   Tri    Updated to PSC standard
  115. |                              MISRA rules applied.
  116. |                              Minor changes.
  117. | 2004-02-11  1.01.01   Ds,Tri Updated and adaption for CANape
  118. |                              ESCAN00007511: Warning when compiling XCP.H
  119. |                              ESCAN00007517: Compiler error when using a packet length of 253 bytes or greater
  120. |                              ESCAN00007518: Seed & Key: reading of the unlock key not performed correctly
  121. |                              ESCAN00007532: Division by zero in calculation of the queue size
  122. |                              ESCAN00007533: Memory overflow check during memory allocation might not be detected.
  123. | 2004-06-16  1.02.00   Tri    ESCAN00008482: Add user defined function to service GET_ID
  124. | 2005-01-03  1.03.00   Tri,Za ESCAN00008009: Rename module versions according to PD_PSC_Development
  125. |                              ESCAN00009121: Add copyright note
  126. |                              ESCAN00009125: Remove defines for revision 18
  127. |                              ESCAN00009127: Remove XCP_ENABLE_SEND_BUFFER
  128. |                              ESCAN00009130: Add support for data stimulation (STIM)
  129. |                              ESCAN00007824: Warning due to unreferenced label 'negative_response1'
  130. |                              ESCAN00008012: Remove include definitions of the standard libraries within XCP Professional
  131. |                              ESCAN00008015: Avoid usage of the test mode within XCP Professional
  132. |                              ESCAN00008018: XCP module version in response of CC_GET_COMM_MODE_INFO corrected
  133. |                              ESCAN00008004: Compiler error when block upload is enabled and block download is disabled
  134. |                              ESCAN00008005: Resource bit for CAL/PAG always set in response upon CC_CONNECT
  135. |                              ESCAN00009141: Compiler warnings while compilation with Tasking Compiler
  136. |                              ESCAN00007823: Warning about unreferenced variable 'prescaler'
  137. |                              ESCAN00008003: Compiler error when block download is disabled and Programming enabled
  138. |                              ESCAN00008060: Issue in negative response of command BUILD_CHECKSUM
  139. |                              ESCAN00008013: Checksum calculation wrong
  140. |                              ESCAN00008072: Compiler warning in range check of defines
  141. |                              ESCAN00007971: Implement and support 'session configuration id'
  142. |                              ESCAN00008006: Page switching always enabled when programming is enabled.
  143. |                              ESCAN00008010: Remove extern declaration for xcp struct
  144. |                              ESCAN00009154: Update Seed & Key
  145. |                              ESCAN00010703: PROGRAM size = 0 is valid
  146. |                              ESCAN00008017: Rework of Flash Programming by Flash Kernel
  147. |                              ESCAN00009200: Positive Response upon command PROGRAM_START not correct
  148. |                              ESCAN00010705: Rework command PROGRAM_RESET
  149. |                              ESCAN00010706: Return the status of event channels
  150. |                              ESCAN00010707: Consistency check in case of no DAQ released
  151. |                              ESCAN00008008: Apply PSC naming convention for types and structures
  152. |                              ESCAN00009173: Consistency check for generator DLL and component
  153. |                              ESCAN00008007: Rename the post-organified filenames to xcpProf.h and xcpProf.c
  154. |                              ESCAN00009172: Atmega only: Compiler error due to pointer conversion from RAM to Flash
  155. |                              ESCAN00007209: Apply naming convention to callback functions
  156. |                              ESCAN00009144: Minor changes
  157. | 2005-02-01  1.04.00   Tri    ESCAN00010989: Update comment for version scan
  158. |                              ESCAN00010848: Move timestamp unit of response to GET_DAQ_EVENT_INFO in low nibble
  159. | 2005-02-17  1.05.00   Tri    ESCAN00011210: Support GENy Fwk 1.3 DLL Versions
  160. | 2005-02-28  1.06.00   Tri    ESCAN00010961: Include XCP Transport Layer on CAN
  161. | 2005-05-10  1.07.00   Tri    ESCAN00011446: Tasking Compiler only: Compiler Warnings
  162. |                              ESCAN00012314: Compatibility with CANape 5.5.x regarding timestamp unit
  163. |                              ESCAN00012356: Support data paging on Star12X / Metrowerks
  164. |                              ESCAN00012617: Add service to retrieve XCP state
  165. | 2006-01-03  1.08.00   Tri    ESCAN00013899: Data acquisition not possible during cold start
  166. |                              ESCAN00009196: PROGRAM_FORMAT is not implemented as specified
  167. |                              ESCAN00009199: Negative Response to command PROGRAM_PREPARE is not correct
  168. |                              ESCAN00009202: Programming Info not implemented correctly
  169. |                              ESCAN00014313: Warning because of undefined 'kXcpStimOdtCount'
  170. |                              ESCAN00013634: Remove kXcpPacketHeaderSize
  171. |                              ESCAN00014710: Rework Calibration Data Page Freeze
  172. |                              ESCAN00014712: Rework Segment Info and Page Info
  173. |                              ESCAN00014775: Delayed EEPROM read access not possible
  174. | 2006-03-09  1.09.00   Tri    ESCAN00013637: Support command TRANSPORT_LAYER_CMD
  175. |                              ESCAN00015283: Start of a single DAQ list is not possible
  176. |                              ESCAN00015607: Support XCP on FlexRay Transport Layer
  177. | 2006-05-05  1.10.00   Tri    ESCAN00016158: Add demo disclaimer to XCP Basic
  178. |                              ESCAN00016098: Calculation of CRC16 CCITT is not correct
  179. | 2006-05-30  1.11.00   Tri    ESCAN00016225: Support Cp_XcpOnLin
  180. | 2006-07-18  1.12.00   Tri    ESCAN00016955: Support AUTOSAR CRC module
  181. |                              ESCAN00016958: Delayed EEPROM read access not possible
  182. | 2006-10-26  1.13.00   Tri    ESCAN00017516: Support Cp_XcpOnCanAsr
  183. |                              ESCAN00017504: Replace P_MEM_ROM by MEMORY_FAR resp. V_MEMRAM2_FAR
  184. |                              ESCAN00017804: Multiple definitions of XCP_DISABLE_TESTMODE
  185. |                              ESCAN00017878: Overwriting of memory during data acquisition allocation
  186. | 2007-01-30  1.14.00   Tri    ESCAN00018808: Support data paging on Star12X / Cosmic
  187. | 2007-04-03  1.15.00   Eta    ESCAN00018153: Overwriting of memory during data stimulation
  188. |                       Svh    ESCAN00020126: Commands SHORT_DOWNLOAD and MODIFY_BITS must be supported
  189. |                              ESCAN00012618: Support command MODIFY_BITS
  190. |                              ESCAN00020127: It has to be possible to en-/disable XCP globally
  191. |                              ESCAN00019094: Extend implementation for runtime deactivation of XCP (professional)
  192. |                              ESCAN00020128: Add AUTOSAR based API
  193. |                              ESCAN00018154: Support overwriting of XcpSendDto() in header
  194. |                              ESCAN00015859: Support memory read protection
  195. | 2007-05-25  1.16.00   Svh    ESCAN00020906: Compiler error due to incorrect pointer assignment
  196. | 2007-07-09  1.16.01   Hr     Support AUTOSAR Memory Mapping
  197. | 2007-12-07  1.16.02   Hr     ISS046 - Only CTOs are flushed by the Protocol Layer
  198. | 2007-09-14  1.17.00   Svh    ESCAN00022293: Support for SET_SEGMENT_MODE and GET_SEGMENT_MODE added
  199. | 2007-12-17  1.18.00   Svh    ESCAN00023759: Compile error for MCS12x
  200. | 2008-03-17  1.19.00   Svh    ESCAN00021035: XcpSendCallBack() always returns 1
  201. |                              ESCAN00024265: STIM with time stamp is not supported
  202. |                              ESCAN00024863: Missing error code in CC_TRANSPORT_LAYER_CMD
  203. |                              ESCAN00025020: Possible stack issues with big MAX_DTO values in case Send Queue is not used
  204. |                              ESCAN00023570: Do not set default answer is last CRM is still pending
  205. | 2008-04-10  1.20.00   Svh    ESCAN00025979: tXcpDto wrong structure ordering causing erroneous one-time Stim trigger
  206. | 2008-04-30  1.21.00   Eta    ESCAN00026424: compiler error when using Cosmic with option -pck
  207. |                       Svh    ESCAN00026491: Data inconsistency of ODTs in case of Overrun + FlexRay
  208. | 2008-04-30  1.21.01   Svh    ESCAN00026541: compiler error due to unknown symbol
  209. | 2008-06-04  1.21.02   Svh    ESCAN00027343: Redefinition of ApplXcpSendFlush
  210. | 2008-07-21  1.22.00   Hr     ESCAN00022545: Memory Read Protection always returns Ok to CANape
  211. |                              ESCAN00020637: Support different Info Time Unit for DTO handling
  212. |                              ESCAN00017954: Support MIN_ST_PGM
  213. |                              ESCAN00017951: Add open interface for command processing
  214. |                              ESCAN00028579: CC_PROGRAM_START should support an application callback
  215. |                       Svh    ESCAN00028720: Support ADDRESS_GRANULARITY WORD
  216. | 2008-09-10  1.23.00   Svh    ESCAN00029890: Incorrect checksum calculation
  217. |                              ESCAN00029896: Command pending for several call backs added
  218. |                              ESCAN00029897: XcpStimEventStatus() returns 1 also if no STIM data is available
  219. |                              ESCAN00029905: Configuration of parameter MIN_ST in response of GET_COMM_MODE_INFO command added
  220. | 2008-10-01  1.23.01   Hr     ESCAN00030382: Compiler error due to missing ;
  221. | 2008-10-10  1.23.02   Bwr    ESCAN00030037: Support for more than 255 ODT entries
  222. | 2008-12-01  1.24.00   Hr     ESCAN00031342: Version information of implementation inconsistent to release version information
  223. |                              ESCAN00031726: Add support for XcpOnTcpIpAsr
  224. |                              ESCAN00031948: Event gets lost, if a Response is still pending
  225. |                              ESCAN00031949: Add error check for ODT_SIZE_WORD with no DAQ_HDR_ODT_DAQ
  226. |                       Bwr    ESCAN00030566: SET_REQUEST with incorrect mode is ignored
  227. |                              ESCAN00030601: Support for more than 255 ODTs
  228. | 2009-02-05  1.24.01   Hr     ESCAN00032861: CC_SET_DAQ_PTR fails due to Diab Data Compiler bug
  229. | 2009-02-27  1.24.02   Hr     ESCAN00031794: Compiler warning: large type was implicitly cast to small type
  230. |                              ESCAN00033655: Canbedded compile error due to uint8
  231. | 2009-05-13  1.25.00   Hr     ESCAN00033909: New features implemented: Prog Write Protection, Timestamps, Calibration activation
  232. | 2009-10-08  1.25.01   Hr     ESCAN00038283: After second measurement start with INCA no timestamps are generated anymore.
  233. |                              ESCAN00039240: Compile error by uint8
  234. |                              ESCAN00039241: Variables not in NOINIT sections
  235. | 2009-11-26            Hr     ESCAN00039350: TMS320 Compile error: struct has no field "EightByteField"
  236. | 2010-03-24  1.26.00   Hr     ESCAN00041784: new API for better calibration support
  237. |                              ESCAN00041784: Queue size calculation incorrect under certain conditions
  238. | 2010-05-25  1.26.01   Hr     ESCAN00042660: Send queue variables to small
  239. |                              ESCAN00043113: Compiler error: identifier uint16 not declared
  240. | 2010-07-08  1.26.02   Hr     ESCAN00043335: Queue size calculation incorrect on 32Bit Platforms
  241. | 2010-10-12  1.26.03   Hr     ESCAN00045791: Send Queue limited to 255 Entries by typecasts
  242. | 2011-02-11  1.27.00   Hr     ESCAN00047153: 'XCP on LIN' and 'XCP on CAN' can not be used in the same configuration.
  243. |                              ESCAN00048613: CC_PROGRAM_CLEAR does not make use of programming write protection
  244. |                              ESCAN00049091: Optimization to prevent a goto in the code
  245. |                              ESCAN00049090: Software might hang in endless software loop
  246. | 2011-06-06  1.27.01   Hr     ESCAN00051222: Customer can't compile XCP when disabling the DAQ feature
  247. | 2011-07-19  1.27.02   Ore    ESCAN00052011: Reading memory of the ECU via XCP is not possible. XCP Connect aborts with error condition PAGE_MODE_NOT_VALID (=0x27)
  248. | 2011-08-29  1.27.03   Hr     ESCAN00052721: Compiler Error because MEMORY_ROM definition
  249. |                              ESCAN00053956: Check DAQ lists for validity before they are started
  250. | 2011-11-02  1.27.04   Hr     ESCAN00054318: Issue of memory read/write protection in DAQ measurement
  251. | 2012-02-20  1.27.05   Hr     ESCAN00055216: DAQ Lists can be extended after START_STOP_SYNCH
  252. | 2012-05-31  1.27.06   Hr     ESCAN00058916: Trap if WRITE_DAQ is used before a DAQ list is created.
  253. | 2012-08-13  1.28.00   Hr     ESCAN00038632: Support for address doubling in CANape for DSP micros
  254. | 2013-06-17  1.28.01   Hr     ESCAN00068052: Provide an API to detect XCP state and usage
  255. | 2013-09-17  1.28.02   Hr     ESCAN00069598: The PROGRAM_MAX command uses a wrong length
  256. |                              ESCAN00067667: Compiler warning: warning #177-D: label "negative_response1" was declared but never referenced
  257. | 2013-12-09  1.29.00   Hr     ESCAN00072412: Provide an API to detect XCP state and usage
  258. |                              ESCAN00072503: Support custom CRC Cbk
  259. |                              ESCAN00072505: Support Generic GET_ID
  260. | 2015-03-26  1.30.00   Hr     ESCAN00082098: Time Check for DAQ lists
  261. | 2016-01-12  1.30.01   Hr     ESCAN00087368: Unexpected byte order used on word-addressed platforms (e.g. TMS320)
  262. | 2016-06-24  1.30.02   Hr     ESCAN00090639: Compiler error: "truncating assignment"
  263. |                              ESCAN00090685: Max PID not checked against 0x7C if Overload Indication is active
  264. |                              ESCAN00090687: Prescaler does not disable single DAQ list per event optimization
  265. |                              ESCAN00090699: MPU detects illegal access to variable dto
  266. | 2016-11-18  1.30.03   Hr     ESCAN00091645: Wrong memory size calculation during memory allocation
  267. |                              ESCAN00092933: XcpMemCpy does not fully utilize XCP_ENABLE_MEM_ACCESS_BY_APPL
  268. |                              ESCAN00092934: Max PID not checked against 0x7B if Overload Indication is active
  269. | 2017-09-01  1.30.04   Hr     ESCAN00095506: TMS320 wrong Endianess used during memory access.
  270. |                              ESCAN00096039: Compiler error: out of bounds array access optimized away
  271. |                              ESCAN00096161: Compiler warning: Unused variable qs
  272. |                              ESCAN00096627: Improve plausibility check of DAQ allocation
  273. |***************************************************************************/
  274.  
  275.  
  276. /***************************************************************************/
  277. /* Include files                                                           */
  278. /***************************************************************************/
  279.  
  280.     #include "xcpBasic.h"
  281.  
  282. /* Include AUTOSAR CRC module header file. */
  283.  
  284. /* XCP DPRAM Client Mode */
  285.  
  286. #if defined ( XCP_ENABLE_SERV_TEXT_PRINTF ) && defined ( XCP_ENABLE_TESTMODE )
  287.   #include <stdio.h>
  288.   #include <stdarg.h>
  289. #endif
  290.  
  291.  
  292. /***************************************************************************/
  293. /* Version check                                                           */
  294. /***************************************************************************/
  295. #if ( CP_XCP_VERSION != 0x0130u )
  296.   #error "Source and Header file are inconsistent!"
  297. #endif
  298. #if ( CP_XCP_RELEASE_VERSION != 0x04u )
  299.   #error "Source and Header file are inconsistent!"
  300. #endif
  301.  
  302. #if defined ( VGEN_GENY )
  303.   #if defined ( CP_XCPDLL_VERSION )
  304.     #if ( CP_XCPDLL_VERSION >= 0x0211u )
  305.     #else
  306.       #error "XCP component version and generator version are not consistent!"
  307.     #endif
  308.   #else
  309.     #if defined ( VGEN_VERSION_CP_XCP_MAIN )
  310.       #if ( ( VGEN_VERSION_CP_XCP_MAIN > 1 ) || ( VGEN_VERSION_CP_XCP_SUB > 5 ) )
  311.       #else
  312.         #error "XCP component version and generator version are not consistent!"
  313.       #endif
  314.     #else
  315.       #error "XCP component version and generator version are not consistent!"
  316.     #endif
  317.   #endif
  318. #endif
  319.  
  320. /* Check specifcation version of AUTOSAR CRC module. */
  321.  
  322.  
  323. /****************************************************************************/
  324. /* Definitions                                                              */
  325. /****************************************************************************/
  326.  
  327. #if defined ( C_COMP_TASKING_ST10_CCAN ) || defined ( C_COMP_TASKING_C16X ) || defined ( C_COMP_TASKING_XC16X )
  328.   #if defined ( XCP_ENABLE_NO_P2INT_CAST ) || defined ( XCP_DISABLE_NO_P2INT_CAST )
  329.   #else
  330.     /* Some uCs use DPPs in the small memory model and encode the information in the most significant bits of pointers.
  331.        The DPP register information gets lost if these pointers are converted to integers.
  332.        The following options disables casts from pointers to integer. */
  333.      #define XCP_ENABLE_NO_P2INT_CAST
  334.   #endif
  335. #endif
  336.  
  337.  
  338. /****************************************************************************/
  339. /* Macros                                                                   */
  340. /****************************************************************************/
  341.  
  342. /* Definition of macros that have to be used within the context of XcpCommand. */
  343. /* They have to be declared global Due to MISRA rule 91. */
  344.  
  345. /* PRQA S 3458 5 */ /* MD_MSR_19.4 */
  346. #define error(e) { err=(e); goto negative_response; }
  347. #define check_error(e) { err=(e); if (err!=0) { goto negative_response; } }
  348. #define error1(e,b1) { err=(e); CRM_BYTE(2)=(b1); xcp.CrmLen=3; goto negative_response1; }
  349. #define error2(e,b1,b2) { err=(e); CRM_BYTE(2)=(b1); CRM_BYTE(3)=(b2); xcp.CrmLen=4; goto negative_response1; }
  350.  
  351. #if defined ( XCP_ENABLE_SEED_KEY )
  352.   /* Return CRC_ACCESS_LOCKED if the resource is locked. */
  353.   #define CheckResourceProtection(resource)   if ( (xcp.ProtectionStatus & (resource)) != 0 ) { error(CRC_ACCESS_LOCKED) } /* PRQA S 3412 */ /* MD_MSR_19.4 */
  354. #else
  355.   /* The resource protection is unavailable. */
  356.   #define CheckResourceProtection(resource)
  357. #endif
  358.  
  359.  
  360.  
  361. #if defined ( XCP_ENABLE_MEM_ACCESS_BY_APPL )
  362.   #define XCP_WRITE_BYTE_2_ADDR(addr, data)           ApplXcpWrite( (vuint32)(addr), (vuint8)(data) ) /* PRQA S 3453 */ /* MD_MSR_19.7 */
  363.   #define XCP_READ_BYTE_FROM_ADDR(addr)               ApplXcpRead ( (vuint32)(addr) ) /* PRQA S 3453 */ /* MD_MSR_19.7 */
  364.   #if defined ( XCP_ENABLE_CHECKSUM )
  365.      #if ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_ADD22 ) || \
  366.          ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_ADD24 ) || \
  367.          ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_ADD44 )
  368.       #define XCP_READ_CHECKSUMVALUE_FROM_ADDR(addr)  ApplXcpReadChecksumValue ( (vuint32)(addr) ) /* PRQA S 3453 */ /* MD_MSR_19.7 */
  369.     #else
  370.       #define XCP_READ_CHECKSUMVALUE_FROM_ADDR(addr)  XCP_READ_BYTE_FROM_ADDR(addr) /* PRQA S 3453 */ /* MD_MSR_19.7 */
  371.     #endif
  372.   #endif
  373. #else
  374.   #define XCP_WRITE_BYTE_2_ADDR(addr, data)           *(addr) = (data) /* PRQA S 3453 */ /* MD_MSR_19.7 */
  375.   #define XCP_READ_BYTE_FROM_ADDR(addr)               *(addr) /* PRQA S 3453 */ /* MD_MSR_19.7 */
  376.   #if defined ( XCP_ENABLE_CHECKSUM )
  377.     #if defined ( XCP_ENABLE_CALIBRATION_MEM_ACCESS_BY_APPL )
  378.       #define XCP_READ_CHECKSUMVALUE_FROM_ADDR(addr)    ApplXcpReadChecksumValue ( (vuint32)(addr) ) /* PRQA S 3453 */ /* MD_MSR_19.7 */
  379.     #else
  380.       #define XCP_READ_CHECKSUMVALUE_FROM_ADDR(addr)    *((tXcpChecksumAddType*)(addr)) /* PRQA S 3453 */ /* MD_MSR_19.7 */
  381.     #endif
  382.   #endif
  383. #endif
  384.  
  385. /* PRQA S 3458 7 */ /* MD_MSR_19.4 */
  386.   #define XcpPlCheckControlState( )
  387.   #define XcpPlCheckControlStateRet( ret_value )
  388.  
  389. /****************************************************************************/
  390. /* Constants                                                                */
  391. /****************************************************************************/
  392.  
  393. /****************************************************************************/
  394. /* 8 Bit Constants for export                                               */
  395. /****************************************************************************/
  396.  
  397. /* Global constants with XCP Protocol Layer main and subversion */
  398. V_MEMROM0 const vuint8 kXcpMainVersion    = (vuint8)(CP_XCP_VERSION >> 8);
  399. V_MEMROM0 const vuint8 kXcpSubVersion     = (vuint8)(CP_XCP_VERSION & 0x00ff);
  400. V_MEMROM0 const vuint8 kXcpReleaseVersion = (vuint8)(CP_XCP_RELEASE_VERSION);
  401.  
  402.  
  403.  
  404. /****************************************************************************/
  405. /* Local data                                                               */
  406. /****************************************************************************/
  407.  
  408. /* This section containes all RAM locations needed by the XCP driver */
  409.  
  410. /******************************************************************************/
  411. /* Local Data definitions with unspecified size                               */
  412. /******************************************************************************/
  413.  
  414. RAM tXcpData xcp; /* PRQA S 3408 */ /* MD_Xcp_3408 */
  415.  
  416. #if defined ( XCP_ENABLE_SEND_QUEUE )
  417. #else
  418. static tXcpDto dto;
  419. #endif
  420.  
  421.  
  422. #if defined ( XCP_ENABLE_TESTMODE )
  423. vuint8 gDebugLevel;
  424. #endif
  425.  
  426. /******************************************************************************/
  427. /* Local Data definitions with 8Bit size                                      */
  428. /******************************************************************************/
  429.  
  430.  
  431.  
  432.  
  433. /***************************************************************************/
  434. /* Prototypes for local functions                                          */
  435. /***************************************************************************/
  436.  
  437. static vuint8 XcpWriteMta( vuint8 size, const BYTEPTR data );
  438. static vuint8 XcpReadMta( vuint8 size, BYTEPTR data );
  439.  
  440. #if defined ( XcpMemClr )
  441. #else
  442. static void XcpMemClr( BYTEPTR p, vuint16 n );
  443. #endif
  444.  
  445. #if defined ( XCP_ENABLE_SEND_EVENT ) || defined ( XCP_ENABLE_SERV_TEXT )
  446. static void XcpSendEv( void );
  447. #endif
  448.  
  449. #if defined ( XCP_ENABLE_SEND_QUEUE )
  450. static vuint8 XcpSendDtoFromQueue( void );
  451. static void XcpQueueInit( void );
  452. #endif
  453.  
  454. #if defined ( XCP_ENABLE_DAQ )
  455. static void XcpFreeDaq( void );
  456. static vuint8 XcpAllocMemory( void );
  457. static vuint8 XcpAllocDaq( vuint8 daqCount );
  458. static vuint8 XcpAllocOdt( vuint8 daq, vuint8 odtCount );
  459. static vuint8 XcpAllocOdtEntry( vuint8 daq, vuint8 odt, vuint8 odtEntryCount );
  460. static void XcpStartDaq( vuint8 daq );
  461. static void XcpStartAllSelectedDaq( void );
  462. static void XcpStopDaq( vuint8 daq );
  463. static void XcpStopAllSelectedDaq( void );
  464. static void XcpStopAllDaq( void );
  465.  
  466.  
  467. #endif
  468.  
  469.  
  470.  
  471. /******************************************************************************
  472. *
  473. *
  474. *           Code Part for Cp_Xcp
  475. *
  476. *
  477. *******************************************************************************/
  478.  
  479.  
  480. /*****************************************************************************
  481. | NAME:             XcpMemSet
  482. | CALLED BY:        XcpFreeDaq
  483. | PRECONDITIONS:    none
  484. | INPUT PARAMETERS: p : pointer to start address.
  485. |                   n : number of data bytes.
  486. |                   d : data byte to initialize with.
  487. | RETURN VALUES:    none
  488. | DESCRIPTION:      Initialize n bytes starting from address p with b.
  489. ******************************************************************************/
  490.  
  491. #if defined ( XcpMemSet )
  492.  /* XcpMemSet is overwritten */
  493. #else
  494. void XcpMemSet( BYTEPTR p, vuint16 n, vuint8 b )
  495. {
  496.   for ( ; n > 0; n-- )
  497.   {
  498.     *p = b;
  499.     p++; /* PRQA S 0489 */ /* MD_Xcp_0489 */
  500.   }
  501. }
  502. #endif
  503.  
  504. /*****************************************************************************
  505. | NAME:             XcpMemClr
  506. | CALLED BY:        XcpFreeDaq, XcpInit
  507. | PRECONDITIONS:    none
  508. | INPUT PARAMETERS: p : pointer to start address.
  509. |                   n : number of data bytes.
  510. | RETURN VALUES:    none
  511. | DESCRIPTION:      Initialize n bytes starting from address p 0.
  512. ******************************************************************************/
  513.  
  514. #if defined ( XcpMemClr )
  515.  /* XcpMemClr is overwritten */
  516. #else
  517. /* A macro would be more efficient. Due to MISRA rule 96 violations a function is implemented. */
  518. static void XcpMemClr( BYTEPTR p, vuint16 n )
  519. {
  520.   XcpMemSet( p, n, (vuint8)0u);
  521. }
  522. #endif
  523.  
  524. /*****************************************************************************
  525. | NAME:             XcpMemCpy
  526. | CALLED BY:        XcpEvent
  527. | PRECONDITIONS:    none
  528. | INPUT PARAMETERS: dest : pointer to destination address.
  529. |                   src  : pointer to source address.
  530. |                   n    : number of data bytes to copy.
  531. | RETURN VALUES:    none
  532. | DESCRIPTION:      Copy n bytes from src to dest.
  533. |                   A maximum of 255 Bytes can be copied at once.
  534. ******************************************************************************/
  535.  
  536. /* Optimize this function
  537.    It is used in the inner loop of XcpEvent for data acquisition sampling
  538. */
  539.  
  540. #if defined ( XcpMemCpy ) || defined ( C_COMP_COSMIC_MCS12X_MSCAN12 )
  541.  /* XcpMemCpy is overwritten */
  542. #else
  543. void XcpMemCpy( DAQBYTEPTR dest, const DAQBYTEPTR src, vuint8 n )
  544. {
  545.   for ( ; n > 0; n-- )
  546.   {
  547.     /* ESCAN00092933 */
  548.     XCP_WRITE_BYTE_2_ADDR( dest, XCP_READ_BYTE_FROM_ADDR(src) );
  549.     dest++; /* PRQA S 0489 */ /* MD_Xcp_0489 */
  550.     src++; /* PRQA S 0489 */ /* MD_Xcp_0489 */
  551.   }
  552. }
  553. #endif
  554.  
  555.  
  556. /*****************************************************************************
  557. | NAME:             XcpSetActiveTl
  558. | CALLED BY:        XcpInit, Tl
  559. | PRECONDITIONS:    none
  560. | INPUT PARAMETERS: MaxCto : Maximum CTO to be used
  561. |                   MaxDto : Maximum DTO to be used
  562. | RETURN VALUES:    none
  563. | DESCRIPTION:      Set the maximum cto/dto to be used by the XCP.
  564. ******************************************************************************/
  565. void XcpSetActiveTl( vuint8 MaxCto, vuint8 MaxDto, vuint8 ActiveTl )
  566. {
  567.   xcp.Daq.ActiveTl  = ActiveTl;
  568.   #if defined ( V_ENABLE_USE_DUMMY_STATEMENT )
  569.   MaxCto = MaxCto;
  570.   MaxDto = MaxDto;
  571.   #endif
  572. }
  573.  
  574. /*****************************************************************************
  575. | NAME:             XcpGetActiveTl
  576. | CALLED BY:        Tl
  577. | PRECONDITIONS:    none
  578. | INPUT PARAMETERS: none
  579. | RETURN VALUES:    Active Tl
  580. | DESCRIPTION:      Get the currently active TL.
  581. ******************************************************************************/
  582. vuint8 XcpGetActiveTl( void )
  583. {
  584.   return( xcp.Daq.ActiveTl );
  585. }
  586.  
  587.  
  588.  
  589. /****************************************************************************/
  590. /* Transmit                                                                 */
  591. /****************************************************************************/
  592.  
  593.  
  594. /*****************************************************************************
  595. | NAME:             XcpSendCrm
  596. | CALLED BY:        XcpBackground, XcpCommand, XcpSendCallBack, application
  597. | PRECONDITIONS:    XCP is initialized and in connected state and
  598. |                   a command packet (CMD) has been received.
  599. | INPUT PARAMETERS: none
  600. | RETURN VALUES:    none
  601. | DESCRIPTION:      Transmission of a command response packet (RES),
  602. |                    or error packet (ERR) if no other packet is pending.
  603. ******************************************************************************/
  604. void XcpSendCrm( void )
  605. {
  606.   /* Activation control */
  607.   XcpPlCheckControlState()
  608.  
  609. #if defined ( XCP_ENABLE_SEND_QUEUE )
  610.  
  611.   ApplXcpInterruptDisable();
  612.  
  613.   if ( (xcp.SendStatus & (vuint8)XCP_SEND_PENDING) != 0 )
  614.   {
  615.     if ( (xcp.SendStatus & (vuint8)XCP_CRM_REQUEST) != 0 )
  616.     {
  617.       XCP_ASSERT(0);
  618.       xcp.SessionStatus |= (SessionStatusType)SS_ERROR;
  619.     }
  620.     xcp.SendStatus |= (vuint8)XCP_CRM_REQUEST;
  621.   }
  622.   else
  623.   {
  624.     xcp.SendStatus |= (vuint8)XCP_CRM_PENDING;
  625.     ApplXcpSend(xcp.CrmLen,&xcp.Crm.b[0]);
  626.   }
  627.  
  628.   ApplXcpInterruptEnable();
  629.  
  630. #else
  631.  
  632.   ApplXcpSend(xcp.CrmLen,&xcp.Crm.b[0]);
  633.  
  634. #endif
  635.  
  636.   ApplXcpSendFlush();
  637.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  638. }
  639.  
  640. #if defined ( XCP_ENABLE_SEND_EVENT ) || defined ( XCP_ENABLE_SERV_TEXT )
  641. /*****************************************************************************
  642. | NAME:             XcpSendEv
  643. | CALLED BY:        XcpSendEvent, XcpSendCallBack, XcpPutchar
  644. | PRECONDITIONS:    none
  645. | INPUT PARAMETERS: none
  646. | RETURN VALUES:    none
  647. | DESCRIPTION:      Send a EV or SERV message, if no other message is pending.
  648. ******************************************************************************/
  649. static void XcpSendEv( void )
  650. {
  651.   #if defined ( XCP_ENABLE_SEND_QUEUE )
  652.  
  653.   ApplXcpInterruptDisable();
  654.  
  655.   if ( (xcp.SendStatus & (vuint8)XCP_SEND_PENDING) != 0 )
  656.   {
  657.     if ( (xcp.SendStatus & (vuint8)XCP_EVT_REQUEST) != 0 )
  658.     {
  659.       XCP_ASSERT(0);
  660.       xcp.SessionStatus |= (SessionStatusType)SS_ERROR;
  661.     }
  662.     xcp.SendStatus |= (vuint8)XCP_EVT_REQUEST;
  663.   }
  664.   else
  665.   {
  666.     xcp.SendStatus |= (vuint8)XCP_EVT_PENDING;
  667.     ApplXcpSend(xcp.EvLen,xcp.Ev.b);
  668.     xcp.EvLen = 0;
  669.   }
  670.  
  671.   ApplXcpInterruptEnable();
  672.  
  673.   #else
  674.  
  675.   ApplXcpSend(xcp.EvLen,xcp.Ev.b);
  676.   xcp.EvLen = 0;
  677.  
  678.   #endif
  679.  
  680.   ApplXcpSendFlush();
  681.  
  682. }
  683. #endif /* XCP_ENABLE_SEND_EVENT || XCP_ENABLE_SERV_TEXT */
  684.  
  685.  
  686. #if defined ( XCP_ENABLE_DAQ )
  687. /*****************************************************************************
  688. | NAME:             XcpSendDto
  689. | CALLED BY:        XcpSendDtoFromQueue, XcpEvent, XcpSendCallBack
  690. | PRECONDITIONS:    none
  691. | INPUT PARAMETERS: dto : pointer to XCP packet type definition
  692. | RETURN VALUES:    none
  693. | DESCRIPTION:      Send a DTO.
  694. ******************************************************************************/
  695.   #if defined ( XcpSendDto )
  696.   /* XcpSendDto is redefined */
  697.   #else
  698. void XcpSendDto( const tXcpDto *dto )
  699. {
  700.   ApplXcpSend( dto->l, &dto->b[0] );
  701. }
  702.   #endif
  703. #endif /* XCP_ENABLE_DAQ */
  704.  
  705.  
  706. #if defined ( XCP_ENABLE_SEND_QUEUE )
  707. /*****************************************************************************
  708. | NAME:             XcpSendDtoFromQueue
  709. | CALLED BY:        XcpEvent, XcpSendCallBack
  710. | PRECONDITIONS:    none
  711. | INPUT PARAMETERS: none
  712. | RETURN VALUES:    0 : DTO has NOT been transmitted from queue.
  713. |                   1 : DTO has been transmitted from queue.
  714. | DESCRIPTION:      Send a DTO from the queue.
  715. ******************************************************************************/
  716. static vuint8 XcpSendDtoFromQueue( void )
  717. {
  718.   ApplXcpInterruptDisable();
  719.   if ( ( (xcp.SendStatus & (vuint8)XCP_SEND_PENDING) == 0 ) && ( xcp.QueueLen != 0 ))
  720.   {
  721.     xcp.SendStatus |= (vuint8)XCP_DTO_PENDING;
  722.     XcpSendDto(&xcp.pQueue[xcp.QueueRp]);
  723.     xcp.QueueRp++;
  724.     if ( xcp.QueueRp >= xcp.QueueSize )
  725.     {
  726.       xcp.QueueRp = (vuint16)0u;
  727.     }
  728.     xcp.QueueLen--;
  729.     ApplXcpInterruptEnable();
  730.     return (vuint8)1u;
  731.   }
  732.   ApplXcpInterruptEnable();
  733.   return (vuint8)0u;
  734.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  735. }
  736. #endif /* XCP_ENABLE_SEND_QUEUE */
  737.  
  738.  
  739. /****************************************************************************/
  740. /* Transmit Queue */
  741. /****************************************************************************/
  742.  
  743. #if defined ( XCP_ENABLE_SEND_QUEUE )
  744.  
  745. /*****************************************************************************
  746. | NAME:             XcpQueueInit
  747. | CALLED BY:        XcpFreeDaq, XcpStopDaq, XcpStopAllDaq
  748. | PRECONDITIONS:    none
  749. | INPUT PARAMETERS: none
  750. | RETURN VALUES:    none
  751. | DESCRIPTION:      Initialize the transmit queue.
  752. ******************************************************************************/
  753. static void XcpQueueInit(void)
  754. {
  755.   xcp.QueueLen = (vuint16)0u;
  756.   xcp.QueueRp = (vuint16)0u;
  757. }
  758.  
  759. #endif /* XCP_ENABLE_SEND_QUEUE */
  760.  
  761.  
  762. /****************************************************************************/
  763. /* Handle Mta (Memory-Transfer-Address) */
  764. /****************************************************************************/
  765.  
  766. /* Assign a pointer to a Mta */
  767. #if defined ( XcpSetMta )
  768. #else
  769.     #define XcpSetMta(p,e) (xcp.Mta = (p)) /* PRQA S 3453 */ /* MD_MSR_19.7 */
  770. #endif
  771.  
  772. /*****************************************************************************
  773. | NAME:             XcpWriteMta
  774. | CALLED BY:        XcpCommand
  775. | PRECONDITIONS:    none
  776. | INPUT PARAMETERS: size : number of data bytes.
  777. |                   data : address of data.
  778. | RETURN VALUES:    XCP_CMD_OK, XCP_CMD_DENIED
  779. | DESCRIPTION:      Write n bytes.
  780. |                   Copying of size bytes from data to xcp.Mta
  781. ******************************************************************************/
  782. static vuint8 XcpWriteMta( vuint8 size, const BYTEPTR data )
  783. {
  784. #if defined ( XCP_ENABLE_CALIBRATION_MEM_ACCESS_BY_APPL )
  785.   vuint8 r;
  786. #endif
  787.  
  788.   /* DPRAM Client */
  789.  
  790.   /* Checked ram memory write access */
  791.  
  792.   /* EEPROM write access */
  793.  
  794.   /* Standard RAM memory write access */
  795. #if defined ( XCP_ENABLE_CALIBRATION_MEM_ACCESS_BY_APPL ) && !defined ( XCP_ENABLE_MEM_ACCESS_BY_APPL )
  796.   r = ApplXcpCalibrationWrite(xcp.Mta, size, data);
  797.   xcp.Mta += size; /* PRQA S 0488 */ /* MD_Xcp_0488 */
  798.   return r;
  799. #else
  800.   while ( size > (vuint8)0u )
  801.   {
  802.     XCP_WRITE_BYTE_2_ADDR( xcp.Mta, *data );
  803.     xcp.Mta++; /* PRQA S 0489 */ /* MD_Xcp_0489 */
  804.     data++; /* PRQA S 0489 */ /* MD_Xcp_0489 */
  805.     size--;
  806.   }
  807.   return (vuint8)XCP_CMD_OK;
  808. #endif
  809.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  810. }
  811.  
  812. /*****************************************************************************
  813. | NAME:             XcpReadMta
  814. | CALLED BY:        XcpCommand
  815. | PRECONDITIONS:    none
  816. | INPUT PARAMETERS: size :
  817. |                   data : address of data
  818. | RETURN VALUES:    XCP_CMD_OK
  819. | DESCRIPTION:      Read n bytes.
  820. |                   Copying of size bytes from data to xcp.Mta
  821. ******************************************************************************/
  822. static vuint8 XcpReadMta( vuint8 size, BYTEPTR data )
  823. {
  824. #if defined ( XCP_ENABLE_CALIBRATION_MEM_ACCESS_BY_APPL )
  825.   vuint8 r;
  826. #endif
  827.  
  828.   /* DPRAM Client */
  829.  
  830.   /* Checked ram memory read access */
  831.  
  832.   /* EEPROM read access */
  833.  
  834. #if defined ( XCP_ENABLE_CALIBRATION_MEM_ACCESS_BY_APPL ) && !defined ( XCP_ENABLE_MEM_ACCESS_BY_APPL )
  835.   r = ApplXcpCalibrationRead(xcp.Mta, size, data);
  836.   xcp.Mta += size; /* PRQA S 0488 */ /* MD_Xcp_0488 */
  837.   return r;
  838. #else
  839.   /* Standard RAM memory read access */
  840.   while (size > 0)
  841.   {
  842.     /*
  843.        Compiler bug Tasking
  844.        *(data++) = *(xcp.Mta++);
  845.     */
  846.     *(data) = XCP_READ_BYTE_FROM_ADDR( xcp.Mta );
  847.     data++; /* PRQA S 0489 */ /* MD_Xcp_0489 */
  848.     xcp.Mta++; /* PRQA S 0489 */ /* MD_Xcp_0489 */
  849.     size--;
  850.   }
  851.   return (vuint8)XCP_CMD_OK;
  852. #endif
  853.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  854. }
  855.  
  856.  
  857. /****************************************************************************/
  858. /* Data Aquisition Setup                                                    */
  859. /****************************************************************************/
  860.  
  861.  
  862. #if defined ( XCP_ENABLE_DAQ )
  863.  
  864. /*****************************************************************************
  865. | NAME:             XcpFreeDaq
  866. | CALLED BY:        XcpCommand
  867. | PRECONDITIONS:    none
  868. | INPUT PARAMETERS: none
  869. | RETURN VALUES:    none
  870. | DESCRIPTION:      Free all dynamic DAQ lists
  871. ******************************************************************************/
  872. static void XcpFreeDaq( void )
  873. {
  874.   xcp.SessionStatus &= (SessionStatusType)((~SS_DAQ) & 0xFFu);
  875.  
  876.   xcp.Daq.DaqCount = 0;
  877.   xcp.Daq.OdtCount = 0;
  878.   xcp.Daq.OdtEntryCount = 0;
  879.  
  880.   xcp.pOdt = (tXcpOdt*)0;
  881.   xcp.pOdtEntryAddr = 0;
  882.   xcp.pOdtEntrySize = 0;
  883.  
  884.   XcpMemClr((BYTEPTR)&xcp.Daq.u.b[0], (vuint16)kXcpDaqMemSize);  /* Deviation of MISRA rule 44. */
  885.   #if defined ( kXcpMaxEvent ) && ! defined ( XCP_ENABLE_DAQ_PRESCALER )
  886.     XcpMemSet( (BYTEPTR)&xcp.Daq.EventDaq[0], (vuint16)sizeof(xcp.Daq.EventDaq), (vuint8)0xFFu);  /* Deviation of MISRA rule 44. */
  887.   #endif
  888.  
  889.   #if defined ( XCP_ENABLE_SEND_QUEUE )
  890.   XcpQueueInit();
  891.   #endif
  892. }
  893.  
  894. /*****************************************************************************
  895. | NAME:             XcpAllocMemory
  896. | CALLED BY:        XcpAllocDaq, XcpAllocOdt, XcpAllocOdtEntry, XcpInit
  897. | PRECONDITIONS:    none
  898. | INPUT PARAMETERS: none
  899. | RETURN VALUES:    0, CRC_MEMORY_OVERFLOW
  900. | DESCRIPTION:      Allocate Memory for daq,odt,odtEntries and Queue
  901. |                   according to DaqCount, OdtCount and OdtEntryCount
  902. ******************************************************************************/
  903. static vuint8 XcpAllocMemory( void )
  904. {
  905.   vuint16 s;
  906.   #if defined ( XCP_ENABLE_NO_P2INT_CAST  )
  907.   vuint8* p;
  908.   vuint8  i;
  909.   #endif
  910.  
  911.   /* Check memory overflow */
  912.   s = (vuint16)( ( xcp.Daq.DaqCount      *   (vuint8)sizeof(tXcpDaqList)                           ) +
  913.                  ( xcp.Daq.OdtCount      *  (vuint16)sizeof(tXcpOdt)                               ) +
  914.                  ( xcp.Daq.OdtEntryCount * ( (vuint8)sizeof(DAQBYTEPTR) + (vuint8)sizeof(vuint8) ) )
  915.                );
  916.   #if defined ( XCP_DISABLE_UNALIGNED_MEM_ACCESS )
  917.     #if defined ( C_CPUTYPE_8BIT ) || defined ( C_CPUTYPE_16BIT )
  918.       s += 5; /* Worst case 5 bytes needed for alignment */ /* ESCAN00091645 */
  919.     #else
  920.       s += 9; /* Worst case 9 bytes needed for alignment */
  921.     #endif
  922.   #endif
  923.  
  924.   if (s>=(vuint16)kXcpDaqMemSize)
  925.   {
  926.     return (vuint8)CRC_MEMORY_OVERFLOW;
  927.   }
  928.  
  929.   /* Force WORD alignment for ODTs */
  930.   #if defined ( XCP_DISABLE_UNALIGNED_MEM_ACCESS )
  931.     #if defined ( XCP_ENABLE_NO_P2INT_CAST  )
  932.   p = (vuint8*)&xcp.Daq.u.DaqList[xcp.Daq.DaqCount];
  933.   i = ((vuint8)p) & (vuint8)0x01u;
  934.   p += i;
  935.   xcp.pOdt = (tXcpOdt*)p;
  936.     #else
  937.       #if defined ( C_CPUTYPE_8BIT ) || defined ( C_CPUTYPE_16BIT )
  938.   /* Align to words */
  939.   xcp.pOdt = (tXcpOdt*)((((vuint32)(&xcp.Daq.u.DaqList[xcp.Daq.DaqCount])) + (vuint32)1u) & (vuint32)0xFFFFFFFEu ); /* PRQA S 0306 */ /* MD_Xcp_0306 */
  940.       #else
  941.   /* Align to dwords */
  942.   xcp.pOdt = (tXcpOdt*)((((vuint32)(&xcp.Daq.u.DaqList[xcp.Daq.DaqCount])) + (vuint32)3u) & (vuint32)0xFFFFFFFCu ); /* PRQA S 0306 */ /* MD_Xcp_0306 */
  943.       #endif
  944.     #endif
  945.   #else
  946.   xcp.pOdt = (tXcpOdt*)&xcp.Daq.u.DaqList[xcp.Daq.DaqCount];
  947.   #endif
  948.  
  949.   /* Force DWORD alignment for ODT entries */
  950.   #if defined ( XCP_DISABLE_UNALIGNED_MEM_ACCESS )
  951.     #if defined ( XCP_ENABLE_NO_P2INT_CAST  )
  952.   p = (vuint8*)&xcp.pOdt[xcp.Daq.OdtCount];
  953.   i = ((vuint8)p) & (vuint8)0x03u;
  954.   i = (vuint8)4u - i;
  955.   i &= 0x03;
  956.   p += i;
  957.   xcp.pOdtEntryAddr = (DAQBYTEPTR*)p;
  958.     #else
  959.   xcp.pOdtEntryAddr = (DAQBYTEPTR*) ((((vuint32)&xcp.pOdt[xcp.Daq.OdtCount]) + (vuint32)3u) & (vuint32)0xFFFFFFFCu ); /* PRQA S 0306 */ /* MD_Xcp_0306 */
  960.     #endif
  961.   #else
  962.   xcp.pOdtEntryAddr = (DAQBYTEPTR*)&xcp.pOdt[xcp.Daq.OdtCount];
  963.   #endif
  964.   xcp.pOdtEntrySize = (vuint8*)&xcp.pOdtEntryAddr[xcp.Daq.OdtEntryCount]; /* PRQA S 0310 */ /* MD_Xcp_0310 */
  965.  
  966.   #if defined ( XCP_ENABLE_SEND_QUEUE )
  967.   /* Force WORD alignment for the queue */
  968.     #if defined ( XCP_DISABLE_UNALIGNED_MEM_ACCESS )
  969.     #if defined ( XCP_ENABLE_NO_P2INT_CAST )
  970.   p = (vuint8*)&xcp.pOdtEntrySize[xcp.Daq.OdtEntryCount];
  971.   i = ((vuint8)p) & (vuint8)0x01u;
  972.   p += i;
  973.   xcp.pQueue = (tXcpDto*)p;
  974.     #else
  975.       #if defined ( C_CPUTYPE_8BIT ) || defined ( C_CPUTYPE_16BIT )
  976.   /* Allign to words */
  977.   xcp.pQueue = (tXcpDto*)((((vuint32)(&xcp.pOdtEntrySize[xcp.Daq.OdtEntryCount])) + (vuint32)1u) & (vuint32)0xFFFFFFFEu ); /* PRQA S 0306 */ /* MD_Xcp_0306 */
  978.       #else
  979.   /* Allign to dwords */
  980.   xcp.pQueue = (tXcpDto*)((((vuint32)(&xcp.pOdtEntrySize[xcp.Daq.OdtEntryCount])) + (vuint32)3u) & (vuint32)0xFFFFFFFCu ); /* PRQA S 0306 */ /* MD_Xcp_0306 */
  981.       #endif
  982.     #endif
  983.     #else
  984.   xcp.pQueue = (tXcpDto*)&xcp.pOdtEntrySize[xcp.Daq.OdtEntryCount];
  985.     #endif
  986.  
  987.   xcp.QueueSize = ((vuint16)kXcpDaqMemSize - s) / sizeof(tXcpDto);
  988.  
  989.     #if defined ( kXcpSendQueueMinSize )
  990.   if (xcp.QueueSize<(vuint16)kXcpSendQueueMinSize)
  991.   {
  992.     return (vuint8)CRC_MEMORY_OVERFLOW;
  993.   }
  994.     #else
  995.   /* At least one queue entry per odt */
  996.   if (xcp.QueueSize<xcp.Daq.OdtCount)
  997.   {
  998.     return (vuint8)CRC_MEMORY_OVERFLOW;
  999.   }
  1000.     #endif
  1001.   #endif /* XCP_ENABLE_SEND_QUEUE */
  1002.  
  1003.   #if defined ( XCP_ENABLE_TESTMODE )
  1004.   if ( gDebugLevel != 0)
  1005.   {
  1006.     ApplXcpPrint("[XcpAllocMemory] %u/%u Bytes used\n",s,kXcpDaqMemSize );
  1007.     #if defined ( XCP_ENABLE_SEND_QUEUE )
  1008.     ApplXcpPrint("[XcpAllocMemory] Queuesize=%u\n",xcp.QueueSize );
  1009.     #endif
  1010.   }
  1011.   #endif
  1012.  
  1013.   return (vuint8)0u;
  1014.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  1015. }
  1016.  
  1017.  
  1018.  
  1019. /*****************************************************************************
  1020. | NAME:             XcpAllocDaq
  1021. | CALLED BY:        XcpCommand
  1022. | PRECONDITIONS:    none
  1023. | INPUT PARAMETERS: daqCount :
  1024. | RETURN VALUES:    return value of XcpAllocMemory, CRC_SEQUENCE
  1025. | DESCRIPTION:      Allocate DAQ list
  1026. ******************************************************************************/
  1027. static vuint8 XcpAllocDaq( vuint8 daqCount )
  1028. {
  1029.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  1030.   if ( (xcp.Daq.OdtCount!=0) || (xcp.Daq.OdtEntryCount!=0) )
  1031.   {
  1032.     return (vuint8)CRC_SEQUENCE;
  1033.   }
  1034.   if( daqCount == 0 )
  1035.   {
  1036.     return (vuint8)CRC_OUT_OF_RANGE;
  1037.   }
  1038.   #endif
  1039.  
  1040.   xcp.Daq.DaqCount = daqCount;
  1041.  
  1042.   return XcpAllocMemory();
  1043.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  1044. }
  1045.  
  1046. /*****************************************************************************
  1047. | NAME:             XcpAllocOdt
  1048. | CALLED BY:        XcpCommand
  1049. | PRECONDITIONS:    none
  1050. | INPUT PARAMETERS: daq      :
  1051. |                   odtCount :
  1052. | RETURN VALUES:    return value of XcpAllocMemory,
  1053. |                   CRC_SEQUENCE, CRC_MEMORY_OVERFLOW
  1054. | DESCRIPTION:      Allocate all ODTs in a DAQ list
  1055. ******************************************************************************/
  1056. static vuint8 XcpAllocOdt( vuint8 daq, vuint8 odtCount )
  1057. {
  1058.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  1059.   if ( (xcp.Daq.DaqCount==0) || (xcp.Daq.OdtEntryCount!=0) )
  1060.   {
  1061.     return (vuint8)CRC_SEQUENCE;
  1062.   }
  1063.   if( odtCount == 0 )
  1064.   {
  1065.     return (vuint8)CRC_OUT_OF_RANGE;
  1066.   }
  1067.   #endif
  1068.  
  1069.   /* Absolute ODT count must fit in a BYTE */
  1070.   #if !defined ( XCP_ENABLE_DAQ_HDR_ODT_DAQ )
  1071.    #if defined XCP_ENABLE_DAQ_OVERRUN_INDICATION
  1072.     if (((vuint16)xcp.Daq.OdtCount+(vuint16)odtCount) > (vuint16)0x7Bu) /* ESCAN00090685 */ /* ESCAN00092934 */
  1073.    #else
  1074.     if (((vuint16)xcp.Daq.OdtCount+(vuint16)odtCount) > (vuint16)0xFBu)
  1075.    #endif
  1076.   {
  1077.     return (vuint8)CRC_MEMORY_OVERFLOW;
  1078.   }
  1079.   #endif
  1080.  
  1081.   xcp.Daq.u.DaqList[daq].firstOdt = xcp.Daq.OdtCount;
  1082.   xcp.Daq.OdtCount += odtCount;
  1083.   xcp.Daq.u.DaqList[daq].lastOdt = (tXcpOdtIdx)(xcp.Daq.OdtCount-1);
  1084.  
  1085.   return XcpAllocMemory();
  1086.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  1087. }
  1088.  
  1089. /*****************************************************************************
  1090. | NAME:             XcpAllocOdtEntry
  1091. | CALLED BY:        XcpCommand
  1092. | PRECONDITIONS:    none
  1093. | INPUT PARAMETERS: daq :
  1094. |                   odt :
  1095. |                   odtEntryCount :
  1096. | RETURN VALUES:    return value of XcpAllocMemory
  1097. | DESCRIPTION:      Allocate all ODT entries
  1098. |                   Parameter odt is relative odt number
  1099. ******************************************************************************/
  1100. static vuint8 XcpAllocOdtEntry( vuint8 daq, vuint8 odt, vuint8 odtEntryCount )
  1101. {
  1102.   tXcpOdtIdx xcpFirstOdt;
  1103.  
  1104.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  1105.   if ( (xcp.Daq.DaqCount==0) || (xcp.Daq.OdtCount==0) )
  1106.   {
  1107.     return (vuint8)CRC_SEQUENCE;
  1108.   }
  1109.   if (odtEntryCount==0)
  1110.   {
  1111.     return (vuint8)CRC_OUT_OF_RANGE;
  1112.   }
  1113.   #endif
  1114.  
  1115.   /* Absolute ODT entry count count must fit in a WORD */
  1116.   if (xcp.Daq.OdtEntryCount > (0xFFFFu - odtEntryCount))
  1117.   {
  1118.     return (vuint8)CRC_MEMORY_OVERFLOW;
  1119.   }
  1120.   xcpFirstOdt = xcp.Daq.u.DaqList[daq].firstOdt;
  1121.   xcp.pOdt[xcpFirstOdt+odt].firstOdtEntry = xcp.Daq.OdtEntryCount;
  1122.   xcp.Daq.OdtEntryCount += (vuint16)odtEntryCount;
  1123.   xcp.pOdt[xcpFirstOdt+odt].lastOdtEntry = (vuint16)(xcp.Daq.OdtEntryCount-1);
  1124.  
  1125.   return XcpAllocMemory();
  1126.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  1127. }
  1128.  
  1129. /*****************************************************************************
  1130. | NAME:             XcpStartDaq
  1131. | CALLED BY:        XcpCommand, XcpStartAllSelectedDaq
  1132. | PRECONDITIONS:    none
  1133. | INPUT PARAMETERS: daq :
  1134. | RETURN VALUES:    none
  1135. | DESCRIPTION:      Start DAQ
  1136. ******************************************************************************/
  1137. static void XcpStartDaq( vuint8 daq )
  1138. {
  1139.   /* Initialize the DAQ list */
  1140.   DaqListFlags(daq) |= (vuint8)DAQ_FLAG_RUNNING;
  1141.   #if defined ( XCP_ENABLE_DAQ_PRESCALER )
  1142.   DaqListCycle(daq) = 1;
  1143.   #endif
  1144.  
  1145.   xcp.SessionStatus |= (SessionStatusType)SS_DAQ;
  1146. }
  1147.  
  1148. /*****************************************************************************
  1149. | NAME:             XcpStartAllSelectedDaq
  1150. | CALLED BY:        XcpCommand, XcpInit
  1151. | PRECONDITIONS:    none
  1152. | INPUT PARAMETERS: none
  1153. | RETURN VALUES:    none
  1154. | DESCRIPTION:      Start all selected DAQs
  1155. ******************************************************************************/
  1156. static void XcpStartAllSelectedDaq(void)
  1157. {
  1158.   vuint8 daq;
  1159.  
  1160.   /* Start all selected DAQs */
  1161.   for (daq=0;daq<xcp.Daq.DaqCount;daq++)
  1162.   {
  1163.     if ( (DaqListFlags(daq) & (vuint8)DAQ_FLAG_SELECTED) != 0 )
  1164.     {
  1165.       XcpStartDaq(daq);
  1166.       DaqListFlags(daq) &= (vuint8)(~DAQ_FLAG_SELECTED & 0x00FFu);
  1167.     }
  1168.   }
  1169. }
  1170.  
  1171. /*****************************************************************************
  1172. | NAME:             XcpStopDaq
  1173. | CALLED BY:        XcpCommand, XcpStopAllSelectedDaq
  1174. | PRECONDITIONS:    none
  1175. | INPUT PARAMETERS: daq :
  1176. | RETURN VALUES:    none
  1177. | DESCRIPTION:      Stop DAQ
  1178. ******************************************************************************/
  1179. static void XcpStopDaq( vuint8 daq )
  1180. {
  1181.   vuint8 i;
  1182.  
  1183.   DaqListFlags(daq) &= (vuint8)(DAQ_FLAG_DIRECTION|DAQ_FLAG_TIMESTAMP|DAQ_FLAG_NO_PID);
  1184.  
  1185.   /* Check if all DAQ lists are stopped */
  1186.   for (i=0;i<xcp.Daq.DaqCount;i++)
  1187.   {
  1188.     if ( (DaqListFlags(i) & (vuint8)DAQ_FLAG_RUNNING) != 0 )
  1189.     {
  1190.       return;
  1191.     }
  1192.   }
  1193.  
  1194.   xcp.SessionStatus &= (SessionStatusType)(~SS_DAQ & 0x00FFu);
  1195.  
  1196.   #if defined ( XCP_ENABLE_SEND_QUEUE )
  1197.   XcpQueueInit();
  1198.   #endif
  1199.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  1200. }
  1201.  
  1202. /*****************************************************************************
  1203. | NAME:             XcpStopAllSelectedDaq
  1204. | CALLED BY:        XcpCommand
  1205. | PRECONDITIONS:    none
  1206. | INPUT PARAMETERS: none
  1207. | RETURN VALUES:    none
  1208. | DESCRIPTION:      Stop all selected DAQs
  1209. ******************************************************************************/
  1210. static void XcpStopAllSelectedDaq(void)
  1211. {
  1212.   vuint8 daq;
  1213.  
  1214.   for (daq=0;daq<xcp.Daq.DaqCount;daq++)
  1215.   {
  1216.     if ( (DaqListFlags(daq) & (vuint8)DAQ_FLAG_SELECTED) != 0 )
  1217.     {
  1218.       XcpStopDaq(daq);
  1219.       DaqListFlags(daq) &= (vuint8)(~DAQ_FLAG_SELECTED & 0x00FFu);
  1220.     }
  1221.   }
  1222. }
  1223.  
  1224. /*****************************************************************************
  1225. | NAME:             XcpStopAllDaq
  1226. | CALLED BY:        XcpCommand, XcpDisconnect
  1227. | PRECONDITIONS:    none
  1228. | INPUT PARAMETERS: none
  1229. | RETURN VALUES:    none
  1230. | DESCRIPTION:      Stop all DAQs
  1231. ******************************************************************************/
  1232. static void XcpStopAllDaq( void )
  1233. {
  1234.   vuint8 daq;
  1235.  
  1236.   for (daq=0; daq<xcp.Daq.DaqCount; daq++)
  1237.   {
  1238.     DaqListFlags(daq) &= (vuint8)(DAQ_FLAG_DIRECTION|DAQ_FLAG_TIMESTAMP|DAQ_FLAG_NO_PID);
  1239.   }
  1240.  
  1241.   xcp.SessionStatus &= (SessionStatusType)(~SS_DAQ & 0x00FFu);
  1242.  
  1243.   #if defined ( XCP_ENABLE_SEND_QUEUE )
  1244.   XcpQueueInit();
  1245.   #endif
  1246. }
  1247.  
  1248.  
  1249. /****************************************************************************/
  1250. /* Data Aquisition Processor                                                */
  1251. /****************************************************************************/
  1252.  
  1253. /*****************************************************************************
  1254. | NAME:             XcpStimEventStatus
  1255. | CALLED BY:        application
  1256. | PRECONDITIONS:    The XCP is initialized and in connected state.
  1257. | INPUT PARAMETERS: event : event channel number to process
  1258. |                   action :
  1259. | RETURN VALUES:    1 (TRUE) if STIM data is available and XcpEvent() can be called
  1260. | DESCRIPTION:      Handling of data acquisition event channel.
  1261. ******************************************************************************/
  1262.  
  1263. /*****************************************************************************
  1264. | NAME:             XcpEvent
  1265. | CALLED BY:        application
  1266. | PRECONDITIONS:    The XCP is initialized and in connected state.
  1267. | INPUT PARAMETERS: event : event channel number to process
  1268. | RETURN VALUES:    status code (XCP_EVENT_...)
  1269. | DESCRIPTION:      Handling of data acquisition or stimulation event channel.
  1270. ******************************************************************************/
  1271. vuint8 XcpEvent( vuint8 event )
  1272. {
  1273.   tXcpDto *dtop;
  1274.   BYTEPTR d;
  1275.   vuint8  status;
  1276.   vuint16 e,el;
  1277.   vuint8  n;
  1278.   vuint8  daq;
  1279.   tXcpOdtIdx odt;
  1280.   vuint8  i;
  1281.   #if defined ( XCP_ENABLE_DAQ_TIMESTAMP ) && defined ( XCP_DISABLE_UNALIGNED_MEM_ACCESS )
  1282.   XcpDaqTimestampType t;
  1283.   #endif
  1284.   #if defined ( C_COMP_COSMIC_MCS12X_MSCAN12 )
  1285.   DAQBYTEPTR src;
  1286.   #endif
  1287.  
  1288.  
  1289.   status = (vuint8)0u;
  1290.  
  1291.   if ( (xcp.SessionStatus & (SessionStatusType)SS_DAQ) == 0 )
  1292.   {
  1293.     return (vuint8)XCP_EVENT_NOP;
  1294.   }
  1295.  
  1296.   /* Activation control */
  1297.   XcpPlCheckControlStateRet((vuint8)XCP_EVENT_NOP)
  1298.  
  1299.   #if defined ( kXcpMaxEvent ) && ! defined ( XCP_ENABLE_DAQ_PRESCALER )
  1300.  
  1301.     #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  1302.   if (event >= (vuint8)kXcpMaxEvent)
  1303.   {
  1304.     return (vuint8)XCP_EVENT_NOP;
  1305.   }
  1306.     #endif
  1307.  
  1308.   BEGIN_PROFILE(4); /* Timingtest */
  1309.   daq = xcp.Daq.EventDaq[event];
  1310.   if ( ((daq<xcp.Daq.DaqCount) && ( (DaqListFlags(daq) & (vuint8)DAQ_FLAG_RUNNING) != 0 )) != 0 )
  1311.   {
  1312.  
  1313.   #else
  1314.  
  1315.   BEGIN_PROFILE(4); /* Timingtest */
  1316.   for (daq=0; daq<xcp.Daq.DaqCount; daq++)
  1317.   {
  1318.     if ( (DaqListFlags(daq)& (vuint8)DAQ_FLAG_RUNNING) == 0 )
  1319.     {
  1320.       continue; /* PRQA S 0770 */ /* MD_Xcp_0770 */
  1321.     }
  1322.     if ( DaqListEventChannel(daq) != event )
  1323.     {
  1324.       continue; /* PRQA S 0770 */ /* MD_Xcp_0770 */
  1325.     }
  1326.  
  1327.   #endif
  1328.  
  1329.   #if defined ( XCP_ENABLE_DAQ_PRESCALER )
  1330.     DaqListCycle(daq)--;
  1331.     if ( DaqListCycle(daq) == (vuint8)0 )
  1332.     {
  1333.       DaqListCycle(daq) = DaqListPrescaler(daq);
  1334.   #endif
  1335.  
  1336.   /* Data Stimulation (STIM) */
  1337.  
  1338.       for (odt=DaqListFirstOdt(daq);odt<=DaqListLastOdt(daq);odt++)
  1339.       {
  1340. #if defined ( XCP_ENABLE_SEND_QUEUE )
  1341.         vuint16 qs;
  1342. #endif
  1343.         status |= (vuint8)XCP_EVENT_DAQ;
  1344.  
  1345.  
  1346.         ApplXcpInterruptDisable(); /* The following code is not reentrant */
  1347.  
  1348.   #if defined ( XCP_ENABLE_SEND_QUEUE )
  1349.         /* Check if there is space in the queue for this ODT */
  1350.         if (xcp.QueueLen>=xcp.QueueSize)
  1351.         {
  1352.           status |= (vuint8)XCP_EVENT_DAQ_OVERRUN; /* Queue overflow */
  1353.           DaqListFlags(daq) |= (vuint8)DAQ_FLAG_OVERRUN;
  1354.           goto next_odt; /* PRQA S 2001 */ /* MD_Xcp_2001 */
  1355.         }
  1356.  
  1357.         qs = (xcp.QueueRp + xcp.QueueLen);
  1358.         if(qs >= xcp.QueueSize)
  1359.         {
  1360.           qs -= xcp.QueueSize;
  1361.         }
  1362.  
  1363.         dtop = &xcp.pQueue[qs];
  1364.     #if defined ( XCP_SEND_QUEUE_SAMPLE_ODT )
  1365.         xcp.QueueLen++;
  1366.     #endif
  1367.   #else
  1368.         dtop = &dto;
  1369.   #endif /* XCP_ENABLE_SEND_QUEUE */
  1370.  
  1371.   #if defined ( XCP_ENABLE_DAQ_HDR_ODT_DAQ )
  1372.  
  1373.         /* ODT,DAQ */
  1374.         dtop->b[0] = odt-DaqListFirstOdt(daq); /* Relative odt number */
  1375.         dtop->b[1] = daq;
  1376.         i = 2;
  1377.  
  1378.   #else
  1379.  
  1380.         /* PID */
  1381.         dtop->b[0] = odt;
  1382.         i = 1;
  1383.  
  1384.   #endif
  1385.  
  1386.         /* Use BIT7 of PID or ODT to indicate overruns */
  1387.   #if defined ( XCP_ENABLE_SEND_QUEUE )
  1388.     #if defined ( XCP_ENABLE_DAQ_OVERRUN_INDICATION )
  1389.         if ( (DaqListFlags(daq) & (vuint8)DAQ_FLAG_OVERRUN) != 0 )
  1390.         {
  1391.           dtop->b[0] |= (vuint8)0x80;
  1392.           DaqListFlags(daq) &= (vuint8)(~DAQ_FLAG_OVERRUN & 0xFFu);
  1393.         }
  1394.     #endif
  1395.   #endif
  1396.  
  1397.         /* Timestamps */
  1398.   #if defined ( XCP_ENABLE_DAQ_TIMESTAMP )
  1399.  
  1400.     #if !defined ( XCP_ENABLE_DAQ_TIMESTAMP_FIXED )
  1401.         if ( (DaqListFlags(daq) & (vuint8)DAQ_FLAG_TIMESTAMP) != 0 )
  1402.         {
  1403.     #endif
  1404.  
  1405.           if (odt==DaqListFirstOdt(daq))
  1406.           {
  1407.     #if defined ( XCP_DISABLE_UNALIGNED_MEM_ACCESS )
  1408.             t = ApplXcpGetTimestamp();
  1409.     #endif
  1410.  
  1411.     #if defined ( XCP_ENABLE_DAQ_HDR_ODT_DAQ )
  1412.  
  1413.             *(XcpDaqTimestampType*)&dtop->b[2] = ApplXcpGetTimestamp();
  1414.             i = 2 + XcpDaqTimestampSize;
  1415.  
  1416.     #else /* XCP_ENABLE_DAQ_HDR_ODT_DAQ */
  1417.  
  1418.       #if defined ( XCP_DISABLE_UNALIGNED_MEM_ACCESS )
  1419.         #if defined ( XCP_CPUTYPE_BIGENDIAN )  /* Avoid WORD access */
  1420.           #if( kXcpDaqTimestampSize == DAQ_TIMESTAMP_BYTE )
  1421.             dtop->b[i+0u] = (vuint8)t;
  1422.           #elif( kXcpDaqTimestampSize == DAQ_TIMESTAMP_WORD )
  1423.             dtop->b[i+1u] = (vuint8)t;
  1424.             dtop->b[i+0u] = (vuint8)(t>>8);
  1425.           #elif( kXcpDaqTimestampSize == DAQ_TIMESTAMP_DWORD )
  1426.             dtop->b[i+3u] = (vuint8)t;
  1427.             dtop->b[i+2u] = (vuint8)(t>>8);
  1428.             dtop->b[i+1u] = (vuint8)(t>>16);
  1429.             dtop->b[i+0u] = (vuint8)(t>>24);
  1430.           #endif
  1431.         #else
  1432.             dtop->b[i+0u] = (vuint8)t;
  1433.           #if( kXcpDaqTimestampSize > DAQ_TIMESTAMP_BYTE )
  1434.             dtop->b[i+1u] = (vuint8)(t>>8);
  1435.           #endif
  1436.           #if( kXcpDaqTimestampSize > DAQ_TIMESTAMP_WORD )
  1437.             dtop->b[i+2u] = (vuint8)(t>>16);
  1438.             dtop->b[i+3u] = (vuint8)(t>>24);
  1439.           #endif
  1440.         #endif
  1441.       #else
  1442.             *(XcpDaqTimestampType*)&dtop->b[i] = ApplXcpGetTimestamp();
  1443.       #endif /* XCP_DISABLE_UNALIGNED_MEM_ACCESS */
  1444.             i += XcpDaqTimestampSize;
  1445.  
  1446.     #endif /* XCP_ENABLE_DAQ_HDR_ODT_DAQ */
  1447.           }
  1448.  
  1449.     #if !defined ( XCP_ENABLE_DAQ_TIMESTAMP_FIXED )
  1450.         }
  1451.     #endif
  1452.  
  1453.   #endif /* XCP_ENABLE_DAQ_TIMESTAMP */
  1454.  
  1455.         /* Sample data */
  1456.         /* This is the inner loop, optimize here */
  1457.         e = DaqListOdtFirstEntry(odt);
  1458.         if (OdtEntrySize(e)==0)
  1459.         {
  1460.           goto next_odt; /* PRQA S 2001 */ /* MD_Xcp_2001 */
  1461.         }
  1462.         el = DaqListOdtLastEntry(odt);
  1463.         d = (vuint8*)&dtop->b[i];
  1464.  
  1465.         while (e<=el)
  1466.         {
  1467.           n = OdtEntrySize(e);
  1468.           if (n == 0)
  1469.           {
  1470.             break;
  1471.           }
  1472.   #if defined ( C_COMP_COSMIC_MCS12X_MSCAN12 )
  1473.           src = (vuint32)OdtEntryAddr(e);
  1474.           for ( ; n > 0; n-- )
  1475.           {
  1476.             *d = XCP_READ_BYTE_FROM_ADDR( src );
  1477.             d++;
  1478.             src++;
  1479.           }
  1480.   #else
  1481.           XcpMemCpy((DAQBYTEPTR)d, OdtEntryAddr(e), n);
  1482.           d = &d[n]; /* d += n; Suppress warning for MISRA rule 101 (pointer arithmetic) */
  1483.   #endif
  1484.           e++;
  1485.         }
  1486.         dtop->l = (vuint8)(d-(&dtop->b[0]) ); /* PRQA S 0488 */ /* MD_Xcp_0488 */
  1487.         XCP_ASSERT(dtop->l<=kXcpMaxDTO);
  1488.  
  1489.         /* Queue or transmit the DTO */
  1490.   #if defined ( XCP_ENABLE_SEND_QUEUE )
  1491.     #if defined ( XCP_SEND_QUEUE_SAMPLE_ODT )
  1492.         /* No action yet */
  1493.     #else
  1494.         if ( (xcp.SendStatus & (vuint8)XCP_SEND_PENDING) != 0 )
  1495.         {
  1496.           xcp.QueueLen++;
  1497.         }
  1498.         else
  1499.         {
  1500.           xcp.SendStatus |= (vuint8)XCP_DTO_PENDING;
  1501.           XcpSendDto(dtop);
  1502.         }
  1503.     #endif
  1504.   #else
  1505.         XcpSendDto(&dto);
  1506.   #endif /* XCP_ENABLE_SEND_QUEUE */
  1507.         next_odt:
  1508.  
  1509.         ApplXcpInterruptEnable();
  1510.  
  1511.       } /* odt */
  1512.  
  1513.   #if defined ( XCP_ENABLE_SEND_QUEUE ) && defined ( XCP_SEND_QUEUE_SAMPLE_ODT )
  1514.       (void)XcpSendDtoFromQueue();
  1515.   #endif
  1516.  
  1517.  
  1518.   #if defined ( XCP_ENABLE_DAQ_PRESCALER )
  1519.     }
  1520.   #endif
  1521.  
  1522.   } /* daq */
  1523.  
  1524.   END_PROFILE(4); /* Timingtest */
  1525.   return status;
  1526.   /* PRQA S 2006 4 */ /* MD_MSR_14.7 */
  1527.   /* PRQA S 6010 3 */ /* MD_MSR_STPTH */
  1528.   /* PRQA S 6030 2 */ /* MD_MSR_STCYC */
  1529.   /* PRQA S 6080 1 */ /* MD_MSR_STMIF */
  1530. }
  1531.  
  1532. #endif /* XCP_ENABLE_DAQ */
  1533.  
  1534.  
  1535. /****************************************************************************/
  1536. /* Background Processing                                                    */
  1537. /* Used for Checksum Calculation                                            */
  1538. /****************************************************************************/
  1539.  
  1540. #if defined ( XCP_ENABLE_CHECKSUM )
  1541. /* Table for CCITT checksum calculation */
  1542.     #if ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_CRC16CCITT )
  1543.  
  1544.  
  1545.  
  1546.   V_MEMROM0 const vuint16 CRC16CCITTtab[256] = { /* PRQA S 3408 */ /* MD_Xcp_3408 */
  1547.       #if defined ( XCP_ENABLE_CRC16CCITT_REFLECTED )
  1548.     0x0000,0x1189,0x2312,0x329B,0x4624,0x57AD,0x6536,0x74BF,
  1549.     0x8C48,0x9DC1,0xAF5A,0xBED3,0xCA6C,0xDBE5,0xE97E,0xF8F7,
  1550.     0x1081,0x0108,0x3393,0x221A,0x56A5,0x472C,0x75B7,0x643E,
  1551.     0x9CC9,0x8D40,0xBFDB,0xAE52,0xDAED,0xCB64,0xF9FF,0xE876,
  1552.     0x2102,0x308B,0x0210,0x1399,0x6726,0x76AF,0x4434,0x55BD,
  1553.     0xAD4A,0xBCC3,0x8E58,0x9FD1,0xEB6E,0xFAE7,0xC87C,0xD9F5,
  1554.     0x3183,0x200A,0x1291,0x0318,0x77A7,0x662E,0x54B5,0x453C,
  1555.     0xBDCB,0xAC42,0x9ED9,0x8F50,0xFBEF,0xEA66,0xD8FD,0xC974,
  1556.     0x4204,0x538D,0x6116,0x709F,0x0420,0x15A9,0x2732,0x36BB,
  1557.     0xCE4C,0xDFC5,0xED5E,0xFCD7,0x8868,0x99E1,0xAB7A,0xBAF3,
  1558.     0x5285,0x430C,0x7197,0x601E,0x14A1,0x0528,0x37B3,0x263A,
  1559.     0xDECD,0xCF44,0xFDDF,0xEC56,0x98E9,0x8960,0xBBFB,0xAA72,
  1560.     0x6306,0x728F,0x4014,0x519D,0x2522,0x34AB,0x0630,0x17B9,
  1561.     0xEF4E,0xFEC7,0xCC5C,0xDDD5,0xA96A,0xB8E3,0x8A78,0x9BF1,
  1562.     0x7387,0x620E,0x5095,0x411C,0x35A3,0x242A,0x16B1,0x0738,
  1563.     0xFFCF,0xEE46,0xDCDD,0xCD54,0xB9EB,0xA862,0x9AF9,0x8B70,
  1564.     0x8408,0x9581,0xA71A,0xB693,0xC22C,0xD3A5,0xE13E,0xF0B7,
  1565.     0x0840,0x19C9,0x2B52,0x3ADB,0x4E64,0x5FED,0x6D76,0x7CFF,
  1566.     0x9489,0x8500,0xB79B,0xA612,0xD2AD,0xC324,0xF1BF,0xE036,
  1567.     0x18C1,0x0948,0x3BD3,0x2A5A,0x5EE5,0x4F6C,0x7DF7,0x6C7E,
  1568.     0xA50A,0xB483,0x8618,0x9791,0xE32E,0xF2A7,0xC03C,0xD1B5,
  1569.     0x2942,0x38CB,0x0A50,0x1BD9,0x6F66,0x7EEF,0x4C74,0x5DFD,
  1570.     0xB58B,0xA402,0x9699,0x8710,0xF3AF,0xE226,0xD0BD,0xC134,
  1571.     0x39C3,0x284A,0x1AD1,0x0B58,0x7FE7,0x6E6E,0x5CF5,0x4D7C,
  1572.     0xC60C,0xD785,0xE51E,0xF497,0x8028,0x91A1,0xA33A,0xB2B3,
  1573.     0x4A44,0x5BCD,0x6956,0x78DF,0x0C60,0x1DE9,0x2F72,0x3EFB,
  1574.     0xD68D,0xC704,0xF59F,0xE416,0x90A9,0x8120,0xB3BB,0xA232,
  1575.     0x5AC5,0x4B4C,0x79D7,0x685E,0x1CE1,0x0D68,0x3FF3,0x2E7A,
  1576.     0xE70E,0xF687,0xC41C,0xD595,0xA12A,0xB0A3,0x8238,0x93B1,
  1577.     0x6B46,0x7ACF,0x4854,0x59DD,0x2D62,0x3CEB,0x0E70,0x1FF9,
  1578.     0xF78F,0xE606,0xD49D,0xC514,0xB1AB,0xA022,0x92B9,0x8330,
  1579.     0x7BC7,0x6A4E,0x58D5,0x495C,0x3DE3,0x2C6A,0x1EF1,0x0F78
  1580.       #else
  1581.     0x0000,0x1021,0x2042,0x3063,0x4084,0x50a5,0x60c6,0x70e7u,
  1582.     0x8108,0x9129,0xa14a,0xb16b,0xc18c,0xd1ad,0xe1ce,0xf1efu,
  1583.     0x1231,0x0210,0x3273,0x2252,0x52b5,0x4294,0x72f7,0x62d6u,
  1584.     0x9339,0x8318,0xb37b,0xa35a,0xd3bd,0xc39c,0xf3ff,0xe3deu,
  1585.     0x2462,0x3443,0x0420,0x1401,0x64e6,0x74c7,0x44a4,0x5485u,
  1586.     0xa56a,0xb54b,0x8528,0x9509,0xe5ee,0xf5cf,0xc5ac,0xd58du,
  1587.     0x3653,0x2672,0x1611,0x0630,0x76d7,0x66f6,0x5695,0x46b4u,
  1588.     0xb75b,0xa77a,0x9719,0x8738,0xf7df,0xe7fe,0xd79d,0xc7bcu,
  1589.     0x48c4,0x58e5,0x6886,0x78a7,0x0840,0x1861,0x2802,0x3823u,
  1590.     0xc9cc,0xd9ed,0xe98e,0xf9af,0x8948,0x9969,0xa90a,0xb92bu,
  1591.     0x5af5,0x4ad4,0x7ab7,0x6a96,0x1a71,0x0a50,0x3a33,0x2a12u,
  1592.     0xdbfd,0xcbdc,0xfbbf,0xeb9e,0x9b79,0x8b58,0xbb3b,0xab1au,
  1593.     0x6ca6,0x7c87,0x4ce4,0x5cc5,0x2c22,0x3c03,0x0c60,0x1c41u,
  1594.     0xedae,0xfd8f,0xcdec,0xddcd,0xad2a,0xbd0b,0x8d68,0x9d49u,
  1595.     0x7e97,0x6eb6,0x5ed5,0x4ef4,0x3e13,0x2e32,0x1e51,0x0e70u,
  1596.     0xff9f,0xefbe,0xdfdd,0xcffc,0xbf1b,0xaf3a,0x9f59,0x8f78u,
  1597.     0x9188,0x81a9,0xb1ca,0xa1eb,0xd10c,0xc12d,0xf14e,0xe16fu,
  1598.     0x1080,0x00a1,0x30c2,0x20e3,0x5004,0x4025,0x7046,0x6067u,
  1599.     0x83b9,0x9398,0xa3fb,0xb3da,0xc33d,0xd31c,0xe37f,0xf35eu,
  1600.     0x02b1,0x1290,0x22f3,0x32d2,0x4235,0x5214,0x6277,0x7256u,
  1601.     0xb5ea,0xa5cb,0x95a8,0x8589,0xf56e,0xe54f,0xd52c,0xc50du,
  1602.     0x34e2,0x24c3,0x14a0,0x0481,0x7466,0x6447,0x5424,0x4405u,
  1603.     0xa7db,0xb7fa,0x8799,0x97b8,0xe75f,0xf77e,0xc71d,0xd73cu,
  1604.     0x26d3,0x36f2,0x0691,0x16b0,0x6657,0x7676,0x4615,0x5634u,
  1605.     0xd94c,0xc96d,0xf90e,0xe92f,0x99c8,0x89e9,0xb98a,0xa9abu,
  1606.     0x5844,0x4865,0x7806,0x6827,0x18c0,0x08e1,0x3882,0x28a3u,
  1607.     0xcb7d,0xdb5c,0xeb3f,0xfb1e,0x8bf9,0x9bd8,0xabbb,0xbb9au,
  1608.     0x4a75,0x5a54,0x6a37,0x7a16,0x0af1,0x1ad0,0x2ab3,0x3a92u,
  1609.     0xfd2e,0xed0f,0xdd6c,0xcd4d,0xbdaa,0xad8b,0x9de8,0x8dc9u,
  1610.     0x7c26,0x6c07,0x5c64,0x4c45,0x3ca2,0x2c83,0x1ce0,0x0cc1u,
  1611.     0xef1f,0xff3e,0xcf5d,0xdf7c,0xaf9b,0xbfba,0x8fd9,0x9ff8u,
  1612.     0x6e17,0x7e36,0x4e55,0x5e74,0x2e93,0x3eb2,0x0ed1,0x1ef0u
  1613.       #endif /* defined ( XCP_ENABLE_CRC16CCITT_REFLECTED ) */
  1614.   };
  1615.  
  1616.  
  1617.  
  1618.     #endif /* ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_CRC16CCITT ) */
  1619.  
  1620.  
  1621.   #if !defined ( kXcpChecksumBlockSize )
  1622.     #define kXcpChecksumBlockSize 256
  1623.   #endif
  1624.  
  1625. #endif /* defined ( XCP_ENABLE_CHECKSUM ) */
  1626.  
  1627.  
  1628. /*****************************************************************************
  1629. | NAME:             XcpBackground
  1630. | CALLED BY:        application
  1631. | PRECONDITIONS:    none
  1632. | INPUT PARAMETERS: none
  1633. | RETURN VALUES:    0 : background calculation finished
  1634. |                   1 : background calculation still pending
  1635. | DESCRIPTION:      perform background calculation of checksum
  1636. ******************************************************************************/
  1637. vuint8 XcpBackground( void )
  1638. {
  1639.  
  1640.   BEGIN_PROFILE(3); /* Timingtest */
  1641.  
  1642.   /* Activation control */
  1643.   XcpPlCheckControlStateRet((vuint8)0u)
  1644.  
  1645.   /* STORE_DAQ_REQ or CLEAR_DAQ_REQ pending */
  1646. #if defined ( XCP_ENABLE_DAQ )
  1647. #endif /* XCP_ENABLE_DAQ */
  1648.  
  1649.   /* XCP checksum calculation */
  1650. #if defined ( XCP_ENABLE_CHECKSUM ) && !defined ( XCP_ENABLE_CUSTOM_CRC )
  1651.  
  1652.   /*
  1653.      Checksum algorithm is not defined by the standard
  1654.      Type is defined by tXcpChecksumSumType, the maximum blocksize is 64K
  1655.   */
  1656.  
  1657.   /* Checksum calculation in progress */
  1658.   if ( (xcp.CheckSumSize) != (tXcpChecksumSumType)0u )
  1659.   {
  1660.  
  1661.     vuint16 n;
  1662.  
  1663.     if (xcp.CheckSumSize<=(kXcpChecksumBlockSize-1))
  1664.     {
  1665.       n = xcp.CheckSumSize;
  1666.       xcp.CheckSumSize = 0;
  1667.     }
  1668.     else
  1669.     {
  1670.       n = (vuint16)kXcpChecksumBlockSize;
  1671.       xcp.CheckSumSize -= kXcpChecksumBlockSize;
  1672.     }
  1673.  
  1674.  
  1675.     do
  1676.     {
  1677.       tXcpChecksumAddType data;
  1678.         data = XCP_READ_CHECKSUMVALUE_FROM_ADDR( xcp.Mta );
  1679.  
  1680.     #if ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_CRC16CCITT )
  1681.  
  1682.       #if defined ( XCP_ENABLE_CRC16CCITT_REFLECTED )
  1683.       /* CRC16 CCITT Reflected: Refin = true and refout = true. */
  1684.       xcp.CheckSum = CRC16CCITTtab[((vuint8)(xcp.CheckSum&0xFF)) ^ data] ^ ((vuint8)((xcp.CheckSum>>8)&0xFF));
  1685.       #else
  1686.       /* CRC16 CCITT */
  1687.       xcp.CheckSum = CRC16CCITTtab[((vuint8)((xcp.CheckSum >> 8)&0xFF)) ^ data] ^ (xcp.CheckSum << 8);
  1688.       #endif
  1689.  
  1690.       xcp.Mta++; /* PRQA S 0489 */ /* MD_Xcp_0489 */
  1691.       n--;
  1692.  
  1693.     #else
  1694.  
  1695.       /* Checksum calculation method: XCP_ADD_xx */
  1696.       xcp.CheckSum += (tXcpChecksumSumType)(data);
  1697.       #if ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_ADD11 )
  1698.         xcp.CheckSum &= 0xFF;
  1699.       #endif
  1700.       xcp.Mta      += (vuint8)tXcpChecksumAddSize; /* PRQA S 0488 */ /* MD_Xcp_0488 */
  1701.       n            -= (vuint8)tXcpChecksumAddSize;
  1702.  
  1703.     #endif
  1704.     }
  1705.     while (n!=0);
  1706.  
  1707.  
  1708.     /* Checksum calculation finished ? */
  1709.     if ( (xcp.CheckSumSize) != 0 )
  1710.     {
  1711.       END_PROFILE(3); /* Timingtest */
  1712.       return (vuint8)1u; /* Still pending */
  1713.     }
  1714.  
  1715.     CRM_BUILD_CHECKSUM_TYPE = kXcpChecksumMethod;
  1716.     /* PRQA S 3757 1 */ /* MD_Xcp_3757 */
  1717.     CRM_BUILD_CHECKSUM_RESULT_WRITE(xcp.CheckSum); /* PRQA S 3109 */ /* MD_MSR_14.3 */
  1718.     xcp.CrmLen = CRM_BUILD_CHECKSUM_LEN;
  1719.  
  1720.   #if defined ( XCP_ENABLE_TESTMODE )
  1721.     if ( gDebugLevel != 0)
  1722.     {
  1723.       ApplXcpPrint("<- 0xFF checksum=%08Xh, type=%02Xh\n",CRM_BUILD_CHECKSUM_RESULT,CRM_BUILD_CHECKSUM_TYPE);
  1724.     }
  1725.   #endif
  1726.  
  1727.     XcpSendCrm();
  1728.  
  1729.   } /* xcp.CheckSumSize */
  1730. #endif /* XCP_ENABLE_CHECKSUM && !XCP_ENABLE_CUSTOM_CRC */
  1731.  
  1732.   /* Application specific background ground loop. */
  1733.   ApplXcpBackground();
  1734.  
  1735.   END_PROFILE(3); /* Timingtest */
  1736.  
  1737.   return (vuint8)0u;
  1738.   /* PRQA S 2006 2 */ /* MD_MSR_14.7 */
  1739.   /* PRQA S 6010 1 */ /* MD_MSR_STPTH */
  1740. }
  1741.  
  1742.  
  1743. /****************************************************************************/
  1744. /* Command Processor                                                        */
  1745. /****************************************************************************/
  1746.  
  1747.  
  1748. /*****************************************************************************
  1749. | NAME:             XcpDisconnect
  1750. | CALLED BY:        XcpCommand
  1751. | PRECONDITIONS:    XCP is initialized and in connected state.
  1752. | INPUT PARAMETERS: none
  1753. | RETURN VALUES:    none
  1754. | DESCRIPTION:      If the XCP slave is connected to a XCP master a call of this
  1755. |                   function discontinues the connection (transition to disconnected state).
  1756. |                   If the XCP slave is not connected this function performs no action.
  1757. ******************************************************************************/
  1758. void XcpDisconnect( void )
  1759. {
  1760.   /* Activation control */
  1761.   XcpPlCheckControlState()
  1762.  
  1763.   xcp.SessionStatus &= (SessionStatusType)(~SS_CONNECTED & 0xFFu);
  1764.  
  1765. #if defined ( XCP_ENABLE_DAQ )
  1766.   XcpStopAllDaq();
  1767. #endif
  1768. #if defined ( XCP_ENABLE_SEED_KEY )
  1769.   /* Lock all resources */
  1770.   xcp.ProtectionStatus = (vuint8)RM_CAL_PAG|RM_DAQ|RM_PGM|RM_STIM;
  1771. #endif
  1772.  
  1773.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  1774. }
  1775.  
  1776.  
  1777. /*****************************************************************************
  1778. | NAME:             XcpCommand
  1779. | CALLED BY:        XcpSendCallBack, XCP Transport Layer
  1780. | PRECONDITIONS:    none
  1781. | INPUT PARAMETERS: pCmd : data of received CTO message.
  1782. | RETURN VALUES:    none
  1783. | DESCRIPTION:
  1784. ******************************************************************************/
  1785. void XcpCommand( const vuint32* pCommand )
  1786. {
  1787.   const tXcpCto* pCmd = (const tXcpCto*) pCommand; /* PRQA S 0310 */ /* MD_Xcp_0310 */
  1788.   vuint8 err;
  1789.  
  1790.   /* Activation control */
  1791.   XcpPlCheckControlState()
  1792.  
  1793.  /* XCP Data Stimulation Handler */
  1794.  
  1795.  
  1796.  
  1797.   /* XCP Command Handler */
  1798.  
  1799.   BEGIN_PROFILE(1); /* Timingtest */
  1800.  
  1801.   /* CONNECT */
  1802.   if (CRO_CMD==CC_CONNECT)
  1803.   {
  1804.  
  1805.     /* Prepare the default response */
  1806.     /* ESCAN00023570 */
  1807.     CRM_CMD = 0xFF; /* No Error */
  1808.     xcp.CrmLen = 1; /* Length = 1 */
  1809.  
  1810. #if defined ( XCP_ENABLE_TESTMODE )
  1811.     if ( gDebugLevel != 0)
  1812.     {
  1813.       ApplXcpPrint("\n-> CONNECT mode=%u\n",CRO_CONNECT_MODE);
  1814.     }
  1815. #endif
  1816.  
  1817.     /* DPRAM */
  1818.     /* DPRAM Client */
  1819.  
  1820.     /* Reset DAQ */
  1821.     /* Do not reset DAQ if in resume mode */
  1822. #if defined ( XCP_ENABLE_DAQ )
  1823.     if ( (xcp.SessionStatus & (SessionStatusType)SS_RESUME) == 0 )
  1824.     {
  1825.       XcpFreeDaq();
  1826.   #if defined ( XCP_ENABLE_SEND_QUEUE )
  1827.       xcp.SendStatus = 0; /* Clear all transmission flags */
  1828.   #endif
  1829.     }
  1830. #endif /* XCP_ENABLE_DAQ */
  1831.  
  1832. #if defined ( XCP_ENABLE_SEED_KEY )
  1833.     /* Lock all resources. */
  1834.     xcp.ProtectionStatus = (vuint8)RM_CAL_PAG|RM_DAQ|RM_PGM|RM_STIM;
  1835. #endif
  1836.  
  1837.     /* Reset Session Status */
  1838.     xcp.SessionStatus = (SessionStatusType)SS_CONNECTED;
  1839.  
  1840.     xcp.CrmLen = CRM_CONNECT_LEN;
  1841.  
  1842.     /* Versions of the XCP Protocol Layer and Transport Layer Specifications. */
  1843.     CRM_CONNECT_TRANSPORT_VERSION = (vuint8)( (vuint16)XCP_TRANSPORT_LAYER_VERSION >> 8 );
  1844.     CRM_CONNECT_PROTOCOL_VERSION =  (vuint8)( (vuint16)XCP_VERSION >> 8 );
  1845.  
  1846.     CRM_CONNECT_MAX_CTO_SIZE = kXcpMaxCTO;
  1847.     CRM_CONNECT_MAX_DTO_SIZE_WRITE(kXcpMaxDTO); /* PRQA S 3109 */ /* MD_MSR_14.3 */
  1848.  
  1849. #if defined ( XCP_ENABLE_CALIBRATION_PAGE )
  1850.     CRM_CONNECT_RESOURCE = RM_CAL_PAG;            /* Calibration */
  1851. #else
  1852.     CRM_CONNECT_RESOURCE = 0x00;                  /* Reset resource mask */
  1853. #endif
  1854. #if defined ( XCP_ENABLE_DAQ )
  1855.     CRM_CONNECT_RESOURCE |= (vuint8)RM_DAQ;       /* Data Acquisition */
  1856. #endif
  1857.  
  1858.     CRM_CONNECT_COMM_BASIC = 0;
  1859. #if defined ( XCP_ENABLE_COMM_MODE_INFO )
  1860.     CRM_CONNECT_COMM_BASIC |= (vuint8)CMB_OPTIONAL;
  1861. #endif
  1862. #if defined ( XCP_CPUTYPE_BIGENDIAN )
  1863.     CRM_CONNECT_COMM_BASIC |= (vuint8)PI_MOTOROLA;
  1864. #endif
  1865.  
  1866.     XCP_PRINT(("<- 0xFF version=%02Xh/%02Xh, maxcro=%02Xh, maxdto=%02Xh, resource=%02X, mode=%02X\n",
  1867.         CRM_CONNECT_PROTOCOL_VERSION,
  1868.         CRM_CONNECT_TRANSPORT_VERSION,
  1869.         CRM_CONNECT_MAX_CTO_SIZE,
  1870.         CRM_CONNECT_MAX_DTO_SIZE,
  1871.         CRM_CONNECT_RESOURCE,
  1872.         CRM_CONNECT_COMM_BASIC));
  1873.  
  1874.     goto positive_response; /* PRQA S 2001 */ /* MD_Xcp_2001 */
  1875.  
  1876.   }
  1877.  
  1878.   /* Handle other commands only if connected */
  1879.   else /* CC_CONNECT */
  1880.   {
  1881.     if ( (xcp.SessionStatus & (SessionStatusType)SS_CONNECTED) != 0 )
  1882.     {
  1883.       /* Ignore commands if the previous command sequence has not been completed */
  1884. #if defined ( XCP_ENABLE_SEND_QUEUE )
  1885.       if ( (xcp.SendStatus & (vuint8)(XCP_CRM_PENDING|XCP_CRM_REQUEST)) != 0 )
  1886.       {
  1887.         xcp.SessionStatus |= (SessionStatusType)SS_ERROR;
  1888.         END_PROFILE(1); /* Timingtest */
  1889.  
  1890.         /* No response */
  1891.         return;
  1892.       }
  1893. #endif
  1894.  
  1895.       #if defined ( XCP_ENABLE_GET_SESSION_STATUS_API )
  1896.         xcp.SessionStatus |= (SessionStatusType)SS_POLLING;
  1897.       #endif
  1898.  
  1899.       /* Prepare the default response */
  1900.       /* ESCAN00023570 */
  1901.       CRM_CMD = 0xFF; /* No Error */
  1902.       xcp.CrmLen = 1; /* Length = 1 */
  1903.  
  1904.       switch (CRO_CMD)
  1905.       {
  1906.  
  1907.         case CC_SYNC:
  1908.           {
  1909.             /* Always return a negative response with the error code ERR_CMD_SYNCH. */
  1910.             xcp.CrmLen = CRM_SYNCH_LEN;
  1911.             CRM_CMD    = PID_ERR;
  1912.             CRM_ERR    = CRC_CMD_SYNCH;
  1913.  
  1914. #if defined ( XCP_ENABLE_TESTMODE )
  1915.             if ( gDebugLevel != 0)
  1916.             {
  1917.               ApplXcpPrint("-> SYNC\n");
  1918.               ApplXcpPrint("<- 0xFE 0x00\n");
  1919.             }
  1920. #endif
  1921.           }
  1922.           break;
  1923.  
  1924.  
  1925. #if defined ( XCP_ENABLE_COMM_MODE_INFO )
  1926.         case CC_GET_COMM_MODE_INFO:
  1927.           {
  1928.             xcp.CrmLen = CRM_GET_COMM_MODE_INFO_LEN;
  1929.             /* Transmit the version of the XCP Protocol Layer implementation.    */
  1930.             /* The higher nibble is the main version, the lower the sub version. */
  1931.             /* The lower nibble overflows, if the sub version is greater than 15.*/
  1932.             CRM_GET_COMM_MODE_INFO_DRIVER_VERSION = (vuint8)( ((CP_XCP_VERSION & 0x0F00) >> 4) |
  1933.                                                                (CP_XCP_VERSION & 0x000F)         );
  1934.             CRM_GET_COMM_MODE_INFO_COMM_OPTIONAL = 0;
  1935.             CRM_GET_COMM_MODE_INFO_QUEUE_SIZE = 0;
  1936.             CRM_GET_COMM_MODE_INFO_MAX_BS = 0;
  1937.             CRM_GET_COMM_MODE_INFO_MIN_ST = 0;
  1938.  
  1939.   #if defined ( XCP_ENABLE_TESTMODE )
  1940.             if ( gDebugLevel != 0)
  1941.             {
  1942.               ApplXcpPrint("-> GET_COMM_MODE_INFO\n");
  1943.               ApplXcpPrint("<- 0xFF \n");
  1944.             }
  1945.   #endif
  1946.  
  1947.           }
  1948.           break;
  1949. #endif /* XCP_ENABLE_COMM_MODE_INFO */
  1950.  
  1951.  
  1952.           case CC_DISCONNECT:
  1953.             {
  1954.               xcp.CrmLen = CRM_DISCONNECT_LEN;
  1955.               XcpDisconnect();
  1956.  
  1957. #if defined ( XCP_ENABLE_TESTMODE )
  1958.               if ( gDebugLevel != 0)
  1959.               {
  1960.                 ApplXcpPrint("-> DISCONNECT\n");
  1961.                 ApplXcpPrint("<- 0xFF\n");
  1962.               }
  1963. #endif
  1964.             }
  1965.             break;
  1966.  
  1967.  
  1968. #if defined ( kXcpStationIdLength ) || defined ( XCP_ENABLE_GET_ID_GENERIC )
  1969.           case CC_GET_ID:
  1970.             {
  1971.               xcp.CrmLen = CRM_GET_ID_LEN;
  1972.               CRM_GET_ID_MODE = 0;
  1973.               CRM_GET_ID_LENGTH_WRITE(0x00); /* PRQA S 3109 */ /* MD_MSR_14.3 */
  1974.  
  1975.   #if defined ( kXcpStationIdLength )
  1976.               if ( CRO_GET_ID_TYPE == IDT_ASAM_NAME )   /* Type = ASAM MC2 */
  1977.               {
  1978.                 CRM_GET_ID_LENGTH_WRITE((vuint32)kXcpStationIdLength); /* PRQA S 3109 */ /* MD_MSR_14.3 */
  1979.                 //XcpSetMta( ApplXcpGetPointer(0xFF, (vuint32)(&kXcpStationId[0])), 0xFF); /* PRQA S 0306 */ /* MD_Xcp_0306 */
  1980.                 XcpSetMta((MTABYTEPTR)(&kXcpStationId[0]), 0xFF);
  1981.               } else
  1982.   #endif
  1983.               {
  1984.   #if defined ( XCP_ENABLE_GET_ID_GENERIC )
  1985.                 MTABYTEPTR pData;
  1986.                 /* PRQA S 3757 1 */ /* MD_Xcp_3757 */
  1987.                 CRM_GET_ID_LENGTH_WRITE(ApplXcpGetIdData(&pData, CRO_GET_ID_TYPE)); /* PRQA S 3109 */ /* MD_MSR_14.3 */
  1988.                 XcpSetMta(ApplXcpGetPointer(0x00, (vuint32)pData), 0xFF); /* PRQA S 0306 */ /* MD_Xcp_0306 */
  1989.   #endif
  1990.               }
  1991.  
  1992.   #if defined ( XCP_ENABLE_TESTMODE )
  1993.               if ( gDebugLevel != 0)
  1994.               {
  1995.                 ApplXcpPrint("-> GET_ID type=%u\n",CRO_GET_ID_TYPE);
  1996.                 ApplXcpPrint("<- 0xFF mode=%u,len=%u\n",CRM_GET_ID_MODE,CRM_GET_ID_LENGTH);
  1997.               }
  1998.   #endif
  1999.             }
  2000.             break;
  2001. #endif
  2002.  
  2003.  
  2004.           case CC_GET_STATUS:
  2005.             {
  2006.               xcp.CrmLen = CRM_GET_STATUS_LEN;
  2007.               CRM_GET_STATUS_STATUS = (vuint8)xcp.SessionStatus;
  2008. #if defined ( XCP_ENABLE_SEED_KEY )
  2009.               /* Return current resource protection status. If a bit is one, the associated resource is locked. */
  2010.               CRM_GET_STATUS_PROTECTION = xcp.ProtectionStatus;
  2011. #else
  2012.               CRM_GET_STATUS_PROTECTION = 0;
  2013. #endif
  2014.  
  2015.               /* Session configuration ID not available. */
  2016.               CRM_GET_STATUS_CONFIG_ID_WRITE(0x00);
  2017.  
  2018. #if defined ( XCP_ENABLE_TESTMODE )
  2019.               if ( gDebugLevel != 0)
  2020.               {
  2021.                 ApplXcpPrint("-> GET_STATUS\n");
  2022.                 ApplXcpPrint("<- 0xFF sessionstatus=%02Xh, protectionstatus=%02X\n",CRM_GET_STATUS_STATUS,CRM_GET_STATUS_PROTECTION);
  2023.               }
  2024. #endif
  2025.             }
  2026.             break;
  2027.  
  2028.  
  2029. #if defined ( XCP_ENABLE_SEED_KEY )
  2030.  
  2031.           case CC_GET_SEED:
  2032.             {
  2033.               /* Only seeds with a maximum length of MAX_CTO-2 are supported so far. */
  2034.  
  2035.               /* Check whether the first part or a remaining part of the seed is requested. */
  2036.               if (CRO_GET_SEED_MODE == 0x01)
  2037.               {
  2038.                 /* Remaining parts of seeds are not supported so far. */
  2039.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2040.               }
  2041.               else
  2042.               {
  2043.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  2044.                 /* Only one resource may be requested at one time. */
  2045.                 switch (CRO_GET_SEED_RESOURCE)
  2046.                 {
  2047.                   case RM_CAL_PAG:
  2048.                     break;
  2049.                   case RM_PGM:
  2050.                     break;
  2051.                   case RM_DAQ:
  2052.                     break;
  2053.                   case RM_STIM:
  2054.                     break;
  2055.                   default:
  2056.                     error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2057.                 }
  2058.  
  2059.   #endif
  2060.                 if ((xcp.ProtectionStatus & CRO_GET_SEED_RESOURCE) != 0)   /* locked */
  2061.                 {
  2062.                    vuint8 seedLength;
  2063.                    seedLength = ApplXcpGetSeed(CRO_GET_SEED_RESOURCE, CRM_GET_SEED_DATA);
  2064.                    if (seedLength > (vuint8)(kXcpMaxCTO-2))
  2065.                    {
  2066.                      /* A maximum seed length of MAX_CTO-2 is supported. */
  2067.                      error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2068.                    }
  2069.                    CRM_GET_SEED_LENGTH = seedLength;
  2070.                 }
  2071.                 else                       /* Unlocked */
  2072.                 {
  2073.                   /* return 0 if the resource is unprotected. */
  2074.                   CRM_GET_SEED_LENGTH = 0;
  2075.                 }
  2076.                 xcp.CrmLen = (vuint8)CRM_GET_SEED_LEN;
  2077.               }
  2078.  
  2079.   #if defined ( XCP_ENABLE_TESTMODE )
  2080.               if ( gDebugLevel != 0)
  2081.               {
  2082.                 ApplXcpPrint("-> GET_SEED resource=%02Xh\n",CRO_GET_SEED_RESOURCE);
  2083.                 ApplXcpPrint("<- 0xFF length=%02Xh, seed=%02X%02X%02X%02X%02X%02X\n",CRM_GET_SEED_LENGTH,CRM_GET_SEED_DATA[0],CRM_GET_SEED_DATA[1],CRM_GET_SEED_DATA[2],CRM_GET_SEED_DATA[3],CRM_GET_SEED_DATA[4],CRM_GET_SEED_DATA[5]);
  2084.               }
  2085.   #endif
  2086.             }
  2087.             break;
  2088.  
  2089.           case CC_UNLOCK:
  2090.             {
  2091.               vuint8 resource;
  2092.  
  2093.   #if defined ( XCP_ENABLE_TESTMODE )
  2094.               if ( gDebugLevel != 0)
  2095.               {
  2096.                 ApplXcpPrint("-> UNLOCK key=%02X%02X%02X%02X%02X%02X\n",CRO_UNLOCK_KEY[0],CRO_UNLOCK_KEY[1],CRO_UNLOCK_KEY[2],CRO_UNLOCK_KEY[3],CRO_UNLOCK_KEY[4],CRO_UNLOCK_KEY[5]);
  2097.               }
  2098.   #endif
  2099.  
  2100.               /* Only keys with a maximum length of MAX_CTO-2 are supported so far. */
  2101.               if (CRO_UNLOCK_LENGTH > (vuint8)(kXcpMaxCTO-2))
  2102.               {
  2103.                 error(CRC_SEQUENCE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2104.               }
  2105.               else
  2106.               {
  2107.                 resource = ApplXcpUnlock(CRO_UNLOCK_KEY, CRO_UNLOCK_LENGTH);
  2108.                 if ( resource == (vuint8)0x00u )
  2109.                 {
  2110.                   /* Key wrong ! */
  2111.                   /* Send ERR_ACCESS_LOCKED and go to disconnected state. */
  2112.                   XcpDisconnect();
  2113.                   error(CRC_ACCESS_LOCKED) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2114.                 }
  2115.                 else
  2116.                 {
  2117.                   /* unlock (reset) the appropriate resource protection mask bit.. */
  2118.                   xcp.ProtectionStatus &= (vuint8)~resource;
  2119.  
  2120.                   /* ..and return the current resource protection status. */
  2121.                   CRM_UNLOCK_PROTECTION = xcp.ProtectionStatus;
  2122.                   xcp.CrmLen = CRM_UNLOCK_LEN;
  2123.                 }
  2124.               }
  2125.  
  2126.   #if defined ( XCP_ENABLE_TESTMODE )
  2127.               if ( gDebugLevel != 0)
  2128.               {
  2129.                 ApplXcpPrint("<- 0xFF\n");
  2130.               }
  2131.   #endif
  2132.             }
  2133.             break;
  2134.  
  2135. #endif /* XCP_ENABLE_SEED_KEY */
  2136.  
  2137.  
  2138. #if defined ( XCP_ENABLE_CALIBRATION_PAGE )
  2139.  
  2140.           case CC_SET_CAL_PAGE:
  2141.             {
  2142.   #if defined ( XCP_ENABLE_TESTMODE )
  2143.               if ( gDebugLevel != 0)
  2144.               {
  2145.                 ApplXcpPrint("-> SET_CAL_PAGE segment=%u,page =%u,mode=%02Xh\n",CRO_SET_CAL_PAGE_SEGMENT,CRO_SET_CAL_PAGE_PAGE,CRO_SET_CAL_PAGE_MODE);
  2146.               }
  2147.   #endif
  2148.  
  2149.               check_error( ApplXcpSetCalPage(CRO_SET_CAL_PAGE_SEGMENT,CRO_SET_CAL_PAGE_PAGE,CRO_SET_CAL_PAGE_MODE) ) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2150.  
  2151.   #if defined ( XCP_ENABLE_TESTMODE )
  2152.               if ( gDebugLevel != 0)
  2153.               {
  2154.                 ApplXcpPrint("<- 0xFF\n");
  2155.               }
  2156.   #endif
  2157.             }
  2158.             break;
  2159.  
  2160.           case CC_GET_CAL_PAGE:
  2161.             {
  2162.  
  2163.   #if defined ( XCP_ENABLE_TESTMODE )
  2164.               if ( gDebugLevel != 0)
  2165.               {
  2166.                 ApplXcpPrint("-> GET_CAL_PAGE Segment=%u, Mode=%u\n",CRO_GET_CAL_PAGE_SEGMENT,CRO_GET_CAL_PAGE_MODE);
  2167.               }
  2168.   #endif
  2169.  
  2170.               xcp.CrmLen = CRM_GET_CAL_PAGE_LEN;
  2171.               CRM_GET_CAL_PAGE_PAGE = ApplXcpGetCalPage(CRO_GET_CAL_PAGE_SEGMENT,CRO_GET_CAL_PAGE_MODE);
  2172.  
  2173.   #if defined ( XCP_ENABLE_TESTMODE )
  2174.               if ( gDebugLevel != 0)
  2175.               {
  2176.                 ApplXcpPrint("<- 0xFF page=%u\n",CRM_GET_CAL_PAGE_PAGE);
  2177.               }
  2178.   #endif
  2179.             }
  2180.             break;
  2181.  
  2182. #endif /* XCP_ENABLE_CALIBRATION_PAGE */
  2183.  
  2184.  
  2185. #if defined ( XCP_ENABLE_PAGE_INFO )
  2186.           /* Paging Information optional */
  2187.           case CC_GET_PAG_PROCESSOR_INFO:
  2188.             {
  2189.   #if defined ( XCP_ENABLE_TESTMODE )
  2190.               if ( gDebugLevel != 0)
  2191.               {
  2192.                 ApplXcpPrint("-> CC_GET_PAG_PROCESSOR_INFO");
  2193.               }
  2194.   #endif
  2195.  
  2196.               xcp.CrmLen = CRM_GET_PAG_PROCESSOR_INFO_LEN;
  2197.  
  2198.               CRM_GET_PAG_PROCESSOR_INFO_MAX_SEGMENT = (vuint8)kXcpMaxSegment;
  2199.   #if defined ( XCP_ENABLE_PAGE_FREEZE )
  2200.               CRM_GET_PAG_PROCESSOR_INFO_PROPERTIES  = 1; /* FREEZE_SUPPORTED = 1 */
  2201.   #else
  2202.               CRM_GET_PAG_PROCESSOR_INFO_PROPERTIES  = 0; /* FREEZE_SUPPORTED = 0 */
  2203.   #endif
  2204.  
  2205.   #if defined ( XCP_ENABLE_TESTMODE )
  2206.                if ( gDebugLevel != 0)
  2207.                {
  2208.                  ApplXcpPrint("<- 0xFF maxsegment=%u\n",(vuint8)kXcpMaxSegment);
  2209.                }
  2210.   #endif
  2211.  
  2212.             }
  2213.             break;
  2214.  
  2215.  
  2216.           case CC_GET_SEGMENT_INFO:
  2217.             {
  2218.     #if defined ( XCP_ENABLE_TESTMODE )
  2219.               if ( gDebugLevel != 0)
  2220.               {
  2221.                 ApplXcpPrint("-> CC_GET_SEGMENT_INFO");
  2222.               }
  2223.     #endif
  2224.  
  2225.               if (CRO_GET_SEGMENT_INFO_NUMBER >= (vuint8)kXcpMaxSegment)
  2226.               {
  2227.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2228.               }
  2229.  
  2230.               xcp.CrmLen = CRM_GET_SEGMENT_INFO_LEN;
  2231.               /* Get standard info for a segment.
  2232.                  SEGMENT_INFO and MAPPING_INDEX are don't care
  2233.               */
  2234.               if (CRO_GET_SEGMENT_INFO_MODE == 1)
  2235.               {
  2236.                 CRM_GET_SEGMENT_INFO_MAX_PAGES         = 2;
  2237.                 CRM_GET_SEGMENT_INFO_ADDRESS_EXTENSION = 0;
  2238.                 CRM_GET_SEGMENT_INFO_MAX_MAPPING       = 0;
  2239.                 CRM_GET_SEGMENT_INFO_COMPRESSION       = 0;
  2240.                 CRM_GET_SEGMENT_INFO_ENCRYPTION        = 0;
  2241.  
  2242.               }
  2243.               /* Get basic address info for a segment:
  2244.                    SEGMENT_INFO contains address range information and
  2245.                    MAPPING_INDEX is don't care
  2246.                  Get address mapping for a segment:
  2247.                    SEGMENT_INFO contains address range information and
  2248.                    MAPPING_INDEX indicates the range MAPPING_INFO belongs to
  2249.               */
  2250.               if ( (CRO_GET_SEGMENT_INFO_MODE == 0) || (CRO_GET_SEGMENT_INFO_MODE == 2) )
  2251.               {
  2252.                 CRM_GET_SEGMENT_INFO_MAPPING_INFO = 0;
  2253.               }
  2254.  
  2255.     #if defined ( XCP_ENABLE_TESTMODE )
  2256.               if (gDebugLevel && CRO_GET_SEGMENT_INFO_MODE == 1)
  2257.               {
  2258.                 ApplXcpPrint("<- 0xFF Mode=%u, Maxpages=%u, AddrExt=%u, Mappingmax=%u, Compression=%u, Encryption=%u\n",CRO_GET_SEGMENT_INFO_MODE,CRM_GET_SEGMENT_INFO_MAX_PAGES,CRM_GET_SEGMENT_INFO_ADDRESS_EXTENSION,CRM_GET_SEGMENT_INFO_MAX_MAPPING,CRM_GET_SEGMENT_INFO_COMPRESSION,CRM_GET_SEGMENT_INFO_ENCRYPTION);
  2259.               }
  2260.               if (gDebugLevel && CRO_GET_SEGMENT_INFO_MODE == 0 || CRO_GET_SEGMENT_INFO_MODE == 2)
  2261.               {
  2262.                 ApplXcpPrint("<- 0xFF Mode=%u, MappingInfo=%u\n",CRO_GET_SEGMENT_INFO_MODE,CRM_GET_SEGMENT_INFO_MAPPING_INFO);
  2263.               }
  2264.     #endif
  2265.             }
  2266.             break;
  2267.  
  2268.           case CC_GET_PAGE_INFO:
  2269.             {
  2270.     #if defined ( XCP_ENABLE_TESTMODE )
  2271.               if ( gDebugLevel != 0)
  2272.               {
  2273.                 ApplXcpPrint("-> CC_GET_PAGE_INFO");
  2274.               }
  2275.     #endif
  2276.  
  2277.               if ( ( CRO_GET_PAGE_INFO_SEGMENT_NUMBER > ((vuint8)(kXcpMaxSegment-1)&0xFFu) ) ||
  2278.                    ( CRO_GET_PAGE_INFO_PAGE_NUMBER >((vuint8)(kXcpMaxPages-1)&0xFFu) ) )
  2279.               {
  2280.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2281.               }
  2282.  
  2283.               xcp.CrmLen = CRM_GET_PAGE_INFO_LEN;
  2284.               CRM_GET_PAGE_INFO_PROPERTIES = 0;
  2285.  
  2286.     #if defined ( XCP_ENABLE_TESTMODE )
  2287.               if ( gDebugLevel != 0)
  2288.               {
  2289.                 ApplXcpPrint("<- 0xFF properties=%u\n",CRM_GET_PAGE_INFO_PROPERTIES);
  2290.               }
  2291.     #endif
  2292.             }
  2293.             break;
  2294. #endif /* defined ( XCP_BASIC_VERSION_COMMENT ) */
  2295.  
  2296.           /* Paging freeze mode support */
  2297. #if defined ( XCP_ENABLE_PAGE_FREEZE )
  2298.           case CC_SET_SEGMENT_MODE:
  2299.             {
  2300.   #if defined ( XCP_ENABLE_TESTMODE )
  2301.               if ( gDebugLevel != 0)
  2302.               {
  2303.                 ApplXcpPrint("-> CC_SET_SEGMENT_MODE segment=%u, mode=%u\n",CRO_SET_SEGMENT_MODE_SEGMENT,CRO_SET_SEGMENT_MODE_MODE);
  2304.               }
  2305.   #endif
  2306.  
  2307.               if (CRO_SET_SEGMENT_MODE_SEGMENT > ((vuint8)(kXcpMaxSegment-1)&0xFFu))
  2308.               {
  2309.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2310.               }
  2311.  
  2312.               /* inform application about Set Segment Mode command */
  2313.               ApplXcpSetFreezeMode(CRO_SET_SEGMENT_MODE_SEGMENT, CRO_SET_SEGMENT_MODE_MODE);
  2314.               /* CRO_SET_SEGMENT_MODE_MODE;*/
  2315.               xcp.CrmLen = CRM_SET_SEGMENT_MODE_LEN;
  2316.  
  2317.   #if defined ( XCP_ENABLE_TESTMODE )
  2318.               if ( gDebugLevel != 0)
  2319.               {
  2320.                 ApplXcpPrint("<- 0xFF\n");
  2321.               }
  2322.   #endif
  2323.             }
  2324.             break;
  2325.  
  2326.           case CC_GET_SEGMENT_MODE:
  2327.             {
  2328.   #if defined ( XCP_ENABLE_TESTMODE )
  2329.               if ( gDebugLevel != 0)
  2330.               {
  2331.                 ApplXcpPrint("-> CC_GET_SEGMENT_MODE");
  2332.               }
  2333.   #endif
  2334.  
  2335.               if (CRO_GET_SEGMENT_MODE_SEGMENT > ((vuint8)(kXcpMaxSegment-1)&0xFFu))
  2336.               {
  2337.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2338.               }
  2339.  
  2340.               /* request current freeze mode information from application */
  2341.               CRM_GET_SEGMENT_MODE_MODE = ApplXcpGetFreezeMode(CRO_GET_SEGMENT_MODE_SEGMENT);
  2342.  
  2343.               xcp.CrmLen = CRM_GET_SEGMENT_MODE_LEN;
  2344.  
  2345.   #if defined ( XCP_ENABLE_TESTMODE )
  2346.               if ( gDebugLevel != 0)
  2347.               {
  2348.                 ApplXcpPrint("<- 0xFF mode=%u\n",CRM_GET_SEGMENT_MODE_MODE);
  2349.               }
  2350.   #endif
  2351.             }
  2352.             break;
  2353. #endif /* XCP_ENABLE_PAGE_FREEZE */
  2354.  
  2355.           /* Copy cal page support */
  2356. #if defined ( XCP_ENABLE_PAGE_COPY )
  2357.           case CC_COPY_CAL_PAGE:
  2358.             {
  2359.   #if defined ( XCP_ENABLE_TESTMODE )
  2360.               if ( gDebugLevel != 0)
  2361.               {
  2362.                 ApplXcpPrint("-> CC_COPY_CAL_PAGE");
  2363.               }
  2364.   #endif
  2365.  
  2366.               xcp.CrmLen = CRM_COPY_CAL_PAGE_LEN;
  2367.  
  2368.               err = ApplXcpCopyCalPage(CRO_COPY_CAL_PAGE_SRC_SEGMENT,CRO_COPY_CAL_PAGE_SRC_PAGE,CRO_COPY_CAL_PAGE_DEST_SEGMENT,CRO_COPY_CAL_PAGE_DEST_PAGE);
  2369.  
  2370.               if (err==(vuint8)XCP_CMD_PENDING)
  2371.               {
  2372.                 goto no_response; /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2373.               }
  2374.  
  2375.               check_error( err ) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2376.  
  2377.   #if defined ( XCP_ENABLE_TESTMODE )
  2378.               if ( gDebugLevel != 0)
  2379.               {
  2380.                 ApplXcpPrint("<- 0xFF\n");
  2381.               }
  2382.   #endif
  2383.             }
  2384.             break;
  2385. #endif /* XCP_ENABLE_PAGE_COPY */
  2386.  
  2387.  
  2388.           case CC_SET_MTA:
  2389.             {
  2390. #if defined ( XCP_ENABLE_TESTMODE )
  2391.               if ( gDebugLevel != 0)
  2392.               {
  2393.                 ApplXcpPrint("-> SET_MTA addr=%08Xh, addrext=%02Xh\n",CRO_SET_MTA_ADDR,CRO_SET_MTA_EXT);
  2394.               }
  2395. #endif
  2396.               XcpSetMta(ApplXcpGetPointer(CRO_SET_MTA_EXT,CRO_SET_MTA_ADDR),CRO_SET_MTA_EXT);
  2397.  
  2398.  
  2399. #if defined ( XCP_ENABLE_TESTMODE )
  2400.               if ( gDebugLevel != 0)
  2401.               {
  2402.                 ApplXcpPrint("<- 0xFF\n");
  2403.               }
  2404. #endif
  2405.             }
  2406.             break;
  2407.  
  2408.  
  2409.           case CC_DOWNLOAD: /* PRQA S 2003 */ /* MD_Xcp_2003 */
  2410.             {
  2411. #if defined ( XCP_ENABLE_CALIBRATION )
  2412.               vuint8 size;
  2413.  
  2414. #if defined ( XCP_ENABLE_TESTMODE )
  2415.               if (gDebugLevel && (CRO_CMD != CC_DOWNLOAD_NEXT))
  2416.               {
  2417.                 vuint16 i;
  2418.                 ApplXcpPrint("-> DOWNLOAD size=%u, data=",CRO_DOWNLOAD_SIZE);
  2419.                 for (i=0;(i<CRO_DOWNLOAD_SIZE) && (i<CRO_DOWNLOAD_MAX_SIZE);i++)
  2420.                 {
  2421.                   ApplXcpPrint("%02X ",CRO_DOWNLOAD_DATA[i]);
  2422.                 }
  2423.                 ApplXcpPrint("\n");
  2424.               }
  2425. #endif
  2426.  
  2427.               CheckResourceProtection( RM_CAL_PAG ) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2428.  
  2429.               size = CRO_DOWNLOAD_SIZE;
  2430.               if (size>CRO_DOWNLOAD_MAX_SIZE)
  2431.               {
  2432.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2433.               }
  2434.  
  2435.               err = XcpWriteMta(size,CRO_DOWNLOAD_DATA);
  2436.               if (err==(vuint8)XCP_CMD_PENDING)
  2437.               {
  2438.                 goto no_response; /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2439.               }
  2440.               if (err==(vuint8)XCP_CMD_DENIED)
  2441.               {
  2442.                 error(CRC_WRITE_PROTECTED) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2443.               }
  2444.               if (err==(vuint8)XCP_CMD_SYNTAX)
  2445.               {
  2446.                 error(CRC_CMD_SYNTAX) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2447.               }
  2448.  
  2449.  
  2450. #if defined ( XCP_ENABLE_TESTMODE )
  2451.               if ( gDebugLevel != 0)
  2452.               {
  2453.                 ApplXcpPrint("<- 0xFF\n");
  2454.               }
  2455. #endif
  2456. #else
  2457.               error(CRC_CMD_UNKNOWN) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2458. #endif /* !defined ( XCP_ENABLE_CALIBRATION ) */
  2459.  
  2460.             }
  2461.             break;
  2462.  
  2463.           case CC_DOWNLOAD_MAX:
  2464.             {
  2465. #if defined ( XCP_ENABLE_CALIBRATION )
  2466.   #if defined ( XCP_ENABLE_TESTMODE )
  2467.               if ( gDebugLevel != 0)
  2468.               {
  2469.                 vuint16 i;
  2470.                 ApplXcpPrint("DOWNLOAD_MAX data=");
  2471.                 for (i=0;i<CRO_DOWNLOAD_MAX_MAX_SIZE;i++)
  2472.                 {
  2473.                   ApplXcpPrint("%02X ",CRO_DOWNLOAD_MAX_DATA[i]);
  2474.                 }
  2475.                 ApplXcpPrint("\n");
  2476.               }
  2477.   #endif
  2478.  
  2479.               CheckResourceProtection( RM_CAL_PAG ) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2480.  
  2481.               err = XcpWriteMta(CRO_DOWNLOAD_MAX_MAX_SIZE,CRO_DOWNLOAD_MAX_DATA);
  2482.               if (err==(vuint8)XCP_CMD_PENDING)
  2483.               {
  2484.                 return;
  2485.               }
  2486.               if (err==(vuint8)XCP_CMD_DENIED)
  2487.               {
  2488.                 error(CRC_WRITE_PROTECTED) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2489.               }
  2490.               if (err==(vuint8)XCP_CMD_SYNTAX)
  2491.               {
  2492.                 error(CRC_CMD_SYNTAX) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2493.               }
  2494.  
  2495.   #if defined ( XCP_ENABLE_TESTMODE )
  2496.               if ( gDebugLevel != 0)
  2497.               {
  2498.                 ApplXcpPrint("<- 0xFF\n");
  2499.               }
  2500.   #endif
  2501. #else
  2502.               error(CRC_ACCESS_DENIED) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2503. #endif /* !defined ( XCP_ENABLE_CALIBRATION ) */
  2504.             }
  2505.             break;
  2506.  
  2507.  
  2508.  
  2509.           case CC_UPLOAD:
  2510.             {
  2511.               vuint8 size = CRO_UPLOAD_SIZE;
  2512.  
  2513. #if defined ( XCP_ENABLE_TESTMODE )
  2514.               if ( gDebugLevel != 0)
  2515.               {
  2516.                 ApplXcpPrint("-> UPLOAD size=%u\n",size);
  2517.               }
  2518. #endif
  2519.  
  2520.               if ( size > (vuint8)CRM_UPLOAD_MAX_SIZE )
  2521.               {
  2522.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2523.               }
  2524.               err = XcpReadMta(size,CRM_UPLOAD_DATA);
  2525.               xcp.CrmLen = (vuint8)((CRM_UPLOAD_LEN+size)&0xFFu);
  2526.               if (err==(vuint8)XCP_CMD_PENDING)
  2527.               {
  2528.                 goto no_response; /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2529.               }
  2530.               if (err==(vuint8)XCP_CMD_DENIED)
  2531.               {
  2532.                 error(CRC_ACCESS_DENIED) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2533.               }
  2534.  
  2535. #if defined ( XCP_ENABLE_TESTMODE )
  2536.               if ( gDebugLevel != 0)
  2537.               {
  2538.                 vuint16 i;
  2539.                 ApplXcpPrint("<- 0xFF data=");
  2540.                 for (i=0;i<size;i++)
  2541.                 {
  2542.                   ApplXcpPrint("%02X ",CRM_UPLOAD_DATA[i]);
  2543.                 }
  2544.                 ApplXcpPrint("\n");
  2545.               }
  2546. #endif
  2547.             }
  2548.             break;
  2549.  
  2550.           case CC_SHORT_UPLOAD:
  2551.             {
  2552. #if defined ( XCP_ENABLE_TESTMODE )
  2553.               if ( gDebugLevel != 0)
  2554.               {
  2555.                 ApplXcpPrint("-> SHORT_UPLOAD addr=%08Xh, addrext=%02Xh, size=%u\n",CRO_SHORT_UPLOAD_ADDR,CRO_SHORT_UPLOAD_EXT,CRO_SHORT_UPLOAD_SIZE);
  2556.               }
  2557. #endif
  2558.  
  2559. #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  2560.               if (CRO_SHORT_UPLOAD_SIZE > (vuint8)CRM_SHORT_UPLOAD_MAX_SIZE)
  2561.               {
  2562.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2563.               }
  2564. #endif
  2565.               XcpSetMta(ApplXcpGetPointer(CRO_SHORT_UPLOAD_EXT,CRO_SHORT_UPLOAD_ADDR),CRO_SHORT_UPLOAD_EXT);
  2566.               err = XcpReadMta(CRO_SHORT_UPLOAD_SIZE,CRM_SHORT_UPLOAD_DATA);
  2567.               xcp.CrmLen = (vuint8)((CRM_SHORT_UPLOAD_LEN+CRO_SHORT_UPLOAD_SIZE)&0xFFu);
  2568.               if (err==(vuint8)XCP_CMD_PENDING)
  2569.               {
  2570.                 goto no_response; /* ESCAN00014775 */ /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2571.               }
  2572.               if (err==(vuint8)XCP_CMD_DENIED)
  2573.               {
  2574.                 error(CRC_ACCESS_DENIED) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2575.               }
  2576.  
  2577. #if defined ( XCP_ENABLE_TESTMODE )
  2578.               if ( gDebugLevel != 0)
  2579.               {
  2580.                 vuint16 i;
  2581.                 ApplXcpPrint("<- 0xFF data=");
  2582.                 for (i=0; i < (vuint16)CRO_SHORT_UPLOAD_SIZE; i++)
  2583.                 {
  2584.                   ApplXcpPrint("%02X ",CRM_SHORT_UPLOAD_DATA[i]);
  2585.                 }
  2586.                 ApplXcpPrint("\n");
  2587.               }
  2588. #endif
  2589.             }
  2590.             break;
  2591.  
  2592.  
  2593. #if defined ( XCP_ENABLE_CHECKSUM )
  2594.  
  2595.           case CC_BUILD_CHECKSUM: /* Build Checksum */
  2596.             {
  2597.               vuint32 s;
  2598.  
  2599.   #if defined ( XCP_ENABLE_TESTMODE )
  2600.               if ( gDebugLevel != 0)
  2601.               {
  2602.                 ApplXcpPrint("-> BUILD_CHECKSUM size=%u\n",CRO_BUILD_CHECKSUM_SIZE);
  2603.               }
  2604.   #endif
  2605.               s = CRO_BUILD_CHECKSUM_SIZE;
  2606.  
  2607.   #if !defined ( XCP_ENABLE_CUSTOM_CRC )
  2608.               /* Initialization of checksum calculation. */
  2609.   #if ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_CRC16CCITT ) || \
  2610.       ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_CRC32 )
  2611.               xcp.CheckSum = (tXcpChecksumSumType)0xFFFFFFFFu;
  2612.   #else
  2613.               xcp.CheckSum = (tXcpChecksumSumType)0u;
  2614.   #endif
  2615.               /* The blocksize is limited to WORD length. */
  2616.               /* If the blocksize exceeds the allowed maximum transmit negative response. */
  2617.               if ( (s & (vuint32)0xffff0000u) != (vuint32)0u )
  2618.               {
  2619.                 CRM_BUILD_CHECKSUM_RESULT_WRITE(0xFFFFu); /* Range, max. 64K-1 */ /* PRQA S 3109 */ /* MD_MSR_14.3 */
  2620.                 err = CRC_OUT_OF_RANGE;
  2621.                 xcp.CrmLen = CRM_BUILD_CHECKSUM_LEN;
  2622.                 /* Response length is arbitrary */
  2623.                 goto negative_response1; /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2624.               }
  2625.               else
  2626.   #endif
  2627.               {
  2628.  
  2629.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  2630.                 /* Parameter check whether the block size is modulo 2 for ADD_22, ADD_24 */
  2631.                 /* and ADD_44 (modulo 4).                                                */
  2632.     #if ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_ADD22 ) || \
  2633.         ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_ADD24 ) || \
  2634.         ( kXcpChecksumMethod == XCP_CHECKSUM_TYPE_ADD44 )
  2635.                 if ( (s % (vuint32)sizeof(tXcpChecksumAddType)) != (vuint32)0u )
  2636.                 {
  2637.                   error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2638.                 }
  2639.                 else
  2640.     #endif
  2641.   #endif
  2642.                 {
  2643.  
  2644.   #if defined ( XCP_ENABLE_CUSTOM_CRC )
  2645.                   err = ApplXcpCalculateChecksum( xcp.Mta, xcp.Crm.b, s );
  2646.                   xcp.Mta += s;
  2647.                   if (err==(vuint8)XCP_CMD_PENDING)
  2648.                   {
  2649.                     goto no_response; /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2650.                   }
  2651.                   if (err!=(vuint8)XCP_CMD_OK)
  2652.                   {
  2653.                     error(CRC_CMD_UNKNOWN) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2654.                   }
  2655.   #else
  2656.                   xcp.CheckSumSize = (vuint16)s;
  2657.                   /* Checksum calculation will be performed by XcpBackground() */
  2658.                   goto no_response; /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2659.   #endif
  2660.                 }
  2661.               }
  2662.             }
  2663.   #if defined ( XCP_ENABLE_CUSTOM_CRC )
  2664.             break;
  2665.   #endif
  2666.  
  2667. #endif /* XCP_ENABLE_CHECKSUM */
  2668.  
  2669.  
  2670. #if defined ( XCP_ENABLE_DAQ )
  2671.  
  2672.   #if defined ( XCP_ENABLE_DAQ_PROCESSOR_INFO )
  2673.  
  2674.           case CC_GET_DAQ_PROCESSOR_INFO: /* PRQA S 2003 */ /* MD_Xcp_2003 */
  2675.             {
  2676.     #if defined ( XCP_ENABLE_TESTMODE )
  2677.               if ( gDebugLevel != 0)
  2678.               {
  2679.                 ApplXcpPrint("-> GET_DAQ_PROCESSOR_INFO\n");
  2680.               }
  2681.     #endif
  2682.  
  2683.               xcp.CrmLen = CRM_GET_DAQ_PROCESSOR_INFO_LEN;
  2684.               CRM_GET_DAQ_PROCESSOR_INFO_MIN_DAQ = 0;
  2685.               /* PRQA S 3757 1 */ /* MD_Xcp_3757 */
  2686.               CRM_GET_DAQ_PROCESSOR_INFO_MAX_DAQ_WRITE(xcp.Daq.DaqCount); /* dynamic or static */ /* PRQA S 3109 */ /* MD_MSR_14.3 */
  2687.     #if defined ( kXcpMaxEvent )
  2688.               CRM_GET_DAQ_PROCESSOR_INFO_MAX_EVENT_WRITE(kXcpMaxEvent); /* PRQA S 3109 */ /* MD_MSR_14.3 */
  2689.     #else
  2690.               CRM_GET_DAQ_PROCESSOR_INFO_MAX_EVENT_WRITE(0x00); /* Unknown */
  2691.     #endif
  2692.     #if defined ( XCP_ENABLE_DAQ_HDR_ODT_DAQ )
  2693.               /* DTO identification field type: Relative ODT number, absolute list number (BYTE) */
  2694.               CRM_GET_DAQ_PROCESSOR_INFO_DAQ_KEY_BYTE = (vuint8)DAQ_HDR_ODT_DAQB;
  2695.     #else
  2696.               /* DTO identification field type: Absolute ODT number */
  2697.               CRM_GET_DAQ_PROCESSOR_INFO_DAQ_KEY_BYTE = (vuint8)DAQ_HDR_PID;
  2698.     #endif
  2699.               CRM_GET_DAQ_PROCESSOR_INFO_PROPERTIES = (vuint8)( DAQ_PROPERTY_CONFIG_TYPE
  2700.     #if defined ( XCP_ENABLE_DAQ_TIMESTAMP )
  2701.                 | DAQ_PROPERTY_TIMESTAMP
  2702.     #endif
  2703.     #if defined ( XCP_ENABLE_DAQ_PRESCALER )
  2704.                 | DAQ_PROPERTY_PRESCALER
  2705.     #endif
  2706.     #if defined ( XCP_ENABLE_DAQ_OVERRUN_INDICATION ) /* DAQ_PROPERTY_OVERLOAD_INDICATION */
  2707.                 | DAQ_OVERLOAD_INDICATION_PID
  2708.     #endif
  2709.                 );
  2710.  
  2711.     #if defined ( XCP_ENABLE_TESTMODE )
  2712.               if ( gDebugLevel != 0)
  2713.               {
  2714.                 ApplXcpPrint("<- 0xFF\n");
  2715.               }
  2716.     #endif
  2717.             }
  2718.             break;
  2719.  
  2720.   #endif /* XCP_ENABLE_DAQ_PROCESSOR_INFO */
  2721.  
  2722.   #if defined ( XCP_ENABLE_DAQ_RESOLUTION_INFO )
  2723.  
  2724.             case CC_GET_DAQ_RESOLUTION_INFO: /* PRQA S 2003 */ /* MD_Xcp_2003 */
  2725.               {
  2726.     #if defined ( XCP_ENABLE_TESTMODE )
  2727.                 if ( gDebugLevel != 0)
  2728.                 {
  2729.                   ApplXcpPrint("-> GET_DAQ_RESOLUTION_INFO\n");
  2730.                 }
  2731.     #endif
  2732.  
  2733.                 xcp.CrmLen = CRM_GET_DAQ_RESOLUTION_INFO_LEN;
  2734.                 CRM_GET_DAQ_RESOLUTION_INFO_GRANULARITY_DAQ = 1;
  2735.                 CRM_GET_DAQ_RESOLUTION_INFO_GRANULARITY_STIM = 1;
  2736.                 CRM_GET_DAQ_RESOLUTION_INFO_MAX_SIZE_DAQ  = (vuint8)XCP_MAX_ODT_ENTRY_SIZE;
  2737.                 CRM_GET_DAQ_RESOLUTION_INFO_MAX_SIZE_STIM = (vuint8)XCP_MAX_ODT_ENTRY_SIZE;
  2738.     #if defined ( XCP_ENABLE_DAQ_TIMESTAMP )
  2739.                 CRM_GET_DAQ_RESOLUTION_INFO_TIMESTAMP_MODE = kXcpDaqTimestampUnit | (vuint8)kXcpDaqTimestampSize
  2740.       #if defined ( XCP_ENABLE_DAQ_TIMESTAMP_FIXED )
  2741.                 | DAQ_TIMESTAMP_FIXED
  2742.       #endif
  2743.                 ;
  2744.                 CRM_GET_DAQ_RESOLUTION_INFO_TIMESTAMP_TICKS_WRITE(kXcpDaqTimestampTicksPerUnit);  /* BCD coded */ /* PRQA S 3109 */ /* MD_MSR_14.3 */
  2745.     #else
  2746.                 CRM_GET_DAQ_RESOLUTION_INFO_TIMESTAMP_MODE = 0;
  2747.                 CRM_GET_DAQ_RESOLUTION_INFO_TIMESTAMP_TICKS_WRITE(0x00);
  2748.     #endif /* XCP_ENABLE_DAQ_TIMESTAMP */
  2749.  
  2750.     #if defined ( XCP_ENABLE_TESTMODE )
  2751.                 if ( gDebugLevel != 0)
  2752.                 {
  2753.                   ApplXcpPrint("<- 0xFF , mode=%02Xh, , ticks=%02Xh\n",CRM_GET_DAQ_RESOLUTION_INFO_TIMESTAMP_MODE,CRM_GET_DAQ_RESOLUTION_INFO_TIMESTAMP_TICKS);
  2754.                 }
  2755.     #endif
  2756.               }
  2757.               break;
  2758.   #endif /* XCP_ENABLE_DAQ_RESOLUTION_INFO */
  2759.  
  2760.   #if defined ( XCP_ENABLE_DAQ_EVENT_INFO ) && defined ( kXcpMaxEvent )
  2761.             case CC_GET_DAQ_EVENT_INFO: /* PRQA S 2003 */ /* MD_Xcp_2003 */
  2762.               {
  2763.                 vuint8 event = (vuint8)CRO_GET_DAQ_EVENT_INFO_EVENT;
  2764.  
  2765.     #if defined ( XCP_ENABLE_TESTMODE )
  2766.                 if ( gDebugLevel != 0)
  2767.                 {
  2768.                   ApplXcpPrint("-> GET_DAQ_EVENT_INFO event=%u\n",event);
  2769.                 }
  2770.     #endif
  2771.  
  2772.     #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  2773.                 if (event >= (vuint8)kXcpMaxEvent )
  2774.                 {
  2775.                   error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2776.                 }
  2777.     #endif
  2778.  
  2779.                 xcp.CrmLen = CRM_GET_DAQ_EVENT_INFO_LEN;
  2780.                 CRM_GET_DAQ_EVENT_INFO_PROPERTIES = kXcpEventDirection[event];
  2781.                 CRM_GET_DAQ_EVENT_INFO_MAX_DAQ_LIST = 1; /* Only one DAQ-List available per event channel */
  2782.                 CRM_GET_DAQ_EVENT_INFO_NAME_LENGTH = kXcpEventNameLength[event];
  2783.                 CRM_GET_DAQ_EVENT_INFO_TIME_CYCLE = kXcpEventCycle[event];
  2784.     #if defined ( XCP_ENABLE_CANAPE_5_5_X_SUPPORT )
  2785.                 CRM_GET_DAQ_EVENT_INFO_TIME_UNIT = kXcpEventUnit[event];
  2786.     #else
  2787.                 CRM_GET_DAQ_EVENT_INFO_TIME_UNIT = (vuint8)(kXcpEventUnit[event]); /* ESCAN00090639 */ //Originaly was ..kXcpEventUnit[event] >> 4); due to usage of DAQ_TIMESTAMP_UNITs wich are placed in a high nibble
  2788.     #endif
  2789.                 CRM_GET_DAQ_EVENT_INFO_PRIORITY = 0;     /* Event channel prioritization is not supported. */
  2790.                 XcpSetMta( (MTABYTEPTR)(kXcpEventName[event]), 0xFF ); /* PRQA S 0306 */ /* MD_Xcp_0306 */  // was < ApplXcpGetPointer( 0xFF, (vuint32)kXcpEventName[event]), 0xFF >
  2791.  
  2792.     #if defined ( XCP_ENABLE_TESTMODE )
  2793.                 if ( gDebugLevel != 0)
  2794.                 {
  2795.                   ApplXcpPrint("<- 0xFF name=%s, unit=%u, cycle=%u\n",kXcpEventName[event],CRM_GET_DAQ_EVENT_INFO_TIME_UNIT,CRM_GET_DAQ_EVENT_INFO_TIME_CYCLE);
  2796.                 }
  2797.     #endif
  2798.               }
  2799.               break;
  2800.   #endif /* XCP_ENABLE_DAQ_EVENT_INFO && kXcpMaxEvent */
  2801.  
  2802.  
  2803.           case CC_FREE_DAQ:
  2804.             {
  2805.   #if defined ( XCP_ENABLE_TESTMODE )
  2806.               if ( gDebugLevel != 0)
  2807.               {
  2808.                 ApplXcpPrint("-> FREE_DAQ\n");
  2809.               }
  2810.   #endif
  2811.  
  2812.               CheckResourceProtection( RM_DAQ ) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2813.  
  2814.               XcpFreeDaq();
  2815.  
  2816.   #if defined ( XCP_ENABLE_TESTMODE )
  2817.               if ( gDebugLevel != 0)
  2818.               {
  2819.                 ApplXcpPrint("<- 0xFF\n");
  2820.               }
  2821.   #endif
  2822.             }
  2823.             break;
  2824.  
  2825.           case CC_ALLOC_DAQ:
  2826.             {
  2827.               vuint8 count = (vuint8)CRO_ALLOC_DAQ_COUNT;
  2828.  
  2829.   #if defined ( XCP_ENABLE_TESTMODE )
  2830.               if ( gDebugLevel != 0)
  2831.               {
  2832.                 ApplXcpPrint("-> ALLOC_DAQ count=%u\n",count);
  2833.               }
  2834.   #endif
  2835.  
  2836.               check_error( XcpAllocDaq(count) ) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2837.  
  2838.   #if defined ( XCP_ENABLE_TESTMODE )
  2839.               if ( gDebugLevel != 0)
  2840.               {
  2841.                 ApplXcpPrint("<- 0xFF\n");
  2842.               }
  2843.   #endif
  2844.             }
  2845.             break;
  2846.  
  2847.           case CC_ALLOC_ODT:
  2848.             {
  2849.               vuint8 daq = (vuint8)CRO_ALLOC_ODT_DAQ;
  2850.               vuint8 count = CRO_ALLOC_ODT_COUNT;
  2851.  
  2852.   #if defined ( XCP_ENABLE_TESTMODE )
  2853.               if ( gDebugLevel != 0)
  2854.               {
  2855.                 ApplXcpPrint("-> ALLOC_ODT daq=%u, count=%u\n",daq,count);
  2856.               }
  2857.   #endif
  2858.  
  2859.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  2860.               if (daq>=xcp.Daq.DaqCount)
  2861.               {
  2862.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2863.               }
  2864.   #endif
  2865.  
  2866.               check_error( XcpAllocOdt(daq, count) ) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2867.  
  2868.   #if defined ( XCP_ENABLE_TESTMODE )
  2869.               if ( gDebugLevel != 0)
  2870.               {
  2871.                 ApplXcpPrint("<- 0xFF\n");
  2872.               }
  2873.   #endif
  2874.             }
  2875.             break;
  2876.  
  2877.           case CC_ALLOC_ODT_ENTRY:
  2878.             {
  2879.               vuint8 daq = (vuint8)CRO_ALLOC_ODT_ENTRY_DAQ;
  2880.               vuint8 odt = CRO_ALLOC_ODT_ENTRY_ODT;
  2881.               vuint8 count = CRO_ALLOC_ODT_ENTRY_COUNT;
  2882.  
  2883.   #if defined ( XCP_ENABLE_TESTMODE )
  2884.               if ( gDebugLevel != 0)
  2885.               {
  2886.                 ApplXcpPrint("-> ALLOC_ODT_ENTRY daq=%u, odt=%u, count=%u\n",daq,odt,count);
  2887.               }
  2888.   #endif
  2889.  
  2890.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  2891.               if ( (daq>=xcp.Daq.DaqCount) || (odt>=(vuint8)DaqListOdtCount(daq)) )
  2892.               {
  2893.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2894.               }
  2895.   #endif
  2896.  
  2897.               check_error( XcpAllocOdtEntry(daq, odt, count) ) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2898.  
  2899.   #if defined ( XCP_ENABLE_TESTMODE )
  2900.               if ( gDebugLevel != 0)
  2901.               {
  2902.                 ApplXcpPrint("<- 0xFF\n");
  2903.               }
  2904.   #endif
  2905.             }
  2906.             break;
  2907.  
  2908.           case CC_GET_DAQ_LIST_MODE:
  2909.             {
  2910.               vuint8 daq = (vuint8)CRO_GET_DAQ_LIST_MODE_DAQ;
  2911.  
  2912.   #if defined ( XCP_ENABLE_TESTMODE )
  2913.               if ( gDebugLevel != 0)
  2914.               {
  2915.                 ApplXcpPrint("-> GET_DAQ_LIST_MODE daq=%u\n",daq);
  2916.               }
  2917.   #endif
  2918.  
  2919.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  2920.               if (daq>=xcp.Daq.DaqCount)
  2921.               {
  2922.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2923.               }
  2924.   #endif
  2925.  
  2926.               xcp.CrmLen = CRM_GET_DAQ_LIST_MODE_LEN;
  2927.               CRM_GET_DAQ_LIST_MODE_MODE = DaqListFlags(daq);
  2928.   #if defined ( XCP_ENABLE_DAQ_PRESCALER )
  2929.               CRM_GET_DAQ_LIST_MODE_PRESCALER = DaqListPrescaler(daq);
  2930.   #else
  2931.               CRM_GET_DAQ_LIST_MODE_PRESCALER = 1;
  2932.   #endif
  2933.   #if defined ( kXcpMaxEvent )
  2934.               CRM_GET_DAQ_LIST_MODE_EVENTCHANNEL_WRITE(0); /* #### Lookup in EventDaq[] */ /* PRQA S 3109 */ /* MD_MSR_14.3 */
  2935.   #else
  2936.               CRM_GET_DAQ_LIST_MODE_EVENTCHANNEL_WRITE(DaqListEventChannel(daq));
  2937.   #endif
  2938.               CRM_GET_DAQ_LIST_MODE_PRIORITY = 0;  /* DAQ-list prioritization is not supported. */
  2939.  
  2940.   #if defined ( XCP_ENABLE_TESTMODE )
  2941.               if ( gDebugLevel != 0)
  2942.               {
  2943.                 ApplXcpPrint("<- 0xFF mode=%02X, prescaler=%u, eventChannel=%u, priority=%u, /*maxOdtEntrySize=%u*/  \n",
  2944.                   CRM_GET_DAQ_LIST_MODE_MODE,CRM_GET_DAQ_LIST_MODE_PRESCALER,CRM_GET_DAQ_LIST_MODE_EVENTCHANNEL,CRM_GET_DAQ_LIST_MODE_PRIORITY, XCP_MAX_ODT_ENTRY_SIZE);
  2945.               }
  2946.   #endif
  2947.             }
  2948.             break;
  2949.  
  2950.           case CC_SET_DAQ_LIST_MODE:
  2951.             {
  2952.               vuint8 daq = (vuint8)CRO_SET_DAQ_LIST_MODE_DAQ;
  2953.   #if defined ( XCP_ENABLE_TESTMODE ) || defined ( XCP_ENABLE_DAQ_PRESCALER ) || ( !defined ( XCP_ENABLE_DAQ_PRESCALER ) && defined ( XCP_ENABLE_PARAMETER_CHECK ) )
  2954.               vuint8 xcpPrescaler = CRO_SET_DAQ_LIST_MODE_PRESCALER;
  2955.   #endif
  2956.               vuint8 event = (vuint8)(CRO_SET_DAQ_LIST_MODE_EVENTCHANNEL&0xFFu);
  2957.  
  2958.   #if defined ( XCP_ENABLE_TESTMODE )
  2959.               if ( gDebugLevel != 0)
  2960.               {
  2961.                 ApplXcpPrint("-> SET_DAQ_LIST_MODE daq=%u, mode=%02Xh, prescaler=%u, eventchannel=%u\n",
  2962.                   daq,CRO_SET_DAQ_LIST_MODE_MODE,xcpPrescaler,event);
  2963.               }
  2964.   #endif
  2965.  
  2966.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  2967.               if (daq>=xcp.Daq.DaqCount)
  2968.               {
  2969.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2970.               }
  2971.     #if defined ( kXcpMaxEvent )
  2972.               if (event >= (vuint8)kXcpMaxEvent)
  2973.               {
  2974.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2975.               }
  2976.     #endif
  2977.     #if !defined ( XCP_ENABLE_DAQ_PRESCALER )
  2978.               if (xcpPrescaler!=1)
  2979.               {
  2980.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2981.               }
  2982.     #endif
  2983.               if (CRO_SET_DAQ_LIST_MODE_PRIORITY!=0)   /* Priorization is not supported */
  2984.               {
  2985.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  2986.               }
  2987.   #endif
  2988.  
  2989.   #if defined ( XCP_ENABLE_DAQ_PRESCALER )
  2990.               if (xcpPrescaler==0)
  2991.               {
  2992.                 xcpPrescaler = 1;
  2993.               }
  2994.               DaqListPrescaler(daq) = xcpPrescaler;
  2995.   #endif
  2996.   #if defined ( kXcpMaxEvent ) && ! defined ( XCP_ENABLE_DAQ_PRESCALER )
  2997.               xcp.Daq.EventDaq[event] = daq;
  2998.   #else
  2999.               DaqListEventChannel(daq) = event;
  3000.   #endif
  3001.               DaqListFlags(daq) = CRO_SET_DAQ_LIST_MODE_MODE;
  3002.  
  3003.  
  3004.   #if defined ( XCP_ENABLE_TESTMODE )
  3005.               if ( gDebugLevel != 0)
  3006.               {
  3007.                 ApplXcpPrint("<- 0xFF\n");
  3008.               }
  3009.   #endif
  3010.               break;
  3011.             }
  3012.  
  3013.  
  3014.           case CC_SET_DAQ_PTR:
  3015.             {
  3016.               vuint8 daq = (vuint8) (CRO_SET_DAQ_PTR_DAQ&0xFFu);
  3017.               vuint8 odt = CRO_SET_DAQ_PTR_ODT;
  3018.               vuint8 idx = CRO_SET_DAQ_PTR_IDX;
  3019.               tXcpOdtIdx odt0 = (tXcpOdtIdx)(DaqListFirstOdt(daq)+odt); /* Absolute odt number */
  3020.  
  3021.   #if defined ( XCP_ENABLE_TESTMODE )
  3022.               if ( gDebugLevel != 0)
  3023.               {
  3024.                 ApplXcpPrint("-> SET_DAQ_PTR daq=%u,odt=%u,idx=%u\n",daq,odt,idx);
  3025.               }
  3026.   #endif
  3027.  
  3028.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  3029.               if ( (daq>=xcp.Daq.DaqCount) || (odt>=(vuint8)DaqListOdtCount(daq)) || (idx>=(vuint8)DaqListOdtEntryCount(odt0)) )
  3030.               {
  3031.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3032.               }
  3033.   #endif
  3034.  
  3035.               xcp.CrmLen = CRM_SET_DAQ_PTR_LEN;
  3036.               xcp.DaqListPtr = DaqListOdtFirstEntry(odt0)+idx;
  3037.   #if defined ( XCP_ENABLE_TESTMODE )
  3038.               if ( gDebugLevel != 0)
  3039.               {
  3040.                 ApplXcpPrint("<- 0xFF \n");
  3041.               }
  3042.   #endif
  3043.             }
  3044.             break;
  3045.  
  3046.           case CC_WRITE_DAQ: /* Write DAQ entry */
  3047.             {
  3048.               DAQBYTEPTR addr;
  3049.   #if defined ( XCP_ENABLE_TESTMODE )
  3050.               if ( gDebugLevel != 0)
  3051.               {
  3052.                 ApplXcpPrint("-> WRITE_DAQ size=%u,addr=%08Xh,%02Xh\n",CRO_WRITE_DAQ_SIZE,CRO_WRITE_DAQ_ADDR,CRO_WRITE_DAQ_EXT);
  3053.               }
  3054.   #endif
  3055.  
  3056.               CheckResourceProtection( RM_DAQ ) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3057.  
  3058.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  3059.               if ( ((vuint8)CRO_WRITE_DAQ_SIZE==(vuint8)0u ) || (CRO_WRITE_DAQ_SIZE > (vuint8)XCP_MAX_ODT_ENTRY_SIZE) )
  3060.               {
  3061.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3062.               }
  3063.               if ( (0u == xcp.Daq.DaqCount) || (0u == xcp.Daq.OdtCount) || (0u == xcp.Daq.OdtEntryCount) )
  3064.               {
  3065.                 error(CRC_DAQ_CONDIF) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3066.               }
  3067.   #endif
  3068.               addr = (DAQBYTEPTR)ApplXcpGetPointer(CRO_WRITE_DAQ_EXT,CRO_WRITE_DAQ_ADDR);
  3069.  
  3070.               xcp.CrmLen = CRM_WRITE_DAQ_LEN;
  3071.               OdtEntrySize(xcp.DaqListPtr) = CRO_WRITE_DAQ_SIZE;
  3072.               OdtEntryAddr(xcp.DaqListPtr) = addr;
  3073.  
  3074.               xcp.DaqListPtr++; /* Autoincrement */
  3075.  
  3076.   #if defined ( XCP_ENABLE_TESTMODE )
  3077.               if ( gDebugLevel != 0)
  3078.               {
  3079.                 ApplXcpPrint("<- 0xFF\n");
  3080.               }
  3081.   #endif
  3082.             }
  3083.             break;
  3084.  
  3085.           case CC_START_STOP_DAQ_LIST:
  3086.             {
  3087.               vuint8 daq = (vuint8)(CRO_START_STOP_DAQ&0xFFu);
  3088.  
  3089.               CheckResourceProtection( RM_DAQ ) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3090.  
  3091.   #if defined ( XCP_ENABLE_PARAMETER_CHECK )
  3092.               if (daq>=xcp.Daq.DaqCount)
  3093.               {
  3094.                 error(CRC_OUT_OF_RANGE) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3095.               }
  3096.   #endif
  3097.  
  3098.               if ( (CRO_START_STOP_MODE==1 ) || (CRO_START_STOP_MODE==2) )
  3099.               {
  3100.                 DaqListFlags(daq) |= (vuint8)DAQ_FLAG_SELECTED;
  3101.   #if defined ( XCP_ENABLE_TESTMODE )
  3102.                   if ( gDebugLevel != 0)
  3103.                   {
  3104.                     XcpPrintDaqList((vuint8)(CRO_START_STOP_DAQ)&0xFFu);
  3105.                     ApplXcpPrint("-> START_STOP mode=%02Xh, daq=%u\n",CRO_START_STOP_MODE,CRO_START_STOP_DAQ);
  3106.                   }
  3107.   #endif
  3108.                 if ( CRO_START_STOP_MODE == (vuint8)1u )
  3109.                 {
  3110.                   XcpStartDaq(daq);
  3111.                 }
  3112.                 xcp.CrmLen = CRM_START_STOP_LEN;
  3113.                 CRM_START_STOP_FIRST_PID = DaqListFirstPid(daq);
  3114.               }
  3115.               else
  3116.               {
  3117.                 XcpStopDaq(daq);
  3118.   #if defined ( XCP_ENABLE_TESTMODE )
  3119.                 if ( gDebugLevel != 0)
  3120.                 {
  3121.                   ApplXcpPrint("-> START_STOP mode=%02Xh\n",CRO_START_STOP_MODE);
  3122.                 }
  3123.   #endif
  3124.               }
  3125.  
  3126.   #if defined ( XCP_ENABLE_TESTMODE )
  3127.               if ( gDebugLevel != 0)
  3128.               {
  3129.                 ApplXcpPrint("<- 0xFF\n");
  3130.               }
  3131.   #endif
  3132.             }
  3133.             break;
  3134.  
  3135.           case CC_START_STOP_SYNCH:
  3136.             {
  3137.   #if defined ( XCP_ENABLE_TESTMODE )
  3138.               if ( gDebugLevel != 0)
  3139.               {
  3140.                 ApplXcpPrint("-> CC_START_STOP_SYNCH mode=%02Xh\n",CRO_START_STOP_MODE);
  3141.               }
  3142.   #endif
  3143.  
  3144.               CheckResourceProtection( RM_DAQ ) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3145.  
  3146.               if( (0 == xcp.Daq.DaqCount) || (0 == xcp.Daq.OdtCount) || (0 == xcp.Daq.OdtEntryCount) )
  3147.               {
  3148.                 error(CRC_DAQ_CONDIF) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3149.               }
  3150.  
  3151.               if (CRO_START_STOP_MODE==2) /* stop selected */
  3152.               {
  3153.                 XcpStopAllSelectedDaq();
  3154.               }
  3155.               else
  3156.               {
  3157.                 if (CRO_START_STOP_MODE==1) /* start selected */
  3158.                 {
  3159.                   XcpStartAllSelectedDaq();
  3160.                 }
  3161.                 else
  3162.                 {
  3163.                   /* CRO_START_STOP_MODE==0 : stop all */
  3164.                   XcpStopAllDaq();
  3165.                 }
  3166.               }
  3167.   #if defined ( XCP_ENABLE_TESTMODE )
  3168.               if ( gDebugLevel != 0)
  3169.               {
  3170.                 ApplXcpPrint("<- 0xFF\n");
  3171.               }
  3172.   #endif
  3173.             }
  3174.             break;
  3175.  
  3176.   #if defined ( XCP_ENABLE_DAQ_TIMESTAMP )
  3177.           case CC_GET_DAQ_CLOCK:
  3178.             {
  3179.               xcp.CrmLen = CRM_GET_DAQ_CLOCK_LEN;
  3180.               /* PRQA S 3757 1 */ /* MD_Xcp_3757 */
  3181.               CRM_GET_DAQ_CLOCK_TIME_WRITE((vuint32)ApplXcpGetTimestamp()); /* PRQA S 3109 */ /* MD_MSR_14.3 */
  3182.  
  3183.     #if defined ( XCP_ENABLE_TESTMODE )
  3184.               if ( gDebugLevel != 0)
  3185.               {
  3186.                 ApplXcpPrint("-> GET_DAQ_CLOCK\n");
  3187.                 ApplXcpPrint("<- 0xFF time=%04Xh\n",CRM_GET_DAQ_CLOCK_TIME);
  3188.               }
  3189.     #endif
  3190.             }
  3191.             break;
  3192.   #endif
  3193.  
  3194. #endif /* XCP_ENABLE_DAQ */
  3195.  
  3196.  
  3197.           /* Flash Programming Kernel Download */
  3198.  
  3199.  
  3200.            /* Flash Programming direct and Kernel */
  3201.  
  3202.           /* Flash Programming  */
  3203.  
  3204.  
  3205. #if defined ( XCP_ENABLE_USER_COMMAND )
  3206.           case CC_USER_CMD:
  3207.             {
  3208.  
  3209.   #if defined ( XCP_ENABLE_TESTMODE )
  3210.               if ( gDebugLevel != 0)
  3211.               {
  3212.                 ApplXcpPrint("-> CC_USER_CMD cmd=%u\n", CRO_BYTE(1));
  3213.               }
  3214.   #endif
  3215.  
  3216.               {
  3217.  
  3218.   #if defined ( XCP_ENABLE_USER_COMMAND )
  3219.                 err = ApplXcpUserService( (const BYTEPTR) &CRO_BYTE(0) );
  3220.  
  3221.                 if (err==(vuint8)XCP_CMD_PENDING)
  3222.                 {
  3223.                   goto no_response;  /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3224.                 }
  3225.                 if (err==(vuint8)XCP_CMD_SYNTAX)
  3226.                 {
  3227.                   error(CRC_CMD_SYNTAX) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3228.                 }
  3229.   #endif
  3230.               }
  3231.  
  3232.   #if defined ( XCP_ENABLE_TESTMODE )
  3233.               if ( gDebugLevel != 0)
  3234.               {
  3235.                 ApplXcpPrint("<- 0xFF\n");
  3236.               }
  3237.   #endif
  3238.  
  3239.             }
  3240.             break;
  3241. #endif
  3242.  
  3243.  
  3244.  
  3245.  
  3246.           default: /* unknown */
  3247.             {
  3248.   #if defined ( XCP_ENABLE_TESTMODE )
  3249.               if ( gDebugLevel != 0)
  3250.               {
  3251.                 ApplXcpPrint("-> UNKNOWN COMMAND %02X\n", CRO_CMD);
  3252.               }
  3253.   #endif
  3254.               error(CRC_CMD_UNKNOWN) /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3255.             }
  3256.  
  3257.       } /* switch */
  3258.  
  3259.       goto positive_response; /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3260.     }
  3261.  
  3262.     /* Not connected */
  3263.     else
  3264.     {
  3265.       goto no_response; /* PRQA S 2001 */ /* MD_Xcp_2001 */
  3266.     }
  3267.   } /* CC_CONNECT */
  3268.  
  3269. negative_response:
  3270.   xcp.CrmLen = 2;
  3271.  
  3272. #if defined ( XCP_ENABLE_CHECKSUM )
  3273. negative_response1:
  3274. #endif
  3275.   CRM_CMD = (vuint8)PID_ERR;
  3276.   CRM_ERR = (vuint8)err;
  3277. #if defined ( XCP_ENABLE_TESTMODE )
  3278.   if ( gDebugLevel != 0)
  3279.   {
  3280.     ApplXcpPrint("<- 0xFE error=%02Xh\n",err);
  3281.   }
  3282. #endif
  3283.  
  3284. positive_response:
  3285.   XcpSendCrm();
  3286.  
  3287. no_response:
  3288.   END_PROFILE(1); /* Timingtest */
  3289.   return;
  3290.   /* PRQA S 2006 5 */ /* MD_MSR_14.7 */
  3291.   /* PRQA S 6010 4 */ /* MD_MSR_STPTH */
  3292.   /* PRQA S 6030 3 */ /* MD_MSR_STCYC */
  3293.   /* PRQA S 6050 2 */ /* MD_MSR_STCAL */
  3294.   /* PRQA S 6080 1 */ /* MD_MSR_STMIF */
  3295. }
  3296.  
  3297.  
  3298. /****************************************************************************/
  3299. /* Send notification callback                                               */
  3300. /****************************************************************************/
  3301.  
  3302.  
  3303. /*****************************************************************************
  3304. | NAME:             XcpSendCallBack
  3305. | CALLED BY:        XCP Transport Layer
  3306. | PRECONDITIONS:    none
  3307. | INPUT PARAMETERS: none
  3308. | RETURN VALUES:    0 : if the XCP Protocol Layer is idle (no transmit messages are pending)
  3309. | DESCRIPTION:      Notifies the XCP Protocol Layer about the successful
  3310. |                   transmission of a XCP packet.
  3311. ******************************************************************************/
  3312. vuint8 XcpSendCallBack( void )
  3313. {
  3314.   BEGIN_PROFILE(2); /* Timingtest */
  3315.  
  3316.   /* Activation control */
  3317.   XcpPlCheckControlStateRet((vuint8)1u)
  3318.  
  3319. #if defined ( XCP_ENABLE_DAQ ) && defined ( XCP_ENABLE_SEND_QUEUE )
  3320.  
  3321.   /* Clear all pending flags */
  3322.   /* A pending flag indicates that ApplXcpSend() is in progress */
  3323.   xcp.SendStatus &= (vuint8)(~XCP_SEND_PENDING & 0xFFu);
  3324.  
  3325.   /* Now check if there is another transmit request */
  3326.  
  3327.   /* Send a RES or ERR (CRM) message */
  3328.   if ( (xcp.SendStatus & (vuint8)XCP_CRM_REQUEST) != 0 )
  3329.   {
  3330.     xcp.SendStatus &= (vuint8)(~XCP_CRM_REQUEST & 0xFFu);
  3331.     XcpSendCrm();
  3332.     END_PROFILE(2); /* Timingtest */
  3333.     return (vuint8)0x01u;
  3334.   }
  3335.  
  3336.   /* Send a EV or SERV message */
  3337.   #if defined ( XCP_ENABLE_SEND_EVENT ) || defined ( XCP_ENABLE_SERV_TEXT )
  3338.   if ( (xcp.SendStatus & (vuint8)XCP_EVT_REQUEST) != 0 )
  3339.   {
  3340.     xcp.SendStatus &= (vuint8)(~XCP_EVT_REQUEST & 0xFFu);
  3341.     XcpSendEv();
  3342.     END_PROFILE(2); /* Timingtest */
  3343.     return (vuint8)0x01u;
  3344.   }
  3345.   #endif
  3346.  
  3347.   /* Send a DAQ message from the queue or from the buffer */
  3348.   if ( (xcp.SessionStatus & (SessionStatusType)SS_DAQ) != 0 )
  3349.   {
  3350.     if ( XcpSendDtoFromQueue() != 0 )
  3351.     {
  3352.       END_PROFILE(2); /* Timingtest */
  3353.       return (vuint8)0x01u;
  3354.     }
  3355.   }
  3356. #endif /* XCP_ENABLE_DAQ && XCP_ENABLE_SEND_QUEUE */
  3357.  
  3358.   /* Continue a pending block upload command */
  3359.  
  3360.   END_PROFILE(2); /* Timingtest */
  3361.   return (vuint8)0x00u;
  3362.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  3363. }
  3364.  
  3365.  
  3366. /****************************************************************************/
  3367. /* Initialization / de-initialization                                       */
  3368. /****************************************************************************/
  3369.  
  3370.  
  3371. /*****************************************************************************
  3372. | NAME:             XcpInit
  3373. | CALLED BY:        application
  3374. | PRECONDITIONS:    the data link layer has to be initialized.
  3375. | INPUT PARAMETERS: none
  3376. | RETURN VALUES:    none
  3377. | DESCRIPTION:      Initialization of the XCP Protocol Layer
  3378. |                   Application specific initialization
  3379. |                    ( e.g. Vector XCP on CAN Transport Layer )
  3380. ******************************************************************************/
  3381. void XcpInit( void )
  3382. {
  3383. #if defined ( XCP_ENABLE_TESTMODE )
  3384.   gDebugLevel = 1;
  3385. #endif
  3386.  
  3387.   /* Application specific initialization function. */
  3388.   ApplXcpInit();
  3389.  
  3390.   /* Initialize all XCP variables to zero */
  3391.   XcpMemClr((BYTEPTR)&xcp,(vuint16)sizeof(xcp)); /* PRQA S 0310 */ /* MD_Xcp_0310_ByteCopy */
  3392.  
  3393.   /* We set 8 bytes as default for CAN */
  3394.   XcpSetActiveTl(8, 8, 0);
  3395.  
  3396.   /* Initialize the RAM interface */
  3397.  
  3398.   /* Initialize the session status (ESCAN00013899) */
  3399.   xcp.SessionStatus = (SessionStatusType)0u;
  3400.  
  3401.   #if defined ( XCP_ENABLE_SEND_QUEUE)
  3402.   /* Initialize the transmit queue (ESCAN00013899) */
  3403.   xcp.SendStatus = (vuint8)0u;
  3404.   #endif
  3405.  
  3406.   /* Resume DAQ */
  3407. #if defined ( XCP_ENABLE_DAQ )
  3408. #endif /* XCP_ENABLE_DAQ */
  3409. }
  3410.  
  3411. /*****************************************************************************
  3412. | NAME:             XcpExit
  3413. | CALLED BY:        application
  3414. | PRECONDITIONS:    The XCP Protocol Layer has to be initialized.
  3415. | INPUT PARAMETERS: none
  3416. | RETURN VALUES:    none
  3417. | DESCRIPTION:      De-initialization of the XCP Protocol Layer.
  3418. ******************************************************************************/
  3419. void XcpExit( void )
  3420. {
  3421.   /* Activation control */
  3422.   XcpPlCheckControlState()
  3423.  
  3424.   /* Deinitialize the RAM interface */
  3425.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  3426. }
  3427.  
  3428.  
  3429. /****************************************************************************/
  3430. /* Print via SERV/SERV_TEXT                                                */
  3431. /****************************************************************************/
  3432.  
  3433.  
  3434. #if defined ( XCP_ENABLE_SERV_TEXT )
  3435.   #if defined ( XCP_ENABLE_SERV_TEXT_PUTCHAR )
  3436.  
  3437. /*****************************************************************************
  3438. | NAME:             XcpPutChar
  3439. | CALLED BY:        application, XcpPrint
  3440. | PRECONDITIONS:    XCP is initialized and in connected state.
  3441. | INPUT PARAMETERS: c : character
  3442. | RETURN VALUES:    none
  3443. | DESCRIPTION:      Put a char into a service request packet (SERV).
  3444. ******************************************************************************/
  3445. void XcpPutchar( const vuint8 c )
  3446. {
  3447.   /* Activation control */
  3448.   XcpPlCheckControlState()
  3449.  
  3450.   /* Check for stall condition */
  3451.     #if defined ( XCP_ENABLE_SEND_QUEUE )
  3452.  
  3453.   while ( (xcp.SendStatus & (vuint8)XCP_EVT_REQUEST) != 0 )
  3454.   {
  3455.     if ( ApplXcpSendStall() == 0 )
  3456.     {
  3457.       return; /* Abort */
  3458.     }
  3459.   }
  3460.  
  3461.     #endif
  3462.  
  3463.   /* If xcp.EvLen!=0 there is a pending text message*/
  3464.   if (xcp.EvLen<2)
  3465.   {
  3466.     xcp.EvLen = 2;
  3467.   }
  3468.  
  3469.   xcp.Ev.b[xcp.EvLen] = c;
  3470.   xcp.EvLen++;
  3471.  
  3472.   if ( (xcp.EvLen>=(vuint8)kXcpMaxCTO) || (c==(vuint8)0x00u) )  /* Flush */
  3473.   {
  3474.     EV_BYTE(0) = 0xFC; /* SERV */
  3475.     EV_BYTE(1) = 0x01; /* SERV_TEXT*/
  3476.     XcpSendEv();
  3477.   }
  3478.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  3479. }
  3480.  
  3481.     #if defined ( XCP_ENABLE_SERV_TEXT_PRINT )
  3482.  
  3483. /*****************************************************************************
  3484. | NAME:             XcpPrint
  3485. | CALLED BY:        application
  3486. | PRECONDITIONS:    XCP is initialized and in connected state.
  3487. | INPUT PARAMETERS: *str : pointer to a string
  3488. | RETURN VALUES:    none
  3489. | DESCRIPTION:      Transmission of a service request packet (SERV).
  3490. ******************************************************************************/
  3491. void XcpPrint( const vuint8 *str )
  3492. {
  3493.   /* Activation control */
  3494.   XcpPlCheckControlState()
  3495.  
  3496.   /* Transmit the text message. */
  3497.   while ( *str != 0x00 )
  3498.   {
  3499.     XcpPutchar(*str);
  3500.     str++; /* PRQA S 0489 */ /* MD_Xcp_0489 */
  3501.   }
  3502.   /* Transmit the terminating 0x00. */
  3503.   XcpPutchar( (vuint8)0x00u );
  3504.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  3505. }
  3506.  
  3507.     #endif
  3508.     #if defined ( XCP_ENABLE_SERV_TEXT_PRINTF )
  3509.  
  3510. /*****************************************************************************
  3511. | NAME:             XcpPrintf
  3512. | CALLED BY:        application
  3513. | PRECONDITIONS:    none
  3514. | INPUT PARAMETERS: *str : pointer to a string
  3515. |                   ...  : varaibale number of parameters (see printf)
  3516. | RETURN VALUES:    none
  3517. | DESCRIPTION:      Printf into a SERV_TEXT message
  3518. ******************************************************************************/
  3519. void XcpPrintf( const vuint8 *str, ... )
  3520. {
  3521.   va_list argptr;
  3522.   vuint8 buf[128];
  3523.  
  3524.   /* Activation control */
  3525.   XcpPlCheckControlState()
  3526.  
  3527.   va_start(argptr,str);
  3528.   vsprintf((vsint8*)buf,( const vsint8*)str,argptr );
  3529.   va_end(argptr);
  3530.  
  3531.   /* Transmit the text message*/
  3532.   {
  3533.     vuint8 *p = buf;
  3534.     while (*p != 0)
  3535.     {
  3536.       XcpPutchar(*p);
  3537.       p++; /* PRQA S 0489 */ /* MD_Xcp_0489 */
  3538.     }
  3539.   }
  3540.   /* Transmit the terminating 0x00. */
  3541.   XcpPutchar( 0x00 );
  3542. }
  3543.  
  3544.     #endif /* XCP_ENABLE_SERV_TEXT_PRINTF */
  3545.   #endif /* XCP_ENABLE_SERV_TEXT_PUTCHAR */
  3546. #endif /* XCP_ENABLE_SERV_TEXT */
  3547.  
  3548.  
  3549. #if defined ( XCP_ENABLE_SEND_EVENT )
  3550.  
  3551. /*****************************************************************************
  3552. | NAME:             XcpSendEvent
  3553. | CALLED BY:        application
  3554. | PRECONDITIONS:    none
  3555. | INPUT PARAMETERS: evc : event code
  3556. |                   c   : pointer to event data
  3557. |                   len : event data length
  3558. | RETURN VALUES:    none
  3559. | DESCRIPTION:      Transmission of an event packet (EV).
  3560. ******************************************************************************/
  3561. void XcpSendEvent( vuint8 evc, const BYTEPTR c, vuint8 len)
  3562. {
  3563.   vuint8 i;
  3564.  
  3565.   /* Activation control */
  3566.   XcpPlCheckControlState()
  3567.  
  3568.   /* Check for stall condition */
  3569. #if defined ( XCP_ENABLE_SEND_QUEUE )
  3570.   while ( (xcp.SendStatus & (vuint8)XCP_EVT_REQUEST) != (vuint8)0u )
  3571.   {
  3572.     if (!ApplXcpSendStall())
  3573.     {
  3574.       return; /* Abort */
  3575.     }
  3576.   }
  3577. #endif
  3578.  
  3579.   EV_BYTE(0)  = PID_EV; /* Event*/
  3580.   EV_BYTE(1)  = evc;  /* Event Code*/
  3581.   xcp.EvLen   = 2;
  3582.  
  3583.   if (len <= (vuint8)(kXcpMaxCTO-2) )
  3584.   {
  3585.     if (c != 0x00u)
  3586.     {
  3587.       for (i = 0; i < len; i++)
  3588.       {
  3589.         xcp.Ev.b[xcp.EvLen]       = c[i];
  3590.         xcp.EvLen++;
  3591.       }
  3592.     }
  3593.     else
  3594.     {
  3595.       xcp.EvLen += len;
  3596.     }
  3597.   }
  3598.  
  3599. #if defined ( XCP_ENABLE_TESTMODE )
  3600.   if ( gDebugLevel != 0)
  3601.   {
  3602.     ApplXcpPrint("[XcpSendEvent]");
  3603.     for (i = 0; i < xcp.EvLen; i++)
  3604.     {
  3605.       ApplXcpPrint(" %02x",xcp.Ev.b[i]);
  3606.     }
  3607.     ApplXcpPrint("\n");
  3608.   }
  3609. #endif
  3610.  
  3611.   XcpSendEv();
  3612.   /* PRQA S 2006 1 */ /* MD_MSR_14.7 */
  3613. }
  3614.  
  3615. #endif /* XCP_ENABLE_SEND_EVENT */
  3616.  
  3617. #if defined ( XCP_ENABLE_GET_CONNECTION_STATE ) || defined ( XCP_ENABLE_GET_SESSION_STATUS_API )
  3618. /*****************************************************************************
  3619. | NAME:             XcpGetState
  3620. | CALLED BY:        XcpPreCopy
  3621. | PRECONDITIONS:    none
  3622. | INPUT PARAMETERS: none
  3623. | RETURN VALUES:    XCP_CONNECTED    : XCP is connected
  3624. |                   XCP_DISCONNECTED : XCP is disconnected
  3625. | DESCRIPTION:      Get the connection state of the XCP Protocol Layer
  3626. ******************************************************************************/
  3627. vuint8 XcpGetState( void )
  3628. {
  3629.   return ((xcp.SessionStatus & (SessionStatusType)SS_CONNECTED) > 0u) ? XCP_CONNECTED : XCP_DISCONNECTED;
  3630. }
  3631. #endif
  3632.  
  3633. #if defined ( XCP_ENABLE_GET_SESSION_STATUS_API )
  3634. /*****************************************************************************
  3635. | NAME:             XcpGetSessionStatus
  3636. | CALLED BY:        -
  3637. | PRECONDITIONS:    none
  3638. | INPUT PARAMETERS: none
  3639. | RETURN VALUES:    Xcp session state
  3640. | DESCRIPTION:      Get the session state of the XCP Protocol Layer
  3641. ******************************************************************************/
  3642. SessionStatusType XcpGetSessionStatus( void )
  3643. {
  3644.   SessionStatusType result;
  3645.  
  3646.   result = xcp.SessionStatus;
  3647.   /* Reset the polling state */
  3648.   xcp.SessionStatus &= (SessionStatusType)(~SS_POLLING);
  3649.   return(result);
  3650. } /* PRQA S 2006 */ /* MD_MSR_14.7 */
  3651. #endif
  3652.  
  3653.  
  3654. #if defined ( XCP_ENABLE_GET_XCP_DATA_POINTER )
  3655. /*****************************************************************************
  3656. | NAME:             XcpGetXcpDataPointer
  3657. | CALLED BY:        Application
  3658. | PRECONDITIONS:    none
  3659. | INPUT PARAMETERS: tXcpData ** pXcpData: Pointer to Pointer that is set to xcp
  3660. | RETURN VALUES:    none
  3661. | DESCRIPTION:      Get the pointer to the internal xcp structure
  3662. ******************************************************************************/
  3663. void XcpGetXcpDataPointer( RAM tXcpData ** pXcpData )
  3664. {
  3665.   *pXcpData = &xcp;
  3666. }
  3667. #endif
  3668.  
  3669.  
  3670. #if defined ( XCP_ENABLE_VERSION_INFO_API )
  3671. /**************************************************************************************************
  3672.    Function name    : XcpGetVersionInfo
  3673.    ------------------------------------------------------------------------------------------------
  3674.    Description      : Returns version information of module
  3675.    ------------------------------------------------------------------------------------------------
  3676.    Called by        : -
  3677.    ------------------------------------------------------------------------------------------------
  3678.    Parameter        : Pointer to location at which version information shall be stored at
  3679.    ------------------------------------------------------------------------------------------------
  3680.    Returncode       : void
  3681.    ------------------------------------------------------------------------------------------------
  3682.    Misc             : -
  3683. **************************************************************************************************/
  3684. void XcpGetVersionInfo(Std_VersionInfoType *XcpVerInfoPtr)
  3685. {
  3686.   /* Since this service only access non-volatile data and no channel parameter is passed,
  3687.      checking of the channel handle and initialization is omitted. */
  3688.   XcpVerInfoPtr->vendorID = XCP_VENDOR_ID;
  3689.   XcpVerInfoPtr->moduleID = XCP_MODULE_ID;
  3690.   XcpVerInfoPtr->sw_major_version = (CP_XCP_VERSION >> 8u);
  3691.   XcpVerInfoPtr->sw_minor_version = (CP_XCP_VERSION & 0xff);
  3692.   XcpVerInfoPtr->sw_patch_version = CP_XCP_RELEASE_VERSION;
  3693. }
  3694. #endif /* XCP_ENABLE_VERSION_INFO_API */
  3695.  
  3696.  
  3697. /****************************************************************************/
  3698. /* Test                                                                     */
  3699. /* Some screen output functions for test and diagnostics                    */
  3700. /****************************************************************************/
  3701.  
  3702.  
  3703. #if defined ( XCP_ENABLE_TESTMODE )
  3704.   #if defined ( XCP_ENABLE_DAQ )
  3705.  
  3706. /*****************************************************************************
  3707. | NAME:             XcpPrintDaqList
  3708. | CALLED BY:
  3709. | PRECONDITIONS:    none
  3710. | INPUT PARAMETERS:
  3711. | RETURN VALUES:    none
  3712. | DESCRIPTION:      Print all DAQ lists to screen
  3713. ******************************************************************************/
  3714. void XcpPrintDaqList( vuint8 daq )
  3715. {
  3716.   vuint8 i;
  3717.   vuint16 e;
  3718.  
  3719.   /* Activation control */
  3720.   XcpPlCheckControlState()
  3721.  
  3722.   if (daq>=xcp.Daq.DaqCount)
  3723.   {
  3724.     return;
  3725.   }
  3726.  
  3727.   ApplXcpPrint("DAQ %u:\n",daq);
  3728.     #if defined ( kXcpMaxEvent ) && ! defined ( XCP_ENABLE_DAQ_PRESCALER )
  3729.   for (i=0;i<kXcpMaxEvent;i++)
  3730.   {
  3731.     if (xcp.Daq.EventDaq[i]==daq)
  3732.     {
  3733.       ApplXcpPrint(" eventchannel=%04Xh,",i);
  3734.     }
  3735.   }
  3736.     #else
  3737.   ApplXcpPrint(" eventchannel=%04Xh,",DaqListEventChannel(daq));
  3738.     #endif
  3739.     #if defined (XCP_ENABLE_DAQ_PRESCALER )
  3740.   ApplXcpPrint(" prescaler=%u,",DaqListPrescaler(daq));
  3741.     #endif
  3742.   ApplXcpPrint(" firstOdt=%u,",DaqListFirstOdt(daq));
  3743.   ApplXcpPrint(" lastOdt=%u,",DaqListLastOdt(daq));
  3744.   ApplXcpPrint(" flags=%02Xh\n",DaqListFlags(daq));
  3745.   ApplXcpPrint(" firstPid=%02Xh\n",DaqListFirstPid(daq));
  3746.   for (i=DaqListFirstOdt(daq);i<=DaqListLastOdt(daq);i++)
  3747.   {
  3748.     ApplXcpPrint("  ODT %u (%u):\n",i-DaqListFirstOdt(daq),i);
  3749.     ApplXcpPrint("   pid=%u:\n",i);
  3750.     ApplXcpPrint("   firstOdtEntry=%u,lastOdtEntry=%u:\n",DaqListOdtFirstEntry(i),DaqListOdtLastEntry(i));
  3751.     for (e=DaqListOdtFirstEntry(i);e<=DaqListOdtLastEntry(i);e++)
  3752.     {
  3753.       ApplXcpPrint("   [%08Xh,%u]\n",OdtEntryAddr(e),OdtEntrySize(e));
  3754.     }
  3755.   } /* j */
  3756. } /* Deviation of MISRA rule 82 (more than one return path). */
  3757.  
  3758.   #endif /* XCP_ENABLE_DAQ */
  3759. #endif /* XCP_ENABLE_TESTMODE */
  3760.  
  3761.  
  3762.  
  3763. /*******************************************************************************
  3764.   Consistency checks
  3765. *******************************************************************************/
  3766.  
  3767. /* Check definition of endianess of CPU */
  3768.  
  3769. #if defined ( XCP_CPUTYPE_LITTLEENDIAN ) || defined ( XCP_CPUTYPE_BIGENDIAN )
  3770. #else
  3771.   #error "Please define XCP_CPUTYPE_LITTLEENDIAN or XCP_CPUTYPE_BIGENDIAN."
  3772. #endif
  3773.  
  3774. /* Check consistency of alignment switch */
  3775.  
  3776. #if defined ( XCP_DISABLE_UNALIGNED_MEM_ACCESS )
  3777.     #if defined ( C_CPUTYPE_8BIT )
  3778.       #error "XCP consistency error: Forcing alignment for 8-bit microcontrollers is useless."
  3779.     #endif
  3780.   #if defined ( XCP_ENABLE_UNALIGNED_MEM_ACCESS )
  3781.     #error "XCP consistency error: Select either alignment or no alignment."
  3782.   #endif
  3783. #else /* if defined ( XCP_DISABLE_UNALIGNED_MEM_ACCESS ) */
  3784.   #if defined ( XCP_ENABLE_UNALIGNED_MEM_ACCESS )
  3785.   #else
  3786.     #error "XCP consistency error: Usage of alignment not specified."
  3787.   #endif
  3788. #endif /* if defined ( XCP_DISABLE_UNALIGNED_MEM_ACCESS ) */
  3789.  
  3790.  
  3791. /*******************************************************************************
  3792. * Organi check
  3793. *******************************************************************************/
  3794.  
  3795.  
  3796.  
  3797.  
  3798.  
  3799.  
  3800.  
  3801.  
  3802.  
  3803.  
  3804.  
  3805.  
  3806.  
  3807.  
  3808.  
  3809.  
  3810.  
  3811.  
  3812.  
  3813.  
  3814.  
  3815. /* module specific MISRA deviations:
  3816.   MD_Xcp_0306:    Rule 11.3
  3817.       Reason:     Pointer alignment has to be set manually due to dynamically structures; solved via cast to int, AND calculation and cast back to a pointer.
  3818.       Risk:       Maintainability reduced due to optimization.
  3819.       Prevention: Covered by code review.
  3820.   MD_Xcp_0310:    Rule 11.4
  3821.       Reason:     Alignment is given by calling function.
  3822.       Risk:       Maintainability reduced due to optimization.
  3823.       Prevention: Covered by code review.
  3824.   MD_Xcp_0310_ByteCopy: Rule 11.4
  3825.       Reason:     XCP accesses arrays always byte-wise (ODT handling and interpretation)
  3826.       Risk:       Maintainability reduced due to optimization.
  3827.       Prevention: Covered by code review.
  3828.   MD_Xcp_0311_StimBuffer: Rule 11.5
  3829.       Reason:     Casting to remove const for optimization reason; XCP command data is re-used for status flag handling.
  3830.       Risk:       Maintainability reduced due to optimization.
  3831.       Prevention: Covered by code review.
  3832.   MD_Xcp_0488:    Rule 17.4
  3833.       Reason:     For optimization reasons direct pointer arithmetic is used.
  3834.       Risk:       There is no risk as this has no effect on the code.
  3835.       Prevention: Covered by code review.
  3836.   MD_Xcp_0489:    Rule 17.4
  3837.       Reason:     For optimization reasons direct pointer arithmetic is used.
  3838.       Risk:       There is no risk as this has no effect on the code.
  3839.       Prevention: Covered by code review.
  3840.   MD_Xcp_0770:    Rule 14.5
  3841.       Reason:     For optimization reasons more than one break/continue was used to leave the for loop.
  3842.       Risk:       Maintainability reduced due to multiple break/continue statements.
  3843.       Prevention: Covered by code review.
  3844.   MD_Xcp_2001:    Rule 14.4
  3845.       Reason:     For optimization reasons a goto is used.
  3846.       Risk:       There is no risk as this the goto is only used function internally.
  3847.       Prevention: Covered by code review.
  3848.   MD_Xcp_2003:    Rule 15.2
  3849.       Reason:     For optimization reasons fall-through is used.
  3850.       Risk:       There is no risk as this the goto is only used function internally.
  3851.       Prevention: Covered by code review.
  3852.   MD_Xcp_3397:    Rule 12.1
  3853.       Reason:     The statement as used in the ASAM specification is used.
  3854.       Risk:       There is no risk as this is reviewd by ASAM group.
  3855.       Prevention: Covered by code review.
  3856.   MD_Xcp_3408:    Rule 8.8
  3857.       Reason:     The variable is not defined as static to be accessible for calibration. No prototype is required for this.
  3858.       Risk:       There is no risk as this variable is not accessed externally.
  3859.       Prevention: Covered by code review.
  3860.   MD_Xcp_3757:    Rule 10.1
  3861.       Reason:     Due to byte access the variable is split.
  3862.       Risk:       There is no risk as this variable is positive.
  3863.       Prevention: Covered by code review.
  3864.   MD_Xcp_4130:    Rule 12.7
  3865.       Reason:     When a vuint8 is in reality 16bit then proper value range must be handled by and mask.
  3866.       Risk:       There is no risk as the target variable is intended to be uint8.
  3867.       Prevention: Covered by code review.
  3868. */
  3869.  
  3870. /**********************************************************************************************************************
  3871.  *  END OF FILE: XcpProf.c
  3872.  *********************************************************************************************************************/
  3873.  
  3874. #pragma diag_warning=Pa082 //restore Warning[Pa082]: undefined behavior: the order of volatile accesses is undefined in this statement
  3875.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement