Progress toward clean SDCC compilation

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@18 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo 2007-02-21 21:55:16 +00:00
parent 7207076a5d
commit b8f3bd857b
90 changed files with 789 additions and 348 deletions

View File

@ -1806,7 +1806,7 @@ initialization time).
<B>Function Prototype:</B> <B>Function Prototype:</B>
<PRE> <PRE>
#include &lt;wdog.h&gt; #include &lt;wdog.h&gt;
STATUS wd_delete (WDOG_ID wdId); STATUS wd_delete (WDOG_ID wdog);
</PRE> </PRE>
<P> <P>
@ -1816,7 +1816,7 @@ has been started.
<P> <P>
<B>Input Parameters:</B> <B>Input Parameters:</B>
<UL> <UL>
<LI><I>wdId</I>. The watchdog ID to delete. This is actually a <LI><I>wdog</I>. The watchdog ID to delete. This is actually a
pointer to a watchdog structure. pointer to a watchdog structure.
</UL> </UL>
@ -1834,7 +1834,7 @@ it.
<B> POSIX Compatibility:</B> This is a NON-POSIX interface. <B> POSIX Compatibility:</B> This is a NON-POSIX interface.
VxWorks provides the following comparable interface: VxWorks provides the following comparable interface:
<PRE> <PRE>
STATUS wdDelete (WDOG_ID wdId); STATUS wdDelete (WDOG_ID wdog);
</PRE> </PRE>
<P> <P>
@ -1850,8 +1850,8 @@ before de-allocating it (i.e., never returns ERROR).
<B>Function Prototype:</B> <B>Function Prototype:</B>
<PRE> <PRE>
#include &lt;wdog.h&gt; #include &lt;wdog.h&gt;
STATUS wd_start( WDOG_ID wdId, int delay, wdentry_t wdentry, STATUS wd_start( WDOG_ID wdog, int delay, wdentry_t wdentry,
int parm1, int parm2, int parm3, int parm4 ); intt argc, ....);
</PRE> </PRE>
<P> <P>
@ -1867,15 +1867,16 @@ was called.
Watchdog timers execute only once. Watchdog timers execute only once.
<P> <P>
To replace either the timeout delay or the function to be executed, To replace either the timeout delay or the function to be executed,
call wd_start again with the same wdId; only the most recent call wd_start again with the same wdog; only the most recent
wd_start() on a given watchdog ID has any effect. wd_start() on a given watchdog ID has any effect.
<P> <P>
<B>Input Parameters:</B> <B>Input Parameters:</B>
<UL> <UL>
<LI><I>wdId</I>. Watchdog ID <LI><I>wdog</I>. Watchdog ID
<LI><I>delay</I>. Delay count in clock ticks <LI><I>delay</I>. Delay count in clock ticks
<LI><I>wdentry</I>. Function to call on timeout <LI><I>wdentry</I>. Function to call on timeout
<LI><I>parm1..4</I>. Parameters to pass to wdentry <LI><I>argc</I>. The number of uint32 parameters to pass to wdentry.
<LI><I>...</I>. uint32 size parameters to pass to wdentry
</UL> </UL>
<P> <P>
@ -1892,14 +1893,15 @@ restrictions.
<B> POSIX Compatibility:</B> This is a NON-POSIX interface. <B> POSIX Compatibility:</B> This is a NON-POSIX interface.
VxWorks provides the following comparable interface: VxWorks provides the following comparable interface:
<PRE> <PRE>
STATUS wdStart (WDOG_ID wdId, int delay, FUNCPTR wdentry, int parameter); STATUS wdStart (WDOG_ID wdog, int delay, FUNCPTR wdentry, int parameter);
</PRE> </PRE>
<P> <P>
Differences from the VxWorks interface include: Differences from the VxWorks interface include:
<UL> <UL>
<LI>The present implementation supports four parameters passed <LI>The present implementation supports multiple parameters passed
to wdentry; VxWorks supports only a single parameter. to wdentry; VxWorks supports only a single parameter. The maximum
number of parameters is determined by
</UL> </UL>
<H3>2.6.4 wd_cancel</H3> <H3>2.6.4 wd_cancel</H3>
@ -1908,7 +1910,7 @@ to wdentry; VxWorks supports only a single parameter.
<B>Function Prototype:</B> <B>Function Prototype:</B>
<PRE> <PRE>
#include &lt;wdog.h&gt; #include &lt;wdog.h&gt;
STATUS wd_cancel (WDOG_ID wdId); STATUS wd_cancel (WDOG_ID wdog);
</PRE> </PRE>
<P> <P>
@ -1918,7 +1920,7 @@ level.
<P> <P>
<B>Input Parameters:</B> <B>Input Parameters:</B>
<UL> <UL>
<LI><I>wdId</I>. ID of the watchdog to cancel. <LI><I>wdog</I>. ID of the watchdog to cancel.
</UL> </UL>
<P> <P>
@ -1933,7 +1935,7 @@ level.
<B> POSIX Compatibility:</B> This is a NON-POSIX interface. <B> POSIX Compatibility:</B> This is a NON-POSIX interface.
VxWorks provides the following comparable interface: VxWorks provides the following comparable interface:
<PRE> <PRE>
STATUS wdCancel (WDOG_ID wdId); STATUS wdCancel (WDOG_ID wdog);
</PRE> </PRE>
<HR> <HR>
@ -4073,6 +4075,39 @@ notify a task when a message is available on a queue.
int sigev_notify; int sigev_notify;
}; };
</PRE> </PRE>
<H3>3.4.9 Watchdog Data Types</H3>
<p>
When a watchdog expires, the callback function with this
type is called:
</p>
<pre>
typedef void (*wdentry_t)(int argc, ...);
</pre>
<p>
Where argc is the number of uint32 type arguments that follow.
</p>
The arguments are passed as uint32 values.
For systems where the sizeof(pointer) &lt; sizeof(uint32), the
following union defines the alignment of the pointer within the
uint32. For example, the SDCC MCS51 general pointer is
24-bits, but uint32 is 32-bits (of course).
</p>
<pre>
union wdparm_u
{
void *pvarg;
uint32 *dwarg;
};
typedef union wdparm_u wdparm_t;
</pre>
<p>
For most 32-bit systems, pointers and uint32 are the same size
For systems where sizeof(pointer) > sizeof(uint32), we will
have to do some redesign.
</p>
<HR> <HR>
<H1>4.0 <A NAME="Problems">Known Problems</A></H1> <H1>4.0 <A NAME="Problems">Known Problems</A></H1>

View File

@ -44,9 +44,9 @@ SUBDIRS = sched lib $(ARCH_SRC) mm fs drivers examples/$(CONFIG_EXAMPLE)
OBJS = $(ARCH_SRC)/up_head.o OBJS = $(ARCH_SRC)/up_head.o
LIBGCC = ${shell $(CC) -print-libgcc-file-name} LIBGCC = ${shell $(CC) -print-libgcc-file-name}
LIBS = sched/libsched.a $(ARCH_SRC)/libarch.a mm/libmm.a \ LIBS = sched/libsched$(LIBEXT) $(ARCH_SRC)/libarch$(LIBEXT) mm/libmm$(LIBEXT) \
fs/libfs.a drivers/libdrivers.a lib/liblib.a \ fs/libfs$(LIBEXT) drivers/libdrivers$(LIBEXT) lib/liblib$(LIBEXT) \
examples/$(CONFIG_EXAMPLE)/lib$(CONFIG_EXAMPLE).a examples/$(CONFIG_EXAMPLE)/lib$(CONFIG_EXAMPLE)$(LIBEXT)
LDLIBS = -lsched -larch -lmm -lfs -ldrivers -llib -l$(CONFIG_EXAMPLE) $(LIBGCC) $(EXTRA_LIBS) LDLIBS = -lsched -larch -lmm -lfs -ldrivers -llib -l$(CONFIG_EXAMPLE) $(LIBGCC) $(EXTRA_LIBS)
BIN = nuttx BIN = nuttx
@ -78,29 +78,29 @@ check_context:
exit 1 ; \ exit 1 ; \
fi fi
sched/libsched.a: context sched/libsched$(LIBEXT): context
$(MAKE) -C sched TOPDIR=$(TOPDIR) libsched.a $(MAKE) -C sched TOPDIR=$(TOPDIR) libsched$(LIBEXT)
lib/liblib.a: context lib/liblib$(LIBEXT): context
$(MAKE) -C lib TOPDIR=$(TOPDIR) liblib.a $(MAKE) -C lib TOPDIR=$(TOPDIR) liblib$(LIBEXT)
$(ARCH_SRC)/libarch.a: context $(ARCH_SRC)/libarch$(LIBEXT): context
$(MAKE) -C $(ARCH_SRC) TOPDIR=$(TOPDIR) libarch.a $(MAKE) -C $(ARCH_SRC) TOPDIR=$(TOPDIR) libarch$(LIBEXT)
$(ARCH_SRC)/up_head.o: context $(ARCH_SRC)/up_head.o: context
$(MAKE) -C $(ARCH_SRC) TOPDIR=$(TOPDIR) up_head.o $(MAKE) -C $(ARCH_SRC) TOPDIR=$(TOPDIR) up_head.o
mm/libmm.a: context mm/libmm$(LIBEXT): context
$(MAKE) -C mm TOPDIR=$(TOPDIR) libmm.a $(MAKE) -C mm TOPDIR=$(TOPDIR) libmm$(LIBEXT)
fs/libfs.a: context fs/libfs$(LIBEXT): context
$(MAKE) -C fs TOPDIR=$(TOPDIR) libfs.a $(MAKE) -C fs TOPDIR=$(TOPDIR) libfs$(LIBEXT)
drivers/libdrivers.a: context drivers/libdrivers$(LIBEXT): context
$(MAKE) -C drivers TOPDIR=$(TOPDIR) libdrivers.a $(MAKE) -C drivers TOPDIR=$(TOPDIR) libdrivers$(LIBEXT)
examples/$(CONFIG_EXAMPLE)/lib$(CONFIG_EXAMPLE).a: context examples/$(CONFIG_EXAMPLE)/lib$(CONFIG_EXAMPLE)$(LIBEXT): context
$(MAKE) -C examples/$(CONFIG_EXAMPLE) TOPDIR=$(TOPDIR) lib$(CONFIG_EXAMPLE).a $(MAKE) -C examples/$(CONFIG_EXAMPLE) TOPDIR=$(TOPDIR) lib$(CONFIG_EXAMPLE)$(LIBEXT)
$(BIN): context depend $(OBJS) $(LIBS) $(BIN): context depend $(OBJS) $(LIBS)
ifeq ($(CONFIG_ARCH),sim) ifeq ($(CONFIG_ARCH),sim)

View File

@ -142,7 +142,18 @@ include/types.h
This provides architecture/toolchain-specific definitions for This provides architecture/toolchain-specific definitions for
standard types. This file should typedef: standard types. This file should typedef:
sbyte, ubyte, uint8, boolean, sint16, uint16, sint32, uint32, sint64, uint64 sbyte, ubyte, uint8, boolean, sint16, uint16, sint32, uint32
and
sint64, uint64
if the architecture supports 64-bit integers.
irqstate_t
Must be defined to the be the size required to hold the interrupt
enable/disable state.
This file will be included by include/sys/types.h and be made This file will be included by include/sys/types.h and be made
available to all files. available to all files.
@ -154,9 +165,9 @@ include/irq.h
- struct xcptcontext. This structures represents the saved context - struct xcptcontext. This structures represents the saved context
of a thread. of a thread.
- uint32 irqsave(void) -- Used to disable all interrupts. - irqstate_t irqsave(void) -- Used to disable all interrupts.
- void irqrestore(uint32 flags) -- Used to restore interrupt - void irqrestore(irqstate_t flags) -- Used to restore interrupt
enables to the same state as before irqsave was called. enables to the same state as before irqsave was called.
This file must also define NR_IRQS, the total number of IRQs supported This file must also define NR_IRQS, the total number of IRQs supported

View File

@ -52,7 +52,7 @@ ARCHSCRIPT = -T$(TOPDIR)/arch/$(CONFIG_ARCH)/ld.script
CROSSDEV = arm-elf- CROSSDEV = arm-elf-
CC = $(CROSSDEV)gcc CC = $(CROSSDEV)gcc
LD = $(CROSSDEV)ld LD = $(CROSSDEV)ld
AR = $(CROSSDEV)ar AR = $(CROSSDEV)ar rcs
NM = $(CROSSDEV)nm NM = $(CROSSDEV)nm
OBJCOPY = $(CROSSDEV)objcopy OBJCOPY = $(CROSSDEV)objcopy
OBJDUMP = $(CROSSDEV)objdump OBJDUMP = $(CROSSDEV)objdump
@ -62,6 +62,7 @@ CFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \
LDFLAGS = $(ARCHSCRIPT) LDFLAGS = $(ARCHSCRIPT)
EXTRA_LIBS = EXTRA_LIBS =
LIBEXT = .a
ifeq ("${CONFIG_DEBUG}","y") ifeq ("${CONFIG_DEBUG}","y")
LDFLAGS += -g LDFLAGS += -g

View File

