board.c 2.3 KB

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