From 3ef523714f9e69771b5288c4c922218edbed2a36 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Thu, 10 Jan 2013 14:58:07 +0800 Subject: [PATCH 1/8] remove math code for newlib Newlib already have optimized and full featured math implementation. To use it, one should add: env['LIBS'] = ['m'] or equivalent to the SConstruct. --- components/libc/newlib/math.c | 260 ---------------------------------- 1 file changed, 260 deletions(-) delete mode 100644 components/libc/newlib/math.c diff --git a/components/libc/newlib/math.c b/components/libc/newlib/math.c deleted file mode 100644 index 61418f25f3..0000000000 --- a/components/libc/newlib/math.c +++ /dev/null @@ -1,260 +0,0 @@ -#include - -/* - * 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 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 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; -} - -static const int N = 100; - -double coef(int n) -{ - double t; - - if (n == 0) - { - return 0; - } - - t = 1.0/n; - - if (n%2 == 0) - { - t = -t; - } - - return t; -} - -double horner(double x) -{ - double u = coef(N); - int i; - - for(i=N-1; i>=0; i--) - { - u = u*x + coef(i); - } - - return u; -} - -double sqrt(double b) -{ - double x = 1; - int step = 0; - - while ((x*x-b<-0.000000000000001 || x*x-b>0.000000000000001) && step<50) - { - x = (b/x+x)/2.0; - step++; - } - return x; -} - -double ln(double x) -{ - int i; - - if (x > 1.5) - { - for(i=0; x>1.25; i++) - { - x = sqrt(x); - } - return (1<0) - { - for(i=0; x<0.7; i++) - { - x = sqrt(x); - } - return (1< 0) - { - return horner(x-1); - } -} - -double exp(double x) -{ - double sum = 1; - int i; - - for(i=N; i>0; i--) - { - sum /= i; - sum *= x; - sum += 1; - } - return sum; -} - -double pow(double m, double n) -{ - return exp(n*ln(m)); -} - From 8ad12057c43b2f08be4578b51f8990296646706a Mon Sep 17 00:00:00 2001 From: Grissiom Date: Fri, 11 Jan 2013 15:13:11 +0800 Subject: [PATCH 2/8] Newlib: link with libm in default. 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. --- components/libc/newlib/SConscript | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/components/libc/newlib/SConscript b/components/libc/newlib/SConscript index 28d66bc0fe..6516840adf 100644 --- a/components/libc/newlib/SConscript +++ b/components/libc/newlib/SConscript @@ -11,6 +11,12 @@ cwd = GetCurrentDir() src = Glob('*.c') CPPPATH = [cwd] +# link with libm in default. +# 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. +Env.Append(LIBS = ['m']) + group = DefineGroup('newlib', src, depend = ['RT_USING_NEWLIB'], CPPPATH = CPPPATH) Return('group') From 9168e18e5cb9589e79752f04b3da911fb9758bf0 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Sun, 13 Jan 2013 09:48:37 +0800 Subject: [PATCH 3/8] newlib: use the LIBS argument in DefineGroup instead of modifying the Env --- components/libc/newlib/SConscript | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/libc/newlib/SConscript b/components/libc/newlib/SConscript index 6516840adf..a3ddbe9f4d 100644 --- a/components/libc/newlib/SConscript +++ b/components/libc/newlib/SConscript @@ -15,8 +15,9 @@ CPPPATH = [cwd] # 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. -Env.Append(LIBS = ['m']) +LIBS = ['m'] -group = DefineGroup('newlib', src, depend = ['RT_USING_NEWLIB'], CPPPATH = CPPPATH) +group = DefineGroup('newlib', src, depend = ['RT_USING_NEWLIB'], + CPPPATH = CPPPATH, LIBS = LIBS) Return('group') From 9721603b72121566b6c0b42c5f39ce9c2599121f Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 17 Jan 2013 10:06:01 +0800 Subject: [PATCH 4/8] Add RT_MTD_ESRC definitions. Add RT_MTD_ESRC definitions. If the source page has issue when copying a page, the low level can return this error code. --- components/drivers/include/drivers/mtd_nand.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/components/drivers/include/drivers/mtd_nand.h b/components/drivers/include/drivers/mtd_nand.h index 45c3016e5c..fdcece3a57 100644 --- a/components/drivers/include/drivers/mtd_nand.h +++ b/components/drivers/include/drivers/mtd_nand.h @@ -25,11 +25,12 @@ struct rt_mtd_nand_driver_ops; #define RT_MTD_NAND_DEVICE(device) ((struct rt_mtd_nand_device*)(device)) -#define RT_MTD_EOK 0 -#define RT_MTD_EECC 1 -#define RT_MTD_EBUSY 2 -#define RT_MTD_EIO 3 -#define RT_MTD_ENOMEM 4 +#define RT_MTD_EOK 0 /* NO error */ +#define RT_MTD_EECC 1 /* ECC error */ +#define RT_MTD_EBUSY 2 /* hardware busy */ +#define RT_MTD_EIO 3 /* generic IO issue */ +#define RT_MTD_ENOMEM 4 /* out of memory */ +#define RT_MTD_ESRC 5 /* source issue */ struct rt_mtd_nand_device { From a3bde3c4a364a2648f626eaab6b79f6e74535525 Mon Sep 17 00:00:00 2001 From: heyuanjie87 Date: Thu, 17 Jan 2013 12:23:06 +0800 Subject: [PATCH 5/8] handle standard request to interface that defined in class --- components/drivers/usb/usbdevice/core/core.c | 43 ++++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/components/drivers/usb/usbdevice/core/core.c b/components/drivers/usb/usbdevice/core/core.c index c0f21a1cd4..ea4efde2d7 100644 --- a/components/drivers/usb/usbdevice/core/core.c +++ b/components/drivers/usb/usbdevice/core/core.c @@ -355,6 +355,38 @@ static rt_err_t _set_address(struct udevice* device, ureq_t setup) return RT_EOK; } +/** + * This function will handle standard request to + * interface that defined in class-specifics + * + * @param device the usb device object. + * @param setup the setup request. + * + * @return RT_EOK on successful. + */ +static rt_err_t _request_interface(struct udevice* device, ureq_t setup) +{ + uintf_t intf; + uclass_t cls; + rt_err_t ret; + + /* parameter check */ + RT_ASSERT(device != RT_NULL); + RT_ASSERT(setup != RT_NULL); + + RT_DEBUG_LOG(RT_DEBUG_USB, ("_request_interface\n")); + + intf = rt_usbd_find_interface(device, setup->index & 0xFF, &cls); + if (intf != RT_NULL) + { + ret = intf->handler(device, cls, setup); + } + else + ret = -RT_ERROR; + + return ret; +} + /** * This function will handle standard request. * @@ -419,9 +451,14 @@ static rt_err_t _standard_request(struct udevice* device, ureq_t setup) _set_interface(device, setup); break; default: - rt_kprintf("unknown interface request\n"); - dcd_ep_stall(device->dcd, 0); - break; + if (_request_interface(device, setup) != RT_EOK) + { + rt_kprintf("unknown interface request\n"); + dcd_ep_stall(device->dcd, 0); + return - RT_ERROR; + } + else + break; } break; case USB_REQ_TYPE_ENDPOINT: From 7ce0547575e11cb9ce94f86fcce3709d060dcc00 Mon Sep 17 00:00:00 2001 From: heyuanjie87 Date: Thu, 17 Jan 2013 14:03:45 +0800 Subject: [PATCH 6/8] fixed the string descriptor send to host more than actual --- components/drivers/usb/usbdevice/core/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/drivers/usb/usbdevice/core/core.c b/components/drivers/usb/usbdevice/core/core.c index ea4efde2d7..9f1738ed33 100644 --- a/components/drivers/usb/usbdevice/core/core.c +++ b/components/drivers/usb/usbdevice/core/core.c @@ -124,7 +124,7 @@ static rt_err_t _get_string_descriptor(struct udevice* device, ureq_t setup) } } - if(setup->length == 0xFF) + if(setup->length > len) len = str_desc.bLength; else len = setup->length; From 0001344105054ed6c09184db96c1b04eb882fdd0 Mon Sep 17 00:00:00 2001 From: Grissiom Date: Thu, 17 Jan 2013 16:00:19 +0800 Subject: [PATCH 7/8] more deterministic on timer If two timer will timeout at the same tick, the one started later will be called later. I've tested the patch on simulator and it _seems_ OK. Reported-by: xdzy on the forum and delin17 --- src/timer.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/timer.c b/src/timer.c index a1699dad63..2a27d9d9a8 100644 --- a/src/timer.c +++ b/src/timer.c @@ -273,12 +273,18 @@ rt_err_t rt_timer_start(rt_timer_t timer) for (n = timer_list->next; n != timer_list; n = n->next) { t = rt_list_entry(n, struct rt_timer, list); - + /* * It supposes that the new tick shall less than the half duration of - * tick max. + * tick max. And if we have two timers that timeout at the same time, + * it's prefered that the timer inserted early get called early. */ - if ((t->timeout_tick - timer->timeout_tick) < RT_TICK_MAX / 2) + if ((t->timeout_tick - timer->timeout_tick) == 0) + { + rt_list_insert_after(n, &(timer->list)); + break; + } + else if ((t->timeout_tick - timer->timeout_tick) < RT_TICK_MAX / 2) { rt_list_insert_before(n, &(timer->list)); break; From 5d68ef8ec1254ec766a3aeb743e164020233e59c Mon Sep 17 00:00:00 2001 From: prife Date: Tue, 22 Jan 2013 12:44:47 +0800 Subject: [PATCH 8/8] fix bug in finsh when built with 64bit-gcc --- components/finsh/cmd.c | 8 ++++++-- components/finsh/finsh.h | 15 +++++++++++++-- components/finsh/finsh_var.c | 4 +++- components/finsh/finsh_vm.c | 12 +++++++++++- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index b4b8712b02..84a0a6f123 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -623,7 +623,9 @@ long list(void) rt_kprintf("--Variable List:\n"); { struct finsh_sysvar *index; - for (index = _sysvar_table_begin; index < _sysvar_table_end; index ++) + for (index = _sysvar_table_begin; + index < _sysvar_table_end; + FINSH_NEXT_SYSVAR(index)) { #ifdef FINSH_USING_DESCRIPTION rt_kprintf("%-16s -- %s\n", index->name, index->desc); @@ -761,7 +763,9 @@ void list_prefix(char *prefix) /* checks in system variable */ { struct finsh_sysvar* index; - for (index = _sysvar_table_begin; index < _sysvar_table_end; index ++) + for (index = _sysvar_table_begin; + index < _sysvar_table_end; + FINSH_NEXT_SYSVAR(index)) { if (str_is_prefix(prefix, index->name) == 0) { diff --git a/components/finsh/finsh.h b/components/finsh/finsh.h index 994509bd64..85e32b9fb8 100644 --- a/components/finsh/finsh.h +++ b/components/finsh/finsh.h @@ -64,8 +64,16 @@ typedef unsigned char u_char; typedef unsigned short u_short; typedef unsigned long u_long; -#if !defined(__CC_ARM) && !defined(__IAR_SYSTEMS_ICC__) && !defined(__ADSPBLACKFIN__) && !defined(_MSC_VER) +#if !defined(__CC_ARM) && \ + !defined(__IAR_SYSTEMS_ICC__) && \ + !defined(__ADSPBLACKFIN__) && \ + !defined(_MSC_VER) + +#if !(defined(__GNUC__) && defined(__x86_64__)) typedef unsigned int size_t; +#else +#include +#endif #ifndef NULL #define NULL RT_NULL @@ -148,11 +156,14 @@ struct finsh_sysvar void* var ; /* the address of variable */ }; -#if defined(_MSC_VER) +#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) struct finsh_syscall* finsh_syscall_next(struct finsh_syscall* call); +struct finsh_sysvar* finsh_sysvar_next(struct finsh_sysvar* call); #define FINSH_NEXT_SYSCALL(index) index=finsh_syscall_next(index) +#define FINSH_NEXT_SYSVAR(index) index=finsh_sysvar_next(index) #else #define FINSH_NEXT_SYSCALL(index) index++ +#define FINSH_NEXT_SYSVAR(index) index++ #endif /* system variable item */ diff --git a/components/finsh/finsh_var.c b/components/finsh/finsh_var.c index 96f1244210..8429f6f21c 100644 --- a/components/finsh/finsh_var.c +++ b/components/finsh/finsh_var.c @@ -121,7 +121,9 @@ struct finsh_sysvar* finsh_sysvar_lookup(const char* name) struct finsh_sysvar* index; struct finsh_sysvar_item* item; - for (index = _sysvar_table_begin; index < _sysvar_table_end; index ++) + for (index = _sysvar_table_begin; + index < _sysvar_table_end; + FINSH_NEXT_SYSVAR(index)) { if (strcmp(index->name, name) == 0) return index; diff --git a/components/finsh/finsh_vm.c b/components/finsh/finsh_vm.c index 845eb48919..6b24b70f24 100644 --- a/components/finsh/finsh_vm.c +++ b/components/finsh/finsh_vm.c @@ -83,7 +83,7 @@ void finsh_syscall_append(const char* name, syscall_func func) } #endif -#ifdef _MSC_VER +#if defined(_MSC_VER) || (defined(__GNUC__) && defined(__x86_64__)) struct finsh_syscall* finsh_syscall_next(struct finsh_syscall* call) { unsigned int *ptr; @@ -93,6 +93,16 @@ struct finsh_syscall* finsh_syscall_next(struct finsh_syscall* call) return (struct finsh_syscall*)ptr; } + +struct finsh_sysvar* finsh_sysvar_next(struct finsh_sysvar* call) +{ + unsigned int *ptr; + ptr = (unsigned int*) (call + 1); + while ((*ptr == 0) && ((unsigned int*)ptr < (unsigned int*) _sysvar_table_end)) + ptr ++; + + return (struct finsh_sysvar*)ptr; +} #endif struct finsh_syscall* finsh_syscall_lookup(const char* name)