S32 SDK
ewm_driver.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 - 2016, 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 
39 #include "ewm_driver.h"
40 
41 /* @brief Local table used to store EWM base pointers */
42 static EWM_Type * const g_ewmBase[] = EWM_BASE_PTRS;
43 
44 /*******************************************************************************
45  * Code
46  ******************************************************************************/
47 
53 /*FUNCTION**********************************************************************
54  *
55  * Function Name : EWM_DRV_Init
56  * Description : This function initializes the EWM instance to a specified
57  * state
58  *
59  * Implements : EWM_DRV_Init_Activity
60  *END**************************************************************************/
61 status_t EWM_DRV_Init(uint32_t instance, const ewm_init_config_t * config)
62 {
63  DEV_ASSERT(instance < EWM_INSTANCE_COUNT);
64  DEV_ASSERT(config != NULL);
65 
66  /* Return status variable */
67  status_t statusCode = STATUS_SUCCESS;
68  /* Flag to store if the module is enabled */
69  bool isModuleEnabled;
70  /* Base pointer */
71  EWM_Type * base = g_ewmBase[instance];
72 
73  /* Get the enablement status of the module */
74  isModuleEnabled = EWM_HAL_IsEnabled(base);
75  /* Check if the EWM instance is already enabled or if the windows values are not correct */
76  if((isModuleEnabled == true) || (config->compareHigh <= config->compareLow) ||
78  {
79  /* If conditions are met change the status code to error */
80  statusCode = STATUS_ERROR;
81  }
82  else
83  {
84  /* Set clock prescaler */
85  EWM_HAL_SetPrescaler(base, config->prescaler);
86  /* Set compare high and low values */
87  EWM_HAL_SetCompareHigh(base, config->compareHigh);
88  EWM_HAL_SetCompareLow(base, config->compareLow);
89  /* Configure the Control register and enable the instance */
90  EWM_HAL_Init(base, config->interruptEnable,
91  config->assertLogic,
92  true);
93  }
94 
95  /* Return the status code */
96  return statusCode;
97 }
98 
99 /*FUNCTION**********************************************************************
100  *
101  * Function Name : EWM_DRV_GetDefaultConfig
102  * Description : This function initializes the EWM configuration structure
103  * to default values
104  *
105  * Implements : EWM_DRV_GetDefaultConfig_Activity
106  *END**************************************************************************/
108 {
109  DEV_ASSERT(config != NULL);
110 
111  /* Disable interrupts */
112  config->interruptEnable = false;
113  /* Input pin enabled and configured to assert on logic 0 */
115  /* Maximum prescaler */
116  config->prescaler = 255U;
117  /* Maximum service window */
120 }
121 
122 /*FUNCTION**********************************************************************
123  *
124  * Function Name : EWM_DRV_Refresh
125  * Description : This function refreshes the EWM instance counter
126  *
127  * Implements : EWM_DRV_Refresh_Activity
128  *END**************************************************************************/
129 void EWM_DRV_Refresh(uint32_t instance)
130 {
131  DEV_ASSERT(instance < EWM_INSTANCE_COUNT);
132 
133  /* Base pointer */
134  EWM_Type * base = g_ewmBase[instance];
135 
136  /* Disable global IRQ's to avoid disturbing the refresh process */
138  /* Write the refresh values */
139  EWM_HAL_Refresh(base);
140  /* Re-enable all IRQ's */
142 }
143 
144 
145 /*******************************************************************************
146  * EOF
147  ******************************************************************************/
static void EWM_HAL_SetPrescaler(EWM_Type *const base, uint8_t value)
Set the Clock Prescaler Value. This register can be only written once after a CPU reset and it must b...
Definition: ewm_hal.h:198
#define FEATURE_EWM_CMPH_MAX_VALUE
void EWM_DRV_Refresh(uint32_t instance)
Refresh EWM. This method needs to be called within the window period specified by the Compare Low and...
Definition: ewm_driver.c:129
#define EWM_INSTANCE_COUNT
Definition: S32K144.h:3374
#define EWM_BASE_PTRS
Definition: S32K144.h:3385
ewm_in_assert_logic_t assertLogic
Definition: ewm_driver.h:47
static bool EWM_HAL_IsEnabled(const EWM_Type *const base)
Get the EWM enable bit.
Definition: ewm_hal.h:125
static void EWM_HAL_Refresh(EWM_Type *const base)
Refresh EWM. This method needs to be called within the window period specified by the Compare Low and...
Definition: ewm_hal.h:95
uint8_t prescaler
Definition: ewm_driver.h:49
void INT_SYS_DisableIRQGlobal(void)
Disable system interrupt.
#define DEV_ASSERT(x)
Definition: devassert.h:78
static EWM_Type *const g_ewmBase[]
Definition: ewm_driver.c:42
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:31
static void EWM_HAL_SetCompareLow(EWM_Type *const base, uint8_t value)
Set the Compare Low Value. This register can be only written once after a CPU reset. The user must make sure that the Compare High is greater than Compare Low value.
Definition: ewm_hal.h:150
void INT_SYS_EnableIRQGlobal(void)
Enables system interrupt.
void EWM_DRV_GetDefaultConfig(ewm_init_config_t *config)
Init configuration structure to default values.
Definition: ewm_driver.c:107
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 FEATURE_EWM_CMPL_MIN_VALUE
status_t EWM_DRV_Init(uint32_t instance, const ewm_init_config_t *config)
Init EWM. This method initializes EWM instance to the configuration from the passed structure...
Definition: ewm_driver.c:61
uint8_t compareLow
Definition: ewm_driver.h:50
uint8_t compareHigh
Definition: ewm_driver.h:51
static void EWM_HAL_SetCompareHigh(EWM_Type *const base, uint8_t value)
Set the Compare High Value. This register can be only written once after a CPU reset. The user must make sure that the Compare High is greater than Compare Low value Note: The maximum Compare High value is 0xFE.
Definition: ewm_hal.h:175