Gpio_Dio_Ip.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 Gpio_Dio_Ip.c
  26. *
  27. * @addtogroup DIO_IPL
  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 "Gpio_Dio_Ip.h"
  40. #include "SchM_Dio.h"
  41. #if (STD_ON == GPIO_DIO_IP_DEV_ERROR_DETECT)
  42. #include "Devassert.h"
  43. #endif /* (STD_ON == GPIO_DIO_IP_DEV_ERROR_DETECT) */
  44. /*=================================================================================================
  45. SOURCE FILE VERSION INFORMATION
  46. =================================================================================================*/
  47. #define GPIO_DIO_IP_VENDOR_ID_C 43
  48. #define GPIO_DIO_IP_AR_RELEASE_MAJOR_VERSION_C 4
  49. #define GPIO_DIO_IP_AR_RELEASE_MINOR_VERSION_C 4
  50. #define GPIO_DIO_IP_AR_RELEASE_REVISION_VERSION_C 0
  51. #define GPIO_DIO_IP_SW_MAJOR_VERSION_C 1
  52. #define GPIO_DIO_IP_SW_MINOR_VERSION_C 0
  53. #define GPIO_DIO_IP_SW_PATCH_VERSION_C 0
  54. /*=================================================================================================
  55. * FILE VERSION CHECKS
  56. =================================================================================================*/
  57. /* Check if Gpio_Dio_Ip source file and Gpio_Dio_Ip header file are of the same vendor */
  58. #if (GPIO_DIO_IP_VENDOR_ID_C != GPIO_DIO_IP_VENDOR_ID_H)
  59. #error "Gpio_Dio_Ip.c and Gpio_Dio_Ip.h have different vendor ids"
  60. #endif
  61. /* Check if Gpio_Dio_Ip source file and Gpio_Dio_Ip header file are of the same Autosar version */
  62. #if ((GPIO_DIO_IP_AR_RELEASE_MAJOR_VERSION_C != GPIO_DIO_IP_AR_RELEASE_MAJOR_VERSION_H) || \
  63. (GPIO_DIO_IP_AR_RELEASE_MINOR_VERSION_C != GPIO_DIO_IP_AR_RELEASE_MINOR_VERSION_H) || \
  64. (GPIO_DIO_IP_AR_RELEASE_REVISION_VERSION_C != GPIO_DIO_IP_AR_RELEASE_REVISION_VERSION_H) \
  65. )
  66. #error "AutoSar Version Numbers of Gpio_Dio_Ip.c and Gpio_Dio_Ip.h are different"
  67. #endif
  68. /* Check if Gpio_Dio_Ip source file and Gpio_Dio_Ip header file are of the same Software version */
  69. #if ((GPIO_DIO_IP_SW_MAJOR_VERSION_C != GPIO_DIO_IP_SW_MAJOR_VERSION_H) || \
  70. (GPIO_DIO_IP_SW_MINOR_VERSION_C != GPIO_DIO_IP_SW_MINOR_VERSION_H) || \
  71. (GPIO_DIO_IP_SW_PATCH_VERSION_C != GPIO_DIO_IP_SW_PATCH_VERSION_H) \
  72. )
  73. #error "Software Version Numbers of Gpio_Dio_Ip.c and Gpio_Dio_Ip.h are different"
  74. #endif
  75. #ifndef DISABLE_MCAL_INTERMODULE_ASR_CHECK
  76. /* Check if Gpio_Dio_Ip source file and Devassert.h header file are of the same release version */
  77. #if (STD_ON == GPIO_DIO_IP_DEV_ERROR_DETECT)
  78. #if ((GPIO_DIO_IP_AR_RELEASE_MAJOR_VERSION_C != DEVASSERT_AR_RELEASE_MAJOR_VERSION) || \
  79. (GPIO_DIO_IP_AR_RELEASE_MINOR_VERSION_C != DEVASSERT_AR_RELEASE_MINOR_VERSION) \
  80. )
  81. #error "AutoSar Version Numbers of Gpio_Dio_Ip.c and Devassert.h are different"
  82. #endif
  83. #endif /* (STD_ON == GPIO_DIO_IP_DEV_ERROR_DETECT) */
  84. /* SchM_Dio.h version check start */
  85. #if ((GPIO_DIO_IP_AR_RELEASE_MAJOR_VERSION_C != SCHM_DIO_AR_RELEASE_MAJOR_VERSION) || \
  86. (GPIO_DIO_IP_AR_RELEASE_MINOR_VERSION_C != SCHM_DIO_AR_RELEASE_MINOR_VERSION) \
  87. )
  88. #error "AUTOSAR Version Numbers of Gpio_Dio_Ip.c and SchM_Dio.h are different"
  89. #endif
  90. /* SchM_Dio.h version check end */
  91. #endif /* DISABLE_MCAL_INTERMODULE_ASR_CHECK */
  92. /*=================================================================================================
  93. * LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
  94. =================================================================================================*/
  95. /*=================================================================================================
  96. * LOCAL MACROS
  97. =================================================================================================*/
  98. /*=================================================================================================
  99. * LOCAL CONSTANTS
  100. =================================================================================================*/
  101. /*=================================================================================================
  102. * LOCAL VARIABLES
  103. =================================================================================================*/
  104. /*=================================================================================================
  105. * GLOBAL CONSTANTS
  106. =================================================================================================*/
  107. /*=================================================================================================
  108. * GLOBAL VARIABLES
  109. =================================================================================================*/
  110. #define DIO_START_SEC_VAR_INIT_32
  111. #include "Dio_MemMap.h"
  112. uint32 GpioBaseAdresses[GPIO_INSTANCE_COUNT] = IP_GPIO_BASE_ADDRS;
  113. #define DIO_STOP_SEC_VAR_INIT_32
  114. #include "Dio_MemMap.h"
  115. /*=================================================================================================
  116. * LOCAL FUNCTION PROTOTYPES
  117. =================================================================================================*/
  118. /*=================================================================================================
  119. * LOCAL FUNCTIONS
  120. =================================================================================================*/
  121. /*==================================================================================================
  122. * GLOBAL FUNCTIONS
  123. ==================================================================================================*/
  124. #define DIO_START_SEC_CODE
  125. #include "Dio_MemMap.h"
  126. /**
  127. *Function Name : Gpio_Dio_Ip_WritePin
  128. * Description : This function writes the given pin from a port, with the given value
  129. * ('0' represents LOW, '1' represents HIGH).
  130. *
  131. * @implements Gpio_Dio_Ip_WritePin_Activity
  132. */
  133. void Gpio_Dio_Ip_WritePin(GPIO_Type * const base,
  134. Gpio_Dio_Ip_PinsChannelType pin,
  135. Gpio_Dio_Ip_PinsLevelType value)
  136. {
  137. /* Enter critical region */
  138. SchM_Enter_Dio_DIO_EXCLUSIVE_AREA_00();
  139. Gpio_Dio_Ip_PinsChannelType pinsValues = (Gpio_Dio_Ip_PinsChannelType)base->PDOR;
  140. pinsValues &= (Gpio_Dio_Ip_PinsChannelType)(~((Gpio_Dio_Ip_PinsChannelType)1U << pin));
  141. pinsValues |= (Gpio_Dio_Ip_PinsChannelType)((Gpio_Dio_Ip_PinsChannelType)value << pin);
  142. base->PDOR = GPIO_PDOR_PDO(pinsValues);
  143. /* Exit critical region */
  144. SchM_Exit_Dio_DIO_EXCLUSIVE_AREA_00();
  145. }
  146. /**
  147. * Function Name : Gpio_Dio_Ip_WritePins
  148. * Description : This function writes all pins configured as output with the values given in
  149. * the parameter pins. '0' represents LOW, '1' represents HIGH.
  150. *
  151. * @implements Gpio_Dio_Ip_WritePins_Activity
  152. */
  153. void Gpio_Dio_Ip_WritePins(GPIO_Type * const base,
  154. Gpio_Dio_Ip_PinsChannelType pins)
  155. {
  156. base->PDOR = GPIO_PDOR_PDO(pins);
  157. }
  158. /**
  159. * Function Name : Gpio_Dio_Ip_GetPinsOutput
  160. * Description : This function returns the current output that is written to a port. Only pins
  161. * that are configured as output will have meaningful values.
  162. *
  163. * @implements Gpio_Dio_Ip_GetPinsOutput_Activity
  164. */
  165. Gpio_Dio_Ip_PinsChannelType Gpio_Dio_Ip_GetPinsOutput(const GPIO_Type * const base)
  166. {
  167. Gpio_Dio_Ip_PinsChannelType returnValue = 0U;
  168. returnValue = (Gpio_Dio_Ip_PinsChannelType)(base->PDOR);
  169. return returnValue;
  170. }
  171. /**
  172. * Function Name : Gpio_Dio_Ip_SetPins
  173. * Description : This function configures output pins listed in parameter pins (bits that are
  174. * '1') to have a value of 'set' (HIGH). Pins corresponding to '0' will be
  175. * unaffected.
  176. *
  177. * @implements Gpio_Dio_Ip_SetPins_Activity
  178. */
  179. void Gpio_Dio_Ip_SetPins(GPIO_Type * const base,
  180. Gpio_Dio_Ip_PinsChannelType pins)
  181. {
  182. base->PSOR = GPIO_PSOR_PTSO(pins);
  183. }
  184. /**
  185. * Function Name : Gpio_Dio_Ip_ClearPins
  186. * Description : This function configures output pins listed in parameter pins (bits that are
  187. * '1') to have a 'cleared' value (LOW). Pins corresponding to '0' will be
  188. * unaffected.
  189. *
  190. * @implements Gpio_Dio_Ip_ClearPins_Activity
  191. */
  192. void Gpio_Dio_Ip_ClearPins(GPIO_Type * const base,
  193. Gpio_Dio_Ip_PinsChannelType pins)
  194. {
  195. base->PCOR = GPIO_PCOR_PTCO(pins);
  196. }
  197. /**
  198. * Function Name : Gpio_Dio_Ip_TogglePins
  199. * Description : This function toggles output pins listed in parameter pins (bits that are
  200. * '1'). Pins corresponding to '0' will be unaffected.
  201. *
  202. * @implements Gpio_Dio_Ip_TogglePins_Activity
  203. */
  204. void Gpio_Dio_Ip_TogglePins(GPIO_Type * const base,
  205. Gpio_Dio_Ip_PinsChannelType pins)
  206. {
  207. base->PTOR = GPIO_PTOR_PTTO(pins);
  208. }
  209. /**
  210. * Function Name : Gpio_Dio_Ip_ReadPins
  211. * Description : This function returns the current input values from a port. Only pins
  212. * configured as input will have meaningful values.
  213. *
  214. * @implements Gpio_Dio_Ip_ReadPins_Activity
  215. */
  216. Gpio_Dio_Ip_PinsChannelType Gpio_Dio_Ip_ReadPins(const GPIO_Type * const base)
  217. {
  218. Gpio_Dio_Ip_PinsChannelType returnValue = 0U;
  219. returnValue = (Gpio_Dio_Ip_PinsChannelType)(base->PDIR);
  220. return returnValue;
  221. }
  222. /**
  223. * Function Name : Gpio_Dio_Ip_ReadPin
  224. * Description : This function returns the current input value of the given pin from port. Only pin
  225. * configured as input will have meaningful value.
  226. *
  227. * @implements Gpio_Dio_Ip_ReadPin_Activity
  228. */
  229. Gpio_Dio_Ip_PinsLevelType Gpio_Dio_Ip_ReadPin(const GPIO_Type * const base, Gpio_Dio_Ip_PinsChannelType pin)
  230. {
  231. Gpio_Dio_Ip_PinsLevelType returnValue = 0U;
  232. returnValue = (Gpio_Dio_Ip_PinsLevelType)(((base->PDIR)&((uint32)1<<pin))>>(pin));
  233. return returnValue;
  234. }
  235. #define DIO_STOP_SEC_CODE
  236. #include "Dio_MemMap.h"
  237. #ifdef __cplusplus
  238. }
  239. #endif
  240. /** @} */
  241. /******************************************************************************
  242. * EOF
  243. *****************************************************************************/