1
0

cpu.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. /**
  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. * shutdown CPU
  131. *
  132. */
  133. void rt_hw_cpu_shutdown()
  134. {
  135. rt_uint32_t level;
  136. rt_kprintf("shutdown...\n");
  137. level = rt_hw_interrupt_disable();
  138. while (level)
  139. {
  140. RT_ASSERT(0);
  141. }
  142. }
  143. /*@}*/