board.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include <board.h>
  17. #include <inc/hw_types.h>
  18. #include <inc/hw_memmap.h>
  19. #include <inc/hw_uart.h>
  20. #include <driverlib/uart.h>
  21. #include <driverlib/gpio.h>
  22. #include <driverlib/sysctl.h>
  23. #include <driverlib/systick.h>
  24. #include <driverlib/interrupt.h>
  25. static void rt_hw_console_init(void);
  26. /**
  27. * @addtogroup LM3S
  28. */
  29. /*@{*/
  30. extern void rt_hw_interrupt_thread_switch(void);
  31. /**
  32. * This is the timer interrupt service routine.
  33. *
  34. */
  35. void rt_hw_timer_handler(void)
  36. {
  37. /* enter interrupt */
  38. rt_interrupt_enter();
  39. rt_tick_increase();
  40. /* leave interrupt */
  41. rt_interrupt_leave();
  42. rt_hw_interrupt_thread_switch();
  43. }
  44. /**
  45. * This is the ethernet interrupt service routine.
  46. *
  47. */
  48. void rt_hw_eth_handler(void)
  49. {
  50. #ifdef RT_USING_LWIP
  51. /* luminary ethernet interface */
  52. extern void luminaryif_isr(void);
  53. luminaryif_isr();
  54. #endif
  55. }
  56. /**
  57. * This function will initial LM3S board.
  58. */
  59. void rt_hw_board_init()
  60. {
  61. // set sysclock to 80M
  62. SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
  63. /* init systick */
  64. SysTickDisable();
  65. SysTickPeriodSet(SysCtlClockGet()/RT_TICK_PER_SECOND);
  66. SysTickIntEnable();
  67. SysTickEnable();
  68. /* enable ssio */
  69. //SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
  70. /* init console */
  71. rt_hw_console_init();
  72. /* enable interrupt */
  73. IntMasterEnable();
  74. }
  75. /* init console to support rt_kprintf */
  76. static void rt_hw_console_init()
  77. {
  78. /* Enable the UART0 peripherals */
  79. SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  80. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  81. /* Set GPIO A0 and A1 as UART pins. */
  82. GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  83. /* Configure the UART for 115,200, 8-N-1 operation. */
  84. UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
  85. (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
  86. UART_CONFIG_PAR_NONE));
  87. }
  88. /* write one character to serial, must not trigger interrupt */
  89. static void rt_hw_console_putc(const char c)
  90. {
  91. if (c == '\n')
  92. while(UARTCharPutNonBlocking(UART0_BASE, '\r') == false);
  93. while(UARTCharPutNonBlocking(UART0_BASE, c) == false);
  94. }
  95. /**
  96. * This function is used by rt_kprintf to display a string on console.
  97. *
  98. * @param str the displayed string
  99. */
  100. void rt_hw_console_output(const char* str)
  101. {
  102. while (*str)
  103. {
  104. rt_hw_console_putc (*str++);
  105. }
  106. }
  107. /*@}*/