Port.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*==================================================================================================
  2. * Project : RTD AUTOSAR 4.4
  3. * Platform : CORTEXM
  4. * Peripheral : PORT_CI
  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 Port.c
  26. *
  27. * @implements Port.c_Artifact
  28. * @brief Autosar Port driver main source file
  29. * @details Port driver file that contains the implementation of the interface functions
  30. *
  31. * @addtogroup Port_HLD
  32. * @{
  33. */
  34. #ifdef __cplusplus
  35. extern "C"{
  36. #endif
  37. /*=================================================================================================
  38. * INCLUDE FILES
  39. * 1) system and project includes
  40. * 2) needed interfaces from external units
  41. * 3) internal and external interfaces from this unit
  42. =================================================================================================*/
  43. #include "Port.h"
  44. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  45. #include "Det.h"
  46. #endif
  47. /*=================================================================================================
  48. * SOURCE FILE VERSION INFORMATION
  49. =================================================================================================*/
  50. /**
  51. * @brief Parameters that shall be published within the Port driver header file and also in the
  52. * module's description file
  53. */
  54. #define PORT_VENDOR_ID_C 43
  55. #define PORT_AR_RELEASE_MAJOR_VERSION_C 4
  56. #define PORT_AR_RELEASE_MINOR_VERSION_C 4
  57. #define PORT_AR_RELEASE_REVISION_VERSION_C 0
  58. #define PORT_SW_MAJOR_VERSION_C 1
  59. #define PORT_SW_MINOR_VERSION_C 0
  60. #define PORT_SW_PATCH_VERSION_C 0
  61. /*=================================================================================================
  62. * FILE VERSION CHECKS
  63. =================================================================================================*/
  64. /* Check if source file and Port header file are of the same vendor */
  65. #if (PORT_VENDOR_ID_C != PORT_VENDOR_ID_H)
  66. #error "Port.c and Port.h have different vendor ids"
  67. #endif
  68. /* Check if source file and Port header file are of the same Autosar version */
  69. #if ((PORT_AR_RELEASE_MAJOR_VERSION_C != PORT_AR_RELEASE_MAJOR_VERSION_H) || \
  70. (PORT_AR_RELEASE_MINOR_VERSION_C != PORT_AR_RELEASE_MINOR_VERSION_H) || \
  71. (PORT_AR_RELEASE_REVISION_VERSION_C != PORT_AR_RELEASE_REVISION_VERSION_H) \
  72. )
  73. #error "AutoSar Version Numbers of Port.c and Port.h are different"
  74. #endif
  75. /* Check if source file and Port header file are of the same Software version */
  76. #if ((PORT_SW_MAJOR_VERSION_C != PORT_SW_MAJOR_VERSION_H) || \
  77. (PORT_SW_MINOR_VERSION_C != PORT_SW_MINOR_VERSION_H) || \
  78. (PORT_SW_PATCH_VERSION_C != PORT_SW_PATCH_VERSION_H) \
  79. )
  80. #error "Software Version Numbers of Port.c and Port.h are different"
  81. #endif
  82. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  83. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  84. /* Check if the source file and Det.h file are of the same Autosar version */
  85. #if ((PORT_AR_RELEASE_MAJOR_VERSION_C != DET_AR_RELEASE_MAJOR_VERSION) || \
  86. (PORT_AR_RELEASE_MINOR_VERSION_C != DET_AR_RELEASE_MINOR_VERSION) \
  87. )
  88. #error "AutoSar Version Numbers of Port.c and Det.h are different"
  89. #endif
  90. #endif
  91. #endif
  92. /*=================================================================================================
  93. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  94. =================================================================================================*/
  95. /*=================================================================================================
  96. * LOCAL MACROS
  97. =================================================================================================*/
  98. /*=================================================================================================
  99. * LOCAL CONSTANTS
  100. =================================================================================================*/
  101. #if (STD_ON == PORT_MULTICORE_ENABLED)
  102. #define Port_GetCoreID() OsIf_GetCoreID()
  103. #else
  104. #define Port_GetCoreID() ((uint32)0UL)
  105. #endif
  106. /*=================================================================================================
  107. * LOCAL VARIABLES
  108. =================================================================================================*/
  109. /*=================================================================================================
  110. * GLOBAL CONSTANTS
  111. =================================================================================================*/
  112. /*=================================================================================================
  113. * GLOBAL VARIABLES
  114. =================================================================================================*/
  115. #define PORT_START_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
  116. #include "Port_MemMap.h"
  117. static const Port_ConfigType * Port_pConfig;
  118. #define PORT_STOP_SEC_VAR_CLEARED_UNSPECIFIED_NO_CACHEABLE
  119. #include "Port_MemMap.h"
  120. #define PORT_START_SEC_CONFIG_DATA_UNSPECIFIED
  121. #include "Port_MemMap.h"
  122. #if (STD_ON == PORT_PRECOMPILE_SUPPORT)
  123. extern Port_ConfigType Port_Config;
  124. #endif
  125. #define PORT_STOP_SEC_CONFIG_DATA_UNSPECIFIED
  126. #include "Port_MemMap.h"
  127. /*=================================================================================================
  128. * LOCAL FUNCTION PROTOTYPES
  129. =================================================================================================*/
  130. /*=================================================================================================
  131. * LOCAL FUNCTIONS
  132. =================================================================================================*/
  133. #define PORT_START_SEC_CODE
  134. #include "Port_MemMap.h"
  135. /*=================================================================================================
  136. * GLOBAL FUNCTIONS
  137. =================================================================================================*/
  138. /**
  139. * @brief Initializes the Port Driver module.
  140. * @details The function @p Port_Init() will initialize ALL ports and port pins
  141. * with the configuration set pointed to by the parameter @p pConfigPtr.
  142. * @post Port_Init() must be called before all other Port Driver module's functions
  143. * otherwise no operation can occur on the MCU ports and port pins.
  144. *
  145. * @param[in] ConfigPtr A pointer to the structure which contains
  146. * initialization parameters.
  147. *
  148. * @implements Port_Init_Activity
  149. */
  150. void Port_Init
  151. (
  152. const Port_ConfigType * ConfigPtr
  153. )
  154. {
  155. const Port_ConfigType * pLocalConfigPtr = ConfigPtr;
  156. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  157. uint8 CoreId;
  158. CoreId = (uint8)Port_GetCoreID();
  159. #if (STD_OFF == PORT_PRECOMPILE_SUPPORT)
  160. if (NULL_PTR == ConfigPtr)
  161. #else /*(STD_OFF == PORT_PRECOMPILE_SUPPORT) */
  162. if (NULL_PTR != ConfigPtr)
  163. #endif /* (STD_OFF == PORT_PRECOMPILE_SUPPORT) */
  164. {
  165. (void)Det_ReportError((uint16)PORT_MODULE_ID, PORT_INSTANCE_ID, (uint8)PORT_INIT_ID, (uint8)PORT_E_INIT_FAILED);
  166. }
  167. else
  168. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  169. {
  170. #if (STD_ON == PORT_PRECOMPILE_SUPPORT)
  171. pLocalConfigPtr = &Port_Config;
  172. #endif /* (STD_ON == PORT_PRECOMPILE_SUPPORT) */
  173. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  174. if ((uint32)1 != pLocalConfigPtr->pau8Port_PartitionList[CoreId])
  175. {
  176. (void)Det_ReportError((uint16)PORT_MODULE_ID, PORT_INSTANCE_ID, (uint8)PORT_INIT_ID, (uint8)PORT_E_PARAM_CONFIG);
  177. }
  178. else
  179. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  180. {
  181. Port_Ipw_Init(pLocalConfigPtr);
  182. /* Save configuration pointer in global variable */
  183. Port_pConfig = pLocalConfigPtr;
  184. }
  185. }
  186. }
  187. #if (STD_ON == PORT_SET_PIN_DIRECTION_API)
  188. /**
  189. * @brief Sets the port pin direction.
  190. * @details The function @p Port_SetPinDirection() will set the port pin direction
  191. * during runtime.
  192. * @pre @p Port_Init() must have been called first. In order to change the
  193. * pin direction the PortPinDirectionChangeable flag must have been set
  194. * to @p TRUE.
  195. *
  196. * @param[in] Pin Pin ID number.
  197. * @param[in] Direction Port Pin direction.
  198. *
  199. * @implements Port_SetPinDirection_Activity
  200. */
  201. void Port_SetPinDirection
  202. (
  203. Port_PinType Pin,
  204. Port_PinDirectionType Direction
  205. )
  206. {
  207. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  208. /* Variable used to store current error status */
  209. Std_ReturnType ErrStatus;
  210. uint8 CoreId;
  211. CoreId = (uint8)Port_GetCoreID();
  212. /* Check if Port module is initialized */
  213. if (NULL_PTR == Port_pConfig)
  214. {
  215. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETPINDIRECTION_ID, (uint8)PORT_E_UNINIT);
  216. }
  217. /* Check port pin validity */
  218. else if (Pin >= (Port_PinType)Port_pConfig->u16NumPins)
  219. {
  220. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETPINDIRECTION_ID, (uint8)PORT_E_PARAM_PIN);
  221. }
  222. else if ((uint32)1 != (((Port_pConfig->pau32Port_PinToPartitionMap[Pin])&((uint32)1 << CoreId)) >> CoreId))
  223. {
  224. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETPINDIRECTION_ID, (uint8)PORT_E_PARAM_CONFIG);
  225. }
  226. else
  227. #endif /* PORT_DEV_ERROR_DETECT */
  228. {
  229. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  230. ErrStatus = Port_Ipw_SetPinDirection(Pin, Direction, Port_pConfig);
  231. #else
  232. (void)Port_Ipw_SetPinDirection(Pin, Direction, Port_pConfig);
  233. #endif
  234. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  235. if ((Std_ReturnType)E_NOT_OK == ErrStatus)
  236. {
  237. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETPINDIRECTION_ID, (uint8)PORT_E_DIRECTION_UNCHANGEABLE);
  238. }
  239. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  240. }
  241. }
  242. #endif /* (STD_ON == PORT_SET_PIN_DIRECTION_API) */
  243. #ifdef PORT_SET_2_PINS_DIRECTION_API
  244. #if (STD_ON == PORT_SET_2_PINS_DIRECTION_API)
  245. /**
  246. * @brief Sets the direction of 2 pins.
  247. * @details The function @p Port_Set2PinsDirection() will set the port pins direction
  248. * during runtime.
  249. * @pre @p Port_Init() must have been called first. In order to change the
  250. * pin direction the PortPinDirectionChangeable flag must have been set
  251. * to @p TRUE for both pins.
  252. *
  253. * @param[in] Pin1 Pin 1 ID number.
  254. * @param[in] Pin2 Pin 2 ID number.
  255. * @param[in] Direction Port Pin direction.
  256. *
  257. * Port_Set2PinsDirection_Activity
  258. * @api
  259. */
  260. void Port_Set2PinsDirection
  261. (
  262. Port_PinType Pin1,
  263. Port_PinType Pin2,
  264. Port_PinDirectionType Direction
  265. )
  266. {
  267. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  268. /* Variable used to store current error status */
  269. Std_ReturnType ErrStatus = (Std_ReturnType)E_OK;
  270. /* Check if Port module is initialized */
  271. if (NULL_PTR == Port_pConfig)
  272. {
  273. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SET2PINSDIRECTION_ID, (uint8)PORT_E_UNINIT);
  274. }
  275. /* Check port pin validity */
  276. else if ((Pin1 >= (Port_PinType)Port_pConfig->u16NumPins) || (Pin2 >= (Port_PinType)Port_pConfig->u16NumPins))
  277. {
  278. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SET2PINSDIRECTION_ID, (uint8)PORT_E_PARAM_PIN);
  279. }
  280. else
  281. #endif /* PORT_DEV_ERROR_DETECT */
  282. {
  283. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  284. ErrStatus = Port_Ipw_Set2PinsDirection(Pin1, Pin2, (Port_PinDirectionType)Direction, Port_pConfig);
  285. #else
  286. (void)Port_Ipw_Set2PinsDirection(Pin1, Pin2, (Port_PinDirectionType)Direction, Port_pConfig);
  287. #endif
  288. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  289. if ((Std_ReturnType)E_NOT_OK == ErrStatus)
  290. {
  291. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SET2PINSDIRECTION_ID, (uint8)PORT_E_DIRECTION_UNCHANGEABLE);
  292. }
  293. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  294. }
  295. }
  296. #endif /*(STD_ON == PORT_SET_2_PINS_DIRECTION_API) */
  297. #endif
  298. #if (STD_ON == PORT_SET_PIN_MODE_API)
  299. /**
  300. * @brief Sets the port pin mode.
  301. * @details The function @p Port_SetPinMode() will set the port pin mode of the
  302. * referenced pin during runtime.
  303. * @pre @p Port_Init() must have been called first.
  304. *
  305. * @param[in] Pin Pin ID number.
  306. * @param[in] Mode New Port Pin mode to be set on port pin.
  307. *
  308. * @implements Port_SetPinMode_Activity
  309. */
  310. void Port_SetPinMode
  311. (
  312. Port_PinType Pin,
  313. Port_PinModeType Mode
  314. )
  315. {
  316. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  317. uint8 u8PinModeError = (uint8)0U;
  318. uint8 CoreId;
  319. CoreId = (uint8)Port_GetCoreID();
  320. /* Check if port is initialized */
  321. if (NULL_PTR == Port_pConfig)
  322. {
  323. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETPINMODE_ID, (uint8)PORT_E_UNINIT);
  324. }
  325. /* Check port pin validity */
  326. else if (Pin >= (Port_PinType)Port_pConfig->u16NumPins)
  327. {
  328. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETPINMODE_ID, (uint8)PORT_E_PARAM_PIN);
  329. }
  330. else if ((uint32)1 != (((Port_pConfig->pau32Port_PinToPartitionMap[Pin])&((uint32)1 << CoreId)) >> CoreId))
  331. {
  332. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETPINMODE_ID, (uint8)PORT_E_PARAM_CONFIG);
  333. }
  334. /* Check port pin mode Unchangeable */
  335. else if(FALSE == Port_pConfig->pUsedPadConfig[Pin].bMC)
  336. {
  337. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETPINMODE_ID, (uint8)PORT_E_MODE_UNCHANGEABLE);
  338. }
  339. else
  340. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  341. {
  342. /* Sets the port pin direction */
  343. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  344. u8PinModeError = (uint8)Port_Ipw_SetPinMode(Pin, Mode, Port_pConfig);
  345. #else
  346. (void)Port_Ipw_SetPinMode(Pin, Mode, Port_pConfig);
  347. #endif
  348. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  349. if (PORT_E_PARAM_INVALID_MODE == u8PinModeError)
  350. {
  351. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETPINMODE_ID, (uint8)PORT_E_PARAM_INVALID_MODE);
  352. }
  353. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  354. }
  355. }
  356. #endif /* (STD_ON == PORT_SET_PIN_MODE_API) */
  357. /**
  358. * @brief Refreshes port direction.
  359. * @details This function will refresh the direction of all configured ports to
  360. * the configured direction.
  361. * The PORT driver will exclude from refreshing those port pins that
  362. * are configured as "pin direction changeable during runtime".
  363. * @pre @p Port_Init() must have been called first.
  364. *
  365. * @implements Port_RefreshPortDirection_Activity
  366. */
  367. void Port_RefreshPortDirection( void )
  368. {
  369. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  370. uint8 CoreId;
  371. CoreId = (uint8)Port_GetCoreID();
  372. /* Check if Port module is initialized */
  373. if (NULL_PTR == Port_pConfig)
  374. {
  375. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_REFRESHPINDIRECTION_ID, (uint8)PORT_E_UNINIT);
  376. }
  377. else if ((uint32)1 != Port_pConfig->pau8Port_PartitionList[CoreId])
  378. {
  379. (void)Det_ReportError((uint16)PORT_MODULE_ID, PORT_INSTANCE_ID, (uint8)PORT_REFRESHPINDIRECTION_ID, (uint8)PORT_E_PARAM_CONFIG);
  380. }
  381. else
  382. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  383. {
  384. Port_Ipw_RefreshPortDirection(Port_pConfig);
  385. }
  386. }
  387. #if (STD_ON == PORT_VERSION_INFO_API)
  388. /**
  389. * @brief Returns the version information of this module.
  390. * @details The function Port_GetVersionInfo() will return the version
  391. * information of this module. The version information includes:
  392. * - Module Id,
  393. * - Vendor Id,
  394. * - Vendor specific version numbers.
  395. *
  396. * @param[in,out] versioninfo Pointer to where to store the version
  397. * information of this module.
  398. *
  399. *
  400. * @implements Port_GetVersionInfo_Activity
  401. */
  402. void Port_GetVersionInfo
  403. (
  404. Std_VersionInfoType * versioninfo
  405. )
  406. {
  407. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  408. if (NULL_PTR == versioninfo)
  409. {
  410. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_GETVERSIONINFO_ID, (uint8)PORT_E_PARAM_POINTER);
  411. }
  412. else
  413. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  414. {
  415. (versioninfo)->vendorID = (uint16)PORT_VENDOR_ID_H;
  416. (versioninfo)->moduleID = (uint16)PORT_MODULE_ID;
  417. (versioninfo)->sw_major_version = (uint8)PORT_SW_MAJOR_VERSION_H;
  418. (versioninfo)->sw_minor_version = (uint8)PORT_SW_MINOR_VERSION_H;
  419. (versioninfo)->sw_patch_version = (uint8)PORT_SW_PATCH_VERSION_H;
  420. }
  421. }
  422. #endif /* (STD_ON == PORT_VERSION_INFO_API) */
  423. #ifdef PORT_SET_AS_UNUSED_PIN_API
  424. #if (STD_ON == PORT_SET_AS_UNUSED_PIN_API)
  425. /**
  426. * @brief Set as unused pin.
  427. * @details This function shall configure the referenced pin with all
  428. * the properties specified in the NotUsedPortPin container.
  429. * @pre @p Port_Init() must have been called first.
  430. *
  431. * @implements Port_SetAsUnusedPin_Activity
  432. */
  433. void Port_SetAsUnusedPin
  434. (
  435. Port_PinType Pin
  436. )
  437. {
  438. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  439. uint8 CoreId;
  440. CoreId = (uint8)Port_GetCoreID();
  441. /* Check if port is initialized */
  442. if (NULL_PTR == Port_pConfig)
  443. {
  444. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETASUNUSEDPIN_ID, (uint8)PORT_E_UNINIT);
  445. }
  446. else if (Pin >= (Port_PinType)Port_pConfig->u16NumPins)
  447. {
  448. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETASUNUSEDPIN_ID, (uint8)PORT_E_PARAM_PIN);
  449. }
  450. /* Check if this function was called with wrong core */
  451. else if ((uint32)1 != (((Port_pConfig->pau32Port_PinToPartitionMap[Pin])&((uint32)1 << CoreId)) >> CoreId))
  452. {
  453. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETASUNUSEDPIN_ID, (uint8)PORT_E_PARAM_CONFIG);
  454. }
  455. /* Check port pin mode Unchangeable */
  456. else if(FALSE == Port_pConfig->pUsedPadConfig[Pin].bMC)
  457. {
  458. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETASUNUSEDPIN_ID, (uint8)PORT_E_MODE_UNCHANGEABLE);
  459. }
  460. else
  461. #endif
  462. {
  463. Port_Ipw_SetAsUnusedPin(Pin, Port_pConfig);
  464. }
  465. }
  466. /**
  467. * @brief Set as used pin.
  468. * @details This function shall configure the referenced pin with
  469. * all the properties that where set during the Port_Init operation.
  470. * @pre @p Port_Init() must have been called first.
  471. *
  472. * @implements Port_SetAsUsedPin_Activity
  473. */
  474. void Port_SetAsUsedPin
  475. (
  476. Port_PinType Pin
  477. )
  478. {
  479. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  480. uint8 CoreId;
  481. CoreId = (uint8)Port_GetCoreID();
  482. /* Check if port is initialized */
  483. if (NULL_PTR == Port_pConfig)
  484. {
  485. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETASUSEDPIN_ID, (uint8)PORT_E_UNINIT);
  486. }
  487. /* Check port pin validity */
  488. else if (Pin >= (Port_PinType)Port_pConfig->u16NumPins)
  489. {
  490. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETASUSEDPIN_ID, (uint8)PORT_E_PARAM_PIN);
  491. }
  492. else if ((uint32)1 != (((Port_pConfig->pau32Port_PinToPartitionMap[Pin])&((uint32)1 << CoreId)) >> CoreId))
  493. {
  494. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETASUSEDPIN_ID, (uint8)PORT_E_PARAM_CONFIG);
  495. }
  496. /* Check port pin mode Unchangeable */
  497. else if(FALSE == Port_pConfig->pUsedPadConfig[Pin].bMC)
  498. {
  499. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_SETASUSEDPIN_ID, (uint8)PORT_E_MODE_UNCHANGEABLE);
  500. }
  501. else
  502. #endif
  503. {
  504. Port_Ipw_SetAsUsedPin(Pin, Port_pConfig);
  505. }
  506. }
  507. #endif /* (STD_ON == PORT_SET_AS_UNUSED_PIN_API) */
  508. #endif
  509. #ifdef PORT_RESET_PIN_MODE_API
  510. #if (STD_ON == PORT_RESET_PIN_MODE_API)
  511. /**
  512. * @brief Reset Pin Mode.
  513. * @details This function shall revert the port pin mode of the referenced pin
  514. * to the value that was set by Port_Init operation.
  515. * @pre @p Port_Init() must have been called first.
  516. *
  517. * @implements Port_ResetPinMode_Activity
  518. */
  519. void Port_ResetPinMode
  520. (
  521. Port_PinType Pin
  522. )
  523. {
  524. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  525. uint8 CoreId;
  526. CoreId = (uint8)Port_GetCoreID();
  527. /* Check if port is initialized */
  528. if (NULL_PTR == Port_pConfig)
  529. {
  530. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_RESETPINMODE_ID, (uint8)PORT_E_UNINIT);
  531. }
  532. /* Check port pin validity */
  533. else if (Pin >= (Port_PinType)Port_pConfig->u16NumPins)
  534. {
  535. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_RESETPINMODE_ID, (uint8)PORT_E_PARAM_PIN);
  536. }
  537. /* Check port pin validity */
  538. else if ((uint32)1 != (((Port_pConfig->pau32Port_PinToPartitionMap[Pin])&((uint32)1 << CoreId)) >> CoreId))
  539. {
  540. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_RESETPINMODE_ID, (uint8)PORT_E_PARAM_CONFIG);
  541. }
  542. /* Check port pin mode Unchangeable */
  543. else if(FALSE == Port_pConfig->pUsedPadConfig[Pin].bMC)
  544. {
  545. (void)Det_ReportError((uint16)PORT_MODULE_ID, (uint8)PORT_INSTANCE_ID, (uint8)PORT_RESETPINMODE_ID, (uint8)PORT_E_MODE_UNCHANGEABLE);
  546. }
  547. else
  548. #endif
  549. {
  550. Port_Ipw_ResetPinMode(Pin, Port_pConfig);
  551. }
  552. }
  553. #endif /* (STD_ON == PORT_RESET_PIN_MODE_API) */
  554. #endif
  555. #define PORT_STOP_SEC_CODE
  556. #include "Port_MemMap.h"
  557. #ifdef __cplusplus
  558. }
  559. #endif
  560. /** @} */
  561. /* End of File */