From 08330bf0be8fed443402ffd1664b2ca4d16b6f8e Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Thu, 27 Jul 2000 01:04:11 +0000 Subject: Port of RTEMS to the ARM processor family by Eric Valette and Emmanuel Raguet of Canon CRF - Communication Dept. This port includes a basic BSP that is sufficient to link hello world. --- c/src/lib/libbsp/arm/shared/.cvsignore | 2 + c/src/lib/libbsp/arm/shared/Makefile.am | 10 + c/src/lib/libbsp/arm/shared/comm/.cvsignore | 2 + c/src/lib/libbsp/arm/shared/comm/Makefile.am | 22 + c/src/lib/libbsp/arm/shared/comm/console.c | 367 +++++++++++++++++ c/src/lib/libbsp/arm/shared/comm/uart.c | 577 +++++++++++++++++++++++++++ c/src/lib/libbsp/arm/shared/comm/uart.h | 158 ++++++++ c/src/lib/libbsp/arm/shared/io/.cvsignore | 2 + c/src/lib/libbsp/arm/shared/io/Makefile.am | 22 + c/src/lib/libbsp/arm/shared/io/bspio.h | 38 ++ c/src/lib/libbsp/arm/shared/io/printk.c | 113 ++++++ c/src/lib/libbsp/arm/shared/irq/.cvsignore | 2 + c/src/lib/libbsp/arm/shared/irq/Makefile.am | 14 + c/src/lib/libbsp/arm/shared/irq/irq_asm.S | 109 +++++ c/src/lib/libbsp/arm/shared/irq/irq_init.c | 51 +++ 15 files changed, 1489 insertions(+) create mode 100644 c/src/lib/libbsp/arm/shared/.cvsignore create mode 100644 c/src/lib/libbsp/arm/shared/Makefile.am create mode 100644 c/src/lib/libbsp/arm/shared/comm/.cvsignore create mode 100644 c/src/lib/libbsp/arm/shared/comm/Makefile.am create mode 100644 c/src/lib/libbsp/arm/shared/comm/console.c create mode 100644 c/src/lib/libbsp/arm/shared/comm/uart.c create mode 100644 c/src/lib/libbsp/arm/shared/comm/uart.h create mode 100644 c/src/lib/libbsp/arm/shared/io/.cvsignore create mode 100644 c/src/lib/libbsp/arm/shared/io/Makefile.am create mode 100644 c/src/lib/libbsp/arm/shared/io/bspio.h create mode 100644 c/src/lib/libbsp/arm/shared/io/printk.c create mode 100644 c/src/lib/libbsp/arm/shared/irq/.cvsignore create mode 100644 c/src/lib/libbsp/arm/shared/irq/Makefile.am create mode 100644 c/src/lib/libbsp/arm/shared/irq/irq_asm.S create mode 100644 c/src/lib/libbsp/arm/shared/irq/irq_init.c (limited to 'c/src/lib/libbsp/arm/shared') diff --git a/c/src/lib/libbsp/arm/shared/.cvsignore b/c/src/lib/libbsp/arm/shared/.cvsignore new file mode 100644 index 0000000000..282522db03 --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/c/src/lib/libbsp/arm/shared/Makefile.am b/c/src/lib/libbsp/arm/shared/Makefile.am new file mode 100644 index 0000000000..2a3b172604 --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/Makefile.am @@ -0,0 +1,10 @@ +## +## $Id$ +## + +AUTOMAKE_OPTIONS = foreign 1.4 + +SUBDIRS = comm io irq + +include $(top_srcdir)/../../../../../automake/subdirs.am +include $(top_srcdir)/../../../../../automake/local.am diff --git a/c/src/lib/libbsp/arm/shared/comm/.cvsignore b/c/src/lib/libbsp/arm/shared/comm/.cvsignore new file mode 100644 index 0000000000..282522db03 --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/comm/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/c/src/lib/libbsp/arm/shared/comm/Makefile.am b/c/src/lib/libbsp/arm/shared/comm/Makefile.am new file mode 100644 index 0000000000..d049ebd8a8 --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/comm/Makefile.am @@ -0,0 +1,22 @@ +## +## $Id$ +## + +AUTOMAKE_OPTIONS = foreign 1.4 + +H_FILES = uart.h + +C_FILES = console.c uart.c + +$(PROJECT_INCLUDE): + $(mkinstalldirs) $@ +$(PROJECT_INCLUDE)/%.h: %.h + $(INSTALL_DATA) $< $@ + +PREINSTALL_FILES += $(PROJECT_INCLUDE) $(H_FILES:%.h=$(PROJECT_INCLUDE)/%.h) + +all: $(PREINSTALL_FILES) + +EXTRA_DIST = console.c uart.c uart.h + +include $(top_srcdir)/../../../../../automake/local.am diff --git a/c/src/lib/libbsp/arm/shared/comm/console.c b/c/src/lib/libbsp/arm/shared/comm/console.c new file mode 100644 index 0000000000..ec623c3dda --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/comm/console.c @@ -0,0 +1,367 @@ +/*-------------------------------------------------------------------------+ +| console.c - ARM BSP ++--------------------------------------------------------------------------+ +| This file contains the ARM console I/O package. ++--------------------------------------------------------------------------+ +| COPYRIGHT (c) 2000 Canon Research France SA. +| Emmanuel Raguet, mailto:raguet@crf.canon.fr +| +| The license and distribution terms for this file may be +| found in found in the file LICENSE in this distribution or at +| http://www.OARcorp.com/rtems/license.html. +| +| $Id$ ++--------------------------------------------------------------------------*/ + +#include +#include +#include +#include +#undef __assert +void __assert (const char *file, int line, const char *msg); + +#include +#include +#include +#include +#include +#include +#include + +/* + * Possible value for console input/output : + * BSP_CONSOLE_PORT_CONSOLE + * BSP_UART_COM1 + * BSP_UART_COM2 + * + * Note: + * 1. Currently BSPPrintkPort, cannot be assigned to COM2, + * it will be fixed soon. + * + * 2. If both BSPConsolePort and BSPPrintkport are assigned + * to same serial device it does not work that great + */ + +int BSPConsolePort = BSP_UART_COM1; +int BSPPrintkPort = BSP_UART_COM1; + +int BSPBaseBaud = 115200; + + +/*-------------------------------------------------------------------------+ +| External Prototypes ++--------------------------------------------------------------------------*/ +extern char BSP_wait_polled_input(void); +extern BSP_polling_getchar_function_type BSP_poll_char; +extern void rtemsReboot(void); + +static int conSetAttr(int minor, const struct termios *); +static void isr_on(const rtems_irq_connect_data *); +static void isr_off(const rtems_irq_connect_data *); +static int isr_is_on(const rtems_irq_connect_data *); + +/* + * BSP initialization + */ + +BSP_output_char_function_type BSP_output_char = BSP_output_char_via_serial; +BSP_polling_getchar_function_type BSP_poll_char = BSP_poll_char_via_serial; + + +static rtems_irq_connect_data console_isr_data = {BSP_UART, + BSP_uart_termios_isr_com1, + isr_on, + isr_off, + isr_is_on}; + +static void +isr_on(const rtems_irq_connect_data *unused) +{ + return; +} + +static void +isr_off(const rtems_irq_connect_data *unused) +{ + return; +} + +static int +isr_is_on(const rtems_irq_connect_data *irq) +{ + if (Regs[INTMASK] & 0x4) + return 0; + else + return 1; +} + +void console_reserve_resources(rtems_configuration_table *conf) +{ + rtems_termios_reserve_resources(conf, 1); + + return; +} + +void __assert (const char *file, int line, const char *msg) +{ + static char exit_msg[] = "EXECUTIVE SHUTDOWN! Any key to reboot..."; + unsigned char ch; + + /* + * Note we cannot call exit or printf from here, + * assert can fail inside ISR too + */ + + /* + * Close console + */ + close(2); + close(1); + close(0); + + printk("\nassert failed: %s: ", file); + printk("%d: ", line); + printk("%s\n\n", msg); + printk(exit_msg); + ch = BSP_poll_char(); + printk("\n\n"); + rtemsReboot(); + +} + + +/*-------------------------------------------------------------------------+ +| Console device driver INITIALIZE entry point. ++--------------------------------------------------------------------------+ +| Initilizes the I/O console (keyboard + VGA display) driver. ++--------------------------------------------------------------------------*/ +rtems_device_driver +console_initialize(rtems_device_major_number major, + rtems_device_minor_number minor, + void *arg) +{ + rtems_status_code status; + + /* + * Set up TERMIOS + */ + rtems_termios_initialize (); + + /* + * Do device-specific initialization + */ + + /* 38400-8-N-1 */ + BSP_uart_init(BSPConsolePort, 38400, 0); + + + /* Set interrupt handler */ + console_isr_data.name = BSP_UART; + console_isr_data.hdl = BSP_uart_termios_isr_com1; + console_isr_data.irqLevel = 3; + console_isr_data.irqTrigger = 0; + + status = BSP_install_rtems_irq_handler(&console_isr_data); + + if (!status){ + printk("Error installing serial console interrupt handler!\n"); + rtems_fatal_error_occurred(status); + } + + /* + * Register the device + */ + status = rtems_io_register_name ("/dev/console", major, 0); + if (status != RTEMS_SUCCESSFUL) + { + printk("Error registering console device!\n"); + rtems_fatal_error_occurred (status); + } + + printk("Initialized console on port COM1 38400-8-N-1\n\n"); + + return RTEMS_SUCCESSFUL; +} /* console_initialize */ + + +static int console_open_count = 0; + +static int console_last_close(int major, int minor, void *arg) +{ + BSP_remove_rtems_irq_handler (&console_isr_data); + + return 0; +} + +/*-------------------------------------------------------------------------+ +| Console device driver OPEN entry point ++--------------------------------------------------------------------------*/ +rtems_device_driver +console_open(rtems_device_major_number major, + rtems_device_minor_number minor, + void *arg) +{ + rtems_status_code status; + static rtems_termios_callbacks cb = + { + NULL, /* firstOpen */ + console_last_close, /* lastClose */ + NULL, /* pollRead */ + BSP_uart_termios_write_com1, /* write */ + conSetAttr, /* setAttributes */ + NULL, /* stopRemoteTx */ + NULL, /* startRemoteTx */ + 1 /* outputUsesInterrupts */ + }; + + status = rtems_termios_open (major, minor, arg, &cb); + + if(status != RTEMS_SUCCESSFUL) + { + printk("Error openning console device\n"); + return status; + } + + /* + * Pass data area info down to driver + */ + BSP_uart_termios_set(BSPConsolePort, + ((rtems_libio_open_close_args_t *)arg)->iop->data1); + + /* Enable interrupts on channel */ + BSP_uart_intr_ctrl(BSPConsolePort, BSP_UART_INTR_CTRL_TERMIOS); + + return RTEMS_SUCCESSFUL; +} + +/*-------------------------------------------------------------------------+ +| Console device driver CLOSE entry point ++--------------------------------------------------------------------------*/ +rtems_device_driver +console_close(rtems_device_major_number major, + rtems_device_minor_number minor, + void *arg) +{ + rtems_device_driver res = RTEMS_SUCCESSFUL; + + res = rtems_termios_close (arg); + + return res; +} /* console_close */ + + +/*-------------------------------------------------------------------------+ +| Console device driver READ entry point. ++--------------------------------------------------------------------------+ +| Read characters from the I/O console. We only have stdin. ++--------------------------------------------------------------------------*/ +rtems_device_driver +console_read(rtems_device_major_number major, + rtems_device_minor_number minor, + void *arg) +{ + + return rtems_termios_read (arg); + +} /* console_read */ + + +/*-------------------------------------------------------------------------+ +| Console device driver WRITE entry point. ++--------------------------------------------------------------------------+ +| Write characters to the I/O console. Stderr and stdout are the same. ++--------------------------------------------------------------------------*/ +rtems_device_driver +console_write(rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg) +{ + + return rtems_termios_write (arg); + +} /* console_write */ + + + +/* + * Handle ioctl request. + */ +rtems_device_driver +console_control(rtems_device_major_number major, + rtems_device_minor_number minor, + void * arg +) +{ + return rtems_termios_ioctl (arg); +} + +static int +conSetAttr(int minor, const struct termios *t) +{ + int baud; + + switch (t->c_cflag & CBAUD) + { + case B50: + baud = 50; + break; + case B75: + baud = 75; + break; + case B110: + baud = 110; + break; + case B134: + baud = 134; + break; + case B150: + baud = 150; + break; + case B200: + baud = 200; + break; + case B300: + baud = 300; + break; + case B600: + baud = 600; + break; + case B1200: + baud = 1200; + break; + case B1800: + baud = 1800; + break; + case B2400: + baud = 2400; + break; + case B4800: + baud = 4800; + break; + case B9600: + baud = 9600; + break; + case B19200: + baud = 19200; + break; + case B38400: + baud = 38400; + break; + case B57600: + baud = 57600; + break; + case B115200: + baud = 115200; + break; + default: + baud = 0; + rtems_fatal_error_occurred (RTEMS_INTERNAL_ERROR); + return 0; + } + + BSP_uart_set_baud(BSPConsolePort, baud); + + return 0; +} + + diff --git a/c/src/lib/libbsp/arm/shared/comm/uart.c b/c/src/lib/libbsp/arm/shared/comm/uart.c new file mode 100644 index 0000000000..ba63b7209c --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/comm/uart.c @@ -0,0 +1,577 @@ +/* + * This software is Copyright (C) 1998 by T.sqware - all rights limited + * It is provided in to the public domain "as is", can be freely modified + * as far as this copyight notice is kept unchanged, but does not imply + * an endorsement by T.sqware of the product in which it is included. + * + * COPYRIGHT (c) 2000 Canon Research France SA. + * Emmanuel Raguet, mailto:raguet@crf.canon.fr + * + * The license and distribution terms for this file may be + * found in found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#include +#include +#include +#include +#include + +/* + * Basic 16552 driver + */ + +struct uart_data +{ + int hwFlow; + int baud; +}; + +static struct uart_data uart_data[2]; + +/* + * Macros to read/wirte register of uart, if configuration is + * different just rewrite these macros + */ + +static inline unsigned char +uread(int uart, unsigned int reg) +{ + register unsigned char val; + + val = Regs[reg]; + + return val; +} + +static inline void +uwrite(int uart, int reg, unsigned int val) +{ + + Regs[reg] = val; + +} + +#ifdef UARTDEBUG + static void +uartError(int uart) +{ + unsigned char uartStatus, dummy; + + uartStatus = uread(uart, LSR); + dummy = uread(uart, RBR); + + if (uartStatus & OE) + printk("********* Over run Error **********\n"); + if (uartStatus & PE) + printk("********* Parity Error **********\n"); + if (uartStatus & FE) + printk("********* Framing Error **********\n"); + if (uartStatus & BI) + printk("********* Parity Error **********\n"); + if (uartStatus & ERFIFO) + printk("********* Error receive Fifo **********\n"); + +} +#else +inline void uartError(int uart) +{ + unsigned char uartStatus; + + uartStatus = uread(uart, LSR); + uartStatus = uread(uart, RBR); +} +#endif + +/* + * Uart initialization, it is hardcoded to 8 bit, no parity, + * one stop bit, FIFO, things to be changed + * are baud rate and nad hw flow control, + * and longest rx fifo setting + */ +void +BSP_uart_init(int uart, int baud, int hwFlow) +{ + unsigned char tmp; + + /* Sanity check */ + assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); + + switch(baud) + { + case 50: + case 75: + case 110: + case 134: + case 300: + case 600: + case 1200: + case 2400: + case 9600: + case 19200: + case 38400: + case 57600: + case 115200: + break; + default: + assert(0); + return; + } + + /* Enable UART block */ + uwrite(uart, CNT, UART_ENABLE | PAD_ENABLE); + + /* Set DLAB bit to 1 */ + uwrite(uart, LCR, DLAB); + + /* Set baud rate */ + uwrite(uart, DLL, (BSPBaseBaud/baud) & 0xff); + uwrite(uart, DLM, ((BSPBaseBaud/baud) >> 8) & 0xff); + + /* 8-bit, no parity , 1 stop */ + uwrite(uart, LCR, CHR_8_BITS); + + /* Enable FIFO */ + uwrite(uart, FCR, FIFO_EN | XMIT_RESET | RCV_RESET | RECEIVE_FIFO_TRIGGER12); + + /* Disable Interrupts */ + uwrite(uart, IER, 0); + + /* Read status to clear them */ + tmp = uread(uart, LSR); + tmp = uread(uart, RBR); + + /* Remember state */ + uart_data[uart].hwFlow = hwFlow; + uart_data[uart].baud = baud; + return; +} + +/* + * Set baud + */ +void +BSP_uart_set_baud(int uart, int baud) +{ + unsigned char ier; + + /* Sanity check */ + assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); + + /* + * This function may be called whenever TERMIOS parameters + * are changed, so we have to make sure that baud change is + * indeed required + */ + + if(baud == uart_data[uart].baud) + { + return; + } + + ier = uread(uart, IER); + + BSP_uart_init(uart, baud, uart_data[uart].hwFlow); + + uwrite(uart, IER, ier); + + return; +} + +/* + * Enable/disable interrupts + */ +void +BSP_uart_intr_ctrl(int uart, int cmd) +{ + + assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); + + switch(cmd) + { + case BSP_UART_INTR_CTRL_DISABLE: + uwrite(uart, IER, INTERRUPT_DISABLE); + break; + case BSP_UART_INTR_CTRL_ENABLE: + uwrite(uart, IER, + (RECEIVE_ENABLE | + TRANSMIT_ENABLE | + RECEIVER_LINE_ST_ENABLE + ) + ); + break; + case BSP_UART_INTR_CTRL_TERMIOS: + uwrite(uart, IER, + (RECEIVE_ENABLE | + RECEIVER_LINE_ST_ENABLE + ) + ); + break; + case BSP_UART_INTR_CTRL_GDB: + uwrite(uart, IER, RECEIVE_ENABLE); + break; + default: + assert(0); + break; + } + + return; +} + + +/* + * Status function, -1 if error + * detected, 0 if no received chars available, + * 1 if received char available, 2 if break + * is detected, it will eat break and error + * chars. It ignores overruns - we cannot do + * anything about - it execpt count statistics + * and we are not counting it. + */ +int +BSP_uart_polled_status(int uart) +{ + unsigned char val; + + assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); + + val = uread(uart, LSR); + + if(val & BI) + { + /* BREAK found, eat character */ + uread(uart, RBR); + return BSP_UART_STATUS_BREAK; + } + + if((val & (DR | OE | FE)) == 1) + { + /* No error, character present */ + return BSP_UART_STATUS_CHAR; + } + + if((val & (DR | OE | FE)) == 0) + { + /* Nothing */ + return BSP_UART_STATUS_NOCHAR; + } + + /* + * Framing or parity error + * eat character + */ + uread(uart, RBR); + + return BSP_UART_STATUS_ERROR; +} + + +/* + * Polled mode write function + */ +void +BSP_uart_polled_write(int uart, int val) +{ + unsigned char val1; + + /* Sanity check */ + assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); + + for(;;) + { + if((val1=uread(uart, LSR)) & THRE) + { + break; + } + } + + uwrite(uart, THR, val & 0xff); + + return; +} + +void +BSP_output_char_via_serial(int val) +{ + BSP_uart_polled_write(BSPConsolePort, val); + if (val == '\n') BSP_uart_polled_write(BSPConsolePort,'\r'); +} + +/* + * Polled mode read function + */ +int +BSP_uart_polled_read(int uart) +{ + unsigned char val; + + assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); + + for(;;) + { + if(uread(uart, LSR) & DR) + { + break; + } + } + + val = uread(uart, RBR); + + return (int)(val & 0xff); +} + +unsigned +BSP_poll_char_via_serial() +{ + return BSP_uart_polled_read(BSPConsolePort); +} + + +/* ================ Termios support =================*/ + +static volatile int termios_stopped_com1 = 0; +static volatile int termios_tx_active_com1 = 0; +static void* termios_ttyp_com1 = NULL; +static char termios_tx_hold_com1 = 0; +static volatile char termios_tx_hold_valid_com1 = 0; + +static volatile int termios_stopped_com2 = 0; +static volatile int termios_tx_active_com2 = 0; +static void* termios_ttyp_com2 = NULL; +static char termios_tx_hold_com2 = 0; +static volatile char termios_tx_hold_valid_com2 = 0; + +/* + * Set channel parameters + */ +void +BSP_uart_termios_set(int uart, void *ttyp) +{ + assert(uart == BSP_UART_COM1 || uart == BSP_UART_COM2); + + if(uart == BSP_UART_COM1) + { + termios_stopped_com1 = 0; + termios_tx_active_com1 = 0; + termios_ttyp_com1 = ttyp; + termios_tx_hold_com1 = 0; + termios_tx_hold_valid_com1 = 0; + } + else + { + termios_stopped_com2 = 0; + termios_tx_active_com2 = 0; + termios_ttyp_com2 = ttyp; + termios_tx_hold_com2 = 0; + termios_tx_hold_valid_com2 = 0; + } + + return; +} + +int +BSP_uart_termios_write_com1(int minor, const char *buf, int len) +{ + assert(buf != NULL); + + if(len <= 0) + { + return 0; + } + + /* If there TX buffer is busy - something is royally screwed up */ + assert((uread(BSP_UART_COM1, LSR) & THRE) != 0); + + if(termios_stopped_com1) + { + /* CTS low */ + termios_tx_hold_com1 = *buf; + termios_tx_hold_valid_com1 = 1; + return 0; + } + + /* Write character */ + uwrite(BSP_UART_COM1, THR, *buf & 0xff); + + /* Enable interrupts if necessary */ + if(!termios_tx_active_com1) + { + termios_tx_active_com1 = 1; + uwrite(BSP_UART_COM1, IER, + (RECEIVE_ENABLE | + TRANSMIT_ENABLE | + RECEIVER_LINE_ST_ENABLE + ) + ); + } + + return 0; +} + +int +BSP_uart_termios_write_com2(int minor, const char *buf, int len) +{ + assert(buf != NULL); + + if(len <= 0) + { + return 0; + } + + + /* If there TX buffer is busy - something is royally screwed up */ + assert((uread(BSP_UART_COM2, LSR) & THRE) != 0); + + if(termios_stopped_com2) + { + /* CTS low */ + termios_tx_hold_com2 = *buf; + termios_tx_hold_valid_com2 = 1; + return 0; + } + + /* Write character */ + + uwrite(BSP_UART_COM2, THR, *buf & 0xff); + + /* Enable interrupts if necessary */ + if(!termios_tx_active_com2) + { + termios_tx_active_com2 = 1; + uwrite(BSP_UART_COM2, IER, + (RECEIVE_ENABLE | + TRANSMIT_ENABLE | + RECEIVER_LINE_ST_ENABLE + ) + ); + } + + return 0; +} + + +void +BSP_uart_termios_isr_com1(void) +{ + unsigned char buf[40]; + int off, ret, vect; + + off = 0; + + for(;;) + { + vect = uread(BSP_UART_COM1, IIR) & 0xf; + + switch(vect) + { + case NO_MORE_INTR : + /* No more interrupts */ + if(off != 0) + { + /* Update rx buffer */ + rtems_termios_enqueue_raw_characters(termios_ttyp_com1, + (char *)buf, + off); + } + return; + case TRANSMITTER_HODING_REGISTER_EMPTY : + /* + * TX holding empty: we have to disable these interrupts + * if there is nothing more to send. + */ + + ret = rtems_termios_dequeue_characters(termios_ttyp_com1, 1); + + /* If nothing else to send disable interrupts */ + if(ret == 0) + { + uwrite(BSP_UART_COM1, IER, + (RECEIVE_ENABLE | + RECEIVER_LINE_ST_ENABLE + ) + ); + termios_tx_active_com1 = 0; + } + break; + case RECEIVER_DATA_AVAIL : + case CHARACTER_TIMEOUT_INDICATION: + /* RX data ready */ + assert(off < sizeof(buf)); + buf[off++] = uread(BSP_UART_COM1, RBR); + break; + case RECEIVER_ERROR: + /* RX error: eat character */ + uartError(BSP_UART_COM1); + break; + default: + /* Should not happen */ + assert(0); + return; + } + } +} + +void +BSP_uart_termios_isr_com2() +{ + unsigned char buf[40]; + int off, ret, vect; + + off = 0; + + for(;;) + { + vect = uread(BSP_UART_COM2, IIR) & 0xf; + + switch(vect) + { + case NO_MORE_INTR : + /* No more interrupts */ + if(off != 0) + { + /* Update rx buffer */ + rtems_termios_enqueue_raw_characters(termios_ttyp_com2, + (char *)buf, + off); + } + return; + case TRANSMITTER_HODING_REGISTER_EMPTY : + /* + * TX holding empty: we have to disable these interrupts + * if there is nothing more to send. + */ + + ret = rtems_termios_dequeue_characters(termios_ttyp_com2, 1); + + /* If nothing else to send disable interrupts */ + if(ret == 0) + { + uwrite(BSP_UART_COM2, IER, + (RECEIVE_ENABLE | + RECEIVER_LINE_ST_ENABLE + ) + ); + termios_tx_active_com2 = 0; + } + break; + case RECEIVER_DATA_AVAIL : + case CHARACTER_TIMEOUT_INDICATION: + /* RX data ready */ + assert(off < sizeof(buf)); + buf[off++] = uread(BSP_UART_COM2, RBR); + break; + case RECEIVER_ERROR: + /* RX error: eat character */ + uartError(BSP_UART_COM2); + break; + default: + /* Should not happen */ + assert(0); + return; + } + } +} diff --git a/c/src/lib/libbsp/arm/shared/comm/uart.h b/c/src/lib/libbsp/arm/shared/comm/uart.h new file mode 100644 index 0000000000..d517109392 --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/comm/uart.h @@ -0,0 +1,158 @@ + + +/* + * This software is Copyright (C) 1998 by T.sqware - all rights limited + * It is provided in to the public domain "as is", can be freely modified + * as far as this copyight notice is kept unchanged, but does not imply + * an endorsement by T.sqware of the product in which it is included. + * + * Copyright (c) Canon Research France SA.] + * Emmanuel Raguet, mailto:raguet@crf.canon.fr + * + * The license and distribution terms for this file may be + * found in found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + */ + +#ifndef _BSPUART_H +#define _BSPUART_H + +void BSP_uart_init(int uart, int baud, int hwFlow); +void BSP_uart_set_baud(int aurt, int baud); +void BSP_uart_intr_ctrl(int uart, int cmd); +void BSP_uart_throttle(int uart); +void BSP_uart_unthrottle(int uart); +int BSP_uart_polled_status(int uart); +void BSP_uart_polled_write(int uart, int val); +int BSP_uart_polled_read(int uart); +void BSP_uart_termios_set(int uart, void *ttyp); +int BSP_uart_termios_write_com1(int minor, const char *buf, int len); +int BSP_uart_termios_write_com2(int minor, const char *buf, int len); +void BSP_uart_termios_isr_com1(); +void BSP_uart_termios_isr_com2(); +void BSP_uart_dbgisr_com1(void); +void BSP_uart_dbgisr_com2(void); +extern unsigned BSP_poll_char_via_serial(void); +extern void BSP_output_char_via_serial(int val); +extern int BSPConsolePort; +extern int BSPBaseBaud; +/* + * Command values for BSP_uart_intr_ctrl(), + * values are strange in order to catch errors + * with assert + */ +#define BSP_UART_INTR_CTRL_DISABLE (0) +#define BSP_UART_INTR_CTRL_GDB (0xaa) /* RX only */ +#define BSP_UART_INTR_CTRL_ENABLE (0xbb) /* Normal operations */ +#define BSP_UART_INTR_CTRL_TERMIOS (0xcc) /* RX & line status */ + +/* Return values for uart_polled_status() */ +#define BSP_UART_STATUS_ERROR (-1) /* No character */ +#define BSP_UART_STATUS_NOCHAR (0) /* No character */ +#define BSP_UART_STATUS_CHAR (1) /* Character present */ +#define BSP_UART_STATUS_BREAK (2) /* Break point is detected */ + +/* PC UART definitions */ +#define BSP_UART_COM1 (0) +#define BSP_UART_COM2 (1) + +/* + * Base IO for UART + */ + +#define COM1_BASE_IO 0x3F8 +#define COM2_BASE_IO 0x2F8 + +/* + * Offsets from base + */ + +/* DLAB 0 */ +#define RBR RSRBR /* Rx Buffer Register (read) */ +#define THR RSTHR /* Tx Buffer Register (write) */ +#define IER RSIER /* Interrupt Enable Register */ + +/* DLAB X */ +#define IIR RSIIR /* Interrupt Ident Register (read) */ +#define FCR RSFCR /* FIFO Control Register (write) */ +#define LCR RSLCR /* Line Control Register */ +#define LSR RSLSR /* Line Status Register */ + +/* DLAB 1 */ +#define DLL RSDLL /* Divisor Latch, LSB */ +#define DLM RSDLH /* Divisor Latch, MSB */ + +/* Uart control */ +#define CNT RSCNT /* General Control register */ + +/* + * define bit for CNT + */ +#define UART_ENABLE 1 +#define PAD_ENABLE 2 + +/* + * Interrupt source definition via IIR + */ +#define NO_MORE_INTR 1 +#define TRANSMITTER_HODING_REGISTER_EMPTY 2 +#define RECEIVER_DATA_AVAIL 4 +#define RECEIVER_ERROR 6 +#define CHARACTER_TIMEOUT_INDICATION 12 + +/* + * Bits definition of IER + */ +#define RECEIVE_ENABLE 0x1 +#define TRANSMIT_ENABLE 0x2 +#define RECEIVER_LINE_ST_ENABLE 0x4 +#define INTERRUPT_DISABLE 0x0 + +/* + * Bits definition of the Line Status Register (LSR) + */ +#define DR 0x01 /* Data Ready */ +#define OE 0x02 /* Overrun Error */ +#define PE 0x04 /* Parity Error */ +#define FE 0x08 /* Framing Error */ +#define BI 0x10 /* Break Interrupt */ +#define THRE 0x20 /* Transmitter Holding Register Empty */ +#define TEMT 0x40 /* Transmitter Empty */ +#define ERFIFO 0x80 /* Error receive Fifo */ + +/* + * Bits definition of the Line Control Register (LCR) + */ +#define CHR_5_BITS 0 +#define CHR_6_BITS 1 +#define CHR_7_BITS 2 +#define CHR_8_BITS 3 + +#define WL 0x03 /* Word length mask */ +#define STB 0x04 /* 1 Stop Bit, otherwise 2 Stop Bits */ +#define PEN 0x08 /* Parity Enabled */ +#define EPS 0x10 /* Even Parity Select, otherwise Odd */ +#define SP 0x20 /* Stick Parity */ +#define BCB 0x40 /* Break Control Bit */ +#define DLAB 0x80 /* Enable Divisor Latch Access */ + +/* + * Bits definition of the FIFO Control Register : WD16C552 or NS16550 + */ + +#define FIFO_CTRL 0x01 /* Set to 1 permit access to other bits */ +#define FIFO_EN 0x01 /* Enable the FIFO */ +#define XMIT_RESET 0x04 /* Transmit FIFO Reset */ +#define RCV_RESET 0x02 /* Receive FIFO Reset */ +#define FCR3 0x08 /* do not understand manual! */ + +#define RECEIVE_FIFO_TRIGGER1 0x0 /* trigger recieve interrupt after 1 byte */ +#define RECEIVE_FIFO_TRIGGER4 0x40 /* trigger recieve interrupt after 4 byte */ +#define RECEIVE_FIFO_TRIGGER8 0x80 /* trigger recieve interrupt after 8 byte */ +#define RECEIVE_FIFO_TRIGGER12 0xc0 /* trigger recieve interrupt after 14 byte */ +#define TRIG_LEVEL 0xc0 /* Mask for the trigger level */ + +#endif /* _BSPUART_H */ + + + diff --git a/c/src/lib/libbsp/arm/shared/io/.cvsignore b/c/src/lib/libbsp/arm/shared/io/.cvsignore new file mode 100644 index 0000000000..282522db03 --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/io/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/c/src/lib/libbsp/arm/shared/io/Makefile.am b/c/src/lib/libbsp/arm/shared/io/Makefile.am new file mode 100644 index 0000000000..2c543cc77d --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/io/Makefile.am @@ -0,0 +1,22 @@ +## +## $Id$ +## + +AUTOMAKE_OPTIONS = foreign 1.4 + +H_FILES = bspio.h + +C_FILES = printk.c + +$(PROJECT_INCLUDE): + $(mkinstalldirs) $@ +$(PROJECT_INCLUDE)/%.h: %.h + $(INSTALL_DATA) $< $@ + +PREINSTALL_FILES += $(PROJECT_INCLUDE) $(H_FILES:%.h=$(PROJECT_INCLUDE)/%.h) + +all: $(PREINSTALL_FILES) + +EXTRA_DIST = bspio.h printk.c + +include $(top_srcdir)/../../../../../automake/local.am diff --git a/c/src/lib/libbsp/arm/shared/io/bspio.h b/c/src/lib/libbsp/arm/shared/io/bspio.h new file mode 100644 index 0000000000..b4ef8510da --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/io/bspio.h @@ -0,0 +1,38 @@ +/* bspIo.h + * + * This include file contains declaration of interface that + * will be provided by the file contained in this directory. + * + * + * COPYRIGHT (c) 2000 Canon Research France SA. + * Emmanuel Raguet, mailto:raguet@crf.canon.fr + * + * The license and distribution terms for this file may be + * found in found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ +#ifndef _LIBBSP_ARM_SHARED_IO_BSP_IO_H +#define _LIBBSP_ARM_SHARED_IO_BSP_IO_H + +/* + * All the functions declared as extern after this comment + * MUST be implemented in each BSP. Using this function, + * this directory contains shared code that export higher level + * functionnality described after the next command. + */ +typedef void (*BSP_output_char_function_type) (char c); +typedef char (*BSP_polling_getchar_function_type) (void); + +extern BSP_output_char_function_type BSP_output_char; +extern BSP_polling_getchar_function_type BSP_poll_char; +/* + * All the function declared as extern after this comment + * are available for each ix86 BSP by compiling and linking + * the files contained in this directory PROVIDED definition + * and initialisation of the previous variable are done. + */ +void printk(char *fmt, ...); + +#endif diff --git a/c/src/lib/libbsp/arm/shared/io/printk.c b/c/src/lib/libbsp/arm/shared/io/printk.c new file mode 100644 index 0000000000..d53699a3de --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/io/printk.c @@ -0,0 +1,113 @@ +/*-------------------------------------------------------------------------+ +| printk.c - ARM BSP ++--------------------------------------------------------------------------+ +| +| COPYRIGHT (c) 2000 Canon Research France SA. +| Emmanuel Raguet, mailto:raguet@crf.canon.fr +| +| The license and distribution terms for this file may be +| found in found in the file LICENSE in this distribution or at +| http://www.OARcorp.com/rtems/license.html. +| +| $Id$ ++--------------------------------------------------------------------------*/ + + +#include +#include +#include + +/*-------------------------------------------------------------------------+ +| Function: printNum +| Description: print number in a given base. +| Global Variables: None. +| Arguments: num - number to print, base - base used to print the number. +| Returns: Nothing. ++--------------------------------------------------------------------------*/ +static void +printNum(long unsigned int num, int base, int sign) +{ + long unsigned int n; + int count; + char toPrint[20]; + + if ( (sign == 1) && ((long)num < 0) ) { + BSP_output_char('-'); + num = -num; + } + + count = 0; + while ((n = num / base) > 0) { + toPrint[count++] = (num - (n*base)); + num = n ; + } + toPrint[count++] = num; + + for (n = 0; n < count; n++){ + BSP_output_char("0123456789ABCDEF"[(int)(toPrint[count-(n+1)])]); + } +} /* printNum */ + + +/*-------------------------------------------------------------------------+ +| Function: printk +| Description: a simplified version of printf intended for use when the + console is not yet initialized or in ISR's. +| Global Variables: None. +| Arguments: as in printf: fmt - format string, ... - unnamed arguments. +| Returns: Nothing. ++--------------------------------------------------------------------------*/ +void +printk(char *fmt, ...) +{ + va_list ap; /* points to each unnamed argument in turn */ + char c, *str; + int lflag, base, sign; + + _CPU_ISR_Disable(level); + + va_start(ap, fmt); /* make ap point to 1st unnamed arg */ + for (; *fmt != '\0'; fmt++) + { + lflag = 0; + base = 0; + sign = 0; + if (*fmt == '%') + { + if ((c = *++fmt) == 'l') + { + lflag = 1; + c = *++fmt; + } + switch (c) + { + case 'o': case 'O': base = 8; sign = 0; break; + case 'd': case 'D': base = 10; sign = 1; break; + case 'u': case 'U': base = 10; sign = 0; break; + case 'x': case 'X': base = 16; sign = 0; break; + case 's': + for (str = va_arg(ap, char *); *str; str++) + BSP_output_char(*str); + break; + case 'c': + BSP_output_char(va_arg(ap, char)); + break; + default: + BSP_output_char(c); + break; + } /* switch*/ + + if (base) + printNum(lflag ? va_arg(ap, long int) : (long int)va_arg(ap, int), + base, sign); + } + else + { + BSP_output_char(*fmt); + } + } + va_end(ap); /* clean up when done */ + _CPU_ISR_Enable(level); + +} /* printk */ + diff --git a/c/src/lib/libbsp/arm/shared/irq/.cvsignore b/c/src/lib/libbsp/arm/shared/irq/.cvsignore new file mode 100644 index 0000000000..282522db03 --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/irq/.cvsignore @@ -0,0 +1,2 @@ +Makefile +Makefile.in diff --git a/c/src/lib/libbsp/arm/shared/irq/Makefile.am b/c/src/lib/libbsp/arm/shared/irq/Makefile.am new file mode 100644 index 0000000000..89925fdfd0 --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/irq/Makefile.am @@ -0,0 +1,14 @@ +## +## $Id$ +## + +AUTOMAKE_OPTIONS = foreign 1.4 + +C_FILES = irq_init.c +S_FILES = irq_asm.S + +all: + +EXTRA_DIST = irq_asm.S irq_init.c + +include $(top_srcdir)/../../../../../automake/local.am diff --git a/c/src/lib/libbsp/arm/shared/irq/irq_asm.S b/c/src/lib/libbsp/arm/shared/irq/irq_asm.S new file mode 100644 index 0000000000..e6b740eb9a --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/irq/irq_asm.S @@ -0,0 +1,109 @@ +/* irq_asm.S + * + * This file contains the implementation of the IRQ handler + * + * CopyRight (C) 2000 Canon Research France SA. + * Emmanuel Raguet, mailto:raguet@crf.canon.fr + * + * The license and distribution terms for this file may be + * found in found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include "asm.h" +#define __asm__ +#include + + +/* + * WARNING : register r5 is important. If you need to use it, + * to forget to save it !!!!!!!!!! + */ + + .globl _ISR_Handler +_ISR_Handler: + stmdb sp!, {r4,r5,lr} /* save regs on INT stack */ + mrs r4, cpsr /* save current CSPR */ + mov r5, r4 /* copy CSPR */ + orr r4, r4, #3 + msr cpsr, r4 /* switch to SVC mode */ + + stmdb sp!, {r0-r3,r12,r14} /* save scratch regs on SVC stack */ + + msr cpsr, r5 /* switch back to INT mode */ + + ldr r0, =_ISR_Nest_level /* one nest level deeper */ + ldr r1, [r0] + add r1, r1,#1 + str r1, [r0] + + ldr r0, =_Thread_Dispatch_disable_level /* disable multitasking */ + ldr r1, [r0] + add r1, r1,#1 + str r1, [r0] + + b ExecuteITHandler /* BSP specific function to INT handler */ + + .globl ReturnFromHandler +ReturnFromHandler : + ldr r0, =_ISR_Nest_level /* one less nest level */ + ldr r1, [r0] + sub r1, r1,#1 + str r1, [r0] + + ldr r0, =_Thread_Dispatch_disable_level /* unnest multitasking */ + ldr r1, [r0] + sub r1, r1,#1 + str r1, [r0] + + cmp r1, #0 /* is dispatch enabled */ + bne exitit /* Yes, then exit */ + + ldr r0, =_Context_Switch_necessary /* task switch necessary ? */ + ldr r1, [r0] + cmp r1, #0 + bne schedule /* yes, call scheduler */ + + ldr r0, =_ISR_Signals_to_thread_executing + ldr r1, [r0] /* signals sent to Run_thread */ + cmp r1, #0 /* while in interrupt handler ? */ + beq exitit /* No, exit */ + +bframe: + mov r1, #0 /* _ISR_Signals_to_thread_executing = FALSE */ + str r1, [r0] + /* + * At this point, we need a complete exception context for the + * current thread. We need to complete the interrupt exception + * with the "not-yet-saved" registers + */ + /* + * currently exception context = interrupt handler + * it needs to be optimized + */ + bl _ThreadProcessSignalsFromIrq + b exitit + +schedule: + /* + * the scratch registers have already been saved and we are already + * back on the thread system stack. So we can call _Thread_Displatch + * directly + */ + bl _Thread_Dispatch + /* + * fall through exit to restore complete contex (scratch registers + * eip, CS, Flags). + */ +exitit: + b AckControler /* BSP specific function to ack PIC */ + + .globl ReturnFromAck +ReturnFromAck : + ldmia sp!, {r0-r3,r12,r14} /* restore regs from SVC stack */ + msr cpsr, r5 /* switch back to INT mode */ + ldmia sp!, {r4,r5,lr} /* restore regs from INT stack */ + subs pc,r14,#4 /* return */ + diff --git a/c/src/lib/libbsp/arm/shared/irq/irq_init.c b/c/src/lib/libbsp/arm/shared/irq/irq_init.c new file mode 100644 index 0000000000..a815657f8d --- /dev/null +++ b/c/src/lib/libbsp/arm/shared/irq/irq_init.c @@ -0,0 +1,51 @@ +/* irq_init.c + * + * This file contains the implementation of rtems initialization + * related to interrupt handling. + * + * CopyRight (C) 2000 Canon Research Centre France SA. + * Emmanuel Raguet, mailto:raguet@crf.canon.fr + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.OARcorp.com/rtems/license.html. + * + * $Id$ + */ + +#include +#include +#include +#include + +/* + * default int vector + */ +extern void _ISR_Handler(); + +void default_int_handler() +{ + printk("raw_idt_notify has been called \n"); +} + +void rtems_irq_mngt_init() +{ + int i; + long *vectorTable; + + vectorTable = VECTOR_TABLE; + + _CPU_ISR_Disable(level); + + /* First, connect the ISR_Handler for IRQ and FIQ interrupts */ + _CPU_ISR_install_vector(ARM_EXCEPTION_IRQ, _ISR_Handler, NULL); + _CPU_ISR_install_vector(ARM_EXCEPTION_FIQ, _ISR_Handler, NULL); + + /* Initialize the vector table contents with default handler */ + for (i=0; i