SmartSnippets DA1459x SDK
hw_cache_da1459x.h
Go to the documentation of this file.
1 
42 #ifndef HW_CACHE_DA1459X_H_
43 #define HW_CACHE_DA1459X_H_
44 
45 
46 #include <sdk_defs.h>
47 
48 /*
49  * ENUMERATION DEFINITIONS
50  *****************************************************************************************
51  */
52 
57 typedef enum {
58  HW_CACHE_EFLASH_REGION_SZ_512KB = 4,
59  HW_CACHE_EFLASH_REGION_SZ_256KB = 5,
60  HW_CACHE_EFLASH_REGION_SZ_128KB = 6,
61  HW_CACHE_EFLASH_REGION_SZ_64KB = 7,
62  HW_CACHE_EFLASH_REGION_SZ_INVALID, /* Used as iteration terminator */
64 
65 typedef uint16_t eflash_region_base_t;
66 typedef uint16_t eflash_region_offset_t;
67 
68 #define HW_CACHE_EFLASH_DEFAULT_REGION_BASE 0x00A0
69 #define HW_CACHE_EFLASH_MAX_REGION_BASE 0xFF
70 #define HW_CACHE_EFLASH_DEFAULT_REGION_OFFSET 0x0
71 #define HW_CACHE_EFLASH_MAX_REGION_OFFSET 0xFFF
72 #define HW_CACHE_EFLASH_DEFAULT_REGION_SZ HW_CACHE_EFLASH_REGION_SZ_128KB
73 #define HW_CACHE_EFLASH_MIN_REGION_SZ HW_CACHE_EFLASH_REGION_SZ_64KB
74 #define HW_CACHE_EFLASH_MAX_REGION_SZ HW_CACHE_EFLASH_REGION_SZ_512KB
75 
80 typedef enum {
81  HW_CACHE_FLASH_REGION_SZ_32MB = 0,
82  HW_CACHE_FLASH_REGION_SZ_16MB = 1,
83  HW_CACHE_FLASH_REGION_SZ_8MB = 2,
84  HW_CACHE_FLASH_REGION_SZ_4MB = 3,
85  HW_CACHE_FLASH_REGION_SZ_2MB = 4,
86  HW_CACHE_FLASH_REGION_SZ_1MB = 5,
87  HW_CACHE_FLASH_REGION_SZ_512KB = 6,
88  HW_CACHE_FLASH_REGION_SZ_256KB = 7,
89  HW_CACHE_FLASH_REGION_SZ_INVALID, /* Used as iteration terminator */
91 
92 typedef uint16_t flash_region_base_t;
93 typedef uint16_t flash_region_offset_t;
94 
95 #define HW_CACHE_FLASH_DEFAULT_REGION_BASE 0x1600
96 #define HW_CACHE_FLASH_MAX_REGION_BASE 0x17fc
97 #define HW_CACHE_FLASH_DEFAULT_REGION_OFFSET 0x0
98 #define HW_CACHE_FLASH_MAX_REGION_OFFSET 0xFFF
99 #define HW_CACHE_FLASH_DEFAULT_REGION_SZ HW_CACHE_FLASH_REGION_SZ_512KB
100 #define HW_CACHE_FLASH_MIN_REGION_SZ HW_CACHE_FLASH_REGION_SZ_256KB
101 #define HW_CACHE_FLASH_MAX_REGION_SZ HW_CACHE_FLASH_REGION_SZ_32MB
102 
103 /*
104  * FAMILY SPECIFIC GENERIC FUNCTIONALITY DEFINITIONS
105  *****************************************************************************************
106  */
107 
116 __STATIC_INLINE void hw_cache_enable()
117 {
118  REG_SET_BIT(CRG_TOP, SYS_CTRL_REG, CACHERAM_MUX);
119  /* Wait until the CACHERAM_MUX=1 (because of the APB Bridge). */
120  while (REG_GETF(CRG_TOP, SYS_CTRL_REG, CACHERAM_MUX) != 1) {}
121 }
122 
131 __STATIC_INLINE void hw_cache_disable()
132 {
133  REG_CLR_BIT(CRG_TOP, SYS_CTRL_REG, CACHERAM_MUX);
134  /* Wait until the CACHERAM_MUX=0 (because of the APB Bridge). */
135  while (REG_GETF(CRG_TOP, SYS_CTRL_REG, CACHERAM_MUX) != 0) {}
136 }
137 
145 __STATIC_INLINE bool hw_cache_is_enabled()
146 {
147  return REG_GETF(CRG_TOP, SYS_CTRL_REG, CACHERAM_MUX);
148 }
149 
160 __STATIC_INLINE void hw_cache_set_extflash_cacheable_len(uint32_t len)
161 {
162  ASSERT_WARNING((len & ~CACHE_CACHE_CTRL2_REG_CACHE_LEN_Msk) == 0);
163  REG_SETF(CACHE, CACHE_CTRL2_REG, CACHE_LEN, len);
164 }
165 
172 __STATIC_INLINE int hw_cache_get_extflash_cacheable_len(void)
173 {
174  return REG_GETF(CACHE, CACHE_CTRL2_REG, CACHE_LEN);
175 }
176 
177 
188 __STATIC_INLINE void hw_cache_set_eflash_cacheable_len(uint32_t len)
189 {
190  ASSERT_WARNING((len & ~(CACHE_CACHE_CTRL2_REG_CACHE_EF_LEN_Msk >>
192  REG_SETF(CACHE, CACHE_CTRL2_REG, CACHE_EF_LEN, len);
193 }
194 
201 __STATIC_INLINE int hw_cache_get_eflash_cacheable_len(void)
202 {
203  return REG_GETF(CACHE, CACHE_CTRL2_REG, CACHE_EF_LEN);
204 }
205 
213 DEPRECATED_MSG("API no longer supported, use hw_cache_set_eflash_cacheable_len.")
214 __STATIC_INLINE void hw_cache_set_len(uint32_t len)
215 {
217 }
218 
225 DEPRECATED_MSG("API no longer supported, use hw_cache_get_eflash_cacheable_len.")
226 __STATIC_INLINE int hw_cache_get_len(void)
227 {
229 }
230 
234 __STATIC_INLINE void hw_cache_enable_flushing(void)
235 {
236  REG_CLR_BIT(CACHE, CACHE_CTRL2_REG, CACHE_FLUSH_DISABLE);
237 }
238 
242 __STATIC_INLINE void hw_cache_disable_flushing(void)
243 {
244  REG_SET_BIT(CACHE, CACHE_CTRL2_REG, CACHE_FLUSH_DISABLE);
245 }
246 
254 __STATIC_INLINE bool hw_cache_is_flushing_disabled()
255 {
256  return REG_GETF(CACHE, CACHE_CTRL2_REG, CACHE_FLUSH_DISABLE);
257 }
258 
265 __STATIC_INLINE void hw_cache_flush(void)
266 {
270  hw_cache_enable();
272  }
273 }
274 
275 /*
276  * CACHEABLE EFLASH RELATED FUNCTIONALITY DEFINITIONS
277  *****************************************************************************************
278  */
279 
290 __STATIC_INLINE void hw_cache_eflash_set_region_base(eflash_region_base_t base)
291 {
292  ASSERT_WARNING(base <= HW_CACHE_EFLASH_MAX_REGION_BASE);
293  REG_SETF(CACHE, CACHE_EFLASH_REG, EFLASH_REGION_BASE, base);
294 }
295 
301 __STATIC_INLINE eflash_region_base_t hw_cache_eflash_get_region_base(void)
302 {
303  return REG_GETF(CACHE, CACHE_EFLASH_REG, EFLASH_REGION_BASE);
304 }
305 
320 __STATIC_INLINE void hw_cache_eflash_set_region_offset(eflash_region_offset_t offset)
321 {
322  ASSERT_WARNING(offset <= HW_CACHE_EFLASH_MAX_REGION_OFFSET);
323  REG_SETF(CACHE, CACHE_EFLASH_REG, EFLASH_REGION_OFFSET, offset);
324 }
325 
332 __STATIC_INLINE eflash_region_offset_t hw_cache_eflash_get_region_offset(void)
333 {
334  return REG_GETF(CACHE, CACHE_EFLASH_REG, EFLASH_REGION_OFFSET);
335 }
336 
349 {
350  ASSERT_WARNING(sz >= HW_CACHE_EFLASH_MAX_REGION_SZ && sz <= HW_CACHE_EFLASH_MIN_REGION_SZ);
351  REG_SETF(CACHE, CACHE_EFLASH_REG, EFLASH_REGION_SIZE, sz);
352 }
353 
360 {
361  return REG_GETF(CACHE, CACHE_EFLASH_REG, EFLASH_REGION_SIZE);
362 }
363 
374 __STATIC_INLINE void hw_cache_eflash_configure_region(eflash_region_base_t base, eflash_region_offset_t offset,
376 {
380 }
381 
382 /*
383  * CACHEABLE FLASH RELATED FUNCTIONALITY DEFINITIONS
384  *****************************************************************************************
385  */
386 
398 __STATIC_INLINE void hw_cache_flash_set_region_base(flash_region_base_t base)
399 {
400  ASSERT_WARNING((base & 0xfe03) == HW_CACHE_FLASH_DEFAULT_REGION_BASE);
401  REG_SETF(CACHE, CACHE_FLASH_REG, FLASH_REGION_BASE, base);
402 }
403 
409 __STATIC_INLINE flash_region_base_t hw_cache_flash_get_region_base(void)
410 {
411  return REG_GETF(CACHE, CACHE_FLASH_REG, FLASH_REGION_BASE);
412 }
413 
428 __STATIC_INLINE void hw_cache_flash_set_region_offset(flash_region_offset_t offset)
429 {
430  ASSERT_WARNING(offset <= HW_CACHE_FLASH_MAX_REGION_OFFSET);
431  REG_SETF(CACHE, CACHE_FLASH_REG, FLASH_REGION_OFFSET, offset);
432 }
433 
440 __STATIC_INLINE flash_region_offset_t hw_cache_flash_get_region_offset(void)
441 {
442  return REG_GETF(CACHE, CACHE_FLASH_REG, FLASH_REGION_OFFSET);
443 }
444 
457 {
458  ASSERT_WARNING(sz >= HW_CACHE_FLASH_MAX_REGION_SZ && sz <= HW_CACHE_FLASH_MIN_REGION_SZ);
459  REG_SETF(CACHE, CACHE_FLASH_REG, FLASH_REGION_SIZE, sz);
460 }
461 
468 {
469  return REG_GETF(CACHE, CACHE_FLASH_REG, FLASH_REGION_SIZE);
470 }
471 
482 __STATIC_INLINE void hw_cache_flash_configure_region(flash_region_base_t base, flash_region_offset_t offset,
484 {
488 }
489 
490 /*
491  * MRM RELATED FUNCTIONALITY DEFINITIONS
492  *****************************************************************************************
493  */
500 __STATIC_INLINE uint32_t hw_cache_mrm_get_hits_with_one_wait_state(void)
501 {
502  return CACHE->CACHE_MRM_HITS1WS_REG;
503 }
504 
513 __STATIC_INLINE void hw_cache_mrm_set_hits_with_one_wait_state(uint32_t hits)
514 {
515  CACHE->CACHE_MRM_HITS1WS_REG = hits;
516 }
517 
518 
519 #endif /* HW_CACHE_DA1459X_H_ */
520 
hw_cache_get_extflash_cacheable_len
__STATIC_INLINE int hw_cache_get_extflash_cacheable_len(void)
Get the external (QSPI) flash cacheable memory length.
Definition: hw_cache_da1459x.h:172
hw_cache_flash_configure_region
__STATIC_INLINE void hw_cache_flash_configure_region(flash_region_base_t base, flash_region_offset_t offset, HW_CACHE_FLASH_REGION_SZ sz)
Configure the flash memory region that will be cacheable.
Definition: hw_cache_da1459x.h:482
hw_cache_eflash_get_region_size
__STATIC_INLINE HW_CACHE_EFLASH_REGION_SZ hw_cache_eflash_get_region_size(void)
Get the eflash region size.
Definition: hw_cache_da1459x.h:359
hw_cache_eflash_set_region_size
__STATIC_INLINE void hw_cache_eflash_set_region_size(HW_CACHE_EFLASH_REGION_SZ sz)
Set the eflash region size.
Definition: hw_cache_da1459x.h:348
REG_SETF
#define REG_SETF(base, reg, field, new_val)
Set the value of a register field.
Definition: sdk_defs.h:738
REG_CLR_BIT
#define REG_CLR_BIT(base, reg, field)
Clear a bit of a register.
Definition: sdk_defs.h:781
hw_cache_enable_flushing
__STATIC_INLINE void hw_cache_enable_flushing(void)
Enable flushing the iCache Controller (cache RAM cells) contents. For debugging only.
Definition: hw_cache_da1459x.h:234
hw_cache_flash_get_region_offset
__STATIC_INLINE flash_region_offset_t hw_cache_flash_get_region_offset(void)
Get the flash region offset.
Definition: hw_cache_da1459x.h:440
REG_SET_BIT
#define REG_SET_BIT(base, reg, field)
Set a bit of a register.
Definition: sdk_defs.h:766
CACHE_CACHE_CTRL2_REG_CACHE_EF_LEN_Pos
#define CACHE_CACHE_CTRL2_REG_CACHE_EF_LEN_Pos
Definition: DA1459x-00.h:1612
hw_cache_eflash_get_region_offset
__STATIC_INLINE eflash_region_offset_t hw_cache_eflash_get_region_offset(void)
Get the eflash region offset.
Definition: hw_cache_da1459x.h:332
sdk_defs.h
Central include header file with platform definitions.
hw_cache_mrm_set_hits_with_one_wait_state
__STATIC_INLINE void hw_cache_mrm_set_hits_with_one_wait_state(uint32_t hits)
Set the cache MRM hits with 1 Wait State number.
Definition: hw_cache_da1459x.h:513
hw_cache_set_extflash_cacheable_len
__STATIC_INLINE void hw_cache_set_extflash_cacheable_len(uint32_t len)
Set the external (QSPI) flash cacheable memory length.
Definition: hw_cache_da1459x.h:160
CACHE_CACHE_CTRL2_REG_CACHE_EF_LEN_Msk
#define CACHE_CACHE_CTRL2_REG_CACHE_EF_LEN_Msk
Definition: DA1459x-00.h:1613
CACHE_CACHE_CTRL2_REG_CACHE_LEN_Msk
#define CACHE_CACHE_CTRL2_REG_CACHE_LEN_Msk
Definition: DA1459x-00.h:1627
hw_cache_eflash_set_region_offset
__STATIC_INLINE void hw_cache_eflash_set_region_offset(eflash_region_offset_t offset)
Set the eflash region offset.
Definition: hw_cache_da1459x.h:320
hw_cache_set_len
__STATIC_INLINE void hw_cache_set_len(uint32_t len)
Set the cacheable memory length. Backwards compatibility wrapper.
Definition: hw_cache_da1459x.h:214
hw_cache_eflash_get_region_base
__STATIC_INLINE eflash_region_base_t hw_cache_eflash_get_region_base(void)
Get the eflash region base.
Definition: hw_cache_da1459x.h:301
hw_cache_get_eflash_cacheable_len
__STATIC_INLINE int hw_cache_get_eflash_cacheable_len(void)
Get the eflash cacheable memory length.
Definition: hw_cache_da1459x.h:201
hw_cache_flash_get_region_base
__STATIC_INLINE flash_region_base_t hw_cache_flash_get_region_base(void)
Get the flash region base.
Definition: hw_cache_da1459x.h:409
hw_cache_eflash_set_region_base
__STATIC_INLINE void hw_cache_eflash_set_region_base(eflash_region_base_t base)
Set the eflash region base.
Definition: hw_cache_da1459x.h:290
hw_cache_eflash_configure_region
__STATIC_INLINE void hw_cache_eflash_configure_region(eflash_region_base_t base, eflash_region_offset_t offset, HW_CACHE_EFLASH_REGION_SZ sz)
Configure the eflash memory region that will be cacheable.
Definition: hw_cache_da1459x.h:374
HW_CACHE_EFLASH_REGION_SZ
HW_CACHE_EFLASH_REGION_SZ
Cacheable eflash Region Sizes as defined in DA1459x datasheet.
Definition: hw_cache_da1459x.h:57
hw_cache_mrm_get_hits_with_one_wait_state
__STATIC_INLINE uint32_t hw_cache_mrm_get_hits_with_one_wait_state(void)
Get the cache MRM hits with 1 Wait State number.
Definition: hw_cache_da1459x.h:500
hw_cache_disable
__STATIC_INLINE void hw_cache_disable()
Disables the iCache Controller.
Definition: hw_cache_da1459x.h:131
hw_cache_flash_set_region_base
__STATIC_INLINE void hw_cache_flash_set_region_base(flash_region_base_t base)
Set the flash region base.
Definition: hw_cache_da1459x.h:398
hw_cache_get_len
__STATIC_INLINE int hw_cache_get_len(void)
Get the cacheable memory length. Backwards compatibility wrapper.
Definition: hw_cache_da1459x.h:226
hw_cache_set_eflash_cacheable_len
__STATIC_INLINE void hw_cache_set_eflash_cacheable_len(uint32_t len)
Set the eflash cacheable memory length.
Definition: hw_cache_da1459x.h:188
hw_cache_enable
__STATIC_INLINE void hw_cache_enable()
Enables the iCache Controller.
Definition: hw_cache_da1459x.h:116
GLOBAL_INT_RESTORE
#define GLOBAL_INT_RESTORE()
Macro to restore all interrupts.
Definition: sdk_defs.h:477
hw_cache_disable_flushing
__STATIC_INLINE void hw_cache_disable_flushing(void)
Disable flushing the iCache Controller (cache RAM cells) contents. For debugging only.
Definition: hw_cache_da1459x.h:242
REG_GETF
#define REG_GETF(base, reg, field)
Return the value of a register field.
Definition: sdk_defs.h:711
hw_cache_flash_set_region_size
__STATIC_INLINE void hw_cache_flash_set_region_size(HW_CACHE_FLASH_REGION_SZ sz)
Set the flash region size.
Definition: hw_cache_da1459x.h:456
HW_CACHE_FLASH_REGION_SZ
HW_CACHE_FLASH_REGION_SZ
Cacheable flash Region Sizes as defined in DA1459x datasheet.
Definition: hw_cache_da1459x.h:80
hw_cache_flash_get_region_size
__STATIC_INLINE HW_CACHE_FLASH_REGION_SZ hw_cache_flash_get_region_size(void)
Get the flash region size.
Definition: hw_cache_da1459x.h:467
hw_cache_flush
__STATIC_INLINE void hw_cache_flush(void)
Flush the cache contents.
Definition: hw_cache_da1459x.h:265
hw_cache_is_enabled
__STATIC_INLINE bool hw_cache_is_enabled()
Checks if the iCache Controller is enabled.
Definition: hw_cache_da1459x.h:145
hw_cache_is_flushing_disabled
__STATIC_INLINE bool hw_cache_is_flushing_disabled()
Checks if the iCache Controller flushing is disabled. For debugging only.
Definition: hw_cache_da1459x.h:254
hw_cache_flash_set_region_offset
__STATIC_INLINE void hw_cache_flash_set_region_offset(flash_region_offset_t offset)
Set the flash region offset.
Definition: hw_cache_da1459x.h:428
GLOBAL_INT_DISABLE
#define GLOBAL_INT_DISABLE()
Macro to disable all interrupts.
Definition: sdk_defs.h:452