summaryrefslogtreecommitdiff
path: root/bsp/lm4f232/drivers/board.c
blob: 1e4b53f110b64e51362fcbd48b58be1138e36495 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * File      : board.c
 * This file is part of RT-Thread RTOS
 * COPYRIGHT (C) 2006 - 2009 RT-Thread Develop Team
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://openlab.rt-thread.com/license/LICENSE
 *
 * Change Logs:
 * Date           Author       Notes
 * 2009-05-16     Bernard      first implementation
 */

#include <rthw.h>
#include <rtthread.h>
#include <board.h>

#include <inc/hw_types.h>
#include <inc/hw_memmap.h>
#include <inc/hw_uart.h>
#include <driverlib/uart.h>
#include <driverlib/gpio.h>
#include <driverlib/sysctl.h>
#include <driverlib/systick.h>
#include <driverlib/interrupt.h>
#include <driverlib/fpu.h>

static void rt_hw_console_init(void);

/**
 * @addtogroup LM3S
 */

/*@{*/

extern void rt_hw_interrupt_thread_switch(void);
/**
 * This is the timer interrupt service routine.
 *
 */
void rt_hw_timer_handler(void)
{
	/* enter interrupt */
	rt_interrupt_enter();

	rt_tick_increase();

	/* leave interrupt */
	rt_interrupt_leave();
	rt_hw_interrupt_thread_switch();
}

/**
 * This is the ethernet interrupt service routine.
 *
 */
void rt_hw_eth_handler(void)
{
#ifdef RT_USING_LWIP
    extern void luminaryif_isr(void);

    /* enter interrupt */
    rt_interrupt_enter();

    /* luminary ethernet interface */
    luminaryif_isr();

    /* leave interrupt */
    rt_interrupt_leave();
#endif
}

/**
 * This function will initial LM3S board.
 */
void rt_hw_board_init()
{
	
    //
    // Enable lazy stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    FPULazyStackingEnable();
    
	// set sysclock to 80M
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

	/* init systick */
	SysTickDisable();
	SysTickPeriodSet(SysCtlClockGet()/RT_TICK_PER_SECOND);
	SysTickIntEnable();
	SysTickEnable();

	/* enable ssio */
	//SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);

#if LM3S_EXT_SRAM == 1
	/* init SDRAM */
	rt_hw_sdram_init();
#endif
	/* init console */
	rt_hw_console_init();

	/* enable interrupt */
	IntMasterEnable();
}

/* init console to support rt_kprintf */
static void rt_hw_console_init()
{
	/* Enable the UART0 peripherals */
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	/* Set GPIO A0 and A1 as UART pins. */
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	/* Configure the UART for 115,200, 8-N-1 operation. */
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
	                    (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
	                     UART_CONFIG_PAR_NONE));
}

/* write one character to serial, must not trigger interrupt */
static void rt_hw_console_putc(const char c)
{
	if (c == '\n')
		while(UARTCharPutNonBlocking(UART0_BASE, '\r') == false);

	while(UARTCharPutNonBlocking(UART0_BASE, c) == false);
}

/**
 * This function is used by rt_kprintf to display a string on console.
 *
 * @param str the displayed string
 */
void rt_hw_console_output(const char* str)
{
	while (*str)
	{
		rt_hw_console_putc (*str++);
	}
}

/*@}*/