board.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. * init hardware FPU
  47. */
  48. void rt_hw_fpu_init(void)
  49. {
  50. rt_uint32_t c0_status = 0;
  51. rt_uint32_t c1_status = 0;
  52. // ʹÄÜЭ´¦ÀíÆ÷1--FPU
  53. c0_status = read_c0_status();
  54. c0_status |= (ST0_CU1 | ST0_FR);
  55. write_c0_status(c0_status);
  56. // ÅäÖÃFPU
  57. c1_status = read_c1_status();
  58. c1_status |= (FPU_CSR_FS | FPU_CSR_FO | FPU_CSR_FN); // set FS, FO, FN
  59. c1_status &= ~(FPU_CSR_ALL_E); // disable exception
  60. c1_status = (c1_status & (~FPU_CSR_RM)) | FPU_CSR_RN; // set RN
  61. write_c1_status(c1_status);
  62. return ;
  63. }
  64. /**
  65. * This function will initial sam7s64 board.
  66. */
  67. void rt_hw_board_init(void)
  68. {
  69. #ifdef RT_USING_UART
  70. /* init hardware UART device */
  71. rt_hw_uart_init();
  72. #endif
  73. #ifdef RT_USING_CONSOLE
  74. /* set console device */
  75. rt_console_set_device("uart2");
  76. #endif
  77. /* init operating system timer */
  78. rt_hw_timer_init();
  79. /* init hardware fpu */
  80. rt_hw_fpu_init();
  81. rt_kprintf("current sr: 0x%08x\n", read_c0_status());
  82. }
  83. #define __raw_out_put(unr) \
  84. while (*ptr) \
  85. { \
  86. if (*ptr == '\n') \
  87. { \
  88. /* FIFO status, contain valid data */ \
  89. while (!(UART_LSR(UART##unr##_BASE) & (UARTLSR_TE | UARTLSR_TFE))); \
  90. /* write data */ \
  91. UART_DAT(UART##unr##_BASE) = '\r'; \
  92. } \
  93. /* FIFO status, contain valid data */ \
  94. while (!(UART_LSR(UART##unr##_BASE) & (UARTLSR_TE | UARTLSR_TFE))); \
  95. /* write data */ \
  96. UART_DAT(UART##unr##_BASE) = *ptr; \
  97. ptr ++; \
  98. }
  99. /* UART line status register value */
  100. #define UARTLSR_ERROR (1 << 7)
  101. #define UARTLSR_TE (1 << 6)
  102. #define UARTLSR_TFE (1 << 5)
  103. #define UARTLSR_BI (1 << 4)
  104. #define UARTLSR_FE (1 << 3)
  105. #define UARTLSR_PE (1 << 2)
  106. #define UARTLSR_OE (1 << 1)
  107. #define UARTLSR_DR (1 << 0)
  108. void rt_hw_console_output(const char *ptr)
  109. {
  110. #if defined(RT_USING_UART0)
  111. __raw_out_put(0);
  112. #elif defined(RT_USING_UART2)
  113. __raw_out_put(2);
  114. #elif defined(RT_USING_UART3)
  115. __raw_out_put(3);
  116. #endif
  117. }
  118. /*@}*/