clk.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * File : clock.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, 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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2010-03-20 zchong first version
  13. */
  14. #include <rtthread.h>
  15. #include "sep4020.h"
  16. #define CLK_IN 4000000 /* Fin = 4.00MHz */
  17. #define SYSCLK 72000000 /* system clock we want */
  18. #define CLK_ESRAM 0
  19. #define CLK_LCDC 1
  20. #define CLK_PWM 2
  21. #define CLK_DMAC 3
  22. #define CLK_EMI 4
  23. #define CLK_MMCSD 5
  24. #define CLK_SSI 7
  25. #define CLK_UART0 8
  26. #define CLK_UART1 9
  27. #define CLK_UART2 10
  28. #define CLK_UART3 11
  29. #define CLK_USB 12
  30. #define CLK_MAC 13
  31. #define CLK_SMC 14
  32. #define CLK_I2C 15
  33. #define CLK_GPT 16
  34. static void rt_hw_set_system_clock(void)
  35. {
  36. rt_uint8_t pv;
  37. /* pv value*/
  38. pv = SYSCLK/2/CLK_IN;
  39. /* go to normal mode*/
  40. PMC_PMDR = 0x01;
  41. /* set the clock */
  42. PMC_PMCR = 0x4000 | pv;
  43. /* trige configurate*/
  44. PMC_PMCR = 0xc000 | pv;
  45. }
  46. static void rt_hw_set_usb_clock(void)
  47. {
  48. /* set the clock */
  49. PMC_PUCR = 0x000c;
  50. /* trige configurate*/
  51. PMC_PMCR = 0x800c;
  52. }
  53. /**
  54. * @brief System Clock Configuration
  55. */
  56. void rt_hw_clock_init(void)
  57. {
  58. /* set system clock */
  59. rt_hw_set_system_clock();
  60. /* set usb clock */
  61. rt_hw_set_usb_clock();
  62. }
  63. /**
  64. * @brief Get system clock
  65. */
  66. rt_uint32_t rt_hw_get_clock(void)
  67. {
  68. rt_uint32_t val;
  69. rt_uint8_t pv, pd, npd;
  70. /* get PMCR value */
  71. val = PMC_PMCR;
  72. /* get NPD */
  73. npd = (val >> 14) & 0x01;
  74. /* get PD */
  75. pd = (val >> 10) & 0x0f;
  76. /* get PV */
  77. pv = val & 0x7f;
  78. /* caculate the system clock */
  79. if(npd)
  80. val = 2 * CLK_IN * pv;
  81. else
  82. val = CLK_IN * pv / (pd + 1);
  83. return(val);
  84. }
  85. /**
  86. * @brief Enable module clock
  87. */
  88. void rt_hw_enable_module_clock(rt_uint8_t module)
  89. {
  90. }
  91. /**
  92. * @brief Disable module clock
  93. */
  94. void rt_hw_disable_module_clock(rt_uint8_t module)
  95. {
  96. }