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 */
15
16#ifndef __HI_HOOK_FUC_H__
17#define __HI_HOOK_FUC_H__
18
19#include <hi_task.h>
20#include <hi_mem.h>
21#include <hi_os_stat.h>
22#include <hi_timer.h>
23#include <hi_isr.h>
24
25#define  fuc_type_name(name)    pfn_##name##_hook
26
27typedef hi_u32 (*fuc_type_name(hi_task_create))(hi_u32 *taskid,
28                                                const hi_task_attr *attr,
29                                                hi_void* (*task_route)(hi_void *),
30                                                hi_void *arg);
31
32typedef hi_u32  (*fuc_type_name(hi_task_delete))(hi_u32 taskid);
33
34typedef hi_u32  (*fuc_type_name(hi_task_suspend))(hi_u32 taskid);
35
36typedef hi_u32  (*fuc_type_name(hi_task_resume))(hi_u32 taskid);
37
38typedef hi_u32  (*fuc_type_name(hi_task_get_priority))(hi_u32 taskid,
39                                                       hi_u32 *priority);
40
41typedef hi_u32  (*fuc_type_name(hi_task_set_priority))(hi_u32 taskid,
42                                                       hi_u32 priority);
43
44typedef hi_u32  (*fuc_type_name(hi_task_get_current_id))(hi_void);
45
46typedef hi_void (*fuc_type_name(hi_task_lock))(hi_void);
47
48typedef hi_void (*fuc_type_name(hi_task_unlock))(hi_void);
49
50typedef hi_u32  (*fuc_type_name(hi_sleep))(hi_u32 ms);
51
52typedef hi_u32 (*fuc_type_name(hi_event_create))(HI_OUT hi_u32 * id);
53
54typedef hi_u32 (*fuc_type_name(hi_event_init))(hi_u8 max_event_cnt,
55                                               hi_pvoid event_space);
56
57typedef hi_u32 (*fuc_type_name(hi_event_send))(hi_u32 id,
58                                               hi_u32 event_bits);
59
60typedef hi_u32 (*fuc_type_name(hi_event_wait))(hi_u32 id,
61                                               hi_u32 mask,
62                                               HI_OUT hi_u32 *event_bits,
63                                               hi_u32 timeout,
64                                               hi_u32 flag);
65
66typedef hi_u32 (*fuc_type_name(hi_event_clear))(hi_u32 id,
67                                                hi_u32 event_bits);
68
69typedef hi_u32 (*fuc_type_name(hi_event_delete))(hi_u32 id);
70
71typedef hi_pvoid (*fuc_type_name(hi_malloc))(hi_u32 mod_id,
72                                             hi_u32 size);
73
74typedef hi_void  (*fuc_type_name(hi_free))(hi_u32 mod_id,
75                                           hi_pvoid addr);
76
77typedef hi_u32 (*fuc_type_name(hi_msg_queue_create))(HI_OUT hi_u32* id,
78                                                     hi_u16 queue_len,
79                                                     hi_u32 msg_size);
80
81typedef hi_u32 (*fuc_type_name(hi_msg_queue_wait))(hi_u32 id,
82                                                   hi_pvoid msg,
83                                                   hi_u32 timeout_ms,
84                                                   hi_u32* msg_size);
85
86typedef hi_u32 (*fuc_type_name(hi_msg_queue_send))(hi_u32 id,
87                                                   hi_pvoid msg,
88                                                   hi_u32 timeout_ms,
89                                                   hi_u32 msg_size);
90
91typedef hi_u32 (*fuc_type_name(hi_msg_queue_delete))(hi_u32 id);
92
93
94typedef hi_u32 (*fuc_type_name(hi_mux_create))(hi_u32* mux_id);
95
96typedef hi_u32 (*fuc_type_name(hi_mux_delete))(hi_u32 mux_id);
97
98typedef hi_u32 (*fuc_type_name(hi_mux_pend))(hi_u32 mux_id,
99                                             hi_u32 timeout_ms);
100
101typedef hi_u32 (*fuc_type_name(hi_mux_post))(hi_u32 mux_id);
102
103typedef hi_u32 (*fuc_type_name(hi_sem_create))(hi_u32* sem_id, hi_u16 init_value);
104
105typedef hi_u32 (*fuc_type_name(hi_sem_bcreate))(hi_u32* sem_id, hi_u8 init_value);
106
107typedef hi_u32 (*fuc_type_name(hi_sem_delete))(hi_u32 sem_id);
108
109typedef hi_u32 (*fuc_type_name(hi_sem_wait))(hi_u32 sem_id, hi_u32 timeout);
110
111typedef hi_u32 (*fuc_type_name(hi_sem_signal))(hi_u32 sem_id);
112
113
114typedef hi_u32 (*fuc_type_name(hi_get_tick))(hi_void);
115
116typedef hi_u64 (*fuc_type_name(hi_get_tick64))(hi_void);
117
118typedef hi_u32 (*fuc_type_name(hi_get_milli_seconds))(hi_void);
119
120typedef hi_u32 (*fuc_type_name(hi_get_seconds))(hi_void);
121
122typedef hi_u64 (*fuc_type_name(hi_get_us))(hi_void);
123
124typedef hi_u32 (*fuc_type_name(hi_get_real_time))(hi_void);
125
126typedef hi_u32 (*fuc_type_name(hi_set_real_time))(hi_u32 sec);
127
128typedef hi_u32 (*fuc_type_name(hi_timer_create))(hi_u32 *timer_handle);
129
130typedef hi_u32 (*fuc_type_name(hi_timer_start))(hi_u32 timer_handle,
131                                                hi_timer_type type,
132                                                hi_u32 expire,
133                                                hi_timer_callback_f timer_func,
134                                                hi_u32 data);
135
136typedef hi_u32 (*fuc_type_name(hi_timer_stop))(hi_u32 timer_handle);
137
138typedef hi_u32 (*fuc_type_name(hi_timer_delete))(hi_u32 timer_handle);
139
140typedef hi_u32 (*fuc_type_name(hi_irq_enable))(hi_u32 vector);
141
142typedef hi_void (*fuc_type_name(hi_irq_disable))(hi_u32 vector);
143
144typedef hi_u32 (*fuc_type_name(hi_irq_request))(hi_u32 vector,
145                                                hi_u32 flags,
146                                                irq_routine routine,
147                                                hi_u32 param);
148
149typedef hi_u32 (*fuc_type_name(hi_irq_free))(hi_u32 vector);
150
151typedef hi_bool (*fuc_type_name(hi_is_int_context))(hi_void);
152
153typedef struct {
154    /* task */
155    fuc_type_name(hi_task_create)         hi_task_create_hook;
156    fuc_type_name(hi_task_delete)         hi_task_delete_hook;
157    fuc_type_name(hi_task_suspend)        hi_task_suspend_hook;
158    fuc_type_name(hi_task_resume)         hi_task_resume_hook;
159    fuc_type_name(hi_task_get_priority)   hi_task_get_priority_hook;
160    fuc_type_name(hi_task_set_priority)   hi_task_set_priority_hook;
161    fuc_type_name(hi_task_get_current_id) hi_task_get_current_id_hook;
162    fuc_type_name(hi_task_lock)           hi_task_lock_hook;
163    fuc_type_name(hi_task_unlock)         hi_task_unlock_hook;
164    fuc_type_name(hi_sleep)               hi_sleep_hook;
165    /* event */
166    fuc_type_name(hi_event_create)        hi_event_create_hook;
167    fuc_type_name(hi_event_init)          hi_event_init_hook;
168    fuc_type_name(hi_event_send)          hi_event_send_hook;
169    fuc_type_name(hi_event_wait)          hi_event_wait_hook;
170    fuc_type_name(hi_event_clear)         hi_event_clear_hook;
171    fuc_type_name(hi_event_delete)        hi_event_delete_hook;
172    /* memory */
173    fuc_type_name(hi_malloc)              hi_malloc_hook;
174    fuc_type_name(hi_free)                hi_free_hook;
175    /* queue */
176    fuc_type_name(hi_msg_queue_create)    hi_msg_queue_create_hook;
177    fuc_type_name(hi_msg_queue_send)      hi_msg_queue_send_hook;
178    fuc_type_name(hi_msg_queue_wait)      hi_msg_queue_wait_hook;
179    fuc_type_name(hi_msg_queue_delete)    hi_msg_queue_delete_hook;
180    /* mux */
181    fuc_type_name(hi_mux_create)          hi_mux_create_hook;
182    fuc_type_name(hi_mux_delete)          hi_mux_delete_hook;
183    fuc_type_name(hi_mux_pend)            hi_mux_pend_hook;
184    fuc_type_name(hi_mux_post)            hi_mux_post_hook;
185    /* semaphore */
186    fuc_type_name(hi_sem_create)          hi_sem_create_hook;
187    fuc_type_name(hi_sem_bcreate)         hi_sem_bcreate_hook;
188    fuc_type_name(hi_sem_delete)          hi_sem_delete_hook;
189    fuc_type_name(hi_sem_wait)            hi_sem_wait_hook;
190    fuc_type_name(hi_sem_signal)          hi_sem_signal_hook;
191    /* time */
192    fuc_type_name(hi_get_tick)            hi_get_tick_hook;
193    fuc_type_name(hi_get_tick64)          hi_get_tick64_hook;
194    fuc_type_name(hi_get_milli_seconds)   hi_get_milli_seconds_hook;
195    fuc_type_name(hi_get_seconds)         hi_get_seconds_hook;
196    fuc_type_name(hi_get_us)              hi_get_us_hook;
197    fuc_type_name(hi_get_real_time)       hi_get_real_time_hook;
198    fuc_type_name(hi_set_real_time)       hi_set_real_time_hook;
199    /* timer */
200    fuc_type_name(hi_timer_create)        hi_timer_create_hook;
201    fuc_type_name(hi_timer_start)         hi_timer_start_hook;
202    fuc_type_name(hi_timer_stop)          hi_timer_stop_hook;
203    fuc_type_name(hi_timer_delete)        hi_timer_delete_hook;
204    /* interrupt */
205    fuc_type_name(hi_irq_enable)          hi_irq_enable_hook;
206    fuc_type_name(hi_irq_disable)         hi_irq_disable_hook;
207    fuc_type_name(hi_irq_request)         hi_irq_request_hook;
208    fuc_type_name(hi_irq_free)            hi_irq_free_hook;
209    fuc_type_name(hi_is_int_context)      hi_is_int_context_hook;
210} hi_hook_osa;
211
212HI_EXTERN hi_hook_osa g_hook_osa;
213
214HI_EXTERN hi_u32 hi_init_hook_osa(const hi_hook_osa *osa);
215
216#endif
217