HPM SDK
HPMicro Software Development Kit
hpm_pcfg_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_PCFG_DRV_H
9 #define HPM_PCFG_DRV_H
10 
11 #include "hpm_common.h"
12 #include "hpm_pcfg_regs.h"
13 
21 #define PCFG_CLOCK_GATE_MODE_ALWAYS_ON (0x3UL)
22 #define PCFG_CLOCK_GATE_MODE_ALWAYS_OFF (0x2UL)
23 
24 #define PCFG_PERIPH_KEEP_CLOCK_ON(p) (PCFG_CLOCK_GATE_MODE_ALWAYS_ON << (p))
25 #define PCFG_PERIPH_KEEP_CLOCK_OFF(p) (PCFG_CLOCK_GATE_MODE_ALWAYS_OFF << (p))
26 
27 /* @brief PCFG irc24m reference */
28 typedef enum {
32 
33 /* @brief PCFG dcdc current limit */
34 typedef enum {
38 
39 /* @brief PCFG dcdc current hys */
40 typedef enum {
44 
45 /* @brief PCFG dcdc mode */
46 typedef enum {
52 
53 /* @brief PCFG pmc domain peripherals */
54 typedef enum {
61 
62 /* @brief PCFG status */
63 enum {
65 };
66 
67 /* @brief PCFG irc24m config */
68 typedef struct {
69  uint32_t freq_in_hz;
72  bool free_run;
74 
75 
76 #define PCFG_CLOCK_GATE_CONTROL_MASK(module, mode) \
77  ((uint32_t) (mode) << ((module) << 1))
78 
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82 
90 static inline bool pcfg_bandgap_is_trimmed(PCFG_Type *ptr)
91 {
93 }
94 
100 static inline void pcfg_bandgap_reload_trim(PCFG_Type *ptr)
101 {
103 }
104 
110 static inline void pcfg_ldo2p5_turn_off(PCFG_Type *ptr)
111 {
113 }
114 
120 static inline void pcfg_ldo2p5_turn_on(PCFG_Type *ptr)
121 {
123 }
124 
132 static inline bool pcfg_ldo2p5_is_stable(PCFG_Type *ptr)
133 {
134  return PCFG_LDO2P5_READY_GET(ptr->LDO2P5);
135 }
136 
137 /*
138  * @brief check if DCDC is stable or not
139  * @param[in] ptr base address
140  * @retval true if DCDC is stable
141  */
142 static inline bool pcfg_dcdc_is_stable(PCFG_Type *ptr)
143 {
144  return PCFG_DCDC_MODE_READY_GET(ptr->DCDC_MODE);
145 }
146 
147 /*
148  * @brief set DCDC work mode
149  * @param[in] ptr base address
150  */
151 static inline void pcfg_dcdc_set_mode(PCFG_Type *ptr, uint8_t mode)
152 {
154 }
155 
163 {
166 }
167 
168 
176 static inline bool pcfg_dcdc_is_power_loss(PCFG_Type *ptr)
177 {
179 }
180 
187 {
189 }
190 
197 {
199 }
200 
207 static inline bool pcfg_dcdc_is_over_voltage(PCFG_Type *ptr)
208 {
210 }
211 
218 {
220 }
221 
228 {
230 }
231 
240 {
242 }
243 
251 static inline uint32_t pcfg_dcdc_get_start_time_in_cycle(PCFG_Type *ptr)
252 {
254 }
255 
263 static inline uint32_t pcfg_dcdc_get_resume_time_in_cycle(PCFG_Type *ptr)
264 {
266 }
267 
274 static inline void pcfg_dcdc_set_start_time_in_cycle(PCFG_Type *ptr, uint32_t cycles)
275 {
277 }
278 
285 static inline void pcfg_dcdc_set_resume_time_in_cycle(PCFG_Type *ptr, uint32_t cycles)
286 {
288 }
289 
297 {
299 }
300 
306 static inline void pcfg_disable_power_trap(PCFG_Type *ptr)
307 {
309 }
310 
316 static inline void pcfg_enable_power_trap(PCFG_Type *ptr)
317 {
319 }
320 
328 static inline bool pcfg_is_power_trap_triggered(PCFG_Type *ptr)
329 {
331 }
332 
339 {
341 }
342 
348 static inline void pcfg_disable_dcdc_retention(PCFG_Type *ptr)
349 {
351 }
352 
358 static inline void pcfg_enable_dcdc_retention(PCFG_Type *ptr)
359 {
361 }
362 
369 static inline void pcfg_clear_wakeup_cause(PCFG_Type *ptr, uint32_t mask)
370 {
371  ptr->WAKE_CAUSE |= mask;
372 }
373 
381 static inline uint32_t pcfg_get_wakeup_cause(PCFG_Type *ptr)
382 {
383  return ptr->WAKE_CAUSE;
384 }
385 
392 static inline void pcfg_enable_wakeup_source(PCFG_Type *ptr, uint32_t mask)
393 {
394  ptr->WAKE_MASK &= ~mask;
395 }
396 
403 static inline void pcfg_disable_wakeup_source(PCFG_Type *ptr, uint32_t mask)
404 {
405  ptr->WAKE_MASK |= mask;
406 }
407 
414 static inline void pcfg_set_periph_clock_mode(PCFG_Type *ptr, uint32_t mode)
415 {
416  ptr->SCG_CTRL = mode;
417 }
418 
426 static inline bool pcfg_irc24m_is_trimmed(PCFG_Type *ptr)
427 {
428  return ptr->RC24M & PCFG_RC24M_RC_TRIMMED_MASK;
429 }
430 
436 static inline void pcfg_irc24m_reload_trim(PCFG_Type *ptr)
437 {
439 }
440 
448 
449 /*
450  * @brief set DCDC voltage at standby mode
451  * @param[in] ptr base address
452  * @param[in] mv target voltage
453  * @retval status_success if successfully configured
454  */
456 
457 /*
458  * @brief set output voltage of LDO 2.5V in mV
459  * @param[in] ptr base address
460  * @param[in] mv target voltage
461  * @retval status_success if successfully configured
462  */
463 hpm_stat_t pcfg_ldo2p5_set_voltage(PCFG_Type *ptr, uint16_t mv);
464 
465 /*
466  * @brief set DCDC voltage
467  * @param[in] ptr base address
468  * @param[in] mv target voltage
469  * @retval status_success if successfully configured
470  */
471 hpm_stat_t pcfg_dcdc_set_voltage(PCFG_Type *ptr, uint16_t mv);
472 
473 /*
474  * @brief set output voltage of LDO 1V in mV
475  * @param[in] ptr base address
476  * @param[in] mv target voltage
477  * @retval status_success if successfully configured
478  */
479 hpm_stat_t pcfg_ldo1p1_set_voltage(PCFG_Type *ptr, uint16_t mv);
480 
481 /*
482  * @brief get current DCDC current level in mA
483  *
484  * @param[in] ptr base address
485  * @retval Current level at mA
486  */
488 
489 
490 #ifdef __cplusplus
491 }
492 #endif
497 #endif /* HPM_PCFG_DRV_H */
#define PCFG_DCDC_RESUME_TIME_RESUME_TIME_GET(x)
Definition: hpm_pcfg_regs.h:592
#define PCFG_LDO2P5_READY_GET(x)
Definition: hpm_pcfg_regs.h:108
#define PCFG_POWER_TRAP_TRIGGERED_MASK
Definition: hpm_pcfg_regs.h:602
#define PCFG_DCDC_CURRENT_VALID_MASK
Definition: hpm_pcfg_regs.h:303
#define PCFG_DCDC_MISC_OL_HYST_MASK
Definition: hpm_pcfg_regs.h:520
#define PCFG_POWER_TRAP_RETENTION_MASK
Definition: hpm_pcfg_regs.h:614
#define PCFG_DCDC_CURRENT_ESTI_EN_MASK
Definition: hpm_pcfg_regs.h:291
#define PCFG_DCDC_MODE_MODE_SET(x)
Definition: hpm_pcfg_regs.h:160
#define PCFG_LDO2P5_ENABLE_MASK
Definition: hpm_pcfg_regs.h:117
#define PCFG_DCDC_MODE_READY_GET(x)
Definition: hpm_pcfg_regs.h:146
#define PCFG_DCDC_START_TIME_START_TIME_GET(x)
Definition: hpm_pcfg_regs.h:581
#define PCFG_DCDC_START_TIME_START_TIME_SET(x)
Definition: hpm_pcfg_regs.h:580
#define PCFG_DCDC_MISC_OL_HYST_SET(x)
Definition: hpm_pcfg_regs.h:522
#define PCFG_POWER_TRAP_TRAP_MASK
Definition: hpm_pcfg_regs.h:626
#define PCFG_DCDC_PROT_OVERVOLT_FLAG_MASK
Definition: hpm_pcfg_regs.h:246
#define PCFG_BANDGAP_VBG_TRIMMED_MASK
Definition: hpm_pcfg_regs.h:48
#define PCFG_DCDC_PROT_DISABLE_OVERVOLTAGE_MASK
Definition: hpm_pcfg_regs.h:234
#define PCFG_DCDC_RESUME_TIME_RESUME_TIME_SET(x)
Definition: hpm_pcfg_regs.h:591
#define PCFG_DCDC_MODE_MODE_MASK
Definition: hpm_pcfg_regs.h:158
#define PCFG_DCDC_PROT_ILIMIT_LP_MASK
Definition: hpm_pcfg_regs.h:200
#define PCFG_DCDC_PROT_OVERLOAD_LP_MASK
Definition: hpm_pcfg_regs.h:212
#define PCFG_DCDC_PROT_OVERVOLT_FLAG_GET(x)
Definition: hpm_pcfg_regs.h:248
#define PCFG_DCDC_PROT_POWER_LOSS_FLAG_GET(x)
Definition: hpm_pcfg_regs.h:225
#define PCFG_RC24M_RC_TRIMMED_MASK
Definition: hpm_pcfg_regs.h:696
#define PCFG_DCDC_PROT_ILIMIT_LP_SET(x)
Definition: hpm_pcfg_regs.h:202
uint32_t hpm_stat_t
Definition: hpm_common.h:119
#define MAKE_STATUS(group, code)
Definition: hpm_common.h:128
@ status_group_pcfg
Definition: hpm_common.h:152
static void pcfg_ldo2p5_turn_on(PCFG_Type *ptr)
turn on LDO 2.5V
Definition: hpm_pcfg_drv.h:120
void pcfg_irc24m_config_track(PCFG_Type *ptr, pcfg_irc24m_config_t *config)
config irc24m track
Definition: hpm_pcfg_drv.c:74
static bool pcfg_bandgap_is_trimmed(PCFG_Type *ptr)
check if bandgap is trimmed or not
Definition: hpm_pcfg_drv.h:90
static void pcfg_enable_power_trap(PCFG_Type *ptr)
enable power trap
Definition: hpm_pcfg_drv.h:316
hpm_stat_t pcfg_ldo1p1_set_voltage(PCFG_Type *ptr, uint16_t mv)
Definition: hpm_pcfg_drv.c:14
hpm_stat_t pcfg_ldo2p5_set_voltage(PCFG_Type *ptr, uint16_t mv)
Definition: hpm_pcfg_drv.c:24
static bool pcfg_dcdc_is_measure_current_valid(PCFG_Type *ptr)
check if measured current is valid
Definition: hpm_pcfg_drv.h:239
pcfg_dcdc_lp_current_limit_t
Definition: hpm_pcfg_drv.h:34
uint16_t pcfg_dcdc_get_current_level(PCFG_Type *ptr)
Definition: hpm_pcfg_drv.c:47
hpm_stat_t pcfg_dcdc_set_voltage(PCFG_Type *ptr, uint16_t mv)
Definition: hpm_pcfg_drv.c:63
static void pcfg_dcdc_set_current_hys_range(PCFG_Type *ptr, pcfg_dcdc_current_hys_t range)
set dcdc current hysteres range
Definition: hpm_pcfg_drv.h:296
static void pcfg_clear_power_trap_trigger_flag(PCFG_Type *ptr)
clear power trap trigger flag
Definition: hpm_pcfg_drv.h:338
static void pcfg_bandgap_reload_trim(PCFG_Type *ptr)
bandgap reload trim value
Definition: hpm_pcfg_drv.h:100
static uint32_t pcfg_dcdc_get_start_time_in_cycle(PCFG_Type *ptr)
get DCDC start time in number of 24MHz clock cycles
Definition: hpm_pcfg_drv.h:251
static void pcfg_dcdc_ensable_over_voltage_prot(PCFG_Type *ptr)
enable over voltage protection
Definition: hpm_pcfg_drv.h:196
pcfg_pmc_periph_t
Definition: hpm_pcfg_drv.h:54
static void pcfg_dcdc_disable_over_voltage_prot(PCFG_Type *ptr)
disable over voltage protection
Definition: hpm_pcfg_drv.h:186
static void pcfg_disable_dcdc_retention(PCFG_Type *ptr)
disable dcdc retention
Definition: hpm_pcfg_drv.h:348
static bool pcfg_is_power_trap_triggered(PCFG_Type *ptr)
check if power trap is triggered
Definition: hpm_pcfg_drv.h:328
static bool pcfg_dcdc_is_stable(PCFG_Type *ptr)
Definition: hpm_pcfg_drv.h:142
static void pcfg_dcdc_set_lp_current_limit(PCFG_Type *ptr, pcfg_dcdc_lp_current_limit_t limit)
set low power current limit
Definition: hpm_pcfg_drv.h:162
static void pcfg_set_periph_clock_mode(PCFG_Type *ptr, uint32_t mode)
set clock gate mode in vpmc domain
Definition: hpm_pcfg_drv.h:414
static void pcfg_dcdc_set_mode(PCFG_Type *ptr, uint8_t mode)
Definition: hpm_pcfg_drv.h:151
pcfg_dcdc_mode_t
Definition: hpm_pcfg_drv.h:46
static void pcfg_disable_wakeup_source(PCFG_Type *ptr, uint32_t mask)
disable wakeup source
Definition: hpm_pcfg_drv.h:403
static bool pcfg_dcdc_is_power_loss(PCFG_Type *ptr)
check if power loss flag is set
Definition: hpm_pcfg_drv.h:176
static bool pcfg_irc24m_is_trimmed(PCFG_Type *ptr)
check if irc24m is trimmed
Definition: hpm_pcfg_drv.h:426
static void pcfg_dcdc_set_resume_time_in_cycle(PCFG_Type *ptr, uint32_t cycles)
set DCDC resuem time in 24MHz clock cycles
Definition: hpm_pcfg_drv.h:285
static bool pcfg_ldo2p5_is_stable(PCFG_Type *ptr)
check if LDO 2.5V is stable
Definition: hpm_pcfg_drv.h:132
pcfg_dcdc_current_hys_t
Definition: hpm_pcfg_drv.h:40
static void pcfg_irc24m_reload_trim(PCFG_Type *ptr)
reload irc24m trim value
Definition: hpm_pcfg_drv.h:436
pcfg_irc24m_reference_t
Definition: hpm_pcfg_drv.h:28
static void pcfg_dcdc_set_start_time_in_cycle(PCFG_Type *ptr, uint32_t cycles)
set DCDC start time in 24MHz clock cycles
Definition: hpm_pcfg_drv.h:274
static void pcfg_dcdc_enable_measure_current(PCFG_Type *ptr)
enable current measurement
Definition: hpm_pcfg_drv.h:227
static void pcfg_clear_wakeup_cause(PCFG_Type *ptr, uint32_t mask)
clear wakeup cause flag
Definition: hpm_pcfg_drv.h:369
static void pcfg_enable_wakeup_source(PCFG_Type *ptr, uint32_t mask)
enable wakeup source
Definition: hpm_pcfg_drv.h:392
static void pcfg_dcdc_disable_measure_current(PCFG_Type *ptr)
disable current measurement
Definition: hpm_pcfg_drv.h:217
static void pcfg_disable_power_trap(PCFG_Type *ptr)
disable power trap
Definition: hpm_pcfg_drv.h:306
static bool pcfg_dcdc_is_over_voltage(PCFG_Type *ptr)
checkover voltage flag
Definition: hpm_pcfg_drv.h:207
static uint32_t pcfg_get_wakeup_cause(PCFG_Type *ptr)
get wakeup cause
Definition: hpm_pcfg_drv.h:381
hpm_stat_t pcfg_dcdc_set_lpmode_voltage(PCFG_Type *ptr, uint16_t mv)
Definition: hpm_pcfg_drv.c:95
static void pcfg_enable_dcdc_retention(PCFG_Type *ptr)
enable dcdc retention to retain soc sram data
Definition: hpm_pcfg_drv.h:358
static void pcfg_ldo2p5_turn_off(PCFG_Type *ptr)
turn off LDO2P5
Definition: hpm_pcfg_drv.h:110
static uint32_t pcfg_dcdc_get_resume_time_in_cycle(PCFG_Type *ptr)
get DCDC resume time in number of 24MHz clock cycles
Definition: hpm_pcfg_drv.h:263
@ pcfg_dcdc_lp_current_limit_250ma
Definition: hpm_pcfg_drv.h:35
@ pcfg_dcdc_lp_current_limit_200ma
Definition: hpm_pcfg_drv.h:36
@ pcfg_pmc_periph_timer
Definition: hpm_pcfg_drv.h:57
@ pcfg_pmc_periph_uart
Definition: hpm_pcfg_drv.h:59
@ pcfg_pmc_periph_ioc
Definition: hpm_pcfg_drv.h:56
@ pcfg_pmc_periph_gpio
Definition: hpm_pcfg_drv.h:55
@ pcfg_pmc_periph_wdog
Definition: hpm_pcfg_drv.h:58
@ pcfg_dcdc_mode_general
Definition: hpm_pcfg_drv.h:49
@ pcfg_dcdc_mode_off
Definition: hpm_pcfg_drv.h:47
@ pcfg_dcdc_mode_basic
Definition: hpm_pcfg_drv.h:48
@ pcfg_dcdc_mode_expert
Definition: hpm_pcfg_drv.h:50
@ status_pcfg_ldo_out_of_range
Definition: hpm_pcfg_drv.h:64
@ pcfg_dcdc_current_hys_25mv
Definition: hpm_pcfg_drv.h:42
@ pcfg_dcdc_current_hys_12_5mv
Definition: hpm_pcfg_drv.h:41
@ pcfg_irc24m_reference_24m_xtal
Definition: hpm_pcfg_drv.h:30
@ pcfg_irc24m_reference_32k
Definition: hpm_pcfg_drv.h:29
Definition: hpm_pcfg_regs.h:12
__RW uint32_t LDO2P5
Definition: hpm_pcfg_regs.h:15
__RW uint32_t POWER_TRAP
Definition: hpm_pcfg_regs.h:28
__RW uint32_t DCDC_CURRENT
Definition: hpm_pcfg_regs.h:20
__RW uint32_t WAKE_MASK
Definition: hpm_pcfg_regs.h:30
__RW uint32_t BANDGAP
Definition: hpm_pcfg_regs.h:13
__RW uint32_t SCG_CTRL
Definition: hpm_pcfg_regs.h:31
__RW uint32_t DCDC_START_TIME
Definition: hpm_pcfg_regs.h:25
__RW uint32_t DCDC_PROT
Definition: hpm_pcfg_regs.h:19
__RW uint32_t DCDC_MODE
Definition: hpm_pcfg_regs.h:17
__RW uint32_t DCDC_MISC
Definition: hpm_pcfg_regs.h:23
__RW uint32_t DCDC_RESUME_TIME
Definition: hpm_pcfg_regs.h:26
__RW uint32_t WAKE_CAUSE
Definition: hpm_pcfg_regs.h:29
__RW uint32_t RC24M
Definition: hpm_pcfg_regs.h:33
Definition: hpm_pcfg_drv.h:68
pcfg_irc24m_reference_t reference
Definition: hpm_pcfg_drv.h:70
bool free_run
Definition: hpm_pcfg_drv.h:72
bool return_to_default_on_xtal_loss
Definition: hpm_pcfg_drv.h:71
uint32_t freq_in_hz
Definition: hpm_pcfg_drv.h:69