123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- #ifndef _CMB_DEF_H_
- #define _CMB_DEF_H_
- #include <cmb_cfg.h>
- #include <stdint.h>
- #include <stdlib.h>
- #define CMB_SW_VERSION "1.4.1"
- #define CMB_CPU_ARM_CORTEX_M0 0
- #define CMB_CPU_ARM_CORTEX_M3 1
- #define CMB_CPU_ARM_CORTEX_M4 2
- #define CMB_CPU_ARM_CORTEX_M7 3
- #define CMB_CPU_ARM_CORTEX_M33 4
- #define CMB_OS_PLATFORM_RTT 0
- #define CMB_OS_PLATFORM_UCOSII 1
- #define CMB_OS_PLATFORM_UCOSIII 2
- #define CMB_OS_PLATFORM_FREERTOS 3
- #define CMB_OS_PLATFORM_RTX5 4
- #define CMB_PRINT_LANGUAGE_ENGLISH 0
- #define CMB_PRINT_LANGUAGE_CHINESE 1
- #define CMB_PRINT_LANGUAGE_CHINESE_UTF8 2
- #ifndef CMB_NAME_MAX
- #define CMB_NAME_MAX 32
- #endif
- #ifndef CMB_PRINT_LANGUAGE
- #define CMB_PRINT_LANGUAGE CMB_PRINT_LANGUAGE_ENGLISH
- #endif
- #if defined(__ARMCC_VERSION)
-
- #ifndef CMB_CSTACK_BLOCK_NAME
- #define CMB_CSTACK_BLOCK_NAME STACK
- #endif
-
- #ifndef CMB_CODE_SECTION_NAME
- #define CMB_CODE_SECTION_NAME ER_IROM1
- #endif
- #elif defined(__ICCARM__)
-
- #ifndef CMB_CSTACK_BLOCK_NAME
- #define CMB_CSTACK_BLOCK_NAME "CSTACK"
- #endif
-
- #ifndef CMB_CODE_SECTION_NAME
- #define CMB_CODE_SECTION_NAME ".text"
- #endif
- #elif defined(__GNUC__)
-
- #ifndef CMB_CSTACK_BLOCK_START
- #define CMB_CSTACK_BLOCK_START __Stack_start_c0
- #endif
-
- #ifndef CMB_CSTACK_BLOCK_END
- #define CMB_CSTACK_BLOCK_END __Stack_end_c0
- #endif
-
- #ifndef CMB_CODE_SECTION_START
- #define CMB_CODE_SECTION_START acfls_code_rom_start
- #endif
-
- #ifndef CMB_CODE_SECTION_END
- #define CMB_CODE_SECTION_END acfls_code_rom_end
- #endif
- #else
- #error "not supported compiler"
- #endif
- #ifndef CMB_CALL_STACK_MAX_DEPTH
- #define CMB_CALL_STACK_MAX_DEPTH 16
- #endif
- #ifndef CMB_SYSHND_CTRL
- #define CMB_SYSHND_CTRL (*(volatile unsigned int*) (0xE000ED24u))
- #endif
- #ifndef CMB_NVIC_MFSR
- #define CMB_NVIC_MFSR (*(volatile unsigned char*) (0xE000ED28u))
- #endif
- #ifndef CMB_NVIC_BFSR
- #define CMB_NVIC_BFSR (*(volatile unsigned char*) (0xE000ED29u))
- #endif
- #ifndef CMB_NVIC_UFSR
- #define CMB_NVIC_UFSR (*(volatile unsigned short*)(0xE000ED2Au))
- #endif
- #ifndef CMB_NVIC_HFSR
- #define CMB_NVIC_HFSR (*(volatile unsigned int*) (0xE000ED2Cu))
- #endif
- #ifndef CMB_NVIC_DFSR
- #define CMB_NVIC_DFSR (*(volatile unsigned short*)(0xE000ED30u))
- #endif
- #ifndef CMB_NVIC_MMAR
- #define CMB_NVIC_MMAR (*(volatile unsigned int*) (0xE000ED34u))
- #endif
- #ifndef CMB_NVIC_BFAR
- #define CMB_NVIC_BFAR (*(volatile unsigned int*) (0xE000ED38u))
- #endif
- #ifndef CMB_NVIC_AFSR
- #define CMB_NVIC_AFSR (*(volatile unsigned short*)(0xE000ED3Cu))
- #endif
- struct cmb_hard_fault_regs{
- struct {
- unsigned int r0;
- unsigned int r1;
- unsigned int r2;
- unsigned int r3;
- unsigned int r12;
- unsigned int lr;
- unsigned int pc;
- union {
- unsigned int value;
- struct {
- #if (CMB_CPU_PLATFORM_TYPE == CMB_CPU_ARM_CORTEX_M33)
- unsigned int IPSR : 9;
- unsigned int EPSR : 18;
- unsigned int APSR : 5;
- #else
- unsigned int IPSR : 8;
- unsigned int EPSR : 19;
- unsigned int APSR : 5;
- #endif
- } bits;
- } psr;
- } saved;
- union {
- unsigned int value;
- struct {
- unsigned int MEMFAULTACT : 1;
- unsigned int BUSFAULTACT : 1;
- #if (CMB_CPU_PLATFORM_TYPE == CMB_CPU_ARM_CORTEX_M33)
- unsigned int HARDFAULTACT : 1;
- #else
- unsigned int UnusedBits1 : 1;
- #endif
- unsigned int USGFAULTACT : 1;
- #if (CMB_CPU_PLATFORM_TYPE == CMB_CPU_ARM_CORTEX_M33)
- unsigned int SECUREFAULTACT : 1;
- unsigned int NMIACT : 1;
- unsigned int UnusedBits2 : 1;
- #else
- unsigned int UnusedBits2 : 3;
- #endif
- unsigned int SVCALLACT : 1;
- unsigned int MONITORACT : 1;
- unsigned int UnusedBits3 : 1;
- unsigned int PENDSVACT : 1;
- unsigned int SYSTICKACT : 1;
- unsigned int USGFAULTPENDED : 1;
- unsigned int MEMFAULTPENDED : 1;
- unsigned int BUSFAULTPENDED : 1;
- unsigned int SVCALLPENDED : 1;
- unsigned int MEMFAULTENA : 1;
- unsigned int BUSFAULTENA : 1;
- unsigned int USGFAULTENA : 1;
- #if (CMB_CPU_PLATFORM_TYPE == CMB_CPU_ARM_CORTEX_M33)
- unsigned int SECUREFAULTENA : 1;
- unsigned int SECUREFAULTPENDED : 1;
- unsigned int HARDFAULTPENDED : 1;
- #else
-
- #endif
- } bits;
- } syshndctrl;
- union {
- unsigned char value;
- struct {
- unsigned char IACCVIOL : 1;
- unsigned char DACCVIOL : 1;
- unsigned char UnusedBits : 1;
- unsigned char MUNSTKERR : 1;
- unsigned char MSTKERR : 1;
- unsigned char MLSPERR : 1;
- unsigned char UnusedBits2 : 1;
- unsigned char MMARVALID : 1;
- } bits;
- } mfsr;
- unsigned int mmar;
- union {
- unsigned char value;
- struct {
- unsigned char IBUSERR : 1;
- unsigned char PRECISERR : 1;
- unsigned char IMPREISERR : 1;
- unsigned char UNSTKERR : 1;
- unsigned char STKERR : 1;
- unsigned char LSPERR : 1;
- unsigned char UnusedBits : 1;
- unsigned char BFARVALID : 1;
- } bits;
- } bfsr;
- unsigned int bfar;
- union {
- unsigned short value;
- struct {
- unsigned short UNDEFINSTR : 1;
- unsigned short INVSTATE : 1;
- unsigned short INVPC : 1;
- unsigned short NOCP : 1;
- #if (CMB_CPU_PLATFORM_TYPE == CMB_CPU_ARM_CORTEX_M33)
- unsigned short STKOF : 1;
- unsigned short UnusedBits : 3;
- #else
- unsigned short UnusedBits : 4;
- #endif
- unsigned short UNALIGNED : 1;
- unsigned short DIVBYZERO0 : 1;
- } bits;
- } ufsr;
- union {
- unsigned int value;
- struct {
- unsigned int UnusedBits : 1;
- unsigned int VECTBL : 1;
- unsigned int UnusedBits2 : 28;
- unsigned int FORCED : 1;
- unsigned int DEBUGEVT : 1;
- } bits;
- } hfsr;
- union {
- unsigned int value;
- struct {
- unsigned int HALTED : 1;
- unsigned int BKPT : 1;
- unsigned int DWTTRAP : 1;
- unsigned int VCATCH : 1;
- unsigned int EXTERNAL : 1;
- } bits;
- } dfsr;
- unsigned int afsr;
- };
- #define CMB_ASSERT(EXPR) \
- if (!(EXPR)) \
- { \
- cmb_println("(%s) has assert failed at %s.", #EXPR, __FUNCTION__); \
- while (1); \
- }
- #if defined(__ARMCC_VERSION)
- #define CMB_ELF_FILE_EXTENSION_NAME ".axf"
- #elif defined(__ICCARM__)
- #define CMB_ELF_FILE_EXTENSION_NAME ".out"
- #elif defined(__GNUC__)
- #define CMB_ELF_FILE_EXTENSION_NAME ".elf"
- #else
- #error "not supported compiler"
- #endif
- #ifndef cmb_println
- #error "cmb_println isn't defined in 'cmb_cfg.h'"
- #endif
- #ifndef CMB_CPU_PLATFORM_TYPE
- #error "CMB_CPU_PLATFORM_TYPE isn't defined in 'cmb_cfg.h'"
- #endif
- #if (defined(CMB_USING_BARE_METAL_PLATFORM) && defined(CMB_USING_OS_PLATFORM))
- #error "CMB_USING_BARE_METAL_PLATFORM and CMB_USING_OS_PLATFORM only one of them can be used"
- #elif defined(CMB_USING_OS_PLATFORM)
- #if !defined(CMB_OS_PLATFORM_TYPE)
- #error "CMB_OS_PLATFORM_TYPE isn't defined in 'cmb_cfg.h'"
- #endif
- #if (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTT)
- #include <rtthread.h>
- #elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_UCOSII)
- #include <ucos_ii.h>
- #elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_UCOSIII)
- #include <os.h>
- #elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_FREERTOS)
- #include <FreeRTOS.h>
- extern uint32_t *vTaskStackAddr(void);
- extern uint32_t vTaskStackSize(void);
- extern char * vTaskName(void);
- #elif (CMB_OS_PLATFORM_TYPE == CMB_OS_PLATFORM_RTX5)
- #include "rtx_os.h"
- #else
- #error "not supported OS type"
- #endif
- #endif
- #if defined(__CC_ARM)
- static __inline __asm uint32_t cmb_get_msp(void) {
- mrs r0, msp
- bx lr
- }
- static __inline __asm uint32_t cmb_get_psp(void) {
- mrs r0, psp
- bx lr
- }
- static __inline __asm uint32_t cmb_get_sp(void) {
- mov r0, sp
- bx lr
- }
- #elif defined(__clang__)
- __attribute__( (always_inline) ) static __inline uint32_t cmb_get_msp(void) {
- uint32_t result;
- __asm volatile ("mrs %0, msp" : "=r" (result) );
- return (result);
- }
- __attribute__( (always_inline) ) static __inline uint32_t cmb_get_psp(void) {
- uint32_t result;
- __asm volatile ("mrs %0, psp" : "=r" (result) );
- return (result);
- }
- __attribute__( (always_inline) ) static __inline uint32_t cmb_get_sp(void) {
- uint32_t result;
- __asm volatile ("mov %0, sp" : "=r" (result) );
- return (result);
- }
- #elif defined(__ICCARM__)
-
- #pragma diag_suppress=Pe940
- static uint32_t cmb_get_msp(void)
- {
- __asm("mrs r0, msp");
- __asm("bx lr");
- }
- static uint32_t cmb_get_psp(void)
- {
- __asm("mrs r0, psp");
- __asm("bx lr");
- }
- static uint32_t cmb_get_sp(void)
- {
- __asm("mov r0, sp");
- __asm("bx lr");
- }
- #pragma diag_default=Pe940
- #elif defined(__GNUC__)
- __attribute__( ( always_inline ) ) static inline uint32_t cmb_get_msp(void) {
- register uint32_t result;
- __asm volatile ("MRS %0, msp\n" : "=r" (result) );
- return(result);
- }
- __attribute__( ( always_inline ) ) static inline uint32_t cmb_get_psp(void) {
- register uint32_t result;
- __asm volatile ("MRS %0, psp\n" : "=r" (result) );
- return(result);
- }
- __attribute__( ( always_inline ) ) static inline uint32_t cmb_get_sp(void) {
- register uint32_t result;
- __asm volatile ("MOV %0, sp\n" : "=r" (result) );
- return(result);
- }
- #else
- #error "not supported compiler"
- #endif
- #endif
|