cpu.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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 <sep4020.h>
  16. extern rt_uint32_t rt_hw_interrupt_disable(void);
  17. //TODO
  18. #warning I DON'T KNOW IF THE MMU OPERATION WORKS ON SEP4020
  19. /**
  20. * @addtogroup S3C24X0
  21. */
  22. /*@{*/
  23. #define ICACHE_MASK (rt_uint32_t)(1 << 12)
  24. #define DCACHE_MASK (rt_uint32_t)(1 << 2)
  25. #ifdef __GNUC__
  26. rt_inline rt_uint32_t cp15_rd(void)
  27. {
  28. rt_uint32_t i;
  29. asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));
  30. return i;
  31. }
  32. rt_inline void cache_enable(rt_uint32_t bit)
  33. {
  34. __asm__ __volatile__( \
  35. "mrc p15,0,r0,c1,c0,0\n\t" \
  36. "orr r0,r0,%0\n\t" \
  37. "mcr p15,0,r0,c1,c0,0" \
  38. : \
  39. :"r" (bit) \
  40. :"memory");
  41. }
  42. rt_inline void cache_disable(rt_uint32_t bit)
  43. {
  44. __asm__ __volatile__( \
  45. "mrc p15,0,r0,c1,c0,0\n\t" \
  46. "bic r0,r0,%0\n\t" \
  47. "mcr p15,0,r0,c1,c0,0" \
  48. : \
  49. :"r" (bit) \
  50. :"memory");
  51. }
  52. #endif
  53. #ifdef __CC_ARM
  54. rt_inline rt_uint32_t cp15_rd(void)
  55. {
  56. rt_uint32_t i;
  57. __asm
  58. {
  59. mrc p15, 0, i, c1, c0, 0
  60. }
  61. return i;
  62. }
  63. rt_inline void cache_enable(rt_uint32_t bit)
  64. {
  65. rt_uint32_t value;
  66. __asm
  67. {
  68. mrc p15, 0, value, c1, c0, 0
  69. orr value, value, bit
  70. mcr p15, 0, value, c1, c0, 0
  71. }
  72. }
  73. rt_inline void cache_disable(rt_uint32_t bit)
  74. {
  75. rt_uint32_t value;
  76. __asm
  77. {
  78. mrc p15, 0, value, c1, c0, 0
  79. bic value, value, bit
  80. mcr p15, 0, value, c1, c0, 0
  81. }
  82. }
  83. #endif
  84. /**
  85. * enable I-Cache
  86. *
  87. */
  88. void rt_hw_cpu_icache_enable()
  89. {
  90. cache_enable(ICACHE_MASK);
  91. }
  92. /**
  93. * disable I-Cache
  94. *
  95. */
  96. void rt_hw_cpu_icache_disable()
  97. {
  98. cache_disable(ICACHE_MASK);
  99. }
  100. /**
  101. * return the status of I-Cache
  102. *
  103. */
  104. rt_base_t rt_hw_cpu_icache_status()
  105. {
  106. return (cp15_rd() & ICACHE_MASK);
  107. }
  108. /**
  109. * enable D-Cache
  110. *
  111. */
  112. void rt_hw_cpu_dcache_enable()
  113. {
  114. cache_enable(DCACHE_MASK);
  115. }
  116. /**
  117. * disable D-Cache
  118. *
  119. */
  120. void rt_hw_cpu_dcache_disable()
  121. {
  122. cache_disable(DCACHE_MASK);
  123. }
  124. /**
  125. * return the status of D-Cache
  126. *
  127. */
  128. rt_base_t rt_hw_cpu_dcache_status()
  129. {
  130. return (cp15_rd() & DCACHE_MASK);
  131. }
  132. /**
  133. * reset cpu by dog's time-out
  134. *
  135. */
  136. void rt_hw_cpu_reset()
  137. {
  138. /* enable watchdog */
  139. *(RP)(RTC_CTR) = 0x02;
  140. /*Enable watchdog reset*/
  141. *(RP)(RTC_INT_EN) = 0x20;
  142. /* Initialize watchdog timer count register */
  143. *(RP)(RTC_WD_CNT) = 0x0001;
  144. while(1); /* loop forever and wait for reset to happen */
  145. /* NEVER REACHED */
  146. }
  147. /**
  148. * shutdown CPU
  149. *
  150. */
  151. void rt_hw_cpu_shutdown()
  152. {
  153. rt_uint32_t UNUSED level;
  154. rt_kprintf("shutdown...\n");
  155. level = rt_hw_interrupt_disable();
  156. RT_ASSERT(RT_NULL);
  157. }
  158. /*@}*/