• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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  * Description: dfx adapt layer
15  * This file should be changed only infrequently and with great care.
16  */
17 #ifndef DFX_ADAPT_LAYER_H
18 #define DFX_ADAPT_LAYER_H
19 
20 #include <stdbool.h>
21 #include "securec.h"
22 #include "dfx_feature_config.h"
23 #include "dfx_resource_id.h"
24 #include "diag_config.h"
25 #include "soc_osal.h"
26 #include "soc_log.h"
27 #include "systick.h"
28 #include "cmsis_os2.h"
29 #include "dfx_system_init.h"
30 
31 typedef enum {
32     FLASH_OP_TYPE_OTA,
33     FLASH_OP_TYPE_LOG_FILE,
34     FLASH_OP_TYPE_FLASH_DATA,
35     FLASH_OP_TYPE_USER,
36     FLASH_OP_TYPE_MAX,
37 } dfx_flash_op_type_t;
38 
dfx_int_lock(void)39 static inline uint32_t dfx_int_lock(void)
40 {
41     return osal_irq_lock();
42 }
43 
dfx_int_restore(uint32_t state)44 static inline void dfx_int_restore(uint32_t state)
45 {
46     osal_irq_restore(state);
47 }
48 
dfx_sleep(uint32_t ms)49 static inline void dfx_sleep(uint32_t ms)
50 {
51     osDelay(ms);
52 }
53 
dfx_malloc_permanent(uint32_t id,uint32_t size)54 static inline void *dfx_malloc_permanent(uint32_t id, uint32_t size)
55 {
56     unused(id);
57     return osal_vmalloc(size);
58 }
59 
dfx_malloc(uint32_t id,uint32_t size)60 static inline void *dfx_malloc(uint32_t id, uint32_t size)
61 {
62     unused(id);
63     return osal_vmalloc(size);
64 }
65 
dfx_zalloc(uint32_t id,uint32_t size)66 static inline void *dfx_zalloc(uint32_t id, uint32_t size)
67 {
68     unused(id);
69     return osal_vzalloc(size);
70 }
71 
dfx_free(uint32_t id,void * addr)72 static inline void dfx_free(uint32_t id, void *addr)
73 {
74     unused(id);
75     osal_vfree(addr);
76 }
77 
dfx_get_cur_second(void)78 static inline uint32_t dfx_get_cur_second(void)
79 {
80     return (uint32_t)uapi_systick_get_s();
81 }
82 
83 /* Event 接口 */
dfx_event_write(dfx_event_id_t event_id)84 static inline int32_t dfx_event_write(dfx_event_id_t event_id)
85 {
86     unused(event_id);
87     return ERRCODE_SUCC;
88 }
89 
90 /* Msg 接口 */
dfx_msg_write(uint32_t msg_id,uint8_t * msg,uint16_t msg_len,bool wait)91 static inline errcode_t dfx_msg_write(uint32_t msg_id, uint8_t *msg, uint16_t msg_len, bool wait)
92 {
93     uint32_t timeout = (wait) ? OSAL_MSGQ_WAIT_FOREVER : 0;
94     uint8_t msg_data[DFX_MSG_MAX_SIZE + DFX_MSG_ID_LEN];
95 
96     *(uint32_t*)msg_data = msg_id;
97 
98     if ((msg != NULL) && (memcpy_s(&msg_data[DFX_MSG_ID_LEN], DFX_MSG_MAX_SIZE, msg, msg_len) != EOK)) {
99         return ERRCODE_FAIL;
100     }
101 
102     return (osal_msg_queue_write_copy(dfx_get_osal_queue_id(), msg_data, DFX_MSG_MAX_SIZE + DFX_MSG_ID_LEN, timeout) ==
103             OSAL_SUCCESS) ? ERRCODE_SUCC : ERRCODE_FAIL;
104 }
105 
106 /*
107  * 文件传输消息发送接口
108  * 如文件传输未单独创建线程,可使用dfx_msg_write适配
109  * 如文件传输单独创建线程,使用g_dfx_transmit_queue_id发送消息
110  */
transmit_msg_write(uint32_t msg_id,uint8_t * msg,uint16_t msg_len,bool wait)111 static inline errcode_t transmit_msg_write(uint32_t msg_id, uint8_t *msg, uint16_t msg_len, bool wait)
112 {
113     return dfx_msg_write(msg_id, msg, msg_len, wait);
114 }
115 
dfx_msg_queue_is_full(unsigned long queue_id)116 static inline int32_t dfx_msg_queue_is_full(unsigned long queue_id)
117 {
118     return osal_msg_queue_is_full(queue_id);
119 }
120 
121 /* TIMER接口 */
122 typedef osal_timer dfx_timer;
123 typedef void (*dfx_timer_handler)(uintptr_t data);
124 typedef void (*temp_osal_handler)(unsigned long data);
dfx_timer_init(dfx_timer * timer,dfx_timer_handler handler,uintptr_t data,uint32_t ms)125 static inline errcode_t dfx_timer_init(dfx_timer *timer, dfx_timer_handler handler, uintptr_t data, uint32_t ms)
126 {
127     timer->handler = (temp_osal_handler)handler;
128     timer->data = data;
129     timer->interval = ms;
130     return osal_timer_init(timer);
131 }
132 
dfx_timer_start(dfx_timer * timer,uint32_t ms)133 static inline int32_t dfx_timer_start(dfx_timer *timer, uint32_t ms)
134 {
135     unused(ms);
136     return osal_timer_start(timer);
137 }
138 
dfx_timer_stop(dfx_timer * timer)139 static inline int32_t dfx_timer_stop(dfx_timer *timer)
140 {
141     return osal_timer_stop(timer);
142 }
143 
dfx_timer_destroy(dfx_timer * timer)144 static inline int32_t dfx_timer_destroy(dfx_timer *timer)
145 {
146     return osal_timer_destroy(timer);
147 }
148 
149 /* machine 接口 */
dfx_machine_get_id(void)150 static inline uint32_t dfx_machine_get_id(void)
151 {
152     return 0;
153 }
154 
dfx_machine_get_name(void)155 static inline char *dfx_machine_get_name(void)
156 {
157     return "unknown";
158 }
159 
160 /* fault 处理 */
dfx_fault_event_data(uint32_t event_id,const uint8_t * data,uint16_t len)161 static inline void dfx_fault_event_data(uint32_t event_id, const uint8_t *data, uint16_t len)
162 {
163     unused(event_id);
164     unused(data);
165     unused(len);
166 }
167 
168 /* flash 读写 */
dfx_flash_read(uint8_t opt_type,uint32_t offset,const uint8_t * buf,uint32_t size)169 static inline uint32_t dfx_flash_read(uint8_t opt_type, uint32_t offset, const uint8_t *buf, uint32_t size)
170 {
171     unused(opt_type);
172     unused(offset);
173     unused(buf);
174     unused(size);
175     return size;
176 }
177 
dfx_flash_write(uint8_t opt_type,unsigned offset,const uint8_t * buf,uint32_t size,bool do_erase)178 static inline uint32_t dfx_flash_write(uint8_t opt_type, unsigned offset, const uint8_t *buf, uint32_t size,
179     bool do_erase)
180 {
181     unused(opt_type);
182     unused(offset);
183     unused(buf);
184     unused(size);
185     unused(do_erase);
186     return size;
187 }
188 
189 /*
190  * flash擦除数据接口
191  */
dfx_flash_erase(uint8_t opt_type,const uint32_t offset,const uint32_t size)192 static inline errcode_t dfx_flash_erase(uint8_t opt_type, const uint32_t offset, const uint32_t size)
193 {
194     unused(opt_type);
195     unused(offset);
196     unused(size);
197     return ERRCODE_SUCC;
198 }
199 
dfx_watchdog_kick(void)200 static inline void dfx_watchdog_kick(void)
201 {
202 }
203 
dfx_pm_add_sleep_veto(void)204 static inline errcode_t dfx_pm_add_sleep_veto(void)
205 {
206     return ERRCODE_SUCC;
207 }
208 
dfx_pm_remove_sleep_veto(void)209 static inline errcode_t dfx_pm_remove_sleep_veto(void)
210 {
211     return ERRCODE_SUCC;
212 }
213 
dfx_log_get_level(uint8_t core,const uint8_t * level)214 static inline errcode_t dfx_log_get_level(uint8_t core, const uint8_t *level)
215 {
216     unused(core);
217     unused(level);
218     return ERRCODE_SUCC;
219 }
220 
dfx_log_set_level(uint8_t core,uint8_t level)221 static inline errcode_t dfx_log_set_level(uint8_t core, uint8_t level)
222 {
223     unused(core);
224     unused(level);
225     return ERRCODE_SUCC;
226 }
227 
228 #define dfx_log_debug(fmt...)
229 #define dfx_log_info(fmt...)
230 #define dfx_log_err(fmt...) printf(fmt)
231 
232 #define dfx_assert(x) ((void)0)
233 
234 #endif /* DFX_ADAPT_LAYER_H */
235