Port_Ipw.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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_Ipw.c
  26. * @internal
  27. * @addtogroup Port_IPW
  28. * @{
  29. */
  30. #ifdef __cplusplus
  31. extern "C"{
  32. #endif
  33. /*=================================================================================================
  34. * INCLUDE FILES
  35. * 1) system and project includes
  36. * 2) needed interfaces from external units
  37. * 3) internal and external interfaces from this unit
  38. =================================================================================================*/
  39. #include "Port_Ipw.h"
  40. #include "Port.h"
  41. #include "SchM_Port.h"
  42. /*=================================================================================================
  43. SOURCE FILE VERSION INFORMATION
  44. ==================================================================================================*/
  45. /**
  46. * @brief Parameters that shall be published within the Port driver header file and also in the
  47. * module description file
  48. * @details The integration of incompatible files shall be avoided.
  49. *
  50. */
  51. #define PORT_VENDOR_ID_IPW_C 43
  52. #define PORT_AR_RELEASE_MAJOR_VERSION_IPW_C 4
  53. #define PORT_AR_RELEASE_MINOR_VERSION_IPW_C 4
  54. #define PORT_AR_RELEASE_REVISION_VERSION_IPW_C 0
  55. #define PORT_SW_MAJOR_VERSION_IPW_C 1
  56. #define PORT_SW_MINOR_VERSION_IPW_C 0
  57. #define PORT_SW_PATCH_VERSION_IPW_C 0
  58. /*=================================================================================================
  59. * FILE VERSION CHECKS
  60. =================================================================================================*/
  61. /* Check if the files Port_Ipw.c and Port_Ipw.h are of the same vendor */
  62. #if (PORT_VENDOR_ID_IPW_C != PORT_VENDOR_ID_IPW_H)
  63. #error "Port_Ipw.c and Port_Ipw.h have different vendor ids"
  64. #endif
  65. /* Check if the files Port_Ipw.c and Port_Ipw.h are of the same Autosar version */
  66. #if ((PORT_AR_RELEASE_MAJOR_VERSION_IPW_C != PORT_AR_RELEASE_MAJOR_VERSION_IPW_H) || \
  67. (PORT_AR_RELEASE_MINOR_VERSION_IPW_C != PORT_AR_RELEASE_MINOR_VERSION_IPW_H) || \
  68. (PORT_AR_RELEASE_REVISION_VERSION_IPW_C != PORT_AR_RELEASE_REVISION_VERSION_IPW_H) \
  69. )
  70. #error "AutoSar Version Numbers of Port_Ipw.c and Port_Ipw.h are different"
  71. #endif
  72. /* Check if the files Port_Ipw.c and Port_Ipw.h are of the same software version */
  73. #if ((PORT_SW_MAJOR_VERSION_IPW_C != PORT_SW_MAJOR_VERSION_IPW_H) || \
  74. (PORT_SW_MINOR_VERSION_IPW_C != PORT_SW_MINOR_VERSION_IPW_H) || \
  75. (PORT_SW_PATCH_VERSION_IPW_C != PORT_SW_PATCH_VERSION_IPW_H) \
  76. )
  77. #error "Software Version Numbers of Port_Ipw.c and Port_Ipw.h are different"
  78. #endif
  79. /* Check if the files Port_Ipw.c and Port.h are of the same vendor */
  80. #if (PORT_VENDOR_ID_IPW_C != PORT_VENDOR_ID_H)
  81. #error "Port_Ipw.c and Port.h have different vendor ids"
  82. #endif
  83. /* Check if the files Port_Ipw.c and Port.h are of the same Autosar version */
  84. #if ((PORT_AR_RELEASE_MAJOR_VERSION_IPW_C != PORT_AR_RELEASE_MAJOR_VERSION_H) || \
  85. (PORT_AR_RELEASE_MINOR_VERSION_IPW_C != PORT_AR_RELEASE_MINOR_VERSION_H) || \
  86. (PORT_AR_RELEASE_REVISION_VERSION_IPW_C != PORT_AR_RELEASE_REVISION_VERSION_H) \
  87. )
  88. #error "AutoSar Version Numbers of Port_Ipw.c and Port.h are different"
  89. #endif
  90. /* Check if the files Port_Ipw.c and Port.h are of the same software version */
  91. #if ((PORT_SW_MAJOR_VERSION_IPW_C != PORT_SW_MAJOR_VERSION_H) || \
  92. (PORT_SW_MINOR_VERSION_IPW_C != PORT_SW_MINOR_VERSION_H) || \
  93. (PORT_SW_PATCH_VERSION_IPW_C != PORT_SW_PATCH_VERSION_H) \
  94. )
  95. #error "Software Version Numbers of Port_Ipw.c and Port.h are different"
  96. #endif
  97. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  98. /* Check if the files Port_Ipw.c and SchM_Port.h are of the same version */
  99. #if ((PORT_AR_RELEASE_MAJOR_VERSION_IPW_C != SCHM_PORT_AR_RELEASE_MAJOR_VERSION) || \
  100. (PORT_AR_RELEASE_MINOR_VERSION_IPW_C != SCHM_PORT_AR_RELEASE_MINOR_VERSION) \
  101. )
  102. #error "AutoSar Version Numbers of Port_Ipw.c and SchM_Port.h are different"
  103. #endif
  104. #endif
  105. /*=================================================================================================
  106. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  107. =================================================================================================*/
  108. /*=================================================================================================
  109. * LOCAL MACROS
  110. =================================================================================================*/
  111. /*=================================================================================================
  112. * LOCAL CONSTANTS
  113. =================================================================================================*/
  114. /*=================================================================================================
  115. * LOCAL VARIABLES
  116. =================================================================================================*/
  117. /*=================================================================================================
  118. * GLOBAL CONSTANTS
  119. =================================================================================================*/
  120. /*=================================================================================================
  121. GLOBAL VARIABLES
  122. =================================================================================================*/
  123. #define PORT_START_SEC_VAR_CLEARED_16
  124. #include "Port_MemMap.h"
  125. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  126. #if ((STD_ON == PORT_SET_PIN_DIRECTION_API) || (STD_ON == PORT_SET_PIN_MODE_API) || \
  127. (defined(PORT_SET_2_PINS_DIRECTION_API) && (STD_ON == PORT_SET_2_PINS_DIRECTION_API)) \
  128. )
  129. /**
  130. * @brief Segment descriptor for data arranged in array
  131. * @detail Port_Ipw_au16GpioDirChangeability variable is only used by Port_Ipw_SetPinDirection and Port_Ipw_SetPinMode
  132. * functions
  133. */
  134. static uint16 Port_Ipw_au16GpioDirChangeability[PAD_16BLOCK_NO_U8];
  135. #endif /* ((STD_ON == PORT_SET_PIN_DIRECTION_API) || (STD_ON == PORT_SET_PIN_MODE_API) || \
  136. (defined(PORT_SET_2_PINS_DIRECTION_API) && (STD_ON == PORT_SET_2_PINS_DIRECTION_API)) \
  137. ) */
  138. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  139. #define PORT_STOP_SEC_VAR_CLEARED_16
  140. #include "Port_MemMap.h"
  141. /*=================================================================================================
  142. * LOCAL FUNCTION PROTOTYPES
  143. =================================================================================================*/
  144. #define PORT_START_SEC_CODE
  145. #include "Port_MemMap.h"
  146. static inline void Port_Ipw_Init_UnusedPins
  147. (
  148. const Port_ConfigType * pConfigPtr
  149. );
  150. #if defined(PORT_SET_2_PINS_DIRECTION_API) && (STD_ON == PORT_SET_2_PINS_DIRECTION_API)
  151. static inline void Port_Ipw_Set2PinsSamePort
  152. (
  153. uint32 Pin1,
  154. uint32 Pin2,
  155. Port_PinDirectionType eDirection
  156. );
  157. static inline void Port_Ipw_Set2PinsDifferentPorts
  158. (
  159. uint32 Pin1,
  160. uint32 Pin2,
  161. Port_PinDirectionType eDirection
  162. );
  163. #endif /* defined(PORT_SET_2_PINS_DIRECTION_API) && (STD_ON == PORT_SET_2_PINS_DIRECTION_API) */
  164. /*=================================================================================================
  165. LOCAL FUNCTIONS
  166. =================================================================================================*/
  167. /**
  168. * @brief Initializes the PORT IP Driver
  169. * @details The function Port_Ipw_Init_UnusedPins will initialize ALL Unused Port Pins with the
  170. * configuration set pointed to by the parameter ConfigPtr.
  171. *
  172. * @param[in] pConfigPtr A pointer to the structure which contains initialization parameters
  173. *
  174. * @return none
  175. *
  176. * @pre none
  177. * @post No function of the driver is executed without the initialization of the module.
  178. *
  179. *
  180. */
  181. static inline void Port_Ipw_Init_UnusedPins
  182. (
  183. const Port_ConfigType * pConfigPtr
  184. )
  185. {
  186. uint16 u16PinIndex;
  187. uint16 u16NumUnusedPins = (uint16)(pConfigPtr->u16NumUnusedPins);
  188. uint8 u8LocalPDO = pConfigPtr->pUnusedPadConfig->u8PDO;
  189. uint32 u32LocalPCR = pConfigPtr->pUnusedPadConfig->u32PCR;
  190. Port_PinDirectionType eLocalPDDIR = pConfigPtr->pUnusedPadConfig->ePadDir;
  191. /* Initialize All UnUsed pins */
  192. for (u16PinIndex = (uint16)0U; u16PinIndex < u16NumUnusedPins; u16PinIndex++)
  193. {
  194. /* Check if the direction of the pin is OUTPUT. In this case the driver needs to set the output level too */
  195. if (PORT_PIN_OUT == eLocalPDDIR)
  196. {
  197. /* Set pin to High value */
  198. if (PORT_PIN_LEVEL_HIGH_U8 == u8LocalPDO)
  199. {
  200. Port_Ci_Port_Ip_SetPSOR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(pConfigPtr->pUnusedPads[u16PinIndex])], ((uint32)1U << GPIO_CHANNEL_U32(pConfigPtr->pUnusedPads[u16PinIndex])));
  201. }
  202. else if (PORT_PIN_LEVEL_LOW_U8 == u8LocalPDO)
  203. {
  204. Port_Ci_Port_Ip_SetPCOR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(pConfigPtr->pUnusedPads[u16PinIndex])], ((uint32)1U << GPIO_CHANNEL_U32(pConfigPtr->pUnusedPads[u16PinIndex])));
  205. }
  206. else
  207. {
  208. /* No action to be done */
  209. }
  210. Port_Ci_Port_Ip_SetPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(pConfigPtr->pUnusedPads[u16PinIndex])], ((uint32)1U << GPIO_CHANNEL_U32(pConfigPtr->pUnusedPads[u16PinIndex])));
  211. }
  212. /* The direction of pin is INPUT or HIGH Z */
  213. else
  214. {
  215. Port_Ci_Port_Ip_ClearPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(pConfigPtr->pUnusedPads[u16PinIndex])], ((uint32)1U << GPIO_CHANNEL_U32(pConfigPtr->pUnusedPads[u16PinIndex])));
  216. #ifndef FEATURE_PORT_CI_PORT_IP_S32K11X_DERIVATIVE
  217. /* Check if the pin is HIGH-Z. In this case the driver needs to disable port input in PIDR register of GPIO IP */
  218. if (PORT_PIN_HIGH_Z == eLocalPDDIR)
  219. {
  220. Port_Ci_Port_Ip_SetPIDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(pConfigPtr->pUnusedPads[u16PinIndex])], ((uint32)1U << GPIO_CHANNEL_U32(pConfigPtr->pUnusedPads[u16PinIndex])));
  221. }
  222. #endif
  223. }
  224. /* Write PCR configuration from Configuration tool */
  225. Port_Ci_Port_Ip_SetPCR(Port_au32PortCiPortBaseAddr[GPIO_PORT_U32(pConfigPtr->pUnusedPads[u16PinIndex])], GPIO_CHANNEL_U32(pConfigPtr->pUnusedPads[u16PinIndex]), u32LocalPCR);
  226. }
  227. }
  228. #if defined(PORT_SET_2_PINS_DIRECTION_API) && (STD_ON == PORT_SET_2_PINS_DIRECTION_API)
  229. /**
  230. * @brief Sets the port direction for 2 pins which are in the same port.
  231. * @details The function Port_Ipw_Set2PinsSamePort will set 2 pins direction which are in the same port.
  232. *
  233. * @param[in] Pin1Index Pin1 ID number
  234. * @param[in] Pin2Index Pin2 ID number
  235. * @param[in] eDirection Port Pin direction
  236. *
  237. * @return none
  238. *
  239. * @pre Port_Init must have been called.
  240. * @post none
  241. *
  242. *
  243. */
  244. static inline void Port_Ipw_Set2PinsSamePort
  245. (
  246. uint32 Pin1,
  247. uint32 Pin2,
  248. Port_PinDirectionType eDirection
  249. )
  250. {
  251. /* Configures Port Pins as Output */
  252. if (PORT_PIN_OUT == eDirection)
  253. {
  254. Port_Ci_Port_Ip_SetPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin1)], (((uint32)1UL << GPIO_CHANNEL_U32(Pin1)) | ((uint32)1UL << GPIO_CHANNEL_U32(Pin2))));
  255. }
  256. /* Configures Port Pins as Input or High-Z */
  257. else if ((PORT_PIN_IN == eDirection) || (PORT_PIN_HIGH_Z == eDirection))
  258. {
  259. Port_Ci_Port_Ip_ClearPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin1)], (((uint32)1U << GPIO_CHANNEL_U32(Pin1)) | ((uint32)1U << GPIO_CHANNEL_U32(Pin2))));
  260. #ifndef FEATURE_PORT_CI_PORT_IP_S32K11X_DERIVATIVE
  261. /* Check if the pin is HIGH-Z. In this case the driver needs to disable port input in PIDR register of GPIO IP */
  262. if (PORT_PIN_HIGH_Z == eDirection)
  263. {
  264. Port_Ci_Port_Ip_SetPIDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin1)], (((uint32)1UL << GPIO_CHANNEL_U32(Pin1)) | ((uint32)1UL << GPIO_CHANNEL_U32(Pin2))));
  265. }
  266. #endif
  267. }
  268. else
  269. {
  270. /* Do nothing */
  271. }
  272. }
  273. /**
  274. * @brief Sets the port direction for 2 pins which are in the different ports.
  275. * @details The function Port_Ipw_Set2PinsDifferentPorts will set 2 pins direction which are in the different ports.
  276. *
  277. * @param[in] Pin1Index Pin1 ID number
  278. * @param[in] Pin2Index Pin2 ID number
  279. * @param[in] eDirection Port Pin direction
  280. *
  281. * @return none
  282. *
  283. * @pre Port_Init must have been called.
  284. * @post none
  285. *
  286. *
  287. */
  288. static inline void Port_Ipw_Set2PinsDifferentPorts
  289. (
  290. uint32 Pin1,
  291. uint32 Pin2,
  292. Port_PinDirectionType eDirection
  293. )
  294. {
  295. /* Configures Port Pins as Output */
  296. if (PORT_PIN_OUT == eDirection)
  297. {
  298. Port_Ci_Port_Ip_SetPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin1)], ((uint32)1UL << GPIO_CHANNEL_U32(Pin1)));
  299. Port_Ci_Port_Ip_SetPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin2)], ((uint32)1UL << GPIO_CHANNEL_U32(Pin2)));
  300. }
  301. /* Configures Port Pins as Input or High-Z */
  302. else if ((PORT_PIN_IN == eDirection) || (PORT_PIN_HIGH_Z == eDirection))
  303. {
  304. Port_Ci_Port_Ip_ClearPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin1)], ((uint32)1UL << GPIO_CHANNEL_U32(Pin1)));
  305. Port_Ci_Port_Ip_ClearPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin2)], ((uint32)1UL << GPIO_CHANNEL_U32(Pin2)));
  306. #ifndef FEATURE_PORT_CI_PORT_IP_S32K11X_DERIVATIVE
  307. /* Check if the pin is HIGH-Z. In this case the driver needs to disable port input in PIDR register of GPIO IP */
  308. if (PORT_PIN_HIGH_Z == eDirection)
  309. {
  310. Port_Ci_Port_Ip_SetPIDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin1)], ((uint32)1UL << GPIO_CHANNEL_U32(Pin1)));
  311. Port_Ci_Port_Ip_SetPIDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin2)], ((uint32)1UL << GPIO_CHANNEL_U32(Pin2)));
  312. }
  313. #endif
  314. }
  315. else
  316. {
  317. /* Do nothing */
  318. }
  319. }
  320. #endif /* defined(PORT_SET_2_PINS_DIRECTION_API) && (STD_ON == PORT_SET_2_PINS_DIRECTION_API) */
  321. /*=================================================================================================
  322. GLOBAL FUNCTIONS
  323. =================================================================================================*/
  324. /**
  325. * @brief Initializes the PORT IP Driver
  326. * @details The function Port_Ipw_Init will initialize ALL ports and port pins with the
  327. * configuration set pointed to by the parameter ConfigPtr.
  328. *
  329. * @param[in] pConfigPtr A pointer to the structure which contains initialization parameters
  330. *
  331. * @return none
  332. *
  333. * @pre none
  334. * @post No function of the driver is executed without the initialisation of the module.
  335. *
  336. *
  337. */
  338. void Port_Ipw_Init
  339. (
  340. const Port_ConfigType * pConfigPtr
  341. )
  342. {
  343. uint16 u16PinIndex;
  344. uint8 u8NumDigFilterPorts = (uint8)(pConfigPtr->u8NumDigitalFilterPorts);
  345. uint8 u8Port;
  346. /* Initialize all configured digital filter ports. Use u16PinIndex variable as counter, even if we loop on a uint8 variable */
  347. for (u16PinIndex = (uint16)0U; u16PinIndex < (uint16)u8NumDigFilterPorts; u16PinIndex++)
  348. {
  349. u8Port = pConfigPtr->pDigitalFilterConfig[u16PinIndex].u8Port;
  350. /* Set digital filter clock and width for the current port */
  351. Port_Ci_Port_Ip_ConfigDigitalFilter(Port_au32PortCiPortBaseAddr[u8Port], &(pConfigPtr->pDigitalFilterConfig[u16PinIndex]));
  352. /* Enable digital filter for the pins selected by the user for the current port */
  353. Port_Ci_Port_Ip_SetDFER(Port_au32PortCiPortBaseAddr[u8Port], (uint32)(pConfigPtr->pDigitalFilterConfig[u16PinIndex].u32PinMask));
  354. }
  355. (void)Port_Ci_Port_Ip_Init(NUM_OF_CONFIGURED_PINS, pConfigPtr->IpConfigPtr);
  356. /* Initialize All Unused Port Pins */
  357. Port_Ipw_Init_UnusedPins(pConfigPtr);
  358. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  359. #if ((STD_ON == PORT_SET_PIN_DIRECTION_API) || (STD_ON == PORT_SET_PIN_MODE_API) || \
  360. (defined(PORT_SET_2_PINS_DIRECTION_API) && (STD_ON == PORT_SET_2_PINS_DIRECTION_API)) \
  361. )
  362. /* Port_Ipw_au16GpioDirChangeability is only used by Port_Ci_Port_Ip_SetPinDirection, Port_Ci_Port_Ip_Set2PinsDirection
  363. and Port_Ci_Port_Ip_SetPinMode functions */
  364. /* Initialize the Array with Change Direction Flags for GPIO */
  365. for (u16PinIndex = (uint16)0U; u16PinIndex < PAD_16BLOCK_NO_U8; u16PinIndex++)
  366. {
  367. Port_Ipw_au16GpioDirChangeability[u16PinIndex] = (uint16)0UL;
  368. }
  369. #endif /* ((STD_ON == PORT_SET_PIN_DIRECTION_API) || (STD_ON == PORT_SET_PIN_MODE_API) || \
  370. (defined(PORT_SET_2_PINS_DIRECTION_API) && (STD_ON == PORT_SET_2_PINS_DIRECTION_API)) \
  371. ) */
  372. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  373. }
  374. #if (STD_ON == PORT_SET_PIN_DIRECTION_API) || (STD_ON == PORT_SET_PIN_MODE_API)
  375. /**
  376. * @brief Sets the port pin direction
  377. * @details Sets the pin direction at runtime, changing it only if the pin is configured as
  378. * changeable.
  379. *
  380. * @param[in] PinIndex Pin ID number
  381. * @param[in] eDirection Port Pin direction
  382. * @param[in] pConfigPtr A pointer to the structure which contains initialization parameters
  383. *
  384. * @return Error code after execution
  385. * @retval 0 No error occured
  386. * @retval 1 Pin direction cannot be changed
  387. *
  388. * @pre Port_Init must have been called
  389. * @post none
  390. *
  391. *
  392. */
  393. Std_ReturnType Port_Ipw_SetPinDirection
  394. (
  395. Port_PinType PinIndex,
  396. Port_PinDirectionType eDirection,
  397. const Port_ConfigType * pConfigPtr
  398. )
  399. {
  400. /* Point to the Port Pin PCR register address */
  401. uint16 Pin = pConfigPtr->pUsedPadConfig[PinIndex].Pin;
  402. /* Return value */
  403. Std_ReturnType PinDirError = (Std_ReturnType)E_OK;
  404. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  405. /* Bit Offset and Table value for change direction flag word */
  406. uint8 u8PinDescBitOffset = (uint8)(Pin & PORT_CI_BIT_OFFSET_MASK_U8);
  407. /* Number of block 16 */
  408. uint16 u16PinChangeDirFlagWord = Port_Ipw_au16GpioDirChangeability[(uint8)(Pin >> 4)];
  409. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  410. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  411. /* Check the Direction changeability option */
  412. if ((TRUE == pConfigPtr->pUsedPadConfig[PinIndex].bDC) || ((uint16)0 != (u16PinChangeDirFlagWord & (uint16)(1UL << u8PinDescBitOffset))))
  413. {
  414. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  415. /* Configures Port Pin as Output */
  416. if (PORT_PIN_OUT == eDirection)
  417. {
  418. Port_Ci_Port_Ip_SetPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (uint32)(1UL << GPIO_CHANNEL_U32(Pin)));
  419. }
  420. /* Configures Port Pin as Input or High-Z*/
  421. else if ((PORT_PIN_IN == eDirection) || (PORT_PIN_HIGH_Z == eDirection))
  422. {
  423. Port_Ci_Port_Ip_ClearPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (uint32)(1UL << GPIO_CHANNEL_U32(Pin)));
  424. #ifndef FEATURE_PORT_CI_PORT_IP_S32K11X_DERIVATIVE
  425. /* Check if the pin is HIGH-Z. In this case the driver needs to disable port input in PIDR register of GPIO IP*/
  426. if (PORT_PIN_HIGH_Z == eDirection)
  427. {
  428. Port_Ci_Port_Ip_SetPIDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (uint32)(1UL << GPIO_CHANNEL_U32(Pin)));
  429. }
  430. #endif
  431. }
  432. else
  433. {
  434. /* Do nothing */
  435. }
  436. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  437. }
  438. /* Direction changeability is NOT supported */
  439. else
  440. {
  441. PinDirError = (Std_ReturnType)E_NOT_OK;
  442. }
  443. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  444. return PinDirError;
  445. }
  446. #endif /* (STD_ON == PORT_SET_PIN_DIRECTION_API) || (STD_ON == PORT_SET_PIN_MODE_API) */
  447. #if defined(PORT_SET_2_PINS_DIRECTION_API) && (STD_ON == PORT_SET_2_PINS_DIRECTION_API)
  448. /**
  449. * @brief Sets the port direction for 2 pins
  450. * @details Sets the pin direction at runtime, changing it only if the pins are configured as
  451. * changeable.
  452. *
  453. * @param[in] Pin1Index Pin1 ID number
  454. * @param[in] Pin2Index Pin2 ID number
  455. * @param[in] eDirection Port Pin direction
  456. * @param[in] pConfigPtr A pointer to the structure which contains initialization parameters
  457. *
  458. * @return Error code after execution
  459. * @retval 0 No error occured
  460. * @retval 1 Pin direction cannot be changed
  461. *
  462. * @pre Port_Init must have been called
  463. * @post none
  464. *
  465. *
  466. */
  467. Std_ReturnType Port_Ipw_Set2PinsDirection
  468. (
  469. Port_PinType Pin1Index,
  470. Port_PinType Pin2Index,
  471. Port_PinDirectionType eDirection,
  472. const Port_ConfigType * pConfigPtr
  473. )
  474. {
  475. /* Point to the Port Pin PCR register address */
  476. uint32 Pin1 = pConfigPtr->pUsedPadConfig[Pin1Index].Pin;
  477. uint32 Pin2 = pConfigPtr->pUsedPadConfig[Pin2Index].Pin;
  478. /* Return value */
  479. Std_ReturnType PinDirError = (Std_ReturnType)E_OK;
  480. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  481. /* Bit Offsets and Table values for change direction flag words */
  482. uint8 u8PinDescBitOffset1 = (uint8)(Pin1 & PORT_CI_BIT_OFFSET_MASK_U8);
  483. uint16 u16PinChangeDirFlagWord1 = Port_Ipw_au16GpioDirChangeability[(uint8)(Pin1 >> 4)];
  484. uint8 u8PinDescBitOffset2 = (uint8)(Pin2 & PORT_CI_BIT_OFFSET_MASK_U8);
  485. uint16 u16PinChangeDirFlagWord2 = Port_Ipw_au16GpioDirChangeability[(uint8)(Pin2 >> 4)];
  486. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  487. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  488. /* Check the Direction changeability option */
  489. if (((TRUE == pConfigPtr->pUsedPadConfig[Pin1Index].bDC) || ((uint16)0 != (u16PinChangeDirFlagWord1 & (uint16)(1UL << u8PinDescBitOffset1)))) && \
  490. (((boolean)TRUE == pConfigPtr->pUsedPadConfig[Pin2Index].bDC) || ((uint16)0 != (u16PinChangeDirFlagWord2 & (uint16)(1UL << u8PinDescBitOffset2)))) \
  491. )
  492. {
  493. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  494. /* Check if the pins belong to the same port. In this case, we need to write the PDDR register once to set direction of both pins in the same time */
  495. if (GPIO_PORT_U32(Pin1) == GPIO_PORT_U32(Pin2))
  496. {
  497. /* Sets the port direction for 2 pins which are in the same port. */
  498. Port_Ipw_Set2PinsSamePort(Pin1, Pin2, eDirection);
  499. }
  500. else
  501. {
  502. /* Sets the port direction for 2 pins which are in the different ports. */
  503. Port_Ipw_Set2PinsDifferentPorts(Pin1, Pin2, eDirection);
  504. }
  505. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  506. }
  507. /* Direction changeability is NOT supported */
  508. else
  509. {
  510. PinDirError = (Std_ReturnType)E_NOT_OK;
  511. }
  512. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  513. return PinDirError;
  514. }
  515. #endif /* defined(PORT_SET_2_PINS_DIRECTION_API) && (STD_ON == PORT_SET_2_PINS_DIRECTION_API) */
  516. #if (STD_ON == PORT_SET_PIN_MODE_API)
  517. /**
  518. * @brief Sets the port pin mode.
  519. * @details The function will set the port pin mode of the referenced pin during runtime
  520. *
  521. * @param[in]
  522. * @param[in]
  523. *
  524. * @return Error code after execution
  525. * @retval 0 No error occured
  526. * @retval PORT_E_MODE_UNCHANGEABLE Pin mode cannot be changed
  527. * @retval PORT_E_PARAM_INVALID_MODE Invalid mode
  528. *
  529. * @pre Port_Init must have been called
  530. * @post none
  531. *
  532. *
  533. */
  534. Std_ReturnType Port_Ipw_SetPinMode
  535. (
  536. Port_PinType PinIndex,
  537. Port_PinModeType PinMode,
  538. const Port_ConfigType * pConfigPtr
  539. )
  540. {
  541. Std_ReturnType PinModeError = (Std_ReturnType)0UL;
  542. uint16 PinPad = pConfigPtr->pUsedPadConfig[PinIndex].Pin;
  543. Port_PinModeType PinCfgRegValue = (Port_PinModeType)PinMode;
  544. uint16 u16PinDescWord;
  545. uint16 u16PinDescBitOffset;
  546. /* Variable used to clear and updated PCR register */
  547. uint32 u32LocalPCR;
  548. if (PAD_MODE_OPTIONS_U8 <= PinMode)
  549. {
  550. PinModeError = PORT_E_PARAM_INVALID_MODE;
  551. }
  552. else
  553. {
  554. Port_PinDirectionType ePadDirection = PORT_PIN_DISABLED;
  555. /* Bit offset of Pin index inside the pin description matrix */
  556. u16PinDescBitOffset = PinPad & PORT_MODE_BIT_OFFSET_MASK_U8;
  557. /* Selected word inside the pin description matrix */
  558. u16PinDescWord = (uint16)Port_au16PinDescription[(uint8)PinMode][PinPad >> 4U];
  559. /* Check if desired mode is valid for selected pin */
  560. if ((u16PinDescWord & ((uint16)1UL<<u16PinDescBitOffset)) != (uint16)0U)
  561. {
  562. switch(PinMode)
  563. {
  564. case PORT_GPIO_MODE:
  565. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  566. Port_Ipw_SetGpioDirChangeability(PinPad, TRUE);
  567. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  568. ePadDirection = pConfigPtr->pUsedPadConfig[PinIndex].ePadDir;
  569. #if (STD_OFF == PORT_SETPINMODE_DOES_NOT_TOUCH_GPIO_LEVEL)
  570. if ((PORT_PIN_IN != ePadDirection) && (PORT_PIN_HIGH_Z != ePadDirection))
  571. {
  572. Port_Ipw_SetGpioPadOutput(PinIndex, pConfigPtr);
  573. }
  574. #endif /* (STD_OFF == PORT_SETPINMODE_DOES_NOT_TOUCH_GPIO_LEVEL) */
  575. (void)Port_Ipw_SetPinDirection(PinIndex, ePadDirection, pConfigPtr);
  576. break;
  577. default:
  578. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  579. /* All the ALT modes except GPIO*/
  580. Port_Ipw_SetGpioDirChangeability(PinPad,FALSE);
  581. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  582. break;
  583. }
  584. /* Sets the port pin mode */
  585. u32LocalPCR = Port_Ci_Port_Ip_ReadPCR(Port_au32PortCiPortBaseAddr[GPIO_PORT_U32(PinPad)], GPIO_CHANNEL_U32(PinPad));
  586. u32LocalPCR &= ~(PORT_CI_PCR_ALT_MODE_U32);
  587. u32LocalPCR |= ((uint32)PinCfgRegValue << PORT_CI_PCR_ALT_MODE_OFFSET_U32);
  588. Port_Ci_Port_Ip_SetPCR(Port_au32PortCiPortBaseAddr[GPIO_PORT_U32(PinPad)], GPIO_CHANNEL_U32(PinPad), u32LocalPCR);
  589. }
  590. else
  591. {
  592. PinModeError = PORT_E_PARAM_INVALID_MODE;
  593. }
  594. }
  595. return PinModeError;
  596. }
  597. #endif /* (STD_ON == PORT_SET_PIN_MODE_API) */
  598. #if (STD_ON == PORT_SET_PIN_MODE_API)
  599. #if (STD_ON == PORT_DEV_ERROR_DETECT)
  600. /**
  601. * @brief Sets or resets the direction changeability for pads in GPIO mode.
  602. * @details The function will update the direction changeability for the pads whose mode is changed
  603. *
  604. * @param[in] PadID Pin ID number.
  605. * @param[in] bStatus The new value true or false for direction changeability.
  606. *
  607. * @return None
  608. *
  609. * @pre none
  610. * @post none
  611. *
  612. *
  613. */
  614. void Port_Ipw_SetGpioDirChangeability
  615. (
  616. uint16 PadID,
  617. boolean bStatus
  618. )
  619. {
  620. /* Pin description variables */
  621. uint8 u8PinBitOffset;
  622. uint16 u16PinDirFlagWord;
  623. /* Enter critical region */
  624. SchM_Enter_Port_PORT_EXCLUSIVE_AREA_00();
  625. /* Bit offset of Pin index inside the pin description matrix */
  626. u8PinBitOffset = (uint8)((uint8)PadID & PORT_CI_BIT_OFFSET_MASK_U8);
  627. u16PinDirFlagWord = Port_Ipw_au16GpioDirChangeability[(uint8)((uint8)PadID >> 4)];
  628. if (TRUE == bStatus)
  629. {
  630. /* Set the change direction flag */
  631. u16PinDirFlagWord |= (uint16)(1UL<<u8PinBitOffset);
  632. }
  633. else
  634. {
  635. /* Reset the change direction flag */
  636. u16PinDirFlagWord &= (uint16)(~((uint16)(1UL<<u8PinBitOffset)));
  637. }
  638. Port_Ipw_au16GpioDirChangeability[(uint8)((uint8)PadID >> 4)] = u16PinDirFlagWord;
  639. /* Exit critical region */
  640. SchM_Exit_Port_PORT_EXCLUSIVE_AREA_00();
  641. }
  642. #endif /* (STD_ON == PORT_DEV_ERROR_DETECT) */
  643. #if (STD_OFF == PORT_SETPINMODE_DOES_NOT_TOUCH_GPIO_LEVEL)
  644. /**
  645. * @brief Sets the output status of the pads in GPIO mode.
  646. * @details The function will update the output for the pads whose mode is changed
  647. *
  648. * @param[in] PinIndex Pin ID number.
  649. * @param[in] pConfigPtr A pointer to the structure which contains initialization parameters
  650. *
  651. *
  652. * @return None
  653. *
  654. * @pre none
  655. * @post none
  656. *
  657. *
  658. */
  659. void Port_Ipw_SetGpioPadOutput
  660. (
  661. Port_PinType PinIndex,
  662. const Port_ConfigType * pConfigPtr
  663. )
  664. {
  665. uint16 Pin = pConfigPtr->pUsedPadConfig[PinIndex].Pin;
  666. uint8 u8LocalPDO = pConfigPtr->pUsedPadConfig[PinIndex].u8PDO;
  667. /* Set pin to High value */
  668. if (PORT_PIN_LEVEL_HIGH_U8 == u8LocalPDO)
  669. {
  670. Port_Ci_Port_Ip_SetPSOR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], ((uint32)1U << GPIO_CHANNEL_U32(Pin)));
  671. }
  672. /* Set pin to Low value */
  673. else if (PORT_PIN_LEVEL_LOW_U8 == u8LocalPDO)
  674. {
  675. Port_Ci_Port_Ip_SetPCOR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], ((uint32)1U << GPIO_CHANNEL_U32(Pin)));
  676. }
  677. else
  678. {
  679. /* No action to be done */
  680. }
  681. }
  682. #endif /* (STD_OFF == PORT_SETPINMODE_DOES_NOT_TOUCH_GPIO_LEVEL) */
  683. #endif /* (STD_ON == PORT_SET_PIN_MODE_API) */
  684. /**
  685. * @brief Refreshes port direction.
  686. * @details This service shall refresh the direction of all configured ports to the configured
  687. * direction. The PORT driver shall exclude from refreshing those port pins that are
  688. * configured as pin direction changeable during runtime.
  689. *
  690. * @param[in] pConfigPtr Pointer to configuration containing pins to be refreshed
  691. * @return none
  692. *
  693. * @pre Port_Init must have been called
  694. * @post none
  695. *
  696. */
  697. void Port_Ipw_RefreshPortDirection
  698. (
  699. const Port_ConfigType * pConfigPtr
  700. )
  701. {
  702. uint16 u16NumPins = pConfigPtr->u16NumPins;
  703. /* Index of the port table */
  704. uint16 u16PinIndex;
  705. uint16 PinPad;
  706. /* Initialize All Configured Port Pins that aren't direction changable */
  707. for (u16PinIndex = (uint16)0U; u16PinIndex < u16NumPins; u16PinIndex++)
  708. {
  709. if (FALSE == pConfigPtr->pUsedPadConfig[u16PinIndex].bDC)
  710. {
  711. /* On this platform we can only determine direction for the pins initialy configured as GPIOs */
  712. if (TRUE == pConfigPtr->pUsedPadConfig[u16PinIndex].bGPIO)
  713. {
  714. /* Point to the Port Pin MSCR register address*/
  715. PinPad = pConfigPtr->pUsedPadConfig[u16PinIndex].Pin;
  716. /* Configures Port Pin as Output */
  717. if (PORT_PIN_OUT == pConfigPtr->pUsedPadConfig[u16PinIndex].ePadDir)
  718. {
  719. /* Configure the pin direction as output in the PDDR register of GPIO IP */
  720. Port_Ci_Port_Ip_SetPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(PinPad)], ((uint32)1U << GPIO_CHANNEL_U32(PinPad)));
  721. }
  722. /* Configures Port Pin as Input or High-Z*/
  723. else if ((PORT_PIN_IN == pConfigPtr->pUsedPadConfig[u16PinIndex].ePadDir) || (PORT_PIN_HIGH_Z == pConfigPtr->pUsedPadConfig[u16PinIndex].ePadDir))
  724. {
  725. /* Configure the pin direction as input in the PDDR register of GPIO IP */
  726. Port_Ci_Port_Ip_ClearPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(PinPad)], ((uint32)1U << GPIO_CHANNEL_U32(PinPad)));
  727. #ifndef FEATURE_PORT_CI_PORT_IP_S32K11X_DERIVATIVE
  728. /* Check if the pin is HIGH-Z. In this case the driver needs to disable port input in PIDR register of GPIO IP*/
  729. if (PORT_PIN_HIGH_Z == pConfigPtr->pUsedPadConfig[u16PinIndex].ePadDir)
  730. {
  731. Port_Ci_Port_Ip_SetPIDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(PinPad)], ((uint32)1U << GPIO_CHANNEL_U32(PinPad)));
  732. }
  733. #endif
  734. }
  735. else
  736. {
  737. /* Do nothing. Else branch present in order to avoid MISRA's violations */
  738. }
  739. }
  740. }
  741. }
  742. }
  743. #ifdef PORT_SET_AS_UNUSED_PIN_API
  744. #if (STD_ON == PORT_SET_AS_UNUSED_PIN_API)
  745. /**
  746. * @brief Set as unused pin.
  747. * @details This function shall configure the referenced pin with all
  748. * the properties specified in the NotUsedPortPin container.
  749. *
  750. * @param[in] PinIndex Pin ID number.
  751. * @param[in] pConfigPtr A pointer to the structure which contains initialization parameters
  752. *
  753. * @return none
  754. *
  755. * @pre Port_Init must have been called
  756. * @post none
  757. */
  758. void Port_Ipw_SetAsUnusedPin
  759. (
  760. Port_PinType PinIndex,
  761. const Port_ConfigType * pConfigPtr
  762. )
  763. {
  764. uint32 u32LocalPCR = (uint32)(pConfigPtr->pUnusedPadConfig->u32PCR);
  765. uint8 u8LocalPDO = (uint8)(pConfigPtr->pUnusedPadConfig->u8PDO);
  766. Port_PinDirectionType eLocalPDDIR = pConfigPtr->pUnusedPadConfig->ePadDir;
  767. uint16 Pin;
  768. Pin = pConfigPtr->pUsedPadConfig[PinIndex].Pin;
  769. /* Check if the direction of the pin is OUTPUT. In this case the driver needs to set the output level too */
  770. if (PORT_PIN_OUT == eLocalPDDIR)
  771. {
  772. /* Set pin to High value */
  773. if (PORT_PIN_LEVEL_HIGH_U8 == u8LocalPDO)
  774. {
  775. Port_Ci_Port_Ip_SetPSOR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  776. }
  777. /* Set pin to Low value */
  778. else if (PORT_PIN_LEVEL_LOW_U8 == u8LocalPDO)
  779. {
  780. Port_Ci_Port_Ip_SetPCOR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  781. }
  782. else
  783. {
  784. /* No action to be done */
  785. }
  786. /* Configure the pin direction as output in the PDDR register of GPIO IP */
  787. Port_Ci_Port_Ip_SetPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  788. }
  789. else
  790. {
  791. /* Not used port pins are configured as inputs or high-z */
  792. /* Configure the pin direction as input in the PDDR register of GPIO IP */
  793. Port_Ci_Port_Ip_ClearPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  794. #ifndef FEATURE_PORT_CI_PORT_IP_S32K11X_DERIVATIVE
  795. /* Check if the pin is HIGH-Z. In this case the driver needs to disable port input in PIDR register of GPIO IP */
  796. if (PORT_PIN_HIGH_Z == eLocalPDDIR)
  797. {
  798. Port_Ci_Port_Ip_SetPIDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  799. }
  800. #endif
  801. }
  802. Port_Ci_Port_Ip_SetPCR(Port_au32PortCiPortBaseAddr[GPIO_PORT_U32(Pin)], GPIO_CHANNEL_U32(Pin), u32LocalPCR);
  803. }
  804. /**
  805. * @brief Set as used pin.
  806. * @details This function shall configure the referenced pin with
  807. * all the properties that where set during the Port_Init operation.
  808. *
  809. * @param[in] PinIndex Pin ID number.
  810. * @param[in] pConfigPtr A pointer to the structure which contains initialization parameters
  811. *
  812. * @return none
  813. *
  814. * @pre Port_Init must have been called
  815. * @post none
  816. */
  817. void Port_Ipw_SetAsUsedPin
  818. (
  819. Port_PinType PinIndex,
  820. const Port_ConfigType * pConfigPtr
  821. )
  822. {
  823. uint32 u32LocalPCR = (uint32)(pConfigPtr->pUnusedPadConfig->u32PCR);
  824. uint8 u8LocalPDO = (uint8)(pConfigPtr->pUnusedPadConfig->u8PDO);
  825. Port_PinDirectionType eLocalPDDIR = pConfigPtr->pUnusedPadConfig->ePadDir;
  826. uint16 Pin;
  827. Pin = pConfigPtr->pUsedPadConfig[PinIndex].Pin;
  828. u8LocalPDO = pConfigPtr->pUsedPadConfig[PinIndex].u8PDO;
  829. eLocalPDDIR = pConfigPtr->pUsedPadConfig[PinIndex].ePadDir;
  830. u32LocalPCR = pConfigPtr->pUsedPadConfig[PinIndex].u32PCR;
  831. if (TRUE == pConfigPtr->pUsedPadConfig[PinIndex].bGPIO)
  832. {
  833. /* Check if the direction of the pin is OUTPUT. In this case the driver needs to set the output level too */
  834. if (PORT_PIN_OUT == eLocalPDDIR)
  835. {
  836. /* Set pin to High value */
  837. if (PORT_PIN_LEVEL_HIGH_U8 == u8LocalPDO)
  838. {
  839. Port_Ci_Port_Ip_SetPSOR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  840. }
  841. /* Set pin to Low value */
  842. else if (PORT_PIN_LEVEL_LOW_U8 == u8LocalPDO)
  843. {
  844. Port_Ci_Port_Ip_SetPCOR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  845. }
  846. else
  847. {
  848. /* No action to be done */
  849. }
  850. /* Configure the pin direction as output in the PDDR register of GPIO IP */
  851. Port_Ci_Port_Ip_SetPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  852. }
  853. else
  854. {
  855. /* Configure the pin direction as input in the PDDR register of GPIO IP */
  856. Port_Ci_Port_Ip_ClearPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  857. #ifndef FEATURE_PORT_CI_PORT_IP_S32K11X_DERIVATIVE
  858. /* Check if the pin is HIGH-Z. In this case the driver needs to disable port input in PIDR register of GPIO IP*/
  859. if (PORT_PIN_HIGH_Z == eLocalPDDIR)
  860. {
  861. Port_Ci_Port_Ip_SetPIDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  862. }
  863. #endif
  864. }
  865. }
  866. Port_Ci_Port_Ip_SetPCR(Port_au32PortCiPortBaseAddr[GPIO_PORT_U32(Pin)], GPIO_CHANNEL_U32(Pin), u32LocalPCR);
  867. }
  868. #endif /* (STD_ON == PORT_SET_AS_UNUSED_PIN_API) */
  869. #endif /* defined(PORT_SET_AS_UNUSED_PIN_API)*/
  870. #ifdef PORT_RESET_PIN_MODE_API
  871. #if (STD_ON == PORT_RESET_PIN_MODE_API)
  872. /**
  873. * @brief Reset Pin Mode.
  874. * @details This function shall revert the port pin mode of the referenced pin
  875. * to the value that was set by Port_Init operation.
  876. *
  877. * @param[in] PinIndex Pin ID number.
  878. * @param[in] pConfigPtr A pointer to the structure which contains initialization parameters.
  879. *
  880. * @return none
  881. *
  882. * @pre Port_Init must have been called
  883. * @post none
  884. */
  885. void Port_Ipw_ResetPinMode
  886. (
  887. Port_PinType PinIndex,
  888. const Port_ConfigType * pConfigPtr
  889. )
  890. {
  891. uint32 u32LocalPCR;
  892. Port_PinDirectionType eLocalPDDIR;
  893. uint16 Pin;
  894. Pin = pConfigPtr->pUsedPadConfig[PinIndex].Pin;
  895. eLocalPDDIR = pConfigPtr->pUsedPadConfig[PinIndex].ePadDir;
  896. /* Check if the mode of the pin is GPIO. */
  897. if (TRUE == pConfigPtr->pUsedPadConfig[PinIndex].bGPIO)
  898. {
  899. /* Check if the direction of the pin is OUTPUT. In this case the driver needs to set the output level too */
  900. if (PORT_PIN_OUT == eLocalPDDIR)
  901. {
  902. /* Configure the pin direction as output in the PDDR register of GPIO IP */
  903. Port_Ci_Port_Ip_SetPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  904. }
  905. else
  906. {
  907. /* Configure the pin direction as input in the PDDR register of GPIO IP */
  908. Port_Ci_Port_Ip_ClearPDDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  909. #ifndef FEATURE_PORT_CI_PORT_IP_S32K11X_DERIVATIVE
  910. /* Check if the pin is HIGH-Z. In this case the driver needs to disable port input in PIDR register of GPIO IP*/
  911. if (PORT_PIN_HIGH_Z == eLocalPDDIR)
  912. {
  913. Port_Ci_Port_Ip_SetPIDR(Port_au32PortCiGpioBaseAddr[GPIO_PORT_U32(Pin)], (1U << GPIO_CHANNEL_U32(Pin)));
  914. }
  915. #endif
  916. }
  917. }
  918. /* Only revert the port pin mode of the referenced pin like Port_Init, not revert other bit for PCR register. */
  919. u32LocalPCR = Port_Ci_Port_Ip_ReadPCR(Port_au32PortCiPortBaseAddr[GPIO_PORT_U32(Pin)], GPIO_CHANNEL_U32(Pin));
  920. u32LocalPCR &= ~(PORT_CI_PCR_ALT_MODE_U32);
  921. u32LocalPCR |= (pConfigPtr->pUsedPadConfig[PinIndex].u32PCR) & PORT_CI_PCR_ALT_MODE_U32;
  922. Port_Ci_Port_Ip_SetPCR(Port_au32PortCiPortBaseAddr[GPIO_PORT_U32(Pin)], GPIO_CHANNEL_U32(Pin), u32LocalPCR);
  923. }
  924. #endif /* (STD_ON == PORT_RESET_PIN_MODE_API) */
  925. #endif /* defined(PORT_RESET_PIN_MODE_API)*/
  926. #define PORT_STOP_SEC_CODE
  927. #include "Port_MemMap.h"
  928. #ifdef __cplusplus
  929. }
  930. #endif
  931. /** @} */