diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-11 21:16:56 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-11 21:16:56 +0000 |
commit | 7e354ad57b4d040ab88e2eeb4ac84240e65e0e52 (patch) | |
tree | a8d9734a0a38870239e613c63c3e066b36221b18 | |
parent | 6877a8efaf6edad7dcff6412c1eb03973d080247 (diff) | |
download | px4-nuttx-7e354ad57b4d040ab88e2eeb4ac84240e65e0e52.tar.gz px4-nuttx-7e354ad57b4d040ab88e2eeb4ac84240e65e0e52.tar.bz2 px4-nuttx-7e354ad57b4d040ab88e2eeb4ac84240e65e0e52.zip |
Fixed 8051 printf bug
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@57 42af7a65-404d-4744-a932-0658087f49c3
-rw-r--r-- | nuttx/arch/pjrc-8051/README.txt | 5 | ||||
-rw-r--r-- | nuttx/arch/pjrc-8051/defconfig | 3 | ||||
-rw-r--r-- | nuttx/arch/pjrc-8051/include/arch.h | 7 | ||||
-rw-r--r-- | nuttx/arch/pjrc-8051/include/irq.h | 4 | ||||
-rw-r--r-- | nuttx/arch/pjrc-8051/sdcc-2.6.0.patch | 17 | ||||
-rw-r--r-- | nuttx/arch/pjrc-8051/src/up_debug.c | 25 | ||||
-rw-r--r-- | nuttx/arch/pjrc-8051/src/up_initialstate.c | 5 | ||||
-rw-r--r-- | nuttx/arch/pjrc-8051/src/up_internal.h | 5 | ||||
-rw-r--r-- | nuttx/examples/ostest/main.c | 73 | ||||
-rw-r--r-- | nuttx/sched/task_create.c | 2 |
10 files changed, 120 insertions, 26 deletions
diff --git a/nuttx/arch/pjrc-8051/README.txt b/nuttx/arch/pjrc-8051/README.txt index 0b73373d3..dae92b59b 100644 --- a/nuttx/arch/pjrc-8051/README.txt +++ b/nuttx/arch/pjrc-8051/README.txt @@ -21,7 +21,10 @@ compatible with this build. First start with the usual steps ./configure make -But before installing, +But before installing, we need to apply a patch to the SDCC 2.6.0 source. +WARNING: This patch is specific to the particular combination of CFLAGS +that are used in the compilation. If you change Make.defs, then you will +likely have to change the patch as well. Apply sdcc-2.6.0.patch cd sdcc/device/lib diff --git a/nuttx/arch/pjrc-8051/defconfig b/nuttx/arch/pjrc-8051/defconfig index 2d7222305..28044f43f 100644 --- a/nuttx/arch/pjrc-8051/defconfig +++ b/nuttx/arch/pjrc-8051/defconfig @@ -40,7 +40,8 @@ # CONFIG_PJRC_LEDS - Use LEDs to show state. Unique to 8051. # CONFIG_ARCH=pjrc-8051 -CONFIG_ARCH_8051=y +CONFIG_ARCH_8052=y +CONFIG_ARCH_PJRC=y CONFIG_8051_LEDS=n # diff --git a/nuttx/arch/pjrc-8051/include/arch.h b/nuttx/arch/pjrc-8051/include/arch.h index b61ce916a..f7d2b956c 100644 --- a/nuttx/arch/pjrc-8051/include/arch.h +++ b/nuttx/arch/pjrc-8051/include/arch.h @@ -67,6 +67,13 @@ extern "C" { #define EXTERN extern #endif +/* The 805x family has a tiny, 256 stack and can be easily + * overflowed. The following macro can be used to instrument + * code to dump the stack pointer at critical locations. + */ + +EXTERN void up_showsp(ubyte ch) __naked; + #undef EXTERN #ifdef __cplusplus } diff --git a/nuttx/arch/pjrc-8051/include/irq.h b/nuttx/arch/pjrc-8051/include/irq.h index 8ca78adc8..819a73df7 100644 --- a/nuttx/arch/pjrc-8051/include/irq.h +++ b/nuttx/arch/pjrc-8051/include/irq.h @@ -44,6 +44,8 @@ * Included Files ************************************************************/ +#include <nuttx/config.h> + /************************************************************ * Definitions ************************************************************/ @@ -65,7 +67,7 @@ #define IRAM_BASE 0x0000 #define IRAM_SIZE 0x0100 -#define STACK_BASE 0x0030 +#define STACK_BASE 0x0024 #define STACK_SIZE (IRAM_SIZE - STACK_BASE) /* This is the form of initial stack frame diff --git a/nuttx/arch/pjrc-8051/sdcc-2.6.0.patch b/nuttx/arch/pjrc-8051/sdcc-2.6.0.patch index e518dab0a..beb8bf2ea 100644 --- a/nuttx/arch/pjrc-8051/sdcc-2.6.0.patch +++ b/nuttx/arch/pjrc-8051/sdcc-2.6.0.patch @@ -1,3 +1,4 @@ +diff -u sdcc/device/lib/Makefile.orig sdcc/device/lib/Makefile --- sdcc/device/lib/Makefile.orig 2007-03-06 09:55:01.000000000 -0600 +++ sdcc/device/lib/Makefile 2007-03-06 09:58:32.000000000 -0600 @@ -242,7 +242,7 @@ @@ -9,3 +10,19 @@ done \ fi +diff -u sdcc/device/include/stdarg.h.orig sdcc/device/include/stdarg.h +--- sdcc/device/include/stdarg.h.orig 2007-03-11 13:21:15.000000000 -0600 ++++ sdcc/device/include/stdarg.h 2007-03-11 13:26:59.000000000 -0600 +@@ -25,9 +25,9 @@ + + #else + +-typedef unsigned char __data * va_list ; +-#define va_arg(marker,type) *((type __data * )(marker -= sizeof(type))) +-#define va_start(marker,first) { marker = (va_list) ((char __data * )&first); } ++typedef unsigned char * va_list ; ++#define va_arg(marker,type) *((type * )(marker -= sizeof(type))) ++#define va_start(marker,first) { marker = (va_list) ((char * )&first); } + + #endif + diff --git a/nuttx/arch/pjrc-8051/src/up_debug.c b/nuttx/arch/pjrc-8051/src/up_debug.c index 6f59f488b..6f1485aaa 100644 --- a/nuttx/arch/pjrc-8051/src/up_debug.c +++ b/nuttx/arch/pjrc-8051/src/up_debug.c @@ -160,3 +160,28 @@ void up_dumpframe(FAR struct xcptcontext *context) _up_dump8(" PSW ", start[FRAME_PSW]); } #endif + +/************************************************************ + * Name: up_dumpframe + ************************************************************/ + +/* The 805x family has a tiny, 256 stack and can be easily + * overflowed. The following macro can be used to instrument + * code to dump the stack pointer at critical locations. + */ + +#ifdef CONFIG_ARCH_PJRC +void up_showsp(ubyte ch) __naked +{ + ch; + _asm + mov a, dpl + lcall PM2_ENTRY_COUT + mov a, sp + lcall PM2_ENTRY_PHEX + lcall PM2_ENTRY_NEWLINE + _endasm; +} +#endif + + diff --git a/nuttx/arch/pjrc-8051/src/up_initialstate.c b/nuttx/arch/pjrc-8051/src/up_initialstate.c index 930f16873..1eae39fa9 100644 --- a/nuttx/arch/pjrc-8051/src/up_initialstate.c +++ b/nuttx/arch/pjrc-8051/src/up_initialstate.c @@ -96,10 +96,7 @@ void up_initial_state(FAR _TCB *tcb) frame[FRAME_RETLS] = (((uint16)tcb->start) & 0xff); frame[FRAME_RETMS] = (((uint16)tcb->start) >> 8); - /* Then the context save area which can be indexed with - * the following definitions (relative to the beginning of - * the initial frame. - */ + /* The context save area follows the return address. */ frame[FRAME_IE] = 0x80; frame[FRAME_PSW] = 0; diff --git a/nuttx/arch/pjrc-8051/src/up_internal.h b/nuttx/arch/pjrc-8051/src/up_internal.h index 95fb97745..19c628f5c 100644 --- a/nuttx/arch/pjrc-8051/src/up_internal.h +++ b/nuttx/arch/pjrc-8051/src/up_internal.h @@ -40,7 +40,10 @@ * Included Files **************************************************************************/ -#include "pjrc.h" +#include <nuttx/config.h> +#ifdef CONFIG_ARCH_PJRC +# include "pjrc.h" +#endif /************************************************************************** * Public Definitions diff --git a/nuttx/examples/ostest/main.c b/nuttx/examples/ostest/main.c index c68aaee89..8272103a5 100644 --- a/nuttx/examples/ostest/main.c +++ b/nuttx/examples/ostest/main.c @@ -59,21 +59,35 @@ * Private Data ************************************************************/ -static FAR char arg1[] = "Arg1"; -static FAR char arg2[] = "Arg2"; -static FAR char arg3[] = "Arg3"; -static FAR char arg4[] = "Arg4"; +static const char arg1[] = "Arg1"; +static const char arg2[] = "Arg2"; +static const char arg3[] = "Arg3"; +static const char arg4[] = "Arg4"; #if CONFIG_NFILE_DESCRIPTORS > 0 -static char write_data1[] = "Standard I/O Check: write fd=1\n"; -static char write_data2[] = "Standard I/O Check: write fd=2\n"; +static const char write_data1[] = "stdio_test: write fd=1\n"; +static const char write_data2[] = "stdio_test: write fd=2\n"; +#endif + +#ifdef SDCC +/* I am not yet certain why SDCC does not like the following + * initializer. It involves some issues with 2- vs 3-byte + * pointer types. + */ + +static const char *g_argv[NARGS+1]; +#else +static const char *g_argv[NARGS+1] = { arg1, arg2, arg3, arg4, NULL }; #endif -static const char *g_argv[NARGS] = { arg1, arg2, arg3, arg4 }; /************************************************************ * Private Functions ************************************************************/ +/************************************************************ + * Name: user_main + ************************************************************/ + static int user_main(int argc, char *argv[]) { int i; @@ -90,7 +104,7 @@ static int user_main(int argc, char *argv[]) for (i = 0; i <= NARGS; i++) { - printf("user_main: argv[%d]=\"%s\"\n", i, (FAR char*)argv[i]); + printf("user_main: argv[%d]=\"%s\"\n", i, argv[i]); } for (i = 1; i <= NARGS; i++) @@ -155,6 +169,27 @@ static int user_main(int argc, char *argv[]) } /************************************************************ + * Name: stdio_test + ************************************************************/ + +static void stdio_test(void) +{ + /* Verify that we can communicate */ + +#if CONFIG_NFILE_DESCRIPTORS > 0 + write(1, write_data1, sizeof(write_data1)-1); +#endif + printf("stdio_test: Standard I/O Check: printf\n"); + +#if CONFIG_NFILE_DESCRIPTORS > 1 + write(2, write_data2, sizeof(write_data2)-1); +#endif +#if CONFIG_NFILE_STREAMS > 0 + fprintf(stderr, "stdio_test: Standard I/O Check: fprintf to stderr\n"); +#endif +} + +/************************************************************ * Public Functions ************************************************************/ @@ -175,18 +210,20 @@ int user_start(int argc, char *argv[]) { int result; - /* Verify that we can communicate */ + /* Verify that stdio works first */ -#if CONFIG_NFILE_DESCRIPTORS > 0 - write(1, write_data1, sizeof(write_data1)-1); -#endif - printf("user_start: Standard I/O Check: printf\n"); + stdio_test(); -#if CONFIG_NFILE_DESCRIPTORS > 1 - write(2, write_data2, sizeof(write_data2)-1); -#endif -#if CONFIG_NFILE_STREAMS > 0 - fprintf(stderr, "user_start: Standard I/O Check: fprintf to stderr\n"); +#ifdef SDCC + /* I am not yet certain why SDCC does not like the initilizer. + * It involves some issues with 2- vs 3-byte pointer types. + */ + + g_argv[0] = arg1; + g_argv[1] = arg2; + g_argv[2] = arg3; + g_argv[3] = arg4; + g_argv[4] = NULL; #endif /* Verify that we can spawn a new task */ diff --git a/nuttx/sched/task_create.c b/nuttx/sched/task_create.c index 70e220fdd..07a6cab22 100644 --- a/nuttx/sched/task_create.c +++ b/nuttx/sched/task_create.c @@ -433,11 +433,13 @@ int task_create(const char *name, int priority, /* Associate file descriptors with the new task */ +#if CONFIG_NFILE_DESCRIPTORS > 0 if (sched_setuptaskfiles(tcb) != OK) { sched_releasetcb(tcb); return ERROR; } +#endif /* Allocate the stack for the TCB */ |