board.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2012, RT-Thread Development 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://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-06-25 Bernard first version
  13. */
  14. #include <rtthread.h>
  15. #include <rthw.h>
  16. #include "board.h"
  17. #include "uart.h"
  18. #include <soc3210.h>
  19. /**
  20. * @addtogroup Loongson SoC3210
  21. */
  22. /*@{*/
  23. /**
  24. * This is the timer interrupt service routine.
  25. */
  26. void rt_hw_timer_handler(void)
  27. {
  28. unsigned int count;
  29. count = read_c0_compare();
  30. write_c0_compare(count);
  31. write_c0_count(0);
  32. /* increase a OS tick */
  33. rt_tick_increase();
  34. }
  35. /**
  36. * This function will initial OS timer
  37. */
  38. void rt_hw_timer_init(void)
  39. {
  40. write_c0_compare(CPU_HZ/2/RT_TICK_PER_SECOND);
  41. write_c0_count(0);
  42. }
  43. /**
  44. * This function will initial sam7s64 board.
  45. */
  46. void rt_hw_board_init(void)
  47. {
  48. #ifdef RT_USING_UART
  49. /* init hardware UART device */
  50. rt_hw_uart_init();
  51. #endif
  52. #ifdef RT_USING_CONSOLE
  53. /* set console device */
  54. rt_console_set_device("uart");
  55. #endif
  56. /* init operating system timer */
  57. rt_hw_timer_init();
  58. rt_kprintf("current sr: 0x%08x\n", read_c0_status());
  59. }
  60. /*@}*/
  61. /* UART line status register value */
  62. #define UARTLSR_ERROR (1 << 7)
  63. #define UARTLSR_TE (1 << 6)
  64. #define UARTLSR_TFE (1 << 5)
  65. #define UARTLSR_BI (1 << 4)
  66. #define UARTLSR_FE (1 << 3)
  67. #define UARTLSR_PE (1 << 2)
  68. #define UARTLSR_OE (1 << 1)
  69. #define UARTLSR_DR (1 << 0)
  70. void rt_hw_console_output(const char *ptr)
  71. {
  72. /* stream mode */
  73. while (*ptr)
  74. {
  75. if (*ptr == '\n')
  76. {
  77. /* FIFO status, contain valid data */
  78. while (!(UART_LSR(UART0_BASE) & (UARTLSR_TE | UARTLSR_TFE)));
  79. /* write data */
  80. UART_DAT(UART0_BASE) = '\r';
  81. }
  82. /* FIFO status, contain valid data */
  83. while (!(UART_LSR(UART0_BASE) & (UARTLSR_TE | UARTLSR_TFE)));
  84. /* write data */
  85. UART_DAT(UART0_BASE) = *ptr;
  86. ptr ++;
  87. }
  88. }