board.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. #include <driverlib/fpu.h>
  26. static void rt_hw_console_init(void);
  27. /**
  28. * @addtogroup LM3S
  29. */
  30. /*@{*/
  31. extern void rt_hw_interrupt_thread_switch(void);
  32. /**
  33. * This is the timer interrupt service routine.
  34. *
  35. */
  36. void rt_hw_timer_handler(void)
  37. {
  38. /* enter interrupt */
  39. rt_interrupt_enter();
  40. rt_tick_increase();
  41. /* leave interrupt */
  42. rt_interrupt_leave();
  43. rt_hw_interrupt_thread_switch();
  44. }
  45. /**
  46. * This is the ethernet interrupt service routine.
  47. *
  48. */
  49. void rt_hw_eth_handler(void)
  50. {
  51. #ifdef RT_USING_LWIP
  52. extern void luminaryif_isr(void);
  53. /* enter interrupt */
  54. rt_interrupt_enter();
  55. /* luminary ethernet interface */
  56. luminaryif_isr();
  57. /* leave interrupt */
  58. rt_interrupt_leave();
  59. #endif
  60. }
  61. /**
  62. * This function will initial LM3S board.
  63. */
  64. void rt_hw_board_init()
  65. {
  66. //
  67. // Enable lazy stacking for interrupt handlers. This allows floating-point
  68. // instructions to be used within interrupt handlers, but at the expense of
  69. // extra stack usage.
  70. //
  71. FPULazyStackingEnable();
  72. // set sysclock to 80M
  73. SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
  74. /* init systick */
  75. SysTickDisable();
  76. SysTickPeriodSet(SysCtlClockGet()/RT_TICK_PER_SECOND);
  77. SysTickIntEnable();
  78. SysTickEnable();
  79. /* enable ssio */
  80. //SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
  81. #if LM3S_EXT_SRAM == 1
  82. /* init SDRAM */
  83. rt_hw_sdram_init();
  84. #endif
  85. /* init console */
  86. rt_hw_console_init();
  87. /* enable interrupt */
  88. IntMasterEnable();
  89. }
  90. /* init console to support rt_kprintf */
  91. static void rt_hw_console_init()
  92. {
  93. /* Enable the UART0 peripherals */
  94. SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  95. SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  96. /* Set GPIO A0 and A1 as UART pins. */
  97. GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
  98. /* Configure the UART for 115,200, 8-N-1 operation. */
  99. UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
  100. (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
  101. UART_CONFIG_PAR_NONE));
  102. }
  103. /* write one character to serial, must not trigger interrupt */
  104. static void rt_hw_console_putc(const char c)
  105. {
  106. if (c == '\n')
  107. while(UARTCharPutNonBlocking(UART0_BASE, '\r') == false);
  108. while(UARTCharPutNonBlocking(UART0_BASE, c) == false);
  109. }
  110. /**
  111. * This function is used by rt_kprintf to display a string on console.
  112. *
  113. * @param str the displayed string
  114. */
  115. void rt_hw_console_output(const char* str)
  116. {
  117. while (*str)
  118. {
  119. rt_hw_console_putc (*str++);
  120. }
  121. }
  122. /*@}*/