SmartSnippets DA1459x SDK
hw_clk.h
Go to the documentation of this file.
1 
42 #ifndef HW_CLK_H_
43 #define HW_CLK_H_
44 
45 
46 #if dg_configUSE_HW_CLK
47 
48 #include "sdk_defs.h"
49 
60 typedef enum lp_clk_is_type {
61  LP_CLK_IS_RCLP = 0,
62  LP_CLK_IS_RCX,
63  LP_CLK_IS_XTAL32K,
64  LP_CLK_IS_EXTERNAL,
65  LP_CLK_IS_INVALID
66 } lp_clk_is_t;
67 
75 typedef enum ahbdiv_type {
76  ahb_div1 = 0,
81  ahb_invalid
82 } ahb_div_t;
83 
87 typedef enum apbdiv_type {
88  apb_div1 = 0,
92  apb_invalid
93 } apb_div_t;
94 
100 __STATIC_FORCEINLINE ahb_div_t hw_clk_get_hclk_div(void)
101 {
102  return REG_GETF(CRG_TOP, CLK_AMBA_REG, HCLK_DIV);
103 }
104 
110 __STATIC_FORCEINLINE apb_div_t hw_clk_get_pclk_div(void)
111 {
112  return REG_GETF(CRG_TOP, CLK_AMBA_REG, PCLK_DIV);
113 }
114 
115  #include "hw_clk_da1459x.h"
116 
117 
123 __STATIC_FORCEINLINE void hw_clk_set_pclk_div(apb_div_t div)
124 {
125  ASSERT_WARNING(div <= apb_div8);
126 
127 
129  REG_SETF(CRG_TOP, CLK_AMBA_REG, PCLK_DIV, div);
131 }
132 
138 __STATIC_INLINE void hw_clk_set_lpclk(lp_clk_is_t mode)
139 {
141  switch (mode) {
142  case LP_CLK_IS_RCLP:
144  break;
145  case LP_CLK_IS_RCX:
147  break;
148  case LP_CLK_IS_XTAL32K:
150  break;
151  case LP_CLK_IS_EXTERNAL:
153  break;
154  default:
155  ASSERT_WARNING(0);
156  break;
157  }
159 }
160 
168 __STATIC_INLINE bool hw_clk_lpclk_is(lp_clk_is_t clk)
169 {
170  switch (clk) {
171  case LP_CLK_IS_RCLP:
172  return hw_clk_lp_is_rclp();
173  case LP_CLK_IS_RCX:
174  return hw_clk_lp_is_rcx();
175  case LP_CLK_IS_XTAL32K:
176  return hw_clk_lp_is_xtal32k();
177  case LP_CLK_IS_EXTERNAL:
178  return hw_clk_lp_is_external();
179  default:
180  /* An invalid clock is requested */
181  ASSERT_WARNING(0);
182  return false;
183  }
184 }
185 
192 __STATIC_INLINE lp_clk_is_t hw_clk_get_lpclk(void)
193 {
194  lp_clk_is_t lp_clk;
195  for (lp_clk = 0; lp_clk < LP_CLK_IS_INVALID; lp_clk++) {
196  if (hw_clk_lpclk_is(lp_clk)) {
197  return lp_clk;
198  }
199  }
200  ASSERT_WARNING(0);
201  return LP_CLK_IS_INVALID;
202 }
203 
209 __STATIC_INLINE void hw_clk_configure_lpclk(lp_clk_is_t clk)
210 {
211  switch (clk) {
212  case LP_CLK_IS_RCLP:
213  // Nothing to do for RCLP
214  return;
215  case LP_CLK_IS_RCX:
217  return;
218  case LP_CLK_IS_XTAL32K:
220  return;
221  case LP_CLK_IS_EXTERNAL:
222  // Nothing to do for external LP clock
223  return;
224  default:
225  /* An invalid clock is requested */
226  ASSERT_WARNING(0);
227  }
228 }
229 
235 __STATIC_INLINE void hw_clk_enable_lpclk(lp_clk_is_t clk)
236 {
237  switch (clk) {
238  case LP_CLK_IS_RCLP:
240  return;
241  case LP_CLK_IS_RCX:
243  return;
244  case LP_CLK_IS_XTAL32K:
246  return;
247  case LP_CLK_IS_EXTERNAL:
248  // Nothing to do for external LP clock
249  return;
250  default:
251  /* An invalid clock is requested */
252  ASSERT_WARNING(0);
253  }
254 }
255 
261 __STATIC_INLINE void hw_clk_disable_lpclk(lp_clk_is_t clk)
262 {
263  switch (clk) {
264  case LP_CLK_IS_RCLP:
266  return;
267  case LP_CLK_IS_RCX:
269  return;
270  case LP_CLK_IS_XTAL32K:
272  return;
273  case LP_CLK_IS_EXTERNAL:
274  // Nothing to do for external LP clock
275  return;
276  default:
277  /* An invalid clock is requested */
278  ASSERT_WARNING(0);
279  }
280 }
281 
289 __STATIC_FORCEINLINE uint32_t hw_clk_get_sys_clk_freq(sys_clk_t sys_clk)
290 {
291  switch (sys_clk) {
292  case sysclk_RC32:
293  return dg_configRC32M_FREQ;
294  case sysclk_XTAL32M:
295  return dg_configXTAL32M_FREQ;
296  case sysclk_DBLR64:
297  return dg_configDBLR64M_FREQ;
298  default:
299  ASSERT_WARNING(0);
300  return 0;
301  }
302 }
303 
304 
316 __RETAINED_CODE void hw_clk_delay_usec(uint32_t usec);
317 
324 __RETAINED_CODE uint32_t hw_clk_get_sysclk_freq(void);
325 
326 #endif /* dg_configUSE_HW_CLK */
327 #endif /* HW_CLK_H_ */
328 
hw_clk_configure_rcx
__STATIC_INLINE void hw_clk_configure_rcx(void)
Configure RCX. This must be done only once since the register is retained.
Definition: hw_clk_da1459x.h:469
hw_clk_lp_is_xtal32k
__STATIC_INLINE bool hw_clk_lp_is_xtal32k(void)
Check whether the XTAL32K is the Low Power clock.
Definition: hw_clk_da1459x.h:312
REG_SETF
#define REG_SETF(base, reg, field, new_val)
Set the value of a register field.
Definition: sdk_defs.h:738
hw_clk_set_lpclk
__STATIC_INLINE void hw_clk_set_lpclk(lp_clk_is_t mode)
Set Low Power clock.
Definition: hw_clk.h:138
ahb_div2
Divide by 2.
Definition: hw_clk.h:77
sysclk_RC32
RC32.
Definition: hw_clk_da1459x.h:130
ahb_div4
Divide by 4.
Definition: hw_clk.h:78
apb_div_t
enum apbdiv_type apb_div_t
The AMBA Peripheral Bus (APB) clock divider.
hw_clk_enable_rcx
__STATIC_INLINE void hw_clk_enable_rcx(void)
Enable RCX but does not set it as the LP clock.
Definition: hw_clk_da1459x.h:477
sdk_defs.h
Central include header file with platform definitions.
apb_div2
Divide by 2.
Definition: hw_clk.h:89
hw_clk_get_sys_clk_freq
__STATIC_FORCEINLINE uint32_t hw_clk_get_sys_clk_freq(sys_clk_t sys_clk)
Get the system clock frequency.
Definition: hw_clk.h:289
hw_clk_enable_xtal32k
__STATIC_INLINE void hw_clk_enable_xtal32k(void)
Enable XTAL32K but do not set it as the LP clock.
Definition: hw_clk_da1459x.h:512
hw_clk_lp_set_ext32k
__STATIC_INLINE void hw_clk_lp_set_ext32k(void)
Set an external digital clock as the Low Power clock.
Definition: hw_clk_da1459x.h:388
hw_clk_configure_lpclk
__STATIC_INLINE void hw_clk_configure_lpclk(lp_clk_is_t clk)
Configure a Low Power clock. This must be done only once since the register is retained.
Definition: hw_clk.h:209
apb_div1
Divide by 1.
Definition: hw_clk.h:88
hw_clk_configure_xtal32k
__STATIC_INLINE void hw_clk_configure_xtal32k(void)
Configure XTAL32K. This must be done only once since the register is retained.
Definition: hw_clk_da1459x.h:497
sysclk_XTAL32M
32MHz
Definition: hw_clk_da1459x.h:131
hw_clk_lp_is_rclp
__STATIC_INLINE bool hw_clk_lp_is_rclp(void)
Check whether the RCLP is the Low Power clock.
Definition: hw_clk_da1459x.h:323
apb_div8
Divide by 8.
Definition: hw_clk.h:91
lp_clk_is_type
lp_clk_is_type
The type of the LP clock.
Definition: hw_clk.h:60
hw_clk_get_pclk_div
__STATIC_FORCEINLINE apb_div_t hw_clk_get_pclk_div(void)
Get the divider of the AMBA Peripheral Bus.
Definition: hw_clk.h:110
hw_clk_disable_xtal32k
__STATIC_INLINE void hw_clk_disable_xtal32k(void)
Disable XTAL32K.
Definition: hw_clk_da1459x.h:522
hw_clk_da1459x.h
Clock Driver header file.
hw_clk_disable_rcx
__STATIC_INLINE void hw_clk_disable_rcx(void)
Disable RCX.
Definition: hw_clk_da1459x.h:487
hw_clk_enable_rclp
__STATIC_INLINE void hw_clk_enable_rclp(void)
Enable RCLP.
Definition: hw_clk_da1459x.h:433
ahbdiv_type
ahbdiv_type
The AMBA High-Performance Bus (AHB) clock divider.
Definition: hw_clk.h:75
hw_clk_get_hclk_div
__STATIC_FORCEINLINE ahb_div_t hw_clk_get_hclk_div(void)
Get the divider of the AMBA High Speed Bus.
Definition: hw_clk.h:100
sys_clk_t
enum sysclk_type sys_clk_t
The system clock type.
hw_clk_disable_lpclk
__STATIC_INLINE void hw_clk_disable_lpclk(lp_clk_is_t clk)
Deactivate a Low Power clock.
Definition: hw_clk.h:261
hw_clk_lpclk_is
__STATIC_INLINE bool hw_clk_lpclk_is(lp_clk_is_t clk)
Check whether a clock is the Low Power clock.
Definition: hw_clk.h:168
ahb_div_t
enum ahbdiv_type ahb_div_t
The AMBA High-Performance Bus (AHB) clock divider.
hw_clk_delay_usec
__RETAINED_CODE void hw_clk_delay_usec(uint32_t usec)
Add delay of N usecs.
ahb_div8
Divide by 8.
Definition: hw_clk.h:79
mode
HW_GPIO_MODE mode
Definition: hw_gpio.h:211
hw_clk_lp_is_external
__STATIC_INLINE bool hw_clk_lp_is_external(void)
Check whether the RCX is the Low Power clock.
Definition: hw_clk_da1459x.h:345
hw_clk_enable_lpclk
__STATIC_INLINE void hw_clk_enable_lpclk(lp_clk_is_t clk)
Activate a Low Power clock.
Definition: hw_clk.h:235
hw_clk_lp_is_rcx
__STATIC_INLINE bool hw_clk_lp_is_rcx(void)
Check whether the RCX is the Low Power clock.
Definition: hw_clk_da1459x.h:334
GLOBAL_INT_RESTORE
#define GLOBAL_INT_RESTORE()
Macro to restore all interrupts.
Definition: sdk_defs.h:477
hw_clk_lp_set_xtal32k
__STATIC_INLINE void hw_clk_lp_set_xtal32k(void)
Set XTAL32K as the Low Power clock.
Definition: hw_clk_da1459x.h:374
sysclk_DBLR64
64MHz
Definition: hw_clk_da1459x.h:132
REG_GETF
#define REG_GETF(base, reg, field)
Return the value of a register field.
Definition: sdk_defs.h:711
hw_clk_disable_rclp
__STATIC_INLINE void hw_clk_disable_rclp(void)
Disable RCLP.
Definition: hw_clk_da1459x.h:443
lp_clk_is_t
enum lp_clk_is_type lp_clk_is_t
The type of the LP clock.
hw_clk_lp_set_rcx
__STATIC_INLINE void hw_clk_lp_set_rcx(void)
Set RCX as the Low Power clock.
Definition: hw_clk_da1459x.h:358
hw_clk_lp_set_rclp
__STATIC_INLINE void hw_clk_lp_set_rclp(void)
Set RCLP as the Low Power clock.
Definition: hw_clk_da1459x.h:458
apb_div4
Divide by 4.
Definition: hw_clk.h:90
hw_clk_get_lpclk
__STATIC_INLINE lp_clk_is_t hw_clk_get_lpclk(void)
Return the clock used as the Low Power clock.
Definition: hw_clk.h:192
ahb_div1
Divide by 1.
Definition: hw_clk.h:76
hw_clk_set_pclk_div
__STATIC_FORCEINLINE void hw_clk_set_pclk_div(apb_div_t div)
Set the divider of the AMBA Peripheral Bus.
Definition: hw_clk.h:123
apbdiv_type
apbdiv_type
The AMBA Peripheral Bus (APB) clock divider.
Definition: hw_clk.h:87
GLOBAL_INT_DISABLE
#define GLOBAL_INT_DISABLE()
Macro to disable all interrupts.
Definition: sdk_defs.h:452
ahb_div16
Divide by 16.
Definition: hw_clk.h:80
hw_clk_get_sysclk_freq
__RETAINED_CODE uint32_t hw_clk_get_sysclk_freq(void)
Get current system clock's frequency.