board.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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. */
  14. #include <rtthread.h>
  15. #include <rthw.h>
  16. #include "board.h"
  17. #include "uart.h"
  18. #include <jz4755.h>
  19. /**
  20. * @addtogroup JZ47xx
  21. */
  22. /*@{*/
  23. /**
  24. * This is the timer interrupt service routine.
  25. */
  26. void rt_hw_timer_handler()
  27. {
  28. /* increase a OS tick */
  29. rt_tick_increase();
  30. /* clear flag */
  31. TCU_TFCR = TCU_TFCR_OSTFLAG;
  32. }
  33. /**
  34. * This function will initial OS timer
  35. */
  36. void rt_hw_timer_init()
  37. {
  38. rt_uint32_t val;
  39. /* disable TCU clock */
  40. CPM_CLKGR &= ~CPM_CLKGR_TCU;
  41. TCU_TECR = TCU_TECR_OSTCL;
  42. /* set */
  43. OST_DR = RT_TICK_PER_SECOND * 0xcffff;
  44. /* clear counter */
  45. OST_CNT = 0;
  46. #if 0
  47. switch (RTC_DIV)
  48. {
  49. case 1:
  50. val = OST_TCSR_PRESCALE1;
  51. break;
  52. case 4:
  53. val = OST_TCSR_PRESCALE4;
  54. break;
  55. case 16:
  56. val = OST_TCSR_PRESCALE16;
  57. break;
  58. case 64:
  59. val = OST_TCSR_PRESCALE64;
  60. break;
  61. case 256:
  62. val = OST_TCSR_PRESCALE256;
  63. break;
  64. case 1024:
  65. val = OST_TCSR_PRESCALE1024;
  66. break;
  67. default:
  68. val = OST_TCSR_PRESCALE4;
  69. break;
  70. }
  71. #endif
  72. #ifdef RTC_SRC_EXTAL
  73. OST_CSR = (val | OST_TCSR_EXT_EN);
  74. #else
  75. OST_CSR = (val | OST_TCSR_PCLK_EN);
  76. #endif
  77. TCU_TFCR = TCU_TFCR_OSTFLAG;
  78. TCU_TMCR = TCU_TMCR_OSTMCL;
  79. TCU_TESR = TCU_TESR_OSTST;
  80. rt_hw_interrupt_install(IRQ_TCU0, rt_hw_timer_handler, RT_NULL);
  81. rt_hw_interrupt_umask (IRQ_TCU0);
  82. }
  83. /**
  84. * This function will initial sam7s64 board.
  85. */
  86. void rt_hw_board_init()
  87. {
  88. #ifdef RT_USING_UART
  89. /* init hardware UART device */
  90. rt_hw_uart_init();
  91. #endif
  92. #ifdef RT_USING_CONSOLE
  93. /* set console device */
  94. rt_console_set_device("uart");
  95. #endif
  96. /* init operating system timer */
  97. rt_hw_timer_init();
  98. }
  99. /*@}*/