task_create now accepts variable number of arguments; 8051 bringup changes
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@56 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
df3e9d1db5
commit
e4f42d8949
@ -182,6 +182,9 @@ CONFIG_RRLOAD_BINARY=y
|
||||
#
|
||||
# CONFIG_MAX_TASKS - The maximum number of simultaneously
|
||||
# active tasks. This value must be a power of two.
|
||||
# CONFIG_MAX_TASK_ARGS - This controls the maximum number of
|
||||
# of parameters that a task may receive (i.e., maxmum value
|
||||
# of 'argc')
|
||||
# CONFIG_NPTHREAD_KEYS - The number of items of thread-
|
||||
# specific data that can be retained
|
||||
# CONFIG_NFILE_DESCRIPTORS - The maximum number of file
|
||||
@ -205,6 +208,7 @@ CONFIG_RRLOAD_BINARY=y
|
||||
# watchdog structures to minimize dynamic allocations
|
||||
#
|
||||
CONFIG_MAX_TASKS=64
|
||||
CONFIG_MAX_TASK_ARGS=4
|
||||
CONFIG_NPTHREAD_KEYS=4
|
||||
CONFIG_NFILE_DESCRIPTORS=32
|
||||
CONFIG_NFILE_STREAMS=16
|
||||
|
@ -37,9 +37,11 @@
|
||||
#
|
||||
# CONFIG_ARCH - identifies the arch subdirectory
|
||||
# CONFIG_ARCH_name - for use in C code
|
||||
# CONFIG_PJRC_LEDS - Use LEDs to show state. Unique to 8051.
|
||||
#
|
||||
CONFIG_ARCH=pjrc-8051
|
||||
CONFIG_ARCH_8051=y
|
||||
CONFIG_8051_LEDS=n
|
||||
|
||||
#
|
||||
# General OS setup
|
||||
@ -142,6 +144,9 @@ CONFIG_RRLOAD_BINARY=n
|
||||
#
|
||||
# CONFIG_MAX_TASKS - The maximum number of simultaneously
|
||||
# actived tasks. This value must be a power of two.
|
||||
# CONFIG_MAX_TASK_ARGS - This controls the maximum number of
|
||||
# of parameters that a task may receive (i.e., maxmum value
|
||||
# of 'argc')
|
||||
# CONFIG_NPTHREAD_KEYS - The number of items of thread-
|
||||
# specific data that can be retained
|
||||
# CONFIG_NFILE_DESCRIPTORS - The maximum number of file
|
||||
@ -165,6 +170,7 @@ CONFIG_RRLOAD_BINARY=n
|
||||
# watchdog structures to minimize dynamic allocations
|
||||
#
|
||||
CONFIG_MAX_TASKS=8
|
||||
CONFIG_MAX_TASK_ARGS=4
|
||||
CONFIG_NPTHREAD_KEYS=0
|
||||
CONFIG_NFILE_DESCRIPTORS=0
|
||||
CONFIG_NFILE_STREAMS=0
|
||||
|
@ -48,7 +48,8 @@ CSRCS = up_initialize.c up_idle.c up_interruptcontext.c \
|
||||
up_releasepending.c up_reprioritizertr.c \
|
||||
up_exit.c up_assert.c up_allocateheap.c \
|
||||
up_irq.c up_savecontext.c up_restorecontext.c \
|
||||
up_timerisr.c up_putc.c up_debug.c
|
||||
up_timerisr.c up_putc.c up_debug.c up_leds.c \
|
||||
up_delay.c
|
||||
COBJS = $(CSRCS:.c=$(OBJEXT))
|
||||
SRCS = $(SSRCS) $(CSRCS)
|
||||
OBJS = $(AOBJS) $(COBJS)
|
||||
@ -64,16 +65,40 @@ LINKLIBS =
|
||||
LDPATHES = $(addprefix -L$(TOPDIR)/,$(dir $(LINKLIBS)))
|
||||
LDLIBS = $(addprefix -l,$(notdir $(LINKLIBS)))
|
||||
|
||||
IRAM_SIZE = 0x100
|
||||
DEF_STACK_BASE = 0x24
|
||||
LDFLAGS = --model-large --nostdlib \
|
||||
--data-loc 0x30 --iram-size 0x100 \
|
||||
--data-loc $(DEF_STACK_BASE) --iram-size $(IRAM_SIZE) \
|
||||
--code-loc 0x2100 --code-size 0x5f40 \
|
||||
--xram-loc 0x0100 --xram-size 0x1f00
|
||||
--xram-loc $(IRAM_SIZE) --xram-size 0x1f00
|
||||
|
||||
DEPSRCS = $(SRCS) $(LINKSSRCS)
|
||||
|
||||
HEAP1_BASE = ${shell cat pass1.mem | grep "EXTERNAL RAM" | sed -e "s/[ ][ ]*/ /g" | cut -d' ' -f5}
|
||||
HEAP2_BASE = ${shell cat pass1.mem | grep "ROM/EPROM/FLASH" | sed -e "s/[ ][ ]*/ /g" | cut -d' ' -f4}
|
||||
STACK_BASE = ${shell cat pass1.mem | grep "Stack starts" | cut -d' ' -f4}
|
||||
HEAP1_BASE = ${shell \
|
||||
if [ -e pass1.mem ]; then \
|
||||
cat pass1.mem | grep "EXTERNAL RAM" | \
|
||||
sed -e "s/[ ][ ]*/ /g" | cut -d' ' -f5 ; \
|
||||
else \
|
||||
echo $(IRAM_SIZE) ; \
|
||||
fi \
|
||||
}
|
||||
DEF_HEAP2_BASE = 0x6000
|
||||
HEAP2_BASE = ${shell \
|
||||
if [ -e pass1.mem ]; then \
|
||||
cat pass1.mem | grep "ROM/EPROM/FLASH" | \
|
||||
sed -e "s/[ ][ ]*/ /g" | cut -d' ' -f4 ; \
|
||||
else \
|
||||
echo $(DEF_HEAP2_BASE) ; \
|
||||
fi \
|
||||
}
|
||||
STACK_BASE = ${shell \
|
||||
if [ -e pass1.mem ]; then \
|
||||
cat pass1.mem | grep "Stack starts" | \
|
||||
cut -d' ' -f4 ; \
|
||||
else \
|
||||
echo $(DEF_STACK_BASE) ; \
|
||||
fi \
|
||||
}
|
||||
|
||||
all: up_head$(OBJEXT) libarch$(LIBEXT)
|
||||
|
||||
@ -93,19 +118,24 @@ pass1.mem:
|
||||
up_mem.h: pass1.mem
|
||||
@echo "#ifndef __ARCH_MEM_H" >up_mem.h
|
||||
@echo "#define __ARCH_MEM_H" >>up_mem.h
|
||||
@if [ -e pass1.mem ]; then \
|
||||
echo "#define UP_STACK_BASE $(STACK_BASE)" >>up_mem.h ; \
|
||||
echo "#define UP_HEAP1_BASE $(HEAP1_BASE)" >> up_mem.h ; \
|
||||
echo "#define UP_HEAP1_END 0x2000" >> up_mem.h ; \
|
||||
echo "#define UP_HEAP2_BASE $(HEAP2_BASE)" >> up_mem.h ; \
|
||||
echo "#define UP_HEAP2_END 0x8000" >> up_mem.h ; \
|
||||
else \
|
||||
echo "#define UP_STACK_BASE 0x30" >>up_mem.h ; \
|
||||
echo "#define UP_HEAP1_BASE 0x0100" >> up_mem.h ; \
|
||||
echo "#define UP_HEAP1_END 0x2000" >> up_mem.h ; \
|
||||
echo "#define UP_HEAP2_BASE 0x6000" >> up_mem.h ; \
|
||||
echo "#define UP_HEAP2_END 0x8000" >> up_mem.h ; \
|
||||
fi
|
||||
@echo "" >>up_mem.h
|
||||
@echo "#define UP_DEFAULT_STACK_BASE $(DEF_STACK_BASE)" >>up_mem.h
|
||||
@echo "#define UP_DEFAULT_HEAP1_BASE $(IRAM_SIZE)" >> up_mem.h
|
||||
@echo "#define UP_DEFAULT_HEAP2_BASE $(DEF_HEAP2_BASE)" >> up_mem.h
|
||||
@echo "" >>up_mem.h
|
||||
@echo "#define UP_STACK_BASE $(STACK_BASE)" >>up_mem.h
|
||||
@echo "#if UP_STACK_BASE > UP_DEFAULT_STACK_BASE" >>up_mem.h
|
||||
@echo "# error \"Stack overlap: $(DEF_STACK_BASE) < $(STACK_BASE)\"" >>up_mem.h
|
||||
@echo "#elif UP_STACK_BASE < UP_DEFAULT_STACK_BASE" >>up_mem.h
|
||||
@echo "# warning \"Wasted stack: $(DEF_STACK_BASE) > $(STACK_BASE)\"" >>up_mem.h
|
||||
@echo "#endif" >>up_mem.h
|
||||
@echo "" >>up_mem.h
|
||||
@echo "#define UP_HEAP1_BASE $(HEAP1_BASE)" >> up_mem.h
|
||||
@echo "#define UP_HEAP1_END 0x2000" >> up_mem.h
|
||||
@echo "" >>up_mem.h
|
||||
@echo "#define UP_HEAP2_BASE $(HEAP2_BASE)" >> up_mem.h
|
||||
@echo "#define UP_HEAP2_END 0x8000" >> up_mem.h
|
||||
@echo "" >>up_mem.h
|
||||
@echo "#endif /* __ARCH_MEM_H */" >>up_mem.h
|
||||
|
||||
# Combine all objects in this directory into a library
|
||||
|
218
arch/pjrc-8051/src/pjrc.h
Normal file
218
arch/pjrc-8051/src/pjrc.h
Normal file
@ -0,0 +1,218 @@
|
||||
/**************************************************************************
|
||||
* pjrc.h
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
**************************************************************************/
|
||||
|
||||
#ifndef __PJRC_H
|
||||
#define __PJRC_H
|
||||
|
||||
/**************************************************************************
|
||||
* Included Files
|
||||
**************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/**************************************************************************
|
||||
* Public Definitions
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Public Types
|
||||
**************************************************************************/
|
||||
|
||||
/**************************************************************************
|
||||
* Public Variables
|
||||
**************************************************************************/
|
||||
|
||||
/* Memory Map
|
||||
*
|
||||
* BEGIN END DESCRIPTION
|
||||
* 0x0000 0x1fff CODE: ROM containg PAULMON2
|
||||
* DATA: RAM for program variables
|
||||
* 0x2000 0x7fff COMMON: RAM for program code or
|
||||
* variables
|
||||
* 0x8000 0xf7ff COMMON: FLASH for program code
|
||||
* 0xf800 0xfeff COMMON: Peripherals
|
||||
* 0xff00 0xffff COMMON: unused
|
||||
*
|
||||
* Program code may be loaded at the RAM location 0x2000-0x7fff
|
||||
* for testing. If loaded into the FLASH location at
|
||||
* 0x8000-0xf7ff, PAULMON2 will automatically write the program
|
||||
* into flash. The program is configured in the RAM-based test
|
||||
* configuration:
|
||||
*/
|
||||
|
||||
#define RAM_BLOCK_START IRAM_SIZE
|
||||
#define RAM_BLOCK_END 0x1fff
|
||||
|
||||
#define PROGRAM_BASE 0x2000
|
||||
#define PROGRAM_END 0x7fff
|
||||
|
||||
#define FLASH_BASE 0x8000
|
||||
#define FLASH_END 0xf7ff
|
||||
|
||||
/* Well-known entry points to access PAULMON2's built-in functions */
|
||||
|
||||
#define PM2_ENTRY_PHEX1 0x002e
|
||||
#define PM2_ENTRY_COUT 0x0030
|
||||
#define PM2_ENTRY_CIN 0x0032
|
||||
#define PM2_ENTRY_PHEX 0x0034
|
||||
#define PM2_ENTRY_PHEX16 0x0036
|
||||
#define PM2_ENTRY_PSTR 0x0038
|
||||
#define PM2_ENTRY_ESC 0x003e
|
||||
#define PM2_ENTRY_UPPER 0x0040
|
||||
#define PM2_ENTRY_PINT8U 0x004D
|
||||
#define PM2_ENTRY_PINT8 0x0050
|
||||
#define PM2_ENTRY_PINT16U 0x0053
|
||||
#define PM2_ENTRY_NEWLINE 0x0048
|
||||
#define PM2_ENTRY_PRGM 0x0059
|
||||
#define PM2_ENTRY_ERBLOCK 0x0067
|
||||
|
||||
/* PAULMON2 captures all interrupt vectors in ROM but relays them
|
||||
* through the following RAM addresses:
|
||||
*/
|
||||
|
||||
#define PM2_VECTOR_BASE PROGRAM_BASE
|
||||
#define PM2_VECTOR_EXTINT0 (PM2_VECTOR_BASE + 3)
|
||||
#define PM2_VECTOR_TIMER0 (PM2_VECTOR_BASE + 11)
|
||||
#define PM2_VECTOR_EXTINT1 (PM2_VECTOR_BASE + 19)
|
||||
#define PM2_VECTOR_TIMER1 (PM2_VECTOR_BASE + 27)
|
||||
#define PM2_VECTOR_UART (PM2_VECTOR_BASE + 35)
|
||||
#define PM2_VECTOR_TIMER2 (PM2_VECTOR_BASE + 43)
|
||||
|
||||
/* Peripheral Mapping
|
||||
*
|
||||
* Begin End Peripheral Addr Acc Function
|
||||
* F800 F8FF 82C55 (A, B, C) F800 R/W Port A
|
||||
* F801 R/W Port B
|
||||
* F802 R/W Port C
|
||||
* F803 W Config A,B,C
|
||||
* F900 F9FF 82C55 (D, E, F) F900 R/W Port D
|
||||
* F901 R/W Port E (LEDs)
|
||||
* F902 R/W Port F
|
||||
* F903 W Config D,E,F
|
||||
* FA00 FAFF User Expansion
|
||||
* FB00 FBFF User Expansion
|
||||
* FC00 FCFF User Expansion
|
||||
* FD00 FDFF User Expansion
|
||||
* FE00 FEFF LCD Port FE00 W Command Register
|
||||
* FE01 R Status Register
|
||||
* FE02 W Display or CGRAM Buffer
|
||||
* FE03 R " " "" " " " "
|
||||
*
|
||||
* These are the memory-mapped locations used to access the two 82C55
|
||||
* chips
|
||||
*/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
xdata at 0xF800 ubyte p82c55_port_a;
|
||||
xdata at 0xF801 ubyte p82c55_port_b;
|
||||
xdata at 0xF802 ubyte p82c55_port_c;
|
||||
xdata at 0xF803 ubyte p82c55_abc_config;
|
||||
xdata at 0xF900 ubyte p82c55_port_d;
|
||||
xdata at 0xF901 ubyte p82c55_port_e;
|
||||
xdata at 0xF902 ubyte p82c55_port_f;
|
||||
xdata at 0xF903 ubyte p82c55_def_config;
|
||||
#endif
|
||||
|
||||
/* LED (Port E) bit definitions */
|
||||
|
||||
#define LED_STARTED 0
|
||||
#define LED_HEAPALLOCATE 1
|
||||
#define LED_IRQSENABLED 2
|
||||
#define LED_UNUSED1 3
|
||||
#define LED_UNUSED2 4
|
||||
#define LED_INIRQ 5
|
||||
#define LED_ASSERTION 6
|
||||
#define LED_PANIC 7
|
||||
|
||||
/* Registers. 8052 regiser definitions are provided in the SDCC header
|
||||
* file 8052.h. However, a few SFR registers are missing from that
|
||||
* file (they can be found in mcs51reg.h, but that file is too much
|
||||
* when the following simple addtions do the job).
|
||||
*/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
sfr at 0xc9 T2MOD ;
|
||||
#endif
|
||||
|
||||
/* Timing information.
|
||||
*
|
||||
* The PJRC board is based on a standard 87C52 CPU clocked at 22.1184 MHz.
|
||||
* The CPU clock is divided by 12 to yield a clock frequency of 1.8432 MHz.
|
||||
*/
|
||||
|
||||
#define CPU_CLOCK_HZ 22118400L
|
||||
#define TIMER_CLOCK_HZ 1843200L
|
||||
|
||||
/* The 87C52 has three timers, timer 0, timer 1, and timer 2. On the PJRC
|
||||
* board, timer 1 and 2 have dedicated functions. They provide baud support
|
||||
* support for the boards two serial ports. Unfortunately, only timer 2
|
||||
* can generate the accurate 100Hz timer desired by the OS.
|
||||
*
|
||||
* Timer 0 provides only a 8-bit auto-reload mode.
|
||||
*/
|
||||
|
||||
#define CONFIG_80C52_TIMER2 1
|
||||
#ifdef CONFIG_80C52_TIMER2
|
||||
|
||||
/* To use timer 2 as the 100Hz system timer, we need to calculate a 16-bit
|
||||
* reload value that results in 100Hz overflow interrupts. That value
|
||||
* is given by:
|
||||
*
|
||||
* Timer ticks = TIMER_CLOCK_HZ / (desired ticks-per-second)
|
||||
* = 18432
|
||||
* Capture value = 0xffff - (Timer ticks)
|
||||
* = 47103 = 0x67ff
|
||||
*/
|
||||
|
||||
# define TIMER2_CAPTURE_LOW 0xff
|
||||
# define TIMER2_CAPTURE_HIGH 0x67
|
||||
|
||||
#else
|
||||
|
||||
/* Timer 0, mode 0 can be used as a system timer. In that mode, the
|
||||
* 1.8432 is further divided by 32. A single 8-bit value is incremented
|
||||
* at 57600 Hz, which results in 225 Timer 0 overflow interrupts per
|
||||
* second.
|
||||
*/
|
||||
|
||||
# warning "No support for timer 0 as the system timer"
|
||||
|
||||
#endif
|
||||
|
||||
/**************************************************************************
|
||||
* Public Function Prototypes
|
||||
**************************************************************************/
|
||||
|
||||
#endif /* __PJRC_H */
|
@ -77,6 +77,7 @@ void up_allocate_heap(FAR void **heap_start, size_t *heap_size)
|
||||
{
|
||||
*heap_start = (FAR void*)UP_HEAP1_BASE;
|
||||
*heap_size = UP_HEAP1_END - UP_HEAP1_BASE;
|
||||
up_ledon(LED_HEAPALLOCATE);
|
||||
}
|
||||
|
||||
#if CONFIG_MM_REGIONS > 1
|
||||
|
@ -41,8 +41,10 @@
|
||||
#include <sys/types.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <sched.h>
|
||||
#include <debug.h>
|
||||
#include <8052.h>
|
||||
#include "os_internal.h"
|
||||
#include "up_internal.h"
|
||||
#include "up_mem.h"
|
||||
|
||||
@ -58,6 +60,33 @@
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Name: _up_assert
|
||||
************************************************************/
|
||||
|
||||
static void _up_assert(int errorcode) /* __attribute__ ((noreturn)) */
|
||||
{
|
||||
/* Are we in an interrupt handler or the idle task? */
|
||||
|
||||
if (g_irqtos || ((FAR _TCB*)g_readytorun.head)->pid == 0)
|
||||
{
|
||||
(void)irqsave();
|
||||
for(;;)
|
||||
{
|
||||
#ifdef CONFIG_8051_LEDS
|
||||
up_ledon(LED_PANIC);
|
||||
up_delay(250);
|
||||
up_ledoff(LED_PANIC);
|
||||
up_delay(250);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
exit(errorcode);
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Public Functions
|
||||
************************************************************/
|
||||
@ -68,9 +97,20 @@
|
||||
|
||||
void up_assert(void)
|
||||
{
|
||||
dbg("Assertion failed\n");
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
_TCB *rtcb = (_TCB*)g_readytorun.head;
|
||||
#endif
|
||||
|
||||
up_ledon(LED_ASSERTION);
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
lldbg("%s: Assertion failed\n", rtcb->name);
|
||||
#else
|
||||
lldbg("Assertion failed\n");
|
||||
#endif
|
||||
|
||||
up_dumpstack();
|
||||
exit(EXIT_FAILURE);
|
||||
_up_assert(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
@ -79,7 +119,18 @@ void up_assert(void)
|
||||
|
||||
void up_assert_code(int errorcode)
|
||||
{
|
||||
dbg("Assertion failed with error code: %d\n", errorcode);
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
_TCB *rtcb = (_TCB*)g_readytorun.head;
|
||||
#endif
|
||||
|
||||
up_ledon(LED_ASSERTION);
|
||||
|
||||
#if CONFIG_TASK_NAME_SIZE > 0
|
||||
lldbg("%s: Assertion failed, error=%d\n", rtcb->name, errorcode);
|
||||
#else
|
||||
lldbg("Assertion failed , error=%d\n", errorcode);
|
||||
#endif
|
||||
|
||||
up_dumpstack();
|
||||
exit(errorcode);
|
||||
_up_assert(errorcode);
|
||||
}
|
||||
|
92
arch/pjrc-8051/src/up_delay.c
Normal file
92
arch/pjrc-8051/src/up_delay.c
Normal file
@ -0,0 +1,92 @@
|
||||
/************************************************************
|
||||
* up_delay.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 <nuttx/config.h>
|
||||
#include "up_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Types
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Function Prototypes
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Variables
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
|
||||
|
||||
/************************************************************
|
||||
* Public Funtions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Name: up_delay
|
||||
*
|
||||
* Description:
|
||||
* Delay inline for the requested number of milliseconds.
|
||||
* NOT multi-tasking friendly.
|
||||
*
|
||||
************************************************************/
|
||||
|
||||
void up_delay(ubyte milliseconds) __naked
|
||||
{
|
||||
_asm
|
||||
mov r0, dpl
|
||||
00001$: mov r1, #230
|
||||
00002$: nop
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
nop
|
||||
djnz r1, 00002$
|
||||
djnz r0, 00001$
|
||||
ret
|
||||
_endasm;
|
||||
}
|
@ -37,6 +37,7 @@
|
||||
* Included Files
|
||||
************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/irq.h>
|
||||
#include "up_internal.h"
|
||||
|
||||
@ -123,6 +124,11 @@
|
||||
|
||||
start:
|
||||
mov sp, #(STACK_BASE-1)
|
||||
|
||||
#ifdef CONFIG_8051_LEDS
|
||||
lcall _up_ledinit
|
||||
#endif
|
||||
|
||||
ljmp _os_start
|
||||
|
||||
/************************************************************
|
||||
@ -170,8 +176,14 @@ _up_interrupt:
|
||||
|
||||
/* Save the IRQ number in r3 */
|
||||
|
||||
#ifdef CONFIG_8051_LEDS
|
||||
push acc
|
||||
mov dpl, #LED_INIRQ
|
||||
lcall _up_ledon
|
||||
pop ar2
|
||||
#else
|
||||
mov r2, a
|
||||
|
||||
#endif
|
||||
/* Mark that we are in an interrupt and provide the top
|
||||
* of stack pointer to the context switching logic.
|
||||
*/
|
||||
@ -229,7 +241,7 @@ _up_interrupt:
|
||||
orl a, r2
|
||||
jz 00003$
|
||||
|
||||
/* A conext switch is pending Clear g_irqcontext */
|
||||
/* A context switch is pending, clear g_irqcontext */
|
||||
|
||||
mov dpl, r2
|
||||
mov dph, r3
|
||||
@ -319,6 +331,10 @@ _up_interrupt:
|
||||
*/
|
||||
|
||||
00003$:
|
||||
#ifdef CONFIG_8051_LEDS
|
||||
mov dpl, #LED_INIRQ
|
||||
lcall _up_ledoff
|
||||
#endif
|
||||
pop _bp
|
||||
pop psw
|
||||
pop ar1
|
||||
|
@ -119,6 +119,6 @@ void up_initialize(void)
|
||||
up_timerinit();
|
||||
#endif
|
||||
|
||||
/* Initialize the serial console support */
|
||||
up_ledon(LED_IRQSENABLED);
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,8 @@
|
||||
* Included Files
|
||||
**************************************************************************/
|
||||
|
||||
#include "pjrc.h"
|
||||
|
||||
/**************************************************************************
|
||||
* Public Definitions
|
||||
**************************************************************************/
|
||||
@ -51,113 +53,6 @@
|
||||
#define CONFIG_SWITCH_FRAME_DUMP 1 /* Dump frames from normal switches */
|
||||
#undef CONFIG_INTERRUPT_FRAME_DUMP /* Dump frames from interrupt switches */
|
||||
|
||||
/* Memory Map
|
||||
*
|
||||
* BEGIN END DESCRIPTION
|
||||
* 0x0000 0x1fff CODE: ROM containg PAULMON2
|
||||
* DATA: RAM for program variables
|
||||
* 0x2000 0x7fff COMMON: RAM for program code or
|
||||
* variables
|
||||
* 0x8000 0xf7ff COMMON: FLASH for program code
|
||||
* 0xf800 0xfeff COMMON: Peripherals
|
||||
* 0xff00 0xffff COMMON: unused
|
||||
*
|
||||
* Program code may be loaded at the RAM location 0x2000-0x7fff
|
||||
* for testing. If loaded into the FLASH location at
|
||||
* 0x8000-0xf7ff, PAULMON2 will automatically write the program
|
||||
* into flash. The program is configured in the RAM-based test
|
||||
* configuration:
|
||||
*/
|
||||
|
||||
#define RAM_BLOCK_START IRAM_SIZE
|
||||
#define RAM_BLOCK_END 0x1fff
|
||||
|
||||
#define PROGRAM_BASE 0x2000
|
||||
#define PROGRAM_END 0x7fff
|
||||
|
||||
#define FLASH_BASE 0x8000
|
||||
#define FLASH_END 0xf7ff
|
||||
|
||||
/* Well-known entry points to access PAULMON2's built-in functions */
|
||||
|
||||
#define PM2_ENTRY_PHEX1 0x002e
|
||||
#define PM2_ENTRY_COUT 0x0030
|
||||
#define PM2_ENTRY_CIN 0x0032
|
||||
#define PM2_ENTRY_PHEX 0x0034
|
||||
#define PM2_ENTRY_PHEX16 0x0036
|
||||
#define PM2_ENTRY_PSTR 0x0038
|
||||
#define PM2_ENTRY_ESC 0x003e
|
||||
#define PM2_ENTRY_UPPER 0x0040
|
||||
#define PM2_ENTRY_PINT8U 0x004D
|
||||
#define PM2_ENTRY_PINT8 0x0050
|
||||
#define PM2_ENTRY_PINT16U 0x0053
|
||||
#define PM2_ENTRY_NEWLINE 0x0048
|
||||
#define PM2_ENTRY_PRGM 0x0059
|
||||
#define PM2_ENTRY_ERBLOCK 0x0067
|
||||
|
||||
#define PM2_VECTOR_BASE PROGRAM_BASE
|
||||
#define PM2_VECTOR_EXTINT0 (PM2_VECTOR_BASE + 3)
|
||||
#define PM2_VECTOR_TIMER0 (PM2_VECTOR_BASE + 11)
|
||||
#define PM2_VECTOR_EXTINT1 (PM2_VECTOR_BASE + 19)
|
||||
#define PM2_VECTOR_TIMER1 (PM2_VECTOR_BASE + 27)
|
||||
#define PM2_VECTOR_UART (PM2_VECTOR_BASE + 35)
|
||||
#define PM2_VECTOR_TIMER2 (PM2_VECTOR_BASE + 43)
|
||||
|
||||
/* Registers. 8052 regiser definitions are provided in the SDCC header
|
||||
* file 8052.h. However, a few SFR registers are missing from that
|
||||
* file (they can be found in mcs51reg.h, but that file is too much
|
||||
* when the following simple addtions do the job).
|
||||
*/
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
sfr at 0xc9 T2MOD ;
|
||||
#endif
|
||||
|
||||
/* Timing information.
|
||||
*
|
||||
* The PJRC board is based on a standard 87C52 CPU clocked at 22.1184 MHz.
|
||||
* The CPU clock is divided by 12 to yield a clock frequency of 1.8432 MHz.
|
||||
*/
|
||||
|
||||
#define CPU_CLOCK_HZ 22118400L
|
||||
#define TIMER_CLOCK_HZ 1843200L
|
||||
|
||||
/* The 87C52 has three timers, timer 0, timer 1, and timer 2. On the PJRC
|
||||
* board, timer 1 and 2 have dedicated functions. They provide baud support
|
||||
* support for the boards two serial ports. Unfortunately, only timer 2
|
||||
* can generate the accurate 100Hz timer desired by the OS.
|
||||
*
|
||||
* Timer 0 provides only a 8-bit auto-reload mode.
|
||||
*/
|
||||
|
||||
#define CONFIG_80C52_TIMER2 1
|
||||
#ifdef CONFIG_80C52_TIMER2
|
||||
|
||||
/* To use timer 2 as the 100Hz system timer, we need to calculate a 16-bit
|
||||
* reload value that results in 100Hz overflow interrupts. That value
|
||||
* is given by:
|
||||
*
|
||||
* Timer ticks = TIMER_CLOCK_HZ / (desired ticks-per-second)
|
||||
* = 18432
|
||||
* Capture value = 0xffff - (Timer ticks)
|
||||
* = 47103 = 0x67ff
|
||||
*/
|
||||
|
||||
# define TIMER2_CAPTURE_LOW 0xff
|
||||
# define TIMER2_CAPTURE_HIGH 0x67
|
||||
|
||||
#else
|
||||
|
||||
/* Timer 0, mode 0 can be used as a system timer. In that mode, the
|
||||
* 1.8432 is further divided by 32. A single 8-bit value is incremented
|
||||
* at 57600 Hz, which results in 225 Timer 0 overflow interrupts per
|
||||
* second.
|
||||
*/
|
||||
|
||||
# warning "No support for timer 0 as the system timer"
|
||||
|
||||
#endif
|
||||
|
||||
/**************************************************************************
|
||||
* Public Types
|
||||
**************************************************************************/
|
||||
@ -197,12 +92,15 @@ extern FAR struct xcptcontext *g_irqcontext;
|
||||
#if CONFIG_MM_REGIONS > 1
|
||||
extern void up_addregion(void);
|
||||
#endif
|
||||
extern void up_delay(ubyte milliseconds) __naked;
|
||||
extern void up_irqinitialize(void);
|
||||
extern void up_restorecontext(FAR struct xcptcontext *context) _naked;
|
||||
extern ubyte up_savecontext(FAR struct xcptcontext *context) __naked;
|
||||
extern void up_savestack(FAR struct xcptcontext *context, ubyte tos);
|
||||
extern void up_timerinit(void);
|
||||
|
||||
/* Defined in up_assert.c */
|
||||
|
||||
#ifdef CONFIG_FRAME_DUMP
|
||||
extern void up_dumpstack(void);
|
||||
extern void up_dumpframe(FAR struct xcptcontext *context);
|
||||
@ -211,5 +109,17 @@ extern void up_dumpframe(FAR struct xcptcontext *context);
|
||||
# define up_dumpframe(x)
|
||||
#endif
|
||||
|
||||
/* Defined in up_leds.c */
|
||||
|
||||
#ifdef CONFIG_8051_LEDS
|
||||
extern void up_ledinit(void);
|
||||
extern void up_ledon(int led);
|
||||
extern void up_ledoff(int led);
|
||||
#else
|
||||
# define up_ledinit()
|
||||
# define up_ledon(led)
|
||||
# define up_ledoff(led)
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY */
|
||||
#endif /* __ARCH_UP_INTERNAL_H */
|
||||
|
105
arch/pjrc-8051/src/up_leds.c
Normal file
105
arch/pjrc-8051/src/up_leds.c
Normal file
@ -0,0 +1,105 @@
|
||||
/************************************************************
|
||||
* up_leds.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 <nuttx/config.h>
|
||||
#include <sys/types.h>
|
||||
#include "up_internal.h"
|
||||
|
||||
/************************************************************
|
||||
* Definitions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Private Data
|
||||
************************************************************/
|
||||
|
||||
static uint32 g_ledstate;
|
||||
|
||||
/************************************************************
|
||||
* Private Functions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Public Funtions
|
||||
************************************************************/
|
||||
|
||||
/************************************************************
|
||||
* Name: up_ledinit
|
||||
************************************************************/
|
||||
|
||||
#ifdef CONFIG_8051_LEDS
|
||||
void up_ledinit(void)
|
||||
{
|
||||
/* Set all ports as outputs */
|
||||
|
||||
p82c55_abc_config = 128;
|
||||
p82c55_def_config = 128;
|
||||
|
||||
/* Turn LED 1-7 off; turn LED 0 on */
|
||||
|
||||
g_ledstate = 0x000000fe;
|
||||
p82c55_port_e = g_ledstate;
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Name: up_ledon
|
||||
************************************************************/
|
||||
|
||||
void up_ledon(int led)
|
||||
{
|
||||
if (led < 8)
|
||||
{
|
||||
g_ledstate &= ~(1 << led);
|
||||
p82c55_port_e = g_ledstate;
|
||||
}
|
||||
}
|
||||
|
||||
/************************************************************
|
||||
* Name: up_ledoff
|
||||
************************************************************/
|
||||
|
||||
void up_ledoff(int led)
|
||||
{
|
||||
if (led < 8)
|
||||
{
|
||||
g_ledstate |= (1 << led);
|
||||
p82c55_port_e = g_ledstate;
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_8051_LEDS */
|
@ -142,6 +142,9 @@ CONFIG_RRLOAD_BINARY=n
|
||||
#
|
||||
# CONFIG_MAX_TASKS - The maximum number of simultaneously
|
||||
# active tasks. This value must be a power of two.
|
||||
# CONFIG_MAX_TASK_ARGS - This controls the maximum number of
|
||||
# of parameters that a task may receive (i.e., maxmum value
|
||||
# of 'argc')
|
||||
# CONFIG_NPTHREAD_KEYS - The number of items of thread-
|
||||
# specific data that can be retained
|
||||
# CONFIG_NFILE_DESCRIPTORS - The maximum number of file
|
||||
@ -165,6 +168,7 @@ CONFIG_RRLOAD_BINARY=n
|
||||
# watchdog structures to minimize dynamic allocations
|
||||
#
|
||||
CONFIG_MAX_TASKS=64
|
||||
CONFIG_MAX_TASK_ARGS=4
|
||||
CONFIG_NPTHREAD_KEYS=4
|
||||
CONFIG_NFILE_DESCRIPTORS=32
|
||||
CONFIG_NFILE_STREAMS=16
|
||||
|
@ -90,7 +90,7 @@ STATUS up_use_stack(_TCB *tcb, void *stack, size_t stack_size)
|
||||
|
||||
/* This is the address of the last word in the allocation */
|
||||
|
||||
size_t *adj_stack_ptr = &stack[adj_stack_words - 1];
|
||||
size_t *adj_stack_ptr = &((size_t*)stack)[adj_stack_words - 1];
|
||||
|
||||
/* Save the values in the TCB */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user