summaryrefslogtreecommitdiff
path: root/halimpl/osi/osi.h
blob: ac29c5442c40b8f88e9c8c957769f5caeec8ef5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
/*
 *    Copyright (C) 2013 SAMSUNG S.LSI
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */

#ifndef OSI_H
#define OSI_H

/************************************************************************
** OS Interface
*************************************************************************/
#include <osi_common.h>

#include <log/log.h>

/************************************************************************
** public functions
*************************************************************************/
/*
 * Function     OSI_init
 *
 * Description  This function is called to initialize OSI context.
 *
 * Return       OSI_FAIL if any problem
 *              OSI_OK if initialization is succeeded.
 */
OSI_STATE OSI_init(void);

/*
 * Function     OSI_deinit
 *
 * Description  This function is called to deinitialize OSI context.
 *
 */
void OSI_deinit(void);

/*
 * Function     OSI_delay
 *
 * Description  This function is called to delay.
 *
 * Parameter    timeout(input): ms
 *
 * Return
 *
 */
void OSI_delay(uint32_t timeout);

/***************
 *  OSI TASK
 ***************/
/*
 * Function     OSI_task_allocate
 *
 * Description  This function is called to create a new task.
 *
 * Parameter    task_name(input):
 *              task_entry(input): entry function.
 *
 * Return       OSI_TASK_HANDLE if allocate is succeeded,
 *              NULL if any problem.
 */
tOSI_TASK_HANDLER OSI_task_allocate(const char* task_name,
                                    tOSI_TASK_ENTRY task_entry);

/*
 * Function     OSI_task_run
 *
 * Description  This function is called to create a new task.
 *
 * Parameter    OSI_TASK_HANDLE(input): target task
 *
 * Return       OSI_OK if creadtion is succeeded,
 *              OSI_FAIL if any problem.
 */
OSI_STATE OSI_task_run(tOSI_TASK_HANDLER task_handler);

/*
 * Function     OSI_task_isRun
 *
 * Description  Check the task is running or not.
 *
 * Parameter    task_handler(input): Target task handler to check running
 *
 * Return       OSI_RUN, on run.
 *              OSI_FAIL, on error.
 */
OSI_STATE OSI_task_isRun(tOSI_TASK_HANDLER task_handler);

/*
 * Function     OSI_task_kill
 *
 * Description  This function is called to kill a task.
 *
 * Parameter    task_handler(input): Target task handler to kill.
 *
 * Return       OSI_OK, on success.
 *              other, on error.
 */
OSI_STATE OSI_task_kill(tOSI_TASK_HANDLER task_handler);

/*
 * Function     OSI_task_stop
 *
 * Description  This function is called to stop a task.
 *
 * Parameter    task_handler(input): Target task handler to kill.
 *
 * Return       OSI_OK, on success.
 *              other, on error.
 */
OSI_STATE OSI_task_stop(tOSI_TASK_HANDLER task_handler);

/*
 * Function     OSI_task_free
 *
 * Description  This function is called to free a task.
 *
 * Parameter    task_handler(input): Target task handler to kill.
 *
 * Return       OSI_OK, on success.
 *              other, on error.
 */
OSI_STATE OSI_task_free(tOSI_TASK_HANDLER task_handler);

/*
 * Function     OSI_task_get_handler
 *
 * Description  This function is called to get handler by task name.
 *
 * Parameter    name(input): Target name to get handler.
 *
 * Return       tOSI_TASK_HANDLER, on success.
 *              NULL, on error.
 */
tOSI_TASK_HANDLER OSI_task_get_handler(char* name);

/***************
 *  OSI MEMORY
 ***************/
/*
 * Function     OSI_mem_get
 *
 * Description  This function is called to get memeory.
 *
 * Parameter    size(input): it should be small than OSI_MEM_POLL_SIZE
 *
 * Return       Memory address if getting is succeeded,
 *              NULL if any problem.
 */
tOSI_MEM_HANDLER OSI_mem_get(size_t size);

/*
 * Function     OSI_mem_free
 *
 * Description  This function is called to free memeory.
 *
 * Parameter    target(input):
 *
 * Return
 */
void OSI_mem_free(tOSI_MEM_HANDLER target);

/** queue **/
/*
 * Function     OSI_queue_allocate
 *
 * Description  This function is called to get a free queue.
 *              Anyone using OSI can access this message que.
 *
 * Parameter    name(input): que_name
 *
 * Return       tOSI_QUEUE_HANDLER if init is succeeded.
 *              NULL if any problem.
 */
tOSI_QUEUE_HANDLER OSI_queue_allocate(const char* que_name);

