1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 #ifndef __HAL_BOOTMODE_H__
5 #define __HAL_BOOTMODE_H__
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 #include "stdint.h"
12 
13 #define HAL_HW_BOOTMODE_MASK                    (0xF << 0)
14 #define HAL_SW_BOOTMODE_MASK                    (0x0FFFFFFF << 4)
15 
16 // SW_BOOTMODE_START                            (1 << 4)
17 #define HAL_SW_BOOTMODE_READ_ENABLED            (1 << 4)
18 #define HAL_SW_BOOTMODE_WRITE_ENABLED           (1 << 5)
19 #define HAL_SW_BOOTMODE_JTAG_ENABLED            (1 << 6)
20 #define HAL_SW_BOOTMODE_FORCE_USB_DLD           (1 << 7)
21 #define HAL_SW_BOOTMODE_FORCE_UART_DLD          (1 << 8)
22 #define HAL_SW_BOOTMODE_DLD_TRANS_UART          (1 << 9)
23 #define HAL_SW_BOOTMODE_SKIP_FLASH_BOOT         (1 << 10)
24 #define HAL_SW_BOOTMODE_CHIP_TEST               (1 << 11)
25 #define HAL_SW_BOOTMODE_FACTORY                 (1 << 12)
26 #define HAL_SW_BOOTMODE_CALIB                   (1 << 13)
27 #define HAL_SW_BOOTMODE_ROM_RESERVED_14         (1 << 14)
28 #define HAL_SW_BOOTMODE_FLASH_BOOT              (1 << 15)
29 #define HAL_SW_BOOTMODE_REBOOT                  (1 << 16)
30 #define HAL_SW_BOOTMODE_ROM_RESERVED_17         (1 << 17)
31 #define HAL_SW_BOOTMODE_FORCE_USB_PLUG_IN       (1 << 18)
32 #define HAL_SW_BOOTMODE_POWER_DOWN_WAKEUP       (1 << 19)
33 
34 // APP_BOOTMODE_START                           (1 << 20)
35 // Add new application bootmodes here (from highest bit to lowest bit)
36 
37 #define HAL_SW_BOOTMODE_TEST_MASK               (0x1F << 20)
38 #define HAL_SW_BOOTMODE_TEST_MODE               (1 << 20)
39 #define HAL_SW_BOOTMODE_TEST_SIGNALINGMODE      (1 << 21)
40 #define HAL_SW_BOOTMODE_TEST_NOSIGNALINGMODE    (1 << 22)
41 #define HAL_SW_BOOTMODE_TEST_SIGNALINGMODE_WIFI (1 << 23)
42 #define HAL_SW_BOOTMODE_TEST_NOSIGNALINGMODE_WIFI (1 << 24)
43 
44 #define HAL_SW_BOOTMODE_ENTER_HIDE_BOOT         (1 << 25)
45 
46 #define HAL_SW_BOOTMODE_RESERVED_BIT24          (1 << 26)
47 #define HAL_SW_BOOTMODE_REBOOT_FROM_CRASH       (1 << 27)
48 
49 #ifdef __USB_COMM__
50 #define HAL_SW_BOOTMODE_CDC_COMM                (1 << 28)
51 #endif
52 #ifdef ANC_APP
53 #define HAL_SW_BOOTMODE_REBOOT_BT_ON            (1 << 29)
54 #define HAL_SW_BOOTMODE_REBOOT_ANC_ON           (1 << 30)
55 #endif
56 
57 #define HAL_SW_BOOTMODE_WARM_BOOT               (1 << 29)
58 
59 #ifdef USER_REBOOT_PLAY_MUSIC_AUTO
60 #define HAL_SW_BOOTMODE_LOCAL_PLAYER            (1 << 31)
61 #endif
62 
63 // APP_BOOTMODE_END                             (1 << 31)
64 // SW_BOOTMODE_END                              (1 << 31)
65 
66 union HAL_HW_BOOTMODE_T {
67     struct {
68         uint8_t watchdog    : 1;
69         uint8_t global      : 1;
70         uint8_t rtc         : 1;
71         uint8_t charger     : 1;
72     };
73     uint8_t reg;
74 };
75 
76 union HAL_HW_BOOTMODE_T hal_rom_hw_bootmode_get(void);
77 
78 union HAL_HW_BOOTMODE_T hal_hw_bootmode_get(void);
79 
80 void hal_hw_bootmode_init(void);
81 
82 void hal_hw_bootmode_clear(uint8_t clear_bits);
83 
84 uint32_t hal_sw_bootmode_get(void);
85 
86 void hal_sw_bootmode_set(uint32_t bm);
87 
88 void hal_sw_bootmode_clear(uint32_t bm);
89 
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif
95 
96