16f2c2defSopenharmony_ci/*
26f2c2defSopenharmony_ci * Copyright (c) 2020 Huawei Device Co., Ltd.
36f2c2defSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
46f2c2defSopenharmony_ci * you may not use this file except in compliance with the License.
56f2c2defSopenharmony_ci * You may obtain a copy of the License at
66f2c2defSopenharmony_ci *
76f2c2defSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
86f2c2defSopenharmony_ci *
96f2c2defSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
106f2c2defSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
116f2c2defSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
126f2c2defSopenharmony_ci * See the License for the specific language governing permissions and
136f2c2defSopenharmony_ci * limitations under the License.
146f2c2defSopenharmony_ci */
156f2c2defSopenharmony_ci
166f2c2defSopenharmony_ci#ifndef HOS_LITE_HIVIEW_UTIL_H
176f2c2defSopenharmony_ci#define HOS_LITE_HIVIEW_UTIL_H
186f2c2defSopenharmony_ci
196f2c2defSopenharmony_ci#include <unistd.h>
206f2c2defSopenharmony_ci#include "ohos_types.h"
216f2c2defSopenharmony_ci
226f2c2defSopenharmony_ci#ifdef __cplusplus
236f2c2defSopenharmony_ci#if __cplusplus
246f2c2defSopenharmony_ciextern "C" {
256f2c2defSopenharmony_ci#endif
266f2c2defSopenharmony_ci#endif /* End of #ifdef __cplusplus */
276f2c2defSopenharmony_ci
286f2c2defSopenharmony_ci/* The definition value is consistent with MEM_POOL_COMMON_ID. */
296f2c2defSopenharmony_ci#define MEM_POOL_HIVIEW_ID     0
306f2c2defSopenharmony_ci
316f2c2defSopenharmony_ci#ifndef HIVIEW_SEEK_SET
326f2c2defSopenharmony_ci#define HIVIEW_SEEK_SET 0
336f2c2defSopenharmony_ci#endif
346f2c2defSopenharmony_ci
356f2c2defSopenharmony_ci#ifndef HIVIEW_SEEK_CUR
366f2c2defSopenharmony_ci#define HIVIEW_SEEK_CUR 1
376f2c2defSopenharmony_ci#endif
386f2c2defSopenharmony_ci
396f2c2defSopenharmony_ci#ifndef HIVIEW_SEEK_END
406f2c2defSopenharmony_ci#define HIVIEW_SEEK_END 2
416f2c2defSopenharmony_ci#endif
426f2c2defSopenharmony_ci
436f2c2defSopenharmony_ci#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
446f2c2defSopenharmony_ci#define LITTLE_ENDIAN_SYSTEM 1
456f2c2defSopenharmony_ci#endif
466f2c2defSopenharmony_ci
476f2c2defSopenharmony_ci#define OPTION_MASK 0x07
486f2c2defSopenharmony_ci#define GETOPTION(opt) ((opt) & OPTION_MASK)
496f2c2defSopenharmony_ci
506f2c2defSopenharmony_citypedef void *HiviewMutexId_t;
516f2c2defSopenharmony_ci
526f2c2defSopenharmony_citypedef struct {
536f2c2defSopenharmony_ci    uint8 minutes;
546f2c2defSopenharmony_ci    uint8 hour;
556f2c2defSopenharmony_ci    uint8 day;
566f2c2defSopenharmony_ci    uint8 month;
576f2c2defSopenharmony_ci    uint8 weekday;
586f2c2defSopenharmony_ci    uint8 seconds;
596f2c2defSopenharmony_ci    uint16 year;
606f2c2defSopenharmony_ci    uint16 millisecond;
616f2c2defSopenharmony_ci} HIVIEW_RtcTime;
626f2c2defSopenharmony_ci
636f2c2defSopenharmony_citypedef struct {
646f2c2defSopenharmony_ci    int (*open_fn)(const char *, int, ...);
656f2c2defSopenharmony_ci    int (*close_fn)(int);
666f2c2defSopenharmony_ci    ssize_t (*read_fn)(int, void *, size_t);
676f2c2defSopenharmony_ci    ssize_t (*write_fn)(int, const void *, size_t);
686f2c2defSopenharmony_ci    off_t (*lseek_fn)(int, off_t, int);
696f2c2defSopenharmony_ci    int (*fsync_fn)(int);
706f2c2defSopenharmony_ci    int (*unlink_fn)(const char *);
716f2c2defSopenharmony_ci    int (*rename_fn)(const char *, const char *);
726f2c2defSopenharmony_ci} HIVIEW_Hooks;
736f2c2defSopenharmony_ci
746f2c2defSopenharmony_ciuint64 HIVIEW_GetCurrentTime(void);
756f2c2defSopenharmony_ciint32 HIVIEW_RtcGetCurrentTime(uint64 *val, HIVIEW_RtcTime *time);
766f2c2defSopenharmony_ci
776f2c2defSopenharmony_civoid *HIVIEW_MemAlloc(uint8 modId, uint32 size);
786f2c2defSopenharmony_civoid HIVIEW_MemFree(uint8 modId, void *pMem);
796f2c2defSopenharmony_ciHiviewMutexId_t HIVIEW_MutexInit(void);
806f2c2defSopenharmony_ciint32 HIVIEW_MutexLock(HiviewMutexId_t mutex);
816f2c2defSopenharmony_ciint32 HIVIEW_MutexLockOrWait(HiviewMutexId_t mutex, uint32 timeout);
826f2c2defSopenharmony_ciint32 HIVIEW_MutexUnlock(HiviewMutexId_t mutex);
836f2c2defSopenharmony_ciuint32 HIVIEW_IntLock(void);
846f2c2defSopenharmony_civoid HIVIEW_IntRestore(uint32 intSave);
856f2c2defSopenharmony_ciuint32 HIVIEW_GetTaskId(void);
866f2c2defSopenharmony_civoid HIVIEW_UartPrint(const char *str);
876f2c2defSopenharmony_civoid HIVIEW_Sleep(uint32 ms);
886f2c2defSopenharmony_ci
896f2c2defSopenharmony_ci/* File system */
906f2c2defSopenharmony_civoid HIVIEW_InitHook(HIVIEW_Hooks *hooks);
916f2c2defSopenharmony_ciint32 HIVIEW_FileOpen(const char *path);
926f2c2defSopenharmony_ciint32 HIVIEW_FileClose(int32 handle);
936f2c2defSopenharmony_ciint32 HIVIEW_FileRead(int32 handle, uint8 *buf, uint32 len);
946f2c2defSopenharmony_ciint32 HIVIEW_FileWrite(int32 handle, const uint8 *buf, uint32 len);
956f2c2defSopenharmony_ciint32 HIVIEW_FileSeek(int32 handle, int32 offset, int32 whence);
966f2c2defSopenharmony_ciint32 HIVIEW_FileSize(int32 handle);
976f2c2defSopenharmony_ciint32 HIVIEW_FileSync(int32 handle);
986f2c2defSopenharmony_ciint32 HIVIEW_FileUnlink(const char *path);
996f2c2defSopenharmony_ciint32 HIVIEW_FileCopy(const char *src, const char *dest);
1006f2c2defSopenharmony_ciint32 HIVIEW_FileMove(const char *src, const char *dest);
1016f2c2defSopenharmony_ci
1026f2c2defSopenharmony_ciuint8 *HIVIEW_GetStackBegin(void);
1036f2c2defSopenharmony_ciuint32 HIVIEW_GetStackSize(void);
1046f2c2defSopenharmony_civoid HIVIEW_WatchDogSystemReset(void);
1056f2c2defSopenharmony_ciuint8 HIVIEW_WdgResetFlag(void);
1066f2c2defSopenharmony_ci
1076f2c2defSopenharmony_ciuint16 Change16Endian(uint16 num);
1086f2c2defSopenharmony_ciuint32 Change32Endian(uint32 num);
1096f2c2defSopenharmony_ci#ifdef __cplusplus
1106f2c2defSopenharmony_ci#if __cplusplus
1116f2c2defSopenharmony_ci}
1126f2c2defSopenharmony_ci#endif
1136f2c2defSopenharmony_ci#endif /* End of #ifdef __cplusplus */
1146f2c2defSopenharmony_ci
1156f2c2defSopenharmony_ci#endif /* End of #ifndef HOS_LITE_HIVIEW_UTIL_H */
116