1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 #ifndef __HAL_OVERLAY_H__
5 #define __HAL_OVERLAY_H__
6 
7 #ifdef __cplusplus
8 extern "C" {
9 #endif
10 
11 #define HAL_OVERLAY_TEXT0_LOC       __attribute__((section(".overlay_text0")))
12 #define HAL_OVERLAY_TEXT1_LOC       __attribute__((section(".overlay_text1")))
13 #define HAL_OVERLAY_TEXT2_LOC       __attribute__((section(".overlay_text2")))
14 #define HAL_OVERLAY_TEXT3_LOC       __attribute__((section(".overlay_text3")))
15 #define HAL_OVERLAY_TEXT4_LOC       __attribute__((section(".overlay_text4")))
16 #define HAL_OVERLAY_TEXT5_LOC       __attribute__((section(".overlay_text5")))
17 #define HAL_OVERLAY_TEXT6_LOC       __attribute__((section(".overlay_text6")))
18 #define HAL_OVERLAY_TEXT7_LOC       __attribute__((section(".overlay_text7")))
19 
20 #define HAL_OVERLAY_RODATA0_LOC     __attribute__((section(".overlay_rodata0")))
21 #define HAL_OVERLAY_RODATA1_LOC     __attribute__((section(".overlay_rodata1")))
22 #define HAL_OVERLAY_RODATA2_LOC     __attribute__((section(".overlay_rodata2")))
23 #define HAL_OVERLAY_RODATA3_LOC     __attribute__((section(".overlay_rodata3")))
24 #define HAL_OVERLAY_RODATA4_LOC     __attribute__((section(".overlay_rodata4")))
25 #define HAL_OVERLAY_RODATA5_LOC     __attribute__((section(".overlay_rodata5")))
26 #define HAL_OVERLAY_RODATA6_LOC     __attribute__((section(".overlay_rodata6")))
27 #define HAL_OVERLAY_RODATA7_LOC     __attribute__((section(".overlay_rodata7")))
28 
29 #define HAL_OVERLAY_DATA0_LOC       __attribute__((section(".overlay_data0")))
30 #define HAL_OVERLAY_DATA1_LOC       __attribute__((section(".overlay_data1")))
31 #define HAL_OVERLAY_DATA2_LOC       __attribute__((section(".overlay_data2")))
32 #define HAL_OVERLAY_DATA3_LOC       __attribute__((section(".overlay_data3")))
33 #define HAL_OVERLAY_DATA4_LOC       __attribute__((section(".overlay_data4")))
34 #define HAL_OVERLAY_DATA5_LOC       __attribute__((section(".overlay_data5")))
35 #define HAL_OVERLAY_DATA6_LOC       __attribute__((section(".overlay_data6")))
36 #define HAL_OVERLAY_DATA7_LOC       __attribute__((section(".overlay_data7")))
37 
38 #define  INVALID_OVERLAY_ADDR 0xffffffff
39 enum HAL_OVERLAY_ID_T {
40     HAL_OVERLAY_ID_0,
41     HAL_OVERLAY_ID_1,
42     HAL_OVERLAY_ID_2,
43     HAL_OVERLAY_ID_3,
44     HAL_OVERLAY_ID_4,
45     HAL_OVERLAY_ID_5,
46     HAL_OVERLAY_ID_6,
47     HAL_OVERLAY_ID_7,
48 
49     HAL_OVERLAY_ID_QTY,
50     HAL_OVERLAY_ID_IN_CFG,
51 };
52 
53 enum HAL_OVERLAY_RET_T {
54     HAL_OVERLAY_RET_OK,
55     HAL_OVERLAY_RET_BAD_ID,
56     HAL_OVERLAY_RET_IN_CFG,
57     HAL_OVERLAY_RET_IN_USE,
58 };
59 
60 #ifndef NO_OVERLAY
61 enum HAL_OVERLAY_RET_T hal_overlay_load(enum HAL_OVERLAY_ID_T id);
62 
63 enum HAL_OVERLAY_RET_T hal_overlay_unload(enum HAL_OVERLAY_ID_T id);
64 
65 /*
66  * get the overlay's text start address
67  */
68 uint32_t hal_overlay_get_text_address(void);
69 
70 /*
71  * get the whole size of the overlay text
72  */
73 uint32_t hal_overlay_get_text_all_size(void);
74 /*
75  * get the segment size of one overlay text
76  */
77 uint32_t hal_overlay_get_text_size(enum HAL_OVERLAY_ID_T id);
78 /*
79  * Use the free space of one segement, this function
80  * return the free address of space
81  */
82 uint32_t hal_overlay_get_text_free_addr(enum HAL_OVERLAY_ID_T id);
83 /*
84  * get the free size for one overlay text
85  */
86 uint32_t hal_overlay_get_text_free_size(enum HAL_OVERLAY_ID_T id);
87 /*
88  * acquire one overlay segment
89  */
90 void hal_overlay_acquire(enum HAL_OVERLAY_ID_T id);
91 /*
92  * release one overlay segment
93  */
94 void hal_overlay_release(enum HAL_OVERLAY_ID_T id);
95 /*
96  * check if any overlay segment is used
97  */
98 bool hal_overlay_is_used(void);
99 
100 #else
101 
hal_overlay_load(enum HAL_OVERLAY_ID_T id)102 static inline enum HAL_OVERLAY_RET_T hal_overlay_load(enum HAL_OVERLAY_ID_T id)
103 { return HAL_OVERLAY_RET_OK; }
104 
hal_overlay_unload(enum HAL_OVERLAY_ID_T id)105 static inline enum HAL_OVERLAY_RET_T hal_overlay_unload(enum HAL_OVERLAY_ID_T id)
106 { return HAL_OVERLAY_RET_OK; }
107 
hal_overlay_get_text_address(void)108 static inline uint32_t hal_overlay_get_text_address(void)
109 { return INVALID_OVERLAY_ADDR;}
110 
hal_overlay_get_text_all_size(void)111 static inline uint32_t hal_overlay_get_text_all_size(void)
112 { return 0;}
113 
hal_overlay_get_text_size(enum HAL_OVERLAY_ID_T id)114 static inline uint32_t hal_overlay_get_text_size(enum HAL_OVERLAY_ID_T id)
115 { return 0;}
116 
hal_overlay_get_text_free_addr(enum HAL_OVERLAY_ID_T id)117 static inline uint32_t hal_overlay_get_text_free_addr(enum HAL_OVERLAY_ID_T id)
118 { return INVALID_OVERLAY_ADDR;}
119 
hal_overlay_get_text_free_size(enum HAL_OVERLAY_ID_T id)120 static inline uint32_t hal_overlay_get_text_free_size(enum HAL_OVERLAY_ID_T id)
121 { return 0;}
122 
hal_overlay_acquire(enum HAL_OVERLAY_ID_T id)123 static inline void hal_overlay_acquire(enum HAL_OVERLAY_ID_T id) { return;}
124 
hal_overlay_release(enum HAL_OVERLAY_ID_T id)125 static inline void hal_overlay_release(enum HAL_OVERLAY_ID_T id) { return;}
126 
hal_overlay_is_used(void)127 static inline bool hal_overlay_is_used(void) { return false;}
128 
129 #endif /*NO_OVERLAY*/
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif /*__HAL_OVERLAY_H__*/
136 
137