更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
time_posix.h 文件参考

浏览源代码.

结构体

struct  ksigevent
 

函数

STATIC INLINE BOOL ValidTimeSpec (const struct timespec *tp)
 
STATIC INLINE UINT32 OsTimeSpec2Tick (const struct timespec *tp)
 
STATIC INLINE VOID OsTick2TimeSpec (struct timespec *tp, UINT32 tick)
 
int OsTimerCreate (clockid_t, struct ksigevent *__restrict, timer_t *__restrict)
 
void OsAdjTime (void)
 

函数说明

◆ OsAdjTime()

void OsAdjTime ( void  )

◆ OsTick2TimeSpec()

STATIC INLINE VOID OsTick2TimeSpec ( struct timespec *  tp,
UINT32  tick 
)

在文件 time_posix.h81 行定义.

82{
83 UINT64 ns = ((UINT64)tick * OS_SYS_NS_PER_SECOND) / LOSCFG_BASE_CORE_TICK_PER_SECOND;
84 tp->tv_sec = (time_t)(ns / OS_SYS_NS_PER_SECOND);
85 tp->tv_nsec = (long)(ns % OS_SYS_NS_PER_SECOND);
86}
long unsigned int UINT64
Definition: los_typedef.h:66
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 ARG_NUM_0 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_6 ARG_NUM_3 ARG_NUM_5 ARG_NUM_7 ARG_NUM_1 ARG_NUM_4 ARG_NUM_5 ARG_NUM_4 ARG_NUM_7 ARG_NUM_2 ARG_NUM_3 ARG_NUM_7 ARG_NUM_7 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_7 ARG_NUM_3 ARG_NUM_2 char ARG_NUM_2 ARG_NUM_1 ARG_NUM_0 ARG_NUM_0 ARG_NUM_3 void ARG_NUM_1 ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_2 ARG_NUM_3 ARG_NUM_2 ARG_NUM_5 ARG_NUM_3 ARG_NUM_3 ARG_NUM_4 ARG_NUM_1 ARG_NUM_1 ARG_NUM_3 ARG_NUM_2 ARG_NUM_1 ARG_NUM_4 ARG_NUM_4 ARG_NUM_5 ARG_NUM_3 ARG_NUM_2 void ARG_NUM_6 unsigned ARG_NUM_0 unsigned ARG_NUM_0 ARG_NUM_3 ARG_NUM_3 ARG_NUM_2 ARG_NUM_2 ARG_NUM_1 ARG_NUM_2 ARG_NUM_1 char ARG_NUM_0 ARG_NUM_4 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_4 ARG_NUM_5 ARG_NUM_2 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_3 ARG_NUM_6 ARG_NUM_6 ARG_NUM_5 ARG_NUM_3 void ARG_NUM_3 ARG_NUM_3 ARG_NUM_5 ARG_NUM_1 unsigned ARG_NUM_3 long
这是这个函数的调用关系图:

◆ OsTimerCreate()

int OsTimerCreate ( clockid_t  clockID,
struct ksigevent __restrict,
timer_t *  __restrict 
)

在文件 time.c842 行定义.

