Add z16f system exception handling logic.

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@564 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2008-01-25 17:49:43 +00:00
parent 45a7fe13bc
commit fd2f3d08d5
11 changed files with 884 additions and 711 deletions
+29 -31
View File
@@ -49,42 +49,40 @@
* Definitions
****************************************************************************/
/* Interrupt Vectors */
/* Interrupt Vectors (excluding reset and sysexec which are handled differently) */
#define Z16F_IRQ_SYSEXC ( 0) /* Vector: 0x08 System Exceptions */
#define Z16F_IRQ_IRQ0 ( 0) /* First of 8 IRQs controlled by IRQ0 registers */
#define Z16F_IRQ_ADC ( 0) /* Vector: 0x2C IRQ0.0 ADC */
#define Z16F_IRQ_SPI ( 1) /* Vector: 0x28 IRQ0.1 SPI */
#define Z16F_IRQ_I2C ( 2) /* Vector: 0x24 IRQ0.2 I2C */
#define Z16F_IRQ_UART0TX ( 3) /* Vector: 0x20 IRQ0.3 UART0 TX */
#define Z16F_IRQ_UART0RX ( 4) /* Vector: 0x1C IRQ0.4 UART0 RX */
#define Z16F_IRQ_TIMER0 ( 5) /* Vector: 0x18 IRQ0.5 Timer 0 */
#define Z16F_IRQ_TIMER1 ( 6) /* Vector: 0x14 IRQ0.6 Timer 1 */
#define Z16F_IRQ_TIMER2 ( 7) /* Vector: 0x10 IRQ0.7 Timer 2 */
#define Z16F_IRQ_IRQ0 ( 1) /* First of 8 IRQs controlled by IRQ0 registers */
#define Z16F_IRQ_ADC ( 1) /* Vector: 0x2C IRQ0.0 ADC */
#define Z16F_IRQ_SPI ( 2) /* Vector: 0x28 IRQ0.1 SPI */
#define Z16F_IRQ_I2C ( 3) /* Vector: 0x24 IRQ0.2 I2C */
#define Z16F_IRQ_UART0TX ( 4) /* Vector: 0x20 IRQ0.3 UART0 TX */
#define Z16F_IRQ_UART0RX ( 5) /* Vector: 0x1C IRQ0.4 UART0 RX */
#define Z16F_IRQ_TIMER0 ( 6) /* Vector: 0x18 IRQ0.5 Timer 0 */
#define Z16F_IRQ_TIMER1 ( 7) /* Vector: 0x14 IRQ0.6 Timer 1 */
#define Z16F_IRQ_TIMER2 ( 8) /* Vector: 0x10 IRQ0.7 Timer 2 */
#define Z16F_IRQ_IRQ1 ( 8) /* First of 8 IRQs controlled by IRQ1 registers */
#define Z16F_IRQ_P0AD ( 8) /* Vector: 0x4C IRQ1.0 Port A/D0, rising/falling edge */
#define Z16F_IRQ_P1AD ( 9) /* Vector: 0x48 IRQ1.1 Port A/D1, rising/falling edge */
#define Z16F_IRQ_P2AD (10) /* Vector: 0x44 IRQ1.2 Port A/D2, rising/falling edge */
#define Z16F_IRQ_P3AD (11) /* Vector: 0x40 IRQ1.3 Port A/D3, rising/falling edge */
#define Z16F_IRQ_P4AD (12) /* Vector: 0x3C IRQ1.4 Port A/D4, rising/falling edge */
#define Z16F_IRQ_P5AD (13) /* Vector: 0x38 IRQ1.5 Port A/D5, rising/falling edge */
#define Z16F_IRQ_P6AD (14) /* Vector: 0x34 IRQ1.6 Port A/D6, rising/falling edge */
#define Z16F_IRQ_P7AD (15) /* Vector: 0x30 IRQ1.7 Port A/D7, rising/falling edge */
#define Z16F_IRQ_IRQ1 ( 9) /* First of 8 IRQs controlled by IRQ1 registers */
#define Z16F_IRQ_P0AD ( 9) /* Vector: 0x4C IRQ1.0 Port A/D0, rising/falling edge */
#define Z16F_IRQ_P1AD (10) /* Vector: 0x48 IRQ1.1 Port A/D1, rising/falling edge */
#define Z16F_IRQ_P2AD (11) /* Vector: 0x44 IRQ1.2 Port A/D2, rising/falling edge */
#define Z16F_IRQ_P3AD (12) /* Vector: 0x40 IRQ1.3 Port A/D3, rising/falling edge */
#define Z16F_IRQ_P4AD (13) /* Vector: 0x3C IRQ1.4 Port A/D4, rising/falling edge */
#define Z16F_IRQ_P5AD (14) /* Vector: 0x38 IRQ1.5 Port A/D5, rising/falling edge */
#define Z16F_IRQ_P6AD (15) /* Vector: 0x34 IRQ1.6 Port A/D6, rising/falling edge */
#define Z16F_IRQ_P7AD (16) /* Vector: 0x30 IRQ1.7 Port A/D7, rising/falling edge */
#define Z16F_IRQ_IRQ2 (17) /* First of 8 IRQs controlled by IRQ2 registers */
#define Z16F_IRQ_C0 (17) /* Vector: IRQ2.0 0x6C Port C0, both edges DMA0 */
#define Z16F_IRQ_C1 (18) /* Vector: IRQ2.1 0x68 Port C1, both edges DMA1 */
#define Z16F_IRQ_C2 (19) /* Vector: IRQ2.2 0x64 Port C2, both edges DMA2 */
#define Z16F_IRQ_C3 (20) /* Vector: IRQ2.3 0x60 Port C3, both edges DMA3 */
#define Z16F_IRQ_PWMFAULT (21) /* Vector: IRQ2.4 0x5C PWM Fault */
#define Z16F_IRQ_UART1TX (22) /* Vector: IRQ2.5 0x58 UART1 TX */
#define Z16F_IRQ_UART1RX (23) /* Vector: IRQ2.6 0x54 UART1 RX */
#define Z16F_IRQ_PWMTIMER (24) /* Vector: IRQ2.7 0x50 PWM Timer */
#define Z16F_IRQ_IRQ2 (16) /* First of 8 IRQs controlled by IRQ2 registers */
#define Z16F_IRQ_C0 (16) /* Vector: IRQ2.0 0x6C Port C0, both edges DMA0 */
#define Z16F_IRQ_C1 (17) /* Vector: IRQ2.1 0x68 Port C1, both edges DMA1 */
#define Z16F_IRQ_C2 (18) /* Vector: IRQ2.2 0x64 Port C2, both edges DMA2 */
#define Z16F_IRQ_C3 (19) /* Vector: IRQ2.3 0x60 Port C3, both edges DMA3 */
#define Z16F_IRQ_PWMFAULT (20) /* Vector: IRQ2.4 0x5C PWM Fault */
#define Z16F_IRQ_UART1TX (21) /* Vector: IRQ2.5 0x58 UART1 TX */
#define Z16F_IRQ_UART1RX (22) /* Vector: IRQ2.6 0x54 UART1 RX */
#define Z16F_IRQ_PWMTIMER (23) /* Vector: IRQ2.7 0x50 PWM Timer */
#define Z16F_IRQ_SYSTIMER Z16F_IRQ_TIMER0
#define NR_IRQS (25)
#define NR_IRQS (24)
/* These macros will map an IRQ to a register bit position */
+1
View File
@@ -43,6 +43,7 @@
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/mm.h>
#include <arch/board/board.h>
#include "chip/chip.h"
#include "up_internal.h"
+1
View File
@@ -46,6 +46,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <arch/board/board.h>
#include "chip/chip.h"
#include "os_internal.h"
+1
View File
@@ -45,6 +45,7 @@
#include <nuttx/kmalloc.h>
#include <nuttx/arch.h>
#include <arch/board/board.h>
#include "chip/chip.h"
#include "up_internal.h"
+4 -2
View File
@@ -40,9 +40,11 @@
#include <nuttx/config.h>
#include <sys/types.h>
#include <assert.h>
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <assert.h>
#include <arch/board/board.h>
#include "chip/chip.h"
#include "os_internal.h"
@@ -79,7 +81,7 @@
FAR chipreg_t *up_doirq(int irq, FAR chipreg_t *regs)
{
chipreg_t *ret = regs;
FAR chipreg_t *ret = regs;
up_ledon(LED_INIRQ);
#ifdef CONFIG_SUPPRESS_INTERRUPTS
+1
View File
@@ -45,6 +45,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <arch/board/board.h>
#include "os_internal.h"
#include "up_internal.h"
+1 -1
View File
@@ -44,5 +44,5 @@ CMN_CSRCS = up_allocateheap.c up_initialize.c up_schedulesigaction.c \
up_exit.c up_releasestack.c up_idle.c up_reprioritizertr.c
CHIP_SSRCS = z16f_lowuart.S z16f_saveusercontext.S z16f_restoreusercontext.S
CHIP_CSRCS = z16f_clkinit.c z16f_irq.c z16f_timerisr.c z16f_serial.c
CHIP_CSRCS = z16f_clkinit.c z16f_sysexec.c z16f_irq.c z16f_timerisr.c z16f_serial.c
+33 -2
View File
@@ -42,6 +42,7 @@
************************************************************************************/
#include <nuttx/config.h>
#include <arch/irq.h>
/************************************************************************************
* Definitions
@@ -199,6 +200,28 @@
#define Z16F_IRQ2_ENH _HX32(ffffe03a) /* 8-bit: IRQ2 Enable High Bit */
#define Z16F_IRQ2_ENL _HX32(ffffe03c) /* 8-bit: IRQ2 Enable Low Bit */
/* System exception status register bit definitions *********************************/
#define Z16F_SYSEXCPH_SPOVF _HX8(80) /* Bit 7: Stack pointer overflow */
#define Z16F_SYSEXCPH_PCOVF _HX8(40) /* Bit 6: Program counter overflow */
#define Z16F_SYSEXCPH_DIV0 _HX8(20) /* Bit 5: Divide by zero */
#define Z16F_SYSEXCPH_DIVOVF _HX8(10) /* Bit 4: Divide overflow */
#define Z16F_SYSEXCPH_ILL _HX8(08) /* Bit 3: Illegal instruction */
/* Bits 0-2: Reserved */
/* Bits 3-7: Reserved */
#define Z16F_SYSEXCPL_WDTOSC _HX8(04) /* Bit 2: WDT oscillator failure */
#define Z16F_SYSEXCPL_PRIOSC _HX8(02) /* Bit 1: Primary oscillator failure */
#define Z16F_SYSEXCPL_WDT _HX8(01) /* Bit 0: Watchdog timer interrupt */
#define Z16F_SYSEXCP_SPOVF (Z16F_SYSEXCPH_SPOVF << 8)
#define Z16F_SYSEXCP_PCOVF (Z16F_SYSEXCPH_PCOVF << 8)
#define Z16F_SYSEXCP_DIV0 (Z16F_SYSEXCPH_DIV0 << 8)
#define Z16F_SYSEXCP_DIVOVF (Z16F_SYSEXCPH_DIVOVF << 8)
#define Z16F_SYSEXCP_ILL (Z16F_SYSEXCPH_ILL << 8)
#define Z16F_SYSEXCP_WDTOSC Z16F_SYSEXCPL_WDTOSC
#define Z16F_SYSEXCP_PRIOSC Z16F_SYSEXCPL_PRIOSC
#define Z16F_SYSEXCP_WDT Z16F_SYSEXCPL_WDT
/* Oscillator control registers *****************************************************/
#define Z16F_OSC_CTL _HX32(ffffe0A0) /* 8-bit: Oscillator Control */
@@ -519,11 +542,19 @@ extern "C" {
* debugging support for up_lowputc (or getc) is enabled.
*/
extern void z16f_lowinit(void);
EXTERN void z16f_lowinit(void);
#if defined(CONFIG_ARCH_LOWPUTC) || defined(CONFIG_ARCH_LOWGETC)
extern void z16f_lowuartinit(void);
EXTERN void z16f_lowuartinit(void);
#endif
/* This function handles Z16F system execeptions */
EXTERN void z16f_sysexec(FAR chipreg_t *regs);
/* Entry point to reset the processor */
EXTERN void z16f_reset(void);
#undef EXTERN
#ifdef __cplusplus
}
File diff suppressed because it is too large Load Diff
+233 -234
View File
@@ -1,234 +1,233 @@
/*************************************************************************
* 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
/*************************************************************************
* 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 _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
+126
View File
@@ -0,0 +1,126 @@
/***************************************************************************
* z16f/z16f_sysexec.c
*
* 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 <sys/types.h>
#include <debug.h>
#include <nuttx/arch.h>
#include "chip/chip.h"
#include "os_internal.h"
#include "up_internal.h"
/***************************************************************************
* Definitions
***************************************************************************/
#ifdef CONFIG_ARCH_LOWPUTC
# define SYSDBG lib_lowprintf
#else
# define SYSDBG lib_rawprintf
#endif
/***************************************************************************
* Private Types
***************************************************************************/
/***************************************************************************
* Private Functions
***************************************************************************/
/***************************************************************************
* Global Functions
***************************************************************************/
/***************************************************************************
* Function: z16f_sysexec
*
* Description:
* Handle a Z16F system execption
*
***************************************************************************/
void z16f_sysexec(FAR chipreg_t *regs)
{
int errcode = OSERR_ERREXCEPTION;
uint16 excp;
/* The cause of the the system exception is indicated in the SYSEXCPH&L
* registers
*/
excp = getreg16(Z16F_SYSEXCP);
if ((excp & Z16F_SYSEXCP_SPOVF) != 0)
{
SYSDBG("SP OVERFLOW\n");
}
if ((excp & Z16F_SYSEXCP_PCOVF) != 0)
{
SYSDBG("PC OVERFLOW\n");
}
if ((excp & Z16F_SYSEXCP_DIV0) != 0)
{
SYSDBG("Divide by zero\n");
}
if ((excp & Z16F_SYSEXCP_DIVOVF) != 0)
{
SYSDBG("Divide overflow\n");
}
if ((excp & Z16F_SYSEXCP_ILL) != 0)
{
SYSDBG("Illegal instruction\n");
errcode = OSERR_UNDEFINEDINSN;
}
if ((excp & Z16F_SYSEXCP_WDTOSC) != 0)
{
SYSDBG("WDT oscillator failure\n");
}
if ((excp & Z16F_SYSEXCP_PRIOSC) != 0)
{
SYSDBG("Primary Oscillator Failure\n");
}
if ((excp & Z16F_SYSEXCP_WDT) != 0)
{
SYSDBG("Watchdog timeout\n");
z16f_reset();
}
PANIC(errcode);
}