clock.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. * 2008-04-25 Yi.qiu first version
  13. */
  14. #include <rtthread.h>
  15. #include "s3c24x0.h"
  16. #define CONFIG_SYS_CLK_FREQ 12000000 // Fin = 12.00MHz
  17. rt_uint32_t PCLK;
  18. rt_uint32_t FCLK;
  19. rt_uint32_t HCLK;
  20. rt_uint32_t UCLK;
  21. void rt_hw_get_clock(void)
  22. {
  23. rt_uint32_t val;
  24. rt_uint8_t m, p, s;
  25. val = MPLLCON;
  26. m = (val>>12)&0xff;
  27. p = (val>>4)&0x3f;
  28. s = val&3;
  29. FCLK = ((m+8)*(CONFIG_SYS_CLK_FREQ/100)*2)/((p+2)*(1<<s))*100;
  30. val = CLKDIVN;
  31. m = (val>>1)&3;
  32. p = val&1;
  33. switch (m) {
  34. case 0:
  35. HCLK = FCLK;
  36. break;
  37. case 1:
  38. HCLK = FCLK>>1;
  39. break;
  40. case 2:
  41. if(s&2)
  42. HCLK = FCLK>>3;
  43. else
  44. HCLK = FCLK>>2;
  45. break;
  46. case 3:
  47. if(s&1)
  48. HCLK = FCLK/6;
  49. else
  50. HCLK = FCLK/3;
  51. break;
  52. }
  53. if(p)
  54. PCLK = HCLK>>1;
  55. else
  56. PCLK = HCLK;
  57. }
  58. void rt_hw_set_clock(rt_uint8_t sdiv, rt_uint8_t pdiv, rt_uint8_t mdiv)
  59. {
  60. MPLLCON = sdiv | pdiv<<4 | mdiv<<12;
  61. }
  62. void rt_hw_set_dividor(rt_uint8_t hdivn, rt_uint8_t pdivn)
  63. {
  64. CLKDIVN = (hdivn<<1) | pdivn;
  65. }