Merge pull request #5228 from mysterywolf/posix

This commit is contained in:
guo authored and GitHub committed 2021-10-27 12:22:35 +08:00
commit 4d256eb308
36 files changed
+361 -704

No files matched your search

File diff suppressed because it is too large. Load diff
+3 -47
View File
@@ -1,7 +1,8 @@
#ifndef RT_CONFIG_H__
#define RT_CONFIG_H__
/* Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) */
/* Automatically generated file; DO NOT EDIT. */
/* RT-Thread Project Configuration */
/* RT-Thread Kernel */
@@ -21,7 +22,6 @@
/* kservice optimization */
/* end of kservice optimization */
#define RT_DEBUG
/* Inter-Thread communication */
@@ -31,7 +31,6 @@
#define RT_USING_EVENT
#define RT_USING_MAILBOX
#define RT_USING_MESSAGEQUEUE
/* end of Inter-Thread communication */
/* Memory Management */
@@ -39,7 +38,6 @@
#define RT_USING_MEMHEAP
#define RT_USING_SMALL_MEM
#define RT_USING_HEAP
/* end of Memory Management */
/* Kernel Device Object */
@@ -48,9 +46,7 @@
#define RT_USING_CONSOLE
#define RT_CONSOLEBUF_SIZE 128
#define RT_CONSOLE_DEVICE_NAME "uart0"
/* end of Kernel Device Object */
#define RT_VER_NUM 0x40004
/* end of RT-Thread Kernel */
/* RT-Thread Components */
@@ -61,7 +57,6 @@
/* C++ features */
/* end of C++ features */
/* Command shell */
@@ -78,11 +73,9 @@
#define MSH_USING_BUILT_IN_COMMANDS
#define FINSH_USING_DESCRIPTION
#define FINSH_ARG_MAX 10
/* end of Command shell */
/* Device virtual file system */
/* end of Device virtual file system */
/* Device Drivers */
@@ -95,47 +88,34 @@
/* Using USB */
/* end of Using USB */
/* end of Device Drivers */
/* POSIX layer and C standard library */
#define RT_USING_LIBC
#define RT_LIBC_USING_TIME
#define RT_LIBC_DEFAULT_TIMEZONE 8
/* end of POSIX layer and C standard library */
/* Network */
/* Socket abstraction layer */
/* end of Socket abstraction layer */
/* Network interface device */
/* end of Network interface device */
/* light weight TCP/IP stack */
/* end of light weight TCP/IP stack */
/* AT commands */
/* end of AT commands */
/* end of Network */
/* VBUS(Virtual Software BUS) */
/* end of VBUS(Virtual Software BUS) */
/* Utilities */
/* end of Utilities */
/* end of RT-Thread Components */
/* RT-Thread Utestcases */
/* end of RT-Thread Utestcases */
/* RT-Thread online packages */
@@ -146,74 +126,53 @@
/* Marvell WiFi */
/* end of Marvell WiFi */
/* Wiced WiFi */
/* end of Wiced WiFi */
/* end of Wi-Fi */
/* IoT Cloud */
/* end of IoT Cloud */
/* end of IoT - internet of things */
/* security packages */
/* end of security packages */
/* language packages */
/* end of language packages */
/* multimedia packages */
/* LVGL: powerful and easy-to-use embedded GUI library */
/* lvgl: powerful and easy-to-use embedded GUI library */
/* end of lvgl: powerful and easy-to-use embedded GUI library */
/* u8g2: a monochrome graphic library */
/* end of u8g2: a monochrome graphic library */
/* end of multimedia packages */
/* tools packages */
/* end of tools packages */
/* system packages */
/* acceleration: Assembly language or algorithmic acceleration packages */
/* end of acceleration: Assembly language or algorithmic acceleration packages */
/* Micrium: Micrium software products porting for RT-Thread */
/* end of Micrium: Micrium software products porting for RT-Thread */
/* end of system packages */
/* peripheral libraries and drivers */
#define PKG_USING_BLUETRUM_SDK
#define PKG_USING_BLUETRUM_SDK_LATEST_VERSION
/* end of peripheral libraries and drivers */
/* AI packages */
/* end of AI packages */
/* miscellaneous packages */
/* samples: kernel and components samples */
/* end of samples: kernel and components samples */
/* entertainment: terminal games and other interesting software packages */
/* end of entertainment: terminal games and other interesting software packages */
/* end of miscellaneous packages */
/* end of RT-Thread online packages */
/* Hardware Drivers Config */
@@ -221,18 +180,15 @@
/* Onboard Peripheral Drivers */
/* end of Onboard Peripheral Drivers */
/* On-chip Peripheral Drivers */
#define BSP_USING_UART
#define BSP_USING_UART0
#define BSP_UART0_FIFO_SIZE 10
/* end of On-chip Peripheral Drivers */
/* Board extended module Drivers */
/* end of Hardware Drivers Config */
#define BOARD_BLUETRUM_EVB
#endif
-1
View File
@@ -125,7 +125,6 @@
/* POSIX layer and C standard library */
#define RT_USING_LIBC
#define RT_USING_POSIX
#define RT_LIBC_USING_TIME
#define RT_LIBC_DEFAULT_TIMEZONE 8
/* end of POSIX layer and C standard library */
File diff suppressed because it is too large. Load diff
-2
View File
@@ -13,6 +13,4 @@ for d in list:
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(d, 'SConscript'))
group = DefineGroup('', src, depend = [''], CPPPATH = [])
#objs += group
Return('objs')
+2 -5
View File
@@ -15,11 +15,8 @@ src += ['GD32VF103_standard_peripheral/system_gd32vf103.c',
CPPPATH = [ cwd + '/GD32VF103_standard_peripheral/Include',
cwd + '/GD32VF103_standard_peripheral',
cwd + '/n22/drivers',
cwd + '/n22/stubs']
cwd + '/n22/drivers']
CPPDEFINES = []
group = DefineGroup('Libraries', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=CPPDEFINES)
group = DefineGroup('Libraries', src, depend = [''], CPPPATH = CPPPATH)
Return('group')
@@ -1,12 +1,12 @@
//See LICENSE for license details.
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include "riscv_encoding.h"
#include "n22_func.h"
#include <rtthread.h>
__attribute__((weak)) uintptr_t handle_nmi() {
write(1, "nmi\n", 5);
_exit(1);
rt_kprintf("nmi\n");
return 0;
}
@@ -14,8 +14,7 @@ __attribute__((weak)) uintptr_t handle_trap(uintptr_t mcause, uintptr_t sp) {
if (mcause == 0xFFF) {
handle_nmi();
}
write(1, "trap\n", 5);
_exit(mcause);
rt_kprintf("trap\n");
return 0;
}
@@ -241,7 +241,7 @@ _start0800:
li a0, 0
li a1, 0
call entry
tail exit
/* tail exit */
1:
j 1b
+3 -47
View File
@@ -1,7 +1,8 @@
#ifndef RT_CONFIG_H__
#define RT_CONFIG_H__
/* Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) */
/* Automatically generated file; DO NOT EDIT. */
/* RT-Thread Configuration */
/* RT-Thread Kernel */
@@ -21,7 +22,6 @@
/* kservice optimization */
/* end of kservice optimization */
#define RT_DEBUG
/* Inter-Thread communication */
@@ -31,14 +31,12 @@
#define RT_USING_EVENT
#define RT_USING_MAILBOX
#define RT_USING_MESSAGEQUEUE
/* end of Inter-Thread communication */
/* Memory Management */
#define RT_USING_MEMPOOL
#define RT_USING_SMALL_MEM
#define RT_USING_HEAP
/* end of Memory Management */
/* Kernel Device Object */
@@ -46,9 +44,7 @@
#define RT_USING_CONSOLE
#define RT_CONSOLEBUF_SIZE 128
#define RT_CONSOLE_DEVICE_NAME "uart0"
/* end of Kernel Device Object */
#define RT_VER_NUM 0x40004
/* end of RT-Thread Kernel */
/* RT-Thread Components */
@@ -59,7 +55,6 @@
/* C++ features */
/* end of C++ features */
/* Command shell */
@@ -76,11 +71,9 @@
#define MSH_USING_BUILT_IN_COMMANDS
#define FINSH_USING_DESCRIPTION
#define FINSH_ARG_MAX 10
/* end of Command shell */
/* Device virtual file system */
/* end of Device virtual file system */
/* Device Drivers */
@@ -93,47 +86,34 @@
/* Using USB */
/* end of Using USB */
/* end of Device Drivers */
/* POSIX layer and C standard library */
#define RT_USING_LIBC
#define RT_LIBC_USING_TIME
#define RT_LIBC_DEFAULT_TIMEZONE 8
/* end of POSIX layer and C standard library */
/* Network */
/* Socket abstraction layer */
/* end of Socket abstraction layer */
/* Network interface device */
/* end of Network interface device */
/* light weight TCP/IP stack */
/* end of light weight TCP/IP stack */
/* AT commands */
/* end of AT commands */
/* end of Network */
/* VBUS(Virtual Software BUS) */
/* end of VBUS(Virtual Software BUS) */
/* Utilities */
/* end of Utilities */
/* end of RT-Thread Components */
/* RT-Thread Utestcases */
/* end of RT-Thread Utestcases */
/* RT-Thread online packages */
@@ -144,72 +124,51 @@
/* Marvell WiFi */
/* end of Marvell WiFi */
/* Wiced WiFi */
/* end of Wiced WiFi */
/* end of Wi-Fi */
/* IoT Cloud */
/* end of IoT Cloud */
/* end of IoT - internet of things */
/* security packages */
/* end of security packages */
/* language packages */
/* end of language packages */
/* multimedia packages */
/* LVGL: powerful and easy-to-use embedded GUI library */
/* lvgl: powerful and easy-to-use embedded GUI library */
/* end of lvgl: powerful and easy-to-use embedded GUI library */
/* u8g2: a monochrome graphic library */
/* end of u8g2: a monochrome graphic library */
/* end of multimedia packages */
/* tools packages */
/* end of tools packages */
/* system packages */
/* acceleration: Assembly language or algorithmic acceleration packages */
/* end of acceleration: Assembly language or algorithmic acceleration packages */
/* Micrium: Micrium software products porting for RT-Thread */
/* end of Micrium: Micrium software products porting for RT-Thread */
/* end of system packages */
/* peripheral libraries and drivers */
/* end of peripheral libraries and drivers */
/* AI packages */
/* end of AI packages */
/* miscellaneous packages */
/* samples: kernel and components samples */
/* end of samples: kernel and components samples */
/* entertainment: terminal games and other interesting software packages */
/* end of entertainment: terminal games and other interesting software packages */
/* end of miscellaneous packages */
/* end of RT-Thread online packages */
/* Hardware Drivers Config */
@@ -218,18 +177,15 @@
/* Onboard Peripheral Drivers */
#define BSP_USING_USART
/* end of Onboard Peripheral Drivers */
/* On-chip Peripheral Drivers */
#define BSP_USING_GPIO
#define BSP_USING_UART
#define BSP_USING_UART0
/* end of On-chip Peripheral Drivers */
/* Board extended module Drivers */
/* end of Hardware Drivers Config */
#define SOC_GD32VF103
#endif
+1 -1
View File
@@ -119,7 +119,7 @@ void rtthread_startup(void)
#ifdef RT_USING_FINSH
/* init finsh */
finsh_system_init();
#if !defined(RT_USING_LIBC) && defined(RT_USING_DEVICE)
#if !defined(RT_LIBC_USING_FILEIO) && defined(RT_USING_DEVICE)
finsh_set_device("uart1");
#endif
#endif
+15 -58
View File
File diff suppressed because it is too large. Load diff
+3 -44
View File
@@ -1,7 +1,8 @@
#ifndef RT_CONFIG_H__
#define RT_CONFIG_H__
/* Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) */
/* Automatically generated file; DO NOT EDIT. */
/* RT-Thread Configuration */
/* RT-Thread Kernel */
@@ -14,7 +15,6 @@
/* kservice optimization */
/* end of kservice optimization */
/* Inter-Thread communication */
@@ -23,14 +23,12 @@
#define RT_USING_EVENT
#define RT_USING_MAILBOX
#define RT_USING_MESSAGEQUEUE
/* end of Inter-Thread communication */
/* Memory Management */
#define RT_USING_MEMPOOL
#define RT_USING_SMALL_MEM
#define RT_USING_HEAP
/* end of Memory Management */
/* Kernel Device Object */
@@ -38,9 +36,7 @@
#define RT_USING_CONSOLE
#define RT_CONSOLEBUF_SIZE 128
#define RT_CONSOLE_DEVICE_NAME "uart"
/* end of Kernel Device Object */
#define RT_VER_NUM 0x40004
/* end of RT-Thread Kernel */
#define ARCH_ARM
#define ARCH_ARM_CORTEX_M
#define ARCH_ARM_CORTEX_M0
@@ -54,7 +50,6 @@
/* C++ features */
/* end of C++ features */
/* Command shell */
@@ -71,11 +66,9 @@
#define MSH_USING_BUILT_IN_COMMANDS
#define FINSH_USING_DESCRIPTION
#define FINSH_ARG_MAX 10
/* end of Command shell */
/* Device virtual file system */
/* end of Device virtual file system */
/* Device Drivers */
@@ -88,47 +81,34 @@
/* Using USB */
/* end of Using USB */
/* end of Device Drivers */
/* POSIX layer and C standard library */
#define RT_USING_LIBC
#define RT_LIBC_USING_TIME
#define RT_LIBC_DEFAULT_TIMEZONE 8
/* end of POSIX layer and C standard library */
/* Network */
/* Socket abstraction layer */
/* end of Socket abstraction layer */
/* Network interface device */
/* end of Network interface device */
/* light weight TCP/IP stack */
/* end of light weight TCP/IP stack */
/* AT commands */
/* end of AT commands */
/* end of Network */
/* VBUS(Virtual Software BUS) */
/* end of VBUS(Virtual Software BUS) */
/* Utilities */
/* end of Utilities */
/* end of RT-Thread Components */
/* RT-Thread Utestcases */
/* end of RT-Thread Utestcases */
/* RT-Thread online packages */
@@ -139,72 +119,51 @@
/* Marvell WiFi */
/* end of Marvell WiFi */
/* Wiced WiFi */
/* end of Wiced WiFi */
/* end of Wi-Fi */
/* IoT Cloud */
/* end of IoT Cloud */
/* end of IoT - internet of things */
/* security packages */
/* end of security packages */
/* language packages */
/* end of language packages */
/* multimedia packages */
/* LVGL: powerful and easy-to-use embedded GUI library */
/* lvgl: powerful and easy-to-use embedded GUI library */
/* end of lvgl: powerful and easy-to-use embedded GUI library */
/* u8g2: a monochrome graphic library */
/* end of u8g2: a monochrome graphic library */
/* end of multimedia packages */
/* tools packages */
/* end of tools packages */
/* system packages */
/* acceleration: Assembly language or algorithmic acceleration packages */
/* end of acceleration: Assembly language or algorithmic acceleration packages */
/* Micrium: Micrium software products porting for RT-Thread */
/* end of Micrium: Micrium software products porting for RT-Thread */
/* end of system packages */
/* peripheral libraries and drivers */
/* end of peripheral libraries and drivers */
/* AI packages */
/* end of AI packages */
/* miscellaneous packages */
/* samples: kernel and components samples */
/* end of samples: kernel and components samples */
/* entertainment: terminal games and other interesting software packages */
/* end of entertainment: terminal games and other interesting software packages */
/* end of miscellaneous packages */
/* end of RT-Thread online packages */
#define SOC_LPC1114
#endif
+2 -2
View File
@@ -18,7 +18,7 @@
#include <lwp.h>
#endif
#ifdef RT_USING_LIBC
#ifdef RT_LIBC_USING_FILEIO
#include <libc.h>
#endif
@@ -216,7 +216,7 @@ struct dfs_fd *fd_get(int fd)
struct dfs_fd *d;
struct dfs_fdtable *fdt;
#ifdef RT_USING_LIBC
#ifdef RT_LIBC_USING_FILEIO
if ((0 <= fd) && (fd <= 2))
fd = libc_stdio_get_console();
#endif
+4 -4
View File
@@ -145,7 +145,7 @@ void finsh_set_prompt_mode(rt_uint32_t prompt_mode)
int finsh_getchar(void)
{
#ifdef RT_USING_DEVICE
#ifdef RT_USING_LIBC
#ifdef RT_LIBC_USING_FILEIO
return getchar();
#else
char ch = 0;
@@ -163,14 +163,14 @@ int finsh_getchar(void)
rt_sem_take(&shell->rx_sem, RT_WAITING_FOREVER);
return ch;
#endif /* RT_USING_LIBC */
#endif /* RT_LIBC_USING_FILEIO */
#else
extern char rt_hw_console_getchar(void);
return rt_hw_console_getchar();
#endif /* RT_USING_DEVICE */
}
#if !defined(RT_USING_LIBC) && defined(RT_USING_DEVICE)
#if !defined(RT_LIBC_USING_FILEIO) && defined(RT_USING_DEVICE)
static rt_err_t finsh_rx_ind(rt_device_t dev, rt_size_t size)
{
RT_ASSERT(shell != RT_NULL);
@@ -436,7 +436,7 @@ void finsh_thread_entry(void *parameter)
shell->echo_mode = 0;
#endif
#if !defined(RT_USING_LIBC) && defined(RT_USING_DEVICE)
#if !defined(RT_LIBC_USING_FILEIO) && defined(RT_USING_DEVICE)
/* set console device as shell device */
if (shell->device == RT_NULL)
{
+1 -1
View File
@@ -78,7 +78,7 @@ struct finsh_shell
rt_uint16_t line_position;
rt_uint16_t line_curpos;
#if !defined(RT_USING_LIBC) && defined(RT_USING_DEVICE)
#if !defined(RT_LIBC_USING_FILEIO) && defined(RT_USING_DEVICE)
rt_device_t device;
#endif
+35 -32
View File
@@ -2,18 +2,49 @@ menu "POSIX layer and C standard library"
config RT_USING_LIBC
bool "Enable libc APIs from toolchain"
select RT_USING_DFS
select RT_USING_POSIX
default y
if RT_USING_LIBC
config RT_LIBC_USING_TIME
default y
config RT_LIBC_USING_FILEIO
bool "Enable libc with file operation, eg.fopen/fwrite/fread/getchar"
select RT_USING_DFS
select RT_USING_POSIX
default n
config RT_USING_MODULE
bool "Enable dynamic module with dlopen/dlsym/dlclose feature"
default n
if RT_USING_MODULE
config RT_USING_CUSTOM_DLMODULE
bool "Enable load dynamic module by custom"
default n
endif
endif
if RT_USING_LIBC != y
config RT_LIBC_USING_TIME
bool "Enable time functions without compiler's libc"
default y
endif
config RT_LIBC_DEFAULT_TIMEZONE
depends on (RT_LIBC_USING_TIME || RT_USING_LIBC)
int "Set the default time zone (UTC+)"
range -12 12
default 8
config RT_USING_PTHREADS
bool "Enable pthreads APIs"
default n
if RT_USING_PTHREADS
config PTHREAD_NUM_MAX
int "Maximum number of pthreads"
default 8
int "Maximum number of pthreads"
default 8
endif
if RT_USING_DFS
@@ -42,32 +73,4 @@ if RT_USING_DFS
endif
if RT_USING_LIBC
config RT_LIBC_USING_TIME
default y
config RT_USING_MODULE
bool "Enable dynamic module with dlopen/dlsym/dlclose feature"
default n
if RT_USING_MODULE
config RT_USING_CUSTOM_DLMODULE
bool "Enable load dynamic module by custom"
default n
endif
endif
if RT_USING_LIBC != y
config RT_LIBC_USING_TIME
bool "Enable time functions without compiler's libc"
default y
endif
config RT_LIBC_DEFAULT_TIMEZONE
depends on (RT_LIBC_USING_TIME || RT_USING_LIBC)
int "Set the default time zone (UTC+)"
range -12 12
default 8
endmenu
@@ -8,9 +8,6 @@ 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'])
+3 -8
View File
@@ -7,29 +7,24 @@
* Date Author Notes
* 2017/10/15 bernard the first version
*/
#include <fcntl.h>
#include <rtthread.h>
#include <fcntl.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)
#ifdef RT_USING_POSIX
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
#endif /* RT_USING_POSIX */
#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
pthread_system_init();
+4
View File
@@ -10,13 +10,17 @@
#ifndef __RTT_LIBC_H__
#define __RTT_LIBC_H__
#include <rtconfig.h>
#ifdef __cplusplus
extern "C" {
#endif
int libc_system_init(void);
#ifdef RT_USING_POSIX
int libc_stdio_get_console(void);
int libc_stdio_set_console(const char* device_name, int mode);
#endif /* RT_USING_POSIX */
#ifdef __cplusplus
}
+5 -4
View File
@@ -7,16 +7,17 @@
* Date Author Notes
* 2017/10/15 bernard implement stdio for armcc.
*/
#include <rtthread.h>
#ifdef RT_USING_POSIX
#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>
#include <fcntl.h>
#include <unistd.h>
#define STDIO_DEVICE_NAME_MAX 32
@@ -48,4 +49,4 @@ int libc_stdio_get_console(void)
return std_fd;
}
#endif
#endif /* RT_USING_POSIX */
File diff suppressed because it is too large. Load diff
+1 -1
View File
@@ -11,7 +11,7 @@ CPPDEFINES = []
if GetDepend('RT_USING_LIBC'):
src += Glob('*.c')
elif GetDepend('RT_LIBC_USING_TIME'):
src += Glob('time.c')
src += ['time.c']
if rtconfig.CROSS_TOOL == 'keil':
CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND']
+2 -3
View File
@@ -11,7 +11,7 @@ CPPDEFINES = ['RT_USING_DLIBC']
if rtconfig.PLATFORM == 'iar':
if GetDepend('RT_USING_DFS'):
if GetDepend('RT_LIBC_USING_FILEIO'):
from distutils.version import LooseVersion
from iar import IARVersion
@@ -20,7 +20,6 @@ if rtconfig.PLATFORM == 'iar':
if LooseVersion(IARVersion()) < LooseVersion("8.20.1"):
CPPDEFINES = CPPDEFINES + ['_DLIB_THREAD_SUPPORT']
group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
Return('group')
+3 -9
View File
@@ -7,29 +7,24 @@
* Date Author Notes
* 2017/10/15 bernard the first version
*/
#include <fcntl.h>
#include <rtthread.h>
#include <fcntl.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)
#ifdef RT_USING_POSIX
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
#endif /* RT_USING_POSIX */
#if defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT)
pthread_system_init();
@@ -38,4 +33,3 @@ int libc_system_init(void)
return 0;
}
INIT_COMPONENT_EXPORT(libc_system_init);
+2
View File
@@ -16,8 +16,10 @@ extern "C" {
#endif
int libc_system_init(void);
#ifdef RT_USING_POSIX
int libc_stdio_get_console(void);
int libc_stdio_set_console(const char* device_name, int mode);
#endif /* RT_USING_POSIX */
#ifdef __cplusplus
}
+6 -6
View File
@@ -7,17 +7,17 @@
* Date Author Notes
* 2017/10/15 bernard implement stdio for IAR dlib.
*/
#include <rtthread.h>
#ifdef RT_USING_POSIX
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rtthread.h>
#include <fcntl.h>
#include <unistd.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;
@@ -46,4 +46,4 @@ int libc_stdio_get_console(void) {
return std_fd;
}
#endif
#endif /* RT_USING_POSIX */
@@ -8,10 +8,8 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
#include <yfuns.h>
#include <unistd.h>
#pragma module_name = "?__close"
int __close(int handle)
@@ -20,10 +18,9 @@ int __close(int handle)
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
#ifdef RT_USING_DFS
#ifdef RT_LIBC_USING_FILEIO
return close(handle);
#else
return 0;
#endif
return _LLIO_ERROR;
#endif /* RT_LIBC_USING_FILEIO */
}
@@ -8,10 +8,8 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
#include <yfuns.h>
#include <unistd.h>
#pragma module_name = "?__lseek"
long __lseek(int handle, long offset, int whence)
@@ -20,8 +18,7 @@ long __lseek(int handle, long offset, int whence)
handle == _LLIO_STDERR ||
handle == _LLIO_STDIN)
return _LLIO_ERROR;
#ifdef RT_USING_DFS
#ifdef RT_LIBC_USING_FILEIO
return lseek(handle, offset, whence);
#else
return _LLIO_ERROR;
@@ -10,17 +10,13 @@
#include <rtthread.h>
#include <yfuns.h>
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
#include <fcntl.h>
#pragma module_name = "?__open"
int __open(const char *filename, int mode)
{
#ifndef RT_USING_DFS
return _LLIO_ERROR;
#else
#ifdef RT_LIBC_USING_FILEIO
int handle;
int open_mode = O_RDONLY;
@@ -70,5 +66,7 @@ int __open(const char *filename, int mode)
return _LLIO_ERROR;
return handle;
#endif
#else
return _LLIO_ERROR;
#endif /* RT_LIBC_USING_FILEIO */
}
+5 -13
View File
@@ -9,10 +9,8 @@
*/
#include <rtthread.h>
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
#include <yfuns.h>
#include <unistd.h>
#include "libc.h"
#define DBG_TAG "dlib.syscall_read"
@@ -22,32 +20,26 @@
#pragma module_name = "?__read"
size_t __read(int handle, unsigned char *buf, size_t len)
{
#ifdef RT_USING_DFS
#ifdef RT_LIBC_USING_FILEIO
int size;
#endif
if (handle == _LLIO_STDIN)
{
#ifdef RT_USING_POSIX
if (libc_stdio_get_console() < 0)
{
LOG_W("Do not invoke standard input before initializing libc");
return 0;
}
return read(STDIN_FILENO, buf, len);
#else
return _LLIO_ERROR;
#endif
}
else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
return _LLIO_ERROR;
}
#ifndef RT_USING_DFS
return _LLIO_ERROR;
#else
size = read(handle, buf, len);
return size;
#endif
#else
return _LLIO_ERROR;
#endif /* RT_LIBC_USING_FILEIO */
}
@@ -8,17 +8,15 @@
* 2015-01-28 Bernard first version
*/
#include <rtthread.h>
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
#include <yfuns.h>
#include <unistd.h>
#pragma module_name = "?remove"
int remove(const char *val)
{
#ifndef RT_USING_DFS
return -1;
#else
#ifdef RT_USING_POSIX
return unlink(val);
#endif
#else
return -1;
#endif /* RT_USING_POSIX */
}
+12 -18
View File
@@ -9,10 +9,8 @@
*/
#include <rtthread.h>
#ifdef RT_USING_DFS
#include <dfs_posix.h>
#endif
#include <yfuns.h>
#include <unistd.h>
#include "libc.h"
#define DBG_TAG "dlib.syscall_write"
@@ -23,24 +21,20 @@
size_t __write(int handle, const unsigned char *buf, size_t len)
{
#ifdef RT_USING_DFS
#ifdef RT_LIBC_USING_FILEIO
int size;
#endif
#endif /* RT_LIBC_USING_FILEIO */
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
#ifndef RT_USING_CONSOLE
return _LLIO_ERROR;
#else
#ifdef RT_USING_POSIX
#ifdef RT_LIBC_USING_FILEIO
if (libc_stdio_get_console() < 0)
{
LOG_W("Do not invoke standard output before initializing libc");
return 0;
}
return write(STDOUT_FILENO, (void*)buf, len);
#else
#elif defined(RT_USING_CONSOLE)
rt_device_t console_device;
console_device = rt_console_get_device();
@@ -50,19 +44,19 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
}
return len;
#endif
#endif
#else
return _LLIO_ERROR;
#endif /* RT_LIBC_USING_FILEIO */
}
else if (handle == _LLIO_STDIN)
{
return _LLIO_ERROR;
}
#ifndef RT_USING_DFS
return _LLIO_ERROR;
#else
#ifdef RT_LIBC_USING_FILEIO
size = write(handle, buf, len);
return size;
#endif
#else
return _LLIO_ERROR;
#endif /* RT_LIBC_USING_FILEIO */
}
+2 -13
View File
@@ -12,34 +12,23 @@
#include <stdlib.h>
#include <fcntl.h>
#include <sys/time.h>
#include "libc.h"
#ifdef RT_USING_PTHREADS
#include <pthread.h>
#endif
int _EXFUN(putenv,(char *__string));
int libc_system_init(void)
{
#if defined(RT_USING_DFS) & defined(RT_USING_DFS_DEVFS) & defined(RT_USING_CONSOLE)
#ifdef RT_LIBC_USING_FILEIO
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
}
/* set PATH and HOME */
putenv("PATH=/bin");
putenv("HOME=/home");
#endif
#endif /* RT_LIBC_USING_FILEIO */
#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT
pthread_system_init();
+3 -4
View File
@@ -10,16 +10,15 @@
#ifndef __RTT_LIBC_H__
#define __RTT_LIBC_H__
#ifndef _EXFUN
#define _EXFUN(name, proto) name proto
#endif
#ifdef __cplusplus
extern "C" {
#endif
int libc_system_init(void);
#ifdef RT_LIBC_USING_FILEIO
int libc_stdio_get_console(void);
int libc_stdio_set_console(const char* device_name, int mode);
#endif /* RT_LIBC_USING_FILEIO */
#ifdef __cplusplus
}
+5 -3
View File
@@ -7,16 +7,16 @@
* Date Author Notes
* 2017/10/15 bernard the first version
*/
#include <rtthread.h>
#ifdef RT_LIBC_USING_FILEIO
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <rtthread.h>
#include "libc.h"
#define STDIO_DEVICE_NAME_MAX 32
int _EXFUN(fileno, (FILE *));
static FILE* std_console = NULL;
int libc_stdio_set_console(const char* device_name, int mode)
@@ -79,3 +79,5 @@ int libc_stdio_get_console(void)
else
return -1;
}
#endif /* RT_LIBC_USING_FILEIO */
File diff suppressed because it is too large. Load diff