board.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 "drv_uart.h"
  20. #include "ls1c.h"
  21. #define A_K0BASE 0x80000000
  22. extern unsigned char __bss_end;
  23. extern void tlb_refill_exception(void);
  24. extern void general_exception(void);
  25. extern void irq_exception(void);
  26. extern void rt_hw_cache_init(void);
  27. extern void invalidate_writeback_dcache_all(void);
  28. extern void invalidate_icache_all(void);
  29. /**
  30. * @addtogroup Loongson LS1B
  31. */
  32. /*@{*/
  33. /**
  34. * This is the timer interrupt service routine.
  35. */
  36. void rt_hw_timer_handler(void)
  37. {
  38. unsigned int count;
  39. count = read_c0_compare();
  40. write_c0_compare(count);
  41. write_c0_count(0);
  42. /* increase a OS tick */
  43. rt_tick_increase();
  44. }
  45. /**
  46. * This function will initial OS timer
  47. */
  48. void rt_hw_timer_init(void)
  49. {
  50. write_c0_compare(CPU_HZ/2/RT_TICK_PER_SECOND);
  51. write_c0_count(0);
  52. }
  53. /**
  54. * init hardware FPU
  55. */
  56. void rt_hw_fpu_init(void)
  57. {
  58. rt_uint32_t c0_status = 0;
  59. rt_uint32_t c1_status = 0;
  60. // 使能协处理器1--FPU
  61. c0_status = read_c0_status();
  62. c0_status |= (ST0_CU1 | ST0_FR);
  63. write_c0_status(c0_status);
  64. // 配置FPU
  65. c1_status = read_c1_status();
  66. c1_status |= (FPU_CSR_FS | FPU_CSR_FO | FPU_CSR_FN); // set FS, FO, FN
  67. c1_status &= ~(FPU_CSR_ALL_E); // disable exception
  68. c1_status = (c1_status & (~FPU_CSR_RM)) | FPU_CSR_RN; // set RN
  69. write_c1_status(c1_status);
  70. return ;
  71. }
  72. /**
  73. * This function will initial sam7s64 board.
  74. */
  75. void rt_hw_board_init(void)
  76. {
  77. /* init cache */
  78. rt_hw_cache_init();
  79. /* init hardware interrupt */
  80. rt_hw_interrupt_init();
  81. /* clear bev */
  82. write_c0_status(read_c0_status()&(~(1<<22)));
  83. /* copy vector */
  84. rt_memcpy((void *)A_K0BASE, tlb_refill_exception, 0x80);
  85. rt_memcpy((void *)(A_K0BASE + 0x180), general_exception, 0x80);
  86. rt_memcpy((void *)(A_K0BASE + 0x200), irq_exception, 0x80);
  87. invalidate_writeback_dcache_all();
  88. invalidate_icache_all();
  89. #ifdef RT_USING_HEAP
  90. rt_system_heap_init((void*)&__bss_end, (void*)RT_HW_HEAP_END);
  91. #endif
  92. #ifdef RT_USING_SERIAL
  93. /* init hardware UART device */
  94. rt_hw_uart_init();
  95. #endif
  96. #ifdef RT_USING_CONSOLE
  97. /* set console device */
  98. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  99. #endif
  100. /* init operating system timer */
  101. rt_hw_timer_init();
  102. #ifdef RT_USING_FPU
  103. /* init hardware fpu */
  104. rt_hw_fpu_init();
  105. #endif
  106. #ifdef RT_USING_COMPONENTS_INIT
  107. rt_components_board_init();
  108. #endif
  109. rt_kprintf("current sr: 0x%08x\n", read_c0_status());
  110. }
  111. /*@}*/