diff options
Diffstat (limited to '')
28 files changed, 2389 insertions, 0 deletions
diff --git a/c/src/lib/libbsp/arm/tms570/Makefile.am b/c/src/lib/libbsp/arm/tms570/Makefile.am new file mode 100644 index 0000000000..02d7b666eb --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/Makefile.am @@ -0,0 +1,145 @@ +## +# +# @file makefile.am +# +# @brief Makefile of LibBSP for the TMS570 boards. +# + +ACLOCAL_AMFLAGS = -I ../../../../aclocal + +include $(top_srcdir)/../../../../automake/compile.am + +include_bspdir = $(includedir)/bsp + +dist_project_lib_DATA = bsp_specs + +# ---------------------------- +# ------ Headers +# ---------------------------- + +include_HEADERS = include/bsp.h + +nodist_include_HEADERS = ../../shared/include/coverhd.h +nodist_include_HEADERS += include/bspopts.h + +nodist_include_bsp_HEADERS = ../../shared/include/bootcard.h + +include_bsp_HEADERS = +include_bsp_HEADERS += ../../shared/include/utility.h +include_bsp_HEADERS += ../../shared/include/irq-generic.h +include_bsp_HEADERS += ../../shared/include/irq-info.h +include_bsp_HEADERS += ../../shared/include/stackalloc.h +include_bsp_HEADERS += ../../shared/include/uart-output-char.h +include_bsp_HEADERS += ../../shared/tod.h +include_bsp_HEADERS += ../shared/include/start.h +include_bsp_HEADERS += include/tms570.h +include_bsp_HEADERS += include/tms570-sci.h +include_bsp_HEADERS += include/irq.h +include_bsp_HEADERS += include/tms570-rti.h +include_bsp_HEADERS += include/tms570-vim.h +include_bsp_HEADERS += include/tms570-pom.h +include_bsp_HEADERS += include/tms570-sci-driver.h + +include_HEADERS += ../../shared/include/tm27.h + +# ---------------------------- +# ------ Data +# ---------------------------- + +noinst_LIBRARIES = libbspstart.a + +libbspstart_a_SOURCES = ../shared/start/start.S + +project_lib_DATA = start.$(OBJEXT) +project_lib_DATA += startup/linkcmds + +EXTRA_DIST = +EXTRA_DIST += startup/linkcmds.tms570ls3137_hdk +EXTRA_DIST += startup/linkcmds.tms570ls3137_hdk_sdram +EXTRA_DIST += startup/linkcmds.tms570ls3137_hdk_intram + +# ---------------------------- +# ------ LibBSP +# ---------------------------- + +noinst_LIBRARIES += libbsp.a + +libbsp_a_SOURCES = +libbsp_a_CPPFLAGS = +libbsp_a_LIBADD = + +# Shared +libbsp_a_SOURCES += ../../shared/bootcard.c +libbsp_a_SOURCES += ../../shared/bspclean.c +libbsp_a_SOURCES += ../../shared/bspgetworkarea.c +libbsp_a_SOURCES += ../../shared/bsplibc.c +libbsp_a_SOURCES += ../../shared/bsppost.c +libbsp_a_SOURCES += ../../shared/bsppredriverhook.c +libbsp_a_SOURCES += ../../shared/gnatinstallhandler.c +libbsp_a_SOURCES += ../../shared/sbrk.c +libbsp_a_SOURCES += ../../shared/src/stackalloc.c + +# Startup +libbsp_a_SOURCES += ../shared/startup/bsp-start-memcpy.S +libbsp_a_SOURCES += ../../shared/bsppretaskinghook.c +libbsp_a_SOURCES += startup/bspreset.c +libbsp_a_SOURCES += startup/bspstart.c + +# POM +libbsp_a_SOURCES += pom/tms570-pom.c + +# IRQ +libbsp_a_SOURCES += ../../shared/src/irq-default-handler.c +libbsp_a_SOURCES += ../../shared/src/irq-generic.c +libbsp_a_SOURCES += ../../shared/src/irq-info.c +libbsp_a_SOURCES += ../../shared/src/irq-legacy.c +libbsp_a_SOURCES += ../../shared/src/irq-server.c +libbsp_a_SOURCES += ../../shared/src/irq-shell.c +libbsp_a_SOURCES += irq/irq.c + +# Console +libbsp_a_SOURCES += ../../shared/console-termios.c +libbsp_a_SOURCES += console/printk-support.c +libbsp_a_SOURCES += console/tms570-sci.c + +# Clock +libbsp_a_SOURCES += ../../shared/clockdrv_shell.h +libbsp_a_SOURCES += clock/clock.c + +# RTC + +# GPIO + +# Timer + +# Benchmark Timer + +# Misc + +# Watchdog + +# Start hooks +libbsp_a_SOURCES += startup/bspstarthooks.c + +# Network + +if HAS_NETWORKING + +noinst_PROGRAMS = network.rel + +network_rel_CPPFLAGS = $(AM_CPPFLAGS) +network_rel_CPPFLAGS += -D__INSIDE_RTEMS_BSD_TCPIP_STACK__ -D__BSD_VISIBLE +network_rel_LDFLAGS = $(RTEMS_RELLDFLAGS) + +libbsp_a_LIBADD += network.rel + +endif + +# ---------------------------- +# ------ Special Rules +# ---------------------------- + +DISTCLEANFILES = include/bspopts.h + +include $(srcdir)/preinstall.am +include $(top_srcdir)/../../../../automake/local.am diff --git a/c/src/lib/libbsp/arm/tms570/README b/c/src/lib/libbsp/arm/tms570/README new file mode 100644 index 0000000000..e1be925395 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/README @@ -0,0 +1,67 @@ +Development Board: TMS570LS31x Hercules Development Kit from TI + +http://www.ti.com/tool/tmds570ls31hdk + +Drivers: + + o Console + o Clock + o Ethernet - work in progress + +BSP variants: + tms570ls3137_hdk_intram - place code and data into internal SRAM + tms570ls3137_hdk_sdram - place code into external SDRAM and data to SRAM + tms570ls3137_hdk - variant prepared for stand-alone RTEMS application + stored and running directly from flash. Not working yet. + +Tool-chain + GCC 4.9.0 + Newlib 2.1.0 + Binutils 2.24 configuration: + + CFLAGS="-O2 -pipe" LDFLAGS=-s \ + ../../../src/gcc-4.9/configure --target=arm-rtems4.11 --prefix=/usr \ + --enable-languages=c,c++ \ + --disable-libstdcxx-pch \ + --with-gnu-ld \ + --with-gnu-as \ + --enable-threads \ + --enable-target-optspace \ + --with-system-zlib \ + --verbose \ + --disable-nls --without-included-gettext \ + --disable-win32-registry \ + --with-newlib \ + --enable-plugin \ + --enable-newlib-io-c99-formats \ + --enable-version-specific-runtime-libs \ + --enable-newlib-iconv \ + --disable-lto \ + +Patches required for Cortex-R and big-endian ARM support are already +accepted by the mainline. + +Execution + +Currently, a bootloader is not used. For test and debug purposes, TI's +HalCoGen generated application is used to set up the board and then +the RTEMS application image is loaded using OpenOCD to internal +EEC SRAM or external DRAM. The following features are +not implemented in the BSP: + + + Initial complex CPU and peripheral initialization + + Cores Self-test + +Setup application code is available there: + https://github.com/hornmich/tms570ls3137-hdk-sdram + +Howto setup TMDS570LS31HDK? + + o Unpack board. + o Verify that demo application runs. + o Upload bootloader specified above + o write BSP application either to sdram or intram and jump to RTEMS start code + +Additional information about the board can be found at + http://www.rtems.org/wiki/index.php/Tms570 + +Additional information about the CPU can be found at + http://www.ti.com/product/tms570ls3137 diff --git a/c/src/lib/libbsp/arm/tms570/bsp_specs b/c/src/lib/libbsp/arm/tms570/bsp_specs new file mode 100644 index 0000000000..1afa2ba72e --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/bsp_specs @@ -0,0 +1,13 @@ +%rename endfile old_endfile +%rename startfile old_startfile +%rename link old_link + +*startfile: +%{!qrtems: %(old_startfile)} \ +%{!nostdlib: %{qrtems: start.o%s crti.o%s crtbegin.o%s -e _start}} + +*link: +%{!qrtems: %(old_link)} %{qrtems: -dc -dp -N -EB } + +*endfile: +%{!qrtems: *(old_endfiles)} %{qrtems: crtend.o%s crtn.o%s } diff --git a/c/src/lib/libbsp/arm/tms570/clock/clock.c b/c/src/lib/libbsp/arm/tms570/clock/clock.c new file mode 100644 index 0000000000..2a8bb5f4a6 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/clock/clock.c @@ -0,0 +1,159 @@ +/** + * @file clock.c + * + * @ingroup tms570 + * + * @brief clock functions definitions. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * by embedded brains GmbH and others + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <stdlib.h> + +#include <rtems.h> +#include <bsp.h> +#include <bsp/irq.h> +#include <bsp/tms570-rti.h> + +/** + * holds HW counter value since last interrupt event + * sets in tms570_clock_driver_support_at_tick + * used in tms570_clock_driver_nanoseconds_since_last_tick + */ +static uint32_t tms570_rti_last_tick_fcr0; + +/** + * @brief Initialize the HW peripheral for clock driver + * + * Clock driver is implemented by RTI module + * + * @retval Void + */ +static void tms570_clock_driver_support_initialize_hardware( void ) +{ + + uint32_t microsec_per_tick = rtems_configuration_get_microseconds_per_tick(); + + /* Hardware specific initialize */ + TMS570_RTI.RTIGCTRL = 0; + TMS570_RTI.RTICPUC0 = BSP_PLL_OUT_CLOCK /1000000 / 2; /* prescaler */ + TMS570_RTI.RTITBCTRL = 2; + TMS570_RTI.RTICAPCTRL = 0; + TMS570_RTI.RTICOMPCTRL = 0; + /* set counter to zero */ + TMS570_RTI.RTIUC0 = 0; + TMS570_RTI.RTIFRC0 = 0; + /* clear interrupts*/ + TMS570_RTI.RTICLEARINTENA = 0x00070f0f; + TMS570_RTI.RTIINTFLAG = 0x0007000f; + /* set timer */ + TMS570_RTI.RTICOMP0 = TMS570_RTI.RTIFRC0 + microsec_per_tick; + TMS570_RTI.RTICOMP0CLR = TMS570_RTI.RTICOMP0 + microsec_per_tick / 2; + TMS570_RTI.RTIUDCP0 = microsec_per_tick; + /* enable interupt */ + TMS570_RTI.RTISETINTENA = 0x1; + /* enable timer */ + TMS570_RTI.RTIGCTRL = 1; +} + +/** + * @brief Clears interrupt source + * + * @retval Void + */ +static void tms570_clock_driver_support_at_tick( void ) +{ + TMS570_RTI.RTIINTFLAG = 0x00000001; + tms570_rti_last_tick_fcr0 = TMS570_RTI.RTICOMP0 - TMS570_RTI.RTIUDCP0; + /* TMS570_RTI.RTICOMP0 += 1000; */ +} + +/** + * @brief registers RTI interrupt handler + * + * @param[in] Clock_isr new ISR handler + * @param[in] Old_ticker old ISR handler (unused and type broken) + * + * @retval Void + */ +static void tms570_clock_driver_support_install_isr( + rtems_isr_entry Clock_isr +) +{ + rtems_status_code sc = RTEMS_SUCCESSFUL; + + sc = rtems_interrupt_handler_install( + TMS570_IRQ_TIMER_0, + "Clock", + RTEMS_INTERRUPT_UNIQUE, + (rtems_interrupt_handler) Clock_isr, + NULL + ); + if ( sc != RTEMS_SUCCESSFUL ) { + rtems_fatal_error_occurred(0xdeadbeef); + } +} + +/** + * @brief disables RTI interrupt + * + * Called when closing clock driver + * + * @retval Void + */ +static void tms570_clock_driver_support_shutdown_hardware( void ) +{ + /* turn off the timer interrupts */ + TMS570_RTI.RTICLEARINTENA = 0x20000; +} + +/** + * @brief returns the nanoseconds since last tick + * + * Return the nanoseconds since last tick + * + * @retval x nanoseconds + * + */ +static uint32_t tms570_clock_driver_nanoseconds_since_last_tick( void ) +{ + uint32_t actual_fcr0 = TMS570_RTI.RTIFRC0; + uint32_t usec_since_tick; + + usec_since_tick = actual_fcr0 - tms570_rti_last_tick_fcr0; + + return usec_since_tick * 1000; +} + +#define Clock_driver_support_initialize_hardware \ + tms570_clock_driver_support_initialize_hardware +#define Clock_driver_support_at_tick \ + tms570_clock_driver_support_at_tick +#define Clock_driver_support_initialize_hardware \ + tms570_clock_driver_support_initialize_hardware +#define Clock_driver_support_shutdown_hardware \ + tms570_clock_driver_support_shutdown_hardware +#define Clock_driver_nanoseconds_since_last_tick \ + tms570_clock_driver_nanoseconds_since_last_tick + +#define Clock_driver_support_install_isr(Clock_isr, Old_ticker ) \ + tms570_clock_driver_support_install_isr( Clock_isr ) + +void Clock_isr(void *arg); /* to supress warning */ + +#include "../../../shared/clockdrv_shell.h" diff --git a/c/src/lib/libbsp/arm/tms570/configure.ac b/c/src/lib/libbsp/arm/tms570/configure.ac new file mode 100644 index 0000000000..10a29208cc --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/configure.ac @@ -0,0 +1,52 @@ +## +# +# @file configure.ac +# +# @brief Configure script of LibBSP for the TMS570 board. +# + +AC_PREREQ([2.69]) +AC_INIT([rtems-c-src-lib-libbsp-arm-tms570],[_RTEMS_VERSION], + [http://www.rtems.org/bugzilla]) +AC_CONFIG_SRCDIR([bsp_specs]) +RTEMS_TOP(../../../../../..) + +RTEMS_CANONICAL_TARGET_CPU +AM_INIT_AUTOMAKE([no-define nostdinc foreign 1.12.2]) +RTEMS_BSP_CONFIGURE + +RTEMS_PROG_CC_FOR_TARGET +RTEMS_CANONICALIZE_TOOLS +RTEMS_PROG_CCAS + +RTEMS_CHECK_NETWORKING +AM_CONDITIONAL(HAS_NETWORKING,test "$HAS_NETWORKING" = "no") + +RTEMS_BSPOPTS_SET([TMS570_SCI_BAUD_RATE],[*],[115200U]) +RTEMS_BSPOPTS_HELP([TMS570_SCI_BAUD_RATE],[baud for UARTs]) + +RTEMS_BSPOPTS_SET([CONSOLE_USE_INTERRUPTS],[*],[1]) +RTEMS_BSPOPTS_HELP([CONSOLE_USE_INTERRUPTS], +[The tms570 console driver can operate in either polled or interrupt mode.]) + +RTEMS_BSPOPTS_SET([ARM_TMS570LS3137],[*],[0]) +RTEMS_BSPOPTS_HELP([ARM_TMS570LS3137],[target used for identify TMS570LS3137 board]) + +RTEMS_BSPOPTS_SET([BSP_MINIMUM_TASK_STACK_SIZE],[*],[1024]) +RTEMS_BSPOPTS_HELP([BSP_MINIMUM_TASK_STACK_SIZE],[Suggested minimum task stack + size in bytes]) + +RTEMS_BSPOPTS_SET([TMS570_OSCILLATOR_MAIN],[*],[12000000U]) +RTEMS_BSPOPTS_HELP([TMS570_OSCILLATOR_MAIN],[main oscillator frequency in Hz]) + +RTEMS_BSPOPTS_SET([TMS570_OSCILLATOR_RTC],[*],[32768U]) +RTEMS_BSPOPTS_HELP([TMS570_OSCILLATOR_RTC],[RTC oscillator frequency in Hz]) + +RTEMS_BSPOPTS_SET([TMS570_CCLK],[*],[96000000U]) +RTEMS_BSPOPTS_HELP([TMS570_CCLK],[CPU clock in Hz]) + +RTEMS_BSP_CLEANUP_OPTIONS(0, 1) +RTEMS_BSP_LINKCMDS + +AC_CONFIG_FILES([Makefile]) +AC_OUTPUT diff --git a/c/src/lib/libbsp/arm/tms570/console/printk-support.c b/c/src/lib/libbsp/arm/tms570/console/printk-support.c new file mode 100644 index 0000000000..241ca9b996 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/console/printk-support.c @@ -0,0 +1,85 @@ +/** + * @file printk-support.c + * + * @ingroup tms570 + * + * @brief definitions of serial line for debugging. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * by embedded brains GmbH and others + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <rtems/bspIo.h> +#include <stdint.h> +#include <bsp/tms570-sci.h> +#include <bsp/tms570-sci-driver.h> + + +/** + * @brief Puts chars into peripheral + * + * debug functions always use serial dev 0 peripheral + * + * @retval Void + */ +static void tms570_putc(char ch) +{ + rtems_interrupt_level level; + + rtems_interrupt_disable(level); + while ( ( driver_context_table[0].regs->SCIFLR & 0x100 ) == 0) { + rtems_interrupt_flash(level); + } + driver_context_table[0].regs->SCITD = ch; + rtems_interrupt_enable(level); +} + +/** + * @brief debug console output + * + * debug functions always use serial dev 0 peripheral + * + * @retval Void + */ +static void tms570_uart_output(char c) +{ + if ( c == '\n' ) { + char r = '\r'; + tms570_putc(r); + } + tms570_putc(c); +} + +/** + * @brief debug console input + * + * debug functions always use serial dev 0 peripheral + * + * @retval x Read char + * @retval -1 No input character available + */ +static int tms570_uart_input( void ) +{ + if ( driver_context_table[0].regs->SCIFLR & (1<<9) ) { + return driver_context_table[0].regs->SCIRD; + } else { + return -1; + } +} + +BSP_output_char_function_type BSP_output_char = tms570_uart_output; +BSP_polling_getchar_function_type BSP_poll_char = tms570_uart_input; diff --git a/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c b/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c new file mode 100644 index 0000000000..8aa3cafcb3 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/console/tms570-sci.c @@ -0,0 +1,559 @@ +/** + * @file tms570-sci.c + * + * @ingroup tms570 + * + * @brief Serial communication interface (SCI) functions definitions. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * by embedded brains GmbH and others + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <bspopts.h> +#include <termios.h> +#include <rtems/termiostypes.h> +#include <libchip/sersupp.h> +#include <bsp/tms570-sci.h> +#include <bsp/tms570-sci-driver.h> +#include <rtems/console.h> +#include <bsp.h> +#include <bsp/fatal.h> +#include <bsp/irq.h> + +#define TMS570_SCI_BUFFER_SIZE 1 + +/** + * @brief Table including all serial drivers + * + * Definitions of all serial drivers + */ +const tms570_sci_context driver_context_table[] = { + { + .device_name = "/dev/console", + .regs = &TMS570_SCI, + .irq = TMS570_IRQ_SCI_LEVEL_0, + }, + { + .device_name = "/dev/ttyS1", + .regs = &TMS570_SCI2, + .irq = TMS570_IRQ_SCI2_LEVEL_0, + } +}; + +/** + * @brief Serial drivers init function + * + * Initialize all serial drivers specified in driver_context_table + * + * @param[in] major + * @param[in] minor + * @param[in] arg + * @retval RTEMS_SUCCESSFUL Initialization completed + */ +rtems_device_driver console_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *arg +) +{ + rtems_status_code sc; +#if CONSOLE_USE_INTERRUPTS + const rtems_termios_device_handler *handler = &tms570_sci_handler_interrupt; +#else + const rtems_termios_device_handler *handler = &tms570_sci_handler_polled; +#endif + + /* + * Initialize the Termios infrastructure. If Termios has already + * been initialized by another device driver, then this call will + * have no effect. + */ + rtems_termios_initialize(); + + /* Initialize each device */ + for ( + minor = 0; + minor < RTEMS_ARRAY_SIZE(driver_context_table); + ++minor + ) { + const tms570_sci_context *ctx = &driver_context_table[minor]; + + /* + * Install this device in the file system and Termios. In order + * to use the console (i.e. being able to do printf, scanf etc. + * on stdin, stdout and stderr), one device must be registered as + * "/dev/console" (CONSOLE_DEVICE_NAME). + */ + sc = rtems_termios_device_install( + ctx->device_name, + major, + minor, + handler, + (void *) ctx + ); + if ( sc != RTEMS_SUCCESSFUL ) { + bsp_fatal(BSP_FATAL_CONSOLE_NO_DEV); + } + } + return RTEMS_SUCCESSFUL; +} + +/** + * @brief Reads chars from HW + * + * Reads chars from HW peripheral specified in driver context. + * TMS570 does not have HW buffer for serial line so this function can + * return only 0 or 1 char + * + * @param[in] ctx context of the driver + * @param[out] buf read data buffer + * @param[in] N size of buffer + * @retval x Number of read chars from peripherals + */ +static int tms570_sci_read_received_chars( + tms570_sci_context * ctx, + char * buf, + int N) +{ + if ( N < 1 ) { + return 0; + } + if ( ctx->regs->SCIRD != 0 ) { + buf[0] = ctx->regs->SCIRD; + return 1; + } + return 0; +} + +/** + * @brief Enables RX interrupt + * + * Enables RX interrupt source of SCI peripheral + * specified in the driver context. + * + * @param[in] ctx context of the driver + * @retval Void + */ +static void tms570_sci_enable_interrupts(tms570_sci_context * ctx) +{ + ctx->regs->SCISETINT = (1<<9); +} + +/** + * @brief Disables RX interrupt + * + * Disables RX interrupt source of SCI peripheral specified in the driver + * context. + * + * @param[in] ctx context of the driver + * @retval Void + */ +static void tms570_sci_disable_interrupts(tms570_sci_context * ctx) +{ + ctx->regs->SCICLEARINT = (1<<9); +} + +/** + * @brief Check whether driver has put char in HW + * + * Check whether driver has put char in HW. + * This information is read from the driver context not from a peripheral. + * TMS570 does not have write data buffer asociated with SCI + * so the return can be only 0 or 1. + * + * @param[in] ctx context of the driver + * @retval x + */ +static int tms570_sci_transmitted_chars(tms570_sci_context * ctx) +{ + int ret; + + ret = ctx->tx_chars_in_hw; + if ( ret == 1 ) { + ctx->tx_chars_in_hw = 0; + return 1; + } + return ret; +} + +/** + * @brief Set attributes of the HW peripheral + * + * Sets attributes of the HW peripheral (parity, baud rate, etc.) + * + * @param[in] tty rtems_termios_tty + * @param[in] t termios driver + * @retval true peripheral setting is changed + */ +static bool tms570_sci_set_attributes( + rtems_termios_tty *tty, + const struct termios *t +) +{ + tms570_sci_context *ctx = rtems_termios_get_device_context(tty); + rtems_interrupt_lock_context lock_context; + int32_t bauddiv; + int32_t baudrate; + + rtems_termios_interrupt_lock_acquire(tty, &lock_context); + + ctx->regs->SCIGCR1 &= ~( (1<<7) | (1<<25) | (1<<24) ); + + ctx->regs->SCIGCR1 &= ~(1<<4); /*one stop bit*/ + ctx->regs->SCIFORMAT = 0x7; + + switch ( t->c_cflag & ( PARENB|PARODD ) ) { + case ( PARENB|PARODD ): + /* Odd parity */ + ctx->regs->SCIGCR1 &= ~(1<<3); + ctx->regs->SCIGCR1 |= (1<<2); + break; + + case PARENB: + /* Even parity */ + ctx->regs->SCIGCR1 |= (1<<3); + ctx->regs->SCIGCR1 |= (1<<2); + break; + + default: + case 0: + case PARODD: + /* No Parity */ + ctx->regs->SCIGCR1 &= ~(1<<2); + } + + /* Baud rate */ + baudrate = rtems_termios_baud_to_number(cfgetospeed(t)); + baudrate *= 2 * 16; + bauddiv = (BSP_PLL_OUT_CLOCK + baudrate / 2) / baudrate; + ctx->regs->BRS = bauddiv; + + ctx->regs->SCIGCR1 |= (1<<7) | (1<<25) | (1<<24); + + rtems_termios_interrupt_lock_release(tty, &lock_context); + + return true; +} + +/** + * @brief sci interrupt handler + * + * Handler checks which interrupt occured and provides nessesary maintenance + * dequeue characters in termios driver whether character is send succesfully + * enqueue characters in termios driver whether character is recieved + * + * @param[in] arg rtems_termios_tty + * @retval Void + */ +static void tms570_sci_interrupt_handler(void * arg) +{ + rtems_termios_tty *tty = arg; + tms570_sci_context *ctx = rtems_termios_get_device_context(tty); + char buf[TMS570_SCI_BUFFER_SIZE]; + size_t n; + + /* + * Check if we have received something. + */ + if ( (ctx->regs->SCIFLR & (1<<9) ) == (1<<9) ) { + n = tms570_sci_read_received_chars(ctx, buf, TMS570_SCI_BUFFER_SIZE); + if ( n > 0 ) { + /* Hand the data over to the Termios infrastructure */ + rtems_termios_enqueue_raw_characters(tty, buf, n); + } + } + /* + * Check if we have something transmitted. + */ + if ( (ctx->regs->SCIFLR & (1<<8) ) == (1<<8) ) { + n = tms570_sci_transmitted_chars(ctx); + if ( n > 0 ) { + /* + * Notify Termios that we have transmitted some characters. It + * will call now the interrupt write function if more characters + * are ready for transmission. + */ + rtems_termios_dequeue_characters(tty, n); + } + } +} + +/** + * @brief sci write function called from interrupt + * + * Nonblocking write function. Writes characters to HW peripheral + * TMS570 does not have write data buffer asociated with SCI + * so only one character can be written. + * + * @param[in] tty rtems_termios_tty + * @param[in] buf buffer of characters pending to send + * @param[in] len size of the buffer + * @retval Void + */ +static void tms570_sci_interrupt_write( + rtems_termios_tty *tty, + const char *buf, + size_t len +) +{ + tms570_sci_context *ctx = rtems_termios_get_device_context(tty); + + if ( len > 0 ) { + /* start UART TX, this will result in an interrupt when done */ + ctx->regs->SCITD = *buf; + /* character written - raise count*/ + ctx->tx_chars_in_hw = 1; + /* Enable TX interrupt (interrupt is edge-triggered) */ + ctx->regs->SCISETINT = (1<<8); + + } else { + /* No more to send, disable TX interrupts */ + ctx->regs->SCICLEARINT = (1<<8); + /* Tell close that we sent everything */ + } +} + +/** + * @brief sci write function + * + * Blocking write function. Waits until HW peripheral is ready and then writes + * character to HW peripheral. Writes all characters in the buffer. + * + * @param[in] tty rtems_termios_tty + * @param[in] buf buffer of characters pending to send + * @param[in] len size of the buffer + * @retval Void + */ +static void tms570_sci_poll_write( + rtems_termios_tty *tty, + const char *buf, + size_t n +) +{ + tms570_sci_context *ctx = rtems_termios_get_device_context(tty); + size_t i; + + /* Write */ + + for ( i = 0; i < n; ++i ) { + while ( (ctx->regs->SCIFLR & (1<<11) ) == 0) { + ; + } + ctx->regs->SCITD = buf[i]; + } +} + +/** + * @brief See if there is recieved charakter to read + * + * read the RX flag from peripheral specified in context + * + * @param[in] ctx context of the driver + * @retval 0 No character to read + * @retval x Character ready to read + */ +static int TMS570_sci_can_read_char( + tms570_sci_context * ctx +) +{ + return ctx->regs->SCIFLR & (1<<9); +} + +/** + * @brief reads character from peripheral + * + * reads the recieved character from peripheral specified in context + * + * @param[in] ctx context of the driver + * @retval x Character + */ +static char TMS570_sci_read_char( + tms570_sci_context * ctx +) +{ + return ctx->regs->SCIRD; +} + +/** + * @brief sci read function + * + * check if there is recieved character to be read and reads it. + * + * @param[in] tty rtems_termios_tty (context of the driver) + * @retval -1 No character to be read + * @retval x Read character + */ +static int tms570_sci_poll_read(rtems_termios_tty *tty) +{ + tms570_sci_context *ctx = rtems_termios_get_device_context(tty); + + /* Check if a character is available */ + if ( TMS570_sci_can_read_char(ctx) ) { + return TMS570_sci_read_char(ctx); + } else { + return -1; + } +} + +/** + * @brief initialization of the driver + * + * initialization of the HW peripheral specified in contex of the driver. + * This function is called only once when opening the driver. + * + * @param[in] tty context of the driver + * @param[in] args + * @retval false Error occured during initialization + * @retval true Driver is open and ready + */ +static bool tms570_sci_poll_first_open( + rtems_termios_tty *tty, + rtems_libio_open_close_args_t *args +) +{ + bool ok; + + rtems_termios_set_best_baud(tty, TMS570_SCI_BAUD_RATE); + ok = tms570_sci_set_attributes(tty, rtems_termios_get_termios(tty)); + if ( !ok ) { + return false; + } + return true; +} + +/** + * @brief initialization of the interrupt driven driver + * + * calls tms570_sci_poll_first_open function. + * install and enables interrupts. + * + * @param[in] tty context of the driver + * @param[in] args + * @retval false Error occured during initialization + * @retval true Driver is open and ready + */ +static bool tms570_sci_interrupt_first_open( + rtems_termios_tty *tty, + rtems_libio_open_close_args_t *args +) +{ + tms570_sci_context *ctx = rtems_termios_get_device_context(tty); + rtems_status_code sc; + bool ret; + + ret = tms570_sci_poll_first_open(tty,args); + if ( ret == false ) { + return false; + } + ctx->regs->SCISETINTLVL = 0; + /* Register Interrupt handler */ + sc = rtems_interrupt_handler_install(ctx->irq, + ctx->device_name, + RTEMS_INTERRUPT_SHARED, + tms570_sci_interrupt_handler, + tty + ); + if ( sc != RTEMS_SUCCESSFUL ) { + return false; + } + tms570_sci_enable_interrupts(rtems_termios_get_device_context(tty)); + return true; +} + +/** + * @brief closes sci peripheral + * + * @param[in] tty context of the driver + * @param[in] args + * @retval false Error occured during initialization + * @retval true Driver is open and ready + */ +static void tms570_sci_poll_last_close( + rtems_termios_tty *tty, + rtems_libio_open_close_args_t *args +) +{ + ; +} + +/** + * @brief closes sci peripheral of interrupt driven driver + * + * calls tms570_sci_poll_last_close and disables interrupts + * + * @param[in] tty context of the driver + * @param[in] args + * @retval false Error occured during initialization + * @retval true Driver is open and ready + */ +static void tms570_sci_interrupt_last_close( + rtems_termios_tty *tty, + rtems_libio_open_close_args_t *args +) +{ + tms570_sci_context *ctx = rtems_termios_get_device_context(tty); + rtems_interrupt_lock_context lock_context; + + /* Turn off RX interrupts */ + rtems_termios_interrupt_lock_acquire(tty, &lock_context); + tms570_sci_disable_interrupts(ctx); + rtems_termios_interrupt_lock_release(tty, &lock_context); + + /* Flush device */ + while ( ( ctx->regs->SCIFLR & (1<<11) ) > 0 ) { + ;/* Wait until all data has been sent */ + } + + /* uninstall ISR */ + rtems_interrupt_handler_remove(ctx->irq, tms570_sci_interrupt_handler, tty); + + tms570_sci_poll_last_close(tty,args); +} + +/** + * @brief Struct containing definitions of polled driver functions. + * + * Encapsulates polled driver functions. + * Use of this table is determited by not defining TMS570_USE_INTERRUPTS + */ +const rtems_termios_device_handler tms570_sci_handler_polled = { + .first_open = tms570_sci_poll_first_open, + .last_close = tms570_sci_poll_last_close, + .poll_read = tms570_sci_poll_read, + .write = tms570_sci_poll_write, + .set_attributes = tms570_sci_set_attributes, + .stop_remote_tx = NULL, + .start_remote_tx = NULL, + .mode = TERMIOS_POLLED +}; + +/** + * @brief Struct containing definitions of interrupt driven driver functions. + * + * Encapsulates interrupt driven driver functions. + * Use of this table is determited by defining TMS570_USE_INTERRUPTS + */ +const rtems_termios_device_handler tms570_sci_handler_interrupt = { + .first_open = tms570_sci_interrupt_first_open, + .last_close = tms570_sci_interrupt_last_close, + .poll_read = NULL, + .write = tms570_sci_interrupt_write, + .set_attributes = tms570_sci_set_attributes, + .stop_remote_tx = NULL, + .start_remote_tx = NULL, + .mode = TERMIOS_IRQ_DRIVEN +}; diff --git a/c/src/lib/libbsp/arm/tms570/include/bsp.h b/c/src/lib/libbsp/arm/tms570/include/bsp.h new file mode 100644 index 0000000000..81bc4cd9cf --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/include/bsp.h @@ -0,0 +1,59 @@ +/** + * @file bsp.h + * + * @ingroup tms570 + * + * @brief Global BSP definitions. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifndef LIBBSP_ARM_TMS570_BSP_H +#define LIBBSP_ARM_TMS570_BSP_H + +#include <bspopts.h> + +#define BSP_FEATURE_IRQ_EXTENSION + +#ifndef ASM + +#include <rtems.h> +#include <rtems/console.h> +#include <rtems/clockdrv.h> +#include <bsp/default-initial-extension.h> + +#define BSP_OSCILATOR_CLOCK 8000000 +#define BSP_PLL_OUT_CLOCK 160000000 + +/** Define operation count for Tests */ +#define OPERATION_COUNT 4 + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +struct rtems_bsdnet_ifconfig; + +/** @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* ASM */ + +#endif /* LIBBSP_ARM_TMS570_BSP_H */ diff --git a/c/src/lib/libbsp/arm/tms570/include/irq.h b/c/src/lib/libbsp/arm/tms570/include/irq.h new file mode 100644 index 0000000000..f35e7fe5ca --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/include/irq.h @@ -0,0 +1,156 @@ +/** + * @file irq.h + * + * @ingroup tms570 + * + * @brief TMS570 interrupt definitions. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * by embedded brains GmbH and others + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifndef LIBBSP_ARM_TMS570_IRQ_H +#define LIBBSP_ARM_TMS570_IRQ_H + +#ifndef ASM +#include <rtems.h> +#include <rtems/irq.h> +#include <rtems/irq-extension.h> +#endif + +#define BSP_INTERRUPT_VECTOR_MIN 0U +#define TMS570_IRQ_ESM_HIGH 0 +#define TMS570_IRQ_RESERVED 1 +#define TMS570_IRQ_TIMER_0 2 +#define TMS570_IRQ_TIMER_1 3 +#define TMS570_IRQ_TIMER_2 4 +#define TMS570_IRQ_TIMER_3 5 +#define TMS570_IRQ_RTI_OVERFLOW_0 6 +#define TMS570_IRQ_RTI_OVERFLOW_1 7 +#define TMS570_IRQ_RTI_TIMEBASE 8 +#define TMS570_IRQ_GIO_HIGH 9 +#define TMS570_IRQ_HET_HIGH 10 +#define TMS570_IRQ_HET_TU_HIGH 11 +#define TMS570_IRQ_MIBSPI1_HIGH 12 +#define TMS570_IRQ_SCI_LEVEL_0 13 +#define TMS570_IRQ_ADC1_EVENT 14 +#define TMS570_IRQ_ADC1_GROUP_1 15 +#define TMS570_IRQ_CAN1_HIGH 16 +#define TMS570_IRQ_RESERVED 17 +#define TMS570_IRQ_FLEXRAY_HIGH 18 +#define TMS570_IRQ_CRC_1 19 +#define TMS570_IRQ_ESM_LOW 20 +#define TMS570_IRQ_SSI 21 +#define TMS570_IRQ_PMU 22 +#define TMS570_IRQ_GIO_LOW 23 +#define TMS570_IRQ_HET_LOW 24 +#define TMS570_IRQ_HET_TU_LOW 25 +#define TMS570_IRQ_MIBSPI1_LOW 26 +#define TMS570_IRQ_SCI_LEVEL_1 27 +#define TMS570_IRQ_ADC1_GROUP_2 28 +#define TMS570_IRQ_CAN1_LOW 29 +#define TMS570_IRQ_RESERVED +#define TMS570_IRQ_ADC1_MAG 31 +#define TMS570_IRQ_FLEXRAY_LOW 32 +#define TMS570_IRQ_DMA_FTCA 33 +#define TMS570_IRQ_DMA_LFSA 34 +#define TMS570_IRQ_CAN2_HIGH 35 +#define TMS570_IRQ_DMM_HIGH 36 +#define TMS570_IRQ_MIBSPI3_HIGH 37 +#define TMS570_IRQ_MIBSPI3_LOW 38 +#define TMS570_IRQ_DMA_HBCA 39 +#define TMS570_IRQ_DMA_BTCA 40 +#define TMS570_IRQ_DMA_BERA 41 +#define TMS570_IRQ_CAN2_LOW 42 +#define TMS570_IRQ_DMM_LOW 43 +#define TMS570_IRQ_CAN1_IF3 44 +#define TMS570_IRQ_CAN3_HIGH 45 +#define TMS570_IRQ_CAN2_IF3 46 +#define TMS570_IRQ_FPU 47 +#define TMS570_IRQ_FLEXRAY_TU 48 +#define TMS570_IRQ_SPI4_HIGH 49 +#define TMS570_IRQ_ADC2_EVENT 50 +#define TMS570_IRQ_ADC2_GROUP_1 51 +#define TMS570_IRQ_FLEXRAY_T0C 52 +#define TMS570_IRQ_MIBSPIP5_HIGH 53 +#define TMS570_IRQ_SPI4_LOW 54 +#define TMS570_IRQ_CAN3_LOW 55 +#define TMS570_IRQ_MIBSPIP5_LOW 56 +#define TMS570_IRQ_ADC2_GROUP_2 57 +#define TMS570_IRQ_FLEXRAY_TU_ERROR 58 +#define TMS570_IRQ_ADC2_MAG 59 +#define TMS570_IRQ_CAN3_IF3 60 +#define TMS570_IRQ_FSM_DONE 61 +#define TMS570_IRQ_FLEXRAY_T1C 62 +#define TMS570_IRQ_HET2_LEVEL_0 63 +#define TMS570_IRQ_SCI2_LEVEL_0 64 +#define TMS570_IRQ_HET_TU2_LEVEL_0 65 +#define TMS570_IRQ_IC2_INTERRUPT 66 +#define TMS570_IRQ_HET2_LEVEL_1 73 +#define TMS570_IRQ_SCI2_LEVEL_1 74 +#define TMS570_IRQ_HET_TU2_LEVEL_1 75 +#define TMS570_IRQ_HWA_INT_REQ_H 80 +#define TMS570_IRQ_HWA_INT_REQ_H 81 +#define TMS570_IRQ_DCC_DONE_INTERRUPT 82 +#define TMS570_IRQ_DCC2_DONE_INTERRUPT 83 +#define TMS570_IRQ_HWAG1_INT_REQ_L 88 +#define TMS570_IRQ_HWAG2_INT_REQ_L 89 +#define BSP_INTERRUPT_VECTOR_MAX 94 + +#define TMS570_IRQ_PRIORITY_VALUE_MIN 0U +#define TMS570_IRQ_PRIORITY_VALUE_MAX 0U + +#define TMS570_IRQ_PRIORITY_COUNT ( TMS570_IRQ_PRIORITY_VALUE_MAX + 1U ) +#define TMS570_IRQ_PRIORITY_HIGHEST TMS570_IRQ_PRIORITY_VALUE_MIN +#define TMS570_IRQ_PRIORITY_LOWEST TMS570_IRQ_PRIORITY_VALUE_MAX + +#ifndef ASM + +/** + * @brief Set priority of the interrupt vector. + * + * This function is here because of compability. It should set + * priority of the interrupt vector. + * @warning It does not set any priority at HW layer. It is nearly imposible to + * @warning set priority of the interrupt on TMS570 in a nice way. + * @param[in] vector vector of isr + * @param[in] priority new priority assigned to the vector + * @return Void + */ +void tms570_irq_set_priority( + rtems_vector_number vector, + unsigned priority +); + +/** + * @brief Gets priority of the interrupt vector. + * + * This function is here because of compability. It returns priority + * of the isr vector last set by tms570_irq_set_priority function. + * + * @warning It does not return any real priority of the HW layer. + * @param[in] vector vector of isr + * @retval 0 vector is invalid. + * @retval priority priority of the interrupt + */ +unsigned tms570_irq_get_priority( rtems_vector_number vector ); + +#endif /* ASM */ + +/** @} */ + +#endif /* LIBBSP_ARM_TMS570_IRQ_H */ diff --git a/c/src/lib/libbsp/arm/tms570/include/tms570-pom.h b/c/src/lib/libbsp/arm/tms570/include/tms570-pom.h new file mode 100644 index 0000000000..a44771157d --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/include/tms570-pom.h @@ -0,0 +1,101 @@ +/** + * @file tms570-pom.h + * @ingroup tms570 + * @brief Parameter Overlay Module (POM) header file + */ + +/* + * Copyright (c) 2014 Pavel Pisa <pisa@cmp.felk.cvut.cz> + * + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifndef LIBBSP_ARM_TMS570_POM_H +#define LIBBSP_ARM_TMS570_POM_H + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define TMS570_POM_REGIONS 32 +#define TMS570_POM_GLBCTRL_ENABLE 0x000000a0a + +/* Specification of memory size used for field REGSIZE of tms570_pom_region_t */ +#define TMS570_POM_REGSIZE_DISABLED 0x0 +#define TMS570_POM_REGSIZE_64B 0x1 +#define TMS570_POM_REGSIZE_128B 0x2 +#define TMS570_POM_REGSIZE_256B 0x3 +#define TMS570_POM_REGSIZE_512B 0x4 +#define TMS570_POM_REGSIZE_1KB 0x5 +#define TMS570_POM_REGSIZE_2KB 0x6 +#define TMS570_POM_REGSIZE_4KB 0x7 +#define TMS570_POM_REGSIZE_8KB 0x8 +#define TMS570_POM_REGSIZE_16KB 0x9 +#define TMS570_POM_REGSIZE_32KB 0xa +#define TMS570_POM_REGSIZE_64KB 0xb +#define TMS570_POM_REGSIZE_128KB 0xc +#define TMS570_POM_REGSIZE_256KB 0xd + +#define TMS570_POM_REGADDRMASK ((1<<23)-1) + +typedef struct tms570_pom_region_t { + uint32_t PROGSTART; + uint32_t OVLSTART; + uint32_t REGSIZE; + uint32_t res0; +} tms570_pom_region_t; + +typedef struct tms570_pom_t { + uint32_t GLBCTRL; /* 000h Global Control Register */ + uint32_t REV; /* 004h Revision ID */ + uint32_t CLKCTRL; /* 008h Clock Gate Control Register */ + uint32_t FLG; /* 00Ch Status Register */ + uint32_t reserved1[0x1f0/4]; + tms570_pom_region_t REG[TMS570_POM_REGIONS]; /* 200h Program Regions */ + uint32_t reserved2[0xb00/4]; + uint32_t ITCTRL; /* F00h Integration Control Register */ + uint32_t reserved3[0x09c/4]; + uint32_t CLAIMSET; /* FA0h Claim Set Register */ + uint32_t CLAIMCLR; /* FA4h Claim Clear Register */ + uint32_t reserved4[0x008/4]; + uint32_t LOCKACCESS; /* FB0h Lock Access Register */ + uint32_t LOCKSTATUS; /* FB4h Lock Status Register */ + uint32_t AUTHSTATUS; /* FB8h Authentication Status Register */ + uint32_t reserved5[0x00c/4]; + uint32_t DEVID; /* FC8h Device ID Register */ + uint32_t DEVTYPE; /* FCCh Device Type Register */ + uint32_t PERIPHERALID4; /* FD0h Peripheral ID 4 Register */ + uint32_t PERIPHERALID5; /* FD4h Peripheral ID 5 Register */ + uint32_t PERIPHERALID6; /* FD8h Peripheral ID 6 Register */ + uint32_t PERIPHERALID7; /* FDCh Peripheral ID 7 Register */ + uint32_t PERIPHERALID0; /* FE0h Peripheral ID 0 Register */ + uint32_t PERIPHERALID1; /* FE4h Peripheral ID 1 Register */ + uint32_t PERIPHERALID2; /* FE8h Peripheral ID 2 Register */ + uint32_t PERIPHERALID3; /* FECh Peripheral ID 3 Register */ + uint32_t COMPONENTID0; /* FF0h Component ID 0 Register */ + uint32_t COMPONENTID1; /* FF4h Component ID 1 Register */ + uint32_t COMPONENTID2; /* FF8h Component ID 2 Register */ + uint32_t COMPONENTID3; /* FFCh Component ID 3 Register */ +} tms570_pom_t; + +#define TMS570_POM (*(volatile tms570_pom_t*)0xffa04000) + +int mem_dump(void *buf, unsigned long start, unsigned long len, int blen); +void tms570_pom_remap(void); + +/** @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LIBBSP_ARM_TMS570_POM_H */ diff --git a/c/src/lib/libbsp/arm/tms570/include/tms570-rti.h b/c/src/lib/libbsp/arm/tms570/include/tms570-rti.h new file mode 100644 index 0000000000..25c02e5906 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/include/tms570-rti.h @@ -0,0 +1,95 @@ +/** + * @file tms570-rti.h + * + * @ingroup tms570 + * + * @brief Real Time Interrupt module (RTI) header file. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * by embedded brains GmbH and others + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifndef LIBBSP_ARM_TMS570_RTI_H +#define LIBBSP_ARM_TMS570_RTI_H + +#ifndef ASM + +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct { + uint32_t RTIGCTRL; /* RTIGlobalControlRegister */ + uint32_t RTITBCTRL; /* RTITimebaseControlRegister */ + uint32_t RTICAPCTRL; /* RTICaptureControlRegister */ + uint32_t RTICOMPCTRL; /* RTICompareControlRegister */ + uint32_t RTIFRC0; /* RTIFreeRunningCounter0Register */ + uint32_t RTIUC0; /* RTIUpCounter0Register */ + uint32_t RTICPUC0; /* RTICompareUpCounter0Register */ + uint32_t reserved1 [0x4/4]; + uint32_t RTICAFRC0; /* RTICaptureFreeRunningCounter0Register */ + uint32_t RTICAUC0; /* RTICaptureUpCounter0Register */ + uint32_t reserved2 [0x8/4]; + uint32_t RTIFRC1; /* RTIFreeRunningCounter1Register */ + uint32_t RTIUC1; /* RTIUpCounter1Register */ + uint32_t RTICPUC1; /* RTICompareUpCounter1Register */ + uint32_t reserved3 [0x4/4]; + uint32_t RTICAFRC1; /* RTICaptureFreeRunningCounter1Register */ + uint32_t RTICAUC1; /* RTICaptureUpCounter1Register */ + uint32_t reserved4 [0x8/4]; + uint32_t RTICOMP0; /* RTICompare0Register */ + uint32_t RTIUDCP0; /* RTIUpdateCompare0Register */ + uint32_t RTICOMP1; /* RTICompare1Register */ + uint32_t RTIUDCP1; /* RTIUpdateCompare1Register */ + uint32_t RTICOMP2; /* RTICompare2Register */ + uint32_t RTIUDCP2; /* RTIUpdateCompare2Register */ + uint32_t RTICOMP3; /* RTICompare3Register */ + uint32_t RTIUDCP3; /* RTIUpdateCompare3Register */ + uint32_t RTITBLCOMP; /* RTITimebaseLowCompareRegister */ + uint32_t RTITBHCOMP; /* RTITimebaseHighCompareRegister */ + uint32_t reserved5 [0x8/4]; + uint32_t RTISETINTENA; /* RTISetInterruptEnableRegister */ + uint32_t RTICLEARINTENA; /* RTIClearInterruptEnableRegister */ + uint32_t RTIINTFLAG; /* RTIInterruptFlagRegister */ + uint32_t reserved6 [0x4/4]; + uint32_t RTIDWDCTRL; /* DigitalWatchdogControlRegister */ + uint32_t RTIDWDPRLD; /* DigitalWatchdogPreloadRegister */ + uint32_t RTIWDSTATUS; /* WatchdogStatusRegister */ + uint32_t RTIWDKEY; /* RTIWatchdogKeyRegister */ + uint32_t RTIDWDCNTR; /* RTIDigitalWatchdogDownCounterRegister */ + uint32_t RTIWWDRXNCTRL; /* DigitalWindowedWatchdogReactionControlRegister */ + uint32_t RTIWWDSIZECTRL; /* DigitalWindowedWatchdogWindowSizeControlRegister */ + uint32_t RTIINTCLRENABLE;/* RTICompareInterruptClearEnableRegister */ + uint32_t RTICOMP0CLR; /* RTICompare0ClearRegister */ + uint32_t RTICOMP1CLR; /* RTICompare1ClearRegister */ + uint32_t RTICOMP2CLR; /* RTICompare2ClearRegister */ + uint32_t RTICOMP3CLR; /* RTICompare3ClearRegister */ +}tms570_rti_t; + +#define TMS570_RTI (*(volatile tms570_rti_t*)0xFFFFFC00) + +/** @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* ASM */ + +#endif /* LIBBSP_ARM_TMS570_IRQ_H */ diff --git a/c/src/lib/libbsp/arm/tms570/include/tms570-sci-driver.h b/c/src/lib/libbsp/arm/tms570/include/tms570-sci-driver.h new file mode 100644 index 0000000000..5f38908499 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/include/tms570-sci-driver.h @@ -0,0 +1,57 @@ +/** + * @file tms570-sci-driver.h + * + * @ingroup tms570 + * + * @brief Declaration of serial's driver inner structure. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * by embedded brains GmbH and others + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifndef TMS570_SCI_DRIVER +#define TMS570_SCI_DRIVER + +#include <rtems/termiostypes.h> +#include <rtems/irq.h> +#include <bsp/tms570-sci.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Low-level driver specific data structure */ +typedef struct { + const char *device_name; + volatile tms570_sci_t *regs; + int tx_chars_in_hw; + rtems_vector_number irq; +} tms570_sci_context; + +extern const rtems_termios_device_handler tms570_sci_handler_polled; + +extern const rtems_termios_device_handler tms570_sci_handler_interrupt; + +extern const tms570_sci_context driver_context_table[]; + +/** @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* TMS570_SCI_DRIVER */ diff --git a/c/src/lib/libbsp/arm/tms570/include/tms570-sci.h b/c/src/lib/libbsp/arm/tms570/include/tms570-sci.h new file mode 100644 index 0000000000..6ed68e24bf --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/include/tms570-sci.h @@ -0,0 +1,76 @@ +/** + * @file tms570-sci.h + * + * @ingroup tms570 + * + * @brief Serial Communication Interface (SCI) header file. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * by embedded brains GmbH and others + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifndef LIBBSP_ARM_TMS570_SCI_H +#define LIBBSP_ARM_TMS570_SCI_H + +#include <libchip/serial.h> + +#include <rtems.h> +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct { + uint32_t SCIGCR0; /*SCIGlobalControlRegister0*/ + uint32_t SCIGCR1; /*SCIGlobalControlRegister1*/ + uint32_t reserved1 [0x4/4]; + uint32_t SCISETINT; /*SCISetInterruptRegister*/ + uint32_t SCICLEARINT; /*SCIClearInterruptRegister*/ + uint32_t SCISETINTLVL; /*SCISetInterruptLevelRegister*/ + uint32_t SCICLEARINTLVL; /*SCIClearInterruptLevelRegister*/ + uint32_t SCIFLR; /*SCIFlagsRegister*/ + uint32_t SCIINTVECT0; /*SCIInterruptVectorOffset0*/ + uint32_t SCIINTVECT1; /*SCIInterruptVectorOffset1*/ + uint32_t SCIFORMAT; /*SCIFormatControlRegister*/ + uint32_t BRS; /*BaudRateSelectionRegister*/ + uint32_t SCIED; /*ReceiverEmulationDataBuffer*/ + uint32_t SCIRD; /*ReceiverDataBuffer*/ + uint32_t SCITD; /*TransmitDataBuffer*/ + uint32_t SCIPIO0; /*SCIPinI/OControlRegister0*/ + uint32_t SCIPIO1; /*SCIPinI/OControlRegister1*/ + uint32_t SCIPIO2; /*SCIPinI/OControlRegister2*/ + uint32_t SCIPIO3; /*SCIPinI/OControlRegister3*/ + uint32_t SCIPIO4; /*SCIPinI/OControlRegister4*/ + uint32_t SCIPIO5; /*SCIPinI/OControlRegister5*/ + uint32_t SCIPIO6; /*SCIPinI/OControlRegister6*/ + uint32_t SCIPIO7; /*SCIPinI/OControlRegister7*/ + uint32_t SCIPIO8; /*SCIPinI/OControlRegister8*/ + uint32_t reserved2 [0x30/4]; + uint32_t IODFTCTRL; /*Input/OutputErrorEnableRegister*/ +}tms570_sci_t; + +#define TMS570_SCI (*(volatile tms570_sci_t*)0xFFF7E400U) +#define TMS570_SCI2 (*(volatile tms570_sci_t*)0xFFF7E500U) + +/** @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/c/src/lib/libbsp/arm/tms570/include/tms570-vim.h b/c/src/lib/libbsp/arm/tms570/include/tms570-vim.h new file mode 100644 index 0000000000..136af531f8 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/include/tms570-vim.h @@ -0,0 +1,75 @@ +/** + * @file tms570-vim.h + * + * @ingroup tms570 + * + * @brief Vectored Interrupt Module (VIM) header file. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * by embedded brains GmbH and others + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifndef LIBBSP_ARM_TMS570_VIM_H +#define LIBBSP_ARM_TMS570_VIM_H + +#ifndef ASM +#include <rtems.h> +#include <stdint.h> + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +typedef struct{ + uint32_t PARFLG; /* InterruptVectorTableParityFlagRegister */ + uint32_t PARCTL; /* InterruptVectorTableParityControlRegister */ + uint32_t ADDERR; /* AddressParityErrorRegister */ + uint32_t FBPARERR; /* Fall-BackAddressParityErrorRegister */ + uint32_t reserved1 [0x4/4]; + uint32_t IRQINDEX; /* IRQIndexOffsetVectorRegister */ + uint32_t FIQINDEX; /* FIQIndexOffsetVectorRegister */ + uint32_t reserved2 [0x8/4]; + uint32_t FIRQPR[3]; /* FIQ/IRQProgramControlRegister0 */ + uint32_t reserved3 [0x4/4]; + uint32_t INTREQ[3]; /* PendingInterruptReadLocationRegister0 */ + uint32_t reserved4 [0x4/4]; + uint32_t REQENASET[3]; /* InterruptEnableSetRegister0 */ + uint32_t reserved5 [0x4/4]; + uint32_t REQENACLR[3]; /* InterruptEnableClearRegister0 */ + uint32_t reserved6 [0x4/4]; + uint32_t WAKEENASET[3]; /* Wake-upEnableSetRegister0 */ + uint32_t reserved7 [0x4/4]; + uint32_t WAKEENACLR[3]; /* Wake-upEnableClearRegister0 */ + uint32_t reserved8 [0x4/4]; + uint32_t IRQVECREG; /* IRQInterruptVectorRegister */ + uint32_t FIQVECREG; /* FIQInterruptVectorRegister */ + uint32_t CAPEVT; /* CaptureEventRegister */ + uint32_t reserved9 [0x4/4]; + uint32_t CHANCTRL [0x5c/4]; /* VIM Interrupt Control Register (PARSER ERROR) */ +}tms570_vim_t; + +#define TMS570_VIM (*(volatile tms570_vim_t*)0xFFFFFDEC) + +#endif + +/** @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LIBBSP_ARM_TMS570_IRQ_H */ diff --git a/c/src/lib/libbsp/arm/tms570/include/tms570.h b/c/src/lib/libbsp/arm/tms570/include/tms570.h new file mode 100644 index 0000000000..2023a29040 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/include/tms570.h @@ -0,0 +1,28 @@ +/** + * @file tms570.h + * + * @ingroup tms570 + * + * @brief Specific register definitions according to tms570 family boards. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#ifndef LIBBSP_ARM_TMS570_H +#define LIBBSP_ARM_TMS570_H + +#endif /* LIBBSP_ARM_TMS570_H */ diff --git a/c/src/lib/libbsp/arm/tms570/irq/irq.c b/c/src/lib/libbsp/arm/tms570/irq/irq.c new file mode 100644 index 0000000000..2e6e3db637 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/irq/irq.c @@ -0,0 +1,207 @@ +/** + * @file irq.c + * + * @ingroup tms570 + * + * @brief TMS570 interrupt support functions definitions. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <bsp.h> +#include <bsp/irq-generic.h> +#include <bsp/tms570-vim.h> +#include <bsp/irq.h> +#include <rtems/score/armv4.h> + +/** + * @brief Check if isr vector is valid + * + * Check if isr vector is valid by using BSP_INTERRUPT_VECTOR_MAX and + * BSP_INTERRUPT_VECTOR_MIN defined in irq.h + * + * @param[in] vector interrupt vector to be checked. + * @retval TRUE vector is valid. + * @retval FALSE vector is invalid + */ +static inline bool tms570_irq_is_valid( + rtems_vector_number vector +) +{ + return (vector <= BSP_INTERRUPT_VECTOR_MAX) && + (vector > BSP_INTERRUPT_VECTOR_MIN); +} + +unsigned int priorityTable[BSP_INTERRUPT_VECTOR_MAX+1]; + +/** + * @brief Set priority of the interrupt vector. + * + * This function is here because of compability. It should set + * priority of the interrupt vector. + * @warning It does not set any priority at HW layer. It is nearly imposible to + * @warning set priority of the interrupt on TMS570 in a nice way. + * @param[in] vector vector of isr + * @param[in] priority new priority assigned to the vector + * @return Void + */ +void tms570_irq_set_priority( + rtems_vector_number vector, + unsigned priority +) +{ + if ( tms570_irq_is_valid(vector) ) { + priorityTable[vector] = priority; + } +} + +/** + * @brief Gets priority of the interrupt vector. + * + * This function is here because of compability. It returns priority + * of the isr vector last set by tms570_irq_set_priority function. + * + * @warning It does not return any real priority of the HW layer. + * @param[in] vector vector of isr + * @retval 0 vector is invalid. + * @retval priority priority of the interrupt + */ +unsigned tms570_irq_get_priority( + rtems_vector_number vector +) +{ + if ( tms570_irq_is_valid(vector) ) { + return priorityTable[vector]; + } + return 0; +} + +/** + * @brief Interrupt dispatch + * + * Called by OS to determine which interrupt occured. + * Function passes control to interrupt handler. + * + * @return Void + */ +void bsp_interrupt_dispatch(void) +{ + rtems_vector_number vector = TMS570_VIM.IRQINDEX-1; + + bsp_interrupt_handler_dispatch(vector); +} + +/** + * @brief enables interrupt vector in the HW + * + * Enables HW interrupt for specified vector + * + * @param[in] vector vector of the isr which needs to be enabled. + * @retval RTEMS_INVALID_ID vector is invalid. + * @retval RTEMS_SUCCESSFUL interrupt source enabled. + */ +rtems_status_code bsp_interrupt_vector_enable( + rtems_vector_number vector +) +{ + if( !tms570_irq_is_valid(vector) ) { + return RTEMS_INVALID_ID; + } + + TMS570_VIM.REQENASET[vector >> 5] = 1 << (vector & 0x1f); + + return RTEMS_SUCCESSFUL; +} + +/** + * @brief disables interrupt vector in the HW + * + * Disables HW interrupt for specified vector + * + * @param[in] vector vector of the isr which needs to be disabled. + * @retval RTEMS_INVALID_ID vector is invalid. + * @retval RTEMS_SUCCESSFUL interrupt source disabled. + */ +rtems_status_code bsp_interrupt_vector_disable( + rtems_vector_number vector +) +{ + if( !tms570_irq_is_valid(vector) ) { + return RTEMS_INVALID_ID; + } + + TMS570_VIM.REQENACLR[vector >> 5] = 1 << (vector & 0x1f); + + return RTEMS_SUCCESSFUL; +} + +/** + * @brief Init function of interrupt module + * + * Resets vectored interrupt interface to default state. + * Disables all interrupts. + * Set all sources as IRQ (not FIR). + * + * @retval RTEMS_SUCCESSFUL All is set + */ +rtems_status_code bsp_interrupt_facility_initialize(void) +{ + void (**vim_vec)(void) = (void (**)(void)) 0xFFF82000; + unsigned int value = 0x00010203; + unsigned int i = 0; + uint32_t sctlr; + + /* Disable interrupts */ + for ( i = 0; i < 3; i++ ) { + TMS570_VIM.REQENACLR[i] = 0xffffffff; + } + /* Map default events on interrupt vectors */ + for ( i = 0; i < 24; i += 1, value += 0x04040404) { + TMS570_VIM.CHANCTRL[i] = value; + } + /* Set all vectors as IRQ (not FIR) */ + TMS570_VIM.FIRQPR[0] = 3; + TMS570_VIM.FIRQPR[1] = 0; + TMS570_VIM.FIRQPR[2] = 0; + + /* + _CPU_ISR_install_vector( + ARM_EXCEPTION_IRQ, + _ARMV4_Exception_interrupt, + NULL + ); + + Call to setup of interrupt entry in CPU level exception vectors table + is not used (necessary/possible) because the table is provided + by c/src/lib/libbsp/arm/shared/start/start.S and POM overlay + solution remaps that to address zero. + */ + + for ( i = 0; i <= 94; ++i ) { + vim_vec[i] = _ARMV4_Exception_interrupt; + } + /* Clear bit VE in SCTLR register to not use VIM IRQ exception bypass*/ + asm volatile ("mrc p15, 0, %0, c1, c0, 0\n": "=r" (sctlr)); + /* + * Disable bypass of CPU level exception table for interrupt entry which + * can be provided by VIM hardware + */ + sctlr &= ~(1 << 24); + asm volatile ("mcr p15, 0, %0, c1, c0, 0\n": : "r" (sctlr)); + + return RTEMS_SUCCESSFUL; +} diff --git a/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk-testsuite.tcfg b/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk-testsuite.tcfg new file mode 100644 index 0000000000..6f722bcae9 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk-testsuite.tcfg @@ -0,0 +1,19 @@ +# +# tms570ls3137 mbed RTEMS Test Database. +# +# Format is one line per test that is _NOT_ built. +# + +flashdisk01 +utf8proc01 +spstkalloc02 +fsdosfsname01 +jffs2_fserror +jffs2_fslink +jffs2_fspatheval +jffs2_fspermission +jffs2_fsrdwr +jffs2_fssymlink +jffs2_fstime +pppd +mghttpd01 diff --git a/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk.cfg b/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk.cfg new file mode 100644 index 0000000000..eb4a65fd55 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk.cfg @@ -0,0 +1,20 @@ +# +# Config file for TMS570LS3137 board. +# + +include $(RTEMS_ROOT)/make/custom/default.cfg + +RTEMS_CPU = arm + +CPU_CFLAGS = -march=armv7-r -mthumb -mbig-endian + +CFLAGS_OPTIMIZE_V = -O2 -ggdb3 -DNDEBUG +BINEXT?=.bin + +# This defines the operations performed on the linked executable. +# is currently required. +define bsp-post-link + $(OBJCOPY) -O binary --strip-all \ + $(basename $@)$(EXEEXT) $(basename $@)$(BINEXT) + $(SIZE) $(basename $@)$(EXEEXT) +endef diff --git a/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk_intram.cfg b/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk_intram.cfg new file mode 100644 index 0000000000..eb4a65fd55 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk_intram.cfg @@ -0,0 +1,20 @@ +# +# Config file for TMS570LS3137 board. +# + +include $(RTEMS_ROOT)/make/custom/default.cfg + +RTEMS_CPU = arm + +CPU_CFLAGS = -march=armv7-r -mthumb -mbig-endian + +CFLAGS_OPTIMIZE_V = -O2 -ggdb3 -DNDEBUG +BINEXT?=.bin + +# This defines the operations performed on the linked executable. +# is currently required. +define bsp-post-link + $(OBJCOPY) -O binary --strip-all \ + $(basename $@)$(EXEEXT) $(basename $@)$(BINEXT) + $(SIZE) $(basename $@)$(EXEEXT) +endef diff --git a/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk_sdram.cfg b/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk_sdram.cfg new file mode 100644 index 0000000000..eb4a65fd55 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/make/custom/tms570ls3137_hdk_sdram.cfg @@ -0,0 +1,20 @@ +# +# Config file for TMS570LS3137 board. +# + +include $(RTEMS_ROOT)/make/custom/default.cfg + +RTEMS_CPU = arm + +CPU_CFLAGS = -march=armv7-r -mthumb -mbig-endian + +CFLAGS_OPTIMIZE_V = -O2 -ggdb3 -DNDEBUG +BINEXT?=.bin + +# This defines the operations performed on the linked executable. +# is currently required. +define bsp-post-link + $(OBJCOPY) -O binary --strip-all \ + $(basename $@)$(EXEEXT) $(basename $@)$(BINEXT) + $(SIZE) $(basename $@)$(EXEEXT) +endef diff --git a/c/src/lib/libbsp/arm/tms570/pom/tms570-pom.c b/c/src/lib/libbsp/arm/tms570/pom/tms570-pom.c new file mode 100644 index 0000000000..6514368e55 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/pom/tms570-pom.c @@ -0,0 +1,53 @@ +/** + * @file tms570-pom.c + * + * @ingroup tms570 + * + * @brief TMS570 Parameter Overlay Module functions definitions. + */ + + /* + * Copyright (c) 2014 Pavel Pisa <pisa@cmp.felk.cvut.cz> + * + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <stdint.h> +#include <bsp/tms570-pom.h> +#include <bsp/linker-symbols.h> +#include <bsp.h> + +/** + * @brief remaps vector table + * + * transfer the rtems start vector table to address 0x0 + * + * @retval Void + */ +void tms570_pom_remap(void) +{ + int i; + uint32_t vec_overlay_start = 0x08000000; + + memcpy((void*)vec_overlay_start, bsp_start_vector_table_begin, 64); + + TMS570_POM.GLBCTRL = 0; + + for ( i = 0; i < TMS570_POM_REGIONS; ++i ) { + TMS570_POM.REG[i].REGSIZE = TMS570_POM_REGSIZE_DISABLED; + } + + TMS570_POM.REG[0].PROGSTART = 0x0 & TMS570_POM_REGADDRMASK; + TMS570_POM.REG[0].OVLSTART = vec_overlay_start & TMS570_POM_REGADDRMASK; + TMS570_POM.REG[0].REGSIZE = TMS570_POM_REGSIZE_64B; + + TMS570_POM.GLBCTRL = TMS570_POM_GLBCTRL_ENABLE | + (vec_overlay_start & ~TMS570_POM_REGADDRMASK); +} diff --git a/c/src/lib/libbsp/arm/tms570/preinstall.am b/c/src/lib/libbsp/arm/tms570/preinstall.am new file mode 100644 index 0000000000..81dbad1506 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/preinstall.am @@ -0,0 +1,123 @@ +## Automatically generated by ampolish3 - Do not edit + +if AMPOLISH3 +$(srcdir)/preinstall.am: Makefile.am + $(AMPOLISH3) $(srcdir)/Makefile.am > $(srcdir)/preinstall.am +endif + +PREINSTALL_DIRS = +DISTCLEANFILES += $(PREINSTALL_DIRS) + +all-local: $(TMPINSTALL_FILES) + +TMPINSTALL_FILES = +CLEANFILES = $(TMPINSTALL_FILES) + +all-am: $(PREINSTALL_FILES) + +PREINSTALL_FILES = +CLEANFILES += $(PREINSTALL_FILES) + +$(PROJECT_LIB)/$(dirstamp): + @$(MKDIR_P) $(PROJECT_LIB) + @: > $(PROJECT_LIB)/$(dirstamp) +PREINSTALL_DIRS += $(PROJECT_LIB)/$(dirstamp) + +$(PROJECT_INCLUDE)/$(dirstamp): + @$(MKDIR_P) $(PROJECT_INCLUDE) + @: > $(PROJECT_INCLUDE)/$(dirstamp) +PREINSTALL_DIRS += $(PROJECT_INCLUDE)/$(dirstamp) + +$(PROJECT_INCLUDE)/bsp/$(dirstamp): + @$(MKDIR_P) $(PROJECT_INCLUDE)/bsp + @: > $(PROJECT_INCLUDE)/bsp/$(dirstamp) +PREINSTALL_DIRS += $(PROJECT_INCLUDE)/bsp/$(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)/coverhd.h: ../../shared/include/coverhd.h $(PROJECT_INCLUDE)/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/coverhd.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/coverhd.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)/bsp/bootcard.h: ../../shared/include/bootcard.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/bootcard.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/bootcard.h + +$(PROJECT_INCLUDE)/bsp/utility.h: ../../shared/include/utility.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/utility.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/utility.h + +$(PROJECT_INCLUDE)/bsp/irq-generic.h: ../../shared/include/irq-generic.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/irq-generic.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/irq-generic.h + +$(PROJECT_INCLUDE)/bsp/irq-info.h: ../../shared/include/irq-info.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/irq-info.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/irq-info.h + +$(PROJECT_INCLUDE)/bsp/stackalloc.h: ../../shared/include/stackalloc.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/stackalloc.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/stackalloc.h + +$(PROJECT_INCLUDE)/bsp/uart-output-char.h: ../../shared/include/uart-output-char.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/uart-output-char.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/uart-output-char.h + +$(PROJECT_INCLUDE)/bsp/tod.h: ../../shared/tod.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/tod.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/tod.h + +$(PROJECT_INCLUDE)/bsp/start.h: ../shared/include/start.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/start.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/start.h + +$(PROJECT_INCLUDE)/bsp/tms570.h: include/tms570.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/tms570.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/tms570.h + +$(PROJECT_INCLUDE)/bsp/tms570-sci.h: include/tms570-sci.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/tms570-sci.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/tms570-sci.h + +$(PROJECT_INCLUDE)/bsp/irq.h: include/irq.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/irq.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/irq.h + +$(PROJECT_INCLUDE)/bsp/tms570-rti.h: include/tms570-rti.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/tms570-rti.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/tms570-rti.h + +$(PROJECT_INCLUDE)/bsp/tms570-vim.h: include/tms570-vim.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/tms570-vim.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/tms570-vim.h + +$(PROJECT_INCLUDE)/bsp/tms570-pom.h: include/tms570-pom.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/tms570-pom.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/tms570-pom.h + +$(PROJECT_INCLUDE)/bsp/tms570-sci-driver.h: include/tms570-sci-driver.h $(PROJECT_INCLUDE)/bsp/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/tms570-sci-driver.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/tms570-sci-driver.h + +$(PROJECT_INCLUDE)/tm27.h: ../../shared/include/tm27.h $(PROJECT_INCLUDE)/$(dirstamp) + $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/tm27.h +PREINSTALL_FILES += $(PROJECT_INCLUDE)/tm27.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 +TMPINSTALL_FILES += $(PROJECT_LIB)/linkcmds + diff --git a/c/src/lib/libbsp/arm/tms570/startup/bspreset.c b/c/src/lib/libbsp/arm/tms570/startup/bspreset.c new file mode 100644 index 0000000000..d47920c485 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/startup/bspreset.c @@ -0,0 +1,36 @@ +/** + * @file bspreset.c + * + * @ingroup tms570 + * + * @brief Reset code. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <rtems.h> + +#include <bsp/bootcard.h> +#include <bsp/tms570.h> +#include <bsp/start.h> + +BSP_START_TEXT_SECTION __attribute__( ( flatten ) ) void bsp_reset( void ) +{ + while ( true ) { + /* Do nothing */ + } +} diff --git a/c/src/lib/libbsp/arm/tms570/startup/bspstart.c b/c/src/lib/libbsp/arm/tms570/startup/bspstart.c new file mode 100644 index 0000000000..31ad1e7cc7 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/startup/bspstart.c @@ -0,0 +1,41 @@ +/** + * @file bspstart.c + * + * @ingroup tms570 + * + * @brief Startup code. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <bsp.h> +#include <bsp/tms570-pom.h> +#include <bsp/irq-generic.h> +#include <bsp/start.h> +#include <bsp/bootcard.h> + +void bsp_start( void ) +{ + /* set the cpu mode to supervisor and big endian */ + arm_cpu_mode = 0x213; + + tms570_pom_remap(); + + /* Interrupts */ + bsp_interrupt_initialize(); + +} diff --git a/c/src/lib/libbsp/arm/tms570/startup/bspstarthooks.c b/c/src/lib/libbsp/arm/tms570/startup/bspstarthooks.c new file mode 100644 index 0000000000..a9e189b6b8 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/startup/bspstarthooks.c @@ -0,0 +1,41 @@ +/** + * @file bspstarthooks.c + * + * @ingroup tms570 + * + * @brief First configurations and initializations to the correct + * functionality of the board. + */ + +/* + * Copyright (c) 2014 Premysl Houdek <kom541000@gmail.com> + * + * Google Summer of Code 2014 at + * Czech Technical University in Prague + * Zikova 1903/4 + * 166 36 Praha 6 + * Czech Republic + * + * Based on LPC24xx and LPC1768 BSP + * by embedded brains GmbH and others + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.org/license/LICENSE. + */ + +#include <bsp.h> +#include <bsp/start.h> + +BSP_START_TEXT_SECTION void bsp_start_hook_0( void ) +{ + ; +} + +BSP_START_TEXT_SECTION void bsp_start_hook_1( void ) +{ + bsp_start_copy_sections(); + bsp_start_clear_bss(); + + /* At this point we can use objects outside the .start section */ +} diff --git a/c/src/lib/libbsp/arm/tms570/startup/linkcmds.tms570ls3137_hdk b/c/src/lib/libbsp/arm/tms570/startup/linkcmds.tms570ls3137_hdk new file mode 100644 index 0000000000..e02dcd6e06 --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/startup/linkcmds.tms570ls3137_hdk @@ -0,0 +1,27 @@ + +MEMORY { + ROM_INT (RX) : ORIGIN = 0x00000000, LENGTH = 3M + RAM_INT (AIW) : ORIGIN = 0x08000000, LENGTH = 256k + RAM_EXT (AIWX) : ORIGIN = 0x80000000, LENGTH = 8M +} + +REGION_ALIAS ("REGION_START", ROM_INT); +REGION_ALIAS ("REGION_VECTOR", RAM_INT); +REGION_ALIAS ("REGION_TEXT", ROM_INT); +REGION_ALIAS ("REGION_TEXT_LOAD", ROM_INT); +REGION_ALIAS ("REGION_RODATA", ROM_INT); +REGION_ALIAS ("REGION_RODATA_LOAD", ROM_INT); +REGION_ALIAS ("REGION_DATA", RAM_INT); +REGION_ALIAS ("REGION_DATA_LOAD", ROM_INT); +REGION_ALIAS ("REGION_FAST_TEXT", RAM_INT); +REGION_ALIAS ("REGION_FAST_TEXT_LOAD", ROM_INT); +REGION_ALIAS ("REGION_FAST_DATA", RAM_INT); +REGION_ALIAS ("REGION_FAST_DATA_LOAD", ROM_INT); +REGION_ALIAS ("REGION_BSS", RAM_INT); +REGION_ALIAS ("REGION_WORK", RAM_INT); +REGION_ALIAS ("REGION_STACK", RAM_INT); + +bsp_stack_main_size = DEFINED (bsp_stack_main_size) ? bsp_stack_main_size : 1024; +bsp_stack_main_size = ALIGN (bsp_stack_main_size, bsp_stack_align); + +INCLUDE linkcmds.armv4 diff --git a/c/src/lib/libbsp/arm/tms570/startup/linkcmds.tms570ls3137_hdk_intram b/c/src/lib/libbsp/arm/tms570/startup/linkcmds.tms570ls3137_hdk_intram new file mode 100644 index 0000000000..19bb7b2fcd --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/startup/linkcmds.tms570ls3137_hdk_intram @@ -0,0 +1,28 @@ + +MEMORY { + ROM_INT (RX) : ORIGIN = 0x00000000, LENGTH = 3M + RAM_INT_VEC : ORIGIN = 0x08000000, LENGTH = 1k + RAM_INT (AIWX) : ORIGIN = 0x08000400, LENGTH = 256k - 1k + RAM_EXT (AIW) : ORIGIN = 0x80000000, LENGTH = 8M +} + +REGION_ALIAS ("REGION_START", RAM_INT); +REGION_ALIAS ("REGION_VECTOR", RAM_INT); +REGION_ALIAS ("REGION_TEXT", RAM_INT); +REGION_ALIAS ("REGION_TEXT_LOAD", RAM_INT); +REGION_ALIAS ("REGION_RODATA", RAM_INT); +REGION_ALIAS ("REGION_RODATA_LOAD", RAM_INT); +REGION_ALIAS ("REGION_DATA", RAM_INT); +REGION_ALIAS ("REGION_DATA_LOAD", RAM_INT); +REGION_ALIAS ("REGION_FAST_TEXT", RAM_INT); +REGION_ALIAS ("REGION_FAST_TEXT_LOAD", RAM_INT); +REGION_ALIAS ("REGION_FAST_DATA", RAM_INT); +REGION_ALIAS ("REGION_FAST_DATA_LOAD", RAM_INT); +REGION_ALIAS ("REGION_BSS", RAM_INT); +REGION_ALIAS ("REGION_WORK", RAM_INT); +REGION_ALIAS ("REGION_STACK", RAM_INT); + +bsp_stack_main_size = DEFINED (bsp_stack_main_size) ? bsp_stack_main_size : 1024; +bsp_stack_main_size = ALIGN (bsp_stack_main_size, bsp_stack_align); + +INCLUDE linkcmds.armv4 diff --git a/c/src/lib/libbsp/arm/tms570/startup/linkcmds.tms570ls3137_hdk_sdram b/c/src/lib/libbsp/arm/tms570/startup/linkcmds.tms570ls3137_hdk_sdram new file mode 100644 index 0000000000..110179ff6b --- /dev/null +++ b/c/src/lib/libbsp/arm/tms570/startup/linkcmds.tms570ls3137_hdk_sdram @@ -0,0 +1,27 @@ + +MEMORY { + ROM_INT (RX) : ORIGIN = 0x00000000, LENGTH = 3M + RAM_INT (AIW) : ORIGIN = 0x08000000, LENGTH = 256k + RAM_EXT (AIWX) : ORIGIN = 0x80000000, LENGTH = 8M +} + +REGION_ALIAS ("REGION_START", RAM_EXT); +REGION_ALIAS ("REGION_VECTOR", RAM_EXT); +REGION_ALIAS ("REGION_TEXT", RAM_EXT); +REGION_ALIAS ("REGION_TEXT_LOAD", RAM_EXT); +REGION_ALIAS ("REGION_RODATA", RAM_EXT); +REGION_ALIAS ("REGION_RODATA_LOAD", RAM_EXT); +REGION_ALIAS ("REGION_DATA", RAM_EXT); +REGION_ALIAS ("REGION_DATA_LOAD", RAM_EXT); +REGION_ALIAS ("REGION_FAST_TEXT", RAM_EXT); +REGION_ALIAS ("REGION_FAST_TEXT_LOAD", RAM_EXT); +REGION_ALIAS ("REGION_FAST_DATA", RAM_EXT); +REGION_ALIAS ("REGION_FAST_DATA_LOAD", RAM_EXT); +REGION_ALIAS ("REGION_BSS", RAM_EXT); +REGION_ALIAS ("REGION_WORK", RAM_EXT); +REGION_ALIAS ("REGION_STACK", RAM_EXT); + +bsp_stack_main_size = DEFINED (bsp_stack_main_size) ? bsp_stack_main_size : 1024; +bsp_stack_main_size = ALIGN (bsp_stack_main_size, bsp_stack_align); + +INCLUDE linkcmds.armv4 |