SmartSnippets DA1459x SDK
sdk_defs.h
Go to the documentation of this file.
1 
44 #ifndef __SDK_DEFS_H__
45 #define __SDK_DEFS_H__
46 
47 #include <stddef.h>
48 
49 #ifdef __cplusplus
50  extern "C" {
51 #endif
52 
53 #ifdef __GNUC__
54 # define GCC_VERSION (__GNUC__ * 10000 \
55  + __GNUC_MINOR__ * 100 \
56  + __GNUC_PATCHLEVEL__)
57 /* assert gcc version is at least 4.9.3 */
58 # if GCC_VERSION < 40903
59 # error "Please use gcc version 4.9.3 or newer!"
60 # endif
61 #endif
62 
63 # include "DA1459x-00.h"
64 
65 #include "system_DA1459x.h" /* DA1459x System */
66 
73 #define MTB_MASTER_REG ((uint32_t *) 0xE0043004)
74 #define MTB_MASTER_REG_DISABLE_VAL (dg_configMTB_MASK)
75 
76 
77 /************************
78  * Memory map
79  ************************/
80 
84 #define MEMORY_REMAPPED_BASE 0x00000000UL
85  /* The max remapped region size according to FLASH_REGION_SIZE register field */
86 #define MEMORY_REMAPPED_END 0x02000000UL
87 
91 #define MEMORY_REMAPPED_SIZE (MEMORY_REMAPPED_END - MEMORY_REMAPPED_BASE)
92 
96 #define MEMORY_ROM_BASE 0x900000UL
97 #define MEMORY_ROM_END (MEMORY_ROM_BASE + 0x48000L)
98 
102 #define MEMORY_ROM_SIZE (MEMORY_ROM_END - MEMORY_ROM_BASE)
103 
115 #define MEMORY_SYSRAM_S_BASE 0x20000000UL
116 #define MEMORY_SYSRAM_S_END (MEMORY_SYSRAM_S_BASE + 0x18000UL)
117 
121 #define MEMORY_SYSRAM_S_SIZE (MEMORY_SYSRAM_S_END - MEMORY_SYSRAM_S_BASE)
122 
126 #define MEMORY_SYSRAM_BASE 0x00800000UL
127 #define MEMORY_SYSRAM_END (MEMORY_SYSRAM_BASE + 0x18000UL)
128 
132 #define MEMORY_SYSRAM_SIZE (MEMORY_SYSRAM_END - MEMORY_SYSRAM_BASE)
133 
137 #define MEMORY_CACHERAM_BASE 0x36000000UL
138 #define MEMORY_CACHERAM_END 0x36002000UL
139 #define MEMORY_CMAC_CACHERAM_BASE 0x40108000UL
140 #define MEMORY_CMAC_CACHERAM_END 0x4010A000UL
141 
145 #define MEMORY_CACHERAM_SIZE (MEMORY_CACHERAM_END - MEMORY_CACHERAM_BASE)
146 #define MEMORY_CMAC_CACHERAM_SIZE (MEMORY_CMAC_CACHERAM_END - MEMORY_CMAC_CACHERAM_BASE)
147 
155 #define MEMORY_QSPIF_BASE (0x16000000UL)
156 #define MEMORY_QSPIF_END (MEMORY_QSPIF_BASE + 0x2000000UL)
157 
161 #define MEMORY_QSPIF_S_BASE (0x32000000UL)
162 #define MEMORY_QSPIF_S_END (MEMORY_QSPIF_S_BASE + 0x2000000UL)
163 
167 #define MEMORY_QSPIF_SIZE (MEMORY_QSPIF_END - MEMORY_QSPIF_BASE)
168 
173 #define MEMORY_EFLASH_BASE (0xA00000UL)
174 #define MEMORY_EFLASH_END (MEMORY_EFLASH_BASE + 0x40800UL)
175 
180 #define MEMORY_EFLASH_S_BASE (0x31000000UL)
181 #define MEMORY_EFLASH_S_END (MEMORY_EFLASH_S_BASE + 0x40800UL)
182 
186 #define MEMORY_EFLASH_SIZE (MEMORY_EFLASH_END - MEMORY_EFLASH_BASE)
187 
191 #if defined(NVMS_PRODUCT_HEADER_PART_START)
192 # if (dg_configCODE_LOCATION == NON_VOLATILE_IS_EMBEDDED_FLASH) || \
193  (dg_configCODE_LOCATION == NON_VOLATILE_IS_QSPI_FLASH)
194 # define PRIMARY_PRODUCT_HEADER_BASE (NVMS_PRODUCT_HEADER_PART_START)
195 # else
196 # undef PRIMARY_PRODUCT_HEADER_BASE
197 # endif
198 #else
199 # if (dg_configCODE_LOCATION == NON_VOLATILE_IS_EMBEDDED_FLASH)
200 # define PRIMARY_PRODUCT_HEADER_BASE (EFLASH_MEM1_VIRTUAL_BASE_ADDR + 0x1000)
201 # elif (dg_configCODE_LOCATION == NON_VOLATILE_IS_QSPI_FLASH)
202 # define PRIMARY_PRODUCT_HEADER_BASE (QSPI_MEM1_VIRTUAL_BASE_ADDR + 0x1000)
203 # else
204 # undef PRIMARY_PRODUCT_HEADER_BASE
205 # endif
206 #endif
207 
211 #if (dg_configCODE_LOCATION == NON_VOLATILE_IS_EMBEDDED_FLASH)
212 # define BACKUP_PRODUCT_HEADER_BASE (PRIMARY_PRODUCT_HEADER_BASE + 0x800)
213 #elif (dg_configCODE_LOCATION == NON_VOLATILE_IS_QSPI_FLASH)
214 # define BACKUP_PRODUCT_HEADER_BASE (PRIMARY_PRODUCT_HEADER_BASE + 0x1000)
215 #else
216 # undef BACKUP_PRODUCT_HEADER_BASE
217 #endif
218 
219 
229 #define MEMORY_EFLASH_USER_DATA_KEYS_BASE (0x00000800UL)
230 #define MEMORY_EFLASH_USER_DATA_KEYS_END (0x00000900UL)
231 #define MEMORY_EFLASH_USER_DATA_KEYS_REVOCATION_BASE (0x000007C0UL)
232 #define MEMORY_EFLASH_USER_DATA_KEYS_REVOCATION_END (0x000007DFUL)
233 #define MEMORY_EFLASH_USER_DATA_KEY_SIZE (0x20)
234 
235 
236 #define WITHIN_RANGE(_a, _s, _e) (((uint32_t)(_a) >= (uint32_t)(_s)) && ((uint32_t)(_a) < (uint32_t)(_e)))
237 
241 #define IS_REMAPPED_ADDRESS(_a) WITHIN_RANGE((_a), MEMORY_REMAPPED_BASE, MEMORY_REMAPPED_END)
242 
246 #define IS_ROM_ADDRESS(_a) WITHIN_RANGE((_a), MEMORY_ROM_BASE, MEMORY_ROM_END)
247 
254 #define IS_SYSRAM_ADDRESS(_a) WITHIN_RANGE((_a), MEMORY_SYSRAM_BASE, MEMORY_SYSRAM_END)
255 
259 #define IS_SYSRAM_S_ADDRESS(_a) WITHIN_RANGE((_a), MEMORY_SYSRAM_S_BASE, MEMORY_SYSRAM_S_END)
260 
264 #define IS_CACHERAM_ADDRESS(_a) WITHIN_RANGE((_a), MEMORY_CACHERAM_BASE, MEMORY_CACHERAM_END)
265 
269 #define IS_QSPIF_ADDRESS(_a) WITHIN_RANGE((_a), MEMORY_QSPIF_BASE, MEMORY_QSPIF_END)
270 
274 #define IS_QSPIF_S_ADDRESS(_a) WITHIN_RANGE((_a), MEMORY_QSPIF_S_BASE, MEMORY_QSPIF_S_END)
275 
279 #define IS_EFLASH_ADDRESS(_a) WITHIN_RANGE((_a), MEMORY_EFLASH_BASE, MEMORY_EFLASH_END)
280 
284 #define IS_EFLASH_S_ADDRESS(_a) WITHIN_RANGE((_a), MEMORY_EFLASH_S_BASE, MEMORY_EFLASH_S_END)
285 
289 #define FLASH_SECTOR_SIZE (0x1000)
290 
291 
292 
293 
298 #define EFLASH_MEM1_VIRTUAL_BASE_ADDR (0x00000000)
299 
307 #define QSPI_MEM1_VIRTUAL_BASE_ADDR (((EFLASH_MEM1_VIRTUAL_BASE_ADDR + MEMORY_EFLASH_SIZE) \
308  & ~(FLASH_SECTOR_SIZE - 1)) + FLASH_SECTOR_SIZE)
309 
313 #define __RETAINED __attribute__((section("retention_mem_zi"))) // RetRAM0
314 #define __RETAINED_1 __attribute__((section("retention_mem_1_zi"))) // RetRAM1
315 
319 #define __RETAINED_RW __attribute__((section("retention_mem_init")))
320 
325 #define __RETAINED_UNINIT __attribute__((section("retention_mem_uninit")))
326 
330 #define __RETAINED_CONST_INIT __attribute__((section("retention_mem_const")))
331 
335 #ifdef CONFIG_USE_BLE
336 #define __RETAINED_CMI __attribute__((section("retention_mem_cmi_zi")))
337 #else
338 #define __RETAINED_CMI __RETAINED
339 #endif /* CONFIG_USE_BLE */
340 
344 #define __RETAIN_CODE_ATTR __attribute__((section("text_retained"))) __attribute__((noinline)) __attribute__((optimize ("no-tree-switch-conversion")))
345 # if dg_configREDUCE_RETAINED_CODE
346 // When the code is executed from eFlash if dg_configREDUCE_RETAINED_CODE == 1, the __ALWAYS_RETAINED_CODE attribute is used to selectively
347 // retain only the necessary functions in SysRAM. When dg_configREDUCE_RETAINED_CODE is set to 0, the system requires more functions to be retained in SysRAM.
348 // The __RETAINED_CODE and __ALWAYS_RETAINED_CODE attributes determine which functions will be retained.
349 // When the code is executed from QSPI the dg_configREDUCE_RETAINED_CODE can only be set to 0. The __RETAINED_CODE and __ALWAYS_RETAINED_CODE attributes determine which functions
350 // will be retained in RAM. Please refer to definition of dg_configREDUCE_RETAINED_CODE for more details.
351 # if ((dg_configCODE_LOCATION == NON_VOLATILE_IS_EMBEDDED_FLASH) && \
352  (dg_configEXEC_MODE == MODE_IS_CACHED))
353 # define __RETAINED_CODE
354 # define __ALWAYS_RETAINED_CODE __RETAIN_CODE_ATTR
355 # else /* RAM build */
356 # define __RETAINED_CODE
357 # define __ALWAYS_RETAINED_CODE
358 # endif
359 # else /* dg_configREDUCE_RETAINED_CODE == 0 */
360 # if (((dg_configCODE_LOCATION == NON_VOLATILE_IS_QSPI_FLASH) || \
361  (dg_configCODE_LOCATION == NON_VOLATILE_IS_EMBEDDED_FLASH)) && \
362  (dg_configEXEC_MODE == MODE_IS_CACHED))
363 # define __RETAINED_CODE __RETAIN_CODE_ATTR
364 # define __ALWAYS_RETAINED_CODE __RETAIN_CODE_ATTR
365 # else /* RAM build */
366 # define __RETAINED_CODE
367 # define __ALWAYS_RETAINED_CODE
368 # endif
369 # endif /* dg_configREDUCE_RETAINED_CODE */
370 
371 
372 # if dg_configRETAIN_HOT_CODE
373 # define __RETAINED_HOT_CODE __RETAINED_CODE
374 # else
375 # define __RETAINED_HOT_CODE
376 # endif
377 
381 #define __UNUSED __attribute__((unused))
382 
386 #define __LTO_EXT __attribute__((externally_visible))
387 
388 // Forward declaration
389 __ALWAYS_RETAINED_CODE void hw_sys_assert_trigger_gpio(void);
390 
396 #if (dg_configIMAGE_SETUP == DEVELOPMENT_MODE)
398 void assertion_functions_set_to_init(void);
399 
400 #define ASSERT_WARNING(a) if (!(a)) { \
401  extern __NO_RETURN void (*assert_warning_func)(void); \
402  register unsigned r4 __asm__("r4") = (uint32_t)&assert_warning_func; \
403  __asm__ volatile ( \
404  " .syntax unified \n" \
405  "LDR r4, [r4, #0]\n" \
406  "BX r4 \n" \
407  : \
408  : "r" (r4) \
409  : "r0","r1","r2","r3" /* force the compiler to avoid R0-R3 */ \
410  ); \
411  __builtin_unreachable(); \
412  }
413 #else
414 #define ASSERT_WARNING(a) do { if (!(a)); } while (0);
415 #endif /* dg_configIMAGE_SETUP */
416 #define ASSERT_WARNING_UNINIT(a) ASSERT_WARNING(a)
417 
422 #if (dg_configIMAGE_SETUP == DEVELOPMENT_MODE)
423 #define ASSERT_ERROR(a) ASSERT_WARNING(a)
424 #else
425 #define ASSERT_ERROR(a) if (!(a)) { \
426  __asm__ volatile ( \
427  " .syntax unified \n" \
428  "CPSID I\n" \
429  "BKPT 2\n" \
430  : \
431  : \
432  : "memory" \
433  ); \
434  __builtin_unreachable(); \
435  }
436 #endif /* dg_configIMAGE_SETUP */
437 
438 #define ASSERT_ERROR_UNINIT(a) ASSERT_ERROR(a)
439 
453 #define GLOBAL_INT_DISABLE() \
454  do { \
455  unsigned int __l_irq_rest; \
456  __ASM volatile ("mrs %0, primask \n\t" \
457  "mov r1, $1 \n\t" \
458  "msr primask, r1 \n\t" \
459  : "=r" (__l_irq_rest) \
460  : \
461  : "r1" \
462  ); \
463  DBG_CONFIGURE_HIGH(CMN_TIMING_DEBUG, CMNDBG_CRITICAL_SECTION);
464 
478 #define GLOBAL_INT_RESTORE() \
479  if (__l_irq_rest == 0) { \
480  DBG_CONFIGURE_LOW(CMN_TIMING_DEBUG, CMNDBG_CRITICAL_SECTION); \
481  } \
482  __ASM volatile ("msr primask, %0 \n\t" \
483  : \
484  : "r" (__l_irq_rest) \
485  : \
486  ); \
487  } while (0)
488 
489 #define containingoffset(address, type, field) ((type*)((uint8*)(address)-(size_t)(&((type*)0)->field)))
490 
497 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
498 
505 #define MAX(a, b) (((a) > (b)) ? (a) : (b))
506 
512 #if defined(__GNUC__)
513 #define SWAP16(a) __builtin_bswap16(a)
514 #else
515 #define SWAP16(a) ((a<<8) | (a>>8))
516 #endif
517 
523 #if defined(__GNUC__)
524 #define SWAP32(a) __builtin_bswap32(a)
525 #else
526 #define SWAP32(a) ((a>>24 & 0xff) | (a>>8 & 0xff00) | (a<<8 & 0xff0000) | (a<<24 & 0xff000000))
527 #endif
528 
529 #if defined(__GNUC__)
530 #define DEPRECATED __attribute__((deprecated))
531 #else
532 #pragma message "Deprecated macro must be implemented for this compiler"
533 #define DEPRECATED
534 #endif
535 
536 #if defined(__GNUC__)
537 #define DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
538 #else
539 #pragma message "Deprecated macro must be implemented for this compiler"
540 #define DEPRECATED_MSG(msg)
541 #endif
542 
543 #if defined(__GNUC__)
544 #define DEPRECATED_MACRO(macro, msg) DEPRECATED_MSG(msg) __STATIC_INLINE void macro(void) {}
545 #else
546 #pragma message "Deprecated macro must be implemented for this compiler"
547 #define DEPRECATED_MACRO(macro, msg)
548 #endif
549 
550 /* The following exist in ROM code */
551 void __aeabi_memcpy(void *dest, const void *src, size_t n);
552 void __aeabi_memmove(void *dest, const void *src, size_t n);
553 void __aeabi_memset(void *dest, size_t n, int c);
554 
558 #define OPT_MEMCPY __aeabi_memcpy
559 
563 #define OPT_MEMMOVE __aeabi_memmove
564 
568 #define OPT_MEMSET(s, c, n) __aeabi_memset(s, n, c)
569 
584 #define REG_MSK(base, reg, field) \
585  (base ## _ ## reg ## _ ## field ## _Msk)
586 
592 #define REG_POS(base, reg, field) \
593  (base ## _ ## reg ## _ ## field ## _Pos)
594 
608 #define REG_GET_FIELD(base, reg, field, var) \
609  ((var & (base ## _ ## reg ## _ ## field ## _Msk)) >> \
610  (base ## _ ## reg ## _ ## field ## _Pos))
611 
627 #define REG_SET_FIELD(base, reg, field, var, val) \
628  var = ((var & ~((base ## _ ## reg ## _ ## field ## _Msk))) | \
629  (((val) << (base ## _ ## reg ## _ ## field ## _Pos)) & \
630  (base ## _ ## reg ## _ ## field ## _Msk)))
631 
644 #define RAW_SET_FIELD(mem, mask, val) \
645  mem = ((mem & ~((mask))) | (((val) << (__builtin_ctz(mask))) & (mask)))
646 
662 #define REG_CLR_FIELD(base, reg, field, var) \
663  var &= ~(base ## _ ## reg ## _ ## field ## _Msk)
664 
675 #define REG_GET_ADDR_INDEXED(base, reg, interval, index) \
676  ((&base->reg) + (((intptr_t) index) * ((interval) / sizeof(base->reg))))
677 
697 #define REG_GETF_INDEXED(base, reg, field, interval, index) \
698  (((*REG_GET_ADDR_INDEXED(base, reg, interval, index)) & \
699  (base ## _ ## reg ## _ ## field ## _Msk)) >> (base ## _ ## reg ## _ ## field ## _Pos))
700 
712 #define REG_GETF(base, reg, field) \
713  (((base->reg) & (base##_##reg##_##field##_Msk)) >> (base##_##reg##_##field##_Pos))
714 
726 #define RAW_GETF(addr, mask) \
727  ((*(volatile uint32_t *)(addr) & (mask)) >> (__builtin_ctz(mask)))
728 
739 #define REG_SETF(base, reg, field, new_val) \
740  base->reg = ((base->reg & ~(base##_##reg##_##field##_Msk)) | \
741  ((base##_##reg##_##field##_Msk) & ((new_val) << (base##_##reg##_##field##_Pos))))
742 
753 #define RAW_SETF(addr, mask, val) \
754  (*(volatile uint32_t *)(addr)) = ((*(volatile uint32_t *)(addr) & ~(mask)) | \
755  ((mask) & ((val) << __builtin_ctz(mask))))
756 
767 #define REG_SET_BIT(base, reg, field) \
768  do { \
769  base->reg |= (1 << (base##_##reg##_##field##_Pos)); \
770  } while (0)
771 
782 #define REG_CLR_BIT(base, reg, field) \
783  do { \
784  base->reg &= ~(base##_##reg##_##field##_Msk); \
785  } while (0)
786 
795 #define REG_SET_MASKED(base, reg, mask, value) \
796  do { \
797  base->reg = (base->reg & ~(mask)) | ((value) & (mask)); \
798  } while (0)
799 
808 #define RAW_SET_MASKED(addr, mask, value) \
809  do { \
810  (*(volatile uint32_t *)(addr)) = ((*(volatile uint32_t *)(addr)) & ~(mask)) | ((value) & (mask)); \
811  } while (0)
812 
816 #define BITS16(base, reg, field, v) \
817  ((uint16_t) (((uint16_t) (v) << (base ## _ ## reg ## _ ## field ## _Pos)) & \
818  (base ## _ ## reg ## _ ## field ## _Msk)))
819 
823 #define BITS32(base, reg, field, v) \
824  ((uint32_t) (((uint32_t) (v) << (base ## _ ## reg ## _ ## field ## _Pos)) & \
825  (base ## _ ## reg ## _ ## field ## _Msk)))
826 
830 #define GETBITS16(base, reg, v, field) \
831  ((uint16_t) (((uint16_t) (v)) & (base ## _ ## reg ## _ ## field ## _Msk)) >> \
832  (base ## _ ## reg ## _ ## field ## _Pos))
833 
837 #define GETBITS32(base, reg, v, field) \
838  ((uint32_t) (((uint32_t) (v)) & (base ## _ ## reg ## _ ## field ## _Msk)) >> \
839  (base ## _ ## reg ## _ ## field ## _Pos))
840 
845 #define ENABLE_DEBUGGER \
846  do { \
847  REG_SET_BIT(CRG_TOP, SYS_CTRL_REG, DEBUGGER_ENABLE); \
848  } while (0)
849 
854 #define ENABLE_CMAC_DEBUGGER \
855  do { \
856  CRG_TOP->SYS_CTRL_REG |= (1 << (6UL)); \
857  } while (0)
858 
863 #define DISABLE_DEBUGGER \
864  do { \
865  REG_CLR_BIT(CRG_TOP, SYS_CTRL_REG, DEBUGGER_ENABLE); \
866  } while (0)
867 
872 #define DISABLE_CMAC_DEBUGGER \
873  do { \
874  CRG_TOP->SYS_CTRL_REG &= ~(0x40UL); \
875  } while (0)
876 
881 #define SWRESET \
882  do { \
883  REG_SET_BIT(CRG_TOP, SYS_CTRL_REG, SW_RESET); \
884  } while (0)
885 
886 #define BIT0 0x01
887 #define BIT1 0x02
888 #define BIT2 0x04
889 #define BIT3 0x08
890 #define BIT4 0x10
891 #define BIT5 0x20
892 #define BIT6 0x40
893 #define BIT7 0x80
894 
895 #define BIT8 0x0100
896 #define BIT9 0x0200
897 #define BIT10 0x0400
898 #define BIT11 0x0800
899 #define BIT12 0x1000
900 #define BIT13 0x2000
901 #define BIT14 0x4000
902 #define BIT15 0x8000
903 
904 #define BIT16 0x00010000
905 #define BIT17 0x00020000
906 #define BIT18 0x00040000
907 #define BIT19 0x00080000
908 #define BIT20 0x00100000
909 #define BIT21 0x00200000
910 #define BIT22 0x00400000
911 #define BIT23 0x00800000
912 
913 #define BIT24 0x01000000
914 #define BIT25 0x02000000
915 #define BIT26 0x04000000
916 #define BIT27 0x08000000
917 #define BIT28 0x10000000
918 #define BIT29 0x20000000
919 #define BIT30 0x40000000
920 #define BIT31 0x80000000
921 
922 typedef unsigned char uint8; // 8 bits
923 typedef char int8; // 8 bits
924 typedef unsigned short uint16; // 16 bits
925 typedef short int16; // 16 bits
926 typedef unsigned long uint32; // 32 bits
927 typedef long int32; // 32 bits
928 typedef unsigned long long uint64; // 64 bits
929 typedef long long int64; // 64 bits
930 
931 /* See also "Data Types" on pag. 21 of the (Doulos) Cortex-M0 / SoC 1.0 training documentation. */
932 typedef unsigned char BYTE; // 8 bits = Byte
933 typedef unsigned short HWORD; // 16 bits = Halfword
934 typedef unsigned long WORD; // 32 bits = Word
935 typedef long long DWORD; // 64 bits = Doubleword
936 
942 #define ARRAY_LENGTH(array) (sizeof((array))/sizeof((array)[0]))
943 
950 #define NSEC_TO_CLK_CYCLES(nsec, clk_freq_hz) ((((nsec) * ((clk_freq_hz) / 10000)) + 99999) / 100000)
951 
952 
953 #ifdef __cplusplus
954 }
955 #endif
956 
957 #endif /* __SDK_DEFS_H__ */
958 
system_DA1459x.h
CMSIS Device System Header File for DA1459x Device.
hw_sys_assert_trigger_gpio
__ALWAYS_RETAINED_CODE void hw_sys_assert_trigger_gpio(void)
Trigger a GPIO when ASSERT_WARNING() or ASSERT_ERROR() hits.
assertion_functions_set_to_uninit
void assertion_functions_set_to_uninit(void)
Assert as warning macro.