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 #include <driverlib/fpu.h>
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)42 void 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)58 void 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()77 void rt_hw_board_init()
78 {
79
80 //
81 // Enable lazy stacking for interrupt handlers. This allows floating-point
82 // instructions to be used within interrupt handlers, but at the expense of
83 // extra stack usage.
84 //
85 FPULazyStackingEnable();
86
87 // set sysclock to 80M
88 SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
89
90 /* init systick */
91 SysTickDisable();
92 SysTickPeriodSet(SysCtlClockGet()/RT_TICK_PER_SECOND);
93 SysTickIntEnable();
94 SysTickEnable();
95
96 /* enable ssio */
97 //SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
98
99 #if LM3S_EXT_SRAM == 1
100 /* init SDRAM */
101 rt_hw_sdram_init();
102 #endif
103 /* init console */
104 rt_hw_console_init();
105
106 /* enable interrupt */
107 IntMasterEnable();
108 }
109
110 /* init console to support rt_kprintf */
rt_hw_console_init()111 static void rt_hw_console_init()
112 {
113 /* Enable the UART0 peripherals */
114 SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
115 SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
116
117 /* Set GPIO A0 and A1 as UART pins. */
118 GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
119
120 /* Configure the UART for 115,200, 8-N-1 operation. */
121 UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
122 (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
123 UART_CONFIG_PAR_NONE));
124 }
125
126 /* write one character to serial, must not trigger interrupt */
rt_hw_console_putc(const char c)127 static void rt_hw_console_putc(const char c)
128 {
129 if (c == '\n')
130 while(UARTCharPutNonBlocking(UART0_BASE, '\r') == false);
131
132 while(UARTCharPutNonBlocking(UART0_BASE, c) == false);
133 }
134
135 /**
136 * This function is used by rt_kprintf to display a string on console.
137 *
138 * @param str the displayed string
139 */
rt_hw_console_output(const char * str)140 void rt_hw_console_output(const char* str)
141 {
142 while (*str)
143 {
144 rt_hw_console_putc (*str++);
145 }
146 }
147
148 /*@}*/
149