cpu.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. * File : cpu.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://openlab.rt-thread.com/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2006-03-13 Bernard first version
  13. */
  14. #include <rtthread.h>
  15. #include "s3c24x0.h"
  16. /**
  17. * @addtogroup S3C24X0
  18. */
  19. /*@{*/
  20. #define ICACHE_MASK (rt_uint32_t)(1 << 12)
  21. #define DCACHE_MASK (rt_uint32_t)(1 << 2)
  22. #ifdef __GNUC__
  23. rt_inline rt_uint32_t cp15_rd(void)
  24. {
  25. rt_uint32_t i;
  26. asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));
  27. return i;
  28. }
  29. rt_inline void cache_enable(rt_uint32_t bit)
  30. {
  31. __asm__ __volatile__( \
  32. "mrc p15,0,r0,c1,c0,0\n\t" \
  33. "orr r0,r0,%0\n\t" \
  34. "mcr p15,0,r0,c1,c0,0" \
  35. : \
  36. :"r" (bit) \
  37. :"memory");
  38. }
  39. rt_inline void cache_disable(rt_uint32_t bit)
  40. {
  41. __asm__ __volatile__( \
  42. "mrc p15,0,r0,c1,c0,0\n\t" \
  43. "bic r0,r0,%0\n\t" \
  44. "mcr p15,0,r0,c1,c0,0" \
  45. : \
  46. :"r" (bit) \
  47. :"memory");
  48. }
  49. #endif
  50. #ifdef __CC_ARM
  51. rt_inline rt_uint32_t cp15_rd(void)
  52. {
  53. rt_uint32_t i;
  54. __asm
  55. {
  56. mrc p15, 0, i, c1, c0, 0
  57. }
  58. return i;
  59. }
  60. rt_inline void cache_enable(rt_uint32_t bit)
  61. {
  62. rt_uint32_t value;
  63. __asm
  64. {
  65. mrc p15, 0, value, c1, c0, 0
  66. orr value, value, bit
  67. mcr p15, 0, value, c1, c0, 0
  68. }
  69. }
  70. rt_inline void cache_disable(rt_uint32_t bit)
  71. {
  72. rt_uint32_t value;
  73. __asm
  74. {
  75. mrc p15, 0, value, c1, c0, 0
  76. bic value, value, bit
  77. mcr p15, 0, value, c1, c0, 0
  78. }
  79. }
  80. #endif
  81. /**
  82. * enable I-Cache
  83. *
  84. */
  85. void rt_hw_cpu_icache_enable()
  86. {
  87. cache_enable(ICACHE_MASK);
  88. }
  89. /**
  90. * disable I-Cache
  91. *
  92. */
  93. void rt_hw_cpu_icache_disable()
  94. {
  95. cache_disable(ICACHE_MASK);
  96. }
  97. /**
  98. * return the status of I-Cache
  99. *
  100. */
  101. rt_base_t rt_hw_cpu_icache_status()
  102. {
  103. return (cp15_rd() & ICACHE_MASK);
  104. }
  105. /**
  106. * enable D-Cache
  107. *
  108. */
  109. void rt_hw_cpu_dcache_enable()
  110. {
  111. cache_enable(DCACHE_MASK);
  112. }
  113. /**
  114. * disable D-Cache
  115. *
  116. */
  117. void rt_hw_cpu_dcache_disable()
  118. {
  119. cache_disable(DCACHE_MASK);
  120. }
  121. /**
  122. * return the status of D-Cache
  123. *
  124. */
  125. rt_base_t rt_hw_cpu_dcache_status()
  126. {
  127. return (cp15_rd() & DCACHE_MASK);
  128. }
  129. /**
  130. * reset cpu by dog's time-out
  131. *
  132. */
  133. void rt_hw_cpu_reset()
  134. {
  135. /* Disable all interrupt except the WDT */
  136. INTMSK = (~((rt_uint32_t)1 << INTWDT));
  137. /* Disable watchdog */
  138. WTCON = 0x0000;
  139. /* Initialize watchdog timer count register */
  140. WTCNT = 0x0001;
  141. /* Enable watchdog timer; assert reset at timer timeout */
  142. WTCON = 0x0021;
  143. while(1); /* loop forever and wait for reset to happen */
  144. /* NEVER REACHED */
  145. }
  146. /**
  147. * shutdown CPU
  148. *
  149. */
  150. void rt_hw_cpu_shutdown()
  151. {
  152. rt_uint32_t level;
  153. rt_kprintf("shutdown...\n");
  154. level = rt_hw_interrupt_disable();
  155. RT_ASSERT(RT_NULL);
  156. }
  157. /*@}*/