cpu.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2011-09-15 Bernard first version
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include "am33xx.h"
  17. /**
  18. * @addtogroup AM33xx
  19. */
  20. /*@{*/
  21. #define ICACHE_MASK (rt_uint32_t)(1 << 12)
  22. #define DCACHE_MASK (rt_uint32_t)(1 << 2)
  23. #if defined(__CC_ARM)
  24. rt_inline rt_uint32_t cp15_rd(void)
  25. {
  26. rt_uint32_t i;
  27. __asm
  28. {
  29. mrc p15, 0, i, c1, c0, 0
  30. }
  31. return i;
  32. }
  33. rt_inline void cache_enable(rt_uint32_t bit)
  34. {
  35. rt_uint32_t value;
  36. __asm
  37. {
  38. mrc p15, 0, value, c1, c0, 0
  39. orr value, value, bit
  40. mcr p15, 0, value, c1, c0, 0
  41. }
  42. }
  43. rt_inline void cache_disable(rt_uint32_t bit)
  44. {
  45. rt_uint32_t value;
  46. __asm
  47. {
  48. mrc p15, 0, value, c1, c0, 0
  49. bic value, value, bit
  50. mcr p15, 0, value, c1, c0, 0
  51. }
  52. }
  53. #elif defined(__GNUC__)
  54. rt_inline rt_uint32_t cp15_rd(void)
  55. {
  56. rt_uint32_t i;
  57. asm ("mrc p15, 0, %0, c1, c0, 0":"=r" (i));
  58. return i;
  59. }
  60. rt_inline void cache_enable(rt_uint32_t bit)
  61. {
  62. __asm__ __volatile__( \
  63. "mrc p15,0,r0,c1,c0,0\n\t" \
  64. "orr r0,r0,%0\n\t" \
  65. "mcr p15,0,r0,c1,c0,0" \
  66. : \
  67. :"r" (bit) \
  68. :"memory");
  69. }
  70. rt_inline void cache_disable(rt_uint32_t bit)
  71. {
  72. __asm__ __volatile__( \
  73. "mrc p15,0,r0,c1,c0,0\n\t" \
  74. "bic r0,r0,%0\n\t" \
  75. "mcr p15,0,r0,c1,c0,0" \
  76. : \
  77. :"r" (bit) \
  78. :"memory");
  79. }
  80. #endif
  81. #if defined(__CC_ARM)|(__GNUC__)
  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. #endif
  131. /**
  132. * shutdown CPU
  133. *
  134. */
  135. void rt_hw_cpu_shutdown()
  136. {
  137. rt_uint32_t level;
  138. rt_kprintf("shutdown...\n");
  139. level = rt_hw_interrupt_disable();
  140. while (level)
  141. {
  142. RT_ASSERT(0);
  143. }
  144. }
  145. /*@}*/