• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Bestechnic (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef __HAL_OVERLAY_H__
16 #define __HAL_OVERLAY_H__
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #define HAL_OVERLAY_TEXT0_LOC       __attribute__((section(".overlay_text0")))
23 #define HAL_OVERLAY_TEXT1_LOC       __attribute__((section(".overlay_text1")))
24 #define HAL_OVERLAY_TEXT2_LOC       __attribute__((section(".overlay_text2")))
25 #define HAL_OVERLAY_TEXT3_LOC       __attribute__((section(".overlay_text3")))
26 #define HAL_OVERLAY_TEXT4_LOC       __attribute__((section(".overlay_text4")))
27 #define HAL_OVERLAY_TEXT5_LOC       __attribute__((section(".overlay_text5")))
28 #define HAL_OVERLAY_TEXT6_LOC       __attribute__((section(".overlay_text6")))
29 #define HAL_OVERLAY_TEXT7_LOC       __attribute__((section(".overlay_text7")))
30 
31 #define HAL_OVERLAY_RODATA0_LOC     __attribute__((section(".overlay_rodata0")))
32 #define HAL_OVERLAY_RODATA1_LOC     __attribute__((section(".overlay_rodata1")))
33 #define HAL_OVERLAY_RODATA2_LOC     __attribute__((section(".overlay_rodata2")))
34 #define HAL_OVERLAY_RODATA3_LOC     __attribute__((section(".overlay_rodata3")))
35 #define HAL_OVERLAY_RODATA4_LOC     __attribute__((section(".overlay_rodata4")))
36 #define HAL_OVERLAY_RODATA5_LOC     __attribute__((section(".overlay_rodata5")))
37 #define HAL_OVERLAY_RODATA6_LOC     __attribute__((section(".overlay_rodata6")))
38 #define HAL_OVERLAY_RODATA7_LOC     __attribute__((section(".overlay_rodata7")))
39 
40 #define HAL_OVERLAY_DATA0_LOC       __attribute__((section(".overlay_data0")))
41 #define HAL_OVERLAY_DATA1_LOC       __attribute__((section(".overlay_data1")))
42 #define HAL_OVERLAY_DATA2_LOC       __attribute__((section(".overlay_data2")))
43 #define HAL_OVERLAY_DATA3_LOC       __attribute__((section(".overlay_data3")))
44 #define HAL_OVERLAY_DATA4_LOC       __attribute__((section(".overlay_data4")))
45 #define HAL_OVERLAY_DATA5_LOC       __attribute__((section(".overlay_data5")))
46 #define HAL_OVERLAY_DATA6_LOC       __attribute__((section(".overlay_data6")))
47 #define HAL_OVERLAY_DATA7_LOC       __attribute__((section(".overlay_data7")))
48 
49 #define  INVALID_OVERLAY_ADDR 0xffffffff
50 enum HAL_OVERLAY_ID_T {
51     HAL_OVERLAY_ID_0,
52     HAL_OVERLAY_ID_1,
53     HAL_OVERLAY_ID_2,
54     HAL_OVERLAY_ID_3,
55     HAL_OVERLAY_ID_4,
56     HAL_OVERLAY_ID_5,
57     HAL_OVERLAY_ID_6,
58     HAL_OVERLAY_ID_7,
59 
60     HAL_OVERLAY_ID_QTY,
61     HAL_OVERLAY_ID_IN_CFG,
62 };
63 
64 enum HAL_OVERLAY_RET_T {
65     HAL_OVERLAY_RET_OK,
66     HAL_OVERLAY_RET_BAD_ID,
67     HAL_OVERLAY_RET_IN_CFG,
68     HAL_OVERLAY_RET_IN_USE,
69 };
70 
71 #ifndef NO_OVERLAY
72 enum HAL_OVERLAY_RET_T hal_overlay_load(enum HAL_OVERLAY_ID_T id);
73 
74 enum HAL_OVERLAY_RET_T hal_overlay_unload(enum HAL_OVERLAY_ID_T id);
75 
76 /*
77  * get the overlay's text start address
78  */
79 uint32_t hal_overlay_get_text_address(void);
80 
81 /*
82  * get the whole size of the overlay text
83  */
84 uint32_t hal_overlay_get_text_all_size(void);
85 /*
86  * get the segment size of one overlay text
87  */
88 uint32_t hal_overlay_get_text_size(enum HAL_OVERLAY_ID_T id);
89 /*
90  * Use the free space of one segement, this function
91  * return the free address of space
92  */
93 uint32_t hal_overlay_get_text_free_addr(enum HAL_OVERLAY_ID_T id);
94 /*
95  * get the free size for one overlay text
96  */
97 uint32_t hal_overlay_get_text_free_size(enum HAL_OVERLAY_ID_T id);
98 /*
99  * acquire one overlay segment
100  */
101 void hal_overlay_acquire(enum HAL_OVERLAY_ID_T id);
102 /*
103  * release one overlay segment
104  */
105 void hal_overlay_release(enum HAL_OVERLAY_ID_T id);
106 /*
107  * check if any overlay segment is used
108  */
109 bool hal_overlay_is_used(void);
110 
111 #else
112 
hal_overlay_load(enum HAL_OVERLAY_ID_T id)113 static inline enum HAL_OVERLAY_RET_T hal_overlay_load(enum HAL_OVERLAY_ID_T id)
114 { return HAL_OVERLAY_RET_OK; }
115 
hal_overlay_unload(enum HAL_OVERLAY_ID_T id)116 static inline enum HAL_OVERLAY_RET_T hal_overlay_unload(enum HAL_OVERLAY_ID_T id)
117 { return HAL_OVERLAY_RET_OK; }
118 
hal_overlay_get_text_address(void)119 static inline uint32_t hal_overlay_get_text_address(void)
120 { return INVALID_OVERLAY_ADDR;}
121 
hal_overlay_get_text_all_size(void)122 static inline uint32_t hal_overlay_get_text_all_size(void)
123 { return 0;}
124 
hal_overlay_get_text_size(enum HAL_OVERLAY_ID_T id)125 static inline uint32_t hal_overlay_get_text_size(enum HAL_OVERLAY_ID_T id)
126 { return 0;}
127 
hal_overlay_get_text_free_addr(enum HAL_OVERLAY_ID_T id)128 static inline uint32_t hal_overlay_get_text_free_addr(enum HAL_OVERLAY_ID_T id)
129 { return INVALID_OVERLAY_ADDR;}
130 
hal_overlay_get_text_free_size(enum HAL_OVERLAY_ID_T id)131 static inline uint32_t hal_overlay_get_text_free_size(enum HAL_OVERLAY_ID_T id)
132 { return 0;}
133 
hal_overlay_acquire(enum HAL_OVERLAY_ID_T id)134 static inline void hal_overlay_acquire(enum HAL_OVERLAY_ID_T id) { return;}
135 
hal_overlay_release(enum HAL_OVERLAY_ID_T id)136 static inline void hal_overlay_release(enum HAL_OVERLAY_ID_T id) { return;}
137 
hal_overlay_is_used(void)138 static inline bool hal_overlay_is_used(void) { return false;}
139 
140 #endif /*NO_OVERLAY*/
141 
142 #ifdef __cplusplus
143 }
144 #endif
145 
146 #endif /*__HAL_OVERLAY_H__*/
147 
148