@ -132,6 +132,8 @@ CONFIG_ARCH_KFREE=n
# #
# General Compile environment setup # General Compile environment setup
# #
# CONFIG_SMALL_MEMORY - enable if your processor supports
# 16-bit addressing; disable if it supports 32-bit.
# CONFIG_HAVE_INLINE - enable if your compiler supports # CONFIG_HAVE_INLINE - enable if your compiler supports
# inline functions # inline functions
# CONFIG_HAVE_DOUBLE - enable if your compiler supports type # CONFIG_HAVE_DOUBLE - enable if your compiler supports type
@ -139,21 +141,26 @@ CONFIG_ARCH_KFREE=n
# CONFIG_HAVE_LONG_LONG - enable if your architecture supports # CONFIG_HAVE_LONG_LONG - enable if your architecture supports
# long long types and if you plan to use them # long long types and if you plan to use them
# CONFIG_CAN_PASS_STRUCTS - enable if your compiler supports # CONFIG_CAN_PASS_STRUCTS - enable if your compiler supports
# passing structures and unions as values # passing and assiging structures and unions as values
# CONFIG_CAN_CAST_POINTERS - enable if you can cast between
# integers and pointer.
# CONFIG_HAVE_WEAKFUNCTIONS - enable if you compiler supports # CONFIG_HAVE_WEAKFUNCTIONS - enable if you compiler supports
# weak functions (see include/nuttx/comp # weak functions (see include/nuttx/comp
# #
CONFIG_SMALL_MEMORY=n
CONFIG_HAVE_INLINE=y CONFIG_HAVE_INLINE=y
CONFIG_HAVE_DOUBLE=y CONFIG_HAVE_DOUBLE=y
CONFIG_HAVE_LONG_LONG=n CONFIG_HAVE_LONG_LONG=n
CONFIG_CAN_PASS_STRUCTS=y CONFIG_CAN_PASS_STRUCTS=y
CONFIG_CAN_CAST_POINTERS=y
CONFIG_HAVE_WEAKFUNCTIONS=y CONFIG_HAVE_WEAKFUNCTIONS=y
# #
# General build options # General build options
# #
# CONFIG_RRLOAD_BINY - make the rrload binary format used with # CONFIG_RRLOAD_BINARY - make the rrload binary format used with
# BSPs from www.ridgerun.com # BSPs from www.ridgerun.com
#
CONFIG_RRLOAD_BINARY=y CONFIG_RRLOAD_BINARY=y
# #
@ -175,6 +182,8 @@ CONFIG_RRLOAD_BINARY=y
# CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with # CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with
# a fixed payload size given by this settin (does not include # a fixed payload size given by this settin (does not include
# other message structure overhead. # other message structure overhead.
# CONFIG_MAX_WDOGPARMS - Maximum number of parameters that
# can be passed to a watchdog handler
# CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog # CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
# structures. The system manages a pool of preallocated # structures. The system manages a pool of preallocated
# watchdog structures to minimize dynamic allocations # watchdog structures to minimize dynamic allocations
@ -186,6 +195,7 @@ CONFIG_STDIO_BUFFER_SIZE=1024
CONFIG_NUNGET_CHARS=2 CONFIG_NUNGET_CHARS=2
CONFIG_PREALLOC_MQ_MSGS=32 CONFIG_PREALLOC_MQ_MSGS=32
CONFIG_MQ_MAXMSGSIZE=32 CONFIG_MQ_MAXMSGSIZE=32
CONFIG_MAX_WDOGPARMS=4
CONFIG_PREALLOC_WDOGS=32 CONFIG_PREALLOC_WDOGS=32
# #

View File

