S32 SDK
pins_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 - 2015, Freescale Semiconductor, Inc.
3  * Copyright 2016 NXP
4  * All rights reserved.
5  *
6  * THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
7  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
9  * IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
10  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
11  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
12  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
13  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
14  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
15  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
16  * THE POSSIBILITY OF SUCH DAMAGE.
17  */
18 
19 #include "pins_driver.h"
20 #include "clock_manager.h"
21 #include <stdint.h>
22 #include <stdbool.h>
23 #include <stddef.h>
24 
46 /*******************************************************************************
47  * Variables
48  ******************************************************************************/
49 
50 /*FUNCTION**********************************************************************
51  *
52  * Function Name : PINS_DRV_Init
53  * Description : This function configures the pins with the options provided
54  * in the provided structure.
55  *
56  * Implements : PINS_DRV_Init_Activity
57  *END**************************************************************************/
58 status_t PINS_DRV_Init(const uint32_t pin_count, const pin_settings_config_t config[])
59 {
60  uint32_t i;
61 #if (defined (DEV_ERROR_DETECT) || defined (CUSTOM_DEVASSERT))
62  bool porta_checked = false;
63  bool portb_checked = false;
64  bool portc_checked = false;
65  bool portd_checked = false;
66  bool porte_checked = false;
67 #endif
68 
69  for (i = 0U; i < pin_count; i++) {
70  /*Check if the clock is enabled for ports*/
71 #if (defined (DEV_ERROR_DETECT) || defined (CUSTOM_DEVASSERT))
72  if (config[i].base == PORTA)
73  {
74  if (porta_checked == false)
75  {
76  porta_checked = true;
78  }
79  }
80  else if (config[i].base == PORTB)
81  {
82  if (portb_checked == false)
83  {
84  portb_checked = true;
86  }
87  }
88  else if (config[i].base == PORTC)
89  {
90  if(portc_checked == false)
91  {
92  portc_checked = true;
94  }
95  }
96  else if (config[i].base == PORTD)
97  {
98  if (portd_checked == false)
99  {
100  portd_checked = true;
102  }
103 
104  }
105  else if (config[i].base == PORTE)
106  {
107  if (porte_checked == false)
108  {
109  porte_checked = true;
111  }
112  }
113  else
114  {
115  /* not a port */
116  DEV_ASSERT(false);
117  }
118 #endif
119 
120 #if FEATURE_PORT_HAS_PULL_SELECTION
121  PORT_HAL_SetPullSel( config[i].base, config[i].pinPortIdx, config[i].pullConfig);
122 #endif
123 #if FEATURE_PORT_HAS_SLEW_RATE
124  PORT_HAL_SetSlewRateMode( config[i].base, config[i].pinPortIdx, config[i].rateSelect);
125 #endif
126 #if FEATURE_PORT_HAS_PASSIVE_FILTER
127  PORT_HAL_SetPassiveFilterMode(config[i].base, config[i].pinPortIdx, config[i].passiveFilter);
128 #endif
129 #if FEATURE_PORT_HAS_OPEN_DRAIN
130  PORT_HAL_SetOpenDrainMode( config[i].base, config[i].pinPortIdx, config[i].openDrain);
131 #endif
132 #if FEATURE_PORT_HAS_DRIVE_STRENGTH
133  PORT_HAL_SetDriveStrengthMode(config[i].base, config[i].pinPortIdx, config[i].driveSelect);
134 #endif
135  PORT_HAL_SetMuxModeSel( config[i].base, config[i].pinPortIdx, config[i].mux);
136 #if FEATURE_PORT_HAS_PIN_CONTROL_LOCK
137  PORT_HAL_SetPinCtrlLockMode( config[i].base, config[i].pinPortIdx, config[i].pinLock);
138 #endif
139  PORT_HAL_SetPinIntSel( config[i].base, config[i].pinPortIdx, config[i].intConfig);
140  if(config[i].clearIntFlag){
141  PORT_HAL_ClearPinIntFlagCmd( config[i].base, config[i].pinPortIdx);
142  }
143  if (PORT_MUX_AS_GPIO == config[i].mux)
144  {
145  switch(config[i].direction)
146  {
148  GPIO_HAL_SetPinDirection(config[i].gpioBase, config[i].pinPortIdx, 0U);
149  break;
151  GPIO_HAL_SetPinDirection(config[i].gpioBase, config[i].pinPortIdx, 1U);
152  break;
154  /* pass-through */
155  default:
156  /* nothing to configure */
157  DEV_ASSERT(false);
158  break;
159  }
160  }
161  }
162  return STATUS_SUCCESS;
163 }
164 
165 
166 /******************************************************************************
167  * EOF
168  *****************************************************************************/
rtc_interrupt_config_t * intConfig
Definition: rtc_driver.c:78
static void PORT_HAL_SetPassiveFilterMode(PORT_Type *const base, const uint32_t pin, const bool isPassiveFilterEnabled)
Configures the passive filter if the pin is used as a digital input.
Definition: port_hal.h:239
#define PORTD
Definition: S32K144.h:8581
static void PORT_HAL_SetDriveStrengthMode(PORT_Type *const base, const uint32_t pin, const port_drive_strength_t driveSelect)
Configures the drive strength if the pin is used as a digital output.
Definition: port_hal.h:284
#define DEV_ASSERT(x)
Definition: devassert.h:78
#define PORTE
Definition: S32K144.h:8585
#define PORTB
Definition: S32K144.h:8573
static void PORT_HAL_ClearPinIntFlagCmd(PORT_Type *const base, const uint32_t pin)
Clears the individual pin-interrupt status flag.
Definition: port_hal.h:517
status_t CLOCK_SYS_GetFreq(clock_names_t clockName, uint32_t *frequency)
Gets the clock frequency for a specific clock name.
static void PORT_HAL_SetPinCtrlLockMode(PORT_Type *const base, const uint32_t pin, const bool isPinLockEnabled)
Locks or unlocks the pin control register bits[15:0].
Definition: port_hal.h:331
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:31
Defines the converter configuration.
Definition: pins_driver.h:134
#define PORTC
Definition: S32K144.h:8577
static void PORT_HAL_SetMuxModeSel(PORT_Type *const base, const uint32_t pin, const port_mux_t mux)
Configures the pin muxing.
Definition: port_hal.h:309
static void GPIO_HAL_SetPinDirection(GPIO_Type *const baseAddr, const uint32_t pinNumber, const uint32_t pinDirection)
Configure the direction for a certain pin from a port.
Definition: gpio_hal.h:219
#define PORTA
Definition: S32K144.h:8569
static void PORT_HAL_SetPinIntSel(PORT_Type *const base, const uint32_t pin, const port_interrupt_config_t intConfig)
Configures the port pin interrupt/DMA request.
Definition: port_hal.h:450
static void PORT_HAL_SetPullSel(PORT_Type *const base, const uint32_t pin, const port_pull_config_t pullConfig)
Configures the internal resistor.
Definition: port_hal.h:164
status_t PINS_DRV_Init(const uint32_t pin_count, const pin_settings_config_t config[])
Initializes the pins with the given configuration structure.
Definition: pins_driver.c:58