cpu.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. * 2011-01-13 weety modified from mini2440
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "at91sam926x.h"
  17. /**
  18. * @addtogroup AT91SAM926X
  19. */
  20. /*@{*/
  21. #define ICACHE_MASK (rt_uint32_t)(1 << 12)
  22. #define DCACHE_MASK (rt_uint32_t)(1 << 2)
  23. #ifdef __GNUC__
  24. rt_inline rt_uint32_t cp15_rd(void)
  25. {
  26. rt_uint32_t i;
  27. asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));
  28. return i;
  29. }
  30. rt_inline void cache_enable(rt_uint32_t bit)
  31. {
  32. __asm__ __volatile__( \
  33. "mrc p15,0,r0,c1,c0,0\n\t" \
  34. "orr r0,r0,%0\n\t" \
  35. "mcr p15,0,r0,c1,c0,0" \
  36. : \
  37. :"r" (bit) \
  38. :"memory");
  39. }
  40. rt_inline void cache_disable(rt_uint32_t bit)
  41. {
  42. __asm__ __volatile__( \
  43. "mrc p15,0,r0,c1,c0,0\n\t" \
  44. "bic r0,r0,%0\n\t" \
  45. "mcr p15,0,r0,c1,c0,0" \
  46. : \
  47. :"r" (bit) \
  48. :"memory");
  49. }
  50. #endif
  51. #ifdef __CC_ARM
  52. rt_inline rt_uint32_t cp15_rd(void)
  53. {
  54. rt_uint32_t i;
  55. __asm
  56. {
  57. mrc p15, 0, i, c1, c0, 0
  58. }
  59. return i;
  60. }
  61. rt_inline void cache_enable(rt_uint32_t bit)
  62. {
  63. rt_uint32_t value;
  64. __asm
  65. {
  66. mrc p15, 0, value, c1, c0, 0
  67. orr value, value, bit
  68. mcr p15, 0, value, c1, c0, 0
  69. }
  70. }
  71. rt_inline void cache_disable(rt_uint32_t bit)
  72. {
  73. rt_uint32_t value;
  74. __asm
  75. {
  76. mrc p15, 0, value, c1, c0, 0
  77. bic value, value, bit
  78. mcr p15, 0, value, c1, c0, 0
  79. }
  80. }
  81. #endif
  82. /**
  83. * enable I-Cache
  84. *
  85. */
  86. void rt_hw_cpu_icache_enable()
  87. {
  88. cache_enable(ICACHE_MASK);
  89. }
  90. /**
  91. * disable I-Cache
  92. *
  93. */
  94. void rt_hw_cpu_icache_disable()
  95. {
  96. cache_disable(ICACHE_MASK);
  97. }
  98. /**
  99. * return the status of I-Cache
  100. *
  101. */
  102. rt_base_t rt_hw_cpu_icache_status()
  103. {
  104. return (cp15_rd() & ICACHE_MASK);
  105. }
  106. /**
  107. * enable D-Cache
  108. *
  109. */
  110. void rt_hw_cpu_dcache_enable()
  111. {
  112. cache_enable(DCACHE_MASK);
  113. }
  114. /**
  115. * disable D-Cache
  116. *
  117. */
  118. void rt_hw_cpu_dcache_disable()
  119. {
  120. cache_disable(DCACHE_MASK);
  121. }
  122. /**
  123. * return the status of D-Cache
  124. *
  125. */
  126. rt_base_t rt_hw_cpu_dcache_status()
  127. {
  128. return (cp15_rd() & DCACHE_MASK);
  129. }
  130. static void at91sam9260_reset(void)
  131. {
  132. at91_sys_write(AT91_RSTC_CR, AT91_RSTC_KEY | AT91_RSTC_PROCRST | AT91_RSTC_PERRST);
  133. }
  134. static void at91sam9260_poweroff(void)
  135. {
  136. at91_sys_write(AT91_SHDW_CR, AT91_SHDW_KEY | AT91_SHDW_SHDW);
  137. }
  138. /**
  139. * reset cpu by dog's time-out
  140. *
  141. */
  142. void rt_hw_cpu_reset()
  143. {
  144. rt_kprintf("Restarting system...\n");
  145. at91sam9260_reset();
  146. while(1); /* loop forever and wait for reset to happen */
  147. /* NEVER REACHED */
  148. }
  149. /**
  150. * shutdown CPU
  151. *
  152. */
  153. void rt_hw_cpu_shutdown()
  154. {
  155. rt_uint32_t level;
  156. rt_kprintf("shutdown...\n");
  157. level = rt_hw_interrupt_disable();
  158. at91sam9260_poweroff();
  159. while (level)
  160. {
  161. RT_ASSERT(0);
  162. }
  163. }
  164. /*@}*/