unistd.c 990 字节
Newer Older
mysterywolf's avatar
mysterywolf 已提交
1 2 3 4 5 6 7
/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
8 9
 * 2020-09-01     Meco Man     first Version
 * 2021-02-12     Meco Man     move all functions located in <pthread_sleep.c> to this file
mysterywolf's avatar
mysterywolf 已提交
10 11 12
 */

#include <unistd.h>
13 14
#include <rtthread.h>
#include <rthw.h>
mysterywolf's avatar
mysterywolf 已提交
15 16

#ifdef RT_USING_POSIX_TERMIOS
17
#include "termios.h"
18

mysterywolf's avatar
mysterywolf 已提交
19 20 21 22 23 24 25 26 27 28 29
int isatty(int fd)
{
    struct termios ts;
    return(tcgetattr(fd,&ts) != -1);/*true if no error (is a tty)*/
}
#endif

char *ttyname(int fd)
{
    return "/dev/tty0"; /*TODO: need to add more specific*/
}
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

unsigned int sleep(unsigned int seconds)
{
    rt_tick_t delta_tick;

    delta_tick = rt_tick_get();
    rt_thread_delay(seconds * RT_TICK_PER_SECOND);
    delta_tick = rt_tick_get() - delta_tick;

    return seconds - delta_tick/RT_TICK_PER_SECOND;
}

int usleep(useconds_t usec)
{
    rt_thread_mdelay(usec / 1000u);
    rt_hw_us_delay(usec % 1000u);
    return 0;
}