board.c 2.5 KB

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