S32 SDK
smc_hal.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 - 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 
19 #if !defined(SMC_HAL_H)
20 #define SMC_HAL_H
21 
22 #include "device_registers.h"
23 #include "status.h"
24 #include <stdbool.h>
25 
26 
50 /*******************************************************************************
51  * Definitions
52  ******************************************************************************/
53 
76 typedef enum
77 {
78 #if FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE
80 #endif
83 #if FEATURE_SMC_HAS_WAIT_VLPW
84  POWER_MANAGER_WAIT,
85  POWER_MANAGER_VLPW,
86 #endif
89 #if FEATURE_SMC_HAS_PSTOPO
90  POWER_MANAGER_PSTOP1,
91  POWER_MANAGER_PSTOP2,
92 #endif
93 #if FEATURE_SMC_HAS_STOPO
96 #endif
99 
114 typedef struct
115 {
120 
125 typedef enum
126 {
127  STAT_RUN = 0x01,
128  STAT_STOP = 0x02,
129  STAT_VLPR = 0x04,
130  STAT_VLPW = 0x08,
131  STAT_VLPS = 0x10,
132  STAT_HSRUN = 0x80,
133  STAT_INVALID = 0xFF
135 
140 typedef enum
141 {
146 
151 typedef enum
152 {
158 
163 typedef enum
164 {
165  SMC_STOP = 0U,
167  SMC_VLPS = 2U
169 
174 typedef enum
175 {
177  SMC_STOP1 = 0x01,
178  SMC_STOP2 = 0x02
181 
186 typedef struct
187 {
188  bool vlpProt;
189 #if FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE
190  bool hsrunProt;
191 #endif
193 
198 typedef struct {
200 #if FEATURE_SMC_HAS_STOPO
201  bool stopOption;
203 #endif
204 #if FEATURE_SMC_HAS_PSTOPO
205  bool pStopOption;
206  smc_stop_option_t pStopOptionValue;
207 #endif
209 
214 typedef struct
215 {
216  uint32_t majorNumber;
217  uint32_t minorNumber;
218  uint32_t featureNumber;
220 
221 
222 
223 /*******************************************************************************
224  * API
225  ******************************************************************************/
226 
227 #if defined(__cplusplus)
228 extern "C" {
229 #endif /* __cplusplus*/
230 
233 
240 void SMC_HAL_GetVersion(const SMC_Type* const baseAddr, smc_version_info_t* const versionInfo);
241 
259 status_t SMC_HAL_SetPowerMode(SMC_Type* const baseAddr,
260  const smc_power_mode_config_t* const powerModeConfig);
261 
279 void SMC_HAL_SetProtectionMode(SMC_Type* const baseAddr,
280  const smc_power_mode_protection_config_t* const protectConfig);
293 bool SMC_HAL_GetProtectionMode(const SMC_Type* const baseAddr, const power_modes_protect_t protect);
294 
307 static inline void SMC_HAL_SetRunModeControl(SMC_Type* const baseAddr, const smc_run_mode_t runMode)
308 {
309  uint32_t regValue = baseAddr->PMCTRL;
310  regValue &= ~(SMC_PMCTRL_RUNM_MASK);
311  regValue |= SMC_PMCTRL_RUNM(runMode);
312  baseAddr->PMCTRL = regValue;
313 }
314 
326 static inline smc_run_mode_t SMC_HAL_GetRunModeControl(const SMC_Type* const baseAddr)
327 {
328  smc_run_mode_t retValue;
329  uint32_t regValue = baseAddr->PMCTRL;
330  regValue = (regValue & SMC_PMCTRL_RUNM_MASK) >> SMC_PMCTRL_RUNM_SHIFT;
331  switch(regValue)
332  {
333  case 0UL:
334  retValue = SMC_RUN;
335  break;
336  case 1UL:
337  retValue = SMC_RESERVED_RUN;
338  break;
339  case 2UL:
340  retValue = SMC_VLPR;
341  break;
342  case 3UL:
343  default:
344  retValue = SMC_HSRUN;
345  break;
346  }
347  return retValue;
348 }
349 
362 static inline void SMC_HAL_SetStopModeControl(SMC_Type* const baseAddr, const smc_stop_mode_t stopMode)
363 {
364  uint32_t regValue = baseAddr->PMCTRL;
365  regValue &= ~(SMC_PMCTRL_STOPM_MASK);
366  regValue |= SMC_PMCTRL_STOPM(stopMode);
367  baseAddr->PMCTRL = regValue;
368 }
369 
379 static inline smc_stop_mode_t SMC_HAL_GetVlpsaModeControl(const SMC_Type* const baseAddr)
380 {
381  smc_stop_mode_t retValue;
382  uint32_t regValue = baseAddr->PMCTRL;
383  regValue = (regValue & SMC_PMCTRL_VLPSA_MASK) >> SMC_PMCTRL_VLPSA_SHIFT;
384  switch(regValue) {
385  case 0UL:
386  retValue = SMC_STOP;
387  break;
388  case 2UL:
389  retValue = SMC_VLPS;
390  break;
391  case 1UL:
392  /* pass-through */
393  default:
394  retValue = SMC_RESERVED_STOP1;
395  break;
396  }
397  return retValue;
398 }
399 
412 static inline smc_stop_mode_t SMC_HAL_GetStopModeControl(const SMC_Type* const baseAddr)
413 {
414  smc_stop_mode_t retValue;
415  uint32_t regValue = baseAddr->PMCTRL;
416  regValue = (regValue & SMC_PMCTRL_STOPM_MASK) >> SMC_PMCTRL_STOPM_SHIFT;
417  switch(regValue) {
418  case 0UL:
419  retValue = SMC_STOP;
420  break;
421  case 2UL:
422  retValue = SMC_VLPS;
423  break;
424  case 1UL:
425  /* pass-through */
426  default:
427  retValue = SMC_RESERVED_STOP1;
428  break;
429  }
430  return retValue;
431 }
432 
433 #if FEATURE_SMC_HAS_STOPO
434 
447 static inline void SMC_HAL_SetStopOption(SMC_Type* const baseAddr, const smc_stop_option_t option)
448 {
449  uint32_t regValue = baseAddr->STOPCTRL;
450  regValue &= ~(SMC_STOPCTRL_STOPO_MASK);
451  regValue |= SMC_STOPCTRL_STOPO(option);
452  baseAddr->STOPCTRL = regValue;
453 }
454 
455 
466 static inline smc_stop_option_t SMC_HAL_GetStopOption(const SMC_Type* const baseAddr)
467 {
468  smc_stop_option_t retValue;
469  uint32_t regValue = baseAddr->STOPCTRL;
470  regValue = (regValue & SMC_STOPCTRL_STOPO_MASK) >> SMC_STOPCTRL_STOPO_SHIFT;
471  switch(regValue) {
472  case 1UL:
473  retValue = SMC_STOP1;
474  break;
475  case 2UL:
476  retValue = SMC_STOP2;
477  break;
478  case 0UL:
479  /* Pass-through */
480  default:
481  retValue = SMC_STOP_RESERVED;
482  break;
483  }
484  return retValue;
485 }
486 
487 #endif
488 
489 #if FEATURE_SMC_HAS_PSTOPO
490 
491 #error "Unimplemented"
492 
493 #endif
494 
510 static inline power_mode_stat_t SMC_HAL_GetPowerModeStatus(const SMC_Type* const baseAddr)
511 {
512  power_mode_stat_t retValue;
513  uint32_t regValue = baseAddr->PMSTAT;
514  regValue = (regValue & SMC_PMSTAT_PMSTAT_MASK) >> SMC_PMSTAT_PMSTAT_SHIFT;
515  switch(regValue) {
516  case 1UL:
517  retValue = STAT_RUN;
518  break;
519  case 2UL:
520  retValue = STAT_STOP;
521  break;
522  case 4UL:
523  retValue = STAT_VLPR;
524  break;
525  case 8UL:
526  retValue = STAT_VLPW;
527  break;
528  case 16UL:
529  retValue = STAT_VLPS;
530  break;
531  case 128UL:
532  retValue = STAT_HSRUN;
533  break;
534  case 255UL:
535  default:
536  retValue = STAT_INVALID;
537  break;
538  }
539  return retValue;
540 }
541 
542 
543 
546 #if defined(__cplusplus)
547 }
548 #endif /* __cplusplus*/
549 
552 #endif /* SMC_HAL_H */
553 /*******************************************************************************
554  * EOF
555  ******************************************************************************/
556 
#define SMC_PMCTRL_RUNM_SHIFT
Definition: S32K144.h:11130
__I uint32_t PMSTAT
Definition: S32K144.h:11055
static smc_stop_option_t SMC_HAL_GetStopOption(const SMC_Type *const baseAddr)
Gets the configuration of the STOPO option.
Definition: smc_hal.h:466
__IO uint32_t PMCTRL
Definition: S32K144.h:11053
static smc_run_mode_t SMC_HAL_GetRunModeControl(const SMC_Type *const baseAddr)
Gets the current RUN mode configuration setting.
Definition: smc_hal.h:326
#define SMC_PMCTRL_STOPM_MASK
Definition: S32K144.h:11121
bool SMC_HAL_GetProtectionMode(const SMC_Type *const baseAddr, const power_modes_protect_t protect)
Gets the the current power mode protection setting.
Definition: smc_hal.c:305
static power_mode_stat_t SMC_HAL_GetPowerModeStatus(const SMC_Type *const baseAddr)
Gets the current power mode stat.
Definition: smc_hal.h:510
Power mode protection configuration Implements smc_power_mode_protection_config_t_Class.
Definition: smc_hal.h:186
#define SMC_PMSTAT_PMSTAT_MASK
Definition: S32K144.h:11139
power_manager_modes_t powerModeName
Definition: smc_hal.h:199
#define SMC_PMCTRL_STOPM(x)
Definition: S32K144.h:11124
uint32_t minorNumber
Definition: smc_hal.h:217
SMC module version number Implements smc_version_info_t_Class.
Definition: smc_hal.h:214
void SMC_HAL_SetProtectionMode(SMC_Type *const baseAddr, const smc_power_mode_protection_config_t *const protectConfig)
Configures all power mode protection settings.
Definition: smc_hal.c:273
static smc_stop_mode_t SMC_HAL_GetVlpsaModeControl(const SMC_Type *const baseAddr)
Checks whether the last very low power stop sequence has been aborted.
Definition: smc_hal.h:379
static void SMC_HAL_SetStopModeControl(SMC_Type *const baseAddr, const smc_stop_mode_t stopMode)
Configures the STOP mode control setting.
Definition: smc_hal.h:362
status_t
Status return codes. Common error codes will be a unified enumeration (C enum) that will contain all ...
Definition: status.h:31
smc_stop_option_t
STOP option Implements smc_stop_option_t_Class.
Definition: smc_hal.h:174
#define SMC_PMCTRL_STOPM_SHIFT
Definition: S32K144.h:11122
power_manager_modes_t
Power modes enumeration.
Definition: smc_hal.h:76
static void SMC_HAL_SetRunModeControl(SMC_Type *const baseAddr, const smc_run_mode_t runMode)
Configures the the RUN mode control setting.
Definition: smc_hal.h:307
status_t SMC_HAL_SetPowerMode(SMC_Type *const baseAddr, const smc_power_mode_config_t *const powerModeConfig)
Configures the power mode.
Definition: smc_hal.c:115
smc_run_mode_t
Run mode definition Implements smc_run_mode_t_Class.
Definition: smc_hal.h:151
void SMC_HAL_GetVersion(const SMC_Type *const baseAddr, smc_version_info_t *const versionInfo)
Get the version of the SMC module.
Definition: smc_hal.c:82
Power mode control configuration used for calling the SMC_SYS_SetPowerMode API Implements smc_power_m...
Definition: smc_hal.h:198
Power mode user configuration structure.
Definition: smc_hal.h:114
static void SMC_HAL_SetStopOption(SMC_Type *const baseAddr, const smc_stop_option_t option)
Configures the STOPO (Stop Option).
Definition: smc_hal.h:447
#define SMC_PMCTRL_VLPSA_MASK
Definition: S32K144.h:11125
power_modes_protect_t
Power Modes Protection Implements power_modes_protect_t_Class.
Definition: smc_hal.h:140
#define SMC_STOPCTRL_STOPO(x)
Definition: S32K144.h:11137
#define SMC_STOPCTRL_STOPO_SHIFT
Definition: S32K144.h:11135
uint32_t featureNumber
Definition: smc_hal.h:218
uint32_t majorNumber
Definition: smc_hal.h:216
#define SMC_PMCTRL_VLPSA_SHIFT
Definition: S32K144.h:11126
power_manager_modes_t powerMode
Definition: smc_hal.h:116
#define SMC_PMCTRL_RUNM(x)
Definition: S32K144.h:11132
power_mode_stat_t
Power Modes in PMSTAT Implements power_mode_stat_t_Class.
Definition: smc_hal.h:125
static smc_stop_mode_t SMC_HAL_GetStopModeControl(const SMC_Type *const baseAddr)
Gets the current STOP mode control settings.
Definition: smc_hal.h:412
#define SMC_STOPCTRL_STOPO_MASK
Definition: S32K144.h:11134
__IO uint32_t STOPCTRL
Definition: S32K144.h:11054
#define SMC_PMSTAT_PMSTAT_SHIFT
Definition: S32K144.h:11140
#define SMC_PMCTRL_RUNM_MASK
Definition: S32K144.h:11129
smc_stop_mode_t
Stop mode definition Implements smc_stop_mode_t_Class.
Definition: smc_hal.h:163
smc_stop_option_t stopOptionValue
Definition: smc_hal.h:202