mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-25 18:53:08 +08:00
46 files changed
+156
-3651
No files matched your search
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -80,10 +80,6 @@
|
||||
/* Using QEMU or SkyEye*/
|
||||
/* #define RT_USING_EMULATOR */
|
||||
|
||||
/* SECTION: a mini libc */
|
||||
/* Using mini libc library*/
|
||||
/* #define RT_USING_MINILIBC */
|
||||
|
||||
/* SECTION: C++ support */
|
||||
/* Using C++ support*/
|
||||
/* #define RT_USING_CPLUSPLUS */
|
||||
|
||||
@@ -93,7 +93,6 @@
|
||||
/* SECTION: a runtime libc library */
|
||||
/* a runtime libc library*/
|
||||
/* #define RT_USING_NEWLIB */
|
||||
#define RT_USING_MINILIBC
|
||||
|
||||
/* SECTION: C++ support */
|
||||
/* Using C++ support*/
|
||||
|
||||
@@ -72,10 +72,6 @@
|
||||
#define FINSH_USING_SYMTAB
|
||||
#define FINSH_USING_DESCRIPTION
|
||||
|
||||
/* SECTION: a mini libc */
|
||||
/* Using mini libc library*/
|
||||
/* #define RT_USING_MINILIBC */
|
||||
|
||||
/* SECTION: C++ support */
|
||||
/* Using C++ support*/
|
||||
/* #define RT_USING_CPLUSPLUS */
|
||||
|
||||
@@ -37,32 +37,6 @@ struct stm32_dac
|
||||
|
||||
static struct stm32_dac stm32_dac_obj[sizeof(dac_config) / sizeof(dac_config[0])];
|
||||
|
||||
static rt_err_t stm32_dac_enabled(struct rt_dac_device *device, rt_uint32_t channel)
|
||||
{
|
||||
DAC_HandleTypeDef *stm32_dac_handler;
|
||||
RT_ASSERT(device != RT_NULL);
|
||||
stm32_dac_handler = device->parent.user_data;
|
||||
|
||||
#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F4)
|
||||
HAL_DAC_Start(stm32_dac_handler, channel);
|
||||
#endif
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t stm32_dac_disabled(struct rt_dac_device *device, rt_uint32_t channel)
|
||||
{
|
||||
DAC_HandleTypeDef *stm32_dac_handler;
|
||||
RT_ASSERT(device != RT_NULL);
|
||||
stm32_dac_handler = device->parent.user_data;
|
||||
|
||||
#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F4)
|
||||
HAL_DAC_Stop(stm32_dac_handler, channel);
|
||||
#endif
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_uint32_t stm32_dac_get_channel(rt_uint32_t channel)
|
||||
{
|
||||
rt_uint32_t stm32_channel = 0;
|
||||
@@ -83,6 +57,54 @@ static rt_uint32_t stm32_dac_get_channel(rt_uint32_t channel)
|
||||
return stm32_channel;
|
||||
}
|
||||
|
||||
static rt_err_t stm32_dac_enabled(struct rt_dac_device *device, rt_uint32_t channel)
|
||||
{
|
||||
uint32_t dac_channel;
|
||||
DAC_HandleTypeDef *stm32_dac_handler;
|
||||
RT_ASSERT(device != RT_NULL);
|
||||
stm32_dac_handler = device->parent.user_data;
|
||||
|
||||
#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F4)
|
||||
if ((channel <= 2) && (channel > 0))
|
||||
{
|
||||
/* set stm32 dac channel */
|
||||
dac_channel = stm32_dac_get_channel(channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("dac channel must be 1 or 2.");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
HAL_DAC_Start(stm32_dac_handler, dac_channel);
|
||||
#endif
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t stm32_dac_disabled(struct rt_dac_device *device, rt_uint32_t channel)
|
||||
{
|
||||
uint32_t dac_channel;
|
||||
DAC_HandleTypeDef *stm32_dac_handler;
|
||||
RT_ASSERT(device != RT_NULL);
|
||||
stm32_dac_handler = device->parent.user_data;
|
||||
|
||||
#if defined(SOC_SERIES_STM32MP1) || defined(SOC_SERIES_STM32H7) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F4)
|
||||
if ((channel <= 2) && (channel > 0))
|
||||
{
|
||||
/* set stm32 dac channel */
|
||||
dac_channel = stm32_dac_get_channel(channel);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_E("dac channel must be 1 or 2.");
|
||||
return -RT_ERROR;
|
||||
}
|
||||
HAL_DAC_Stop(stm32_dac_handler, dac_channel);
|
||||
#endif
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
static rt_err_t stm32_set_dac_value(struct rt_dac_device *device, rt_uint32_t channel, rt_uint32_t *value)
|
||||
{
|
||||
uint32_t dac_channel;
|
||||
|
||||
@@ -114,7 +114,10 @@ static rt_err_t stm32_configure(struct rt_serial_device *serial, struct serial_c
|
||||
switch (cfg->data_bits)
|
||||
{
|
||||
case DATA_BITS_8:
|
||||
uart->handle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
if (cfg->parity == PARITY_ODD || cfg->parity == PARITY_EVEN)
|
||||
uart->handle.Init.WordLength = UART_WORDLENGTH_9B;
|
||||
else
|
||||
uart->handle.Init.WordLength = UART_WORDLENGTH_8B;
|
||||
break;
|
||||
case DATA_BITS_9:
|
||||
uart->handle.Init.WordLength = UART_WORDLENGTH_9B;
|
||||
|
||||
@@ -65,10 +65,6 @@
|
||||
/* Using FinSH as Shell*/
|
||||
/* #define RT_USING_FINSH */
|
||||
|
||||
/* SECTION: a mini libc */
|
||||
/* Using mini libc library*/
|
||||
/* #define RT_USING_MINILIBC */
|
||||
|
||||
/* SECTION: C++ support */
|
||||
/* Using C++ support*/
|
||||
/* #define RT_USING_CPLUSPLUS */
|
||||
|
||||
@@ -47,15 +47,7 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef RT_USING_MINILIBC
|
||||
typedef unsigned int u_int;
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned long u_long;
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
@@ -63,14 +55,6 @@ typedef unsigned long long uint64_t;
|
||||
typedef int bool_t;
|
||||
typedef int enum_t;
|
||||
|
||||
#ifndef RT_USING_NEWLIB
|
||||
typedef unsigned long dev_t;
|
||||
#endif
|
||||
|
||||
#if !defined(RT_USING_NEWLIB) && !defined(RT_USING_MINILIBC)
|
||||
typedef rt_int32_t ssize_t;
|
||||
#endif
|
||||
|
||||
/* This needs to be changed to uint32_t in the future */
|
||||
typedef unsigned long rpcprog_t;
|
||||
typedef unsigned long rpcvers_t;
|
||||
|
||||
@@ -25,4 +25,10 @@ typedef long signed int ssize_t; /* Used for a count of bytes or an error
|
||||
#endif
|
||||
typedef unsigned long useconds_t; /* microseconds (unsigned) */
|
||||
|
||||
typedef unsigned long dev_t;
|
||||
|
||||
typedef unsigned int u_int;
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned long u_long;
|
||||
|
||||
#endif
|
||||
@@ -13,6 +13,7 @@
|
||||
* RT_USING_DFS is not defined
|
||||
* 2020-02-13 Meco Man re-implement exit() and abort()
|
||||
* 2020-02-14 Meco Man implement _sys_tmpnam()
|
||||
* 2020-02-25 Meco Man add multithreaded protection
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
@@ -41,6 +42,36 @@ const char __stdin_name[] = "STDIN";
|
||||
const char __stdout_name[] = "STDOUT";
|
||||
const char __stderr_name[] = "STDERR";
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
int _mutex_initialize(rt_mutex_t *m)
|
||||
{
|
||||
*m = rt_mutex_create("_mutex_", RT_IPC_FLAG_PRIO);
|
||||
if(*m == RT_NULL)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void _mutex_acquire(rt_mutex_t *m)
|
||||
{
|
||||
rt_mutex_take(*m, RT_WAITING_FOREVER);
|
||||
}
|
||||
|
||||
void _mutex_release(rt_mutex_t *m)
|
||||
{
|
||||
rt_mutex_release(*m);
|
||||
}
|
||||
|
||||
void _mutex_free(rt_mutex_t *m)
|
||||
{
|
||||
rt_mutex_delete(*m);
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* required by fopen() and freopen().
|
||||
*
|
||||
|
||||
@@ -10,7 +10,7 @@ CPPPATH = [cwd]
|
||||
if GetDepend('RT_USING_LIBC'):
|
||||
src += Glob('*.c')
|
||||
else:
|
||||
if GetDepend('RT_LIBC_USING_TIME') and not GetDepend('RT_USING_MINILIBC'):
|
||||
if GetDepend('RT_LIBC_USING_TIME'):
|
||||
src += ['time.c']
|
||||
|
||||
if GetDepend('RT_USING_POSIX') == False:
|
||||
@@ -21,7 +21,7 @@ if rtconfig.CROSS_TOOL == 'keil':
|
||||
else:
|
||||
CPPDEFINES = []
|
||||
|
||||
if not GetDepend('RT_USING_MINILIBC') and (GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME')):
|
||||
if GetDepend('RT_USING_LIBC') or GetDepend('RT_LIBC_USING_TIME'):
|
||||
group = DefineGroup('libc', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
|
||||
|
||||
Return('group')
|
||||
@@ -24,4 +24,10 @@ typedef long signed int ssize_t; /* Used for a count of bytes or an error
|
||||
#endif
|
||||
typedef unsigned long useconds_t; /* microseconds (unsigned) */
|
||||
|
||||
typedef unsigned long dev_t;
|
||||
|
||||
typedef unsigned int u_int;
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned long u_long;
|
||||
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
from building import *
|
||||
Import('rtconfig')
|
||||
|
||||
src = Glob('*.c') + Glob('*.cpp')
|
||||
cwd = GetCurrentDir()
|
||||
group = []
|
||||
|
||||
CPPPATH = [cwd]
|
||||
CPPDEFINES = ['RT_USING_MINILIBC']
|
||||
|
||||
if rtconfig.PLATFORM == 'gcc' and rtconfig.ARCH != 'sim' and not GetDepend('RT_USING_LIBC') and GetDepend('RT_USING_MINILIBC'):
|
||||
group = DefineGroup('libc', src, depend = [''],
|
||||
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)
|
||||
|
||||
Return('group')
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2008-08-14 Bernard the first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
|
||||
#include "ctype.h"
|
||||
|
||||
int isprint (int ch)
|
||||
{
|
||||
ch&=0x7f;
|
||||
return (ch>=32 && ch<127);
|
||||
}
|
||||
|
||||
int isalpha(int ch)
|
||||
{
|
||||
return (unsigned int)((ch | 0x20) - 'a') < 26u;
|
||||
}
|
||||
|
||||
int isdigit (int ch)
|
||||
{
|
||||
return (unsigned int)(ch - '0') < 10u;
|
||||
}
|
||||
|
||||
int isspace(int ch)
|
||||
{
|
||||
switch(ch)
|
||||
{
|
||||
case ' ':
|
||||
case '\n':
|
||||
case '\f':
|
||||
case '\r':
|
||||
case '\t':
|
||||
case '\v':
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2008-08-14 Bernard the first version
|
||||
*/
|
||||
#ifndef __CTYPE_H__
|
||||
#define __CTYPE_H__
|
||||
|
||||
int isprint(int c) __attribute__ ((__const__));
|
||||
int isalpha (int c) __attribute__ ((__const__));
|
||||
int isdigit (int ch) __attribute__ ((__const__));
|
||||
int isspace(int ch) __attribute__ ((__const__));
|
||||
|
||||
#endif
|
||||
@@ -1,16 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef __ERRNO_H__
|
||||
#define __ERRNO_H__
|
||||
|
||||
#include "libc/libc_errno.h"
|
||||
/* Others defined in libc/libc_errno.h */
|
||||
#define ENSRNOTFOUND 163 /* Domain name not found */
|
||||
|
||||
#endif
|
||||
@@ -1,14 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef __INTTYPES_H__
|
||||
#define __INTTYPES_H__
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#endif
|
||||
@@ -1,176 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#include <math.h>
|
||||
|
||||
/*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS CRT
|
||||
* FILE: lib/crt/math/cos.c
|
||||
* PURPOSE: Generic C Implementation of cos
|
||||
* PROGRAMMER: Timo Kreuzer (timo.kreuzer@reactos.org)
|
||||
*/
|
||||
|
||||
#define PRECISION 9
|
||||
|
||||
static double cos_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.};
|
||||
static double cos_sign_tbl[] = {1,-1,-1,1};
|
||||
|
||||
static double sin_off_tbl[] = {0.0, -M_PI/2., 0, -M_PI/2.};
|
||||
static double sin_sign_tbl[] = {1,-1,-1,1};
|
||||
|
||||
double sin(double x)
|
||||
{
|
||||
int quadrant;
|
||||
double x2, result;
|
||||
|
||||
/* Calculate the quadrant */
|
||||
quadrant = x * (2./M_PI);
|
||||
|
||||
/* Get offset inside quadrant */
|
||||
x = x - quadrant * (M_PI/2.);
|
||||
|
||||
/* Normalize quadrant to [0..3] */
|
||||
quadrant = (quadrant - 1) & 0x3;
|
||||
|
||||
/* Fixup value for the generic function */
|
||||
x += sin_off_tbl[quadrant];
|
||||
|
||||
/* Calculate the negative of the square of x */
|
||||
x2 = - (x * x);
|
||||
|
||||
/* This is an unrolled taylor series using <PRECISION> iterations
|
||||
* Example with 4 iterations:
|
||||
* result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8!
|
||||
* To save multiplications and to keep the precision high, it's performed
|
||||
* like this:
|
||||
* result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!))))
|
||||
*/
|
||||
|
||||
/* Start with 0, compiler will optimize this away */
|
||||
result = 0;
|
||||
|
||||
#if (PRECISION >= 10)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20);
|
||||
result *= x2;
|
||||
#endif
|
||||
#if (PRECISION >= 9)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18);
|
||||
result *= x2;
|
||||
#endif
|
||||
#if (PRECISION >= 8)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16);
|
||||
result *= x2;
|
||||
#endif
|
||||
#if (PRECISION >= 7)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14);
|
||||
result *= x2;
|
||||
#endif
|
||||
#if (PRECISION >= 6)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12);
|
||||
result *= x2;
|
||||
#endif
|
||||
#if (PRECISION >= 5)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10);
|
||||
result *= x2;
|
||||
#endif
|
||||
result += 1./(1.*2*3*4*5*6*7*8);
|
||||
result *= x2;
|
||||
|
||||
result += 1./(1.*2*3*4*5*6);
|
||||
result *= x2;
|
||||
|
||||
result += 1./(1.*2*3*4);
|
||||
result *= x2;
|
||||
|
||||
result += 1./(1.*2);
|
||||
result *= x2;
|
||||
|
||||
result += 1;
|
||||
|
||||
/* Apply correct sign */
|
||||
result *= sin_sign_tbl[quadrant];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
double cos(double x)
|
||||
{
|
||||
int quadrant;
|
||||
double x2, result;
|
||||
|
||||
/* Calculate the quadrant */
|
||||
quadrant = x * (2./M_PI);
|
||||
|
||||
/* Get offset inside quadrant */
|
||||
x = x - quadrant * (M_PI/2.);
|
||||
|
||||
/* Normalize quadrant to [0..3] */
|
||||
quadrant = quadrant & 0x3;
|
||||
|
||||
/* Fixup value for the generic function */
|
||||
x += cos_off_tbl[quadrant];
|
||||
|
||||
/* Calculate the negative of the square of x */
|
||||
x2 = - (x * x);
|
||||
|
||||
/* This is an unrolled taylor series using <PRECISION> iterations
|
||||
* Example with 4 iterations:
|
||||
* result = 1 - x^2/2! + x^4/4! - x^6/6! + x^8/8!
|
||||
* To save multiplications and to keep the precision high, it's performed
|
||||
* like this:
|
||||
* result = 1 - x^2 * (1/2! - x^2 * (1/4! - x^2 * (1/6! - x^2 * (1/8!))))
|
||||
*/
|
||||
|
||||
/* Start with 0, compiler will optimize this away */
|
||||
result = 0;
|
||||
|
||||
#if (PRECISION >= 10)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18*19*20);
|
||||
result *= x2;
|
||||
#endif
|
||||
#if (PRECISION >= 9)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16*17*18);
|
||||
result *= x2;
|
||||
#endif
|
||||
#if (PRECISION >= 8)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14*15*16);
|
||||
result *= x2;
|
||||
#endif
|
||||
#if (PRECISION >= 7)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12*13*14);
|
||||
result *= x2;
|
||||
#endif
|
||||
#if (PRECISION >= 6)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10*11*12);
|
||||
result *= x2;
|
||||
#endif
|
||||
#if (PRECISION >= 5)
|
||||
result += 1./(1.*2*3*4*5*6*7*8*9*10);
|
||||
result *= x2;
|
||||
#endif
|
||||
result += 1./(1.*2*3*4*5*6*7*8);
|
||||
result *= x2;
|
||||
|
||||
result += 1./(1.*2*3*4*5*6);
|
||||
result *= x2;
|
||||
|
||||
result += 1./(1.*2*3*4);
|
||||
result *= x2;
|
||||
|
||||
result += 1./(1.*2);
|
||||
result *= x2;
|
||||
|
||||
result += 1;
|
||||
|
||||
/* Apply correct sign */
|
||||
result *= cos_sign_tbl[quadrant];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef __MATH_H__
|
||||
#define __MATH_H__
|
||||
|
||||
#define M_PI 3.141592653589793238462643
|
||||
|
||||
double sin(double x);
|
||||
double cos(double x);
|
||||
|
||||
typedef float float_t;
|
||||
typedef double double_t;
|
||||
|
||||
#endif
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void exch(char* base,size_t size,size_t a,size_t b) {
|
||||
char* x=base+a*size;
|
||||
char* y=base+b*size;
|
||||
while (size) {
|
||||
char z=*x;
|
||||
*x=*y;
|
||||
*y=z;
|
||||
--size; ++x; ++y;
|
||||
}
|
||||
}
|
||||
|
||||
/* Quicksort with 3-way partitioning, ala Sedgewick */
|
||||
/* Blame him for the scary variable names */
|
||||
/* http://www.cs.princeton.edu/~rs/talks/QuicksortIsOptimal.pdf */
|
||||
static void quicksort(char* base,size_t size,ssize_t l,ssize_t r,
|
||||
int (*compar)(const void*,const void*)) {
|
||||
ssize_t i=l-1, j=r, p=l-1, q=r, k;
|
||||
char* v=base+r*size;
|
||||
if (r<=l) return;
|
||||
for (;;) {
|
||||
while (++i != r && compar(base+i*size,v)<0) ;
|
||||
while (compar(v,base+(--j)*size)<0) if (j == l) break;
|
||||
if (i >= j) break;
|
||||
exch(base,size,i,j);
|
||||
if (compar(base+i*size,v)==0) exch(base,size,++p,i);
|
||||
if (compar(v,base+j*size)==0) exch(base,size,j,--q);
|
||||
}
|
||||
exch(base,size,i,r); j = i-1; ++i;
|
||||
for (k=l; k<p; k++, j--) exch(base,size,k,j);
|
||||
for (k=r-1; k>q; k--, i++) exch(base,size,i,k);
|
||||
quicksort(base,size,l,j,compar);
|
||||
quicksort(base,size,i,r,compar);
|
||||
}
|
||||
|
||||
void qsort(void* base,size_t nmemb,size_t size,int (*compar)(const void*,const void*)) {
|
||||
/* check for integer overflows */
|
||||
if (nmemb >= (((size_t)-1)>>1) ||
|
||||
size >= (((size_t)-1)>>1)) return;
|
||||
if (nmemb>1)
|
||||
quicksort(base,size,0,nmemb-1,compar);
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
static unsigned int _seed=1;
|
||||
|
||||
/* Knuth's TAOCP section 3.6 */
|
||||
#define M ((1U<<31) -1)
|
||||
#define A 48271
|
||||
#define Q 44488 // M/A
|
||||
#define R 3399 // M%A; R < Q !!!
|
||||
|
||||
int rand_r(unsigned int* seed)
|
||||
{ int32_t X;
|
||||
|
||||
X = *seed;
|
||||
X = A*(X%Q) - R * (int32_t) (X/Q);
|
||||
if (X < 0)
|
||||
X += M;
|
||||
|
||||
*seed = X;
|
||||
return X;
|
||||
}
|
||||
|
||||
int rand(void) {
|
||||
return rand_r(&_seed);
|
||||
}
|
||||
|
||||
void srand(unsigned int i)
|
||||
{
|
||||
_seed=i;
|
||||
}
|
||||
|
||||
int random(void) __attribute__((alias("rand")));
|
||||
void srandom(unsigned int i) __attribute__((alias("srand")));
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017-09-12 Bernard The first version
|
||||
*/
|
||||
|
||||
#ifndef SIGNAL_H__
|
||||
#define SIGNAL_H__
|
||||
|
||||
#include <libc/libc_signal.h>
|
||||
|
||||
#define SIG_DFL ((_sig_func_ptr)0) /* Default action */
|
||||
#define SIG_IGN ((_sig_func_ptr)1) /* Ignore action */
|
||||
#define SIG_ERR ((_sig_func_ptr)-1) /* Error return */
|
||||
|
||||
#endif
|
||||
@@ -1,15 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef __STDDEF_H__
|
||||
#define __STDDEF_H__
|
||||
|
||||
#include <sys/types.h>
|
||||
typedef signed long ptrdiff_t;
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef __STDIO_H__
|
||||
#define __STDIO_H__
|
||||
|
||||
#define BUFSIZ 128
|
||||
#define EOF (-1)
|
||||
|
||||
#ifndef SEEK_SET
|
||||
#define SEEK_SET 0 /* set file offset to offset */
|
||||
#endif
|
||||
#ifndef SEEK_CUR
|
||||
#define SEEK_CUR 1 /* set file offset to current plus offset */
|
||||
#endif
|
||||
#ifndef SEEK_END
|
||||
#define SEEK_END 2 /* set file offset to EOF plus offset */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2008-08-14 Bernard the first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
|
||||
#include "stdlib.h"
|
||||
|
||||
int atoi(const char* s)
|
||||
{
|
||||
long int v=0;
|
||||
int sign=1;
|
||||
while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) s++;
|
||||
switch (*s)
|
||||
{
|
||||
case '-':
|
||||
sign=-1;
|
||||
case '+':
|
||||
++s;
|
||||
}
|
||||
while ((unsigned int) (*s - '0') < 10u)
|
||||
{
|
||||
v=v*10+*s-'0';
|
||||
++s;
|
||||
}
|
||||
return sign==-1?-v:v;
|
||||
}
|
||||
|
||||
long int atol(const char* s)
|
||||
{
|
||||
long int v=0;
|
||||
int sign=0;
|
||||
while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) ++s;
|
||||
switch (*s)
|
||||
{
|
||||
case '-': sign=-1;
|
||||
case '+': ++s;
|
||||
}
|
||||
while ((unsigned int) (*s - '0') < 10u)
|
||||
{
|
||||
v=v*10+*s-'0'; ++s;
|
||||
}
|
||||
return sign?-v:v;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
void *malloc(size_t size)
|
||||
{
|
||||
return rt_malloc(size);
|
||||
}
|
||||
|
||||
void free(void *ptr)
|
||||
{
|
||||
rt_free(ptr);
|
||||
}
|
||||
|
||||
void *realloc(void *ptr, size_t size)
|
||||
{
|
||||
return rt_realloc(ptr, size);
|
||||
}
|
||||
|
||||
void *calloc(size_t nelem, size_t elsize)
|
||||
{
|
||||
return rt_calloc(nelem, elsize);
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2008-08-14 Bernard the first version
|
||||
*/
|
||||
|
||||
#ifndef __STDLIB_H__
|
||||
#define __STDLIB_H__
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
|
||||
int atoi(const char *nptr);
|
||||
long int atol(const char *nptr);
|
||||
|
||||
int rand(void);
|
||||
int rand_r(unsigned int *seed);
|
||||
void srand(unsigned int seed);
|
||||
|
||||
void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
|
||||
|
||||
void *malloc(size_t size);
|
||||
void free(void *ptr);
|
||||
void *realloc(void *ptr, size_t size);
|
||||
void *calloc(size_t nelem, size_t elsize);
|
||||
void abort(void);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2008-08-14 Bernard the first version
|
||||
*/
|
||||
#ifndef __STRING_H__
|
||||
#define __STRING_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* replace for standard string library */
|
||||
#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC)
|
||||
|
||||
#define ZEROPAD (1 << 0) /* pad with zero */
|
||||
#define SIGN (1 << 1) /* unsigned/signed long */
|
||||
#define PLUS (1 << 2) /* show plus */
|
||||
#define SPACE (1 << 3) /* space if plus */
|
||||
#define LEFT (1 << 4) /* left justified */
|
||||
#define SPECIAL (1 << 5) /* 0x */
|
||||
#define LARGE (1 << 6) /* use 'ABCDEF' instead of 'abcdef' */
|
||||
|
||||
#define _U 0x01 /* upper */
|
||||
#define _L 0x02 /* lower */
|
||||
#define _D 0x04 /* digit */
|
||||
#define _C 0x08 /* cntrl */
|
||||
#define _P 0x10 /* punct */
|
||||
#define _S 0x20 /* white space (space/lf/tab) */
|
||||
#define _X 0x40 /* hex digit */
|
||||
#define _SP 0x80 /* hard space (0x20) */
|
||||
|
||||
void* memset(void *s, int c, size_t n);
|
||||
void* memcpy(void *dest, const void *src, size_t n);
|
||||
void* memmove(void *dest, const void *src, size_t n);
|
||||
int memcmp(const void *s1, const void *s2, size_t n);
|
||||
|
||||
int tolower(int c);
|
||||
int toupper(int c);
|
||||
|
||||
int strcmp (const char *s1, const char *s2);
|
||||
int strncmp(const char *cs,const char *ct, size_t count);
|
||||
int strcasecmp(const char *a, const char *b);
|
||||
int strncasecmp(const char *cs, const char *ct, size_t count);
|
||||
int sscanf(const char * buf, const char * fmt, ...);
|
||||
size_t strlen(const char *s);
|
||||
char *strstr(const char * s1,const char * s2);
|
||||
char *strcpy(char *dest, const char *src);
|
||||
char *strncpy(char *dest, const char *src, size_t n);
|
||||
size_t strlcpy(char *dst, const char *src, size_t siz);
|
||||
char *strncat(char *dest, const char *src, size_t count);
|
||||
char *strcat(char * dest, const char * src);
|
||||
char *strchr(const char *s1, int i);
|
||||
char *strrchr(const char *t, int c);
|
||||
char *strdup(const char *s);
|
||||
char *strtok(char *s, const char *delim);
|
||||
char*strtok_r(char*s, const char*delim, char**ptrptr);
|
||||
|
||||
size_t strcspn(const char *s, const char *reject);
|
||||
size_t strspn (const char *s, const char *accept);
|
||||
|
||||
long strtol(const char *str, char **endptr, int base);
|
||||
long long strtoll(const char *str, char **endptr, int base);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef __STAT_H__
|
||||
#define __STAT_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef RT_USING_DFS
|
||||
#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
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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 <sys/types.h>
|
||||
typedef long time_t;
|
||||
|
||||
/*
|
||||
* Structure returned by gettimeofday(2) system call,
|
||||
* and used in other calls.
|
||||
*/
|
||||
struct timeval {
|
||||
long tv_sec; /* seconds */
|
||||
long tv_usec; /* and microseconds */
|
||||
};
|
||||
|
||||
/*
|
||||
* Structure defined by POSIX.1b to be like a timeval.
|
||||
*/
|
||||
struct timespec {
|
||||
time_t tv_sec; /* seconds */
|
||||
long tv_nsec; /* and nanoseconds */
|
||||
};
|
||||
|
||||
struct timezone {
|
||||
int tz_minuteswest; /* minutes west of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
|
||||
struct tm {
|
||||
int tm_sec; /* Seconds. [0-60] (1 leap second) */
|
||||
int tm_min; /* Minutes. [0-59] */
|
||||
int tm_hour; /* Hours. [0-23] */
|
||||
int tm_mday; /* Day. [1-31] */
|
||||
int tm_mon; /* Month. [0-11] */
|
||||
int tm_year; /* Year - 1900. */
|
||||
int tm_wday; /* Day of week. [0-6] */
|
||||
int tm_yday; /* Days in year.[0-365] */
|
||||
int tm_isdst; /* DST. [-1/0/1]*/
|
||||
|
||||
long int tm_gmtoff; /* Seconds east of UTC. */
|
||||
const char *tm_zone; /* Timezone abbreviation. */
|
||||
};
|
||||
|
||||
int gettimeofday(struct timeval *tp, void *ignore);
|
||||
|
||||
#endif
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* 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 <rtconfig.h>
|
||||
|
||||
typedef long off_t;
|
||||
|
||||
#ifndef ARCH_CPU_64BIT
|
||||
typedef unsigned int size_t;
|
||||
typedef signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
#else
|
||||
typedef long unsigned int size_t;
|
||||
typedef long signed int ssize_t; /* Used for a count of bytes or an error indication. */
|
||||
#endif
|
||||
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned short u_short;
|
||||
typedef unsigned int u_int;
|
||||
typedef unsigned long u_long;
|
||||
|
||||
typedef unsigned long clockid_t;
|
||||
typedef int pid_t;
|
||||
|
||||
typedef int gid_t;
|
||||
typedef int uid_t;
|
||||
typedef int dev_t;
|
||||
typedef int ino_t;
|
||||
typedef int mode_t;
|
||||
typedef int caddr_t;
|
||||
|
||||
typedef unsigned int wint_t;
|
||||
typedef unsigned long useconds_t;
|
||||
|
||||
typedef unsigned long clock_t; /* clock() */
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL (0)
|
||||
#endif
|
||||
|
||||
#define __u_char_defined
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
#ifndef __TIME_H__
|
||||
#define __TIME_H__
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
time_t mktime(struct tm * const t);
|
||||
|
||||
char *asctime(const struct tm *timeptr);
|
||||
char *ctime(const time_t *timep);
|
||||
struct tm* localtime(const time_t* t);
|
||||
|
||||
char *asctime_r(const struct tm *t, char *buf);
|
||||
struct tm *gmtime_r(const time_t *timep, struct tm *r);
|
||||
struct tm* localtime_r(const time_t* t, struct tm* r);
|
||||
|
||||
#endif
|
||||
@@ -1,21 +1,30 @@
|
||||
from building import *
|
||||
Import('rtconfig')
|
||||
|
||||
src = Glob('*.c')
|
||||
src = []
|
||||
cwd = GetCurrentDir()
|
||||
group = []
|
||||
|
||||
CPPPATH = [cwd]
|
||||
CPPDEFINES = ['RT_USING_NEWLIB']
|
||||
|
||||
# link with libc and libm:
|
||||
# libm is a frequently used lib. Newlib is compiled with -ffunction-sections in
|
||||
# recent GCC tool chains. The linker would just link in the functions that have
|
||||
# been referenced. So setting this won't result in bigger text size.
|
||||
LIBS = ['c', 'm']
|
||||
|
||||
if rtconfig.PLATFORM == 'gcc':
|
||||
group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'],
|
||||
CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
|
||||
if GetDepend('RT_USING_LIBC'):
|
||||
CPPDEFINES = ['RT_USING_NEWLIB']
|
||||
# link with libc and libm:
|
||||
# libm is a frequently used lib. Newlib is compiled with -ffunction-sections in
|
||||
# recent GCC tool chains. The linker would just link in the functions that have
|
||||
# been referenced. So setting this won't result in bigger text size.
|
||||
LIBS = ['c', 'm']
|
||||
|
||||
src += Glob('*.c')
|
||||
SrcRemove(src, ['minilib.c'])
|
||||
if GetDepend('RT_USING_MODULE') == False:
|
||||
SrcRemove(src, ['libc_syms.c'])
|
||||
else:
|
||||
src += ['minilib.c']
|
||||
CPPDEFINES = []
|
||||
LIBS = []
|
||||
|
||||
group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS)
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2021-02-23 Meco Man first version
|
||||
*/
|
||||
|
||||
#include <reent.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
|
||||
{
|
||||
/* no use this routine to get memory */
|
||||
return RT_NULL;
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
* 2021-02-11 Meco Man remove _gettimeofday_r() and _times_r()
|
||||
* 2020-02-13 Meco Man re-implement exit() and abort()
|
||||
* 2020-02-21 Meco Man improve and beautify syscalls
|
||||
* 2020-02-24 Meco Man fix bug of _isatty_r()
|
||||
*/
|
||||
|
||||
#include <reent.h>
|
||||
@@ -89,12 +90,14 @@ int
|
||||
_isatty_r(struct _reent *ptr, int fd)
|
||||
{
|
||||
if (fd >=0 && fd < 3)
|
||||
{
|
||||
return 1;
|
||||
|
||||
ptr->_errno = ENOTTY ;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
_kill_r(struct _reent *ptr, int pid, int sig)
|
||||
{
|
||||
|
||||
@@ -66,7 +66,7 @@ typedef uintptr_t mem_ptr_t;
|
||||
#endif /* __CC_ARM/__IAR_SYSTEMS_ICC__ */
|
||||
#endif
|
||||
|
||||
#if defined(RT_USING_LIBC) || defined(RT_USING_MINILIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
|
||||
#if defined(RT_USING_LIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
|
||||
#include <sys/time.h>
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#else
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
#define S32_F "ld"
|
||||
#define X32_F "lx"
|
||||
|
||||
#if defined(RT_USING_LIBC) || defined(RT_USING_MINILIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
|
||||
#if defined(RT_USING_LIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
|
||||
#include <sys/time.h>
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#else
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
#endif /* __CC_ARM/__IAR_SYSTEMS_ICC__ */
|
||||
#endif /* RT_USING_LIBC */
|
||||
|
||||
#if defined(RT_USING_LIBC) || defined(RT_USING_MINILIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
|
||||
#if defined(RT_USING_LIBC) || defined(RT_LIBC_USING_TIME) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION))
|
||||
#include <sys/time.h>
|
||||
#define LWIP_TIMEVAL_PRIVATE 0
|
||||
#else
|
||||
|
||||
@@ -77,6 +77,14 @@ int netdev_register(struct netdev *netdev, const char *name, void *user_data)
|
||||
netdev->status_callback = RT_NULL;
|
||||
netdev->addr_callback = RT_NULL;
|
||||
|
||||
if(rt_strlen(name) > RT_NAME_MAX)
|
||||
{
|
||||
char netdev_name[RT_NAME_MAX + 1] = {0};
|
||||
|
||||
rt_strncpy(netdev_name, name, RT_NAME_MAX);
|
||||
LOG_E("netdev name[%s] length is so long that have been cut into [%s].", name, netdev_name);
|
||||
}
|
||||
|
||||
/* fill network interface device */
|
||||
rt_strncpy(netdev->name, name, RT_NAME_MAX);
|
||||
netdev->user_data = user_data;
|
||||
@@ -260,7 +268,7 @@ struct netdev *netdev_get_by_name(const char *name)
|
||||
for (node = &(netdev_list->list); node; node = rt_slist_next(node))
|
||||
{
|
||||
netdev = rt_slist_entry(node, struct netdev, list);
|
||||
if (netdev && (rt_strncmp(netdev->name, name, RT_NAME_MAX) == 0))
|
||||
if (netdev && (rt_strncmp(netdev->name, name, rt_strlen(netdev->name) < RT_NAME_MAX ? rt_strlen(netdev->name) : RT_NAME_MAX) == 0))
|
||||
{
|
||||
rt_hw_interrupt_enable(level);
|
||||
return netdev;
|
||||
|
||||
@@ -1386,26 +1386,4 @@ void rt_assert_handler(const char *ex_string, const char *func, rt_size_t line)
|
||||
RTM_EXPORT(rt_assert_handler);
|
||||
#endif /* RT_DEBUG */
|
||||
|
||||
#if !defined (RT_USING_NEWLIB) && defined (RT_USING_MINILIBC) && defined (__GNUC__)
|
||||
#include <sys/types.h>
|
||||
void *memcpy(void *dest, const void *src, size_t n) __attribute__((weak, alias("rt_memcpy")));
|
||||
void *memset(void *s, int c, size_t n) __attribute__((weak, alias("rt_memset")));
|
||||
void *memmove(void *dest, const void *src, size_t n) __attribute__((weak, alias("rt_memmove")));
|
||||
int memcmp(const void *s1, const void *s2, size_t n) __attribute__((weak, alias("rt_memcmp")));
|
||||
|
||||
size_t strlen(const char *s) __attribute__((weak, alias("rt_strlen")));
|
||||
char *strstr(const char *s1, const char *s2) __attribute__((weak, alias("rt_strstr")));
|
||||
int strcasecmp(const char *a, const char *b) __attribute__((weak, alias("rt_strcasecmp")));
|
||||
char *strncpy(char *dest, const char *src, size_t n) __attribute__((weak, alias("rt_strncpy")));
|
||||
int strncmp(const char *cs, const char *ct, size_t count) __attribute__((weak, alias("rt_strncmp")));
|
||||
#ifdef RT_USING_HEAP
|
||||
char *strdup(const char *s) __attribute__((weak, alias("rt_strdup")));
|
||||
#endif
|
||||
|
||||
int sprintf(char *buf, const char *format, ...) __attribute__((weak, alias("rt_sprintf")));
|
||||
int snprintf(char *buf, rt_size_t size, const char *fmt, ...) __attribute__((weak, alias("rt_snprintf")));
|
||||
int vsprintf(char *buf, const char *format, va_list arg_ptr) __attribute__((weak, alias("rt_vsprintf")));
|
||||
|
||||
#endif
|
||||
|
||||
/**@}*/
|
||||
+2
-13
@@ -382,19 +382,8 @@ rt_err_t rt_thread_detach(rt_thread_t thread)
|
||||
/* change stat */
|
||||
thread->stat = RT_THREAD_CLOSE;
|
||||
|
||||
if (rt_object_is_systemobject((rt_object_t)thread) == RT_TRUE)
|
||||
{
|
||||
rt_object_detach((rt_object_t)thread);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* disable interrupt */
|
||||
lock = rt_hw_interrupt_disable();
|
||||
/* insert to defunct thread list */
|
||||
rt_list_insert_after(&rt_thread_defunct, &(thread->tlist));
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(lock);
|
||||
}
|
||||
/* detach thread object */
|
||||
rt_object_detach((rt_object_t)thread);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
+1
-1
@@ -233,7 +233,7 @@ rt_err_t rt_timer_detach(rt_timer_t timer)
|
||||
/* enable interrupt */
|
||||
rt_hw_interrupt_enable(level);
|
||||
|
||||
rt_object_detach((rt_object_t)timer);
|
||||
rt_object_detach(&(timer->parent));
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user