S32 SDK
ewm_hal.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 - 2016, Freescale Semiconductor, Inc.
3  * Copyright 2016-2017 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 
33 #include "ewm_hal.h"
34 
35 /*******************************************************************************
36  * Code
37  ******************************************************************************/
38 
39 /*FUNCTION**********************************************************************
40  *
41  * Function Name : EWM_HAL_Init
42  * Description : Init EWM. This method configures the EWM instance Control
43  * Register fields such as interrupt enable, input pin, instance enable.
44  * The user must make sure that the prescaler, compare high and compare low
45  * registers are configured prior to this function call
46  *
47  * Implements : EWM_HAL_Init_Activity
48  *END**************************************************************************/
49 void EWM_HAL_Init(EWM_Type * const base,
50  bool interruptEnable,
51  ewm_in_assert_logic_t assertLogic,
52  bool enable)
53 {
54 
55  /* Set the values that are not affected by the input pin */
56  uint8_t tempValue = (uint8_t)(EWM_CTRL_EWMEN(enable) | EWM_CTRL_INTEN(interruptEnable));
57 
58  /* Depending how the input pin is configured set the values into the
59  * temporary variable
60  */
61  switch(assertLogic)
62  {
64  tempValue |= (uint8_t)(EWM_CTRL_INEN(1U) | /* Input pin enabled */
65  EWM_CTRL_ASSIN(0U)); /* Input asserted on logic 0 */
66  break;
68  tempValue |= (uint8_t)(EWM_CTRL_INEN(1U) | /* Input pin enabled */
69  EWM_CTRL_ASSIN(1U)); /* Input asserted on logic 1 */
70  break;
71  default:
72  /* Input pin disabled */
73  break;
74  }
75 
76  /* Write the configuration into the Control register */
77  base->CTRL = tempValue;
78 }
79 
80 /*FUNCTION**********************************************************************
81  *
82  * Function Name : EWM_HAL_GetInputPinAssertLogic
83  * Description : Get the Input pin assert logic
84  *
85  * Implements : EWM_HAL_GetInputPinAssertLogic_Activity
86  *END**************************************************************************/
88 {
89  /* Variable where to save the retrieved configuration */
90  ewm_in_assert_logic_t returnValue;
91  /* Temporary variable to use for storing the configuration */
92  uint8_t tempValue;
93 
94  /* Check if input pin is enabled */
95  if((base->CTRL & EWM_CTRL_INEN_MASK) != 0U)
96  {
97  /* If true get the assert logic into the temp variable */
98  tempValue = (uint8_t)((base->CTRL & EWM_CTRL_ASSIN_MASK) >> EWM_CTRL_ASSIN_SHIFT);
99 
100  /* Convert the assert logic to the corresponding ewm_in_assert_logic_t
101  * value.
102  */
103  switch(tempValue)
104  {
105  case 0U:
106  returnValue = EWM_IN_ASSERT_ON_LOGIC_ZERO;
107  break;
108  case 1U:
109  returnValue = EWM_IN_ASSERT_ON_LOGIC_ONE;
110  break;
111  default:
112  returnValue = EWM_IN_ASSERT_DISABLED;
113  break;
114  }
115  }
116  else
117  {
118  /* Pin is disabled, return the corresponding value */
119  returnValue = EWM_IN_ASSERT_DISABLED;
120  }
121 
122  return returnValue;
123 }
124 /*******************************************************************************
125  * EOF
126  ******************************************************************************/
#define EWM_CTRL_ASSIN_SHIFT
Definition: S32K144.h:3408
#define EWM_CTRL_ASSIN(x)
Definition: S32K144.h:3410
ewm_in_assert_logic_t EWM_HAL_GetInputPinAssertLogic(const EWM_Type *const base)
Get the Input pin assert logic.
Definition: ewm_hal.c:87
#define EWM_CTRL_ASSIN_MASK
Definition: S32K144.h:3407
ewm_in_assert_logic_t
EWM input pin configuration Configures if the input pin is enabled and when is asserted Implements : ...
Definition: ewm_hal.h:43
#define EWM_CTRL_INEN_MASK
Definition: S32K144.h:3411
#define EWM_CTRL_EWMEN(x)
Definition: S32K144.h:3406
void EWM_HAL_Init(EWM_Type *const base, bool interruptEnable, ewm_in_assert_logic_t assertLogic, bool enable)
Init EWM. This method configures the EWM instance Control Register fields such as interrupt enable...
Definition: ewm_hal.c:49
#define EWM_CTRL_INEN(x)
Definition: S32K144.h:3414
#define EWM_CTRL_INTEN(x)
Definition: S32K144.h:3418
__IO uint8_t CTRL
Definition: S32K144.h:3365