• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 Huawei Device Co., Ltd.
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 HOS_LITE_HIVIEW_UTIL_H
17 #define HOS_LITE_HIVIEW_UTIL_H
18 
19 #include <unistd.h>
20 #include "ohos_types.h"
21 
22 #ifdef __cplusplus
23 #if __cplusplus
24 extern "C" {
25 #endif
26 #endif /* End of #ifdef __cplusplus */
27 
28 /* The definition value is consistent with MEM_POOL_COMMON_ID. */
29 #define MEM_POOL_HIVIEW_ID     0
30 
31 #ifndef HIVIEW_SEEK_SET
32 #define HIVIEW_SEEK_SET 0
33 #endif
34 
35 #ifndef HIVIEW_SEEK_CUR
36 #define HIVIEW_SEEK_CUR 1
37 #endif
38 
39 #ifndef HIVIEW_SEEK_END
40 #define HIVIEW_SEEK_END 2
41 #endif
42 
43 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
44 #define LITTLE_ENDIAN_SYSTEM 1
45 #endif
46 
47 #define OPTION_MASK 0x07
48 #define GETOPTION(opt) ((opt) & OPTION_MASK)
49 
50 typedef void *HiviewMutexId_t;
51 
52 typedef struct {
53     uint8 minutes;
54     uint8 hour;
55     uint8 day;
56     uint8 month;
57     uint8 weekday;
58     uint8 seconds;
59     uint16 year;
60     uint16 millisecond;
61 } HIVIEW_RtcTime;
62 
63 typedef struct {
64     int (*open_fn)(const char *, int, ...);
65     int (*close_fn)(int);
66     ssize_t (*read_fn)(int, void *, size_t);
67     ssize_t (*write_fn)(int, const void *, size_t);
68     off_t (*lseek_fn)(int, off_t, int);
69     int (*fsync_fn)(int);
70     int (*unlink_fn)(const char *);
71     int (*rename_fn)(const char *, const char *);
72 } HIVIEW_Hooks;
73 
74 uint64 HIVIEW_GetCurrentTime(void);
75 int32 HIVIEW_RtcGetCurrentTime(uint64 *val, HIVIEW_RtcTime *time);
76 
77 void *HIVIEW_MemAlloc(uint8 modId, uint32 size);
78 void HIVIEW_MemFree(uint8 modId, void *pMem);
79 HiviewMutexId_t HIVIEW_MutexInit(void);
80 int32 HIVIEW_MutexLock(HiviewMutexId_t mutex);
81 int32 HIVIEW_MutexLockOrWait(HiviewMutexId_t mutex, uint32 timeout);
82 int32 HIVIEW_MutexUnlock(HiviewMutexId_t mutex);
83 uint32 HIVIEW_IntLock(void);
84 void HIVIEW_IntRestore(uint32 intSave);
85 uint32 HIVIEW_GetTaskId(void);
86 void HIVIEW_UartPrint(const char *str);
87 void HIVIEW_Sleep(uint32 ms);
88 
89 /* File system */
90 void HIVIEW_InitHook(HIVIEW_Hooks *hooks);
91 int32 HIVIEW_FileOpen(const char *path);
92 int32 HIVIEW_FileClose(int32 handle);
93 int32 HIVIEW_FileRead(int32 handle, uint8 *buf, uint32 len);
94 int32 HIVIEW_FileWrite(int32 handle, const uint8 *buf, uint32 len);
95 int32 HIVIEW_FileSeek(int32 handle, int32 offset, int32 whence);
96 int32 HIVIEW_FileSize(int32 handle);
97 int32 HIVIEW_FileSync(int32 handle);
98 int32 HIVIEW_FileUnlink(const char *path);
99 int32 HIVIEW_FileCopy(const char *src, const char *dest);
100 int32 HIVIEW_FileMove(const char *src, const char *dest);
101 
102 uint8 *HIVIEW_GetStackBegin(void);
103 uint32 HIVIEW_GetStackSize(void);
104 void HIVIEW_WatchDogSystemReset(void);
105 uint8 HIVIEW_WdgResetFlag(void);
106 
107 uint16 Change16Endian(uint16 num);
108 uint32 Change32Endian(uint32 num);
109 #ifdef __cplusplus
110 #if __cplusplus
111 }
112 #endif
113 #endif /* End of #ifdef __cplusplus */
114 
115 #endif /* End of #ifndef HOS_LITE_HIVIEW_UTIL_H */
116