diff options
-rw-r--r-- | nuttx/TODO | 7 | ||||
-rw-r--r-- | nuttx/arch/z16/src/z16f/Make.defs | 2 | ||||
-rw-r--r-- | nuttx/arch/z16/src/z16f/chip.h | 58 | ||||
-rwxr-xr-x | nuttx/arch/z16/src/z16f/z16f_head.S | 459 | ||||
-rwxr-xr-x | nuttx/arch/z16/src/z16f/z16f_lowuart.S | 472 | ||||
-rw-r--r-- | nuttx/arch/z16/src/z16f/z16f_saveusercontext.S | 104 | ||||
-rw-r--r-- | nuttx/arch/z16/src/z16f/z16f_serial.c | 2 |
7 files changed, 640 insertions, 464 deletions
diff --git a/nuttx/TODO b/nuttx/TODO index 917122cc8..3b40c39a3 100644 --- a/nuttx/TODO +++ b/nuttx/TODO @@ -21,6 +21,7 @@ NuttX TODO List (Last updated January 6, 2008) (2) ARM/LPC214x (arch/arm/src/lpc214x/) (4) pjrc-8052 / MCS51 (arch/pjrc-8051/) (2) z80 (arch/z80/) + (1) z16 (arch/z16/) o Task/Scheduler (sched/) ^^^^^^^^^^^^^^^^^^^^^^^ @@ -350,4 +351,10 @@ o z80 (arch/z80) to solve the problem are complex. +o z16 (arch/z16) +^^^^^^^^^^^^^^^^ + Description: ZDS-II Librarian complains that the source for the .obj file + is not in the library. + Status: Open + Priority: Low, thought to be cosmetic. diff --git a/nuttx/arch/z16/src/z16f/Make.defs b/nuttx/arch/z16/src/z16f/Make.defs index 7edd0c257..4c3a610e4 100644 --- a/nuttx/arch/z16/src/z16f/Make.defs +++ b/nuttx/arch/z16/src/z16f/Make.defs @@ -43,6 +43,6 @@ CMN_CSRCS = up_allocateheap.c up_initialize.c up_schedulesigaction.c \ up_unblocktask.c up_doirq.c up_releasepending.c up_usestack.c \ up_exit.c up_releasestack.c up_idle.c up_reprioritizertr.c -CHIP_SSRCS = z16f_lowuart.S +CHIP_SSRCS = z16f_lowuart.S z16f_saveusercontext.S CHIP_CSRCS = z16f_clkinit.c z16f_irq.c z16f_timerisr.c z16f_serial.c diff --git a/nuttx/arch/z16/src/z16f/chip.h b/nuttx/arch/z16/src/z16f/chip.h index 3a1d3d172..47e152e6b 100644 --- a/nuttx/arch/z16/src/z16f/chip.h +++ b/nuttx/arch/z16/src/z16f/chip.h @@ -367,41 +367,41 @@ /* UART0/1 Status 0 Register Bit Definitions ****************************************/ -#define Z16F_UARTSTAT0_RDA _HX8(0x80) /* Bit 7: Receive Data Available */ -#define Z16F_UARTSTAT0_PE _HX8(0x40) /* Bit 6: Parity Error */ -#define Z16F_UARTSTAT0_OE _HX8(0x20) /* Bit 5: Overrun Error */ -#define Z16F_UARTSTAT0_FE _HX8(0x10) /* Bit 4: Framing Error */ -#define Z16F_UARTSTAT0_BRKD _HX8(0x08) /* Bit 3: Break Detect */ -#define Z16F_UARTSTAT0_TDRE _HX8(0x04) /* Bit 2: Transmitter Data Register Empty */ -#define Z16F_UARTSTAT0_TXE _HX8(0x02) /* Bit 1: Transmitter Empty */ -#define Z16F_UARTSTAT0_CTS _HX8(0x01) /* Bit 0: Clear To Send */ +#define Z16F_UARTSTAT0_RDA _HX8(80) /* Bit 7: Receive Data Available */ +#define Z16F_UARTSTAT0_PE _HX8(40) /* Bit 6: Parity Error */ +#define Z16F_UARTSTAT0_OE _HX8(20) /* Bit 5: Overrun Error */ +#define Z16F_UARTSTAT0_FE _HX8(10) /* Bit 4: Framing Error */ +#define Z16F_UARTSTAT0_BRKD _HX8(08) /* Bit 3: Break Detect */ +#define Z16F_UARTSTAT0_TDRE _HX8(04) /* Bit 2: Transmitter Data Register Empty */ +#define Z16F_UARTSTAT0_TXE _HX8(02) /* Bit 1: Transmitter Empty */ +#define Z16F_UARTSTAT0_CTS _HX8(01) /* Bit 0: Clear To Send */ /* UART0/1 Control 0/1 Register Bit Definitions *************************************/ -#define Z16F_UARTCTL0_TEN _HX8(0x80) /* Bit 7: Transmit Enable */ -#define Z16F_UARTCTL0_REN _HX8(0x40) /* Bit 6: Receive Enable */ -#define Z16F_UARTCTL0_CTSE _HX8(0x20) /* Bit 5: CTS Enable */ -#define Z16F_UARTCTL0_PEN _HX8(0x10) /* Bit 4: Parity Enable */ -#define Z16F_UARTCTL0_PSEL _HX8(0x08) /* Bit 3: Odd Parity Select */ -#define Z16F_UARTCTL0_SBRK _HX8(0x04) /* Bit 2: Send Break */ -#define Z16F_UARTCTL0_STOP _HX8(0x02) /* Bit 1: Stop Bit Select */ -#define Z16F_UARTCTL0_LBEN _HX8(0x01) /* Bit 0: Loopback Enable */ - -#define Z16F_UARTCTL1_MPMD1 _HX8(0x80) /* Bit 7: Multiprocessor Mode (bit1) */ -#define Z16F_UARTCTL1_MPEN _HX8(0x40) /* Bit 6: Multiprocessor Enable */ -#define Z16F_UARTCTL1_MPMD0 _HX8(0x20) /* Bit 5: Multiprocessor Mode (bit0) */ -#define Z16F_UARTCTL1_MPBT _HX8(0x10) /* Bit 4: Multiprocessor Bit Transmit */ -#define Z16F_UARTCTL1_DEPOL _HX8(0x08) /* Bit 3: Driver Enable Polarity */ -#define Z16F_UARTCTL1_BRGCTL _HX8(0x04) /* Bit 2: Baud Rate Generator Control */ -#define Z16F_UARTCTL1_RDAIRQ _HX8(0x02) /* Bit 1: Receive Data Interrupt Enable */ -#define Z16F_UARTCTL1_IREN _HX8(0x01) /* Bit 0: Infrared Encoder/Decoder Eanble */ +#define Z16F_UARTCTL0_TEN _HX8(80) /* Bit 7: Transmit Enable */ +#define Z16F_UARTCTL0_REN _HX8(40) /* Bit 6: Receive Enable */ +#define Z16F_UARTCTL0_CTSE _HX8(20) /* Bit 5: CTS Enable */ +#define Z16F_UARTCTL0_PEN _HX8(10) /* Bit 4: Parity Enable */ +#define Z16F_UARTCTL0_PSEL _HX8(08) /* Bit 3: Odd Parity Select */ +#define Z16F_UARTCTL0_SBRK _HX8(04) /* Bit 2: Send Break */ +#define Z16F_UARTCTL0_STOP _HX8(02) /* Bit 1: Stop Bit Select */ +#define Z16F_UARTCTL0_LBEN _HX8(01) /* Bit 0: Loopback Enable */ + +#define Z16F_UARTCTL1_MPMD1 _HX8(80) /* Bit 7: Multiprocessor Mode (bit1) */ +#define Z16F_UARTCTL1_MPEN _HX8(40) /* Bit 6: Multiprocessor Enable */ +#define Z16F_UARTCTL1_MPMD0 _HX8(20) /* Bit 5: Multiprocessor Mode (bit0) */ +#define Z16F_UARTCTL1_MPBT _HX8(10) /* Bit 4: Multiprocessor Bit Transmit */ +#define Z16F_UARTCTL1_DEPOL _HX8(08) /* Bit 3: Driver Enable Polarity */ +#define Z16F_UARTCTL1_BRGCTL _HX8(04) /* Bit 2: Baud Rate Generator Control */ +#define Z16F_UARTCTL1_RDAIRQ _HX8(02) /* Bit 1: Receive Data Interrupt Enable */ +#define Z16F_UARTCTL1_IREN _HX8(01) /* Bit 0: Infrared Encoder/Decoder Eanble */ /* UART0/1 Mode Status/Select Register Bit Definitions ******************************/ -#define Z16F_UARTMDSEL_NORMAL _HX8(0x00) /* Bits 5-7=0: Multiprocessor and Normal Mode */ -#define Z16F_UARTMDSEL_FILTER _HX8(0x20) /* Bits 5-7=1: Noise Filter Control/Status */ -#define Z16F_UARTMDSEL_LINP _HX8(0x40) /* Bits 5-7=2: LIN protocol Contol/Status */ -#define Z16F_UARTMDSEL_HWREV _HX8(0xe0) /* Bits 5-7=7: LIN-UART Hardware Revision */ +#define Z16F_UARTMDSEL_NORMAL _HX8(00) /* Bits 5-7=0: Multiprocessor and Normal Mode */ +#define Z16F_UARTMDSEL_FILTER _HX8(20) /* Bits 5-7=1: Noise Filter Control/Status */ +#define Z16F_UARTMDSEL_LINP _HX8(40) /* Bits 5-7=2: LIN protocol Contol/Status */ +#define Z16F_UARTMDSEL_HWREV _HX8(e0) /* Bits 5-7=7: LIN-UART Hardware Revision */ /* Bits 0-4: Mode dependent status */ /* Timer0/1/2 registers *************************************************************/ diff --git a/nuttx/arch/z16/src/z16f/z16f_head.S b/nuttx/arch/z16/src/z16f/z16f_head.S index 1a35e4064..9e9012a5a 100755 --- a/nuttx/arch/z16/src/z16f/z16f_head.S +++ b/nuttx/arch/z16/src/z16f/z16f_head.S @@ -1,195 +1,264 @@ -/**************************************************************************
- * arch/z16/src/z16f/z16f_head.S
- * Z16F Reset Entry Point
- *
- * Copyright (C) 2008 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 NuttX 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>
-
-/**************************************************************************
- * External References / External Definitions
- **************************************************************************/
-
- xref _z16f_lowinit:EROM
-#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_ARCH_LOWGETC)
- xref _z16f_lowuartinit:EROM
-#endif
- xref _os_start:EROM
- xdef _reset
- xdef _sysexc_isr
- xdef _timer2_isr
- xdef _timer1_isr
- xdef _timer0_isr
- xdef _uart0rx_isr
- xdef _uart0tx_isr
- xdef _i2c_isr
- xdef _spi_isr
- xdef _adc_isr
- xdef _p7ad_isr
- xdef _p6ad_isr
- xdef _p5ad_isr
- xdef _p4ad_isr
- xdef _p3ad_isr
- xdef _p2ad_isr
- xdef _p1ad_isr
- xdef _p0ad_isr
- xdef _pwmtimer_isr
- xdef _uart1rx_isr
- xdef _uart1tx_isr
- xdef _pwmfault_isr
- xdef _c3_isr
- xdef _c2_isr
- xdef _c1_isr
- xdef _c0_isr
- xdef _common_isr
-
-/**************************************************************************
- * Flash Option Byte Setup
- **************************************************************************/
-
- define FOPTIONSEG, SPACE=ROM, ORG=0
- segment FOPTIONSEG
- db %FF
- db %FF
- db %FF
- db %FF
-
-/**************************************************************************
- * vectors
- **************************************************************************/
-
- vector RESET=_reset
- vector SYSEXC=_sysexc_isr
- vector TIMER2=_timer2_isr
- vector TIMER1=_timer1_isr
- vector TIMER0=_timer0_isr
- vector UART0_RX=_uart0rx_isr
- vector UART0_TX=_uart0tx_isr
- vector I2C=_i2c_isr
- vector SPI=_spi_isr
- vector ADC=_adc_isr
- vector P7AD=_p7ad_isr
- vector P6AD=_p6ad_isr
- vector P5AD=_p5ad_isr
- vector P4AD=_p4ad_isr
- vector P3AD=_p3ad_isr
- vector P2AD=_p2ad_isr
- vector P1AD=_p1ad_isr
- vector P0AD=_p0ad_isr
- vector PWM_TIMER=_pwmtimer_isr
- vector UART1_RX=_uart1rx_isr
- vector UART1_TX=_uart1tx_isr
- vector PWM_FAULT=_pwmfault_isr
- vector C3=_c3_isr
- vector C2=_c3_isr
- vector C1=_c2_isr
- vector C0=_c0_isr
-
-/**************************************************************************
- * Equates
- **************************************************************************/
-
-STACK_TOP equ %FFC000
-
-/**************************************************************************
- * Data Allocation
- **************************************************************************/
-
-/**************************************************************************
- * Code
- **************************************************************************/
-
- define CODESEG, SPACE=EROM
- segment CODESEG
-
-/**************************************************************************
- * Name: _reset
- *
- * Description:
- * Reset entry point
- *
- **************************************************************************/
-
-_reset:
- ld sp, #STACK_TOP /* Set Stack Pointer */
- call _z16f_lowinit /* Perform low-level hardware initialization */
-#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_ARCH_LOWGETC)
- call _z16f_lowuartinit /* Initialize the UART for debugging */
-#endif
- call _os_start /* Start the operating system */
-_halted: /* _os_start() should not return */
- halt
- jp _halted
-
-/**************************************************************************
- * Name: Interrupt handlers
- *
- * Description:
- * All interrupts will be vectored to the following locations.
- *
- **************************************************************************/
-
-_sysexc_isr:
-_timer2_isr:
-_timer1_isr:
-_timer0_isr:
-_uart0rx_isr:
-_uart0tx_isr:
-_i2c_isr:
-_spi_isr:
-_adc_isr:
-_p7ad_isr:
-_p6ad_isr:
-_p5ad_isr:
-_p4ad_isr:
-_p3ad_isr:
-_p2ad_isr:
-_p1ad_isr:
-_p0ad_isr:
-_pwmtimer_isr:
-_uart1rx_isr:
-_uart1tx_isr:
-_pwmfault_isr:
-_c3_isr:
-_c2_isr:
-_c1_isr:
-_c0_isr:
-_common_isr:
- nop
- iret
-
- end
+/************************************************************************** + * arch/z16/src/z16f/z16f_head.S + * Z16F Reset Entry Point + * + * Copyright (C) 2008 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 NuttX 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> + +/************************************************************************** + * External References / External Definitions + **************************************************************************/ + + xref _z16f_lowinit:EROM +#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_ARCH_LOWGETC) + xref _z16f_lowuartinit:EROM +#endif + xref _os_start:EROM + xdef _reset + xdef _sysexc_isr + xdef _timer2_isr + xdef _timer1_isr + xdef _timer0_isr + xdef _uart0rx_isr + xdef _uart0tx_isr + xdef _i2c_isr + xdef _spi_isr + xdef _adc_isr + xdef _p7ad_isr + xdef _p6ad_isr + xdef _p5ad_isr + xdef _p4ad_isr + xdef _p3ad_isr + xdef _p2ad_isr + xdef _p1ad_isr + xdef _p0ad_isr + xdef _pwmtimer_isr + xdef _uart1rx_isr + xdef _uart1tx_isr + xdef _pwmfault_isr + xdef _c3_isr + xdef _c2_isr + xdef _c1_isr + xdef _c0_isr + xdef _common_isr + + xref _low_nearbss:RAM + xref _len_nearbss + xref _low_farbss:ERAM + xref _len_farbss:ERAM + xref _low_neardata:RAM + xref _len_neardata + xref _low_near_romdata:EROM + xref _low_fardata:ERAM + xref _len_fardata:ERAM + xref _low_far_romdata:EROM + xref far_heapbot:ERAM + xref _far_stack:ERAM + xref _near_stack:RAM + +/************************************************************************** + * Flash Option Byte Setup + **************************************************************************/ + + define FOPTIONSEG, SPACE=ROM, ORG=0 + segment FOPTIONSEG + db %FF + db %FF + db %FF + db %FF + +/************************************************************************** + * vectors + **************************************************************************/ + + vector RESET=_reset + vector SYSEXC=_sysexc_isr + vector TIMER2=_timer2_isr + vector TIMER1=_timer1_isr + vector TIMER0=_timer0_isr + vector UART0_RX=_uart0rx_isr + vector UART0_TX=_uart0tx_isr + vector I2C=_i2c_isr + vector SPI=_spi_isr + vector ADC=_adc_isr + vector P7AD=_p7ad_isr + vector P6AD=_p6ad_isr + vector P5AD=_p5ad_isr + vector P4AD=_p4ad_isr + vector P3AD=_p3ad_isr + vector P2AD=_p2ad_isr + vector P1AD=_p1ad_isr + vector P0AD=_p0ad_isr + vector PWM_TIMER=_pwmtimer_isr + vector UART1_RX=_uart1rx_isr + vector UART1_TX=_uart1tx_isr + vector PWM_FAULT=_pwmfault_isr + vector C3=_c3_isr + vector C2=_c3_isr + vector C1=_c2_isr + vector C0=_c0_isr + +/************************************************************************** + * Equates + **************************************************************************/ + +/************************************************************************** + * Data Allocation + **************************************************************************/ + +/************************************************************************** + * Code + **************************************************************************/ + + define CODESEG, SPACE=EROM + segment CODESEG + +/************************************************************************** + * Name: _reset + * + * Description: + * Reset entry point + * + **************************************************************************/ + +_reset: + /* Initialize the init/idle task stack */ + + ld sp, #(_near_stack+1) /* Set Stack Pointer to the top of internal RAM */ + clr fp + + /* Perform VERY early UART initialization so that we can use it here */ + +#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_ARCH_LOWGETC) + call _z16f_lowuartinit /* Initialize the UART for debugging */ +#endif + /* Initialize the hardware stack overflow register */ + +#ifdef CONFIG_Z16F_INITSPOV + ld r0, #(_near_stack_bot+1) + ld spov, r0 +#endif + /* Clear BSS */ + + lea r0, _low_nearbss + ld r1, #_len_nearbss+1 + jp _reset2 +_reset1: + ld.b (r0++), #0 +_reset2: + djnz r1, _reset1 + + lea r0, _low_farbss + ld r1, #_len_farbss+1 + jp _reset4 +_reset3: + ld.b (r0++), #0 +_reset4: + djnz r1, _reset3 + + /* Copy ROM data into RAM */ + + lea r0, _low_near_romdata + lea r1, _low_neardata + ld r2, #_len_neardata+1 + jp _reset6 +_reset5: + ld.b r3, (r0++) + ld.b (r1++), r3 +_reset6: + djnz r2, _reset5 + + lea r0, _low_far_romdata + lea r1, _low_fardata + ld r2, #_len_fardata+1 + jp _reset8 +_reset7: + ld.b r3, (r0++) + ld.b (r1++), r3 +_reset8: + djnz r2, _reset7 + + /* Perform low-level hardware initialization */ + + call _z16f_lowinit /* Perform low-level hardware initialization */ + + /* Start NuttX */ + + call _os_start /* Start the operating system */ +_halted: /* _os_start() should not return */ + halt + jp _halted + +/************************************************************************** + * Name: Interrupt handlers + * + * Description: + * All interrupts will be vectored to the following locations. + * + **************************************************************************/ + +_sysexc_isr: +_timer2_isr: +_timer1_isr: +_timer0_isr: +_uart0rx_isr: +_uart0tx_isr: +_i2c_isr: +_spi_isr: +_adc_isr: +_p7ad_isr: +_p6ad_isr: +_p5ad_isr: +_p4ad_isr: +_p3ad_isr: +_p2ad_isr: +_p1ad_isr: +_p0ad_isr: +_pwmtimer_isr: +_uart1rx_isr: +_uart1tx_isr: +_pwmfault_isr: +_c3_isr: +_c2_isr: +_c1_isr: +_c0_isr: +_common_isr: + nop + iret + + end diff --git a/nuttx/arch/z16/src/z16f/z16f_lowuart.S b/nuttx/arch/z16/src/z16f/z16f_lowuart.S index 8123f99ab..e25b3b439 100755 --- a/nuttx/arch/z16/src/z16f/z16f_lowuart.S +++ b/nuttx/arch/z16/src/z16f/z16f_lowuart.S @@ -1,238 +1,234 @@ -/*************************************************************************
- * arch/z16/src/z16f/z16f_lowuart.asm
- * Z16F UART management
- *
- * Copyright (C) 2008 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 NuttX 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 "chip/chip.h"
-
-#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_ARCH_LOWGETC)
-
-/*************************************************************************
- * External References / External Definitions
- *************************************************************************/
-
- xdef z16f_lowuartinit
- xref _SYS_CLK_FREQ:EROM
-#ifdef CONFIG_ARCH_LOWPUTC
- xdef _z16f_xmitc
- xdef _up_lowputc
-#endif
-#ifdef CONFIG_ARCH_LOWGETC
- xdef _up_lowgetc
-#endif
-
-/*************************************************************************
- * Data Allocation
- *************************************************************************/
-
-/*************************************************************************
- * Data Allocation
- *************************************************************************/
-
- define CODESEG, SPACE=EROM
- segment CODESEG
-
-/*************************************************************************
- * Code
- *************************************************************************/
-
-/*************************************************************************
- * Name: z16f_lowuartinit
- *
- * Description:
- * Initialize UART0 or UART1
- *
- * Parameters:
- * None
- *
- *************************************************************************/
-
-z16f_lowuartinit:
- pushmlo <r0, r3> /* Save registers */
-
- /* Calculate and set the baud rate generation register */
-
-
-#ifdef CONFIG_UART0_SERIAL_CONSOLE
- ld r3, #CONFIG_UART0_BAUD /* r3 = baud */
-#else
- ld r3, #CONFIG_UART1_BAUD /* r3 = baud */
-#endif
- ld r0, r3 /* r0 = baud */
- sll r0, #3 /* r0 = baud * 8 */
- add r0, #_SYS_CLK_FREQ /* r3 = freq + baud * 8*/
- sll r3, #4 /* r3 = baud * 16 */
- udiv r0, r3 /* BRG = (freq + baud * 8)/(baud * 16) */
-
-#ifdef CONFIG_UART0_SERIAL_CONSOLE
- ld.w Z16F_UART0_BR, r0 /* Z16F_UART0_BR = BRG */
-
- /* Set the GPIO Alternate Function Register Lo (AFL) register */
-
- ld r0, #%30
- or.b Z16F_GPIOA_AFL, r0 /* Z16F_GPIOA_AFL |= %30 */
-
- /* Enable UART receive (REN) and transmit (TEN) */
-
- clr.b Z16F_UART0_CTL1 /* Z16F_UART0_CTL1 = 0 */
- ld r0, #(Z16F_UARTCTL0_TEN|Z16F_UARTCTL0_REN)
- ld.b Z16F_UART0_CTL0, r0 /* Z16F_UART0_CTL0 = %c0 */
-#else
- ld.w Z16F_UART1_BR, r0 /* Z16F_UART1_BR = BRG */
-
- /* Set the GPIO Alternate Function Register Lo (AFL) register */
-
- ld r0, #%30
- or.b Z16F_GPIOD_AFL, r0 /* Z16F_GPIOD_AFL |= %30 */
-
- /* Enable UART receive (REN) and transmit (TEN) */
-
- clr.b Z16F_UART1_CTL1 /* Z16F_UART1_CTL1 = 0 */
- ld r0, #(Z16F_UARTCTL0_TEN|Z16F_UARTCTL0_REN)
- ld.b Z16F_UART1_CTL0, r0 /* Z16F_UART1_CTL0 = %c0 */
-#endif
- popmlo <r0, r3> /* Restore registers */
- ret /* Return */
-
-
-/*************************************************************************
- * Name: _z16f_xmitc
- *
- * Description:
- * Send one character on the selected port
- *
- * Parmeters:
- * r1 = character
- *
- *************************************************************************/
-
-#ifdef CONFIG_ARCH_LOWPUTC
-_z16f_xmitc:
- pushmlo <r0> /* Save registers */
-
-_z16f_xmitc1:
- ld r0, #Z16F_UARTSTAT0_TDRE /* TDRE=Transmitter Data Register Empty */
-#ifdef CONFIG_UART0_SERIAL_CONSOLE
- tm.b Z16F_UART0_STAT0, r0 /* r0 = Z16F_UART0_STAT0 */
- jp eq, _z16f_xmitc1 /* While (!(Z16F_UART0_STAT0 & TDRE)) */
- ld.b Z16F_UART0_TXD, r1 /* Z16F_UART0_TXD = r1 (character) */
-#else
- tm.b Z16F_UART1_STAT0, r0 /* r0 = Z16F_UART0_STAT1 */
- jp eq, _z16f_xmitc1 /* While (!(Z16F_UART1_STAT0 & TDRE)) */
- ld.b Z16F_UART1_TXD, r1 /* Z16F_UART1_TXD = r1 (character) */
-#endif
- popmlo <r0> /* Restore registers */
- ret /* Return */
-#endif
-
-/*************************************************************************
- * Name: _up_lowputc
- *
- * Description:
- * Send one character to the selected serial console
- *
- * Parmeters:
- * r1 = character
- *
- * Return
- * R0 = 0
- *
- *************************************************************************/
-
-#ifdef CONFIG_ARCH_LOWPUTC
-_up_lowputc:
- pushmlo <r1,r5> /* Save registers */
- ld r0,r1
- ext.ub r5,r0
- cp r5,#10
- jp ne, _up_lowputc1 /* If (character == \n) */
-
- ld r1,#13
- call _z16f_xmitc /* Call _z16f_xmitc with \r */
-
-_up_lowputc1:
- ld r1, r0
- call _z16f_xmitc /* Xall _z16f_xmitc with character */
-
- ld r0, #0 /* return r0 = 0 */
- popmlo <r1,r5> /* Restore registers */
- ret /* Return */
-#endif
-
-/*************************************************************************
- * Name: _up_lowgetc
- *
- * Description:
- * Get a character from the serial port
- *
- * Parmeters:
- * None
- *
- * Return
- * R0 = Character read
- *
- *************************************************************************/
-
-#ifdef CONFIG_ARCH_LOWGETC
-_up_lowgetc:
-up_lowgetc1:
- ld r0, #Z16F_UARTSTAT0_RDA /* RDA=Receive data available */
-#ifdef CONFIG_UART0_SERIAL_CONSOLE
- tm.b Z16F_UART0_STAT0, r0
- jp eq, _up_lowgetc1 /* While (!Z16F_UART0_STAT0 & RDA)) */
- ld.ub r0, Z16F_UART0_RXD /* r0 = Z16F_UART0_RXD */
-#else
- tm.b Z16F_UART1_STAT0,r0 /* While (!Z16F_UART1_STAT0 & RDA) */
- jp eq, _up_lowgetc1
- ld.ub r0, Z16F_UART1_RXD /* r0 = Z16F_UART1_RXD */
-#endif
- cp r0, #%0d /* Test for '\r' */
- jp eq, _up_lowgetc2
-
- cp r0, #%0d /* Test \r + high bit */
- jp ne, _up_lowgetc3
-_up_lowgetc2:
- ld r0, #%0a /* Convert '\r' to '\n' */
-_up_lowgetc3: /* Return value in r0 */
- ret /* Return */
-#endif
-
-#endif /* CONFIG_ARCH_LOWPUTC || CONFIG_ARCH_LOWGETC */
-
- end
+/************************************************************************* + * arch/z16/src/z16f/z16f_lowuart.asm + * Z16F UART management + * + * Copyright (C) 2008 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 NuttX 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 "chip/chip.h" + +#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_ARCH_LOWGETC) + +/************************************************************************* + * External References / External Definitions + *************************************************************************/ + + xdef z16f_lowuartinit + xref _SYS_CLK_FREQ:EROM +#ifdef CONFIG_ARCH_LOWPUTC + xdef _z16f_xmitc + xdef _up_lowputc +#endif +#ifdef CONFIG_ARCH_LOWGETC + xdef _up_lowgetc +#endif + +/************************************************************************* + * Data Allocation + *************************************************************************/ + + define CODESEG, SPACE=EROM + segment CODESEG + +/************************************************************************* + * Code + *************************************************************************/ + +/************************************************************************* + * Name: z16f_lowuartinit + * + * Description: + * Initialize UART0 or UART1 + * + * Parameters: + * None + * + *************************************************************************/ + +z16f_lowuartinit: + pushmlo <r0, r3> /* Save registers */ + + /* Calculate and set the baud rate generation register */ + + +#ifdef CONFIG_UART0_SERIAL_CONSOLE + ld r3, #CONFIG_UART0_BAUD /* r3 = baud */ +#else + ld r3, #CONFIG_UART1_BAUD /* r3 = baud */ +#endif + ld r0, r3 /* r0 = baud */ + sll r0, #3 /* r0 = baud * 8 */ + add r0, #_SYS_CLK_FREQ /* r3 = freq + baud * 8*/ + sll r3, #4 /* r3 = baud * 16 */ + udiv r0, r3 /* BRG = (freq + baud * 8)/(baud * 16) */ + +#ifdef CONFIG_UART0_SERIAL_CONSOLE + ld.w Z16F_UART0_BR, r0 /* Z16F_UART0_BR = BRG */ + + /* Set the GPIO Alternate Function Register Lo (AFL) register */ + + ld r0, #%30 + or.b Z16F_GPIOA_AFL, r0 /* Z16F_GPIOA_AFL |= %30 */ + + /* Enable UART receive (REN) and transmit (TEN) */ + + clr.b Z16F_UART0_CTL1 /* Z16F_UART0_CTL1 = 0 */ + ld r0, #(Z16F_UARTCTL0_TEN|Z16F_UARTCTL0_REN) + ld.b Z16F_UART0_CTL0, r0 /* Z16F_UART0_CTL0 = %c0 */ +#else + ld.w Z16F_UART1_BR, r0 /* Z16F_UART1_BR = BRG */ + + /* Set the GPIO Alternate Function Register Lo (AFL) register */ + + ld r0, #%30 + or.b Z16F_GPIOD_AFL, r0 /* Z16F_GPIOD_AFL |= %30 */ + + /* Enable UART receive (REN) and transmit (TEN) */ + + clr.b Z16F_UART1_CTL1 /* Z16F_UART1_CTL1 = 0 */ + ld r0, #(Z16F_UARTCTL0_TEN|Z16F_UARTCTL0_REN) + ld.b Z16F_UART1_CTL0, r0 /* Z16F_UART1_CTL0 = %c0 */ +#endif + popmlo <r0, r3> /* Restore registers */ + ret /* Return */ + + +/************************************************************************* + * Name: _z16f_xmitc + * + * Description: + * Send one character on the selected port + * + * Parmeters: + * r1 = character + * + *************************************************************************/ + +#ifdef CONFIG_ARCH_LOWPUTC +_z16f_xmitc: + pushmlo <r0> /* Save registers */ + +_z16f_xmitc1: + ld r0, Z16F_UARTSTAT0_TDRE /* TDRE=Transmitter Data Register Empty */ +#ifdef CONFIG_UART0_SERIAL_CONSOLE + tm.b Z16F_UART0_STAT0, r0 /* r0 = Z16F_UART0_STAT0 */ + jp eq, _z16f_xmitc1 /* While (!(Z16F_UART0_STAT0 & TDRE)) */ + ld.b Z16F_UART0_TXD, r1 /* Z16F_UART0_TXD = r1 (character) */ +#else + tm.b Z16F_UART1_STAT0, r0 /* r0 = Z16F_UART0_STAT1 */ + jp eq, _z16f_xmitc1 /* While (!(Z16F_UART1_STAT0 & TDRE)) */ + ld.b Z16F_UART1_TXD, r1 /* Z16F_UART1_TXD = r1 (character) */ +#endif + popmlo <r0> /* Restore registers */ + ret /* Return */ +#endif + +/************************************************************************* + * Name: _up_lowputc + * + * Description: + * Send one character to the selected serial console + * + * Parmeters: + * r1 = character + * + * Return + * R0 = 0 + * + *************************************************************************/ + +#ifdef CONFIG_ARCH_LOWPUTC +_up_lowputc: + pushmlo <r1,r5> /* Save registers */ + ld r0, r1 + ext.ub r5, r0 + cp r5, #10 + jp ne, _up_lowputc1 /* If (character == \n) */ + + ld r1,#13 + call _z16f_xmitc /* Call _z16f_xmitc with \r */ + +_up_lowputc1: + ld r1, r0 + call _z16f_xmitc /* Xall _z16f_xmitc with character */ + + ld r0, #0 /* return r0 = 0 */ + popmlo <r1,r5> /* Restore registers */ + ret /* Return */ +#endif + +/************************************************************************* + * Name: _up_lowgetc + * + * Description: + * Get a character from the serial port + * + * Parmeters: + * None + * + * Return + * R0 = Character read + * + *************************************************************************/ + +#ifdef CONFIG_ARCH_LOWGETC +_up_lowgetc: +up_lowgetc1: + ld r0, #Z16F_UARTSTAT0_RDA /* RDA=Receive data available */ +#ifdef CONFIG_UART0_SERIAL_CONSOLE + tm.b Z16F_UART0_STAT0, r0 + jp eq, _up_lowgetc1 /* While (!Z16F_UART0_STAT0 & RDA)) */ + ld.ub r0, Z16F_UART0_RXD /* r0 = Z16F_UART0_RXD */ +#else + tm.b Z16F_UART1_STAT0,r0 /* While (!Z16F_UART1_STAT0 & RDA) */ + jp eq, _up_lowgetc1 + ld.ub r0, Z16F_UART1_RXD /* r0 = Z16F_UART1_RXD */ +#endif + cp r0, #%0d /* Test for '\r' */ + jp eq, _up_lowgetc2 + + cp r0, #%0d /* Test \r + high bit */ + jp ne, _up_lowgetc3 +_up_lowgetc2: + ld r0, #%0a /* Convert '\r' to '\n' */ +_up_lowgetc3: /* Return value in r0 */ + ret /* Return */ +#endif + +#endif /* CONFIG_ARCH_LOWPUTC || CONFIG_ARCH_LOWGETC */ + + end diff --git a/nuttx/arch/z16/src/z16f/z16f_saveusercontext.S b/nuttx/arch/z16/src/z16f/z16f_saveusercontext.S new file mode 100644 index 000000000..339ced811 --- /dev/null +++ b/nuttx/arch/z16/src/z16f/z16f_saveusercontext.S @@ -0,0 +1,104 @@ +/************************************************************************* + * arch/z16/src/z16f/z16f_saveusercontext.asm + * + * Copyright (C) 2008 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 NuttX 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 <arch/irq.h> +#include "chip/chip.h" + +/************************************************************************* + * External References / External Definitions + *************************************************************************/ + + xdef up_saveusercontext + +/************************************************************************* + * Data Allocation + *************************************************************************/ + + define CODESEG, SPACE=EROM + segment CODESEG + +/************************************************************************* + * Code + *************************************************************************/ + +/************************************************************************* + * Name: up_saveusercontext + * + * Description: + * Save the current user context. + * r0-r7: These are caller saved registers and do not need to be stored + * here + * r8-r13: There callee saved registers must be preserved + * r14: Frame pointer + * r15: Stack pointer (with return address on stack) + * + * Parameters: + * r1: pointer to the register save array in the XCPT structure + * + *************************************************************************/ + +up_saveusercontext: + /* Save the flags (needed to restore the interrupt state) */ + + ld r3, Z16F_CNTRL_FLAGS /* Fetch the flags register */ + sll r3, #8 /* Pad with zero */ + ld 2*REG_FLAGS(r1), r3 + + /* Save r8-R13 */ + + ld 2*REG_R8(r1), r8 /* Save r8 */ + ld 2*REG_R8(r1), r9 /* Save r9 */ + ld 2*REG_R8(r1), r10 /* Save r10 */ + ld 2*REG_R8(r1), r11 /* Save r11 */ + ld 2*REG_R8(r1), r12 /* Save r12 */ + ld 2*REG_R8(r1), r13 /* Save r13 */ + + /* Save the stack pointer and the frame pointer */ + + ld 2*REG_FP(r1), fp /* Save the frame pointer */ + ld 2*REG_SP(r1), sp /* Save the stack pointer */ + + /* Save the return address at the top of the stack */ + + ld r0, (sp) /* Save the return address */ + ld 2*REG_PC(r1), r0 + clr r0 /* Always returns 0 */ + ret + end diff --git a/nuttx/arch/z16/src/z16f/z16f_serial.c b/nuttx/arch/z16/src/z16f/z16f_serial.c index 6089a555c..1ca6e0377 100644 --- a/nuttx/arch/z16/src/z16f/z16f_serial.c +++ b/nuttx/arch/z16/src/z16f/z16f_serial.c @@ -51,7 +51,7 @@ #include <nuttx/serial.h> #include <arch/serial.h> -#include "up_arch.h" +#include "chip/chip.h" #include "os_internal.h" #include "up_internal.h" |