add RT_USING_POSIX_DELAY

This commit is contained in:
Meco Man 2021-11-07 21:03:16 -05:00
parent 910961c091
commit 2639171885
4 changed files with 46 additions and 38 deletions

View File

@ -53,6 +53,10 @@ if RT_USING_POSIX
select RT_USING_POSIX_POLL
default n
config RT_USING_POSIX_DELAY
bool "Enable delay functions"
default n
config RT_USING_POSIX_GETLINE
bool "Enable getline()/getdelim() APIs"
default n

View File

@ -1,7 +1,8 @@
from building import *
Import('rtconfig')
# RT-Thread building script for component
src = ['libc.c','delay.c','unistd.c']
from building import *
src = ['libc.c', 'unistd.c']
cwd = GetCurrentDir()
CPPPATH = [cwd]
@ -11,6 +12,9 @@ if GetDepend('RT_USING_POSIX_POLL'):
if GetDepend('RT_USING_POSIX_SELECT'):
src += ['select.c']
if GetDepend('RT_USING_POSIX_DELAY'):
src += ['delay.c']
group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX'], CPPPATH = CPPPATH)
Return('group')

View File

@ -48,3 +48,38 @@ void ndelay(unsigned long nsecs)
rt_hw_us_delay(1);
}
RTM_EXPORT(ndelay);
unsigned int sleep(unsigned int seconds)
{
if (rt_thread_self() != RT_NULL)
{
ssleep(seconds);
}
else /* scheduler has not run yet */
{
while(seconds > 0)
{
udelay(1000000u);
seconds --;
}
}
return 0;
}
RTM_EXPORT(sleep);
int usleep(useconds_t usec)
{
if (rt_thread_self() != RT_NULL)
{
msleep(usec / 1000u);
}
else /* scheduler has not run yet */
{
udelay(usec / 1000u);
}
udelay(usec % 1000u);
return 0;
}
RTM_EXPORT(usleep);

View File

@ -965,38 +965,3 @@ char *ttyname(int fd)
return "/dev/tty"; /* TODO: need to add more specific */
}
RTM_EXPORT(ttyname);
unsigned int sleep(unsigned int seconds)
{
if (rt_thread_self() != RT_NULL)
{
ssleep(seconds);
}
else /* scheduler has not run yet */
{
while(seconds > 0)
{
udelay(1000000u);
seconds --;
}
}
return 0;
}
RTM_EXPORT(sleep);
int usleep(useconds_t usec)
{
if (rt_thread_self() != RT_NULL)
{
msleep(usec / 1000u);
}
else /* scheduler has not run yet */
{
udelay(usec / 1000u);
}
udelay(usec % 1000u);
return 0;
}
RTM_EXPORT(usleep);