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