@ -177,10 +177,10 @@ struct xcptcontext
/* Save the current interrupt enable state & disable IRQs */ /* Save the current interrupt enable state & disable IRQs */
static inline uint32 irqsave(void) static inline irqstate_t irqsave(void)
{ {
unsigned long flags; unsigned int flags;
unsigned long temp; unsigned int temp;
__asm__ __volatile__ __asm__ __volatile__
( (
"\tmrs %0, cpsr\n" "\tmrs %0, cpsr\n"
@ -194,7 +194,7 @@ static inline uint32 irqsave(void)
/* Restore saved IRQ & FIQ state */ /* Restore saved IRQ & FIQ state */
static inline void irqrestore(uint32 flags) static inline void irqrestore(irqstate_t flags)
{ {
__asm__ __volatile__ __asm__ __volatile__
( (
@ -204,8 +204,8 @@ static inline void irqrestore(uint32 flags)
: "memory"); : "memory");
} }
static inline void system_call(swint_t func, uint32 parm1, static inline void system_call(swint_t func, int parm1,
uint32 parm2, uint32 parm3) int parm2, int parm3)
{ {
__asm__ __volatile__ __asm__ __volatile__
( (

View File

@ -52,6 +52,10 @@
* Type Declarations * Type Declarations
************************************************************/ ************************************************************/
#ifndef __ASSEMBLY__
/* These are the sizes of the standard GNU types */
typedef char sbyte; typedef char sbyte;
typedef unsigned char ubyte; typedef unsigned char ubyte;
typedef unsigned char uint8; typedef unsigned char uint8;
@ -63,6 +67,14 @@ typedef unsigned int uint32;
typedef long long sint64; typedef long long sint64;
typedef unsigned long long uint64; typedef unsigned long long uint64;
/* This is the size of the interrupt state save returned by
* irqsave()
*/
typedef unsigned int irqstate_t;
#endif /* __ASSEMBLY__ */
/************************************************************ /************************************************************
* Global Function Prototypes * Global Function Prototypes
************************************************************/ ************************************************************/

View File

@ -56,7 +56,7 @@ COBJS = $(CSRCS:.c=.o)
SRCS = $(ASRCS) $(CSRCS) SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS) OBJS = $(AOBJS) $(COBJS)
all: up_head.o libarch.a all: up_head.o libarch$(LIBEXT)
$(AOBJS) up_head.o: %.o: %.S $(AOBJS) up_head.o: %.o: %.S
$(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@ $(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@
@ -64,8 +64,11 @@ $(AOBJS) up_head.o: %.o: %.S
$(COBJS): %.o: %.c $(COBJS): %.o: %.c
$(CC) -c $(CFLAGS) $< -o $@ $(CC) -c $(CFLAGS) $< -o $@
libarch.a: $(OBJS) libarch$(LIBEXT): $(OBJS)
$(AR) rcs $@ $(OBJS) ( for obj in $(OBJS) ; do \
$(AR) $@ $${obj} || \
{ echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \
done ; )
.depend: Makefile $(SRCS) .depend: Makefile $(SRCS)
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@ -74,7 +77,7 @@ libarch.a: $(OBJS)
depend: .depend depend: .depend
clean: clean:
rm -f libarch.a *.o *~ rm -f libarch$(LIBEXT) *.o *~
distclean: clean distclean: clean
rm -f Make.dep .depend rm -f Make.dep .depend

View File

@ -63,7 +63,7 @@
* Name: up_assert * Name: up_assert
************************************************************/ ************************************************************/
void up_assert(const ubyte *filename, uint32 lineno) void up_assert(const ubyte *filename, int lineno)
{ {
dbg("Assertion failed at file:%s line: %d\n", dbg("Assertion failed at file:%s line: %d\n",
filename, lineno); filename, lineno);
@ -74,7 +74,7 @@ void up_assert(const ubyte *filename, uint32 lineno)
* Name: up_assert_code * Name: up_assert_code
************************************************************/ ************************************************************/
void up_assert_code(const ubyte *filename, uint32 lineno, uint16 errorcode) void up_assert_code(const ubyte *filename, int lineno, int errorcode)
{ {
dbg("Assertion failed at file:%s line: %d error code: %d\n", dbg("Assertion failed at file:%s line: %d error code: %d\n",
filename, lineno, errorcode); filename, lineno, errorcode);

View File

@ -78,7 +78,7 @@
* must be allocated. * must be allocated.
************************************************************/ ************************************************************/
STATUS up_create_stack(_TCB *tcb, uint32 stack_size) STATUS up_create_stack(_TCB *tcb, size_t stack_size)
{ {
if (tcb->stack_alloc_ptr && if (tcb->stack_alloc_ptr &&
tcb->adj_stack_size != stack_size) tcb->adj_stack_size != stack_size)
@ -94,8 +94,8 @@ STATUS up_create_stack(_TCB *tcb, uint32 stack_size)
if (tcb->stack_alloc_ptr) if (tcb->stack_alloc_ptr)
{ {
uint32 top_of_stack; size_t top_of_stack;
uint32 size_of_stack; size_t size_of_stack;
/* The Arm7Tdmi uses a push-down stack: the stack grows /* The Arm7Tdmi uses a push-down stack: the stack grows
* toward loweraddresses in memory. The stack pointer * toward loweraddresses in memory. The stack pointer

View File

@ -101,7 +101,7 @@ void up_schedule_sigaction(_TCB *tcb, sig_deliver_t sigdeliver)
if (!tcb->xcp.sigdeliver) if (!tcb->xcp.sigdeliver)
{ {
uint32 flags; irqstate_t flags;
/* Make sure that interrupts are disabled */ /* Make sure that interrupts are disabled */

View File

@ -721,7 +721,7 @@ static void up_uartsetup(up_dev_t *dev)
static void shutdown(up_dev_t * dev) static void shutdown(up_dev_t * dev)
{ {
uint32 flags; irqstate_t flags;
uint16 msr; uint16 msr;
/* Free the IRQ */ /* Free the IRQ */
@ -878,7 +878,7 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg)
case TIOCSBRK: /* BSD compatibility: Turn break on, unconditionally */ case TIOCSBRK: /* BSD compatibility: Turn break on, unconditionally */
{ {
uint32 flags = irqsave(); irqstate_t flags = irqsave();
up_enablebreaks(dev); up_enablebreaks(dev);
irqrestore(flags); irqrestore(flags);
} }
@ -886,7 +886,7 @@ static int up_ioctl(struct file *filep, int cmd, unsigned long arg)
case TIOCCBRK: /* BSD compatibility: Turn break off, unconditionally */ case TIOCCBRK: /* BSD compatibility: Turn break off, unconditionally */
{ {
uint32 flags; irqstate_t flags;
flags = irqsave(); flags = irqsave();
up_disablebreaks(dev); up_disablebreaks(dev);
irqrestore(flags); irqrestore(flags);
@ -973,7 +973,7 @@ static int up_open(struct file *filep)
if (++dev->open_count == 1) if (++dev->open_count == 1)
{ {
int flags = irqsave(); irqstate_t flags = irqsave();
/* If this is the console, then the UART has already /* If this is the console, then the UART has already
* been initialized. * been initialized.

View File

@ -78,10 +78,10 @@
* *
************************************************************/ ************************************************************/
STATUS up_use_stack(_TCB *tcb, uint32 *stack, uint32 stack_size) STATUS up_use_stack(_TCB *tcb, void *stack, size_t stack_size)
{ {
uint32 top_of_stack; size_t top_of_stack;
uint32 size_of_stack; size_t size_of_stack;
if (tcb->stack_alloc_ptr) if (tcb->stack_alloc_ptr)
{ {

View File

@ -51,7 +51,7 @@ ARCHSCRIPT =
CROSSDEV = CROSSDEV =
CC = $(CROSSDEV)gcc CC = $(CROSSDEV)gcc
LD = $(CROSSDEV)ld LD = $(CROSSDEV)ld
AR = $(CROSSDEV)ar AR = $(CROSSDEV)ar rcs
NM = $(CROSSDEV)nm NM = $(CROSSDEV)nm
OBJCOPY = $(CROSSDEV)objcopy OBJCOPY = $(CROSSDEV)objcopy
OBJDUMP = $(CROSSDEV)objdump OBJDUMP = $(CROSSDEV)objdump
@ -61,6 +61,7 @@ CFLAGS = $(ARCHWARNINGS) $(ARCHOPTIMIZATION) \
LDFLAGS = $(ARCHSCRIPT) LDFLAGS = $(ARCHSCRIPT)
EXTRA_LIBS = -lc EXTRA_LIBS = -lc
LIBEXT = .a
ifeq ("${CONFIG_DEBUG}","y") ifeq ("${CONFIG_DEBUG}","y")
LDFLAGS += -g LDFLAGS += -g

View File

@ -99,6 +99,8 @@ CONFIG_ARCH_KFREE=n
# #
# General Compile environment setup # General Compile environment setup
# #
# CONFIG_SMALL_MEMORY - enable if your processor supports
# 16-bit addressing; disable if it supports 32-bit.
# CONFIG_HAVE_INLINE - enable if your compiler supports # CONFIG_HAVE_INLINE - enable if your compiler supports
# inline functions # inline functions
# CONFIG_HAVE_DOUBLE - enable if your compiler supports type # CONFIG_HAVE_DOUBLE - enable if your compiler supports type
@ -106,21 +108,26 @@ CONFIG_ARCH_KFREE=n
# CONFIG_HAVE_LONG_LONG - enable if your architecture supports # CONFIG_HAVE_LONG_LONG - enable if your architecture supports
# long long types and if you plan to use them # long long types and if you plan to use them
# CONFIG_CAN_PASS_STRUCTS - enable if your compiler supports # CONFIG_CAN_PASS_STRUCTS - enable if your compiler supports
# passing structures and unions as values # passing and assiging structures and unions as values
# CONFIG_CAN_CAST_POINTERS - enable if you can cast between
# integers and pointer.
# CONFIG_HAVE_WEAKFUNCTIONS - enable if you compiler supports # CONFIG_HAVE_WEAKFUNCTIONS - enable if you compiler supports
# weak functions (see include/nuttx/comp # weak functions (see include/nuttx/comp
# #
CONFIG_SMALL_MEMORY=n
CONFIG_HAVE_INLINE=y CONFIG_HAVE_INLINE=y
CONFIG_HAVE_DOUBLE=y CONFIG_HAVE_DOUBLE=y
CONFIG_HAVE_LONG_LONG=n CONFIG_HAVE_LONG_LONG=n
CONFIG_CAN_PASS_STRUCTS=y CONFIG_CAN_PASS_STRUCTS=y
CONFIG_CAN_CAST_POINTERS=y
CONFIG_HAVE_WEAKFUNCTIONS=y CONFIG_HAVE_WEAKFUNCTIONS=y
# #
# General build options # General build options
# #
# CONFIG_RRLOAD_BINY - make the rrload binary format used with # CONFIG_RRLOAD_BINARY - make the rrload binary format used with
# BSPs from www.ridgerun.com # BSPs from www.ridgerun.com
#
CONFIG_RRLOAD_BINARY=n CONFIG_RRLOAD_BINARY=n
# #
@ -142,6 +149,8 @@ CONFIG_RRLOAD_BINARY=n
# CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with # CONFIG_MQ_MAXMSGSIZE - Message structures are allocated with
# a fixed payload size given by this settin (does not include # a fixed payload size given by this settin (does not include
# other message structure overhead. # other message structure overhead.
# CONFIG_MAX_WDOGPARMS - Maximum number of parameters that
# can be passed to a watchdog handler
# CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog # CONFIG_PREALLOC_WDOGS - The number of pre-allocated watchdog
# structures. The system manages a pool of preallocated # structures. The system manages a pool of preallocated
# watchdog structures to minimize dynamic allocations # watchdog structures to minimize dynamic allocations
@ -153,6 +162,7 @@ CONFIG_STDIO_BUFFER_SIZE=1024
CONFIG_NUNGET_CHARS=2 CONFIG_NUNGET_CHARS=2
CONFIG_PREALLOC_MQ_MSGS=32 CONFIG_PREALLOC_MQ_MSGS=32
CONFIG_MQ_MAXMSGSIZE=32 CONFIG_MQ_MAXMSGSIZE=32
CONFIG_MAX_WDOGPARMS=4
CONFIG_PREALLOC_WDOGS=32 CONFIG_PREALLOC_WDOGS=32
# #

View File

@ -44,6 +44,8 @@
* Included Files * Included Files
************************************************************/ ************************************************************/
#include <sys/types.h>
/************************************************************ /************************************************************
* Definitions * Definitions
************************************************************/ ************************************************************/
@ -72,12 +74,12 @@ struct xcptcontext
************************************************************/ ************************************************************/
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
static inline uint32 irqsave(void) static inline irqstate_t irqsave(void)
{ {
return 0; return 0;
} }
static inline void irqrestore(uint32 flags) static inline void irqrestore(irqstate_t flags)
{ {
} }
#endif #endif

View File

@ -52,6 +52,10 @@
* Type Declarations * Type Declarations
************************************************************/ ************************************************************/
#ifndef __ASSEMBLY__
/* These are the sizes of the standard GNU types */
typedef char sbyte; typedef char sbyte;
typedef unsigned char ubyte; typedef unsigned char ubyte;
typedef unsigned char uint8; typedef unsigned char uint8;
@ -63,6 +67,14 @@ typedef unsigned int uint32;
typedef long long sint64; typedef long long sint64;
typedef unsigned long long uint64; typedef unsigned long long uint64;
/* This is the size of the interrupt state save returned by
* irqsave()
*/
typedef unsigned int irqstate_t;
#endif /* __ASSEMBLY__ */
/************************************************************ /************************************************************
* Global Function Prototypes * Global Function Prototypes
************************************************************/ ************************************************************/

View File

@ -49,7 +49,7 @@ COBJS = $(CSRCS:.c=.o)
SRCS = $(ASRCS) $(CSRCS) SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS) OBJS = $(AOBJS) $(COBJS)
all: up_head.o libarch.a all: up_head.o libarch$(LIBEXT)
$(AOBJS): %.o: %.S $(AOBJS): %.o: %.S
$(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@ $(CC) -c $(CFLAGS) -D__ASSEMBLY__ $< -o $@
@ -57,8 +57,11 @@ $(AOBJS): %.o: %.S
$(COBJS) up_head.o: %.o: %.c $(COBJS) up_head.o: %.o: %.c
$(CC) -c $(CFLAGS) $< -o $@ $(CC) -c $(CFLAGS) $< -o $@
libarch.a: $(OBJS) libarch$(LIBEXT): $(OBJS)
$(AR) rcs $@ $(OBJS) ( for obj in $(OBJS) ; do \
$(AR) $@ $${obj} || \
{ echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \
done ; )
.depend: Makefile $(SRCS) .depend: Makefile $(SRCS)
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep
@ -67,7 +70,7 @@ libarch.a: $(OBJS)
depend: .depend depend: .depend
clean: clean:
rm -f libarch.a *.o *~ rm -f libarch$(LIBEXT) *.o *~
distclean: clean distclean: clean
rm -f Make.dep .depend rm -f Make.dep .depend

View File

@ -81,14 +81,14 @@
* *
************************************************************/ ************************************************************/
STATUS up_create_stack(_TCB *tcb, uint32 stack_size) STATUS up_create_stack(_TCB *tcb, size_t stack_size)
{ {
STATUS ret = ERROR; STATUS ret = ERROR;
/* Move up to next even word boundary if necessary */ /* Move up to next even word boundary if necessary */
uint32 adj_stack_size = (stack_size + 3) & ~3; size_t adj_stack_size = (stack_size + 3) & ~3;
uint32 adj_stack_words = adj_stack_size >> 2; size_t adj_stack_words = adj_stack_size >> 2;
/* Allocate the memory for the stack */ /* Allocate the memory for the stack */
@ -97,9 +97,10 @@ STATUS up_create_stack(_TCB *tcb, uint32 stack_size)
{ {
/* This is the address of the last word in the allocation */ /* This is the address of the last word in the allocation */
uint32 *adj_stack_ptr = &stack_alloc_ptr[adj_stack_words - 1]; size_t *adj_stack_ptr = &stack_alloc_ptr[adj_stack_words - 1];
/* Save the values in the TCB */ /* Save the values in the TCB */
tcb->adj_stack_size = adj_stack_size; tcb->adj_stack_size = adj_stack_size;
tcb->stack_alloc_ptr = stack_alloc_ptr; tcb->stack_alloc_ptr = stack_alloc_ptr;
tcb->adj_stack_ptr = adj_stack_ptr; tcb->adj_stack_ptr = adj_stack_ptr;

View File

@ -64,13 +64,13 @@ int main(int argc, char **argv, char **envp)
return 0; return 0;
} }
void up_assert(const ubyte *filename, uint32 line) void up_assert(const ubyte *filename, int line)
{ {
fprintf(stderr, "Assertion failed at file:%s line: %d\n", filename, line); fprintf(stderr, "Assertion failed at file:%s line: %d\n", filename, line);
longjmp(sim_abort, 1); longjmp(sim_abort, 1);
} }
void up_assert_code(const ubyte *filename, uint32 line, uint16 code) void up_assert_code(const ubyte *filename, int line, int code)
{ {
fprintf(stderr, "Assertion failed at file:%s line: %d error code: %d\n", filename, line, code); fprintf(stderr, "Assertion failed at file:%s line: %d error code: %d\n", filename, line, code);
longjmp(sim_abort, 1); longjmp(sim_abort, 1);

View File

@ -81,18 +81,19 @@
* *
************************************************************/ ************************************************************/
STATUS up_use_stack(_TCB *tcb, uint32 *stack, uint32 stack_size) STATUS up_use_stack(_TCB *tcb, void *stack, size_t stack_size)
{ {
/* Move up to next even word boundary if necessary */ /* Move up to next even word boundary if necessary */
uint32 adj_stack_size = stack_size & ~3; size_t adj_stack_size = stack_size & ~3;
uint32 adj_stack_words = adj_stack_size >> 2; size_t adj_stack_words = adj_stack_size >> 2;
/* This is the address of the last word in the allocation */ /* This is the address of the last word in the allocation */
uint32 *adj_stack_ptr = &stack[adj_stack_words - 1]; size_t *adj_stack_ptr = &stack[adj_stack_words - 1];
/* Save the values in the TCB */ /* Save the values in the TCB */
tcb->adj_stack_size = adj_stack_size; tcb->adj_stack_size = adj_stack_size;
tcb->stack_alloc_ptr = stack; tcb->stack_alloc_ptr = stack;
tcb->adj_stack_ptr = adj_stack_ptr; tcb->adj_stack_ptr = adj_stack_ptr;

View File

@ -46,7 +46,7 @@ COBJS = $(CSRCS:.c=.o)
SRCS = $(ASRCS) $(CSRCS) SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS) OBJS = $(AOBJS) $(COBJS)
BIN = libdrivers.a BIN = libdrivers$(LIBEXT)
all: $(BIN) all: $(BIN)
@ -57,7 +57,10 @@ $(cOBJS): %.o: %.c
$(CC) -c $(CFLAGS) $< -o $@ $(CC) -c $(CFLAGS) $< -o $@
$(BIN): $(OBJS) $(BIN): $(OBJS)
$(AR) rcs $@ $(OBJS) ( for obj in $(OBJS) ; do \
$(AR) $@ $${obj} || \
{ echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \
done ; )
.depend: Makefile $(SRCS) .depend: Makefile $(SRCS)
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep

View File

@ -47,7 +47,7 @@ COBJS = $(CSRCS:.c=.o)
SRCS = $(ASRCS) $(CSRCS) SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS) OBJS = $(AOBJS) $(COBJS)
BIN = lib$(CONFIG_EXAMPLE).a BIN = lib$(CONFIG_EXAMPLE)$(LIBEXT)
all: $(BIN) all: $(BIN)
@ -58,7 +58,10 @@ $(COBJS): %.o: %.c
$(CC) -c $(CFLAGS) $< -o $@ $(CC) -c $(CFLAGS) $< -o $@
$(BIN): $(OBJS) $(BIN): $(OBJS)
$(AR) rcs $@ $(OBJS) ( for obj in $(OBJS) ; do \
$(AR) $@ $${obj} || \
{ echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \
done ; )
.depend: Makefile $(SRCS) .depend: Makefile $(SRCS)
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep

View File

@ -37,6 +37,7 @@
#include <time.h> #include <time.h>
#include <pthread.h> #include <pthread.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include "ostest.h" #include "ostest.h"
static pthread_mutex_t mutex; static pthread_mutex_t mutex;
@ -69,9 +70,20 @@ static void *thread_waiter(void *parameter)
status = pthread_cond_timedwait(&cond, &mutex, &time); status = pthread_cond_timedwait(&cond, &mutex, &time);
if (status != 0) if (status != 0)
{
if (status == ETIMEDOUT)
{
printf("thread_waiter: pthread_cond_timedwait timed out\n");
}
else
{ {
printf("thread_waiter: ERROR pthread_cond_timedwait failed, status=%d\n", status); printf("thread_waiter: ERROR pthread_cond_timedwait failed, status=%d\n", status);
} }
}
else
{
printf("thread_waiter: ERROR pthread_cond_timedwait returned without timeout, status=%d\n", status);
}
/* Release the mutex */ /* Release the mutex */

View File

@ -47,7 +47,7 @@ COBJS = $(CSRCS:.c=.o)
SRCS = $(ASRCS) $(CSRCS) SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS) OBJS = $(AOBJS) $(COBJS)
BIN = libfs.a BIN = libfs$(LIBEXT)
all: $(BIN) all: $(BIN)
@ -58,7 +58,10 @@ $(cOBJS): %.o: %.c
$(CC) -c $(CFLAGS) $< -o $@ $(CC) -c $(CFLAGS) $< -o $@
$(BIN): $(OBJS) $(BIN): $(OBJS)
$(AR) rcs $@ $(OBJS) ( for obj in $(OBJS) ; do \
$(AR) $@ $${obj} || \
{ echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \
done ; )
.depend: Makefile $(SRCS) .depend: Makefile $(SRCS)
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep

View File

@ -53,21 +53,42 @@
#undef ASSERTCODE #undef ASSERTCODE
#undef DEBUGASSERT #undef DEBUGASSERT
#define ASSERT(f) \ #ifdef __GNUC__
{ if (!(f)) up_assert((const ubyte *)__FILE__, (uint32)__LINE__); }
#define ASSERTCODE(f, errCode) \ # define ASSERT(f) \
{ if (!(f)) up_assert_code((const ubyte *)__FILE__, (uint32)__LINE__, errCode); } { if (!(f)) up_assert((const ubyte *)__FILE__, (int)__LINE__); }
# define ASSERTCODE(f, errCode) \
{ if (!(f)) up_assert_code((const ubyte *)__FILE__, (int)__LINE__, errCode); }
# ifdef CONFIG_DEBUG
# define DEBUGASSERT(f) \
{ if (!(f)) up_assert((const ubyte *)__FILE__, (int)__LINE__); }
# else
# define DEBUGASSERT(f)
# endif /* CONFIG_DEBUG */
# define PANIC(errCode) \
up_assert_code((const ubyte *)__FILE__, (int)__LINE__, (errCode)|0x8000)
#ifdef CONFIG_DEBUG
#define DEBUGASSERT(f) \
{ if (!(f)) up_assert((const ubyte *)__FILE__, (uint32)__LINE__); }
#else #else
#define DEBUGASSERT(f) # define ASSERT(f) \
#endif /* CONFIG_DEBUG */ { if (!(f)) up_assert(); }
#define PANIC(errCode) \ # define ASSERTCODE(f, errCode) \
up_assert_code((const ubyte *)__FILE__, (uint32)__LINE__, ((errCode)|(0x8000))) { if (!(f)) up_assert_code(errCode); }
# ifdef CONFIG_DEBUG
# define DEBUGASSERT(f) \
{ if (!(f)) up_assert(); }
# else
# define DEBUGASSERT(f)
# endif /* CONFIG_DEBUG */
# define PANIC(errCode) \
up_assert_code((errCode)|0x8000)
#endif
/************************************************************ /************************************************************
* Included Files * Included Files
@ -84,9 +105,14 @@ extern "C" {
#define EXTERN extern #define EXTERN extern
#endif #endif
EXTERN void up_assert(const ubyte *fileName, uint32 lineNum); #ifdef __GNUC__
EXTERN void up_assert_code(const ubyte *fileName, uint32 lineNum, EXTERN void up_assert(const ubyte *fileName, int lineNum);
uint16 errorCode); EXTERN void up_assert_code(const ubyte *fileName, int lineNum,
int error_code);
#else
EXTERN void up_assert(void);
EXTERN void up_assert_code(int error_code);
#endif
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -188,8 +188,16 @@ extern "C" {
#define EXTERN extern #define EXTERN extern
#endif #endif
/* Return a pointer to the thread specifid errno */
extern int *get_errno_ptr(void); extern int *get_errno_ptr(void);
#ifndef CONFIG_CAN_CAST_POINTERS
/* Return the value ERROR cast to (void*) */
extern void *get_errorptr(void);
#endif
#undef EXTERN #undef EXTERN
#if defined(__cplusplus) #if defined(__cplusplus)
} }

View File

@ -150,7 +150,7 @@ EXTERN void up_initial_state(_TCB *tcb);
* must be allocated. * must be allocated.
************************************************************/ ************************************************************/
EXTERN STATUS up_create_stack(_TCB *tcb, uint32 stack_size); EXTERN STATUS up_create_stack(_TCB *tcb, size_t stack_size);
/************************************************************ /************************************************************
* Name: up_use_stack * Name: up_use_stack
@ -173,7 +173,7 @@ EXTERN STATUS up_create_stack(_TCB *tcb, uint32 stack_size);
* *
************************************************************/ ************************************************************/
EXTERN STATUS up_use_stack(_TCB *tcb, uint32 *stack, uint32 stack_size); EXTERN STATUS up_use_stack(_TCB *tcb, void *stack, size_t stack_size);
/************************************************************ /************************************************************
* Name: up_release_stack * Name: up_release_stack

View File

@ -52,6 +52,7 @@
# define noreturn_function __attribute__ ((noreturn)) # define noreturn_function __attribute__ ((noreturn))
# define reentrant_function # define reentrant_function
#elif defined(__SDCC__) #elif defined(__SDCC__)
# pragma disable_warning 85
# define weak_alias(name, aliasname) # define weak_alias(name, aliasname)
# define weak_function # define weak_function
# define weak_const_function # define weak_const_function

View File

@ -61,7 +61,7 @@
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
typedef int (*xcpt_t)(int irq, void *context); typedef int (*xcpt_t)(int irq, void *context);
typedef int (*swint_t)(uint32 code, uint32 parm2, uint32 parm3, typedef int (*swint_t)(int code, int parm2, int parm3,
void *context); void *context);
#endif #endif

View File

@ -85,7 +85,11 @@
/* Thread return value when a pthread is canceled */ /* Thread return value when a pthread is canceled */
#define PTHREAD_CANCELED ((void*)-1) #ifdef CONFIG_CAN_CAST_POINTERS
# define PTHREAD_CANCELED ((void*)ERROR)
#else
# define PTHREAD_CANCELED ((void*)pthread_create)
#endif
/************************************************************ /************************************************************
* Global Type Declarations * Global Type Declarations

View File

@ -171,17 +171,19 @@ struct _TCB
/* Stack-Related Fields *********************************************/ /* Stack-Related Fields *********************************************/
uint32 adj_stack_size; /* Stack size after adjustment */ size_t adj_stack_size; /* Stack size after adjustment */
/* for hardware, processor, etc. */ /* for hardware, processor, etc. */
/* (for debug purposes only) */ /* (for debug purposes only) */
uint32 *stack_alloc_ptr; /* Pointer to allocated stack */ void *stack_alloc_ptr; /* Pointer to allocated stack */
/* Need to deallocate stack */ /* Need to deallocate stack */
uint32 *adj_stack_ptr; /* Adjusted StatckAllocPtr for HW */ void *adj_stack_ptr; /* Adjusted StatckAllocPtr for HW */
/* The initial stack pointer value */ /* The initial stack pointer value */
/* POSIX thread Specific Data ***************************************/ /* POSIX thread Specific Data ***************************************/
#if CONFIG_NPTHREAD_KEYS > 0
void *pthread_data[CONFIG_NPTHREAD_KEYS]; void *pthread_data[CONFIG_NPTHREAD_KEYS];
#endif
/* POSIX Semaphore Control Fields ***********************************/ /* POSIX Semaphore Control Fields ***********************************/

View File

@ -112,6 +112,7 @@
* Type Declarations * Type Declarations
************************************************************/ ************************************************************/
#ifndef __ASSEMBLY__
#ifndef CONFIG_HAVE_DOUBLE #ifndef CONFIG_HAVE_DOUBLE
typedef float double_t; typedef float double_t;
#else #else
@ -120,15 +121,21 @@ typedef double double_t;
/* Misc. scalar types */ /* Misc. scalar types */
typedef uint32 mode_t; typedef unsigned int mode_t;
#ifdef CONFIG_SMALL_MEMORY
typedef uint16 size_t;
typedef sint16 ssize_t;
typedef sint16 off_t;
#else
typedef uint32 size_t; typedef uint32 size_t;
typedef sint32 ssize_t; typedef sint32 ssize_t;
//typedef sint32 time_t;
typedef sint32 off_t; typedef sint32 off_t;
typedef sint32 uid_t; #endif
typedef sint32 gid_t; //typedef sint32 time_t;
typedef uint32 dev_t; typedef sint16 uid_t;
typedef uint32 ino_t; typedef sint16 gid_t;
typedef uint16 dev_t;
typedef uint16 ino_t;
typedef unsigned int sig_atomic_t; typedef unsigned int sig_atomic_t;
typedef int pid_t; typedef int pid_t;
typedef int STATUS; typedef int STATUS;
@ -143,6 +150,7 @@ struct sched_param
{ {
int sched_priority; int sched_priority;
}; };
#endif
/************************************************************ /************************************************************
* Global Function Prototypes * Global Function Prototypes

View File

@ -55,11 +55,28 @@
* Global Type Declarations * Global Type Declarations
************************************************************/ ************************************************************/
/* The arguments are passed as uint32 values. For systems
* where the sizeof(pointer) < sizeof(uint32), the following
* union defines the alignment of the pointer within the
* uint32. For example, the SDCC MCS51 general pointer is
* 24-bits, but uint32 is 32-bits (of course).
*
* For systems where sizeof(pointer) > sizeof(uint32), we will
* have to do some redesign.
*/
union wdparm_u
{
void *pvarg;
uint32 *dwarg;
};
typedef union wdparm_u wdparm_t;
/* This is the form of the function that is called when the /* This is the form of the function that is called when the
* watchdog function expires. Up to four parameters may be passed. * watchdog function expires. Up to four parameters may be passed.
*/ */
typedef void (*wdentry_t)(int arg1, ...); typedef void (*wdentry_t)(int argc, uint32 arg1, ...);
/* Watchdog 'handle' */ /* Watchdog 'handle' */
@ -81,10 +98,10 @@ extern "C" {
#endif #endif
EXTERN WDOG_ID wd_create(void); EXTERN WDOG_ID wd_create(void);
EXTERN STATUS wd_delete(WDOG_ID wdId); EXTERN STATUS wd_delete(WDOG_ID wdog);
EXTERN STATUS wd_start(WDOG_ID wdId, int delay, wdentry_t wdentry, EXTERN STATUS wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry,
int parm1, int parm2, int parm3, int parm4); int argc, ...);
EXTERN STATUS wd_cancel(WDOG_ID wdId); EXTERN STATUS wd_cancel(WDOG_ID wdog);
#undef EXTERN #undef EXTERN
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -68,7 +68,7 @@ COBJS = $(CSRCS:.c=.o)
SRCS = $(ASRCS) $(CSRCS) SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS) OBJS = $(AOBJS) $(COBJS)
BIN = liblib.a BIN = liblib$(LIBEXT)
all: $(BIN) all: $(BIN)
@ -79,7 +79,10 @@ $(COBJS): %.o: %.c
$(CC) -c $(CFLAGS) $< -o $@ $(CC) -c $(CFLAGS) $< -o $@
$(BIN): $(OBJS) $(BIN): $(OBJS)
$(AR) rcs $@ $(OBJS) ( for obj in $(OBJS) ; do \
$(AR) $@ $${obj} || \
{ echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \
done ; )
.depend: Makefile $(SRCS) .depend: Makefile $(SRCS)
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep

View File

@ -47,7 +47,7 @@ COBJS = $(CSRCS:.c=.o)
SRCS = $(ASRCS) $(CSRCS) SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS) OBJS = $(AOBJS) $(COBJS)
BIN = libmm.a BIN = libmm$(LIBEXT)
all: $(BIN) all: $(BIN)
@ -58,7 +58,10 @@ $(COBJS): %.o: %.c
$(CC) -c $(CFLAGS) $< -o $@ $(CC) -c $(CFLAGS) $< -o $@
$(BIN): $(OBJS) $(BIN): $(OBJS)
$(AR) rcs $@ $(OBJS) ( for obj in $(OBJS) ; do \
$(AR) $@ $${obj} || \
{ echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \
done ; )
.depend: Makefile $(SRCS) .depend: Makefile $(SRCS)
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep

View File

@ -69,10 +69,6 @@
#ifdef MM_TEST #ifdef MM_TEST
/* Standard types */
typedef unsigned int uint32;
/* Use the real system errno */ /* Use the real system errno */
# define mm_errno errno # define mm_errno errno

View File

@ -50,7 +50,7 @@
/* This is the size of the heap provided to mm */ /* This is the size of the heap provided to mm */
uint32 g_heapsize; size_t g_heapsize;
/* This is the first and last nodes of the heap */ /* This is the first and last nodes of the heap */
@ -97,8 +97,8 @@ void mm_initialize(void *heapstart, size_t heapsize)
* both aligned with the MM_MIN_CHUNK size. * both aligned with the MM_MIN_CHUNK size.
*/ */
uint32 heapbase = MM_ALIGN_UP((uint32)heapstart); size_t heapbase = MM_ALIGN_UP((size_t)heapstart);
uint32 heapend = MM_ALIGN_DOWN((uint32)heapstart + (uint32)heapsize); size_t heapend = MM_ALIGN_DOWN((size_t)heapstart + (size_t)heapsize);
/* Save the size of the heap */ /* Save the size of the heap */

View File

@ -61,8 +61,13 @@
* losses. * losses.
*/ */
#define MM_MIN_SHIFT 4 /* 16 bytes */ #ifdef CONFIG_SMALL_MEMORY
#define MM_MAX_SHIFT 22 /* 4 Mb */ # define MM_MIN_SHIFT 4 /* 16 bytes */
# define MM_MAX_SHIFT 15 /* 32 Kb */
#else
# define MM_MIN_SHIFT 4 /* 16 bytes */
# define MM_MAX_SHIFT 22 /* 4 Mb */
#endif
/* All other definitions derive from these two */ /* All other definitions derive from these two */
@ -79,7 +84,11 @@
* an allocated chunk. * an allocated chunk.
*/ */
#define MM_ALLOC_BIT 0x80000000 #ifdef CONFIG_SMALL_MEMORY
# define MM_ALLOC_BIT 0x8000
#else
# define MM_ALLOC_BIT 0x80000000
#endif
#define MM_IS_ALLOCATED(n) \ #define MM_IS_ALLOCATED(n) \
((int)((struct mm_allocnode_s*)(n)->preceding) < 0)) ((int)((struct mm_allocnode_s*)(n)->preceding) < 0))
@ -94,11 +103,16 @@
struct mm_allocnode_s struct mm_allocnode_s
{ {
uint32 size; /* Size of this chunk */ size_t size; /* Size of this chunk */
uint32 preceding; /* Size of the preceding chunk */ size_t preceding; /* Size of the preceding chunk */
}; };
#define SIZEOF_MM_ALLOCNODE 8 #ifdef CONFIG_SMALL_MEMORY
# define SIZEOF_MM_ALLOCNODE 4
#else
# define SIZEOF_MM_ALLOCNODE 8
#endif
#define CHECK_ALLOCNODE_SIZE \ #define CHECK_ALLOCNODE_SIZE \
DEBUGASSERT(sizeof(struct mm_allocnode_s) == SIZEOF_MM_ALLOCNODE) DEBUGASSERT(sizeof(struct mm_allocnode_s) == SIZEOF_MM_ALLOCNODE)
@ -106,13 +120,17 @@ struct mm_allocnode_s
struct mm_freenode_s struct mm_freenode_s
{ {
uint32 size; /* Size of this chunk */ size_t size; /* Size of this chunk */
uint32 preceding; /* Size of the preceding chunk */ size_t preceding; /* Size of the preceding chunk */
struct mm_freenode_s *flink; /* Supports a doubly linked list */ struct mm_freenode_s *flink; /* Supports a doubly linked list */
struct mm_freenode_s *blink; struct mm_freenode_s *blink;
}; };
#define SIZEOF_MM_FREENODE 16 #ifdef CONFIG_SMALL_MEMORY
# define SIZEOF_MM_FREENODE 10
#else
# define SIZEOF_MM_FREENODE 16
#endif
#define CHECK_FREENODE_SIZE \ #define CHECK_FREENODE_SIZE \
DEBUGASSERT(sizeof(struct mm_freenode_s) == SIZEOF_MM_FREENODE) DEBUGASSERT(sizeof(struct mm_freenode_s) == SIZEOF_MM_FREENODE)
@ -138,7 +156,7 @@ struct mallinfo
/* This is the size of the heap provided to mm */ /* This is the size of the heap provided to mm */
extern uint32 g_heapsize; extern size_t g_heapsize;
/* This is the first and last nodes of the heap */ /* This is the first and last nodes of the heap */
@ -168,9 +186,9 @@ extern struct mm_freenode_s g_nodelist[MM_NNODES];
extern struct mallinfo mallinfo(void); extern struct mallinfo mallinfo(void);
#endif #endif
extern void mm_shrinkchunk(struct mm_allocnode_s *node, uint32 size); extern void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size);
extern void mm_addfreechunk(struct mm_freenode_s *node); extern void mm_addfreechunk(struct mm_freenode_s *node);
extern int mm_size2ndx(uint32 size); extern int mm_size2ndx(size_t size);
extern void mm_seminitialize(void); extern void mm_seminitialize(void);
extern void mm_takesemaphore(void); extern void mm_takesemaphore(void);
extern void mm_givesemaphore(void); extern void mm_givesemaphore(void);

View File

@ -69,10 +69,10 @@ struct mallinfo mallinfo(void)
{ {
static struct mallinfo stats; static struct mallinfo stats;
struct mm_allocnode_s *node; struct mm_allocnode_s *node;
uint32 mxordblk = 0; size_t mxordblk = 0;
int ordblks = 0; /* Number of non-inuse chunks */ int ordblks = 0; /* Number of non-inuse chunks */
uint32 uordblks = 0; /* Total allocated space */ size_t uordblks = 0; /* Total allocated space */
uint32 fordblks = 0; /* Total non-inuse space */ size_t fordblks = 0; /* Total non-inuse space */
/* Visit each node in physical memory */ /* Visit each node in physical memory */

View File

@ -144,7 +144,7 @@ void *malloc(size_t size)
{ {
struct mm_freenode_s *remainder; struct mm_freenode_s *remainder;
struct mm_freenode_s *next; struct mm_freenode_s *next;
uint32 remaining; size_t remaining;
/* Remove the node. There must be a predecessor, but there may /* Remove the node. There must be a predecessor, but there may
* not be a successor node. * not be a successor node.

View File

@ -66,10 +66,10 @@
void *memalign(size_t alignment, size_t size) void *memalign(size_t alignment, size_t size)
{ {
struct mm_allocnode_s *node; struct mm_allocnode_s *node;
uint32 rawchunk; size_t rawchunk;
uint32 alignedchunk; size_t alignedchunk;
uint32 mask = (uint32)(alignment - 1); size_t mask = (size_t)(alignment - 1);
uint32 allocsize; size_t allocsize;
/* If this requested alignement less than or equal to the /* If this requested alignement less than or equal to the
* natural alignment of malloc, then just let malloc do the * natural alignment of malloc, then just let malloc do the
@ -99,7 +99,7 @@ void *memalign(size_t alignment, size_t size)
/* Then malloc that size */ /* Then malloc that size */
rawchunk = (uint32)malloc(allocsize); rawchunk = (size_t)malloc(allocsize);
if (!rawchunk) if (!rawchunk)
{ {
return NULL; return NULL;
@ -127,7 +127,7 @@ void *memalign(size_t alignment, size_t size)
{ {
struct mm_allocnode_s *newnode; struct mm_allocnode_s *newnode;
struct mm_allocnode_s *next; struct mm_allocnode_s *next;
uint32 precedingsize; size_t precedingsize;
/* Get the node the next node after the allocation. */ /* Get the node the next node after the allocation. */
@ -145,7 +145,7 @@ void *memalign(size_t alignment, size_t size)
* SIZEOF_MM_ALLOCNODE * SIZEOF_MM_ALLOCNODE
*/ */
precedingsize = (uint32)newnode - (uint32)node; precedingsize = (size_t)newnode - (size_t)node;
/* If we were unlucky, then the alignedchunk can lie in such /* If we were unlucky, then the alignedchunk can lie in such
* a position that precedingsize < SIZEOF_NODE_FREENODE. We * a position that precedingsize < SIZEOF_NODE_FREENODE. We
@ -159,12 +159,12 @@ void *memalign(size_t alignment, size_t size)
{ {
alignedchunk += alignment; alignedchunk += alignment;
newnode = (struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE); newnode = (struct mm_allocnode_s*)(alignedchunk - SIZEOF_MM_ALLOCNODE);
precedingsize = (uint32)newnode - (uint32)node; precedingsize = (size_t)newnode - (size_t)node;
} }
/* Set up the size of the new node */ /* Set up the size of the new node */
newnode->size = (uint32)next - (uint32)newnode; newnode->size = (size_t)next - (size_t)newnode;
newnode->preceding = precedingsize | MM_ALLOC_BIT; newnode->preceding = precedingsize | MM_ALLOC_BIT;
/* Reduce the size of the original chunk and mark it not allocated, */ /* Reduce the size of the original chunk and mark it not allocated, */

View File

@ -78,9 +78,9 @@ void *realloc(void *oldmem, size_t size)
struct mm_allocnode_s *oldnode; struct mm_allocnode_s *oldnode;
struct mm_freenode_s *prev; struct mm_freenode_s *prev;
struct mm_freenode_s *next; struct mm_freenode_s *next;
uint32 oldsize; size_t oldsize;
uint32 prevsize = 0; size_t prevsize = 0;
uint32 nextsize = 0; size_t nextsize = 0;
/* If oldmem is NULL, then realloc is equivalent to malloc */ /* If oldmem is NULL, then realloc is equivalent to malloc */
@ -145,9 +145,9 @@ void *realloc(void *oldmem, size_t size)
if (nextsize + prevsize + oldsize >= size) if (nextsize + prevsize + oldsize >= size)
{ {
uint32 needed = size - oldsize; size_t needed = size - oldsize;
uint32 takeprev; size_t takeprev;
uint32 takenext; size_t takenext;
/* Check if we can extend into the previous chunk and if the /* Check if we can extend into the previous chunk and if the
* previous chunk is smaller than the next chunk. * previous chunk is smaller than the next chunk.

View File

@ -64,7 +64,7 @@
* *
************************************************************/ ************************************************************/
void mm_shrinkchunk(struct mm_allocnode_s *node, uint32 size) void mm_shrinkchunk(struct mm_allocnode_s *node, size_t size)
{ {
struct mm_freenode_s *next; struct mm_freenode_s *next;

View File

@ -50,7 +50,7 @@
/* Convert the size to a nodelist index */ /* Convert the size to a nodelist index */
int mm_size2ndx(uint32 size) int mm_size2ndx(size_t size)
{ {
int ndx = 0; int ndx = 0;

View File

@ -37,7 +37,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
typedef unsigned int uint32;
#include "mm_internal.h" #include "mm_internal.h"
/* Definitions */ /* Definitions */

View File

@ -40,7 +40,7 @@ MKDEP = $(TOPDIR)/tools/mkdeps.sh
ASRCS = ASRCS =
AOBJS = $(ASRCS:.S=.o) AOBJS = $(ASRCS:.S=.o)
MISC_SRCS = os_start.c get_errno_ptr.c \ MISC_SRCS = os_start.c get_errno_ptr.c get_errorptr.c \
sched_setupstreams.c sched_getfiles.c sched_getstreams.c \ sched_setupstreams.c sched_getfiles.c sched_getstreams.c \
sched_setupidlefiles.c sched_setuptaskfiles.c sched_setuppthreadfiles.c \ sched_setupidlefiles.c sched_setuptaskfiles.c sched_setuppthreadfiles.c \
sched_releasefiles.c sched_releasefiles.c
@ -101,7 +101,7 @@ COBJS = $(CSRCS:.c=.o)
SRCS = $(ASRCS) $(CSRCS) SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS) OBJS = $(AOBJS) $(COBJS)
BIN = libsched.a BIN = libsched$(LIBEXT)
all: $(BIN) all: $(BIN)
@ -112,7 +112,10 @@ $(COBJS): %.o: %.c
$(CC) -c $(CFLAGS) $< -o $@ $(CC) -c $(CFLAGS) $< -o $@
$(BIN): $(OBJS) $(BIN): $(OBJS)
$(AR) rcs $@ $(OBJS) ( for obj in $(OBJS) ; do \
$(AR) $@ $${obj} || \
{ echo "$(AR) $@ $obj FAILED!" ; exit 1 ; } ; \
done ; )
.depend: Makefile $(SRCS) .depend: Makefile $(SRCS)
$(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep $(MKDEP) $(CC) -- $(CFLAGS) -- $(SRCS) >Make.dep

83
sched/get_errorptr.c Normal file
View File

@ -0,0 +1,83 @@
/************************************************************
* get_errorptr.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
************************************************************/
/************************************************************
* Included Files
************************************************************/
#include <sys/types.h>
#include <errno.h>
/************************************************************
* Global Functions
************************************************************/
/************************************************************
* Function: get_errorptr
*
* Description:
* Return a pointer that is just ERROR cast to void *.
* most fully performing processors don't need anything
* like this. Hoever, this little of nonsense is necessary
* for some processors where sizeof(pointer) < sizeof(uint32)
* and which do not support casts of integers to pointers.
*
* Parameters:
* None
*
* Return Value:
* ERROR cast as a pointer value
*
* Assumptions:
*
************************************************************/
void *get_errnorptr(void)
{
#ifdef CONFIG_CAN_CAST_POINTERS
return (void*)ERROR;
#else
union
{
void *verror;
sint32 ierror;
} u;
u.ierror = ERROR;
return u.verror;
#endif
}

View File

@ -80,7 +80,7 @@ int irq_attach(int irq, xcpt_t isr)
if ((unsigned)irq < NR_IRQS) if ((unsigned)irq < NR_IRQS)
{ {
int state; irqstate_t state;
/* If the new ISR is NULL, then the ISR is being detached. /* If the new ISR is NULL, then the ISR is being detached.
* In this case, disable the ISR and direct any interrupts * In this case, disable the ISR and direct any interrupts

View File

@ -115,7 +115,7 @@ int mq_close(mqd_t mqdes)
{ {
_TCB *rtcb = (_TCB*)g_readytorun.head; _TCB *rtcb = (_TCB*)g_readytorun.head;
msgq_t *msgq; msgq_t *msgq;
uint32 saved_state; irqstate_t saved_state;
int ret = ERROR; int ret = ERROR;
/* Verify the inputs */ /* Verify the inputs */

View File

@ -86,7 +86,7 @@
void mq_msgfree(mqmsg_t * mqmsg) void mq_msgfree(mqmsg_t * mqmsg)
{ {
uint32 saved_state; irqstate_t saved_state;
/* If this is a generally available pre-allocated message, /* If this is a generally available pre-allocated message,
* then just put it back in the free list. * then just put it back in the free list.

View File

@ -141,7 +141,7 @@ int mq_notify(mqd_t mqdes, const struct sigevent *notification)
{ {
/* Yes... Assign it to the current task. */ /* Yes... Assign it to the current task. */
msgq->ntvalue = notification->sigev_value; msgq->ntvalue.sival_ptr = notification->sigev_value.sival_ptr;
msgq->ntsigno = notification->sigev_signo; msgq->ntsigno = notification->sigev_signo;
msgq->ntpid = rtcb->pid; msgq->ntpid = rtcb->pid;
msgq->ntmqdes = mqdes; msgq->ntmqdes = mqdes;
@ -159,7 +159,7 @@ int mq_notify(mqd_t mqdes, const struct sigevent *notification)
msgq->ntpid = INVALID_PROCESS_ID; msgq->ntpid = INVALID_PROCESS_ID;
msgq->ntsigno = 0; msgq->ntsigno = 0;
msgq->ntvalue.sival_int = 0; msgq->ntvalue.sival_ptr = NULL;
msgq->ntmqdes = NULL; msgq->ntmqdes = NULL;
ret = OK; ret = OK;
} }

View File

@ -42,6 +42,7 @@
#include <mqueue.h> #include <mqueue.h>
#include <string.h> #include <string.h>
#include <sched.h> #include <sched.h>
#include <errno.h>
#include <debug.h> #include <debug.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include "os_internal.h" #include "os_internal.h"
@ -217,7 +218,11 @@ mqd_t mq_open(const char *mq_name, int oflags, ...)
if (mqdes == NULL) if (mqdes == NULL)
{ {
#ifdef CONFIG_CAN_CAST_POINTERS
return (mqd_t)ERROR; return (mqd_t)ERROR;
#else
return get_errorptr();
#endif
} }
else else
{ {

View File

@ -118,7 +118,7 @@ int mq_receive(mqd_t mqdes, void *msg, size_t msglen, int *prio)
_TCB *btcb; _TCB *btcb;
msgq_t *msgq; msgq_t *msgq;
mqmsg_t *curr; mqmsg_t *curr;
uint32 saved_state; irqstate_t saved_state;
ubyte rcvmsglen; ubyte rcvmsglen;
int ret = ERROR; int ret = ERROR;

View File

@ -95,7 +95,7 @@
mqmsg_t *mq_msgalloc(void) mqmsg_t *mq_msgalloc(void)
{ {
mqmsg_t *mqmsg; mqmsg_t *mqmsg;
uint32 saved_state; irqstate_t saved_state;
/* If we were called from an interrupt handler, then try to /* If we were called from an interrupt handler, then try to
* get the message from generally available list of messages. * get the message from generally available list of messages.
@ -208,7 +208,7 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
mqmsg_t *curr; mqmsg_t *curr;
mqmsg_t *next; mqmsg_t *next;
mqmsg_t *prev; mqmsg_t *prev;
uint32 saved_state; irqstate_t saved_state;
int ret = ERROR; int ret = ERROR;
/* Verify the input parameters */ /* Verify the input parameters */
@ -343,7 +343,11 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
{ {
/* Remove the message notification data from the message queue. */ /* Remove the message notification data from the message queue. */
#ifdef CONFIG_CAN_PASS_STRUCTS
union sigval value = msgq->ntvalue; union sigval value = msgq->ntvalue;
#else
void *sival_ptr = msgq->ntvalue.sival_ptr;
#endif
int signo = msgq->ntsigno; int signo = msgq->ntsigno;
int pid = msgq->ntpid; int pid = msgq->ntpid;
@ -356,7 +360,11 @@ int mq_send(mqd_t mqdes, const void *msg, size_t msglen, int prio)
/* Queue the signal -- What if this returns an error? */ /* Queue the signal -- What if this returns an error? */
#ifdef CONFIG_CAN_PASS_STRUCTS
sig_mqnotempty(pid, signo, value); sig_mqnotempty(pid, signo, value);
#else
sig_mqnotempty(pid, signo, sival_ptr);
#endif
} }
/* Check if any tasks are waiting for the MQ not empty event. */ /* Check if any tasks are waiting for the MQ not empty event. */

View File

@ -90,7 +90,7 @@
int mq_unlink(const char *mq_name) int mq_unlink(const char *mq_name)
{ {
msgq_t *msgq; msgq_t *msgq;
uint32 saved_state; irqstate_t saved_state;
int ret = ERROR; int ret = ERROR;
/* Verify the input values */ /* Verify the input values */

View File

@ -386,7 +386,7 @@ void os_start(void)
{ {
/* Remove the first delayed deallocation. */ /* Remove the first delayed deallocation. */
uint32 saved_state = irqsave(); irqstate_t saved_state = irqsave();
void *address = (void*)sq_remfirst(&g_delayeddeallocations); void *address = (void*)sq_remfirst(&g_delayeddeallocations);
irqrestore(saved_state); irqrestore(saved_state);

View File

@ -71,14 +71,18 @@
* Private Functions * Private Functions
************************************************************/ ************************************************************/
static void pthread_condtimedout(int pid, int signo, int arg3, int arg4) static void pthread_condtimedout(int argc, uint32 pid, uint32 signo, ...)
{ {
#ifdef CONFIG_CAN_PASS_STRUCTS
union sigval value; union sigval value;
/* Send the specified signal to the specified task. */ /* Send the specified signal to the specified task. */
value.sival_ptr = 0; value.sival_ptr = NULL;
(void)sigqueue(pid, signo, value); (void)sigqueue((int)pid, (int)signo, value);
#else
(void)sigqueue((int)pid, (int)signo, NULL);
#endif
} }
/************************************************************ /************************************************************
@ -112,8 +116,8 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
sint32 relusec; sint32 relusec;
sint32 ticks; sint32 ticks;
int mypid = (int)getpid(); int mypid = (int)getpid();
irqstate_t int_state;
int ret = OK; int ret = OK;
int int_state;
int status; int status;
dbg("cond=0x%p mutex=0x%p abstime=0x%p\n", cond, mutex, abstime); dbg("cond=0x%p mutex=0x%p abstime=0x%p\n", cond, mutex, abstime);
@ -240,7 +244,7 @@ int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
/* Start the watchdog */ /* Start the watchdog */
wd_start(wdog, ticks, (wdentry_t)pthread_condtimedout, wd_start(wdog, ticks, (wdentry_t)pthread_condtimedout,
mypid, ECHO_COND_WAIT_SIGNO, 0, 0); 2, (uint32)mypid, (uint32)ECHO_COND_WAIT_SIGNO);
/* Take the condition semaphore. Do not restore interrupts /* Take the condition semaphore. Do not restore interrupts
* until we return from the wait. This is necessary to * until we return from the wait. This is necessary to

View File

@ -65,10 +65,10 @@
pthread_attr_t g_default_pthread_attr = pthread_attr_t g_default_pthread_attr =
{ {
.stacksize = PTHREAD_STACK_DEFAULT, PTHREAD_STACK_DEFAULT, /* stacksize */
.priority = PTHREAD_DEFAULT_PRIORITY, PTHREAD_DEFAULT_PRIORITY, /* priority */
.policy = SCHED_RR, SCHED_RR, /* policy */
.inheritsched = PTHREAD_EXPLICIT_SCHED, PTHREAD_EXPLICIT_SCHED, /* inheritsched */
}; };
/************************************************************ /************************************************************

View File

@ -37,6 +37,8 @@
* Included Files * Included Files
************************************************************/ ************************************************************/
#include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
#include <sched.h> #include <sched.h>
#include <errno.h> #include <errno.h>
@ -103,6 +105,7 @@
void *pthread_getspecific(pthread_key_t key) void *pthread_getspecific(pthread_key_t key)
{ {
#if CONFIG_NPTHREAD_KEYS > 0
_TCB *rtcb = (_TCB*)g_readytorun.head; _TCB *rtcb = (_TCB*)g_readytorun.head;
void *ret = NULL; void *ret = NULL;
@ -116,4 +119,7 @@ void *pthread_getspecific(pthread_key_t key)
} }
return ret; return ret;
#else
return NULL;
#endif
} }

View File

@ -37,6 +37,8 @@
* Included Files * Included Files
************************************************************/ ************************************************************/
#include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
#include <sched.h> #include <sched.h>
#include <errno.h> #include <errno.h>
@ -112,6 +114,7 @@
int pthread_key_create(pthread_key_t *key, void (*destructor)(void*)) int pthread_key_create(pthread_key_t *key, void (*destructor)(void*))
{ {
#if CONFIG_NPTHREAD_KEYS > 0
int ret = EAGAIN; int ret = EAGAIN;
/* Check if we have exceeded the system-defined number of keys. */ /* Check if we have exceeded the system-defined number of keys. */
@ -132,4 +135,7 @@ int pthread_key_create(pthread_key_t *key, void (*destructor)(void*))
} }
return ret; return ret;
#else
return ENOSYS;
#endif
} }

View File

@ -37,6 +37,8 @@
* Included Files * Included Files
************************************************************/ ************************************************************/
#include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
#include <sched.h> #include <sched.h>
#include <errno.h> #include <errno.h>
@ -91,3 +93,4 @@ int pthread_key_delete(pthread_key_t key)
{ {
return ENOSYS; return ENOSYS;
} }

View File

@ -37,6 +37,8 @@
* Included Files * Included Files
************************************************************/ ************************************************************/
#include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
#include <sched.h> #include <sched.h>
#include <errno.h> #include <errno.h>
@ -111,6 +113,7 @@
int pthread_setspecific(pthread_key_t key, void *value) int pthread_setspecific(pthread_key_t key, void *value)
{ {
#if CONFIG_NPTHREAD_KEYS > 0
_TCB *rtcb = (_TCB*)g_readytorun.head; _TCB *rtcb = (_TCB*)g_readytorun.head;
int ret = EINVAL; int ret = EINVAL;
@ -128,4 +131,9 @@ int pthread_setspecific(pthread_key_t key, void *value)
} }
return ret; return ret;
#else
return ENOSYS;
#endif
} }

View File

@ -90,7 +90,7 @@ void sched_free(void *address)
{ {
/* Yes.. Delay the deallocation until a more appropriate time. */ /* Yes.. Delay the deallocation until a more appropriate time. */
uint32 saved_state = irqsave(); irqstate_t saved_state = irqsave();
sq_addlast((sq_entry_t*)address, &g_delayeddeallocations); sq_addlast((sq_entry_t*)address, &g_delayeddeallocations);
irqrestore(saved_state); irqrestore(saved_state);
} }

View File

@ -108,7 +108,7 @@ int sched_setparam(pid_t pid, const struct sched_param *param)
_TCB *rtcb; _TCB *rtcb;
_TCB *tcb; _TCB *tcb;
tstate_t task_state; tstate_t task_state;
uint32 saved_state; irqstate_t saved_state;
int sched_priority = param->sched_priority; int sched_priority = param->sched_priority;
int ret = 0; int ret = 0;

View File

@ -112,7 +112,7 @@ int sched_setscheduler(pid_t pid, int policy,
{ {
_TCB *tcb; _TCB *tcb;
#if CONFIG_RR_INTERVAL > 0 #if CONFIG_RR_INTERVAL > 0
uint32 saved_state; irqstate_t saved_state;
#endif #endif
int ret; int ret;

View File

@ -41,6 +41,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <semaphore.h> #include <semaphore.h>
#include <errno.h>
#include <nuttx/kmalloc.h> #include <nuttx/kmalloc.h>
#include "sem_internal.h" #include "sem_internal.h"
@ -117,7 +118,11 @@ sem_t *sem_open (const char *name, int oflag, ...)
{ {
int namelen; int namelen;
nsem_t *psem; nsem_t *psem;
#ifdef CONFIG_CAN_CAST_POINTERS
sem_t *sem = (sem_t*)ERROR; sem_t *sem = (sem_t*)ERROR;
#else
sem_t *sem = get_errorptr();
#endif
va_list arg; /* Points to each un-named argument */ va_list arg; /* Points to each un-named argument */
mode_t mode; /* Creation mode parameter (ignored) */ mode_t mode; /* Creation mode parameter (ignored) */
unsigned int value; /* Semaphore value parameter */ unsigned int value; /* Semaphore value parameter */

View File

@ -108,7 +108,7 @@ int sem_post (sem_t *sem)
{ {
_TCB *stcb; _TCB *stcb;
STATUS ret = ERROR; STATUS ret = ERROR;
uint32 saved_state; irqstate_t saved_state;
/* Make sure we were supplied with a valid semaphore. */ /* Make sure we were supplied with a valid semaphore. */

View File

@ -99,7 +99,7 @@
int sem_trywait(sem_t *sem) int sem_trywait(sem_t *sem)
{ {
_TCB *rtcb = (_TCB*)g_readytorun.head; _TCB *rtcb = (_TCB*)g_readytorun.head;
uint32 saved_state; irqstate_t saved_state;
int ret = ERROR; int ret = ERROR;
/* Assume any errors reported are due to invalid arguments. */ /* Assume any errors reported are due to invalid arguments. */

View File

@ -101,7 +101,7 @@ int sem_wait (sem_t *sem)
{ {
_TCB *rtcb = (_TCB*)g_readytorun.head; _TCB *rtcb = (_TCB*)g_readytorun.head;
int ret = ERROR; int ret = ERROR;
uint32 saved_state; irqstate_t saved_state;
/* Assume any errors reported are due to invalid arguments. */ /* Assume any errors reported are due to invalid arguments. */

View File

@ -94,7 +94,7 @@
void sem_waitirq (_TCB *wtcb) void sem_waitirq (_TCB *wtcb)
{ {
uint32 saved_state; irqstate_t saved_state;
/* Disable interrupts. This is necessary (unfortunately) because an /* Disable interrupts. This is necessary (unfortunately) because an
* interrupt handler may attempt to post the semaphore while we are * interrupt handler may attempt to post the semaphore while we are

View File

@ -78,7 +78,7 @@
sigq_t *sig_allocatependingsigaction(void) sigq_t *sig_allocatependingsigaction(void)
{ {
sigq_t *sigq; sigq_t *sigq;
uint32 saved_state; irqstate_t saved_state;
/* Check if we were called from an interrupt handler. */ /* Check if we were called from an interrupt handler. */

View File

@ -87,7 +87,7 @@ void sig_deliver(_TCB *stcb)
sigq_t *sigq; sigq_t *sigq;
sigq_t *next; sigq_t *next;
sigset_t savesigprocmask; sigset_t savesigprocmask;
uint32 saved_state; irqstate_t saved_state;
int saved_errno; int saved_errno;
sched_lock(); sched_lock();

View File

@ -80,7 +80,11 @@
* *
************************************************************/ ************************************************************/
#ifdef CONFIG_CAN_PASS_STRUCTS
int sig_mqnotempty (int pid, int signo, const union sigval value) int sig_mqnotempty (int pid, int signo, const union sigval value)
#else
int sig_mqnotempty (int pid, int signo, void *sival_ptr)
#endif
{ {
_TCB *stcb; _TCB *stcb;
siginfo_t info; siginfo_t info;
@ -91,14 +95,22 @@ int sig_mqnotempty (int pid, int signo, const union sigval value)
/* Get the TCB of the receiving task */ /* Get the TCB of the receiving task */
stcb = sched_gettcb(pid); stcb = sched_gettcb(pid);
dbg("sig_mqnotempty: TCB=0x%08x signo=%d value=%d\n",
stcb, signo, value.sival_int); #ifdef CONFIG_CAN_PASS_STRUCTS
dbg("TCB=%p signo=%d value=%d\n", stcb, signo, value.sival_int);
#else
dbg("TCB=%p signo=%d sival_ptr=%p\n", stcb, signo, sival_ptr);
#endif
/* Create the siginfo structure */ /* Create the siginfo structure */
info.si_signo = signo; info.si_signo = signo;
info.si_code = SI_MESGQ; info.si_code = SI_MESGQ;
#ifdef CONFIG_CAN_PASS_STRUCTS
info.si_value = value; info.si_value = value;
#else
info.si_value.sival_ptr = sival_ptr;
#endif
/* Verify that we can perform the signalling operation */ /* Verify that we can perform the signalling operation */

View File

@ -110,7 +110,7 @@ sigset_t sig_pendingset(_TCB *stcb)
{ {
sigset_t sigpendset; sigset_t sigpendset;
sigpendq_t *sigpend; sigpendq_t *sigpend;
uint32 saved_state; irqstate_t saved_state;
sigpendset = NULL_SIGNAL_SET; sigpendset = NULL_SIGNAL_SET;

View File

@ -116,7 +116,7 @@ int sigprocmask(int how, const sigset_t *set, sigset_t *oset)
{ {
_TCB *rtcb = (_TCB*)g_readytorun.head; _TCB *rtcb = (_TCB*)g_readytorun.head;
sigset_t oldsigprocmask; sigset_t oldsigprocmask;
uint32 saved_state; irqstate_t saved_state;
int ret = OK; int ret = OK;
sched_lock(); sched_lock();

View File

@ -38,6 +38,7 @@
************************************************************/ ************************************************************/
#include <sys/types.h> #include <sys/types.h>
#include <string.h>
#include <signal.h> #include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <sched.h> #include <sched.h>
@ -79,7 +80,7 @@ static int sig_queueaction(_TCB *stcb, siginfo_t *info)
{ {
sigactq_t *sigact; sigactq_t *sigact;
sigq_t *sigq; sigq_t *sigq;
uint32 saved_state; irqstate_t saved_state;
int ret = OK; int ret = OK;
sched_lock(); sched_lock();
@ -106,7 +107,7 @@ static int sig_queueaction(_TCB *stcb, siginfo_t *info)
sigq->action.sighandler = sigact->act.sa_u._sa_sigaction; sigq->action.sighandler = sigact->act.sa_u._sa_sigaction;
sigq->mask = sigact->act.sa_mask; sigq->mask = sigact->act.sa_mask;
sigq->info = *info; memcpy(&sigq->info, info, sizeof(siginfo_t));
/* Put it at the end of the pending signals list */ /* Put it at the end of the pending signals list */
@ -131,7 +132,7 @@ static int sig_queueaction(_TCB *stcb, siginfo_t *info)
static sigpendq_t *sig_findpendingsignal(_TCB *stcb, int signo) static sigpendq_t *sig_findpendingsignal(_TCB *stcb, int signo)
{ {
sigpendq_t *sigpend = NULL; sigpendq_t *sigpend = NULL;
uint32 saved_state; irqstate_t saved_state;
/* Verify the caller's sanity */ /* Verify the caller's sanity */
@ -163,7 +164,7 @@ static sigpendq_t *sig_findpendingsignal(_TCB *stcb, int signo)
static sigpendq_t *sig_allocatependingsignal(void) static sigpendq_t *sig_allocatependingsignal(void)
{ {
sigpendq_t *sigpend; sigpendq_t *sigpend;
uint32 saved_state; irqstate_t saved_state;
/* Check if we were called from an interrupt handler. */ /* Check if we were called from an interrupt handler. */
@ -227,7 +228,7 @@ static sigpendq_t *sig_allocatependingsignal(void)
static sigpendq_t *sig_addpendingsignal(_TCB *stcb, siginfo_t *info) static sigpendq_t *sig_addpendingsignal(_TCB *stcb, siginfo_t *info)
{ {
sigpendq_t *sigpend; sigpendq_t *sigpend;
uint32 saved_state; irqstate_t saved_state;
/* Check if the signal is already pending */ /* Check if the signal is already pending */
@ -236,7 +237,7 @@ static sigpendq_t *sig_addpendingsignal(_TCB *stcb, siginfo_t *info)
{ {
/* The signal is already pending... retain only one copy */ /* The signal is already pending... retain only one copy */
sigpend->info = *info; memcpy(&sigpend->info, info, sizeof(siginfo_t));
} }
/* No... There is nothing pending for this signo */ /* No... There is nothing pending for this signo */
@ -250,7 +251,7 @@ static sigpendq_t *sig_addpendingsignal(_TCB *stcb, siginfo_t *info)
{ {
/* Put the signal information into the allocated structure */ /* Put the signal information into the allocated structure */
sigpend->info = *info; memcpy(&sigpend->info, info, sizeof(siginfo_t));
/* Add the structure to the pending signal list */ /* Add the structure to the pending signal list */
@ -284,8 +285,8 @@ static sigpendq_t *sig_addpendingsignal(_TCB *stcb, siginfo_t *info)
int sig_received(_TCB *stcb, siginfo_t *info) int sig_received(_TCB *stcb, siginfo_t *info)
{ {
irqstate_t saved_state;
int ret = ERROR; int ret = ERROR;
uint32 saved_state;
dbg("sig_received: TCB=0x%08x signo=%d code=%d value=%d\n", dbg("sig_received: TCB=0x%08x signo=%d code=%d value=%d\n",
stcb, info->si_signo, info->si_code, info->si_value.sival_int); stcb, info->si_signo, info->si_code, info->si_value.sival_int);
@ -310,7 +311,7 @@ int sig_received(_TCB *stcb, siginfo_t *info)
if (stcb->task_state == TSTATE_WAIT_SIG && if (stcb->task_state == TSTATE_WAIT_SIG &&
sigismember(&stcb->sigwaitmask, info->si_signo)) sigismember(&stcb->sigwaitmask, info->si_signo))
{ {
stcb->sigunbinfo = *info; memcpy(&stcb->sigunbinfo, info, sizeof(siginfo_t));
stcb->sigwaitmask = NULL_SIGNAL_SET; stcb->sigwaitmask = NULL_SIGNAL_SET;
up_unblock_task(stcb); up_unblock_task(stcb);
irqrestore(saved_state); irqrestore(saved_state);
@ -352,7 +353,7 @@ int sig_received(_TCB *stcb, siginfo_t *info)
saved_state = irqsave(); saved_state = irqsave();
if (stcb->task_state == TSTATE_WAIT_SIG) if (stcb->task_state == TSTATE_WAIT_SIG)
{ {
stcb->sigunbinfo = *info; memcpy(&stcb->sigunbinfo, info, sizeof(siginfo_t));
stcb->sigwaitmask = NULL_SIGNAL_SET; stcb->sigwaitmask = NULL_SIGNAL_SET;
up_unblock_task(stcb); up_unblock_task(stcb);
} }

View File

@ -76,7 +76,7 @@
void sig_releasependingsigaction(sigq_t *sigq) void sig_releasependingsigaction(sigq_t *sigq)
{ {
uint32 saved_state; irqstate_t saved_state;
/* If this is a generally available pre-allocated structyre, /* If this is a generally available pre-allocated structyre,
* then just put it back in the free list. * then just put it back in the free list.

View File

@ -84,7 +84,7 @@
void sig_releasependingsignal(sigpendq_t *sigpend) void sig_releasependingsignal(sigpendq_t *sigpend)
{ {
uint32 saved_state; irqstate_t saved_state;
/* If this is a generally available pre-allocated structyre, /* If this is a generally available pre-allocated structyre,
* then just put it back in the free list. * then just put it back in the free list.

View File

@ -84,8 +84,9 @@
sigpendq_t *sig_removependingsignal(_TCB *stcb, int signo) sigpendq_t *sig_removependingsignal(_TCB *stcb, int signo)
{ {
sigpendq_t *currsig, *prevsig; sigpendq_t *currsig;
uint32 saved_state; sigpendq_t *prevsig;
irqstate_t saved_state;
saved_state = irqsave(); saved_state = irqsave();
for (prevsig = NULL, currsig = (sigpendq_t*)stcb->sigpendingq.head; for (prevsig = NULL, currsig = (sigpendq_t*)stcb->sigpendingq.head;

View File

@ -115,7 +115,7 @@ int sigsuspend(const sigset_t *set)
sigset_t intersection; sigset_t intersection;
sigset_t saved_sigprocmask; sigset_t saved_sigprocmask;
sigpendq_t *sigpend; sigpendq_t *sigpend;
uint32 saved_state; irqstate_t saved_state;
int unblocksigno; int unblocksigno;
/* Several operations must be performed below: We must determine if any /* Several operations must be performed below: We must determine if any

View File

@ -38,6 +38,7 @@
************************************************************/ ************************************************************/
#include <sys/types.h> #include <sys/types.h>
#include <string.h>
#include <signal.h> #include <signal.h>
#include <time.h> #include <time.h>
#include <wdog.h> #include <wdog.h>
@ -76,11 +77,24 @@
* A timeout elapsed while waiting for signals to be queued. * A timeout elapsed while waiting for signals to be queued.
************************************************************/ ************************************************************/
static void sig_timeout(int itcb, int parm2, int parm3, int parm4) static void sig_timeout(int argc, uint32 itcb, ...)
{ {
_TCB *wtcb = (_TCB*)itcb; /* On many small machines, pointers are encoded and cannot
* be simply cast from uint32 to _TCB*. The following
* union works around this (see wdogparm_t). This odd
* logic could be conditioned on CONFIG_CAN_CAST_POINTERS,
* but it is not too bad in any case.
*/
if (!wtcb) union
{
_TCB *wtcb;
uint32 itcb;
} u;
u.itcb = itcb;
if (!u.wtcb)
{ {
PANIC(OSERR_TIMEOUTNOTCB); PANIC(OSERR_TIMEOUTNOTCB);
} }
@ -89,12 +103,12 @@ static void sig_timeout(int itcb, int parm2, int parm3, int parm4)
* still waiting for a signal * still waiting for a signal
*/ */
if (wtcb->task_state == TSTATE_WAIT_SIG) if (u.wtcb->task_state == TSTATE_WAIT_SIG)
{ {
wtcb->sigunbinfo.si_signo = ERROR; u.wtcb->sigunbinfo.si_signo = ERROR;
wtcb->sigunbinfo.si_code = SI_TIMEOUT; u.wtcb->sigunbinfo.si_code = SI_TIMEOUT;
wtcb->sigunbinfo.si_value.sival_int = 0; u.wtcb->sigunbinfo.si_value.sival_int = 0;
up_unblock_task(wtcb); up_unblock_task(u.wtcb);
} }
} }
@ -150,7 +164,7 @@ int sigtimedwait(const sigset_t *set, struct siginfo *info,
sigset_t intersection; sigset_t intersection;
sigpendq_t *sigpend; sigpendq_t *sigpend;
WDOG_ID wdog; WDOG_ID wdog;
uint32 saved_state; irqstate_t saved_state;
sint32 waitticks; sint32 waitticks;
int ret = ERROR; int ret = ERROR;
@ -184,7 +198,10 @@ int sigtimedwait(const sigset_t *set, struct siginfo *info,
/* Return the signal info to the caller if so requested */ /* Return the signal info to the caller if so requested */
if (info) *info = sigpend->info; if (info)
{
memcpy(info, &sigpend->info, sizeof(struct siginfo));
}
/* Then dispose of the pending signal structure properly */ /* Then dispose of the pending signal structure properly */
@ -218,10 +235,18 @@ int sigtimedwait(const sigset_t *set, struct siginfo *info,
wdog = wd_create(); wdog = wd_create();
if (wdog) if (wdog)
{ {
/* This little of nonsense is necessary for some
* processors where sizeof(pointer) < sizeof(uint32).
* see wdog.h.
*/
wdparm_t wdparm;
wdparm.pvarg = (void*)rtcb;
/* Start the watchdog */ /* Start the watchdog */
wd_start(wdog, waitticks, (wdentry_t)sig_timeout, wd_start(wdog, waitticks, (wdentry_t)sig_timeout,
(int)rtcb, 0, 0, 0); 1, wdparm.dwarg);
/* Now wait for either the signal or the watchdog */ /* Now wait for either the signal or the watchdog */
@ -252,7 +277,7 @@ int sigtimedwait(const sigset_t *set, struct siginfo *info,
if (info) if (info)
{ {
*info = rtcb->sigunbinfo; memcpy(info, &rtcb->sigunbinfo, sizeof(struct siginfo));
} }
irqrestore(saved_state); irqrestore(saved_state);

View File

@ -377,11 +377,7 @@ STATUS task_init(_TCB *tcb, char *name, int priority,
STATUS task_activate(_TCB *tcb) STATUS task_activate(_TCB *tcb)
{ {
#ifdef CONFIG_SCHED_INSTRUMENTATION #ifdef CONFIG_SCHED_INSTRUMENTATION
uint32 flags; irqstate_t flags = irqsave();
#endif
#ifdef CONFIG_SCHED_INSTRUMENTATION
flags = irqsave();
/* Check if this is really a re-start */ /* Check if this is really a re-start */

View File

@ -97,7 +97,7 @@ STATUS task_delete(pid_t pid)
{ {
_TCB *rtcb; _TCB *rtcb;
_TCB *dtcb; _TCB *dtcb;
uint32 saved_state; irqstate_t saved_state;
STATUS ret = ERROR; STATUS ret = ERROR;
/* Check if the task to delete is the calling task */ /* Check if the task to delete is the calling task */

View File

@ -102,7 +102,7 @@ STATUS task_restart(pid_t pid)
_TCB *rtcb; _TCB *rtcb;
_TCB *tcb; _TCB *tcb;
STATUS status; STATUS status;
uint32 state; irqstate_t state;
/* Make sure this task does not become ready-to-run while /* Make sure this task does not become ready-to-run while
* we are futzing with its TCB * we are futzing with its TCB

View File

@ -89,7 +89,7 @@ STATUS wd_cancel (WDOG_ID wdid)
{ {
wdog_t *curr; wdog_t *curr;
wdog_t *prev; wdog_t *prev;
uint32 saved_state; irqstate_t saved_state;
STATUS ret = ERROR; STATUS ret = ERROR;
/* Prohibit timer interactions with the timer queue until the /* Prohibit timer interactions with the timer queue until the

View File

@ -88,7 +88,7 @@
WDOG_ID wd_create (void) WDOG_ID wd_create (void)
{ {
wdog_t *wdog; wdog_t *wdog;
sint32 saved_state; irqstate_t saved_state;
saved_state = irqsave(); saved_state = irqsave();
wdog = (wdog_t*)sq_remfirst(&g_wdfreelist); wdog = (wdog_t*)sq_remfirst(&g_wdfreelist);

View File

@ -90,7 +90,7 @@
STATUS wd_delete (WDOG_ID wdId) STATUS wd_delete (WDOG_ID wdId)
{ {
uint32 saved_state; irqstate_t saved_state;
/* Check if the watchdog has been started. */ /* Check if the watchdog has been started. */

View File

@ -40,6 +40,7 @@
* Included Files * Included Files
************************************************************/ ************************************************************/
#include <nuttx/config.h>
#include <sys/types.h> #include <sys/types.h>
#include <wdog.h> #include <wdog.h>
#include <nuttx/compiler.h> #include <nuttx/compiler.h>
@ -64,11 +65,11 @@ struct wdog_s
{ {
struct wdog_s *next; /* Support for singly linked lists. */ struct wdog_s *next; /* Support for singly linked lists. */
wdentry_t func; /* Function to execute when delay expires */ wdentry_t func; /* Function to execute when delay expires */
sint32 lag; /* Timer associated with the delay */ int lag; /* Timer associated with the delay */
uint32 parm[4]; /* Four parameters passed to func */
boolean active; /* TRUE if the watchdog is actively timing */ boolean active; /* TRUE if the watchdog is actively timing */
ubyte argc; /* The number of parameters to pass */
uint32 parm[CONFIG_MAX_WDOGPARMS];
}; };
typedef struct wdog_s wdog_t; typedef struct wdog_s wdog_t;
/************************************************************ /************************************************************

View File

@ -38,9 +38,12 @@
************************************************************/ ************************************************************/
#include <sys/types.h> #include <sys/types.h>
#include <stdarg.h>
#include <wdog.h> #include <wdog.h>
#include <unistd.h> #include <unistd.h>
#include <sched.h> #include <sched.h>
#include <errno.h>
#include "os_internal.h"
#include "wd_internal.h" #include "wd_internal.h"
/************************************************************ /************************************************************
@ -51,6 +54,22 @@
* Private Type Declarations * Private Type Declarations
************************************************************/ ************************************************************/
typedef void (*wdentry0_t)(int argc);
#if CONFIG_MAX_WDOGPARMS > 0
typedef void (*wdentry1_t)(int argc, uint32 arg1);
#endif
#if CONFIG_MAX_WDOGPARMS > 1
typedef void (*wdentry2_t)(int argc, uint32 arg1, uint32 arg2);
#endif
#if CONFIG_MAX_WDOGPARMS > 2
typedef void (*wdentry3_t)(int argc, uint32 arg1, uint32 arg2,
uint32 arg3);
#endif
#if CONFIG_MAX_WDOGPARMS > 3
typedef void (*wdentry4_t)(int argc, uint32 arg1, uint32 arg2,
uint32 arg3, uint32 arg4);
#endif
/************************************************************ /************************************************************
* Global Variables * Global Variables
************************************************************/ ************************************************************/
@ -83,12 +102,12 @@
* Watchdog timers execute only once. * Watchdog timers execute only once.
* *
* To replace either the timeout delay or the function to * To replace either the timeout delay or the function to
* be executed, call wd_start again with the same wdId; only * be executed, call wd_start again with the same wdog; only
* the most recent wdStart() on a given watchdog ID has * the most recent wdStart() on a given watchdog ID has
* any effect. * any effect.
* *
* Parameters: * Parameters:
* wdId = watchdog ID * wdog = watchdog ID
* delay = Delay count in clock ticks * delay = Delay count in clock ticks
* wdentry = function to call on timeout * wdentry = function to call on timeout
* parm1..4 = parameters to pass to wdentry * parm1..4 = parameters to pass to wdentry
@ -102,19 +121,22 @@
* *
************************************************************/ ************************************************************/
STATUS wd_start(WDOG_ID wdId, int delay, wdentry_t wdentry, STATUS wd_start(WDOG_ID wdog, int delay, wdentry_t wdentry,
int parm1, int parm2, int parm3, int parm4) int argc, ...)
{ {
va_list ap;
wdog_t *curr; wdog_t *curr;
wdog_t *prev; wdog_t *prev;
wdog_t *next; wdog_t *next;
sint32 now; sint32 now;
sint32 saved_state; irqstate_t saved_state;
int i;
/* Verify the wdId */ /* Verify the wdog */
if (!wdId) if (!wdog || argc > CONFIG_MAX_WDOGPARMS || delay < 0)
{ {
*get_errno_ptr() = EINVAL;
return ERROR; return ERROR;
} }
@ -125,18 +147,28 @@ STATUS wd_start(WDOG_ID wdId, int delay, wdentry_t wdentry,
*/ */
saved_state = irqsave(); saved_state = irqsave();
if (wdId->active) if (wdog->active)
{ {
wd_cancel(wdId); wd_cancel(wdog);
} }
/* Save the data in the watchdog structure */ /* Save the data in the watchdog structure */
wdId->func = wdentry; /* Function to execute when delay expires */ wdog->func = wdentry; /* Function to execute when delay expires */
wdId->parm[0] = parm1; /* Same as the parameter to pass */ wdog->argc = argc;
wdId->parm[1] = parm2; /* 2nd parameter not used */
wdId->parm[2] = parm3; /* 3rd parameter not used */ va_start(ap, argc);
wdId->parm[3] = parm4; /* 4th parameter not used */ for (i = 0; i < argc; i++)
{
wdog->parm[i] = va_arg(ap, uint32);
}
#ifdef CONFIG_DEBUG
for (; i < CONFIG_MAX_WDOGPARMS; i++)
{
wdog->parm[i] = 0;
}
#endif
va_end(ap);
/* Calculate delay+1, forcing the delay into a range that we can handle */ /* Calculate delay+1, forcing the delay into a range that we can handle */
@ -153,7 +185,7 @@ STATUS wd_start(WDOG_ID wdId, int delay, wdentry_t wdentry,
if (g_wdactivelist.head == NULL) if (g_wdactivelist.head == NULL)
{ {
sq_addlast((sq_entry_t*)wdId,&g_wdactivelist); sq_addlast((sq_entry_t*)wdog,&g_wdactivelist);
} }
/* There are other active watchdogs in the timer queue */ /* There are other active watchdogs in the timer queue */
@ -180,7 +212,7 @@ STATUS wd_start(WDOG_ID wdId, int delay, wdentry_t wdentry,
now += curr->lag; now += curr->lag;
} }
/* Check if the new wdId must be inserted before the curr. */ /* Check if the new wdog must be inserted before the curr. */
if (delay < now) if (delay < now)
{ {
@ -196,18 +228,18 @@ STATUS wd_start(WDOG_ID wdId, int delay, wdentry_t wdentry,
if (curr == (wdog_t*)g_wdactivelist.head) if (curr == (wdog_t*)g_wdactivelist.head)
{ {
sq_addfirst((sq_entry_t*)wdId, &g_wdactivelist); sq_addfirst((sq_entry_t*)wdog, &g_wdactivelist);
} }
else else
{ {
sq_addafter((sq_entry_t*)prev, (sq_entry_t*)wdId, sq_addafter((sq_entry_t*)prev, (sq_entry_t*)wdog,
&g_wdactivelist); &g_wdactivelist);
} }
} }
/* The new watchdog delay time is greater than the curr delay time, /* The new watchdog delay time is greater than the curr delay time,
* so the new wdId must be inserted after the curr. This only occurs * so the new wdog must be inserted after the curr. This only occurs
* if the wdId is to be added to the end of the list. * if the wdog is to be added to the end of the list.
*/ */
else else
@ -215,13 +247,13 @@ STATUS wd_start(WDOG_ID wdId, int delay, wdentry_t wdentry,
delay -= now; delay -= now;
if (!curr->next) if (!curr->next)
{ {
sq_addlast((sq_entry_t*)wdId, &g_wdactivelist); sq_addlast((sq_entry_t*)wdog, &g_wdactivelist);
} }
else else
{ {
next = curr->next; next = curr->next;
next->lag -= delay; next->lag -= delay;
sq_addafter((sq_entry_t*)curr, (sq_entry_t*)wdId, sq_addafter((sq_entry_t*)curr, (sq_entry_t*)wdog,
&g_wdactivelist); &g_wdactivelist);
} }
} }
@ -229,8 +261,8 @@ STATUS wd_start(WDOG_ID wdId, int delay, wdentry_t wdentry,
/* Put the lag into the watchdog structure and mark it as active. */ /* Put the lag into the watchdog structure and mark it as active. */
wdId->lag = delay; wdog->lag = delay;
wdId->active = TRUE; wdog->active = TRUE;
irqrestore(saved_state); irqrestore(saved_state);
return OK; return OK;
@ -304,8 +336,42 @@ void wd_timer(void)
/* Execute the watchdog function */ /* Execute the watchdog function */
(*wdog->func)(wdog->parm[0], wdog->parm[1], switch (wdog->argc)
{
default:
#ifdef CONFIG_DEBUG
PANIC(OSERR_INTERNAL);
#endif
case 0:
(*((wdentry0_t)(wdog->func)))(0);
break;
#if CONFIG_MAX_WDOGPARMS > 0
case 1:
(*((wdentry1_t)(wdog->func)))(1, wdog->parm[0]);
break;
#endif
#if CONFIG_MAX_WDOGPARMS > 1
case 2:
(*((wdentry2_t)(wdog->func)))(2,
wdog->parm[0], wdog->parm[1]);
break;
#endif
#if CONFIG_MAX_WDOGPARMS > 2
case 3:
(*((wdentry3_t)(wdog->func)))(3,
wdog->parm[0], wdog->parm[1],
wdog->parm[2]);
break;
#endif
#if CONFIG_MAX_WDOGPARMS > 3
case 4:
(*((wdentry4_t)(wdog->func)))(4,
wdog->parm[0], wdog->parm[1],
wdog->parm[2] ,wdog->parm[3]); wdog->parm[2] ,wdog->parm[3]);
break;
#endif
}
} }
} }
} }