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