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 #include "hdmi_product_define.h" /* because of refined warning, hdmi_product_define.h go first. */
19 #include "hdmi_osal.h"
20 #include "hi_osal.h"
21
22 #define HDMI_MILLION 1000000
23
hdmi_osal_file_open(const hi_char * file_name,osal_file_flag e_flags)24 struct file *hdmi_osal_file_open(const hi_char *file_name, osal_file_flag e_flags)
25 {
26 struct file *file = NULL;
27
28 if (file_name == HI_NULL) {
29 return HI_NULL;
30 }
31
32 e_flags = OSAL_O_RDWR | OSAL_O_CREAT;
33 file = osal_klib_fopen(file_name, e_flags, HDMI_FILE_MODE);
34
35 return file;
36 }
37
hdmi_osal_file_close(struct file * file)38 hi_void hdmi_osal_file_close(struct file *file)
39 {
40 if (file != HI_NULL) {
41 osal_klib_fclose(file);
42 }
43 return;
44 }
45
hdmi_osal_file_read(struct file * file,hi_char * buf,hi_u32 len)46 hi_s32 hdmi_osal_file_read(struct file *file, hi_char *buf, hi_u32 len)
47 {
48 hi_s32 read_len;
49
50 if (buf == HI_NULL) {
51 return HI_SUCCESS;
52 }
53 read_len = osal_klib_fread(buf, len, file);
54
55 return read_len;
56 }
57
hdmi_osal_file_write(struct file * file,hi_char * buf,hi_u32 len)58 hi_s32 hdmi_osal_file_write(struct file *file, hi_char *buf, hi_u32 len)
59 {
60 hi_s32 write_len;
61
62 if (buf == HI_NULL) {
63 return HI_SUCCESS;
64 }
65 write_len = osal_klib_fwrite(buf, len, file);
66
67 return write_len;
68 }
69
hdmi_osal_get_time_in_ms(hi_void)70 hi_u32 hdmi_osal_get_time_in_ms(hi_void)
71 {
72 hi_u64 sys_time;
73 sys_time = osal_div_u64(osal_sched_clock(), HDMI_MILLION);
74 return (hi_u32)sys_time;
75 }
76
hdmi_osal_get_time_in_us(hi_void)77 hi_u64 hdmi_osal_get_time_in_us(hi_void)
78 {
79 hi_u64 curr_us;
80 osal_timeval_t current_time = {0};
81
82 osal_gettimeofday(¤t_time);
83 curr_us = ((hi_u64)current_time.tv_sec * HDMI_MILLION + current_time.tv_usec);
84
85 return curr_us;
86 }
87
88