diff options
author | Ralf Corsepius <ralf.corsepius@rtems.org> | 2007-04-25 12:50:25 +0000 |
---|---|---|
committer | Ralf Corsepius <ralf.corsepius@rtems.org> | 2007-04-25 12:50:25 +0000 |
commit | f4392b88bb0e38c0b4a1e586dfc6502edde6be92 (patch) | |
tree | 41a1365abe91faad8de6875ff1beac5dab88d8ed /c/src/lib/libbsp/arm/rtl22xx | |
parent | Fixup CVS Ids. (diff) | |
download | rtems-f4392b88bb0e38c0b4a1e586dfc6502edde6be92.tar.bz2 |
2007-04-25 Ray Xu <xr@trasin.net>
* Makefile.am, README, bsp_specs, configure.ac,
console/lpc22xx_uart.h, console/uart.c, include/bsp.h,
network/network.c: New (Initial submission).
Diffstat (limited to 'c/src/lib/libbsp/arm/rtl22xx')
-rw-r--r-- | c/src/lib/libbsp/arm/rtl22xx/ChangeLog | 5 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/rtl22xx/Makefile.am | 116 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/rtl22xx/README | 6 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/rtl22xx/bsp_specs | 12 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/rtl22xx/configure.ac | 23 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/rtl22xx/console/lpc22xx_uart.h | 88 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/rtl22xx/console/uart.c | 374 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/rtl22xx/include/bsp.h | 152 | ||||
-rw-r--r-- | c/src/lib/libbsp/arm/rtl22xx/network/network.c | 126 |
9 files changed, 902 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/arm/rtl22xx/ChangeLog b/c/src/lib/libbsp/arm/rtl22xx/ChangeLog new file mode 100644 index 0000000000..4d00d2ee0f --- /dev/null +++ b/c/src/lib/libbsp/arm/rtl22xx/ChangeLog @@ -0,0 +1,5 @@ +2007-04-25 Ray Xu <xr@trasin.net> + + * Makefile.am, README, bsp_specs, configure.ac, + console/lpc22xx_uart.h, console/uart.c, include/bsp.h, + network/network.c: New (Initial submission). diff --git a/c/src/lib/libbsp/arm/rtl22xx/Makefile.am b/c/src/lib/libbsp/arm/rtl22xx/Makefile.am new file mode 100644 index 0000000000..f325b8bc98 --- /dev/null +++ b/c/src/lib/libbsp/arm/rtl22xx/Makefile.am @@ -0,0 +1,116 @@ +## +## $Id$ +## + +ACLOCAL_AMFLAGS = -I ../../../../aclocal + +include $(top_srcdir)/../../../../automake/compile.am +include $(top_srcdir)/../../bsp.am + +dist_project_lib_DATA = bsp_specs + +include_HEADERS = include/bsp.h +include_HEADERS += include/tm27.h + +nodist_include_HEADERS = include/bspopts.h +DISTCLEANFILES = include/bspopts.h + +noinst_PROGRAMS = + +nodist_include_HEADERS += ../../shared/include/coverhd.h + +EXTRA_DIST = start/start.S +start.$(OBJEXT): start/start.S + $(CPPASCOMPILE) -DASM -o $@ -c $< +project_lib_DATA = start.$(OBJEXT) + +dist_project_lib_DATA += startup/linkcmds + +noinst_PROGRAMS += startup.rel +include_HEADERS += ../../arm/shared/comm/uart.h +startup_rel_SOURCES = ../../shared/bsplibc.c ../../shared/bsppost.c \ + startup/bspstart.c startup/exit.c ../../shared/bootcard.c \ + ../../shared/main.c ../../shared/sbrk.c \ + ../../shared/gnatinstallhandler.c +startup_rel_CPPFLAGS = $(AM_CPPFLAGS) +startup_rel_LDFLAGS = $(RTEMS_RELLDFLAGS) + + +noinst_PROGRAMS += console.rel +console_rel_SOURCES = console/uart.c ../../shared/console.c +console_rel_CPPFLAGS = $(AM_CPPFLAGS) +console_rel_LDFLAGS = $(RTEMS_RELLDFLAGS) + + + +if HAS_NETWORKING +network_CPPFLAGS = -D__INSIDE_RTEMS_BSD_TCPIP_STACK__ +noinst_PROGRAMS += network.rel +network_rel_SOURCES = network/network.c +network_rel_CPPFLAGS = $(AM_CPPFLAGS) $(network_CPPFLAGS) +network_rel_LDFLAGS = $(RTEMS_RELLDFLAGS) +endif + +noinst_LIBRARIES = libbsp.a +libbsp_a_SOURCES = +libbsp_a_LIBADD = startup.rel console.rel +if HAS_NETWORKING +libbsp_a_LIBADD += network.rel +endif + +libbsp_a_LIBADD += \ + ../../../libcpu/@RTEMS_CPU@/@RTEMS_CPU_MODEL@/clock.rel \ + ../../../libcpu/@RTEMS_CPU@/@RTEMS_CPU_MODEL@/timer.rel \ + ../../../libcpu/@RTEMS_CPU@/@RTEMS_CPU_MODEL@/irq.rel + +all-local: $(PREINSTALL_FILES) $(TMPINSTALL_FILES) + +PREINSTALL_DIRS = +PREINSTALL_FILES = +TMPINSTALL_FILES = + +$(PROJECT_INCLUDE)/$(dirstamp): + @$(mkdir_p) $(PROJECT_INCLUDE) + @: > $(PROJECT_INCLUDE)/$(dirstamp) +PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp) + +$(PROJECT_LIB)/$(dirstamp): + @$(mkdir_p) $(PROJECT_LIB) + @: > $(PROJECT_LIB)/$(dirstamp) +PREINSTALL_DIRS += $(PROJECT_LIB)/$(dirstamp) + +$(PROJECT_LIB)/bsp_specs: bsp_specs $(PROJECT_LIB)/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_LIB)/bsp_specs +PREINSTALL_FILES += $(PROJECT_LIB)/bsp_specs + +$(PROJECT_INCLUDE)/bsp.h: include/bsp.h $(PROJECT_INCLUDE)/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp.h + +$(PROJECT_INCLUDE)/tm27.h: include/tm27.h $(PROJECT_INCLUDE)/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/tm27.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/tm27.h + +$(PROJECT_INCLUDE)/bspopts.h: include/bspopts.h $(PROJECT_INCLUDE)/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bspopts.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bspopts.h + + +$(PROJECT_INCLUDE)/coverhd.h: ../../shared/include/coverhd.h $(PROJECT_INCLUDE)/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/coverhd.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/coverhd.h + +$(PROJECT_LIB)/start.$(OBJEXT): start.$(OBJEXT) $(PROJECT_LIB)/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_LIB)/start.$(OBJEXT) +TMPINSTALL_FILES += $(PROJECT_LIB)/start.$(OBJEXT) + +$(PROJECT_LIB)/linkcmds: startup/linkcmds $(PROJECT_LIB)/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_LIB)/linkcmds +PREINSTALL_FILES += $(PROJECT_LIB)/linkcmds + + +CLEANFILES = $(PREINSTALL_FILES) +DISTCLEANFILES += $(PREINSTALL_DIRS) +CLEANFILES += $(TMPINSTALL_FILES) + +include $(top_srcdir)/../../../../automake/local.am diff --git a/c/src/lib/libbsp/arm/rtl22xx/README b/c/src/lib/libbsp/arm/rtl22xx/README new file mode 100644 index 0000000000..f09312df3d --- /dev/null +++ b/c/src/lib/libbsp/arm/rtl22xx/README @@ -0,0 +1,6 @@ + +RTEMS bsp for Philips's ARM processor +This BSP is design for Philips's LPC2210/LPC2212/LPC2214/LPC2290/LPC2294 (LPC22xx) serial ARM processor. +Philphs's LPC22xx ARM processor got an ARM7TDMI-S core, and can run at 60MHz. It has an external memory bus, and peripherals like UART, I2C, SPI, ADC and etc. Some of them got on chip flash (256k) and CAN. +The board used to develop the board is compatible with LPC-E2214/LPC-E2294 boards from http://www.olimex.com. The board got a 256K SDRAM and two serial ports. +The license and distribution terms for this file may be found in the file LICENSE in this distribution or at http://www.rtems.com/license/LICENSE diff --git a/c/src/lib/libbsp/arm/rtl22xx/bsp_specs b/c/src/lib/libbsp/arm/rtl22xx/bsp_specs new file mode 100644 index 0000000000..86aa91f283 --- /dev/null +++ b/c/src/lib/libbsp/arm/rtl22xx/bsp_specs @@ -0,0 +1,12 @@ +%rename endfile old_endfile +%rename startfile old_startfile +%rename link old_link + +*startfile: +%{!qrtems: %(old_startfile)} %{qrtems: \ +%{!qrtems_debug: start.o%s crtbegin.o%s} \ +%{qrtems_debug: start_g.o%s crtbegin.o%s}} + +*link: +%{!qrtems: %(old_link)} %{qrtems: -Qy -dp -Bstatic -N -e _start} + diff --git a/c/src/lib/libbsp/arm/rtl22xx/configure.ac b/c/src/lib/libbsp/arm/rtl22xx/configure.ac new file mode 100644 index 0000000000..3d7ce47e9f --- /dev/null +++ b/c/src/lib/libbsp/arm/rtl22xx/configure.ac @@ -0,0 +1,23 @@ +## Process this file with autoconf to produce a configure script. +## +## $Id$ + +AC_PREREQ(2.59) +AC_INIT([rtems-c-src-lib-libbsp-arm-rtl22xx],[_RTEMS_VERSION],[rtems-bugs@rtems.com]) +AC_CONFIG_SRCDIR([bsp_specs]) +RTEMS_TOP(../../../../../..) + +RTEMS_CANONICAL_TARGET_CPU +AM_INIT_AUTOMAKE([no-define nostdinc foreign 1.9]) +RTEMS_BSP_CONFIGURE + +RTEMS_PROG_CC_FOR_TARGET([-fasm]) +RTEMS_CANONICALIZE_TOOLS +RTEMS_PROG_CCAS + +RTEMS_CHECK_NETWORKING +AM_CONDITIONAL(HAS_NETWORKING,test "$HAS_NETWORKING" = "yes") + +# Explicitly list all Makefiles here +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/c/src/lib/libbsp/arm/rtl22xx/console/lpc22xx_uart.h b/c/src/lib/libbsp/arm/rtl22xx/console/lpc22xx_uart.h new file mode 100644 index 0000000000..edd4916303 --- /dev/null +++ b/c/src/lib/libbsp/arm/rtl22xx/console/lpc22xx_uart.h @@ -0,0 +1,88 @@ +/*Define for LPC22xx*/
+#ifndef UART_H
+#define UART_H
+
+#define FIFODEEP 16
+
+#define BD115200 115200
+#define BD38400 38400
+#define BD9600 9600
+
+#define CR 0x0D
+#define LF 0x0A
+#define U0_PINSEL (0x00000005) /* PINSEL0 Value for UART0 */
+#define U0_PINMASK (0x0000000F) /* PINSEL0 Mask for UART0 */
+#define U1_PINSEL (0x00050000) /* PINSEL0 Value for UART1 */
+#define U1_PINMASK (0x000F0000) /* PINSEL0 Mask for UART1 */
+
+/* Uart line control register bit descriptions */
+#define LCR_WORDLENTH_BIT 0
+#define LCR_STOPBITSEL_BIT 2
+#define LCR_PARITYENBALE_BIT 3
+#define LCR_PARITYSEL_BIT 4
+#define LCR_BREAKCONTROL_BIT 6
+#define LCR_DLAB_BIT 7
+// Line Control Register bit definitions
+#define ULCR_CHAR_5 (0 << 0) // 5-bit character length
+#define ULCR_CHAR_6 (1 << 0) // 6-bit character length
+#define ULCR_CHAR_7 (2 << 0) // 7-bit character length
+#define ULCR_CHAR_8 (3 << 0) // 8-bit character length
+#define ULCR_STOP_0 (0 << 2) // no stop bits
+#define ULCR_STOP_1 (1 << 2) // 1 stop bit
+#define ULCR_PAR_NO (0 << 3) // No Parity
+#define ULCR_PAR_ODD (1 << 3) // Odd Parity
+#define ULCR_PAR_EVEN (3 << 3) // Even Parity
+#define ULCR_PAR_MARK (5 << 3) // MARK "1" Parity
+#define ULCR_PAR_SPACE (7 << 3) // SPACE "0" Paruty
+#define ULCR_BREAK_ENABLE (1 << 6) // Output BREAK line condition
+#define ULCR_DLAB_ENABLE (1 << 7) // Enable Divisor Latch Access
+// Modem Control Register bit definitions
+#define UMCR_DTR (1 << 0) // Data Terminal Ready
+#define UMCR_RTS (1 << 1) // Request To Send
+#define UMCR_LB (1 << 4) // Loopback
+
+// Line Status Register bit definitions
+#define ULSR_RDR (1 << 0) // Receive Data Ready
+#define ULSR_OE (1 << 1) // Overrun Error
+#define ULSR_PE (1 << 2) // Parity Error
+#define ULSR_FE (1 << 3) // Framing Error
+#define ULSR_BI (1 << 4) // Break Interrupt
+#define ULSR_THRE (1 << 5) // Transmit Holding Register Empty
+#define ULSR_TEMT (1 << 6) // Transmitter Empty
+#define ULSR_RXFE (1 << 7) // Error in Receive FIFO
+#define ULSR_ERR_MASK 0x1E
+
+// Modem Status Register bit definitions
+#define UMSR_DCTS (1 << 0) // Delta Clear To Send
+#define UMSR_DDSR (1 << 1) // Delta Data Set Ready
+#define UMSR_TERI (1 << 2) // Trailing Edge Ring Indicator
+#define UMSR_DDCD (1 << 3) // Delta Data Carrier Detect
+#define UMSR_CTS (1 << 4) // Clear To Send
+#define UMSR_DSR (1 << 5) // Data Set Ready
+#define UMSR_RI (1 << 6) // Ring Indicator
+#define UMSR_DCD (1 << 7) // Data Carrier Detect
+
+/* Uart Interrupt Identification */
+#define IIR_RSL 0x3
+#define IIR_RDA 0x2
+#define IIR_CTI 0x6
+#define IIR_THRE 0x1
+
+/* Uart Interrupt Enable Type*/
+#define IER_RBR 0x1
+#define IER_THRE 0x2
+#define IER_RLS 0x4
+
+/* Uart Receiver Errors*/
+#define RC_FIFO_OVERRUN_ERR 0x1
+#define RC_OVERRUN_ERR 0x2
+#define RC_PARITY_ERR 0x4
+#define RC_FRAMING_ERR 0x8
+#define RC_BREAK_IND 0x10
+
+typedef enum {
+ UART0 = 0,
+ UART1
+} LPC_UartChanel_t;
+#endif
+
diff --git a/c/src/lib/libbsp/arm/rtl22xx/console/uart.c b/c/src/lib/libbsp/arm/rtl22xx/console/uart.c new file mode 100644 index 0000000000..5901db3782 --- /dev/null +++ b/c/src/lib/libbsp/arm/rtl22xx/console/uart.c @@ -0,0 +1,374 @@ +/* + * console driver for RTL22xx UARTs + * + * This driver uses the shared console driver in + * ...../libbsp/shared/console.c + * + * If you want the driver to be interrupt driven, you + * need to write the ISR, and in the ISR insert the + * chars into termios's queue. + * Copyright (c) By ray + * + * 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. + * + * +*/ +#include <bsp.h> /* Must be before libio.h */ +#include <rtems/libio.h> +#include <termios.h> +#include <rtems/bspIo.h> + +/* Put the CPU (or UART) specific header file #include here */ +#include <lpc22xx.h> +#include "lpc22xx_uart.h" + +#include <libchip/serial.h> +#include <libchip/sersupp.h> + +/* How many serial ports? */ +#define NUM_DEVS 1 + +int uart_poll_read(int minor); + +int dbg_dly; + +/* static function prototypes */ +static int uart_first_open(int major, int minor, void *arg); +static int uart_last_close(int major, int minor, void *arg); +static int uart_read(int minor); +static int uart_write(int minor, const char *buf, int len); +static void uart_init(int minor); +static void uart_write_polled(int minor, char c); +static int uart_set_attributes(int minor, const struct termios *t); + +/* These are used by code in console.c */ +unsigned long Console_Port_Count = NUM_DEVS; +console_data Console_Port_Data[NUM_DEVS]; + +/* rtems console uses the following minor number */ +rtems_device_minor_number Console_Port_Minor = 0; + +/* Pointers to functions for handling the UART. */ +console_fns uart_fns = +{ + libchip_serial_default_probe, + uart_first_open, + uart_last_close, + uart_read, + uart_write, + uart_init, + uart_write_polled, /* not used in this driver */ + uart_set_attributes, + FALSE /* TRUE if interrupt driven, FALSE if not. */ +}; + +/* + * There's one item in array for each UART. + * + * Some of these fields are marked "NOT USED". They are not used + * by console.c, but may be used by drivers in libchip + * + */ +console_tbl Console_Port_Tbl[] = { + { + "/dev/console", /* sDeviceName */ + SERIAL_CUSTOM, /* deviceType */ + &uart_fns, /* pDeviceFns */ + NULL, /* deviceProbe */ + NULL, /* pDeviceFlow */ + 0, /* ulMargin - NOT USED */ + 0, /* ulHysteresis - NOT USED */ + NULL, /* pDeviceParams */ + 0, /* ulCtrlPort1 - NOT USED */ + 0, /* ulCtrlPort2 - NOT USED */ + 0, /* ulDataPort - NOT USED */ + NULL, /* getRegister - NOT USED */ + NULL, /* setRegister - NOT USED */ + NULL, /* getData - NOT USED */ + NULL, /* setData - NOT USED */ + 0, /* ulClock - NOT USED */ + 0 /* ulIntVector - NOT USED */ + } + #if 0 + { + "/dev/com1", /* sDeviceName */ + SERIAL_CUSTOM, /* deviceType */ + &uart_fns, /* pDeviceFns */ + NULL, /* deviceProbe */ + NULL, /* pDeviceFlow */ + 0, /* ulMargin - NOT USED */ + 0, /* ulHysteresis - NOT USED */ + NULL, /* pDeviceParams */ + 0, /* ulCtrlPort1 - NOT USED */ + 0, /* ulCtrlPort2 - NOT USED */ + 0, /* ulDataPort - NOT USED */ + NULL, /* getRegister - NOT USED */ + NULL, /* setRegister - NOT USED */ + NULL, /* getData - NOT USED */ + NULL, /* setData - NOT USED */ + 0, /* ulClock - NOT USED */ + 0 /* ulIntVector - NOT USED */ + } + #endif +}; + +/*********************************************************************/ +/* Functions called via termios callbacks (i.e. the ones in uart_fns */ +/*********************************************************************/ + +/* + * This is called the first time each device is opened. If the driver + * is interrupt driven, you should enable interrupts here. Otherwise, + * it's probably safe to do nothing. + * + * Since micromonitor already set up the UART, we do nothing. + */ +static int uart_first_open(int major, int minor, void *arg) +{ + return 0; +} + + +/* + * This is called the last time each device is closed. If the driver + * is interrupt driven, you should disable interrupts here. Otherwise, + * it's probably safe to do nothing. + */ +static int uart_last_close(int major, int minor, void *arg) +{ + return 0; +} + + +/* + * Read one character from UART. + * + * Return -1 if there's no data, otherwise return + * the character in lowest 8 bits of returned int. + */ +static int uart_read(int minor) +{ + char c; + + if (minor == 0) { + if(U0LSR & ULSR_RDR) { + c = U0RBR; + return c; + } else { + return -1; + } + } else if (minor == 1) { + if (U1LSR & ULSR_RDR) { + c = U1RBR; + return c; + } else { + return -1; + } + } else { + printk("Unknown console minor number: %d\n", minor); + return -1; + } + +} + + +/* + * Write buffer to UART + * + * return 1 on success, -1 on error + */ +static int uart_write(int minor, const char *buf, int len) +{ + int i; + + if (minor == 0) { + for (i = 0; i < len; i++) { + while(!(U0LSR & ULSR_THRE)) /* wait for TX buffer to empty*/ + continue; /* also either WDOG() or swap()*/ + U0THR = (char) buf[i]; + } + } else if (minor == 1) { + for (i = 0; i < len; i++) { + while(!(U0LSR & ULSR_THRE)) /* wait for TX buffer to empty*/ + continue; /* also either WDOG() or swap()*/ + U0THR = (char) buf[i]; + } + }else { + printk("Unknown console minor number: %d\n", minor); + return -1; + } + + return 1; +} + + +/* Set up the UART. */ +static void uart_init(int minor) +{ +#if 0 //init will be done in bspstart.c + int baud=6; + int mode =0x03; + if(minor==0){ + // set port pins for UART0 + PINSEL0 = (PINSEL0 & ~U0_PINMASK) | U0_PINSEL; + + U0IER = 0x00; // disable all interrupts + + // set the baudrate + U0LCR = 1<<7; // select divisor latches + U0DLL = (uint8_t)baud; // set for baud low byte + U0DLM = (uint8_t)(baud >> 8); // set for baud high byte + + // set the number of characters and other + // user specified operating parameters + U0LCR = (mode & ~ULCR_DLAB_ENABLE); + U0FCR = mode>>8; /*fifo mode*/ + + // set port pins for UART1 + PINSEL0 = (PINSEL0 & ~U1_PINMASK) | U1_PINSEL; + + U1IER = 0x00; // disable all interrupts + }else if(minor==1){ + // set the baudrate + U1LCR = ULCR_DLAB_ENABLE; // select divisor latches + U1DLL = (uint8_t)baud; // set for baud low byte + U1DLM = (uint8_t)(baud >> 8); // set for baud high byte + + // set the number of characters and other + // user specified operating parameters + U1LCR = (mode & ~ULCR_DLAB_ENABLE); + U1FCR = mode>>8;/*fifo mode*/ + } + +#endif +} + +/* I'm not sure this is needed for the shared console driver. */ +static void uart_write_polled(int minor, char c) +{ + uart_write(minor, &c, 1); +} + +/* This is for setting baud rate, bits, etc. */ +static int uart_set_attributes(int minor, const struct termios *t) +{ + return 0; +} + +/***********************************************************************/ +/* + * The following functions are not used by TERMIOS, but other RTEMS + * functions use them instead. + */ +/***********************************************************************/ +/* + * Read from UART. This is used in the exit code, and can't + * rely on interrupts. +*/ +int uart_poll_read(int minor) +{ + return uart_read(minor); +} + + +/* + * Write a character to the console. This is used by printk() and + * maybe other low level functions. It should not use interrupts or any + * RTEMS system calls. It needs to be very simple + */ +static void _BSP_put_char( char c ) { + uart_write_polled(0, c); + if (c == '\n') { + uart_write_polled(0, '\r'); + } +} + +BSP_output_char_function_type BSP_output_char = _BSP_put_char; + + + + +/**************************************************************************** +* init USART 0。8 bit, 1 Stop,No checkout, BPS115200 +****************************************************************************/ +void UART0_Ini(void) +{ + long Fdiv; + int i; + PINSEL0 = 0x00000005; // I/O to UART0 + U0LCR = 0x83; // DLAB = 1 + Fdiv = (Fpclk >>4) / UART_BPS; // configure BPS + U0DLM = Fdiv/256; + U0DLL = Fdiv%256; + U0LCR = 0x03; + + for(i=0;i<10;i++){ + U0THR = 67; //send a C to see if is OK + while( (U0LSR&0x40)==0 ); + } +} + + +/**************************************************************************** +*Send a Byte +****************************************************************************/ +void UART0_SendByte(char data) +{ + U0THR = data; + + while( (U0LSR&0x40)==0 ); +} + + +/**************************************************************************** +*Send a string +****************************************************************************/ +void UART0_SendStr(char const *str) +{ while(1) + { if( *str == '\0' ) break; + UART0_SendByte(*str++); // Send the char + } +} + +debug_printk(char *dg_str) +{ + UART0_SendStr(dg_str); + UART0_SendStr("\r\n"); +} + +void printi(unsigned long value) +{ + static char istring[9]={0,0,0,0,0,0,0,0,0}; + static char tmp[9]={0,0,0,0,0,0,0,0,0}; + char *sp; + char *tp = tmp; + + long i; + unsigned long v = value; + int index; + + for(index=0;index<9;index++) + istring[index]=tmp[index]=0x0; + + while (v || tp == tmp) + { + i = v % 16; + v = v / 16; + if (i < 10) + *tp++ = i+'0'; + else + *tp++ = i + 'a' - 10; + } + + sp = istring; + while (tp > tmp) + *sp++ = *--tp; + + tp=tmp; + sp=istring; + debug_printk(istring); + +} diff --git a/c/src/lib/libbsp/arm/rtl22xx/include/bsp.h b/c/src/lib/libbsp/arm/rtl22xx/include/bsp.h new file mode 100644 index 0000000000..0d85742e73 --- /dev/null +++ b/c/src/lib/libbsp/arm/rtl22xx/include/bsp.h @@ -0,0 +1,152 @@ +/* + * Philips LPC22XX BSP header file + * + * by Ray,Xu + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * + * http://www.rtems.com/license/LICENSE. + * + * + * $Id$ +*/ +#ifndef _BSP_H +#define _BSP_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <bspopts.h> + +#include <rtems.h> +#include <rtems/iosupp.h> +#include <rtems/console.h> +#include <rtems/clockdrv.h> + + +#define CONFIG_ARM_CLK 60000000L +/* cclk=cco/(2*P) */ +/* cco = cclk*2*P */ + +#define LPC22xx_Fcclk CONFIG_ARM_CLK /* system clk frequecy,<=60Mhz, defined in system configuration */ + +/* Fcco 156M~320Mhz*/ +#define LPC22xx_Fcclk CONFIG_ARM_CLK /* system clk frequecy,<=60Mhz, defined in system configuration */ +#define LPC22xx_Fcco LPC22xx_Fcclk * 4 +#define LPC22xx_Fpclk (LPC22xx_Fcclk /4) *1 /*VPB clk frequency,1,1/2,1/4 times of Fcclk */ + + + +/* Fcclk range: 10MHz ~ MCU allowed frequency */ +#define Fcclk_MIN 10000000L +#define Fcclk_MAX 60000000L + +/* Fcco range: 156MHz ~ 320MHz */ +#define Fcco_MIN 156000000L +#define Fcco_MAX 320000000L + +#define PLLFEED_DATA1 0xAA +#define PLLFEED_DATA2 0x55 + +/* PLL PLLCON register bit descriptions */ +#define PLLCON_ENABLE_BIT 0 +#define PLLCON_CONNECT_BIT 1 + +/* PLL PLLSTAT register bit descriptions */ +#define PLLSTAT_ENABLE_BIT 8 +#define PLLSTAT_CONNECT_BIT 9 +#define PLLSTAT_LOCK_BIT 10 + +/* PM Peripheral Type */ +#define PC_TIMER0 0x2 +#define PC_TIMER1 0x4 +#define PC_UART0 0x8 +#define PC_UART1 0x10 +#define PC_PWM0 0x20 +#define PC_I2C 0x80 +#define PC_SPI0 0x100 +#define PC_RTC 0x200 + +// OSC [Hz] +#define FOSC 11059200 +// Core clk [Hz] +#define FCCLK FOSC<<2 +/** +* help file +*/ +/* 系统设置, Fosc、Fcclk、Fcco、Fpclk必须定义*/ +#define Fosc 11059200 //晶振频率,10MHz~25MHz,应当与实际一至 +#define Fcclk (Fosc << 2) //系统频率,必须为Fosc的整数倍(1~32),且<=60MHZ +#define Fcco (Fcclk <<2) //CCO频率,必须为Fcclk的2、4、8、16倍,范围为156MHz~320MHz +#define Fpclk (Fcclk >>2) * 1 //VPB时钟频率,只能为(Fcclk / 4)的1 ~ 4倍 +#define M Fcclk / Fosc; +#define P_min Fcco_MIN / (2*Fcclk) + 1; +#define P_max Fcco_MAX / (2*Fcclk); + + + +#define UART_BPS 115200 + +// Time Precision time [us] +#define TIMER_PRECISION 10 + +// I2C Speed [bit/s] +#define I2CSPEED 20000 // 20 Kbit/s + +// Uarts buffers size +#define RXBUFSIZE 32 +#define TXBUFSIZE 32 + +// SPI Speed [bit/s] +#define SPISPEED 1500000 // 1.5 Mbit/s +// SPI EEPROM CS pin (SSEL is not suitable for CS, because is used by SPI module for multi master SPI interface) +#define SPI_CS_PIN P0_13 +#define SPI_CS_PIN_FUNC PINSEL0_bit.SPI_CS_PIN + +// Flash definition +//#define FLASH_SIZE (0x200000-FLASH_BOOT) // Total area of Flash region in words 8 bit +#define FLASH_SIZE (0x80000-FLASH_BOOT) // Total area of Flash region in words 8 bit +//#define FLASH_SIZE (0x80000-FLASH_BOOT) // Total area of Flash region in words 8 bit +#define FLASH_BEGIN 0x80000000 +#define FLASH_BASE (FLASH_BEGIN+FLASH_BOOT) //First 0x8000 bytes reserved for boot loader etc. + +// SRAM definition +#define SRAM_SIZE 0x100000 // Total area of Flash region in words 8 bit +#define SRAM_BASE 0x81000000 //First 0x8000 bytes reserved for boot loader etc. + +// CS8900A definition +#define CS8900A_BASE 0x82000000 // +// RTL8019AS definition +#define RTL8019AS_BASE 0x82000000 // + + + + +/* + * Define the interrupt mechanism for Time Test 27 + * + * NOTE: Following are not defined and are board independent + * + */ +struct rtems_bsdnet_ifconfig; +int cs8900_driver_attach (struct rtems_bsdnet_ifconfig *config, + int attaching); + +#define CONFIGURE_NUMBER_OF_TERMIOS_PORTS 2 +#define CONFIGURE_INTERRUPT_STACK_MEMORY (1 * 1024) + +extern rtems_configuration_table BSP_Configuration; + +/* + * Network driver configuration + */ +#define RTEMS_BSP_NETWORK_DRIVER_NAME "eth0" +#define RTEMS_BSP_NETWORK_DRIVER_ATTACH cs8900_driver_attach + +#ifdef __cplusplus +} +#endif + +#endif /* _BSP_H */ diff --git a/c/src/lib/libbsp/arm/rtl22xx/network/network.c b/c/src/lib/libbsp/arm/rtl22xx/network/network.c new file mode 100644 index 0000000000..b9917ea45e --- /dev/null +++ b/c/src/lib/libbsp/arm/rtl22xx/network/network.c @@ -0,0 +1,126 @@ +/*Note: this file is copy from 7312 BSP, and untested yet*/ +#include <rtems.h> +#include <sys/mbuf.h> +#include <irq.h> +#include <libchip/cs8900.h> + +#define CS8900_BASE 0x20000300 +unsigned int bsp_cs8900_io_base = 0; +unsigned int bsp_cs8900_memory_base = 0; +cs8900_device *g_cs; +rtems_isr cs8900_isr(rtems_vector_number v); +rtems_irq_connect_data cs8900_isr_data = {LPC22xx_INTERRUPT_EINT2, + (rtems_irq_hdl)cs8900_isr, + NULL, + NULL, + NULL, + 0, + 0 }; + +char g_enetbuf[1520]; + +rtems_isr cs8900_isr(rtems_vector_number v) +{ + cs8900_interrupt(v, g_cs); +} + +/* cs8900_io_set_reg - set one of the I/O addressed registers */ +void cs8900_io_set_reg (cs8900_device *cs, unsigned short reg, unsigned short data) +{ + /* works the same for all values of dev */ +/* + printf("cs8900_io_set_reg: reg: %#6x, val %#6x\n", + CS8900_BASE + reg, + data); +*/ + *(unsigned short *)(CS8900_BASE + reg) = data; +} + +/* cs8900_io_get_reg - reads one of the I/O addressed registers */ +unsigned short cs8900_io_get_reg (cs8900_device *cs, unsigned short reg) +{ + unsigned short val; + /* works the same for all values of dev */ + val = *(unsigned short *)(CS8900_BASE + reg); +/* + printf("cs8900_io_get_reg: reg: %#6x, val %#6x\n", reg, val); +*/ + return val; +} + +/* cs8900_mem_set_reg - sets one of the registers mapped through + * PacketPage + */ +void cs8900_mem_set_reg (cs8900_device *cs, unsigned long reg, unsigned short data) +{ + /* works the same for all values of dev */ + cs8900_io_set_reg(cs, CS8900_IO_PACKET_PAGE_PTR, reg); + cs8900_io_set_reg(cs, CS8900_IO_PP_DATA_PORT0, data); +} + +/* cs8900_mem_get_reg - reads one of the registers mapped through + * PacketPage + */ +unsigned short cs8900_mem_get_reg (cs8900_device *cs, unsigned long reg) +{ + /* works the same for all values of dev */ + cs8900_io_set_reg(cs, CS8900_IO_PACKET_PAGE_PTR, reg); + return cs8900_io_get_reg(cs, CS8900_IO_PP_DATA_PORT0); +} + +void cs8900_get_mac_addr (cs8900_device *cs, unsigned char *mac_address) +{ + mac_address[0] = 0x08; + mac_address[1] = 0x00; + mac_address[2] = 0x3e; + mac_address[3] = 0x21; + mac_address[4] = 0xc7; + mac_address[5] = 0xf7; +} + +void cs8900_attach_interrupt (cs8900_device *cs) +{ + g_cs = cs; + BSP_install_rtems_irq_handler(&cs8900_isr_data); +} + +void cs8900_detach_interrupt (cs8900_device *cs) +{ + BSP_remove_rtems_irq_handler(&cs8900_isr_data); +} + +unsigned short cs8900_get_data_block (cs8900_device *cs, unsigned char *data) +{ + int len; + int i; + + len = cs8900_mem_get_reg(cs, CS8900_PP_RxLength); + + for (i = 0; i < ((len + 1) / 2); i++) { + ((short *)data)[i] = cs8900_io_get_reg(cs, + CS8900_IO_RX_TX_DATA_PORT0); + } + return len; +} + +void cs8900_tx_load (cs8900_device *cs, struct mbuf *m) +{ + int len; + unsigned short *data; + int i; + + len = 0; + + do { + memcpy(&g_enetbuf[len], mtod(m, const void *), m->m_len); + len += m->m_len; + m = m->m_next; + } while (m != 0); + + data = (unsigned short *) &g_enetbuf[0]; + for (i = 0; i < ((len + 1) / 2); i++) { + cs8900_io_set_reg(cs, + CS8900_IO_RX_TX_DATA_PORT0, + data[i]); + } +} |