S32 SDK
pmc_hal.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - 2014, 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 #if !defined(PMC_HAL_H)
19 #define PMC_HAL_H
20 
21 #include "device_registers.h"
22 #include <stdbool.h>
23 
44 /*******************************************************************************
45  * Definitions
46  ******************************************************************************/
47 
52 typedef enum {
56 
57 
59 typedef struct
60 {
61  bool initialize;
62  bool enable;
63  int8_t trimValue;
66 
70 typedef struct
71 {
74 } pmc_config_t;
75 
76 
77 
78 
79 /*******************************************************************************
80  * API
81  ******************************************************************************/
82 
83 #if defined(__cplusplus)
84 extern "C" {
85 #endif /* __cplusplus*/
86 
89 
90 
91 
102 void PMC_HAL_SetLowVoltIntCmd(PMC_Type* const baseAddr, const pmc_int_select_t intSelect, const bool enable);
103 
104 
114 void PMC_HAL_SetLowVoltIntAckCmd(PMC_Type* const baseAddr, const pmc_int_select_t intSelect);
115 
116 
129 bool PMC_HAL_GetLowVoltIntFlag(const PMC_Type* const baseAddr, const pmc_int_select_t intSelect);
130 
131 
144 static inline void PMC_HAL_SetLowVoltDetectResetCmd(PMC_Type* const baseAddr, const bool enable)
145 {
146  uint8_t regValue = baseAddr->LVDSC1;
147  regValue &= (uint8_t)(~(PMC_LVDSC1_LVDRE_MASK));
148  regValue |= (uint8_t)PMC_LVDSC1_LVDRE(enable ? 1U : 0U);
149  baseAddr->LVDSC1 = regValue;
150 }
151 
152 
162 static inline void PMC_HAL_SetBiasMode(PMC_Type* const baseAddr, const bool enable)
163 {
164  uint8_t regValue = baseAddr->REGSC;
165  regValue &= (uint8_t)(~(PMC_REGSC_BIASEN_MASK));
166  regValue |= (uint8_t)PMC_REGSC_BIASEN(enable?1U:0U);
167  baseAddr->REGSC = regValue;
168 }
169 
179 static inline void PMC_HAL_SetLpoMode(PMC_Type* const baseAddr, const bool enable)
180 {
181  uint8_t regValue = baseAddr->REGSC;
182  regValue &= (uint8_t)(~(PMC_REGSC_LPODIS_MASK));
183  regValue |= (uint8_t)PMC_REGSC_LPODIS(enable?0U:1U);
184  baseAddr->REGSC = regValue;
185 }
186 
187 
199 static inline bool PMC_HAL_GetLpoMode(const PMC_Type * const baseAddr)
200 {
201  uint8_t regValue = baseAddr->REGSC;
202  regValue = (uint8_t)((regValue & PMC_REGSC_LPODIS_MASK) >> PMC_REGSC_LPODIS_SHIFT);
203  return (regValue == 0U) ? true : false;
204 }
205 
206 
219 static inline uint8_t PMC_HAL_GetRegulatorStatus(const PMC_Type* const baseAddr)
220 {
221  uint8_t regValue = baseAddr->REGSC;
222  regValue = (uint8_t)((regValue & PMC_REGSC_REGFPM_MASK) >> PMC_REGSC_REGFPM_SHIFT);
223  return regValue;
224 }
225 
238 static inline uint8_t PMC_HAL_GetLpoStatus(const PMC_Type* const baseAddr)
239 {
240  uint8_t regValue = baseAddr->REGSC;
241  regValue = (uint8_t)((regValue & PMC_REGSC_LPOSTAT_MASK) >> PMC_REGSC_LPOSTAT_SHIFT);
242  return regValue;
243 }
244 
254 static inline void PMC_HAL_SetLpoTrimValue(PMC_Type* const baseAddr, const int8_t decimalValue)
255 {
256  int8_t decValue = decimalValue;
257  uint8_t lpotrim, trimval, regValue;
258 
259  if (decValue < 0)
260  {
261  lpotrim = ((uint8_t)1U) << (PMC_LPOTRIM_LPOTRIM_WIDTH);
262  decValue = (int8_t)(decValue + (int8_t)(lpotrim));
263  }
264  trimval = (uint8_t)decValue;
265 
266  DEV_ASSERT(trimval <= (1U << (PMC_LPOTRIM_LPOTRIM_WIDTH - 1U)));
267 
268  regValue = baseAddr->LPOTRIM;
269  regValue &= (uint8_t)(~(PMC_LPOTRIM_LPOTRIM_MASK));
270  regValue |= (uint8_t)PMC_LPOTRIM_LPOTRIM(trimval);
271  baseAddr->LPOTRIM = regValue;
272 }
273 
276 #if defined(__cplusplus)
277 }
278 #endif /* __cplusplus*/
279 
282 #endif /* PMC_HAL_H */
283 /*******************************************************************************
284  * EOF
285  ******************************************************************************/
286 
#define PMC_REGSC_BIASEN_MASK
Definition: S32K144.h:8499
#define PMC_REGSC_LPODIS_SHIFT
Definition: S32K144.h:8516
#define PMC_REGSC_REGFPM_MASK
Definition: S32K144.h:8507
#define PMC_LPOTRIM_LPOTRIM_MASK
Definition: S32K144.h:8520
#define PMC_REGSC_BIASEN(x)
Definition: S32K144.h:8502
pmc_int_select_t
Power management control interrupts Implements pmc_int_select_t_Class.
Definition: pmc_hal.h:52
void PMC_HAL_SetLowVoltIntAckCmd(PMC_Type *const baseAddr, const pmc_int_select_t intSelect)
Acknowledges the low voltage-related interrupts.
Definition: pmc_hal.c:84
#define PMC_LVDSC1_LVDRE(x)
Definition: S32K144.h:8472
#define DEV_ASSERT(x)
Definition: devassert.h:78
#define PMC_LPOTRIM_LPOTRIM_WIDTH
Definition: S32K144.h:8522
static void PMC_HAL_SetLowVoltDetectResetCmd(PMC_Type *const baseAddr, const bool enable)
Low-Voltage Detect Hardware Reset Enable/Disable (write once)
Definition: pmc_hal.h:144
#define PMC_LPOTRIM_LPOTRIM(x)
Definition: S32K144.h:8523
pmc_lpo_clock_config_t lpoClockConfig
Definition: pmc_hal.h:72
static void PMC_HAL_SetBiasMode(PMC_Type *const baseAddr, const bool enable)
Enables/Disables the Bias.
Definition: pmc_hal.h:162
static uint8_t PMC_HAL_GetRegulatorStatus(const PMC_Type *const baseAddr)
Gets the Regulator regulation status.
Definition: pmc_hal.h:219
__IO uint8_t REGSC
Definition: S32K144.h:8434
__IO uint8_t LVDSC1
Definition: S32K144.h:8432
static void PMC_HAL_SetLpoTrimValue(PMC_Type *const baseAddr, const int8_t decimalValue)
Low Power Oscillator Trimming Value.
Definition: pmc_hal.h:254
#define PMC_REGSC_LPODIS(x)
Definition: S32K144.h:8518
#define PMC_LVDSC1_LVDRE_MASK
Definition: S32K144.h:8469
PMC configure structure.
Definition: pmc_hal.h:70
#define PMC_REGSC_LPODIS_MASK
Definition: S32K144.h:8515
#define PMC_REGSC_LPOSTAT_SHIFT
Definition: S32K144.h:8512
#define PMC_REGSC_REGFPM_SHIFT
Definition: S32K144.h:8508
static uint8_t PMC_HAL_GetLpoStatus(const PMC_Type *const baseAddr)
Gets the Low Power Oscillator status.
Definition: pmc_hal.h:238
void PMC_HAL_SetLowVoltIntCmd(PMC_Type *const baseAddr, const pmc_int_select_t intSelect, const bool enable)
Enables/Disables the low voltage-related interrupts.
Definition: pmc_hal.c:50
PMC LPO configuration.
Definition: pmc_hal.h:59
#define PMC_REGSC_LPOSTAT_MASK
Definition: S32K144.h:8511
bool PMC_HAL_GetLowVoltIntFlag(const PMC_Type *const baseAddr, const pmc_int_select_t intSelect)
Gets the flag for the low voltage-related interrupts.
Definition: pmc_hal.c:117
__IO uint8_t LPOTRIM
Definition: S32K144.h:8436
static bool PMC_HAL_GetLpoMode(const PMC_Type *const baseAddr)
Gets the Low Power Oscillator status.
Definition: pmc_hal.h:199
static void PMC_HAL_SetLpoMode(PMC_Type *const baseAddr, const bool enable)
Enables/Disables the Low Power Oscillator.
Definition: pmc_hal.h:179