1 #ifndef __BL808_COMMON_H__ 2 #define __BL808_COMMON_H__ 3 4 #include "bl808.h" 5 #include "bflb_core.h" 6 7 #ifndef __set_MSP 8 #define __set_MSP(msp) __ASM volatile("add sp, x0, %0" ::"r"(msp)) 9 #endif 10 11 /** @addtogroup BL808_Peripheral_Driver 12 * @{ 13 */ 14 15 /** @addtogroup COMMON 16 * @{ 17 */ 18 19 /** 20 * @brief Memory access macro 21 */ 22 #define BL_RD_WORD(addr) (*((volatile uint32_t *)(uintptr_t)(addr))) 23 #define BL_WR_WORD(addr, val) ((*(volatile uint32_t *)(uintptr_t)(addr)) = (val)) 24 #define BL_RD_SHORT(addr) (*((volatile uint16_t *)(uintptr_t)(addr))) 25 #define BL_WR_SHORT(addr, val) ((*(volatile uint16_t *)(uintptr_t)(addr)) = (val)) 26 #define BL_RD_BYTE(addr) (*((volatile uint8_t *)(uintptr_t)(addr))) 27 #define BL_WR_BYTE(addr, val) ((*(volatile uint8_t *)(uintptr_t)(addr)) = (val)) 28 #define BL_RDWD_FRM_BYTEP(p) ((p[3] << 24) | (p[2] << 16) | (p[1] << 8) | (p[0])) 29 30 #define BL_WRWD_TO_BYTEP(p, val) \ 31 { \ 32 p[0] = val & 0xff; \ 33 p[1] = (val >> 8) & 0xff; \ 34 p[2] = (val >> 16) & 0xff; \ 35 p[3] = (val >> 24) & 0xff; \ 36 } 37 /** 38 * @brief Register access macro 39 */ 40 #define BL_RD_REG16(addr, regname) BL_RD_SHORT(addr + regname##_OFFSET) 41 #define BL_WR_REG16(addr, regname, val) BL_WR_SHORT(addr + regname##_OFFSET, val) 42 #define BL_RD_REG(addr, regname) BL_RD_WORD(addr + regname##_OFFSET) 43 #define BL_WR_REG(addr, regname, val) BL_WR_WORD(addr + regname##_OFFSET, val) 44 #define BL_SET_REG_BIT(val, bitname) ((val) | (1U << bitname##_POS)) 45 #define BL_CLR_REG_BIT(val, bitname) ((val)&bitname##_UMSK) 46 #define BL_GET_REG_BITS_VAL(val, bitname) (((val)&bitname##_MSK) >> bitname##_POS) 47 #define BL_SET_REG_BITS_VAL(val, bitname, bitval) (((val)&bitname##_UMSK) | ((uint32_t)(bitval) << bitname##_POS)) 48 #define BL_IS_REG_BIT_SET(val, bitname) (((val) & (1U << (bitname##_POS))) != 0) 49 #define BL_DRV_DUMMY \ 50 { \ 51 __ASM volatile("nop"); \ 52 __ASM volatile("nop"); \ 53 __ASM volatile("nop"); \ 54 __ASM volatile("nop"); \ 55 } 56 57 /** @defgroup COMMON_Public_Types 58 * @{ 59 */ 60 #ifdef BIT 61 #undef BIT 62 #define BIT(n) (1UL << (n)) 63 #else 64 #define BIT(n) (1UL << (n)) 65 #endif 66 67 /** 68 * @brief Null Type definition 69 */ 70 #ifndef NULL 71 #define NULL 0 72 #endif 73 74 /** 75 * @brief Error type definition 76 */ 77 typedef enum { 78 SUCCESS = 0, 79 ERROR = 1, 80 TIMEOUT = 2, 81 INVALID = 3, /* invalid arguments */ 82 NORESC = 4 /* no resource or resource temperary unavailable */ 83 } BL_Err_Type; 84 85 /** 86 * @brief Functional type definition 87 */ 88 typedef enum { 89 DISABLE = 0, 90 ENABLE = 1, 91 } BL_Fun_Type; 92 93 /** 94 * @brief Status type definition 95 */ 96 typedef enum { 97 RESET = 0, 98 SET = 1, 99 } BL_Sts_Type; 100 101 /** 102 * @brief Mask type definition 103 */ 104 typedef enum { 105 UNMASK = 0, 106 MASK = 1 107 } BL_Mask_Type; 108 109 /** 110 * @brief Logical status Type definition 111 */ 112 typedef enum { 113 LOGIC_LO = 0, 114 LOGIC_HI = !LOGIC_LO 115 } LogicalStatus; 116 117 /** 118 * @brief Active status Type definition 119 */ 120 typedef enum { 121 DEACTIVE = 0, 122 ACTIVE = !DEACTIVE 123 } ActiveStatus; 124 125 /** 126 * @brief Interrupt callback function type 127 */ 128 typedef void(intCallback_Type)(void); 129 typedef void (*pFunc)(void); 130 131 #ifdef DEBUG 132 void check_failed(uint8_t *file, uint32_t line); 133 #define CHECK_PARAM(expr) ((expr) ? (void)0 : check_failed((uint8_t *)__FILE__, __LINE__)) 134 #else 135 #define CHECK_PARAM(expr) ((void)0) 136 #endif /* DEBUG */ 137 138 /** @defgroup COMMON_Public_Types 139 * @{ 140 */ 141 142 /*@} end of group COMMON_Public_Types */ 143 144 /** @defgroup COMMON_Public_Constants 145 * @{ 146 */ 147 148 /** @defgroup DRIVER_INT_PERIPH 149 * @{ 150 */ 151 #define IS_INT_PERIPH(INT_PERIPH) ((INT_PERIPH) < IRQn_LAST) 152 153 /*@} end of group DRIVER_INT_PERIPH */ 154 155 /** @defgroup DRIVER_INT_MASK 156 * @{ 157 */ 158 #define IS_BL_MASK_TYPE(type) (((type) == MASK) || ((type) == UNMASK)) 159 160 #define ARCH_MemCpy arch_memcpy 161 #define ARCH_MemSet arch_memset 162 #define ARCH_MemCmp arch_memcmp 163 #define ARCH_MemCpy4 arch_memcpy4 164 #define arch_memcpy_fast arch_memcpy_fast 165 #define ARCH_MemSet4 arch_memset4 166 #define BFLB_Soft_CRC32 bflb_soft_crc32 167 #define CPU_Interrupt_Enable(irq) 168 #define CPU_Interrupt_Disable(irq) 169 #define Interrupt_Handler_Register(irq, callback) 170 /*@} end of group COMMON_Public_Constants */ 171 172 /** @defgroup DRIVER_Public_FunctionDeclaration 173 * @brief DRIVER functions declaration 174 * @{ 175 */ 176 177 void ASM_Delay_Us(uint32_t core, uint32_t cnt, uint32_t loopT); 178 void arch_delay_us(uint32_t cnt); 179 void arch_delay_ms(uint32_t cnt); 180 181 void *ARCH_MemCpy(void *dst, const void *src, uint32_t n); 182 uint32_t *ARCH_MemCpy4(uint32_t *dst, const uint32_t *src, uint32_t n); 183 void *arch_memcpy_fast(void *pdst, const void *psrc, uint32_t n); 184 void *ARCH_MemSet(void *s, uint8_t c, uint32_t n); 185 uint32_t *ARCH_MemSet4(uint32_t *dst, const uint32_t val, uint32_t n); 186 int ARCH_MemCmp(const void *s1, const void *s2, uint32_t n); 187 188 void C906_All_Int_Enable(void); 189 void C906_All_Int_Disable(void); 190 /*@} end of group DRIVER_COMMON */ 191 192 #endif /* __BL808_COMMON_H__ */ 193