HPM SDK
HPMicro Software Development Kit
hpm_pdgo_drv.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 HPMicro
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  *
6  */
7 
8 #ifndef HPM_PDGO_DRV_H
9 #define HPM_PDGO_DRV_H
10 
11 #include "hpm_common.h"
12 #include "hpm_pdgo_regs.h"
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 #define DGO_GPR_WORD_COUNT (4U)
19 #define DGO_WAKEUP_COUNTER_TICKS_PER_SEC (32768UL)
20 #define DGO_TURNOFF_COUNTER_TICKS_PER_SEC (24000000UL)
21 #define DGO_WAKEUP_TICK_IN_US (1000000UL / DGO_WAKEUP_COUNTER_TICKS_PER_SEC)
22 #define DGO_TURNOFF_TICKS_PER_US (DGO_TURNOFF_COUNTER_TICKS_PER_SEC / 1000000UL)
23 
38 static inline void pdgo_set_turnoff_counter(PDGO_Type *ptr, uint32_t counter)
39 {
40  ptr->DGO_TURNOFF = counter;
41 }
42 
48 {
50 }
51 
57 {
59 }
60 
65 static inline void pdgo_enable_oneshot_wakeup(PDGO_Type *ptr)
66 {
68 }
69 
74 static inline void pdgo_enable_retention_mode(PDGO_Type *ptr)
75 {
77 }
78 
86 static inline bool pdgo_is_retention_mode_enabled(PDGO_Type *ptr)
87 {
88  return ((ptr->DGO_CTR0 & PDGO_DGO_CTR0_RETENTION_MASK) != 0U);
89 }
90 
95 static inline void pdgo_disable_retention_mode(PDGO_Type *ptr)
96 {
98 }
99 
104 static inline void pdgo_enable_auto_wakeup(PDGO_Type *ptr)
105 {
107 }
108 
109 #if defined(PDGO_SUPPORT_SYS_WAKEUP_STATUS) && (PDGO_SUPPORT_SYS_WAKEUP_STATUS == 1)
116 static inline bool pdgo_is_system_wakeup(PDGO_Type *ptr)
117 {
118  return ((ptr->DGO_CTR1 & PDGO_DGO_CTR1_SYS_WAKEUP_STATUS_MASK) != 0U);
119 }
120 #endif
121 
128 static inline bool pdgo_is_pin_wakeup(PDGO_Type *ptr)
129 {
130  return ((ptr->DGO_CTR1 & PDGO_DGO_CTR1_PIN_WAKEUP_STATUS_MASK) != 0U);
131 }
132 
133 
141 static inline bool pdgo_is_auto_wakeup_enabled(PDGO_Type *ptr)
142 {
143  return ((ptr->DGO_CTR1 & PDGO_DGO_CTR1_AOTO_SYS_WAKEUP_MASK) != 0U);
144 }
145 
151 {
153 }
154 
160 {
162 }
163 
169 {
171 }
172 
178 {
180 }
181 
187 static inline void pdgo_set_wakeup_counter(PDGO_Type *ptr, uint32_t wakeup_ctr)
188 {
189  ptr->DGO_CTR3 = wakeup_ctr;
190 }
191 
198 static inline uint32_t pdgo_get_wakeup_counter(PDGO_Type *ptr)
199 {
200  return ptr->DGO_CTR3;
201 }
202 
209 static inline void pdgo_write_gpr(PDGO_Type *ptr, uint32_t index, uint32_t content)
210 {
211  if (index < DGO_GPR_WORD_COUNT) {
212  *(volatile uint32_t *) ((uint32_t) &ptr->DGO_GPR00 + index * 4) = content;
213  }
214 }
215 
223 static inline uint32_t pdgo_read_gpr(PDGO_Type *ptr, uint32_t index)
224 {
225  uint32_t reg_val = 0;
226  if (index < DGO_GPR_WORD_COUNT) {
227  reg_val = *(volatile uint32_t *) ((uint32_t) &ptr->DGO_GPR00 + index * 4);
228  }
229  return reg_val;
230 }
231 
238 static inline uint32_t pdgo_get_wakeup_counter_from_us(uint32_t us)
239 {
240  return (us + DGO_WAKEUP_TICK_IN_US - 1U) / DGO_WAKEUP_TICK_IN_US;
241 }
242 
249 static inline uint32_t pdgo_get_us_from_wakeup_counter(uint32_t counter)
250 {
251  return (counter * DGO_WAKEUP_TICK_IN_US);
252 }
253 
260 static inline uint32_t pdgo_get_turnoff_counter_from_us(uint32_t us)
261 {
262  return (us * DGO_TURNOFF_TICKS_PER_US);
263 }
264 
271 static inline uint32_t pdgo_get_us_from_turnoff_counter(uint32_t counter)
272 {
273  return (counter + DGO_TURNOFF_TICKS_PER_US - 1U) / DGO_TURNOFF_TICKS_PER_US;
274 }
275 
280 #ifdef __cplusplus
281 }
282 #endif
283 
284 
285 #endif /* HPM_DGO_DRV_H */
#define DGO_TURNOFF_TICKS_PER_US
Definition: hpm_pdgo_drv.h:22
#define DGO_GPR_WORD_COUNT
Definition: hpm_pdgo_drv.h:18
#define DGO_WAKEUP_TICK_IN_US
Definition: hpm_pdgo_drv.h:21
#define PDGO_DGO_CTR2_RESETN_PULLUP_DISABLE_MASK
Definition: hpm_pdgo_regs.h:174
#define PDGO_DGO_CTR1_WAKEUP_EN_MASK
Definition: hpm_pdgo_regs.h:154
#define PDGO_DGO_CTR2_WAKEUP_PULLDN_DISABLE_MASK
Definition: hpm_pdgo_regs.h:184
#define PDGO_DGO_CTR1_AOTO_SYS_WAKEUP_MASK
Definition: hpm_pdgo_regs.h:144
#define PDGO_DGO_CTR0_RETENTION_MASK
Definition: hpm_pdgo_regs.h:133
#define PDGO_DGO_CTR1_PIN_WAKEUP_STATUS_MASK
Definition: hpm_pdgo_regs.h:164
static uint32_t pdgo_get_us_from_turnoff_counter(uint32_t counter)
Convert the DGO Turn-off counter to microseconds.
Definition: hpm_pdgo_drv.h:271
static uint32_t pdgo_get_wakeup_counter(PDGO_Type *ptr)
Get DGO wakeup counter value.
Definition: hpm_pdgo_drv.h:198
static uint32_t pdgo_get_us_from_wakeup_counter(uint32_t counter)
Convert the DGO Wake-up counter to microseconds.
Definition: hpm_pdgo_drv.h:249
static void pdgo_enable_oneshot_wakeup(PDGO_Type *ptr)
Set DGO to one-shot wakeup mode.
Definition: hpm_pdgo_drv.h:65
static void pdgo_enable_pullup_resistor_for_reset_pin(PDGO_Type *ptr)
Enable pull-up resistor for Reset Pin [in] ptr DGO base address.
Definition: hpm_pdgo_drv.h:150
static bool pdgo_is_auto_wakeup_enabled(PDGO_Type *ptr)
Check whether Auto wake-up is enabled.
Definition: hpm_pdgo_drv.h:141
static void pdgo_enable_wkup_software_wakeup(PDGO_Type *ptr)
Enable wakeup pin or software wakeup.
Definition: hpm_pdgo_drv.h:47
static bool pdgo_is_pin_wakeup(PDGO_Type *ptr)
Check whether DGO is waked up by Wake-up/Reset Pin.
Definition: hpm_pdgo_drv.h:128
static void pdgo_enable_pulldown_resistor_for_wakeup_pin(PDGO_Type *ptr)
Definition: hpm_pdgo_drv.h:168
static bool pdgo_is_retention_mode_enabled(PDGO_Type *ptr)
Check whether the DGO retention mode is enabled or not.
Definition: hpm_pdgo_drv.h:86
static void pdgo_enable_retention_mode(PDGO_Type *ptr)
Enable DGO register retention mode.
Definition: hpm_pdgo_drv.h:74
static void pdgo_disable_pullup_resistor_for_reset_pin(PDGO_Type *ptr)
Disable pull-up resistor for Reset Pin [in] ptr DGO base address.
Definition: hpm_pdgo_drv.h:159
static void pdgo_disable_wkup_software_wakeup(PDGO_Type *ptr)
Disable wakeup pin or software wakeup.
Definition: hpm_pdgo_drv.h:56
static void pdgo_disable_retention_mode(PDGO_Type *ptr)
Disable DGO register retention mode.
Definition: hpm_pdgo_drv.h:95
static uint32_t pdgo_get_wakeup_counter_from_us(uint32_t us)
Convert the microsecond to DGO Wake-up counter value.
Definition: hpm_pdgo_drv.h:238
static void pdgo_disable_pulldown_resistor_for_wakeup_pin(PDGO_Type *ptr)
Definition: hpm_pdgo_drv.h:177
static uint32_t pdgo_read_gpr(PDGO_Type *ptr, uint32_t index)
Read data from DGO GPR register.
Definition: hpm_pdgo_drv.h:223
static void pdgo_write_gpr(PDGO_Type *ptr, uint32_t index, uint32_t content)
Write data to DGO GPR register.
Definition: hpm_pdgo_drv.h:209
static uint32_t pdgo_get_turnoff_counter_from_us(uint32_t us)
Convert the microsecond to DGO Turn-off counter value.
Definition: hpm_pdgo_drv.h:260
static void pdgo_enable_auto_wakeup(PDGO_Type *ptr)
Set DGO to automatic wakeup mode.
Definition: hpm_pdgo_drv.h:104
static void pdgo_set_wakeup_counter(PDGO_Type *ptr, uint32_t wakeup_ctr)
Set DGO wakeup counter.
Definition: hpm_pdgo_drv.h:187
static void pdgo_set_turnoff_counter(PDGO_Type *ptr, uint32_t counter)
Set DGO turn-off counter.
Definition: hpm_pdgo_drv.h:38
Definition: hpm_pdgo_regs.h:12
__RW uint32_t DGO_CTR0
Definition: hpm_pdgo_regs.h:21
__RW uint32_t DGO_GPR00
Definition: hpm_pdgo_regs.h:16
__RW uint32_t DGO_CTR3
Definition: hpm_pdgo_regs.h:24
__RW uint32_t DGO_CTR2
Definition: hpm_pdgo_regs.h:23
__W uint32_t DGO_TURNOFF
Definition: hpm_pdgo_regs.h:13
__RW uint32_t DGO_CTR1
Definition: hpm_pdgo_regs.h:22