843{
844 UINT32 ret;
845 UINT16 swtmrID;
846 swtmr_proc_arg *arg = NULL;
847 int signo;
848#ifdef LOSCFG_SECURITY_VID
849 UINT16 vid;
850#endif
851
852 if ((clockID != CLOCK_REALTIME) || (timerID == NULL)) {
853 errno = EINVAL;
854 return -1;
855 }
856
857 signo = evp ? evp->sigev_signo : SIGALRM;
858 if (signo > SIGRTMAX || signo < 1) {
859 errno = EINVAL;
860 return -1;
861 }
862 if (evp && (evp->sigev_notify != SIGEV_SIGNAL && evp->sigev_notify != SIGEV_THREAD_ID)) {
863 errno = ENOTSUP;
864 return -1;
865 }
866
867 arg = (swtmr_proc_arg *)malloc(sizeof(swtmr_proc_arg));
868 if (arg == NULL) {
869 errno = ENOMEM;
870 return -1;
871 }
872
873 arg->tid = evp ? evp->sigev_tid : 0;
874 arg->sigev_signo = signo;
875 arg->pid = LOS_GetCurrProcessID();
876 arg->sigev_value.sival_ptr = evp ? evp->sigev_value.sival_ptr : NULL;
877 ret = LOS_SwtmrCreate(1, LOS_SWTMR_MODE_ONCE, SwtmrProc, &swtmrID, (UINTPTR)arg);
878 if (ret != LOS_OK) {
879 errno = (ret == LOS_ERRNO_SWTMR_MAXSIZE) ? EAGAIN : EINVAL;
880 free(arg);
881 return -1;
882 }
883
884#ifdef LOSCFG_SECURITY_VID
885 vid = AddNodeByRid(swtmrID);
886 if (vid == MAX_INVALID_TIMER_VID) {
887 free(arg);
888 (VOID)LOS_SwtmrDelete(swtmrID);
889 return -1;
890 }
891 swtmrID = vid;
892#endif
893 *timerID = (timer_t)(UINTPTR)swtmrID;
894 return 0;
895}
LITE_OS_SEC_TEXT UINT32 LOS_SwtmrDelete(UINT16 swtmrID)
接口函数 删除定时器
Definition: los_swtmr.c:889
LITE_OS_SEC_TEXT_INIT UINT32 LOS_SwtmrCreate(UINT32 interval, UINT8 mode, SWTMR_PROC_FUNC handler, UINT16 *swtmrID, UINTPTR arg)
创建定时器,设置定时器的定时时长、定时器模式、回调函数,并返回定时器ID
Definition: los_swtmr.c:712
@ LOS_SWTMR_MODE_ONCE
Definition: los_swtmr.h:232
LITE_OS_SEC_TEXT UINT32 LOS_GetCurrProcessID(VOID)
获取当前进程的进程ID
Definition: los_process.c:2161
unsigned short UINT16
Definition: los_typedef.h:56
unsigned long UINTPTR
Definition: los_typedef.h:68
unsigned int UINT32
Definition: los_typedef.h:57
void * malloc(size_t size)
动态分配内存块大小
Definition: malloc.c:81
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
union sigval sigev_value
Definition: time.c:752
unsigned int tid
Definition: time.c:751
pid_t pid
Definition: time.c:750
int sigev_signo
Definition: time.c:749
static VOID SwtmrProc(UINTPTR tmrArg)
Definition: time.c:755
UINT16 AddNodeByRid(UINT16 rid)
Definition: vid.c:178
函数调用图:
这是这个函数的调用关系图:

◆ OsTimeSpec2Tick()

STATIC INLINE UINT32 OsTimeSpec2Tick ( const struct timespec *  tp)

在文件 time_posix.h68 行定义.

69{
70 UINT64 tick, ns;
71
72 ns = (UINT64)tp->tv_sec * OS_SYS_NS_PER_SECOND + tp->tv_nsec;
73 /* Round up for ticks */
74 tick = (ns * LOSCFG_BASE_CORE_TICK_PER_SECOND + (OS_SYS_NS_PER_SECOND - 1)) / OS_SYS_NS_PER_SECOND;
75 if (tick > LOS_WAIT_FOREVER) {
76 tick = LOS_WAIT_FOREVER;
77 }
78 return (UINT32)tick;
79}
这是这个函数的调用关系图:

◆ ValidTimeSpec()

STATIC INLINE BOOL ValidTimeSpec ( const struct timespec *  tp)

在文件 time_posix.h53 行定义.

54{
55 /* Fail a NULL pointer */
56 if (tp == NULL) {
57 return FALSE;
58 }
59
60 /* Fail illegal nanosecond values */
61 if ((tp->tv_nsec < 0) || (tp->tv_nsec >= OS_SYS_NS_PER_SECOND) || (tp->tv_sec < 0)) {
62 return FALSE;
63 }
64
65 return TRUE;
66}
这是这个函数的调用关系图: