1 /* 2 * File : board.c 3 * This file is part of RT-Thread RTOS 4 * COPYRIGHT (C) 2006 - 2009 RT-Thread Develop Team 5 * 6 * The license and distribution terms for this file may be 7 * found in the file LICENSE in this distribution or at 8 * http://openlab.rt-thread.com/license/LICENSE 9 * 10 * Change Logs: 11 * Date Author Notes 12 * 2009-05-16 Bernard first implementation 13 */ 14 15 #include <rthw.h> 16 #include <rtthread.h> 17 #include <board.h> 18 19 #include <inc/hw_types.h> 20 #include <inc/hw_memmap.h> 21 #include <inc/hw_uart.h> 22 #include <driverlib/uart.h> 23 #include <driverlib/gpio.h> 24 #include <driverlib/sysctl.h> 25 #include <driverlib/systick.h> 26 #include <driverlib/interrupt.h> 27 28 29 static void rt_hw_console_init(void); 30 31 /** 32 * @addtogroup LM3S 33 */ 34 35 /*@{*/ 36 37 extern void rt_hw_interrupt_thread_switch(void); 38 /** 39 * This is the timer interrupt service routine. 40 * 41 */ rt_hw_timer_handler(void)42void rt_hw_timer_handler(void) 43 { 44 /* enter interrupt */ 45 rt_interrupt_enter(); 46 47 rt_tick_increase(); 48 49 /* leave interrupt */ 50 rt_interrupt_leave(); 51 rt_hw_interrupt_thread_switch(); 52 } 53 54 /** 55 * This is the ethernet interrupt service routine. 56 * 57 */ rt_hw_eth_handler(void)58void rt_hw_eth_handler(void) 59 { 60 #ifdef RT_USING_LWIP 61 extern void luminaryif_isr(void); 62 63 /* enter interrupt */ 64 rt_interrupt_enter(); 65 66 /* luminary ethernet interface */ 67 luminaryif_isr(); 68 69 /* leave interrupt */ 70 rt_interrupt_leave(); 71 #endif 72 } 73 74 /** 75 * This function will initial LM3S board. 76 */ rt_hw_board_init()77void rt_hw_board_init() 78 { 79 /* set ldo */ 80 SysCtlLDOSet(SYSCTL_LDO_2_50V); 81 /* set clock */ 82 SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | 83 LM3S_XTAL_TYPE); 84 85 /* init systick */ 86 SysTickDisable(); 87 SysTickPeriodSet(SysCtlClockGet()/RT_TICK_PER_SECOND); 88 SysTickIntEnable(); 89 SysTickEnable(); 90 91 /* enable ssio */ 92 SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0); 93 94 /* init console */ 95 rt_hw_console_init(); 96 97 /* enable interrupt */ 98 IntMasterEnable(); 99 } 100 101 /* init console to support rt_kprintf */ rt_hw_console_init()102static void rt_hw_console_init() 103 { 104 /* Enable the UART0 peripherals */ 105 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); 106 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); 107 108 /* Set GPIO A0 and A1 as UART pins. */ 109 GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); 110 111 /* Configure the UART for 115,200, 8-N-1 operation. */ 112 UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200, 113 (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | 114 UART_CONFIG_PAR_NONE)); 115 } 116 117 /* write one character to serial, must not trigger interrupt */ rt_hw_console_putc(const char c)118static void rt_hw_console_putc(const char c) 119 { 120 if (c == '\n') 121 while(UARTCharPutNonBlocking(UART0_BASE, '\r') == false); 122 123 while(UARTCharPutNonBlocking(UART0_BASE, c) == false); 124 } 125 126 /** 127 * This function is used by rt_kprintf to display a string on console. 128 * 129 * @param str the displayed string 130 */ rt_hw_console_output(const char * str)131void rt_hw_console_output(const char* str) 132 { 133 while (*str) 134 { 135 rt_hw_console_putc (*str++); 136 } 137 } 138 139 /*@}*/ 140