17 #include "in_compile.h" 18 #include "./hal/hal_clk.h" 19 #define ENV_MAGIC_WORD 0xB563A832 20 #define ENV_DATA_ADDR 0x7f000 37 GLB_IRQ_PS_TRANS_DONE,
38 GLB_IRQ_PD_DOO_SLEEP_BLOCK,
41 GLB_IRQ_AON_SQ_WAVE_START,
42 GLB_IRQ_AON_SQ_WAVE_END,
43 GLB_IRQ_CM4_PC_MATCH_HIT,
44 GLB_IRQ_CM4_DATA_ADDR_MATCH_HIT,
45 GLB_IRQ_CM4_SYS_ADDR_MATCH_HIT,
50 NMI_IRQ_PD1_WDT_TIME_OUT,
51 NMI_IRQ_PD0_WDT_TIME_OUT,
52 NMI_IRQ_SEL_0_GPIO_RISE_EDGE,
53 NMI_IRQ_SEL_0_GPIO_FALL_EDGE,
54 NMI_IRQ_SEL_1_GPIO_RISE_EDGE,
55 NMI_IRQ_SEL_1_GPIO_FALL_EDGE,
62 OSC_XO_IRQ_OSC_EN = 0,
63 OSC_XO_IRQ_OSC_EN_INV = 1,
64 OSC_XO_IRQ_XO_READY = 2,
66 OSC_XO_IRQ_XO_STG_1 = 4,
67 OSC_XO_IRQ_XO_DET_0 = 5,
68 OSC_XO_IRQ_XO_ERR_DET_0 = 6,
69 OSC_XO_IRQ_XO_UNDET_0 = 7,
70 OSC_XO_IRQ_XO_DET_1 = 8,
71 OSC_XO_IRQ_XO_ERR_DET_1 = 9,
72 OSC_XO_IRQ_XO_UNDET_1 = 10,
73 OSC_XO_IRQ_CPLL_RST_DONE = 11,
74 OSC_XO_IRQ_CPLL_LOCK = 12,
75 OSC_XO_IRQ_CPLL_UNLOCK = 13,
76 OSC_XO_IRQ_XO_GT_TGT = 14,
77 OSC_XO_IRQ_XO_GT_TGT_INV = 15,
78 OSC_XO_IRQ_BOD_RISE = 16,
79 OSC_XO_IRQ_BOD2_RISE = 17,
83 enum data_ram_access_prio {
84 DATA_RAM_ACCESS_PRIO_1=0,
85 DATA_RAM_ACCESS_PRIO_2=1,
86 DATA_RAM_ACCESS_PRIO_3=2,
121 static INLINE uint32_t chip_get_id(
void)
123 return (RD_WORD(GLOBAL_REG_CHIP_ID) & (GLOBAL_REG_CHIP_ID_VERSION|GLOBAL_REG_CHIP_ID_SUBVERSION));
126 static INLINE
void disable_fpu(
int disable)
128 uint32_t reg = RD_WORD(AON_REG_CM4_CTRL);
131 reg |= AON_REG_CM4_CTRL_CTL_CM4_DISABLE_FPU;
133 reg &= ~AON_REG_CM4_CTRL_CTL_CM4_DISABLE_FPU;
135 WR_WORD(AON_REG_CM4_CTRL, reg);
138 static INLINE
void disable_mpu(
int disable)
140 uint32_t reg = RD_WORD(AON_REG_CM4_CTRL);
143 reg |= AON_REG_CM4_CTRL_CTL_CM4_DISABLE_MPU;
145 reg &= ~AON_REG_CM4_CTRL_CTL_CM4_DISABLE_MPU;
147 WR_WORD(AON_REG_CM4_CTRL, reg);
150 static INLINE
void cache_mem_as_dram(
int en)
152 uint32_t reg = RD_WORD(AON_REG_CM4_CTRL);
155 reg |= AON_REG_CM4_CTRL_CTL_CACHE_MEM_AS_DC_RAM;
157 reg &= ~AON_REG_CM4_CTRL_CTL_CACHE_MEM_AS_DC_RAM;
159 WR_WORD(AON_REG_CM4_CTRL, reg);
160 RD_WORD(AON_REG_CM4_CTRL);
163 static INLINE
void share_mem_as_dram(
int en,
int shm_as_dram)
165 uint32_t reg = RD_WORD(AON_REG_CM4_CTRL);
168 if ((shm_as_dram == SHM_16K_AS_DRAM)) {
171 if ((shm_as_dram == SHM_32K_AS_DRAM)) {
175 if ((shm_as_dram == SHM_16K_AS_DRAM)) {
178 if ((shm_as_dram == SHM_32K_AS_DRAM)) {
183 WR_WORD(AON_REG_CM4_CTRL, reg);
184 RD_WORD(AON_REG_CM4_CTRL);
187 static INLINE
void enable_all_as_dram(
void)
189 uint32_t reg = RD_WORD(AON_REG_CM4_CTRL);
193 WR_WORD(AON_REG_CM4_CTRL, reg);
194 RD_WORD(AON_REG_CM4_CTRL);
197 static FORCEINLINE uint32_t fw_get_version(
void)
200 return RD_WORD(0x5FFF8);
203 static FORCEINLINE uint32_t chip_sleep(
void)
205 return (WR_WORD(GLOBAL_REG_SLEEP_CTRL, 1));
208 static FORCEINLINE
void aon_reset_pd0(
void)
210 WR_WORD(AON_REG_AON_GLOBAL_RESET_CTRL, 0);
213 static __inline
void aon_reset_pd1(
void)
215 uint32_t reg = RD_WORD(AON_REG_AON_RESET_CTRL);
217 if (reg & AON_REG_AON_RESET_CTRL_CTL_PD1_MANUAL_RST_N) {
219 reg &= ~AON_REG_AON_RESET_CTRL_CTL_PD1_MANUAL_RST_N;
220 WR_WORD(AON_REG_AON_RESET_CTRL, reg);
223 reg |= AON_REG_AON_RESET_CTRL_CTL_PD1_MANUAL_RST_N;
224 WR_WORD(AON_REG_AON_RESET_CTRL, reg);
228 reg &= ~AON_REG_AON_RESET_CTRL_CTL_PD1_MANUAL_RST_N;
229 WR_WORD(AON_REG_AON_RESET_CTRL, reg);
233 static FORCEINLINE
void aon_set_pc(uint32_t pc)
235 WR_WORD(AON_REG_CPU_PROGRAM_COUNTER_COLD_BOOT, pc);
238 static FORCEINLINE uint32_t aon_get_pc(
void)
240 return RD_WORD(AON_REG_CPU_PROGRAM_COUNTER_COLD_BOOT);
243 static FORCEINLINE
void aon_set_sp(uint32_t sp)
245 WR_WORD(AON_REG_CPU_STACK_POINTER, sp);
248 static FORCEINLINE uint32_t aon_get_sp(
void)
250 return RD_WORD(AON_REG_CPU_STACK_POINTER);
253 static INLINE
void data_ram_access_prio(
int cpu_i_prio,
int cpu_d_prio,
int dma_prio)
255 uint32_t reg = RD_WORD(GLOBAL_REG_AHB_CTRL_1);
257 reg &= ~GLOBAL_REG_AHB_CTRL_1_CTL_ICM_D2_DATA_CODE_RAM_PRIORITY ;
258 reg |= ((cpu_i_prio & 0x3) << 0) | ((cpu_d_prio & 0x3) << 2) | ((dma_prio & 0x3) << 4);
259 WR_WORD(GLOBAL_REG_AHB_CTRL_1, reg);
262 static FORCEINLINE uint32_t glb_int_status(
void)
264 return (RD_WORD(GLOBAL_REG_INTR_STATUS));
267 static FORCEINLINE uint32_t glb_int_mask_status(
void)
269 return (RD_WORD(GLOBAL_REG_INTR_MASK_STATUS));
272 static FORCEINLINE
void glb_int_clear_all(
void)
274 WR_WORD(GLOBAL_REG_INTR_CLEAR, GLOBAL_REG_INTR_CLEAR_IRQ);
277 static FORCEINLINE
void glb_int_clear(uint32_t status)
279 WR_WORD(GLOBAL_REG_INTR_CLEAR, status);
282 static FORCEINLINE
void glb_int_mask_all(
void)
284 WR_WORD(GLOBAL_REG_INTR_MASK_SET, GLOBAL_REG_INTR_MASK_SET_IRQ);
287 static FORCEINLINE
void glb_int_mask(uint32_t mask)
289 WR_WORD(GLOBAL_REG_INTR_MASK_SET, mask);
292 static FORCEINLINE
void glb_int_unmask(uint32_t mask)
294 WR_WORD(GLOBAL_REG_INTR_MASK_CLEAR, mask);
297 static FORCEINLINE uint32_t swi_status(
void)
299 return (RD_WORD(GLOBAL_REG_INTR_SW_STATUS));
302 static FORCEINLINE uint32_t swi_mask_status(
void)
304 return (RD_WORD(GLOBAL_REG_INTR_SW_MASK_STATUS));
307 static FORCEINLINE
void swi_clear_all(
void)
309 WR_WORD(GLOBAL_REG_INTR_SW_CLEAR, GLOBAL_REG_INTR_SW_CLEAR_IRQ);
312 static FORCEINLINE
void swi_clear(uint32_t status)
314 WR_WORD(GLOBAL_REG_INTR_SW_CLEAR, status);
317 static FORCEINLINE
void swi_mask_all(
void)
319 WR_WORD(GLOBAL_REG_INTR_SW_MASK_SET, GLOBAL_REG_INTR_SW_MASK_SET_IRQ);
322 static FORCEINLINE
void swi_mask(uint32_t mask)
324 WR_WORD(GLOBAL_REG_INTR_SW_MASK_SET, mask);
327 static FORCEINLINE
void swi_unmask(uint32_t mask)
329 WR_WORD(GLOBAL_REG_INTR_SW_MASK_CLEAR, mask);
332 static FORCEINLINE
void swi_set(
int bit)
334 WR_WORD(GLOBAL_REG_INTR_SW_SET, (1 << bit));
337 static INLINE
void aon_bod_en(
int en)
339 uint32_t reg = RD_WORD(AON_REG_PMU_DOOPD_REG_1TO4);
345 WR_WORD(AON_REG_PMU_DOOPD_REG_1TO4, reg);
348 static INLINE
void aon_bod_thrd(
int val)
350 uint32_t reg = RD_WORD(AON_REG_PMU_DOOPD_REG_1TO4);
359 reg |= (val & 0x3) << 29;
361 WR_WORD(AON_REG_PMU_DOOPD_REG_1TO4, reg);
364 static INLINE
void arm_wic(
int en)
368 WR_WORD(GLOBAL_REG_CM4_WIC_EN_REQ, 1);
369 while (!(RD_WORD(GLOBAL_REG_CM4_WIC_EN_ACK) & GLOBAL_REG_CM4_WIC_EN_ACK_STS_CM4_WIC_EN_ACK));
371 WR_WORD(GLOBAL_REG_CM4_WIC_EN_REQ, 0);
375 static FORCEINLINE uint32_t osc_xo_int_status(
void)
377 return (RD_WORD(GLOBAL2_REG_OSC_XO_INTR_STATUS));
380 static FORCEINLINE uint32_t osc_xo_int_mask_status(
void)
382 return (RD_WORD(GLOBAL2_REG_OSC_XO_INTR_MASK_STATUS));
385 static FORCEINLINE
void osc_xo_int_clear_all(
void)
387 WR_WORD(GLOBAL2_REG_OSC_XO_INTR_CLEAR, GLOBAL2_REG_OSC_XO_INTR_CLEAR_IRQ);
390 static FORCEINLINE
void osc_xo_int_clear(uint32_t status)
392 WR_WORD(GLOBAL2_REG_OSC_XO_INTR_CLEAR, status);
395 static FORCEINLINE
void osc_xo_int_mask_all(
void)
397 WR_WORD(GLOBAL2_REG_OSC_XO_INTR_MASK_SET, GLOBAL2_REG_OSC_XO_INTR_MASK_SET_IRQ);
400 static FORCEINLINE
void osc_xo_int_mask(uint32_t mask)
402 WR_WORD(GLOBAL2_REG_OSC_XO_INTR_MASK_SET, mask);
405 static FORCEINLINE
void osc_xo_int_unmask(uint32_t unmask)
407 WR_WORD(GLOBAL2_REG_OSC_XO_INTR_MASK_CLEAR, unmask);
410 static INLINE
void xo_stage_delay(uint32_t stage0_delay, uint32_t stage1_delay)
413 reg = RD_WORD(AON_REG_XO_EN_STAGE_CTRL);
414 reg &= ~(AON_REG_XO_EN_STAGE_CTRL_CTL_XO_STAGE0_DURATION | AON_REG_XO_EN_STAGE_CTRL_CTL_XO_STAGE1_DURATION);
415 reg |= (stage0_delay<<AON_REG_XO_EN_STAGE_CTRL_CTL_XO_STAGE0_DURATION_SHIFT);
416 reg |= (stage1_delay<<AON_REG_XO_EN_STAGE_CTRL_CTL_XO_STAGE1_DURATION_SHIFT);
417 WR_WORD(AON_REG_XO_EN_STAGE_CTRL, reg);
420 static FORCEINLINE uint32_t nmi_int_status(
void)
422 return (RD_WORD(GLOBAL_REG_NMI_STATUS));
425 static FORCEINLINE uint32_t nmi_int_mask_status(
void)
427 return (RD_WORD(GLOBAL_REG_NMI_MASK_STATUS));
430 static FORCEINLINE
void nmi_int_clear_all(
void)
432 WR_WORD(GLOBAL_REG_NMI_CLEAR, GLOBAL_REG_NMI_CLEAR_NMI);
435 static FORCEINLINE
void nmi_int_clear(
int id)
437 WR_WORD(GLOBAL_REG_NMI_CLEAR, (1 <<
id));
440 static FORCEINLINE
void nmi_int_mask_all(
void)
442 WR_WORD(GLOBAL_REG_NMI_MASK_SET, GLOBAL_REG_NMI_MASK_SET_NMI);
445 static FORCEINLINE
void nmi_int_mask(uint32_t mask)
447 WR_WORD(GLOBAL_REG_NMI_MASK_SET, mask);
450 static FORCEINLINE
void nmi_int_unmask(uint32_t unmask)
452 WR_WORD(GLOBAL_REG_NMI_MASK_CLEAR, unmask);
455 static INLINE
void snapshot_ctrl(uint32_t type,
int en)
457 uint32_t reg = RD_WORD(GLOBAL2_REG_SNAPSHOT_CTRL);
463 WR_WORD(GLOBAL2_REG_SNAPSHOT_CTRL, reg);
466 static FORCEINLINE uint32_t snapshot_fr_ipmac_cnt(
void)
468 return RD_WORD(GLOBAL2_REG_SNAPSHOT_VAL_IPMAC_FR);
535 void hal_global_pd0_reset(
void);
563 int hal_bod_enable(
int bod_thrd_mv,
void *arg,
void (*callback)(
void *arg));
819 #endif // HAL_GLOBAL_H void hal_osc_xo_isr_register(int irq_id, int prio, void *arg, void(*callback)(void *))
Register Osc and XO shared interupts.
void hal_nmi_deregister(int irq_id)
Deregister a NMI interrupt.
void hal_global_suspend(void)
Globally save system (such as system tick...) registers before deep sleep.
int RTC_timer_start(void)
Start the RTC timer.
void hal_swi_set(int index)
Trigger a Software interrupt.
void hal_nmi_register(int irq_id, void *arg, void(*callback)(void *))
Register a NMI interrupt.
void RAM_PM delay_us(uint32_t us)
Delay in tight loop.
int hal_bod_enable(int bod_thrd_mv, void *arg, void(*callback)(void *arg))
Enable BOD , set a bod_thrd_mv will return a closest value. Detail please see: <<IN602F0 reference ma...
int hal_swi_register(void *arg, void(*callback)(void *))
Register a Software interrupt index. There are max 4 SWI.
void hal_global_cpu_reset(void)
Reset the CPU (cold boot)
void * hal_sys_uart_hdl(void)
Enable/disable external PA.
void RTC_timer_stop(void)
Stop the RTC timer.
void hal_global_post_init(void)
Globally initialize system (such as debug, RTC...) after OS starting.
uint32_t RTC_timer_diff_low(uint32_t s_tick, uint32_t e_tick)
Calculate tick difference convert to time.
int hal_swi_int_prio(int prio)
Set Software interrupt priority. There are max 4 SWI.
uint64_t RTC_timer_diff(uint64_t s_tick, uint64_t e_tick)
Calculate tick difference convert to time.
void hal_swi_deregister(int index)
Deregister a Software interrupt index.
void hal_osc_xo_isr_deregister(int irq_id)
Deregister an Osc and XO shared interupt.
void hal_global_sys_reset(void)
Reset the system (cold boot)
void hal_global_pre_init(void)
Globally initialize system (such as clock...) before OS starting.
void hal_glb_isr_register(int irq_id, int prio, void *arg, void(*callback)(void *))
Globally manage shared interupts.
uint64_t RTC_timer_get_time(void)
Get the RTC timer in micro second.
void hal_glb_isr_deregister(int irq_id)
Deregister global shared interupts.
void hal_global_resume(void)
Globally resume system (such as system tick...) registers after wake up.
void hal_bod_disable(void)
Disable BOD.
void hal_ble_isr_register(void *arg, void(*callback)(void *))
Register BLE interupt.
void hal_ble_isr_deregister(void)
Deregister BLE interupt.
uint32_t RTC_timer_get_tick_low(void)
Get the RTC timer ticks low part.
void hal_global_close_sys_uart(void)
Close debug uart.
uint64_t RTC_timer_get_tick(void)
Get the RTC timer ticks (64 bits)