初始提交
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
from building import *
|
||||
Import('rtconfig')
|
||||
|
||||
src = Glob('*.c') + Glob('*.cpp')
|
||||
cwd = GetCurrentDir()
|
||||
group = []
|
||||
|
||||
CPPPATH = [cwd]
|
||||
CPPDEFINES = ['RT_USING_ARM_LIBC']
|
||||
|
||||
if GetDepend('RT_USING_DFS') == False:
|
||||
SrcRemove(src, ['stdio.c'])
|
||||
|
||||
if GetDepend('RT_USING_MODULE') == False:
|
||||
SrcRemove(src, ['libc_syms.c'])
|
||||
|
||||
if rtconfig.PLATFORM == 'armcc':
|
||||
group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
|
||||
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef __RTT_DIRENT_H__
|
||||
#define __RTT_DIRENT_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtlibc.h>
|
||||
|
||||
/*
|
||||
* dirent.h - format of directory entries
|
||||
* Ref: http://www.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
|
||||
*/
|
||||
|
||||
/* File types */
|
||||
#define FT_REGULAR 0 /* regular file */
|
||||
#define FT_SOCKET 1 /* socket file */
|
||||
#define FT_DIRECTORY 2 /* directory */
|
||||
#define FT_USER 3 /* user defined */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DIR_STRUCTURE
|
||||
typedef struct
|
||||
{
|
||||
int fd; /* directory file */
|
||||
char buf[512];
|
||||
int num;
|
||||
int cur;
|
||||
} DIR;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_DIRENT_STRUCTURE
|
||||
struct dirent
|
||||
{
|
||||
rt_uint8_t d_type; /* The type of the file */
|
||||
rt_uint8_t d_namlen; /* The length of the not including the terminating null file name */
|
||||
rt_uint16_t d_reclen; /* length of this record */
|
||||
char d_name[256]; /* The null-terminated file name */
|
||||
};
|
||||
#endif
|
||||
|
||||
int closedir(DIR *);
|
||||
DIR *opendir(const char *);
|
||||
struct dirent *readdir(DIR *);
|
||||
int readdir_r(DIR *, struct dirent *, struct dirent **);
|
||||
void rewinddir(DIR *);
|
||||
void seekdir(DIR *, long int);
|
||||
long telldir(DIR *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef FCNTL_H__
|
||||
#define FCNTL_H__
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
#include <dfs_posix.h>
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017/10/15 bernard the first version
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "libc.h"
|
||||
|
||||
#ifdef RT_USING_PTHREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
int libc_system_init(void)
|
||||
{
|
||||
#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS)
|
||||
rt_device_t dev_console;
|
||||
|
||||
dev_console = rt_console_get_device();
|
||||
if (dev_console)
|
||||
{
|
||||
#if defined(RT_USING_POSIX)
|
||||
libc_stdio_set_console(dev_console->parent.name, O_RDWR);
|
||||
#else
|
||||
libc_stdio_set_console(dev_console->parent.name, O_WRONLY);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
|
||||
pthread_system_init();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
INIT_COMPONENT_EXPORT(libc_system_init);
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017/10/15 bernard the first version
|
||||
*/
|
||||
#ifndef __RTT_LIBC_H__
|
||||
#define __RTT_LIBC_H__
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
int libc_system_init(void);
|
||||
|
||||
int libc_stdio_set_console(const char* device_name, int mode);
|
||||
int libc_stdio_get_console(void);
|
||||
int libc_stdio_read (void *buffer, size_t size);
|
||||
int libc_stdio_write(const void *buffer, size_t size);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <rtm.h>
|
||||
|
||||
/* some export routines for module */
|
||||
|
||||
RTM_EXPORT(strstr);
|
||||
RTM_EXPORT(strlen);
|
||||
RTM_EXPORT(strchr);
|
||||
RTM_EXPORT(strcpy);
|
||||
RTM_EXPORT(strncpy);
|
||||
RTM_EXPORT(strcmp);
|
||||
RTM_EXPORT(strncmp);
|
||||
RTM_EXPORT(strcat);
|
||||
RTM_EXPORT(strtol);
|
||||
|
||||
RTM_EXPORT(memcpy);
|
||||
RTM_EXPORT(memcmp);
|
||||
RTM_EXPORT(memmove);
|
||||
RTM_EXPORT(memset);
|
||||
RTM_EXPORT(memchr);
|
||||
|
||||
RTM_EXPORT(toupper);
|
||||
RTM_EXPORT(atoi);
|
||||
|
||||
#ifdef RT_USING_RTC
|
||||
RTM_EXPORT(localtime);
|
||||
RTM_EXPORT(time);
|
||||
#endif
|
||||
|
||||
/* import the full stdio for printf */
|
||||
#if defined(RT_USING_MODULE) && defined(__MICROLIB)
|
||||
#error "[RT_USING_LIBC] Please use standard libc but not microlib."
|
||||
#endif
|
||||
|
||||
RTM_EXPORT(puts);
|
||||
RTM_EXPORT(printf);
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* 2014-08-03 bernard Add file header.
|
||||
*/
|
||||
|
||||
#include "rtthread.h"
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
|
||||
#ifdef __CC_ARM
|
||||
/* avoid the heap and heap-using library functions supplied by arm */
|
||||
#pragma import(__use_no_heap)
|
||||
#endif
|
||||
|
||||
void *malloc(size_t n)
|
||||
{
|
||||
return rt_malloc(n);
|
||||
}
|
||||
RTM_EXPORT(malloc);
|
||||
|
||||
void *realloc(void *rmem, size_t newsize)
|
||||
{
|
||||
return rt_realloc(rmem, newsize);
|
||||
}
|
||||
RTM_EXPORT(realloc);
|
||||
|
||||
void *calloc(size_t nelem, size_t elsize)
|
||||
{
|
||||
return rt_calloc(nelem, elsize);
|
||||
}
|
||||
RTM_EXPORT(calloc);
|
||||
|
||||
void free(void *rmem)
|
||||
{
|
||||
rt_free(rmem);
|
||||
}
|
||||
RTM_EXPORT(free);
|
||||
#endif
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017/10/15 bernard implement stdio for armcc.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "libc.h"
|
||||
|
||||
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS)
|
||||
#include <dfs_posix.h>
|
||||
|
||||
#define STDIO_DEVICE_NAME_MAX 32
|
||||
|
||||
static int std_fd = -1;
|
||||
int libc_stdio_set_console(const char* device_name, int mode)
|
||||
{
|
||||
int fd;
|
||||
char name[STDIO_DEVICE_NAME_MAX];
|
||||
|
||||
snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
|
||||
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
|
||||
|
||||
fd = open(name, mode, 0);
|
||||
if (fd >= 0)
|
||||
{
|
||||
if (std_fd >= 0)
|
||||
{
|
||||
close(std_fd);
|
||||
}
|
||||
std_fd = fd;
|
||||
}
|
||||
|
||||
return std_fd;
|
||||
}
|
||||
|
||||
int libc_stdio_get_console(void)
|
||||
{
|
||||
return std_fd;
|
||||
}
|
||||
|
||||
int libc_stdio_read(void *buffer, size_t size)
|
||||
{
|
||||
if (std_fd >= 0)
|
||||
{
|
||||
return read(std_fd, buffer, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("Illegal stdio input!\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int libc_stdio_write(const void *buffer, size_t size)
|
||||
{
|
||||
if (std_fd >= 0)
|
||||
{
|
||||
return write(std_fd, buffer, size);
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("Illegal stdio output!\n");
|
||||
return size;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
331
Project/Src/rt-thread/components/libc/compilers/armlibc/stubs.c
Normal file
331
Project/Src/rt-thread/components/libc/compilers/armlibc/stubs.c
Normal file
@@ -0,0 +1,331 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2012-11-23 Yihui The first version
|
||||
* 2013-11-24 aozima fixed _sys_read()/_sys_write() issues.
|
||||
* 2014-08-03 bernard If using msh, use system() implementation
|
||||
* in msh.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <rt_sys.h>
|
||||
|
||||
#include "rtthread.h"
|
||||
#include "libc.h"
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
#include "dfs_posix.h"
|
||||
#endif
|
||||
|
||||
#ifdef __CLANG_ARM
|
||||
__asm(".global __use_no_semihosting\n\t");
|
||||
#else
|
||||
#pragma import(__use_no_semihosting_swi)
|
||||
#endif
|
||||
|
||||
/* Standard IO device handles. */
|
||||
#define STDIN 0
|
||||
#define STDOUT 1
|
||||
#define STDERR 2
|
||||
|
||||
/* Standard IO device name defines. */
|
||||
const char __stdin_name[] = "STDIN";
|
||||
const char __stdout_name[] = "STDOUT";
|
||||
const char __stderr_name[] = "STDERR";
|
||||
|
||||
/**
|
||||
* required by fopen() and freopen().
|
||||
*
|
||||
* @param name - file name with path.
|
||||
* @param openmode - a bitmap hose bits mostly correspond directly to
|
||||
* the ISO mode specification.
|
||||
* @return -1 if an error occurs.
|
||||
*/
|
||||
FILEHANDLE _sys_open(const char *name, int openmode)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
int fd;
|
||||
int mode = O_RDONLY;
|
||||
#endif
|
||||
|
||||
/* Register standard Input Output devices. */
|
||||
if (strcmp(name, __stdin_name) == 0)
|
||||
return (STDIN);
|
||||
if (strcmp(name, __stdout_name) == 0)
|
||||
return (STDOUT);
|
||||
if (strcmp(name, __stderr_name) == 0)
|
||||
return (STDERR);
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return -1;
|
||||
#else
|
||||
/* Correct openmode from fopen to open */
|
||||
if (openmode & OPEN_PLUS)
|
||||
{
|
||||
if (openmode & OPEN_W)
|
||||
{
|
||||
mode |= (O_RDWR | O_TRUNC | O_CREAT);
|
||||
}
|
||||
else if (openmode & OPEN_A)
|
||||
{
|
||||
mode |= (O_RDWR | O_APPEND | O_CREAT);
|
||||
}
|
||||
else
|
||||
mode |= O_RDWR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (openmode & OPEN_W)
|
||||
{
|
||||
mode |= (O_WRONLY | O_TRUNC | O_CREAT);
|
||||
}
|
||||
else if (openmode & OPEN_A)
|
||||
{
|
||||
mode |= (O_WRONLY | O_APPEND | O_CREAT);
|
||||
}
|
||||
}
|
||||
|
||||
fd = open(name, mode, 0);
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
else
|
||||
return fd;
|
||||
#endif
|
||||
}
|
||||
|
||||
int _sys_close(FILEHANDLE fh)
|
||||
{
|
||||
#ifndef RT_USING_DFS
|
||||
return 0;
|
||||
#else
|
||||
if (fh <= STDERR) return 0;
|
||||
|
||||
return close(fh);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Read from a file. Can return:
|
||||
* - zero if the read was completely successful
|
||||
* - the number of bytes _not_ read, if the read was partially successful
|
||||
* - the number of bytes not read, plus the top bit set (0x80000000), if
|
||||
* the read was partially successful due to end of file
|
||||
* - -1 if some error other than EOF occurred
|
||||
*
|
||||
* It is also legal to signal EOF by returning no data but
|
||||
* signalling no error (i.e. the top-bit-set mechanism need never
|
||||
* be used).
|
||||
*
|
||||
* So if (for example) the user is trying to read 8 bytes at a time
|
||||
* from a file in which only 5 remain, this routine can do three
|
||||
* equally valid things:
|
||||
*
|
||||
* - it can return 0x80000003 (3 bytes not read due to EOF)
|
||||
* - OR it can return 3 (3 bytes not read), and then return
|
||||
* 0x80000008 (8 bytes not read due to EOF) on the next attempt
|
||||
* - OR it can return 3 (3 bytes not read), and then return
|
||||
* 8 (8 bytes not read, meaning 0 read, meaning EOF) on the next
|
||||
* attempt
|
||||
*
|
||||
* `mode' exists for historical reasons and must be ignored.
|
||||
*/
|
||||
int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
int size;
|
||||
#endif
|
||||
|
||||
if (fh == STDIN)
|
||||
{
|
||||
#ifdef RT_USING_POSIX
|
||||
size = libc_stdio_read(buf, len);
|
||||
return len - size;
|
||||
#else
|
||||
/* no stdin */
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((fh == STDOUT) || (fh == STDERR))
|
||||
return -1;
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return 0;
|
||||
#else
|
||||
size = read(fh, buf, len);
|
||||
if (size >= 0)
|
||||
return len - size;
|
||||
else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Write to a file. Returns 0 on success, negative on error, and
|
||||
* the number of characters _not_ written on partial success.
|
||||
* `mode' exists for historical reasons and must be ignored.
|
||||
*/
|
||||
int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode)
|
||||
{
|
||||
#ifdef RT_USING_DFS
|
||||
int size;
|
||||
#endif
|
||||
|
||||
if ((fh == STDOUT) || (fh == STDERR))
|
||||
{
|
||||
#if !defined(RT_USING_CONSOLE) || !defined(RT_USING_DEVICE)
|
||||
return 0;
|
||||
#else
|
||||
#ifdef RT_USING_POSIX
|
||||
size = libc_stdio_write(buf, len);
|
||||
return len - size;
|
||||
#else
|
||||
if (rt_console_get_device())
|
||||
{
|
||||
rt_device_write(rt_console_get_device(), -1, buf, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
if (fh == STDIN) return -1;
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return 0;
|
||||
#else
|
||||
size = write(fh, buf, len);
|
||||
if (size >= 0)
|
||||
return len - size;
|
||||
else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Move the file position to a given offset from the file start.
|
||||
* Returns >=0 on success, <0 on failure.
|
||||
*/
|
||||
int _sys_seek(FILEHANDLE fh, long pos)
|
||||
{
|
||||
if (fh < STDERR)
|
||||
return -1;
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return -1;
|
||||
#else
|
||||
|
||||
/* position is relative to the start of file fh */
|
||||
return lseek(fh, pos, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* used by tmpnam() or tmpfile()
|
||||
*/
|
||||
int _sys_tmpnam(char *name, int fileno, unsigned maxlength)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *_sys_command_string(char *cmd, int len)
|
||||
{
|
||||
/* no support */
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
/* This function writes a character to the console. */
|
||||
void _ttywrch(int ch)
|
||||
{
|
||||
#ifdef RT_USING_CONSOLE
|
||||
char c;
|
||||
|
||||
c = (char)ch;
|
||||
rt_kprintf(&c);
|
||||
#endif
|
||||
}
|
||||
|
||||
void _sys_exit(int return_code)
|
||||
{
|
||||
/* TODO: perhaps exit the thread which is invoking this function */
|
||||
while (1);
|
||||
}
|
||||
|
||||
/**
|
||||
* return current length of file.
|
||||
*
|
||||
* @param fh - file handle
|
||||
* @return file length, or -1 on failed
|
||||
*/
|
||||
long _sys_flen(FILEHANDLE fh)
|
||||
{
|
||||
struct stat stat;
|
||||
|
||||
if (fh < STDERR)
|
||||
return -1;
|
||||
|
||||
#ifndef RT_USING_DFS
|
||||
return -1;
|
||||
#else
|
||||
fstat(fh, &stat);
|
||||
return stat.st_size;
|
||||
#endif
|
||||
}
|
||||
|
||||
int _sys_istty(FILEHANDLE fh)
|
||||
{
|
||||
if((STDIN <= fh) && (fh <= STDERR))
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int remove(const char *filename)
|
||||
{
|
||||
#ifndef RT_USING_DFS
|
||||
return -1;
|
||||
#else
|
||||
return unlink(filename);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(RT_USING_FINSH) && defined(FINSH_USING_MSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS)
|
||||
/* use system(const char *string) implementation in the msh */
|
||||
#else
|
||||
int system(const char *string)
|
||||
{
|
||||
RT_ASSERT(0);
|
||||
for (;;);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __MICROLIB
|
||||
#include <stdio.h>
|
||||
|
||||
int fputc(int c, FILE *f)
|
||||
{
|
||||
char ch[2] = {0};
|
||||
|
||||
ch[0] = c;
|
||||
rt_kprintf(&ch[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fgetc(FILE *f)
|
||||
{
|
||||
#ifdef RT_USING_POSIX
|
||||
char ch;
|
||||
|
||||
if (libc_stdio_read(&ch, 1) == 1)
|
||||
return ch;
|
||||
#endif
|
||||
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1 @@
|
||||
Because Keil MDK leaks some system header file, we put them in here.
|
||||
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef SYS_ERRNO_H__
|
||||
#define SYS_ERRNO_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
//#include "libc_ioctl.h"
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017/11/30 Bernard The first version.
|
||||
*/
|
||||
|
||||
#ifndef _SYS_MMAN_H
|
||||
#define _SYS_MMAN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define MAP_FAILED ((void *) -1)
|
||||
|
||||
#define MAP_SHARED 0x01
|
||||
#define MAP_PRIVATE 0x02
|
||||
#define MAP_TYPE 0x0f
|
||||
#define MAP_FIXED 0x10
|
||||
#define MAP_ANON 0x20
|
||||
#define MAP_ANONYMOUS MAP_ANON
|
||||
#define MAP_NORESERVE 0x4000
|
||||
#define MAP_GROWSDOWN 0x0100
|
||||
#define MAP_DENYWRITE 0x0800
|
||||
#define MAP_EXECUTABLE 0x1000
|
||||
#define MAP_LOCKED 0x2000
|
||||
#define MAP_POPULATE 0x8000
|
||||
#define MAP_NONBLOCK 0x10000
|
||||
#define MAP_STACK 0x20000
|
||||
#define MAP_HUGETLB 0x40000
|
||||
#define MAP_FILE 0
|
||||
|
||||
#define PROT_NONE 0
|
||||
#define PROT_READ 1
|
||||
#define PROT_WRITE 2
|
||||
#define PROT_EXEC 4
|
||||
#define PROT_GROWSDOWN 0x01000000
|
||||
#define PROT_GROWSUP 0x02000000
|
||||
|
||||
#define MS_ASYNC 1
|
||||
#define MS_INVALIDATE 2
|
||||
#define MS_SYNC 4
|
||||
|
||||
#define MCL_CURRENT 1
|
||||
#define MCL_FUTURE 2
|
||||
#define MCL_ONFAULT 4
|
||||
|
||||
void *mmap (void *start, size_t len, int prot, int flags, int fd, off_t off);
|
||||
int munmap (void *start, size_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef _SYS_TIME_H_
|
||||
#define _SYS_TIME_H_
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef _TIMEVAL_DEFINED
|
||||
#define _TIMEVAL_DEFINED
|
||||
/*
|
||||
* Structure returned by gettimeofday(2) system call,
|
||||
* and used in other calls.
|
||||
*/
|
||||
struct timeval {
|
||||
long tv_sec; /* seconds */
|
||||
long tv_usec; /* and microseconds */
|
||||
};
|
||||
#endif /* _TIMEVAL_DEFINED */
|
||||
|
||||
#ifndef _TIMESPEC_DEFINED
|
||||
#define _TIMESPEC_DEFINED
|
||||
/*
|
||||
* Structure defined by POSIX.1b to be like a timeval.
|
||||
*/
|
||||
struct timespec {
|
||||
time_t tv_sec; /* seconds */
|
||||
long tv_nsec; /* and nanoseconds */
|
||||
};
|
||||
#endif /* _TIMESPEC_DEFINED */
|
||||
|
||||
struct timezone {
|
||||
int tz_minuteswest; /* minutes west of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
|
||||
int gettimeofday(struct timeval *tp, void *ignore);
|
||||
struct tm *gmtime_r(const time_t *timep, struct tm *r);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_TIME_H_ */
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef __TYPES_H__
|
||||
#define __TYPES_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
typedef rt_int32_t clockid_t;
|
||||
typedef rt_int32_t key_t; /* Used for interprocess communication. */
|
||||
typedef rt_int32_t pid_t; /* Used for process IDs and process group IDs. */
|
||||
typedef signed long ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef _SYS_UNISTD_H
|
||||
#define _SYS_UNISTD_H
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
|
||||
#define STDIN_FILENO 0 /* standard input file descriptor */
|
||||
#define STDOUT_FILENO 1 /* standard output file descriptor */
|
||||
#define STDERR_FILENO 2 /* standard error file descriptor */
|
||||
|
||||
#include <dfs_posix.h>
|
||||
#else
|
||||
#define _FREAD 0x0001 /* read enabled */
|
||||
#define _FWRITE 0x0002 /* write enabled */
|
||||
#define _FAPPEND 0x0008 /* append (writes guaranteed at the end) */
|
||||
#define _FMARK 0x0010 /* internal; mark during gc() */
|
||||
#define _FDEFER 0x0020 /* internal; defer for next gc pass */
|
||||
#define _FASYNC 0x0040 /* signal pgrp when data ready */
|
||||
#define _FSHLOCK 0x0080 /* BSD flock() shared lock present */
|
||||
#define _FEXLOCK 0x0100 /* BSD flock() exclusive lock present */
|
||||
#define _FCREAT 0x0200 /* open with file create */
|
||||
#define _FTRUNC 0x0400 /* open with truncation */
|
||||
#define _FEXCL 0x0800 /* error on open if file exists */
|
||||
#define _FNBIO 0x1000 /* non blocking I/O (sys5 style) */
|
||||
#define _FSYNC 0x2000 /* do all writes synchronously */
|
||||
#define _FNONBLOCK 0x4000 /* non blocking I/O (POSIX style) */
|
||||
#define _FNDELAY _FNONBLOCK /* non blocking I/O (4.2 style) */
|
||||
#define _FNOCTTY 0x8000 /* don't assign a ctty on this open */
|
||||
|
||||
#define O_RDONLY 0 /* +1 == FREAD */
|
||||
#define O_WRONLY 1 /* +1 == FWRITE */
|
||||
#define O_RDWR 2 /* +1 == FREAD|FWRITE */
|
||||
#define O_APPEND _FAPPEND
|
||||
#define O_CREAT _FCREAT
|
||||
#define O_TRUNC _FTRUNC
|
||||
#define O_EXCL _FEXCL
|
||||
#define O_SYNC _FSYNC
|
||||
#endif
|
||||
|
||||
#endif /* _SYS_UNISTD_H */
|
||||
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef _TERMIOS_H__
|
||||
#define _TERMIOS_H__
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <posix_termios.h>
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#include <sys/time.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef RT_USING_DEVICE
|
||||
int gettimeofday(struct timeval *tp, void *ignore)
|
||||
{
|
||||
time_t time;
|
||||
rt_device_t device;
|
||||
|
||||
device = rt_device_find("rtc");
|
||||
if (device != RT_NULL)
|
||||
{
|
||||
rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time);
|
||||
if (tp != RT_NULL)
|
||||
{
|
||||
tp->tv_sec = time;
|
||||
tp->tv_usec = 0;
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Returns the current time.
|
||||
*
|
||||
* @param time_t * t the timestamp pointer, if not used, keep NULL.
|
||||
*
|
||||
* @return time_t return timestamp current.
|
||||
*
|
||||
*/
|
||||
/* for IAR 6.2 later Compiler */
|
||||
#if defined (__IAR_SYSTEMS_ICC__) && (__VER__) >= 6020000
|
||||
#pragma module_name = "?time"
|
||||
time_t (__time32)(time_t *t) /* Only supports 32-bit timestamp */
|
||||
#else
|
||||
time_t time(time_t *t)
|
||||
#endif
|
||||
{
|
||||
time_t time_now = 0;
|
||||
|
||||
#ifdef RT_USING_RTC
|
||||
static rt_device_t device = RT_NULL;
|
||||
|
||||
/* optimization: find rtc device only first. */
|
||||
if (device == RT_NULL)
|
||||
{
|
||||
device = rt_device_find("rtc");
|
||||
}
|
||||
|
||||
/* read timestamp from RTC device. */
|
||||
if (device != RT_NULL)
|
||||
{
|
||||
if (rt_device_open(device, 0) == RT_EOK)
|
||||
{
|
||||
rt_device_control(device, RT_DEVICE_CTRL_RTC_GET_TIME, &time_now);
|
||||
rt_device_close(device);
|
||||
}
|
||||
}
|
||||
#endif /* RT_USING_RTC */
|
||||
|
||||
/* if t is not NULL, write timestamp to *t */
|
||||
if (t != RT_NULL)
|
||||
{
|
||||
*t = time_now;
|
||||
}
|
||||
|
||||
return time_now;
|
||||
}
|
||||
|
||||
RT_WEAK clock_t clock(void)
|
||||
{
|
||||
return rt_tick_get();
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#include "sys/unistd.h"
|
||||
Reference in New Issue
Block a user