board.c 2.9 KB
Newer Older
wuyangyong's avatar
wuyangyong 已提交
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
/*
 * 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>


static void rt_hw_console_init(void);

/**
 * @addtogroup LM3S
 */

/*@{*/

extern void rt_hw_interrupt_thread_switch(void);
/**
 * This is the timer interrupt service routine.
wuyangyong's avatar
wuyangyong 已提交
40
 *
wuyangyong's avatar
wuyangyong 已提交
41 42 43 44 45 46 47
 */
void rt_hw_timer_handler(void)
{
	/* enter interrupt */
	rt_interrupt_enter();

	rt_tick_increase();
wuyangyong's avatar
wuyangyong 已提交
48

wuyangyong's avatar
wuyangyong 已提交
49 50 51 52 53 54 55
	/* leave interrupt */
	rt_interrupt_leave();
	rt_hw_interrupt_thread_switch();
}

/**
 * This is the ethernet interrupt service routine.
wuyangyong's avatar
wuyangyong 已提交
56
 *
wuyangyong's avatar
wuyangyong 已提交
57 58 59 60
 */
void rt_hw_eth_handler(void)
{
#ifdef RT_USING_LWIP
wuyangyong's avatar
wuyangyong 已提交
61 62 63 64 65 66 67 68 69 70
    extern void luminaryif_isr(void);

    /* enter interrupt */
    rt_interrupt_enter();

    /* luminary ethernet interface */
    luminaryif_isr();

    /* leave interrupt */
    rt_interrupt_leave();
wuyangyong's avatar
wuyangyong 已提交
71
#endif
wuyangyong's avatar
wuyangyong 已提交
72 73 74 75 76 77 78
}

/**
 * This function will initial LM3S board.
 */
void rt_hw_board_init()
{
wuyangyong's avatar
wuyangyong 已提交
79 80
	// set sysclock to 80M
    SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
wuyangyong's avatar
wuyangyong 已提交
81 82 83 84 85 86 87 88

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

	/* enable ssio */
wuyangyong's avatar
wuyangyong 已提交
89
	//SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
wuyangyong's avatar
wuyangyong 已提交
90

wuyangyong's avatar
wuyangyong 已提交
91 92 93 94
#if LM3S_EXT_SRAM == 1
	/* init SDRAM */
	rt_hw_sdram_init();
#endif
wuyangyong's avatar
wuyangyong 已提交
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
	/* 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++);
	}
}

/*@}*/