1 /*
2 * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19 #ifndef __VALG_PLAT_H__
20 #define __VALG_PLAT_H__
21
22 #include "hi_osal.h"
23
24 #include "hi_type.h"
25 #include "hi_errno.h"
26 #include "hi_debug.h"
27 #include "hi_board.h"
28
29 #include "hi_common.h"
30 #include "hi_comm_video.h"
31 #include "mm_ext.h"
32 #include "dev_ext.h"
33 #include "proc_ext.h"
34
35 #ifdef __KERNEL__
36 #else
37 #include <sys/time.h>
38 #endif
39
40 #ifdef __cplusplus
41 #if __cplusplus
42 extern "C" {
43 #endif
44 #endif
45
46 #define VALG_TRACE(level, mod_id, fmt, ...) \
47 do { \
48 HI_TRACE(level, mod_id, "[Func]:%s [Line]:%d [Info]:" fmt, __FUNCTION__, __LINE__, ##__VA_ARGS__); \
49 } while (0)
50 #define VALG_ERR_LEVEL_NOTE 0
51
52
53 typedef osal_spinlock_t valg_lock;
54 typedef unsigned long VALG_LOCK_FLAG;
55
56
valg_create_lock(valg_lock * lock,hi_bool locked)57 __inline static hi_s32 valg_create_lock(valg_lock *lock, hi_bool locked)
58 {
59 hi_unused(locked);
60 return osal_spin_lock_init(lock);
61 }
62
valg_lock_irqsave(valg_lock * lock,VALG_LOCK_FLAG * flag)63 __inline static hi_s32 valg_lock_irqsave(valg_lock *lock, VALG_LOCK_FLAG *flag)
64 {
65 osal_spin_lock_irqsave(lock, flag);
66 return HI_SUCCESS;
67 }
68
valg_unlock(valg_lock * lock,VALG_LOCK_FLAG * flag)69 __inline static hi_s32 valg_unlock(valg_lock *lock, VALG_LOCK_FLAG *flag)
70 {
71 osal_spin_unlock_irqrestore(lock, flag);
72 return HI_SUCCESS;
73 }
74
valg_delete_lock(valg_lock * lock)75 __inline static hi_void valg_delete_lock(valg_lock *lock)
76 {
77 osal_spin_lock_destroy(lock);
78 return;
79 }
80 #define forceinline __inline__ __attribute__((always_inline))
81
82 typedef osal_timer_t valg_timer;
83 typedef hi_void (*PTR_TIMER_CALLBACK)(unsigned long data);
84
valg_timer_init(valg_timer * ph_timer,PTR_TIMER_CALLBACK ptr_timer,hi_ulong ul_data)85 __inline static hi_s32 valg_timer_init(valg_timer *ph_timer, PTR_TIMER_CALLBACK ptr_timer, hi_ulong ul_data)
86 {
87 hi_s32 ret;
88
89 ret = osal_timer_init(ph_timer);
90 if (ret) {
91 return ret;
92 }
93
94 ph_timer->data = ul_data;
95 ph_timer->function = ptr_timer;
96 return HI_SUCCESS;
97 }
98
valg_timer_start_once(valg_timer * ph_timer,hi_ulong ul_interval)99 __inline static hi_s32 valg_timer_start_once(valg_timer *ph_timer, hi_ulong ul_interval)
100 {
101 return osal_set_timer(ph_timer, ul_interval);
102 }
103
valg_timer_delete(valg_timer * ph_timer)104 __inline static hi_void valg_timer_delete(valg_timer *ph_timer)
105 {
106 osal_del_timer(ph_timer);
107 osal_timer_destroy(ph_timer);
108
109 return;
110 }
111
valg_thread_init(osal_task_t ** thread,hi_void * task_function,hi_void * data,char * task_name)112 __inline static hi_s32 valg_thread_init(osal_task_t **thread, hi_void *task_function, hi_void *data, char *task_name)
113 {
114 *thread = osal_kthread_create(task_function, data, task_name);
115 if (*thread == NULL) {
116 osal_printk("create thread fail!!!\n");
117 return HI_FAILURE;
118 }
119
120 return HI_SUCCESS;
121 }
122
valg_thread_delete(osal_task_t * task,hi_bool stop_flag)123 __inline static hi_u32 valg_thread_delete(osal_task_t *task, hi_bool stop_flag)
124 {
125 osal_kthread_destroy(task, stop_flag);
126 return HI_SUCCESS;
127 }
128
129 typedef hi_u32 VALG_POOL_HANDLE;
130 typedef int irqreturn_t;
131 typedef osal_irq_handler_t PTR_INT_CALLBACK;
132
valg_irq_init(hi_s32 irq,PTR_INT_CALLBACK ptr_call_back,hi_void * data)133 __inline static hi_s32 valg_irq_init(hi_s32 irq, PTR_INT_CALLBACK ptr_call_back, hi_void *data)
134 {
135 return osal_request_irq(irq, ptr_call_back, NULL, "vedu", data);
136 }
137
valg_irq_delete(hi_s32 irq,void * dev_id)138 __inline static hi_s32 valg_irq_delete(hi_s32 irq, void *dev_id)
139 {
140 osal_free_irq(irq, dev_id);
141 return HI_SUCCESS;
142 }
143
get_sys_time_by_sec(void)144 __inline static hi_u64 get_sys_time_by_sec(void)
145 {
146 #ifdef __KERNEL__
147 osal_timeval_t time;
148 osal_gettimeofday(&time);
149 #else
150 struct timeval time;
151 gettimeofday(&time, NULL);
152 #endif
153 return (hi_u64)time.tv_sec;
154 }
155
get_sys_time_by_usec(void)156 __inline static hi_u64 get_sys_time_by_usec(void)
157 {
158 #ifdef __KERNEL__
159 osal_timeval_t time;
160 osal_gettimeofday(&time);
161 #else
162 struct timeval time;
163 gettimeofday(&time, NULL);
164 #endif
165 return (hi_u64)((time.tv_sec * 1000000LLU) + time.tv_usec);
166 }
167
168 #ifdef __cplusplus
169 #if __cplusplus
170 }
171 #endif
172 #endif
173
174 #endif /* __VALG_PLAT_H__ */
175