/*
 * Function     OSI_queue_put
 *
 * Description  This function is called to put data to the queue.
 *
 * Parameter    que (input): queue handler.
 *              data (input): void * data to put the stack.
 *
 * Return       number of element in target queue
 *
 */
int OSI_queue_put(tOSI_QUEUE_HANDLER queue, void* p_data);

/*
 * Function     OSI_queue_get
 *
 * Description  This function is called to get data from the queue.
 *
 * Parameter    que (input): queue handler.
 *
 * Return       (void *) the first data in the queue.
 *              NULL if any problem.
 */
void* OSI_queue_get(tOSI_QUEUE_HANDLER queue);

/*
 * Function     OSI_queue_get_wait
 *
 * Description  This function is called to get data from the queue.
 *              If the queue is empty, this function is waiting for
 *              putting data.
 *
 * Parameter    que (input): queue handler.
 *
 * Return       (void *) the first data in the queue.
 *              NULL if any problem.
 */
void* OSI_queue_get_wait(tOSI_QUEUE_HANDLER target);

/*
 * Function     OSI_queue_free
 *
 * Description  This function is called to make que free.
 *
 * Parameter    que (input): queue handler.
 *
 * Return       void
 */
void OSI_queue_free(tOSI_QUEUE_HANDLER target);

/*
 * Function     OSI_queue_get_handler
 *
 * Description  This function is called to get handler by queue name.
 *
 * Parameter    name(input): Target name to get handler.
 *
 * Return       tOSI_QUEUE_HANDLER, on success.
 *              NULL, on error.
 */
tOSI_QUEUE_HANDLER OSI_queue_get_handler(const char* name);

/***************
 *  OSI TIMER
 ***************/
/*
 * Function     OSI_timer_allocate
 *
 * Description  This function is called to get a timer.
 *
 * Parameter    timer_name(input):
 *
 * Return       0 if any problem
 *              other if initialization is succeeded.
 */
tOSI_TIMER_HANDLER OSI_timer_allocate(const char* timer_name);

/*
 * Function     OSI_timer_start
 *
 * Description  This function is called to start a timer.
 *
 * Parameter    timer_handler (input)
 *              timeout (input): time out value. it is millisecond.
 *              callback (input): callback function.
 *
 * Return       0 if any problem
 *              other if initialization is succeeded.
 *
 */
int OSI_timer_start(tOSI_TIMER_HANDLER timer, uint32_t timeout,
                    tOSI_TIMER_CALLBACK callback, void* param);

/*
 * Function     OSI_timer_stop
 *
 * Description  This function is called to stop a timer.
 *
 * Parameter    timer_handler (input)
 *
 * Return
 *
 */
void OSI_timer_stop(tOSI_TIMER_HANDLER timer);

/*
 * Function     OSI_timer_free
 *
 * Description  This function is called to free a timer.
 *
 * Parameter    timer_handler (input)
 *
 * Return
 *
 */
void OSI_timer_free(tOSI_TIMER_HANDLER timer);

/*
 * Function     OSI_timer_get_handler
 *
 * Description  This function is called to get timer handler by name.
 *
 * Parameter    name(input): Target name to get handler.
 *
 * Return       tOSI_QUEUE_HANDLER, on success.
 *              NULL, on error.
 */
tOSI_TIMER_HANDLER OSI_timer_get_handler(char* name);

/***************
 *  OSI DEBUG
 ***************/
#define OSI_DEBUG
extern int osi_debug_level;
#define OSI_set_debug_level(xx) (osi_debug_level = xx)
#ifdef OSI_DEBUG
#define __osi_log(type, ...) (void)ALOG(type, "SecHAL", __VA_ARGS__)
#define OSI_logt(format, ...)                                      \
  do {                                                             \
    if (osi_debug_level >= 2)                                      \
      __osi_log(LOG_INFO, "%s: " format, __func__, ##__VA_ARGS__); \
  } while (0)
#define OSI_logd(format, ...)                                       \
  do {                                                              \
    if (osi_debug_level >= 1)                                       \
      __osi_log(LOG_DEBUG, "%s: " format, __func__, ##__VA_ARGS__); \
  } while (0)
#define OSI_loge(format, ...)                                       \
  do {                                                              \
    if (osi_debug_level >= 0)                                       \
      __osi_log(LOG_ERROR, "%s: " format, __func__, ##__VA_ARGS__); \
  } while (0)
#else
#define OSI_logt(...)
#define OSI_logd(...)
#define OSI_loge(...)
#endif

#endif /* OSI_H */