1 /*
2  *    Copyright (C) 2013 SAMSUNG S.LSI
3  *
4  *   Licensed under the Apache License, Version 2.0 (the "License");
5  *   you may not use this file except in compliance with the License.
6  *   You may obtain a copy of the License at:
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *   Unless required by applicable law or agreed to in writing, software
11  *   distributed under the License is distributed on an "AS IS" BASIS,
12  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *   See the License for the specific language governing permissions and
14  *   limitations under the License.
15  *
16  */
17 
18 #ifndef OSI_H
19 #define OSI_H
20 
21 /************************************************************************
22 ** OS Interface
23 *************************************************************************/
24 #include <osi_common.h>
25 
26 #include <log/log.h>
27 
28 /************************************************************************
29 ** public functions
30 *************************************************************************/
31 /*
32  * Function     OSI_init
33  *
34  * Description  This function is called to initialize OSI context.
35  *
36  * Return       OSI_FAIL if any problem
37  *              OSI_OK if initialization is succeeded.
38  */
39 OSI_STATE OSI_init(void);
40 
41 /*
42  * Function     OSI_deinit
43  *
44  * Description  This function is called to deinitialize OSI context.
45  *
46  */
47 void OSI_deinit(void);
48 
49 /*
50  * Function     OSI_delay
51  *
52  * Description  This function is called to delay.
53  *
54  * Parameter    timeout(input): ms
55  *
56  * Return
57  *
58  */
59 void OSI_delay(uint32_t timeout);
60 
61 /***************
62  *  OSI TASK
63  ***************/
64 /*
65  * Function     OSI_task_allocate
66  *
67  * Description  This function is called to create a new task.
68  *
69  * Parameter    task_name(input):
70  *              task_entry(input): entry function.
71  *
72  * Return       OSI_TASK_HANDLE if allocate is succeeded,
73  *              NULL if any problem.
74  */
75 tOSI_TASK_HANDLER OSI_task_allocate(const char* task_name,
76                                     tOSI_TASK_ENTRY task_entry);
77 
78 /*
79  * Function     OSI_task_run
80  *
81  * Description  This function is called to create a new task.
82  *
83  * Parameter    OSI_TASK_HANDLE(input): target task
84  *
85  * Return       OSI_OK if creadtion is succeeded,
86  *              OSI_FAIL if any problem.
87  */
88 OSI_STATE OSI_task_run(tOSI_TASK_HANDLER task_handler);
89 
90 /*
91  * Function     OSI_task_isRun
92  *
93  * Description  Check the task is running or not.
94  *
95  * Parameter    task_handler(input): Target task handler to check running
96  *
97  * Return       OSI_RUN, on run.
98  *              OSI_FAIL, on error.
99  */
100 OSI_STATE OSI_task_isRun(tOSI_TASK_HANDLER task_handler);
101 
102 /*
103  * Function     OSI_task_kill
104  *
105  * Description  This function is called to kill a task.
106  *
107  * Parameter    task_handler(input): Target task handler to kill.
108  *
109  * Return       OSI_OK, on success.
110  *              other, on error.
111  */
112 OSI_STATE OSI_task_kill(tOSI_TASK_HANDLER task_handler);
113 
114 /*
115  * Function     OSI_task_stop
116  *
117  * Description  This function is called to stop a task.
118  *
119  * Parameter    task_handler(input): Target task handler to kill.
120  *
121  * Return       OSI_OK, on success.
122  *              other, on error.
123  */
124 OSI_STATE OSI_task_stop(tOSI_TASK_HANDLER task_handler);
125 
126 /*
127  * Function     OSI_task_free
128  *
129  * Description  This function is called to free a task.
130  *
131  * Parameter    task_handler(input): Target task handler to kill.
132  *
133  * Return       OSI_OK, on success.
134  *              other, on error.
135  */
136 OSI_STATE OSI_task_free(tOSI_TASK_HANDLER task_handler);
137 
138 /*
139  * Function     OSI_task_get_handler
140  *
141  * Description  This function is called to get handler by task name.
142  *
143  * Parameter    name(input): Target name to get handler.
144  *
145  * Return       tOSI_TASK_HANDLER, on success.
146  *              NULL, on error.
147  */
148 tOSI_TASK_HANDLER OSI_task_get_handler(char* name);
149 
150 /***************
151  *  OSI MEMORY
152  ***************/
153 /*
154  * Function     OSI_mem_get
155  *
156  * Description  This function is called to get memeory.
157  *
158  * Parameter    size(input): it should be small than OSI_MEM_POLL_SIZE
159  *
160  * Return       Memory address if getting is succeeded,
161  *              NULL if any problem.
162  */
163 tOSI_MEM_HANDLER OSI_mem_get(size_t size);
164 
165 /*
166  * Function     OSI_mem_free
167  *
168  * Description  This function is called to free memeory.
169  *
170  * Parameter    target(input):
171  *
172  * Return
173  */
174 void OSI_mem_free(tOSI_MEM_HANDLER target);
175 
176 /** queue **/
177 /*
178  * Function     OSI_queue_allocate
179  *
180  * Description  This function is called to get a free queue.
181  *              Anyone using OSI can access this message que.
182  *
183  * Parameter    name(input): que_name
184  *
185  * Return       tOSI_QUEUE_HANDLER if init is succeeded.
186  *              NULL if any problem.
187  */
188 tOSI_QUEUE_HANDLER OSI_queue_allocate(const char* que_name);
189 
190 /*
191  * Function     OSI_queue_put
192  *
193  * Description  This function is called to put data to the queue.
194  *
195  * Parameter    que (input): queue handler.
196  *              data (input): void * data to put the stack.
197  *
198  * Return       number of element in target queue
199  *
200  */
201 int OSI_queue_put(tOSI_QUEUE_HANDLER queue, void* p_data);
202 
203 /*
204  * Function     OSI_queue_get
205  *
206  * Description  This function is called to get data from the queue.
207  *
208  * Parameter    que (input): queue handler.
209  *
210  * Return       (void *) the first data in the queue.
211  *              NULL if any problem.
212  */
213 void* OSI_queue_get(tOSI_QUEUE_HANDLER queue);
214 
215 /*
216  * Function     OSI_queue_get_wait
217  *
218  * Description  This function is called to get data from the queue.
219  *              If the queue is empty, this function is waiting for
220  *              putting data.
221  *
222  * Parameter    que (input): queue handler.
223  *
224  * Return       (void *) the first data in the queue.
225  *              NULL if any problem.
226  */
227 void* OSI_queue_get_wait(tOSI_QUEUE_HANDLER target);
228 
229 /*
230  * Function     OSI_queue_free
231  *
232  * Description  This function is called to make que free.
233  *
234  * Parameter    que (input): queue handler.
235  *
236  * Return       void
237  */
238 void OSI_queue_free(tOSI_QUEUE_HANDLER target);
239 
240 /*
241  * Function     OSI_queue_get_handler
242  *
243  * Description  This function is called to get handler by queue name.
244  *
245  * Parameter    name(input): Target name to get handler.
246  *
247  * Return       tOSI_QUEUE_HANDLER, on success.
248  *              NULL, on error.
249  */
250 tOSI_QUEUE_HANDLER OSI_queue_get_handler(const char* name);
251 
252 /***************
253  *  OSI TIMER
254  ***************/
255 /*
256  * Function     OSI_timer_allocate
257  *
258  * Description  This function is called to get a timer.
259  *
260  * Parameter    timer_name(input):
261  *
262  * Return       0 if any problem
263  *              other if initialization is succeeded.
264  */
265 tOSI_TIMER_HANDLER OSI_timer_allocate(const char* timer_name);
266 
267 /*
268  * Function     OSI_timer_start
269  *
270  * Description  This function is called to start a timer.
271  *
272  * Parameter    timer_handler (input)
273  *              timeout (input): time out value. it is millisecond.
274  *              callback (input): callback function.
275  *
276  * Return       0 if any problem
277  *              other if initialization is succeeded.
278  *
279  */
280 int OSI_timer_start(tOSI_TIMER_HANDLER timer, uint32_t timeout,
281                     tOSI_TIMER_CALLBACK callback, void* param);
282 
283 /*
284  * Function     OSI_timer_stop
285  *
286  * Description  This function is called to stop a timer.
287  *
288  * Parameter    timer_handler (input)
289  *
290  * Return
291  *
292  */
293 void OSI_timer_stop(tOSI_TIMER_HANDLER timer);
294 
295 /*
296  * Function     OSI_timer_free
297  *
298  * Description  This function is called to free a timer.
299  *
300  * Parameter    timer_handler (input)
301  *
302  * Return
303  *
304  */
305 void OSI_timer_free(tOSI_TIMER_HANDLER timer);
306 
307 /*
308  * Function     OSI_timer_get_handler
309  *
310  * Description  This function is called to get timer handler by name.
311  *
312  * Parameter    name(input): Target name to get handler.
313  *
314  * Return       tOSI_QUEUE_HANDLER, on success.
315  *              NULL, on error.
316  */
317 tOSI_TIMER_HANDLER OSI_timer_get_handler(char* name);
318 
319 /***************
320  *  OSI DEBUG
321  ***************/
322 #define OSI_DEBUG
323 extern int osi_debug_level;
324 #define OSI_set_debug_level(xx) (osi_debug_level = xx)
325 #ifdef OSI_DEBUG
326 #define __osi_log(type, ...) (void)ALOG(type, "SecHAL", __VA_ARGS__)
327 #define OSI_logt(format, ...)                                      \
328   do {                                                             \
329     if (osi_debug_level >= 2)                                      \
330       __osi_log(LOG_INFO, "%s: " format, __func__, ##__VA_ARGS__); \
331   } while (0)
332 #define OSI_logd(format, ...)                                       \
333   do {                                                              \
334     if (osi_debug_level >= 1)                                       \
335       __osi_log(LOG_DEBUG, "%s: " format, __func__, ##__VA_ARGS__); \
336   } while (0)
337 #define OSI_loge(format, ...)                                       \
338   do {                                                              \
339     if (osi_debug_level >= 0)                                       \
340       __osi_log(LOG_ERROR, "%s: " format, __func__, ##__VA_ARGS__); \
341   } while (0)
342 #else
343 #define OSI_logt(...)
344 #define OSI_logd(...)
345 #define OSI_loge(...)
346 #endif
347 
348 #endif /* OSI_H */
349