From: arighi Date: Wed, 28 Apr 2010 20:24:51 +0000 (+0000) Subject: lm3s8962: add an example application for this specific board. X-Git-Tag: 2.5.0~340 X-Git-Url: https://codewiz.org/gitweb?p=bertos.git;a=commitdiff_plain;h=d6386a161215035692e755d0e4ea44d96d2e7e84 lm3s8962: add an example application for this specific board. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3568 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/Makefile b/Makefile index d7ec603f..44600dd6 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ include examples/demo/demo.mk #include examples/at91sam7/at91sam7s.mk #include examples/at91sam7/at91sam7x.mk #include examples/lm3s1968/lm3s1968.mk +#include examples/lm3s8962/lm3s8962.mk #include examples/develgps/develgps.mk #include examples/lpc2378/lpc2378.mk #include examples/avr-kern/avr-kern.mk diff --git a/examples/lm3s8962/cfg/cfg_debug.h b/examples/lm3s8962/cfg/cfg_debug.h new file mode 100644 index 00000000..ef7c4a75 --- /dev/null +++ b/examples/lm3s8962/cfg/cfg_debug.h @@ -0,0 +1,53 @@ +/** + * \file + * + * + * \brief Configuration file for Debug module. + * + * \author Daniele Basile + */ + +#ifndef CFG_DEBUG_H +#define CFG_DEBUG_H + +/** + * Debug console port. + * $WIZ$ type = "int"; min = 0 + */ +#define CONFIG_KDEBUG_PORT 0 + +/** + * Baudrate for the debug console. + * $WIZ$ type = "int"; min = 300 + */ +#define CONFIG_KDEBUG_BAUDRATE 115200UL + +#endif /* CFG_DEBUG_H */ diff --git a/examples/lm3s8962/cfg/cfg_gfx.h b/examples/lm3s8962/cfg/cfg_gfx.h new file mode 100644 index 00000000..8d8b6fa2 --- /dev/null +++ b/examples/lm3s8962/cfg/cfg_gfx.h @@ -0,0 +1,74 @@ +/** + * \file + * + * + * \brief Configuration file for GFX module. + * + * \version $Id$ + * + * \author Daniele Basile + */ + +#ifndef CFG_GFX_H +#define CFG_GFX_H + +/// Enable line clipping algorithm. +#define CONFIG_GFX_CLIPPING 1 + +/// Enable text rendering in bitmaps. +#define CONFIG_GFX_TEXT 1 + +/// Enable virtual coordinate system. +#define CONFIG_GFX_VCOORDS 1 + +/// Select bitmap pixel format. +#define CONFIG_BITMAP_FMT BITMAP_FMT_PLANAR_V_LSB + + +#define CONFIG_CHART_TYPE_X uint8_t ///< Type for the chart dataset +#define CONFIG_CHART_TYPE_Y uint8_t ///< Type for the chart dataset + + +/// Enable button bar behind menus +#define CONFIG_MENU_MENUBAR 0 + +/// Level Edit Timeout +#define CONFIG_LEVELEDIT_TIMEOUT 0 + +/// Menu timeout +#define CONFIG_MENU_TIMEOUT 0 + +/// Enable smooth scrolling in menus +#define CONFIG_MENU_SMOOTH 1 + + +#endif /* CFG_GFX_H */ + diff --git a/examples/lm3s8962/cfg/cfg_heap.h b/examples/lm3s8962/cfg/cfg_heap.h new file mode 100644 index 00000000..7d080012 --- /dev/null +++ b/examples/lm3s8962/cfg/cfg_heap.h @@ -0,0 +1,49 @@ +/** + * \file + * + * + * \brief Configuration file for heap module. + * + * \author Daniele Basile + */ + +#ifndef CFG_HEAP_H +#define CFG_HEAP_H + +/** + * Enable malloc/free like API. + * $WIZ$ type = "boolean" + */ +#define CONFIG_HEAP_MALLOC 1 + +#endif /* CFG_HEAP_H */ + + diff --git a/examples/lm3s8962/cfg/cfg_kfile.h b/examples/lm3s8962/cfg/cfg_kfile.h new file mode 100644 index 00000000..1b1989c9 --- /dev/null +++ b/examples/lm3s8962/cfg/cfg_kfile.h @@ -0,0 +1,62 @@ +/** + * \file + * + * + * \brief Configuration file for KFile interface module. + * + * \version $Id$ + * \author Daniele Basile + */ + +#ifndef CFG_KFILE_H +#define CFG_KFILE_H + +/** + * Module logging level. + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_level" + */ +#define KFILE_LOG_LEVEL LOG_LVL_INFO + +/** + * Module logging format. + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_format" + */ +#define KFILE_LOG_FORMAT LOG_FMT_TERSE + +/** + * Enable the gets function with echo. + * $WIZ$ type = "boolean" + */ +#define CONFIG_KFILE_GETS 1 + +#endif /* CFG_KFILE_H */ diff --git a/examples/lm3s8962/cfg/cfg_lcd.h b/examples/lm3s8962/cfg/cfg_lcd.h new file mode 100644 index 00000000..d48fa5df --- /dev/null +++ b/examples/lm3s8962/cfg/cfg_lcd.h @@ -0,0 +1,68 @@ +/** + * \file + * + * + * \brief Configuration file for lcd display module. + */ + +#ifndef CFG_LCD_H +#define CFG_LCD_H + +/** + * Use 4 bit addressing mode. + * $WIZ$ type = "boolean" + */ +#define CONFIG_LCD_4BIT 0 + +/** + * Use a table to speed up LCD memory addressing. + * This will use about 100 bytes of RAM. + * $WIZ$ type = "boolean" + */ +#define CONFIG_LCD_ADDRESS_FAST 0 + +/** + * LCD setting for 32122A (AVR implementation). + * $WIZ$ type = "boolean" + * $WIZ$ supports = "avr and False" + */ +#define CONFIG_LCD_SOFTINT_REFRESH 0 + +/** + * LCD setting for 32122A (AVR implementation). + * $WIZ$ type = "boolean" + * $WIZ$ supports = "avr and False" + */ +#define CONFIG_LCD_WAIT 0 + + +#endif /* CFG_LCD_H */ + diff --git a/examples/lm3s8962/cfg/cfg_monitor.h b/examples/lm3s8962/cfg/cfg_monitor.h new file mode 100644 index 00000000..d0e24da4 --- /dev/null +++ b/examples/lm3s8962/cfg/cfg_monitor.h @@ -0,0 +1,47 @@ +/** + * \file + * + * + * \brief Kernel monitor configuration parameters + * + * \author Bernie Innocenti + */ + +#ifndef CFG_MONITOR_H +#define CFG_MONITOR_H + +/** + * Process monitor. + * $WIZ$ type = "autoenabled" + */ +#define CONFIG_KERN_MONITOR 1 + +#endif /* CFG_MONITOR_H */ diff --git a/examples/lm3s8962/cfg/cfg_proc.h b/examples/lm3s8962/cfg/cfg_proc.h new file mode 100644 index 00000000..eb5506b4 --- /dev/null +++ b/examples/lm3s8962/cfg/cfg_proc.h @@ -0,0 +1,107 @@ +/** + * \file + * + * + * \brief Kernel configuration parameters + * + * \author Bernie Innocenti + */ + +#ifndef CFG_PROC_H +#define CFG_PROC_H + +/** + * Enable the multithreading kernel. + * + * $WIZ$ type = "autoenabled" + */ +#define CONFIG_KERN 1 + +/** + * Kernel interrupt supervisor. WARNING: Experimental, still incomplete! + * $WIZ$ type = "boolean" + * $WIZ$ supports = "False" + */ +#define CONFIG_KERN_IRQ 0 + +/** + * Preemptive process scheduling. + * + * $WIZ$ type = "boolean" + * $WIZ$ conditional_deps = "timer" + */ +#define CONFIG_KERN_PREEMPT 1 + +/** + * Time sharing quantum (a prime number prevents interference effects) [ms]. + * + * $WIZ$ type = "int" + * $WIZ$ min = 1 + */ +#define CONFIG_KERN_QUANTUM 11 + +/** + * Priority-based scheduling policy. + * $WIZ$ type = "boolean" + */ +#define CONFIG_KERN_PRI 1 + +/** + * Dynamic memory allocation for processes. + * $WIZ$ type = "boolean" + * $WIZ$ conditional_deps = "heap" + */ +#define CONFIG_KERN_HEAP 1 + +/** + * Size of the dynamic memory pool used by processes. + * $WIZ$ type = "int" + * $WIZ$ min = 0 + */ +#define CONFIG_KERN_HEAP_SIZE 16384L + +/** + * Module logging level. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_level" + */ +#define KERN_LOG_LEVEL LOG_LVL_ERR + +/** + * Module logging format. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "log_format" + */ +#define KERN_LOG_FORMAT LOG_FMT_VERBOSE + +#endif /* CFG_PROC_H */ diff --git a/examples/lm3s8962/cfg/cfg_sem.h b/examples/lm3s8962/cfg/cfg_sem.h new file mode 100644 index 00000000..51811da4 --- /dev/null +++ b/examples/lm3s8962/cfg/cfg_sem.h @@ -0,0 +1,47 @@ +/** + * \file + * + * + * \brief Kernel semaphores configuration parameters. + * + * \author Bernie Innocenti + */ + +#ifndef CFG_SEM_H +#define CFG_SEM_H + +/** + * Re-entrant mutual exclusion primitives. + * $WIZ$ type = "autoenabled" + */ +#define CONFIG_KERN_SEMAPHORES 0 + +#endif /* CFG_SEM_H */ diff --git a/examples/lm3s8962/cfg/cfg_ser.h b/examples/lm3s8962/cfg/cfg_ser.h new file mode 100644 index 00000000..91a10e0b --- /dev/null +++ b/examples/lm3s8962/cfg/cfg_ser.h @@ -0,0 +1,222 @@ +/** + * \file + * + * + * \brief Configuration file for serial module. + * + * \author Daniele Basile + */ + +#ifndef CFG_SER_H +#define CFG_SER_H + +/** + * Example of setting for serial port and + * spi port. + * Edit these define for your project. + */ + +/** + * Size of the outbound FIFO buffer for port 0 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + */ +#define CONFIG_UART0_TXBUFSIZE 32 + +/** + * Size of the inbound FIFO buffer for port 0 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + */ +#define CONFIG_UART0_RXBUFSIZE 32 + +/** + * Size of the outbound FIFO buffer for port 1 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "lm3s or lpc2 or (at91 and not atmega8 and not atmega168 and not atmega32)" + */ +#define CONFIG_UART1_TXBUFSIZE 32 + +/** + * Size of the inbound FIFO buffer for port 1 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "lm3s or lpc2 or (at91 and not atmega8 and not atmega168 and not atmega32)" + */ +#define CONFIG_UART1_RXBUFSIZE 32 + +/** + * Size of the outbound FIFO buffer for port 2 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "lm3s or lpc2" + */ +#define CONFIG_UART2_TXBUFSIZE 32 + +/** + * Size of the inbound FIFO buffer for port 2 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "lm3s or lpc2" + */ +#define CONFIG_UART2_RXBUFSIZE 32 + +/** + * Size of the outbound FIFO buffer for port 3 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "lpc2" + */ +#define CONFIG_UART3_TXBUFSIZE 32 + +/** + * Size of the inbound FIFO buffer for port 3 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "lpc2" + */ +#define CONFIG_UART3_RXBUFSIZE 32 + + +/** + * Size of the outbound FIFO buffer for SPI port [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "avr" + */ +#define CONFIG_SPI_TXBUFSIZE 32 + +/** + * Size of the inbound FIFO buffer for SPI port [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "avr" + */ +#define CONFIG_SPI_RXBUFSIZE 32 + +/** + * Size of the outbound FIFO buffer for SPI port 0 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "at91" + */ +#define CONFIG_SPI0_TXBUFSIZE 32 + +/** + * Size of the inbound FIFO buffer for SPI port 0 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "at91" + */ +#define CONFIG_SPI0_RXBUFSIZE 32 + +/** + * Size of the outbound FIFO buffer for SPI port 1 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "at91" + */ +#define CONFIG_SPI1_TXBUFSIZE 32 + +/** + * Size of the inbound FIFO buffer for SPI port 1 [bytes]. + * $WIZ$ type = "int" + * $WIZ$ min = 2 + * $WIZ$ supports = "at91" + */ +#define CONFIG_SPI1_RXBUFSIZE 32 + +/** + * SPI data order. + * + * $WIZ$ type = "enum" + * $WIZ$ value_list = "ser_order_bit" + * $WIZ$ supports = "avr" + */ +#define CONFIG_SPI_DATA_ORDER SER_MSB_FIRST + +/** + * SPI clock division factor. + * $WIZ$ type = "int" + * $WIZ$ supports = "avr" + */ +#define CONFIG_SPI_CLOCK_DIV 16 + +/** + * SPI clock polarity: normal low or normal high. + * $WIZ$ type = "enum" + * $WIZ$ value_list = "ser_spi_pol" + * $WIZ$ supports = "avr" + */ +#define CONFIG_SPI_CLOCK_POL SPI_NORMAL_LOW + +/** + * SPI clock phase you can choose sample on first edge or + * sample on second clock edge. + * $WIZ$ type = "enum" + * $WIZ$ value_list = "ser_spi_phase" + * $WIZ$ supports = "avr" + */ +#define CONFIG_SPI_CLOCK_PHASE SPI_SAMPLE_ON_FIRST_EDGE + +/** + * Default transmit timeout (ms). Set to -1 to disable timeout support. + * $WIZ$ type = "int" + * $WIZ$ min = -1 + */ +#define CONFIG_SER_TXTIMEOUT -1 + +/** + * Default receive timeout (ms). Set to -1 to disable timeout support. + * $WIZ$ type = "int" + * $WIZ$ min = -1 + */ +#define CONFIG_SER_RXTIMEOUT -1 + +/** + * Use RTS/CTS handshake. + * $WIZ$ type = "boolean" + * $WIZ$ supports = "False" + */ +#define CONFIG_SER_HWHANDSHAKE 0 + +/** + * Default baudrate for all serial ports (set to 0 to disable). + * $WIZ$ type = "int" + * $WIZ$ min = 0 + */ +#define CONFIG_SER_DEFBAUDRATE 0UL + +/// Enable strobe pin for debugging serial interrupt. $WIZ$ type = "boolean" +#define CONFIG_SER_STROBE 0 + +#endif /* CFG_SER_H */ diff --git a/examples/lm3s8962/cfg/cfg_signal.h b/examples/lm3s8962/cfg/cfg_signal.h new file mode 100644 index 00000000..ce5324ec --- /dev/null +++ b/examples/lm3s8962/cfg/cfg_signal.h @@ -0,0 +1,47 @@ +/** + * \file + * + * + * \brief Kernel signals configuration parameters + * + * \author Bernie Innocenti + */ + +#ifndef CFG_SIGNAL_H +#define CFG_SIGNAL_H + +/** + * Inter-process signals. + * $WIZ$ type = "autoenabled" + */ +#define CONFIG_KERN_SIGNALS 1 + +#endif /* CFG_SIGNAL_H */ diff --git a/examples/lm3s8962/cfg/cfg_timer.h b/examples/lm3s8962/cfg/cfg_timer.h new file mode 100644 index 00000000..ae1a60b9 --- /dev/null +++ b/examples/lm3s8962/cfg/cfg_timer.h @@ -0,0 +1,66 @@ +/** + * \file + * + * + * \brief Configuration file for timer module. + * + * \author Daniele Basile + */ + +#ifndef CFG_TIMER_H +#define CFG_TIMER_H + +/** + * Hardware timer selection for drv/timer.c. + * $WIZ$ type = "enum" + * $WIZ$ value_list = "timer_select" + */ +#define CONFIG_TIMER TIMER_DEFAULT + +/** + * Debug timer interrupt using a strobe pin. + * $WIZ$ type = "boolean" + */ +#define CONFIG_TIMER_STROBE 0 + +/** + * Enable asynchronous timers. + * $WIZ$ type = "boolean" + */ +#define CONFIG_TIMER_EVENTS 1 + +/** + * Support hi-res timer_usleep(). + * $WIZ$ type = "boolean" + */ +#define CONFIG_TIMER_UDELAY 1 + +#endif /* CFG_TIMER_H */ diff --git a/examples/lm3s8962/hw/hw_kbd.h b/examples/lm3s8962/hw/hw_kbd.h new file mode 100644 index 00000000..d47d8863 --- /dev/null +++ b/examples/lm3s8962/hw/hw_kbd.h @@ -0,0 +1,78 @@ +/** + * \file + * + * + * \brief LM3S1968 keypad: hardware-specific definitions + * + * \author Andrea Righi + */ + +#ifndef HW_KBD_H +#define HW_KBD_H + +#include /* BV() */ +#include /* GPIO_PORTG_BASE */ +#include /* lm3s_busyWait() */ +#include /* lm3s_gpioPinConfig() / lm3s_gpioPinRead() */ +#include "hw/kbd_map.h" + +#define K_RPT_MASK (K_UP | K_DOWN | K_LEFT | K_RIGHT) + +#define KBD_HW_INIT \ + do { \ + /* Enable the peripheral clock */ \ + SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOE; \ + SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; \ + lm3s_busyWait(512); \ + lm3s_gpioPinConfig(GPIO_PORTE_BASE, \ + BV(3) | BV(2) | BV(1) | BV(0), \ + GPIO_DIR_MODE_IN, \ + GPIO_STRENGTH_2MA, \ + GPIO_PIN_TYPE_STD_WPU); \ + lm3s_gpioPinConfig(GPIO_PORTF_BASE, \ + BV(1), \ + GPIO_DIR_MODE_IN, \ + GPIO_STRENGTH_2MA, \ + GPIO_PIN_TYPE_STD_WPU); \ + } while (0) + +/** + * Read the keyboard ports and return the mask of depressed keys. + */ +INLINE keymask_t kbd_readkeys(void) +{ + return ~(lm3s_gpioPinRead(GPIO_PORTE_BASE, + BV(3) | BV(2) | BV(1) | BV(0)) | + lm3s_gpioPinRead(GPIO_PORTF_BASE, BV(1)) << 3); + +} + +#endif /* HW_KBD_H */ diff --git a/examples/lm3s8962/hw/hw_rit128x96.h b/examples/lm3s8962/hw/hw_rit128x96.h new file mode 100644 index 00000000..c857bda9 --- /dev/null +++ b/examples/lm3s8962/hw/hw_rit128x96.h @@ -0,0 +1,121 @@ +/** + * \file + * + * + * \brief LM3S1986: OLED-RIT-128x96 (P14201) low-level hardware macros + * + * \author Andrea Righi + */ + +#ifndef HW_RIT128x96_H +#define HW_RIT128x96_H + +#include "cfg/macros.h" /* BV() */ +#include "cfg/debug.h" + +#include +#include +#include + +#include +#include +#include + +/** + * \name LCD I/O pins/ports + * @{ + */ +/* OLED Data/Command control pin */ +#define GPIO_OLEDDC_PIN BV(6) + +/* OLED enable pin */ +#define GPIO_OLEDEN_PIN BV(7) +/*@}*/ + +/** + * \name LCD bus control macros + * @{ + */ +/* Enter command mode */ +#define LCD_SET_COMMAND() \ + lm3s_gpioPinWrite(GPIO_PORTA_BASE, GPIO_OLEDDC_PIN, 0) + +/* Enter data mode */ +#define LCD_SET_DATA() \ + lm3s_gpioPinWrite(GPIO_PORTA_BASE, GPIO_OLEDDC_PIN, GPIO_OLEDDC_PIN) + +/* Send data to the display */ +#define LCD_WRITE(x) \ + { \ + uint32_t _x; \ + while (!lm3s_ssiWriteFrameNonBlocking(SSI0_BASE, x)); \ + /* Dummy read to drain the FIFO */ \ + while (!lm3s_ssiReadFrameNonBlocking(SSI0_BASE, &_x)); \ + } +/*@}*/ + +INLINE void lcd_bus_init(void) +{ + uint32_t dummy; + + /* Enable the peripheral clock */ + SYSCTL_RCGC1_R |= SYSCTL_RCGC1_SSI0; + SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOA; + lm3s_busyWait(512); + + /* Configure the SSI0CLK SSI0FS and SSI0TX pins for SSI operation. */ + lm3s_gpioPinConfig(GPIO_PORTA_BASE, BV(2) | BV(3) | BV(5), + GPIO_DIR_MODE_HW, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD_WPU); + /* + * Configure the GPIO port pin used as a D/C# signal (data/command + * control) for OLED device, and the port pin used to enable power to + * the OLED panel. + */ + lm3s_gpioPinConfig(GPIO_PORTA_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN, + GPIO_DIR_MODE_OUT, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD); + lm3s_gpioPinWrite(GPIO_PORTA_BASE, GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN, + GPIO_OLEDDC_PIN | GPIO_OLEDEN_PIN); + + /* Configure the SSI0 port for master mode */ + lm3s_ssiOpen(SSI0_BASE, SSI_FRF_MOTO_MODE_2, + SSI_MODE_MASTER, CPU_FREQ / 2, 8); + + /* Drain the SSI RX FIFO */ + while (lm3s_ssiReadFrameNonBlocking(SSI0_BASE, &dummy)); +} + +/* + * XXX: menu stuff requires lcd_blitBimap() function to be defined. + * Find a better way to do this. + */ +#define rit128x96_blitBitmap lcd_blitBitmap + +#endif /* HW_RIT128x96_H */ diff --git a/examples/lm3s8962/hw/kbd_map.h b/examples/lm3s8962/hw/kbd_map.h new file mode 100644 index 00000000..5493410c --- /dev/null +++ b/examples/lm3s8962/hw/kbd_map.h @@ -0,0 +1,65 @@ +/** + * \file + * + * + * \brief Keyboard map definitions. + * + * \author Andrea Righi + */ + +#ifndef HW_KBD_MAP_H +#define HW_KBD_MAP_H + +#include + +/** + * Type for keyboard mask. + */ +typedef uint16_t keymask_t; + +/** + * \name Keycodes. + */ +/*@{*/ +#define K_UP BV(0) +#define K_DOWN BV(1) +#define K_LEFT BV(2) +#define K_RIGHT BV(3) +#define K_OK BV(4) +#define K_CANCEL BV(8) + +#define K_REPEAT BV(13) /**< This is a repeated keyevent. */ +#define K_TIMEOUT BV(14) /**< Fake key event for timeouts. */ +#define K_LONG BV(15) +/*@}*/ + +#define K_LNG_MASK 0 + +#endif /* HW_KBD_MAP_H */ diff --git a/examples/lm3s8962/lm3s8962.c b/examples/lm3s8962/lm3s8962.c new file mode 100644 index 00000000..cb1200c9 --- /dev/null +++ b/examples/lm3s8962/lm3s8962.c @@ -0,0 +1,366 @@ +/** + * \file + * + * + * \brief LM3S8962 Cortex-M3 testcase + * + * \author Andrea Righi + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cfg/compiler.h" +#include "cfg/cfg_gfx.h" + +#include "hw/hw_rit128x96.h" + +#define PROC_STACK_SIZE KERN_MINSTACKSIZE * 2 + +#if CONFIG_KERN_HEAP +#define hp_stack NULL +#define lp_stack NULL +#define ser_stack NULL +#define led_stack NULL +#else +static PROC_DEFINE_STACK(hp_stack, PROC_STACK_SIZE); +static PROC_DEFINE_STACK(lp_stack, PROC_STACK_SIZE); +static PROC_DEFINE_STACK(ser_stack, PROC_STACK_SIZE); +static PROC_DEFINE_STACK(led_stack, PROC_STACK_SIZE); +#endif + +extern Font font_gohu; +static uint8_t raster[RAST_SIZE(LCD_WIDTH, LCD_HEIGHT)]; +static Bitmap lcd_bitmap; + +#define KEY_MASK (K_UP | K_DOWN | K_LEFT | K_RIGHT | K_OK) + +static Process *hp_proc, *lp_proc, *led_proc; +static hptime_t start, end; + +static Serial ser_port; + +static void led_init(void) +{ + /* Enable the GPIO port that is used for the on-board LED */ + SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF; + /* + * Perform a dummy read to insert a few cycles delay before enabling + * the peripheral. + */ + (void)SYSCTL_RCGC2_R; + /* Enable the GPIO pin for the LED */ + GPIO_PORTF_DIR_R = 0x01; + GPIO_PORTF_DEN_R = 0x01; +} + +INLINE void led_on(void) +{ + GPIO_PORTF_DATA_R |= 0x01; +} + +INLINE void led_off(void) +{ + GPIO_PORTF_DATA_R &= ~0x01; +} + +static bool led_blinking; + +static void NORETURN led_process(void) +{ + int i; + + for (i = 0; ; i++) + { + if (!led_blinking) + { + led_off(); + sig_wait(SIG_USER0); + } + if (i & 1) + led_on(); + else + led_off(); + timer_delay(50); + } +} + +static void led_test(UNUSED_ARG(Bitmap *, bm)) +{ + led_blinking = !led_blinking; + sig_send(led_proc, SIG_USER0); +} + +static void bouncing_logo(Bitmap *bm) +{ + const long SPEED_SCALE = 1000; + const long GRAVITY_ACCEL = 100; + const long BOUNCE_ELASTICITY = 1; + long h = (long)(-bertos_logo.height) * SPEED_SCALE; + long speed = 0, i; + + for (i = 0; ; i++) + { + /* Move */ + h += speed; + + /* Gravity acceleration */ + speed += GRAVITY_ACCEL; + + if (h > 0 && speed > 0) + { + /* Bounce */ + speed = -(speed / BOUNCE_ELASTICITY); + + } + /* Update graphics */ + gfx_bitmapClear(bm); + gfx_blitImage(bm, + (LCD_WIDTH - bertos_logo.width) / 2, + (LCD_HEIGHT - bertos_logo.height) / 2 + h / SPEED_SCALE, + &bertos_logo); + text_xprintf(bm, 7, 0, TEXT_FILL | TEXT_CENTER, "Press SELECT to quit"); + rit128x96_blitBitmap(bm); + timer_delay(5); + if (kbd_peek() & KEY_MASK) + break; + } +} + +static void screen_saver(Bitmap *bm) +{ + int x1, y1, x2, y2; + int i; + + for (i = 0; ; i++) + { + x1 = i % LCD_WIDTH; + y1 = i % LCD_HEIGHT; + + x2 = LCD_WIDTH - i % LCD_WIDTH; + y2 = LCD_HEIGHT - i % LCD_HEIGHT; + + gfx_bitmapClear(bm); + gfx_rectDraw(bm, x1, y1, x2, y2); + rit128x96_blitBitmap(bm); + if (kbd_peek() & KEY_MASK) + break; + } +} + +INLINE hptime_t get_hp_ticks(void) +{ + return (TIMER_HW_CNT - timer_hw_hpread()) + + timer_clock_unlocked() * TIMER_HW_CNT; +} + +static void NORETURN hp_process(void) +{ + while (1) + { + sig_wait(SIG_USER0); + end = get_hp_ticks(); + timer_delay(100); + sig_send(lp_proc, SIG_USER0); + } +} + +static void NORETURN lp_process(void) +{ + while (1) + { + start = get_hp_ticks(); + sig_send(hp_proc, SIG_USER0); + sig_wait(SIG_USER0); + } +} + +static void res_process(void) +{ + const char spinner[] = {'/', '-', '\\', '|'}; + int i; + char c; + + for (i = 0; ; i++) + { + /* Show context switch (in clock cycles) */ + c = spinner[i % countof(spinner)]; + text_xprintf(&lcd_bitmap, 3, 0, TEXT_CENTER | TEXT_FILL, "%c Context switch %c", c, c); + text_xprintf(&lcd_bitmap, 5, 0, TEXT_FILL, " %lu clock cycles", end - start); + /* Show context switch (in usec) */ + text_xprintf(&lcd_bitmap, 6, 0, TEXT_FILL, + " %lu.%lu usec", + ((end - start) * 1000000) / CPU_FREQ, + ((end - start) * (100000000 / CPU_FREQ)) % 100); + rit128x96_blitBitmap(&lcd_bitmap); + timer_delay(5); + if (kbd_peek() & KEY_MASK) + break; + } +} + +static void context_switch_test(Bitmap *bm) +{ + gfx_bitmapClear(bm); + text_xprintf(bm, 0, 0, TEXT_FILL, + "CPU: Cortex-M3 %luMHz", CPU_FREQ / 1000000); + rit128x96_blitBitmap(bm); + text_xprintf(bm, 1, 0, TEXT_FILL, "Board: LM3S8962 EVB"); + rit128x96_blitBitmap(bm); + + res_process(); +} + +static void uptime(Bitmap *bm) +{ + extern const Font font_luBS14; + const Font *old_font; + + old_font = bm->font; + + /* Set big font */ + gfx_bitmapClear(bm); + gfx_setFont(bm, &font_luBS14); + text_xprintf(bm, 0, 0, TEXT_FILL | TEXT_CENTER, "Uptime"); + while (1) + { + ticks_t clock = ticks_to_ms(timer_clock_unlocked()); + + /* Display uptime (in ticks) */ + text_xprintf(&lcd_bitmap, 2, 0, TEXT_FILL | TEXT_CENTER, + "%lu", clock / 1000); + rit128x96_blitBitmap(bm); + timer_delay(5); + if (kbd_peek() & KEY_MASK) + break; + } + gfx_setFont(bm, old_font); +} + +static void NORETURN soft_reset(Bitmap * bm) +{ + extern const Font font_luBS14; + int i; + + /* Set big font */ + gfx_bitmapClear(bm); + gfx_setFont(bm, &font_luBS14); + for (i = 5; i; --i) + { + text_xprintf(bm, 2, 0, TEXT_FILL | TEXT_CENTER, "%d", i); + rit128x96_blitBitmap(bm); + timer_delay(1000); + } + text_xprintf(bm, 2, 0, TEXT_FILL | TEXT_CENTER, "REBOOT"); + rit128x96_blitBitmap(bm); + timer_delay(1000); + + /* Perform a software reset request */ + HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | NVIC_APINT_SYSRESETREQ; + UNREACHABLE(); +} + +static void NORETURN ser_process(void) +{ + char buf[32]; + int i; + + ser_init(&ser_port, SER_UART0); + ser_setbaudrate(&ser_port, 115200); + + /* BeRTOS terminal */ + for (i = 0; ; i++) + { + kfile_printf(&ser_port.fd, "\n\r[%03d] BeRTOS:~$ ", i); + kfile_gets_echo(&ser_port.fd, buf, sizeof(buf), true); + kfile_printf(&ser_port.fd, "%s", buf); + } +} + +static struct MenuItem main_items[] = +{ + { (const_iptr_t)"LED blinking", 0, (MenuHook)led_test, (iptr_t)&lcd_bitmap }, + { (const_iptr_t)"Bouncing logo", 0, (MenuHook)bouncing_logo, (iptr_t)&lcd_bitmap }, + { (const_iptr_t)"Screen saver demo", 0, (MenuHook)screen_saver, (iptr_t)&lcd_bitmap }, + { (const_iptr_t)"Scheduling test", 0, (MenuHook)context_switch_test, (iptr_t)&lcd_bitmap }, + { (const_iptr_t)"Show uptime", 0, (MenuHook)uptime, (iptr_t)&lcd_bitmap }, + { (const_iptr_t)"Reboot", 0, (MenuHook)soft_reset, (iptr_t)&lcd_bitmap }, + { (const_iptr_t)0, 0, NULL, (iptr_t)0 } +}; +static struct Menu main_menu = { main_items, "BeRTOS", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 }; + +int main(void) +{ + IRQ_ENABLE; + kdbg_init(); + + kputs("Init LED.."); + led_init(); + kputs("Done.\n"); + kputs("Init Timer.."); + timer_init(); + kputs("Done.\n"); + kputs("Init Process.."); + proc_init(); + kputs("Done.\n"); + + kputs("Init OLED display.."); + rit128x96_init(); + gfx_bitmapInit(&lcd_bitmap, raster, LCD_WIDTH, LCD_HEIGHT); + gfx_setFont(&lcd_bitmap, &font_gohu); + rit128x96_blitBitmap(&lcd_bitmap); + kputs("Done.\n"); + kputs("Init Keypad.."); + kbd_init(); + kputs("Done.\n"); + hp_proc = proc_new(hp_process, NULL, PROC_STACK_SIZE, hp_stack); + lp_proc = proc_new(lp_process, NULL, PROC_STACK_SIZE, lp_stack); + led_proc = proc_new(led_process, NULL, PROC_STACK_SIZE, led_stack); + /* Open a dummy echo terminal on UART0 */ + proc_new(ser_process, NULL, PROC_STACK_SIZE, ser_stack); + + proc_setPri(hp_proc, 2); + proc_setPri(lp_proc, 1); + while (1) + { + menu_handle(&main_menu); + cpu_relax(); + } +} diff --git a/examples/lm3s8962/lm3s8962.mk b/examples/lm3s8962/lm3s8962.mk new file mode 100644 index 00000000..c76d022e --- /dev/null +++ b/examples/lm3s8962/lm3s8962.mk @@ -0,0 +1,79 @@ +# Copyright 2010 Develer S.r.l. (http://www.develer.com/) +# All rights reserved. +# +# Author: Andrea Righi +# + +# Set to 1 for debug builds +lm3s8962_DEBUG = 0 + +include bertos/fonts/fonts.mk + +# Our target application +TRG += lm3s8962 + +lm3s8962_CSRC = \ + examples/lm3s8962/lm3s8962.c \ + bertos/gfx/bitmap.c \ + bertos/gfx/line.c \ + bertos/gfx/win.c \ + bertos/gfx/text.c \ + bertos/gfx/text_format.c \ + bertos/gui/menu.c \ + bertos/fonts/gohu.c \ + bertos/fonts/luBS14.c \ + bertos/icons/logo.c \ + bertos/mware/formatwr.c \ + bertos/mware/hex.c \ + bertos/mware/sprintf.c \ + bertos/mware/event.c \ + bertos/struct/heap.c \ + bertos/drv/timer.c \ + bertos/drv/ser.c \ + bertos/drv/kbd.c \ + bertos/drv/lcd_rit128x96.c \ + bertos/kern/kfile.c \ + bertos/kern/monitor.c \ + bertos/kern/proc_test.c \ + bertos/kern/proc.c \ + bertos/kern/signal.c \ + bertos/cpu/cortex-m3/drv/gpio_lm3s.c \ + bertos/cpu/cortex-m3/drv/clock_lm3s.c \ + bertos/cpu/cortex-m3/drv/ser_lm3s.c \ + bertos/cpu/cortex-m3/drv/kdebug_lm3s.c \ + bertos/cpu/cortex-m3/drv/ssi_lm3s.c \ + bertos/cpu/cortex-m3/drv/timer_cm3.c \ + bertos/cpu/cortex-m3/drv/irq_cm3.c \ + bertos/cpu/cortex-m3/hw/switch_ctx_cm3.c \ + bertos/cpu/cortex-m3/hw/init_lm3s.c + +lm3s8962_CPPASRC = \ + bertos/cpu/cortex-m3/hw/vectors_cm3.S \ + bertos/cpu/cortex-m3/hw/crt_cm3.S \ + # + +# This is an hosted application +lm3s8962_PREFIX = arm-none-eabi- + +lm3s8962_CPPAFLAGS = -mthumb -mno-thumb-interwork +lm3s8962_CPPFLAGS = -D'ARCH=0' -D__ARM_LM3S8962__ -D'CPU_FREQ=(50000000L)' -D'WIZ_AUTOGEN' -mthumb -mno-thumb-interwork -Iexamples/lm3s8962 -Ibertos/cpu/cortex-m3 -fno-strict-aliasing -fwrapv +lm3s8962_LDFLAGS = -nostartfiles -T bertos/cpu/cortex-m3/scripts/lm3s1968_rom.ld -Wl,--no-warn-mismatch -mthumb -mno-thumb-interwork + +lm3s8962_CPU = cortex-m3 + +lm3s8962_PROGRAMMER_CPU = lm3s1968 +lm3s8962_PROGRAMMER_TYPE = lm3s1968 +lm3s8962_FLASH_SCRIPT = bertos/prg_scripts/arm/flash-cortex.sh +lm3s8962_STOPFLASH_SCRIPT = bertos/prg_scripts/arm/stopopenocd.sh +lm3s8962_DEBUG_SCRIPT = bertos/prg_scripts/arm/debug-cortex.sh +lm3s8962_STOPDEBUG_SCRIPT = bertos/prg_scripts/arm/stopopenocd.sh + +ifeq ($(lm3s8962_DEBUG),0) + # Production options + lm3s8962_CFLAGS += -O2 -fomit-frame-pointer + lm3s8962_CXXFLAGS += -O2 -fomit-frame-pointer +else + # Debug options + lm3s8962_CPPAFLAGS += -g -gdwarf-2 + lm3s8962_CPPFLAGS += -O0 -g3 -gdwarf-2 -fverbose-asm +endif