Dio.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : GPIO
  5. * Dependencies : none
  6. *
  7. * Autosar Version : 4.4.0
  8. * Autosar Revision : ASR_REL_4_4_REV_0000
  9. * Autosar Conf.Variant :
  10. * SW Version : 1.0.0
  11. * Build Version : S32K1_RTD_1_0_0_HF01_D2109_ASR_REL_4_4_REV_0000_20210907
  12. *
  13. * (c) Copyright 2020-2021 NXP Semiconductors
  14. * All Rights Reserved.
  15. *
  16. * NXP Confidential. This software is owned or controlled by NXP and may only be
  17. * used strictly in accordance with the applicable license terms. By expressly
  18. * accepting such terms or by downloading, installing, activating and/or otherwise
  19. * using the software, you are agreeing that you have read, and that you agree to
  20. * comply with and are bound by, such license terms. If you do not agree to be
  21. * bound by the applicable license terms, then you may not retain, install,
  22. * activate or otherwise use the software.
  23. ==================================================================================================*/
  24. /**
  25. * @file Dio.c
  26. * @implements Dio.c_Artifact
  27. *
  28. * @addtogroup DIO_HLD
  29. * @{
  30. */
  31. #ifdef __cplusplus
  32. extern "C"{
  33. #endif
  34. /*=================================================================================================
  35. * INCLUDE FILES
  36. * 1) system and project includes
  37. * 2) needed interfaces from external units
  38. * 3) internal and external interfaces from this unit
  39. =================================================================================================*/
  40. #include "Dio.h"
  41. #include "Dio_Ipw.h"
  42. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  43. #include "Det.h"
  44. #endif
  45. /*=================================================================================================
  46. * SOURCE FILE VERSION INFORMATION
  47. =================================================================================================*/
  48. #define DIO_VENDOR_ID_C 43
  49. #define DIO_AR_RELEASE_MAJOR_VERSION_C 4
  50. #define DIO_AR_RELEASE_MINOR_VERSION_C 4
  51. #define DIO_AR_RELEASE_REVISION_VERSION_C 0
  52. #define DIO_SW_MAJOR_VERSION_C 1
  53. #define DIO_SW_MINOR_VERSION_C 0
  54. #define DIO_SW_PATCH_VERSION_C 0
  55. /*=================================================================================================
  56. * FILE VERSION CHECKS
  57. =================================================================================================*/
  58. /* Check if current file and DET header file are of the same version.*/
  59. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  60. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  61. #if ((DIO_AR_RELEASE_MAJOR_VERSION_C != DET_AR_RELEASE_MAJOR_VERSION) || \
  62. (DIO_AR_RELEASE_MINOR_VERSION_C != DET_AR_RELEASE_MINOR_VERSION) \
  63. )
  64. #error "AutoSar Version Numbers of Dio.c and Det.h are different"
  65. #endif
  66. #endif
  67. #endif
  68. /* Check if current file and DIO header file are of the same vendor.*/
  69. #if (DIO_VENDOR_ID_C != DIO_VENDOR_ID)
  70. #error "Dio.c and Dio.h have different vendor ids"
  71. #endif
  72. /* Check if current file and DIO header file are of the same Autosar version.*/
  73. #if ((DIO_AR_RELEASE_MAJOR_VERSION_C != DIO_AR_RELEASE_MAJOR_VERSION) || \
  74. (DIO_AR_RELEASE_MINOR_VERSION_C != DIO_AR_RELEASE_MINOR_VERSION) || \
  75. (DIO_AR_RELEASE_REVISION_VERSION_C != DIO_AR_RELEASE_REVISION_VERSION) \
  76. )
  77. #error "AutoSar Version Numbers of Dio.c and Dio.h are different"
  78. #endif
  79. /* Check if current file and DIO header file are of the same Software version.*/
  80. #if ((DIO_SW_MAJOR_VERSION_C != DIO_SW_MAJOR_VERSION) || \
  81. (DIO_SW_MINOR_VERSION_C != DIO_SW_MINOR_VERSION) || \
  82. (DIO_SW_PATCH_VERSION_C != DIO_SW_PATCH_VERSION) \
  83. )
  84. #error "Software Version Numbers of Dio.c and Dio.h are different"
  85. #endif
  86. /* Dio_Ipw.h version check start */
  87. #if ((DIO_AR_RELEASE_MAJOR_VERSION_C != DIO_AR_RELEASE_MAJOR_VERSION_IPW_H) || \
  88. (DIO_AR_RELEASE_MINOR_VERSION_C != DIO_AR_RELEASE_MINOR_VERSION_IPW_H) || \
  89. (DIO_AR_RELEASE_REVISION_VERSION_C != DIO_AR_RELEASE_REVISION_VERSION_IPW_H)\
  90. )
  91. #error "AUTOSAR Version Numbers of Dio.c and Dio_Ipw.h are different"
  92. #endif
  93. #if ((DIO_SW_MAJOR_VERSION_C != DIO_SW_MAJOR_VERSION_IPW_H) || \
  94. (DIO_SW_MINOR_VERSION_C != DIO_SW_MINOR_VERSION_IPW_H) || \
  95. (DIO_SW_PATCH_VERSION_C != DIO_SW_PATCH_VERSION_IPW_H) \
  96. )
  97. #error "Software Version Numbers of Dio.c and Dio_Ipw.h are different"
  98. #endif
  99. #if (DIO_VENDOR_ID_C != DIO_VENDOR_ID_IPW_H)
  100. #error "VENDOR ID for Dio.c and Dio_Ipw.h is different"
  101. #endif
  102. /* Dio_Ipw.h version check end */
  103. /*=================================================================================================
  104. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  105. =================================================================================================*/
  106. /*=================================================================================================
  107. * LOCAL MACROS
  108. =================================================================================================*/
  109. #if (STD_ON == DIO_MULTICORE_ENABLED)
  110. #define Dio_GetCoreID() OsIf_GetCoreID()
  111. #else
  112. #define Dio_GetCoreID() ((uint32)0UL)
  113. #endif
  114. /*=================================================================================================
  115. * LOCAL CONSTANTS
  116. =================================================================================================*/
  117. /*=================================================================================================
  118. * LOCAL VARIABLES
  119. =================================================================================================*/
  120. #if (defined(DIO_PRECOMPILE_SUPPORT) || defined(DIO_LINKTIME_SUPPORT))
  121. #define DIO_START_SEC_CONFIG_DATA_UNSPECIFIED
  122. #include "Dio_MemMap.h"
  123. /* Local Variable for storing the generated Dio configuration */
  124. extern const Dio_ConfigType Dio_ConfigPC;
  125. #define DIO_STOP_SEC_CONFIG_DATA_UNSPECIFIED
  126. #include "Dio_MemMap.h"
  127. #endif /* (defined(DIO_PRECOMPILE_SUPPORT) || defined(DIO_LINKTIME_SUPPORT)) */
  128. /*=================================================================================================
  129. * GLOBAL CONSTANTS
  130. =================================================================================================*/
  131. /*=================================================================================================
  132. * GLOBAL VARIABLES
  133. =================================================================================================*/
  134. /*=================================================================================================
  135. * LOCAL FUNCTION PROTOTYPES
  136. =================================================================================================*/
  137. #define DIO_START_SEC_CODE
  138. #include "Dio_MemMap.h"
  139. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  140. static inline Std_ReturnType Dio_ValidateChannelLevel
  141. (
  142. Dio_LevelType Level
  143. );
  144. static inline Std_ReturnType Dio_ValidateChannelForWrite
  145. (
  146. Dio_ChannelType ChannelId,
  147. uint8 u8ServiceId
  148. );
  149. static inline Std_ReturnType Dio_ValidateChannelForRead
  150. (
  151. Dio_ChannelType ChannelId,
  152. uint8 u8ServiceId
  153. );
  154. static inline Std_ReturnType Dio_ValidatePortForWrite
  155. (
  156. Dio_PortType PortId,
  157. uint8 u8ServiceId
  158. );
  159. static inline Std_ReturnType Dio_ValidatePortForRead
  160. (
  161. Dio_PortType PortId,
  162. uint8 u8ServiceId
  163. );
  164. static inline Std_ReturnType Dio_ValidateChannelGroupForWrite
  165. (
  166. const Dio_ChannelGroupType * pChannelGroup,
  167. uint8 u8ServiceId
  168. );
  169. static inline Std_ReturnType Dio_ValidateChannelGroupForRead
  170. (
  171. const Dio_ChannelGroupType * pChannelGroup,
  172. uint8 u8ServiceId
  173. );
  174. #endif /* (STD_ON == DIO_DEV_ERROR_DETECT) */
  175. /*=================================================================================================
  176. * LOCAL FUNCTIONS
  177. =================================================================================================*/
  178. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  179. /**
  180. * @brief DIO channel level validation.
  181. * @details Checks if the specified channel level is valid (either STD_HIGH or STD_LOW).
  182. *
  183. * @param[in] Level channel level parameter to be checked
  184. *
  185. * @return Std_ReturnType
  186. *
  187. * @api
  188. *
  189. * @implements Dio_ValidateChannelLevel_Activity
  190. */
  191. static inline Std_ReturnType Dio_ValidateChannelLevel
  192. (
  193. Dio_LevelType Level
  194. )
  195. {
  196. Std_ReturnType Valid = (Std_ReturnType)E_NOT_OK;
  197. if (((Dio_LevelType)STD_HIGH == Level) || ((Dio_LevelType)STD_LOW == Level))
  198. {
  199. Valid = (Std_ReturnType)E_OK;
  200. }
  201. else
  202. {
  203. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, DIO_WRITECHANNEL_ID, DIO_E_PARAM_LEVEL);
  204. }
  205. return Valid;
  206. }
  207. #endif
  208. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  209. /**
  210. * @brief DIO channel availability check.
  211. * @details Checks if the specified channel is implemented in the current platform package.
  212. *
  213. * @param[in] ChannelId Identifier of the channel to be checked.
  214. * u8ServiceId The service id of the caller function
  215. *
  216. * @return Std_ReturnType
  217. *
  218. * @api
  219. *
  220. * @implements Dio_ValidateChannelForWrite_Activity
  221. */
  222. static inline Std_ReturnType Dio_ValidateChannelForWrite
  223. (
  224. Dio_ChannelType ChannelId,
  225. uint8 u8ServiceId
  226. )
  227. {
  228. Std_ReturnType Valid = (Std_ReturnType)E_NOT_OK;
  229. uint8 CoreId = (uint8)Dio_GetCoreID();
  230. if ((((Dio_ChannelType)(ChannelId) <= DIO_NUM_CHANNELS_U16)) &&
  231. ((Dio_PortLevelType)0 != (Dio_aAvailablePinsForWrite[DIO_PORTID_EXTRACT(ChannelId)] &
  232. (DIO_CHECK_CHANNEL_VALIDITY((uint16)ChannelId))
  233. )
  234. )
  235. )
  236. {
  237. if ((uint32)1 == ((Dio_ConfigPC.pau32Dio_ChannelToPartitionMap[ChannelId] & ((uint32)1 << CoreId)) >> CoreId))
  238. {
  239. Valid = (Std_ReturnType)E_OK;
  240. }
  241. else
  242. {
  243. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, u8ServiceId, DIO_E_PARAM_CONFIG);
  244. }
  245. }
  246. else
  247. {
  248. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, u8ServiceId, DIO_E_PARAM_INVALID_CHANNEL_ID);
  249. }
  250. return Valid;
  251. }
  252. /**
  253. * @brief DIO channel availability check.
  254. * @details Checks if the specified channel is implemented in the current platform package.
  255. *
  256. * @param[in] ChannelId Identifier of the channel to be checked.
  257. * u8ServiceId The service id of the caller function
  258. *
  259. * @return Std_ReturnType
  260. *
  261. * @api
  262. *
  263. * @implements Dio_ValidateChannelForRead_Activity
  264. */
  265. static inline Std_ReturnType Dio_ValidateChannelForRead
  266. (
  267. Dio_ChannelType ChannelId,
  268. uint8 u8ServiceId
  269. )
  270. {
  271. Std_ReturnType Valid = (Std_ReturnType)E_NOT_OK;
  272. uint8 CoreId = (uint8)Dio_GetCoreID();
  273. /* Check if that channel ID is available for read */
  274. if ((((Dio_ChannelType)(ChannelId) <= DIO_NUM_CHANNELS_U16)) &&
  275. ((Dio_PortLevelType)0 != (Dio_aAvailablePinsForRead[DIO_PORTID_EXTRACT(ChannelId)] &
  276. (DIO_CHECK_CHANNEL_VALIDITY((uint16)ChannelId))
  277. )
  278. )
  279. )
  280. {
  281. /* Check if port was assigned to the current coreID */
  282. if ((uint32)1 == ((Dio_ConfigPC.pau32Dio_ChannelToPartitionMap[ChannelId] & ((uint32)1 << CoreId)) >> CoreId))
  283. {
  284. Valid = (Std_ReturnType)E_OK;
  285. }
  286. else
  287. {
  288. /* Raise Det error when invalid serviceID */
  289. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, u8ServiceId, DIO_E_PARAM_CONFIG);
  290. }
  291. }
  292. else
  293. {
  294. /* Raise Det error when invalid channel ID */
  295. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, u8ServiceId, DIO_E_PARAM_INVALID_CHANNEL_ID);
  296. }
  297. return Valid;
  298. }
  299. #endif
  300. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  301. /**
  302. * @brief DIO port availability check.
  303. * @details Checks if the specified port is implemented in the current platform package.
  304. *
  305. * @param[in] PortId Identifier of the port to be checked.
  306. * u8ServiceId The service id of the caller function
  307. *
  308. * @return Std_ReturnType
  309. *
  310. * @api
  311. *
  312. * @implements Dio_ValidatePortForWrite_Activity
  313. */
  314. static inline Std_ReturnType Dio_ValidatePortForWrite
  315. (
  316. Dio_PortType PortId,
  317. uint8 u8ServiceId
  318. )
  319. {
  320. Std_ReturnType Valid = (Std_ReturnType)E_NOT_OK;
  321. uint8 CoreId = (uint8)Dio_GetCoreID();
  322. if (((uint8)(PortId) < DIO_NUM_PORTS_U16) &&
  323. (Dio_aAvailablePinsForWrite[(uint8)(PortId)] != DIO_NO_AVAILABLE_CHANNELS_U16)
  324. )
  325. {
  326. if ((uint32)1 == ((Dio_ConfigPC.pau32Dio_PortToPartitionMap[PortId] & ((uint32)1 << CoreId)) >> CoreId))
  327. {
  328. Valid = ( Std_ReturnType)E_OK;
  329. }
  330. else
  331. {
  332. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, u8ServiceId, DIO_E_PARAM_CONFIG);
  333. }
  334. }
  335. else
  336. {
  337. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, u8ServiceId, DIO_E_PARAM_INVALID_PORT_ID);
  338. }
  339. return Valid;
  340. }
  341. /**
  342. * @brief DIO port availability check.
  343. * @details Checks if the specified port is implemented in the current platform package.
  344. *
  345. * @param[in] PortId Identifier of the port to be checked.
  346. * u8ServiceId The service id of the caller function
  347. *
  348. * @return Std_ReturnType
  349. *
  350. * @api
  351. *
  352. * @implements Dio_ValidatePortForRead_Activity
  353. */
  354. static inline Std_ReturnType Dio_ValidatePortForRead
  355. (
  356. Dio_PortType PortId,
  357. uint8 u8ServiceId
  358. )
  359. {
  360. Std_ReturnType Valid = (Std_ReturnType)E_NOT_OK;
  361. uint8 CoreId = (uint8)Dio_GetCoreID();
  362. /* Check input parameters are available for read */
  363. if (((uint8)(PortId) < DIO_NUM_PORTS_U16) &&
  364. (Dio_aAvailablePinsForRead[(uint8)(PortId)] != DIO_NO_AVAILABLE_CHANNELS_U16)
  365. )
  366. {
  367. /* Check if Port was assigned to the current coreID */
  368. if ((uint32)1 == ((Dio_ConfigPC.pau32Dio_PortToPartitionMap[PortId] & ((uint32)1 << CoreId)) >> CoreId))
  369. {
  370. Valid = ( Std_ReturnType)E_OK;
  371. }
  372. else
  373. {
  374. /* Raise Det error when invalid serviceID */
  375. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, u8ServiceId, DIO_E_PARAM_CONFIG);
  376. }
  377. }
  378. else
  379. {
  380. /* Raise Det error when invalid port ID */
  381. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, u8ServiceId, DIO_E_PARAM_INVALID_PORT_ID);
  382. }
  383. return Valid;
  384. }
  385. #endif
  386. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  387. /**
  388. * @brief DIO channel group validity check.
  389. * @details Checks if the parameter matches one of the channel group pointers in
  390. * the configuration.
  391. *
  392. * @param[in] pChannelGroup The channel group to be validated.
  393. * u8ServiceId The service id of the caller function
  394. *
  395. * @return Std_ReturnType
  396. *
  397. * @api
  398. *
  399. * @implements Dio_ValidateChannelGroupForWrite_Activity
  400. */
  401. static inline Std_ReturnType Dio_ValidateChannelGroupForWrite
  402. (
  403. const Dio_ChannelGroupType * pChannelGroup,
  404. uint8 u8ServiceId
  405. )
  406. {
  407. Std_ReturnType Valid = (Std_ReturnType)E_NOT_OK;
  408. /* Compiler_Warning: Pointer to channel group is converted to unsigned long in order for it to
  409. be compared with the boundaries of the channel group list. */
  410. if ((((pointerSizeType)(pChannelGroup)) >= ((pointerSizeType)Dio_ConfigPC.pChannelGroupList)) && \
  411. (((pointerSizeType)(pChannelGroup)) <= (pointerSizeType)(&Dio_ConfigPC.pChannelGroupList[Dio_ConfigPC.u8NumChannelGroups - 1U])) && \
  412. ((uint8)(pChannelGroup->port) < DIO_NUM_PORTS_U16) && \
  413. (Dio_aAvailablePinsForWrite[(uint8)(pChannelGroup->port)] != DIO_NO_AVAILABLE_CHANNELS_U16) && \
  414. ((uint8)(pChannelGroup->u8offset) <= DIO_MAX_VALID_OFFSET_U8)
  415. )
  416. {
  417. Valid = (Std_ReturnType)E_OK;
  418. }
  419. else
  420. {
  421. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, u8ServiceId, DIO_E_PARAM_INVALID_GROUP_ID);
  422. }
  423. return Valid;
  424. }
  425. /**
  426. * @brief DIO channel group validity check.
  427. * @details Checks if the parameter matches one of the channel group pointers in
  428. * the configuration.
  429. *
  430. * @param[in] pChannelGroup The channel group to be validated.
  431. * u8ServiceId The service id of the caller function
  432. *
  433. * @return Std_ReturnType
  434. *
  435. * @api
  436. *
  437. * @implements Dio_ValidateChannelGroupForRead_Activity
  438. */
  439. static inline Std_ReturnType Dio_ValidateChannelGroupForRead
  440. (
  441. const Dio_ChannelGroupType * pChannelGroup,
  442. uint8 u8ServiceId
  443. )
  444. {
  445. Std_ReturnType Valid = (Std_ReturnType)E_NOT_OK;
  446. /* Compiler_Warning: Pointer to channel group is converted to unsigned long in order for it to
  447. be compared with the boundaries of the channel group list. */
  448. if ((((pointerSizeType)(pChannelGroup)) >= ((pointerSizeType)Dio_ConfigPC.pChannelGroupList)) && \
  449. (((pointerSizeType)(pChannelGroup)) <= (pointerSizeType)(&Dio_ConfigPC.pChannelGroupList[Dio_ConfigPC.u8NumChannelGroups - 1U])) && \
  450. ((uint8)(pChannelGroup->port) < DIO_NUM_PORTS_U16) && \
  451. (Dio_aAvailablePinsForRead[(uint8)(pChannelGroup->port)] != DIO_NO_AVAILABLE_CHANNELS_U16) && \
  452. ((uint8)(pChannelGroup->u8offset) <= DIO_MAX_VALID_OFFSET_U8)
  453. )
  454. {
  455. Valid = (Std_ReturnType)E_OK;
  456. }
  457. else
  458. {
  459. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, u8ServiceId, DIO_E_PARAM_INVALID_GROUP_ID);
  460. }
  461. return Valid;
  462. }
  463. #endif
  464. /*=================================================================================================
  465. * GLOBAL FUNCTIONS
  466. =================================================================================================*/
  467. /*================================================================================================*/
  468. #if (STD_ON == DIO_VERSION_INFO_API)
  469. /*================================================================================================*/
  470. /**
  471. * @brief Service to get the version information of this module.
  472. * @details The @p Dio_GetVersionInfo() function shall return the version
  473. * information of this module. The version information includes:
  474. * - Module Id.
  475. * - Vendor Id.
  476. * - Vendor specific version numbers.
  477. * .
  478. *
  479. * @param[in,out] VersionInfo Pointer to where to store the version
  480. * information of this module.
  481. *
  482. * @pre This function can be used only if @p DIO_VERSION_INFO_API
  483. * has been enabled.
  484. *
  485. * @implements Dio_GetVersionInfo_Activity
  486. */
  487. void Dio_GetVersionInfo
  488. (
  489. Std_VersionInfoType * VersionInfo
  490. )
  491. {
  492. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  493. if (NULL_PTR == VersionInfo)
  494. {
  495. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, DIO_GETVERSIONINFO_ID, DIO_E_PARAM_POINTER);
  496. }
  497. else
  498. #endif /* (STD_ON == DIO_DEV_ERROR_DETECT) */
  499. {
  500. VersionInfo->vendorID = (uint16)DIO_VENDOR_ID;
  501. VersionInfo->moduleID = (uint16)DIO_MODULE_ID;
  502. VersionInfo->sw_major_version = (uint8)DIO_SW_MAJOR_VERSION;
  503. VersionInfo->sw_minor_version = (uint8)DIO_SW_MINOR_VERSION;
  504. VersionInfo->sw_patch_version = (uint8)DIO_SW_PATCH_VERSION;
  505. }
  506. }
  507. #endif /* (STD_ON == DIO_DEV_ERROR_DETECT) */
  508. /*================================================================================================*/
  509. /**
  510. * @brief Returns the value of the specified DIO channel.
  511. * @details This function returns the value of the specified DIO channel.
  512. *
  513. * @param[in] ChannelId Specifies the required channel id.
  514. *
  515. * @return Returns the level of the corresponding pin as
  516. * @p STD_HIGH or @p STD_LOW.
  517. * @retval STD_HIGH The logical level of the corresponding pin is 1.
  518. * @retval STD_LOW The logical level of the corresponding Pin is 0.
  519. *
  520. * @implements Dio_ReadChannel_Activity
  521. */
  522. Dio_LevelType Dio_ReadChannel
  523. (
  524. Dio_ChannelType ChannelId
  525. )
  526. {
  527. Dio_LevelType ChannelLevel = (Dio_LevelType)STD_LOW;
  528. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  529. Std_ReturnType Valid = Dio_ValidateChannelForRead(ChannelId, DIO_READCHANNEL_ID);
  530. if ((Std_ReturnType)E_OK == Valid)
  531. {
  532. #endif
  533. ChannelLevel = Dio_Ipw_ReadChannel(ChannelId);
  534. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  535. }
  536. #endif
  537. return ChannelLevel;
  538. }
  539. /*================================================================================================*/
  540. /**
  541. * @brief Sets the level of a channel.
  542. * @details If the specified channel is configured as an output channel,
  543. * this function shall set the specified level on the
  544. * specified channel. If the specified channel is configured
  545. * as an input channel, this function shall have no influence
  546. * on the physical output and on the result of the next read
  547. * service.
  548. *
  549. * @param[in] ChannelId Specifies the required channel id.
  550. * @param[in] Level Specifies the channel desired level.
  551. *
  552. * @implements Dio_WriteChannel_Activity
  553. */
  554. void Dio_WriteChannel
  555. (
  556. Dio_ChannelType ChannelId,
  557. Dio_LevelType Level
  558. )
  559. {
  560. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  561. Std_ReturnType Valid = Dio_ValidateChannelForWrite(ChannelId, DIO_WRITECHANNEL_ID);
  562. if ((Std_ReturnType) E_OK == Valid)
  563. {
  564. Valid = Dio_ValidateChannelLevel(Level);
  565. if ((Std_ReturnType) E_OK == Valid)
  566. {
  567. #endif
  568. Dio_Ipw_WriteChannel(ChannelId, Level);
  569. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  570. }
  571. }
  572. #endif
  573. }
  574. #if (STD_ON == DIO_FLIP_CHANNEL_API)
  575. /*================================================================================================*/
  576. /**
  577. * @brief Inverts the level of a channel.
  578. * @details If the specified channel is configured as an output channel,
  579. * this function shall invert the level of the specified
  580. * channel. If the specified channel is configured as an
  581. * input channel, this function shall have no influence
  582. * on the physical output and on the result of the next
  583. * read service.
  584. *
  585. * @param[in] ChannelId Specifies the required channel id.
  586. *
  587. * @return Returns the level of the corresponding pin as
  588. * @p STD_HIGH or @p STD_LOW.
  589. * @retval STD_HIGH The logical level of the corresponding pin is 1.
  590. * @retval STD_LOW The logical level of the corresponding Pin is 0.
  591. *
  592. * @pre This function can be used only if @p DIO_FLIP_CHANNEL_API
  593. * has been enabled.
  594. *
  595. * @implements Dio_FlipChannel_Activity
  596. */
  597. Dio_LevelType Dio_FlipChannel
  598. (
  599. Dio_ChannelType ChannelId
  600. )
  601. {
  602. Dio_LevelType ChannelLevel = (Dio_LevelType)STD_LOW;
  603. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  604. Std_ReturnType Valid = Dio_ValidateChannelForWrite(ChannelId, DIO_FLIPCHANNEL_ID);
  605. if ((Std_ReturnType)E_OK == Valid)
  606. {
  607. #endif
  608. ChannelLevel = Dio_Ipw_FlipChannel(ChannelId);
  609. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  610. }
  611. #endif
  612. return ChannelLevel;
  613. }
  614. #endif /* (STD_ON == DIO_FLIP_CHANNEL_API) */
  615. /*================================================================================================*/
  616. /**
  617. * @brief Returns the level of all channels of specified port.
  618. * @details This function will return the level of all channels
  619. * belonging to the specified port.
  620. *
  621. * @param[in] PortId Specifies the required port id.
  622. *
  623. * @return Levels of all channels of specified port.
  624. *
  625. * @implements Dio_ReadPort_Activity
  626. */
  627. Dio_PortLevelType Dio_ReadPort
  628. (
  629. Dio_PortType PortId
  630. )
  631. {
  632. Dio_PortLevelType PortLevel = (Dio_PortLevelType)STD_LOW;
  633. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  634. Std_ReturnType Valid = Dio_ValidatePortForRead(PortId, DIO_READPORT_ID);
  635. if ((Std_ReturnType) E_OK == Valid)
  636. {
  637. #endif
  638. PortLevel = Dio_Ipw_ReadPort(PortId);
  639. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  640. }
  641. #endif
  642. return PortLevel;
  643. }
  644. /*================================================================================================*/
  645. /**
  646. * @brief Sets the value of a port.
  647. * @details This function will set the specified value on the specified
  648. * port.
  649. *
  650. * @param[in] PortId Specifies the required port id.
  651. * @param[in] Level Specifies the required levels for the port pins.
  652. *
  653. * @implements Dio_WritePort_Activity
  654. */
  655. void Dio_WritePort
  656. (
  657. Dio_PortType PortId,
  658. Dio_PortLevelType Level
  659. )
  660. {
  661. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  662. Std_ReturnType Valid = Dio_ValidatePortForWrite(PortId, DIO_WRITEPORT_ID);
  663. if ((Std_ReturnType)E_OK == Valid)
  664. {
  665. #endif
  666. Dio_Ipw_WritePort(PortId, Level);
  667. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  668. }
  669. #endif
  670. }
  671. /*================================================================================================*/
  672. /**
  673. * @brief This service reads a subset of the adjoining bits of a port.
  674. * @details This function will read a subset of adjoining bits of a
  675. * port (channel group).
  676. *
  677. * @param[in] ChannelGroupIdPtr Pointer to the channel group.
  678. *
  679. * @return The channel group levels.
  680. *
  681. * @implements Dio_ReadChannelGroup_Activity
  682. */
  683. Dio_PortLevelType Dio_ReadChannelGroup
  684. (
  685. const Dio_ChannelGroupType * ChannelGroupIdPtr
  686. )
  687. {
  688. Dio_PortLevelType PortLevel = (Dio_PortLevelType)STD_LOW;
  689. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  690. #ifdef DIO_CHANNEL_GROUPS_AVAILABLE
  691. uint8 GroupAlocated = 0;
  692. uint8 GroupIndex = 0;
  693. uint8 CoreId;
  694. #endif /* DIO_CHANNEL_GROUPS_AVAILABLE */
  695. Std_ReturnType Valid;
  696. #ifdef DIO_CHANNEL_GROUPS_AVAILABLE
  697. CoreId = (uint8)Dio_GetCoreID();
  698. #endif /* DIO_CHANNEL_GROUPS_AVAILABLE */
  699. Valid = Dio_ValidateChannelGroupForRead(ChannelGroupIdPtr, DIO_READCHANNELGROUP_ID);
  700. if ((Std_ReturnType)E_OK == Valid)
  701. {
  702. #ifdef DIO_CHANNEL_GROUPS_AVAILABLE
  703. for(GroupIndex = 0; GroupIndex < Dio_ConfigPC.u8NumChannelGroups; GroupIndex++)
  704. {
  705. if(au32ChannelGroupsListForEachPartition[CoreId][GroupIndex] == ChannelGroupIdPtr)
  706. {
  707. GroupAlocated = 1;
  708. }
  709. }
  710. if ((uint8)1 == GroupAlocated)
  711. {
  712. #endif /* DIO_CHANNEL_GROUPS_AVAILABLE */
  713. #endif /* DIO_DEV_ERROR_DETECT */
  714. PortLevel = Dio_Ipw_ReadChannelGroup(ChannelGroupIdPtr);
  715. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  716. #ifdef DIO_CHANNEL_GROUPS_AVAILABLE
  717. }
  718. else
  719. {
  720. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, DIO_READCHANNELGROUP_ID, DIO_E_PARAM_CONFIG);
  721. }
  722. #endif /* DIO_CHANNEL_GROUPS_AVAILABLE */
  723. }
  724. #endif /* DIO_DEV_ERROR_DETECT */
  725. return PortLevel;
  726. }
  727. /*================================================================================================*/
  728. /**
  729. * @brief Sets a subset of the adjoining bits of a port to the
  730. * specified levels.
  731. * @details This function will set a subset of adjoining bits of a port
  732. * (channel group) to the specified levels without changing
  733. * the remaining channels of the port and channels that
  734. * are configured as input.
  735. * This function will do the masking of the channels and will
  736. * do the shifting so that the values written by the function
  737. * are aligned to the LSB.
  738. *
  739. * @param[in] ChannelGroupIdPtr Pointer to the channel group.
  740. * @param[in] Level Desired levels for the channel group.
  741. *
  742. * @implements Dio_WriteChannelGroup_Activity
  743. */
  744. void Dio_WriteChannelGroup
  745. (
  746. const Dio_ChannelGroupType * ChannelGroupIdPtr,
  747. Dio_PortLevelType Level
  748. )
  749. {
  750. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  751. #ifdef DIO_CHANNEL_GROUPS_AVAILABLE
  752. uint8 GroupAlocated = 0;
  753. uint8 GroupIndex = 0;
  754. uint8 CoreId;
  755. #endif /* DIO_CHANNEL_GROUPS_AVAILABLE */
  756. Std_ReturnType Valid;
  757. #ifdef DIO_CHANNEL_GROUPS_AVAILABLE
  758. CoreId = (uint8)Dio_GetCoreID();
  759. #endif /* DIO_CHANNEL_GROUPS_AVAILABLE */
  760. Valid = Dio_ValidateChannelGroupForWrite(ChannelGroupIdPtr, DIO_WRITECHANNELGROUP_ID);
  761. if ((Std_ReturnType)E_OK == Valid)
  762. {
  763. #ifdef DIO_CHANNEL_GROUPS_AVAILABLE
  764. for(GroupIndex = 0; GroupIndex < Dio_ConfigPC.u8NumChannelGroups; GroupIndex++)
  765. {
  766. if(au32ChannelGroupsListForEachPartition[CoreId][GroupIndex] == ChannelGroupIdPtr)
  767. {
  768. GroupAlocated = 1;
  769. }
  770. }
  771. if ((uint8)1 == GroupAlocated)
  772. {
  773. #endif /* DIO_CHANNEL_GROUPS_AVAILABLE */
  774. #endif /* DIO_DEV_ERROR_DETECT */
  775. Dio_Ipw_WriteChannelGroup(ChannelGroupIdPtr, Level);
  776. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  777. #ifdef DIO_CHANNEL_GROUPS_AVAILABLE
  778. }
  779. else
  780. {
  781. (void)Det_ReportError((uint16)DIO_MODULE_ID, DIO_INSTANCE_ID, DIO_WRITECHANNELGROUP_ID, DIO_E_PARAM_CONFIG);
  782. }
  783. #endif /* DIO_CHANNEL_GROUPS_AVAILABLE */
  784. }
  785. #endif /* DIO_DEV_ERROR_DETECT */
  786. }
  787. #if (STD_ON == DIO_MASKEDWRITEPORT_API)
  788. /*================================================================================================*/
  789. /**
  790. * @brief DIO Mask write port using mask.
  791. * @details Writes a DIO port with masked value.
  792. *
  793. * @param[in] PortId Specifies the required port id.
  794. * @param[in] Level Specifies the required levels for the port pins.
  795. * @param[in] Mask Specifies the Mask value of the port.
  796. *
  797. * @pre This function can be used only if @p DIO_MASKEDWRITEPORT_API
  798. * has been enabled.
  799. *
  800. * @implements Dio_MaskedWritePort_Activity
  801. */
  802. void Dio_MaskedWritePort
  803. (
  804. Dio_PortType PortId,
  805. Dio_PortLevelType Level,
  806. Dio_PortLevelType Mask
  807. )
  808. {
  809. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  810. Std_ReturnType Valid = Dio_ValidatePortForWrite(PortId, DIO_MASKEDWRITEPORT_ID);
  811. if ((Std_ReturnType)E_OK == Valid)
  812. {
  813. #endif
  814. Dio_Ipw_MaskedWritePort(PortId, Level, Mask);
  815. #if (STD_ON == DIO_DEV_ERROR_DETECT)
  816. }
  817. #endif
  818. }
  819. #endif /* (STD_ON == DIO_MASKEDWRITEPORT_API) */
  820. #define DIO_STOP_SEC_CODE
  821. #include "Dio_MemMap.h"
  822. #ifdef __cplusplus
  823. }
  824. #endif
  825. /** @} */