cpu.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. /*
  2. * File : cpu.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2013-7-14 Peng Fan sep6200 implementation
  23. */
  24. #include <rthw.h>
  25. #include <rtthread.h>
  26. #include <sep6200.h>
  27. /**
  28. * @addtogroup sep6200
  29. */
  30. /*@{*/
  31. #ifdef __GNUC__
  32. rt_inline void cache_invalid(void)
  33. {
  34. __asm__ volatile ("movc p0.c5, r1, #28\n"
  35. "nop;nop;nop;nop;nop;nop;nop;nop;\n"
  36. :
  37. :
  38. :"memory", "cc"
  39. );
  40. }
  41. rt_inline void cache_enable(void)
  42. {
  43. __asm__ volatile ( "movc r1, p0.c1, #0\n"
  44. "or r1, r1, #0xc\n"
  45. "movc p0.c1, r1, #0\n"
  46. "nop;nop;nop;nop;nop;nop;nop;nop;\n"
  47. :
  48. :
  49. :"r0", "memory", "cc");
  50. }
  51. rt_inline void clean_dcache(void)
  52. {
  53. __asm__ volatile ( "mov ip, #0\n"
  54. "movc p0.c5, ip, #10\n"
  55. "nop; nop; nop; nop; nop; nop; nop; nop\n"
  56. :
  57. :
  58. :"ip", "memory", "cc");
  59. }
  60. rt_inline rt_uint32_t icache_status(void)
  61. {
  62. rt_uint32_t ret;
  63. __asm__ volatile ( "movc %0, p0.c1, #0\n"
  64. "and %0, %0, #8\n"
  65. : "=&r" (ret)
  66. :
  67. :"memory", "cc");
  68. return ret;
  69. }
  70. rt_inline rt_uint32_t dcache_status(void)
  71. {
  72. rt_uint32_t ret;
  73. __asm__ volatile ( "movc %0, p0.c1, #0\n"
  74. "and %0, %0, #4\n"
  75. : "=&r" (ret)
  76. :
  77. :"memory", "cc");
  78. return ret;
  79. }
  80. rt_inline void dcache_flush(void)
  81. {
  82. __asm__ volatile ( "mov ip, #0\n"
  83. "movc p0.c5, ip, #14\n"
  84. "nop; nop; nop; nop; nop; nop; nop; nop\n"
  85. :
  86. :
  87. : "ip" );
  88. }
  89. rt_inline void icache_invalid(void)
  90. {
  91. __asm__ volatile ( "mov r0, #0\n"
  92. "movc p0.c5, r0, #20\n"
  93. "nop; nop; nop; nop; nop; nop; nop; nop\n"
  94. :
  95. :
  96. :"r0", "memory", "cc");
  97. }
  98. rt_inline void dcache_invalid(void)
  99. {
  100. __asm__ volatile ( "mov r0, #0\n"
  101. "movc p0.c5, r0, #12\n"
  102. "nop; nop; nop; nop; nop; nop; nop; nop\n"
  103. :
  104. :
  105. :"r0", "memory", "cc");
  106. }
  107. rt_inline void icache_disable(void)
  108. {
  109. icache_invalid();
  110. __asm__ volatile ( "movc r0, p0.c1, #0\n"
  111. "andn r0, r0, #8\n"
  112. "movc p0.c1, r0, #0\n"
  113. :
  114. :
  115. :"r0", "memory", "cc");
  116. }
  117. rt_inline void dcache_disable(void)
  118. {
  119. dcache_flush();
  120. __asm__ volatile ( "movc r0, p0.c1, #0\n"
  121. "andn r0, r0, #20\n"
  122. "movc p0.c1, r0, #0\n"
  123. :
  124. :
  125. :"r0", "memory", "cc");
  126. }
  127. rt_inline void icache_enable(void)
  128. {
  129. __asm__ volatile ( "mov r0, #0\n"
  130. "movc p0.c5, r0, #20\n"
  131. "nop; nop; nop; nop; nop; nop; nop; nop\n"
  132. :
  133. :
  134. :"r0", "memory", "cc");
  135. __asm__ volatile ( "movc r0, p0.c1, #0\n"
  136. "or r0, r0, #8\n"
  137. "movc p0.c1, r0, #0\n"
  138. :
  139. :
  140. :"r0", "memory", "cc");
  141. }
  142. rt_inline void dcache_enable(void)
  143. {
  144. __asm__ volatile ( "mov r0, #0\n"
  145. "movc p0.c5, r0, #12\n"
  146. "nop; nop; nop; nop; nop; nop; nop; nop\n"
  147. :
  148. :
  149. :"r0", "memory", "cc");
  150. __asm__ volatile ( "movc r0, p0.c1, #0\n"
  151. "or r0, r0, #20\n"
  152. "movc p0.c1, r0, #0\n"
  153. :
  154. :
  155. :"r0", "memory", "cc");
  156. }
  157. #endif
  158. /**
  159. * enable I-Cache
  160. *
  161. */
  162. void rt_hw_cpu_icache_enable()
  163. {
  164. icache_enable();
  165. }
  166. /**
  167. * disable I-Cache
  168. *
  169. */
  170. void rt_hw_cpu_icache_disable()
  171. {
  172. icache_disable();
  173. }
  174. /**
  175. * return the status of I-Cache
  176. *
  177. */
  178. rt_base_t rt_hw_cpu_icache_status()
  179. {
  180. return icache_status();
  181. }
  182. /**
  183. * enable D-Cache
  184. *
  185. */
  186. void rt_hw_cpu_dcache_enable()
  187. {
  188. dcache_enable();
  189. }
  190. /**
  191. * disable D-Cache
  192. *
  193. */
  194. void rt_hw_cpu_dcache_disable()
  195. {
  196. dcache_disable();
  197. }
  198. /**
  199. * return the status of D-Cache
  200. *
  201. */
  202. rt_base_t rt_hw_cpu_dcache_status()
  203. {
  204. return dcache_status();
  205. }
  206. static void sep6200_reset(rt_uint32_t addr)
  207. {
  208. __asm__ volatile ( "mov ip, #0\n"
  209. "movc p0.c5, ip, #28\n" /*Cache invalidate all*/
  210. "movc p0.c6, ip, #6\n" /*TLB invalidate all*/
  211. "nop;nop;nop;nop;nop;nop;nop;nop;\n"
  212. "movc ip, p0.c1, #0\n" /*ctrl register*/
  213. "andn ip, ip, #0x000f\n" /*disable caches and mmu*/
  214. "movc p0.c1, ip, #0\n"
  215. "nop\n"
  216. "mov pc, %0\n"
  217. "nop;nop;nop;nop;nop;nop;nop;nop;\n"
  218. : "=&r" (addr)
  219. :
  220. :"memory", "cc");
  221. }
  222. static void sep6200_poweroff(void)
  223. {
  224. rt_kprintf("sep6200 power off not implemented\n");
  225. while(1);
  226. }
  227. /**
  228. * reset cpu by dog's time-out
  229. *
  230. */
  231. void rt_hw_cpu_reset()
  232. {
  233. rt_kprintf("Soft reset, Restarting system...\n");
  234. sep6200_reset(0);
  235. while(1); /* loop forever and wait for reset to happen */
  236. /* NEVER REACHED */
  237. }
  238. /**
  239. * shutdown CPU
  240. *
  241. */
  242. void rt_hw_cpu_shutdown()
  243. {
  244. rt_uint32_t level;
  245. rt_kprintf("shutdown...\n");
  246. level = rt_hw_interrupt_disable();
  247. sep6200_poweroff();
  248. while (level)
  249. {
  250. RT_ASSERT(0);
  251. }
  252. }
  253. /*@}*/