cpu.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. //*****************************************************************************
  2. //
  3. // cpu.c - Instruction wrappers for special CPU instructions needed by the
  4. // drivers.
  5. //
  6. // Copyright (c) 2006-2011 Texas Instruments Incorporated. All rights reserved.
  7. // Software License Agreement
  8. //
  9. // Texas Instruments (TI) is supplying this software for use solely and
  10. // exclusively on TI's microcontroller products. The software is owned by
  11. // TI and/or its suppliers, and is protected under applicable copyright
  12. // laws. You may not combine this software with "viral" open-source
  13. // software in order to form a larger program.
  14. //
  15. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  16. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  17. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  18. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  19. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  20. // DAMAGES, FOR ANY REASON WHATSOEVER.
  21. //
  22. // This is part of revision 8264 of the Stellaris Peripheral Driver Library.
  23. //
  24. //*****************************************************************************
  25. #include "driverlib/cpu.h"
  26. //*****************************************************************************
  27. //
  28. // Wrapper function for the CPSID instruction. Returns the state of PRIMASK
  29. // on entry.
  30. //
  31. //*****************************************************************************
  32. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  33. unsigned long __attribute__((naked))
  34. CPUcpsid(void)
  35. {
  36. unsigned long ulRet;
  37. //
  38. // Read PRIMASK and disable interrupts.
  39. //
  40. __asm(" mrs r0, PRIMASK\n"
  41. " cpsid i\n"
  42. " bx lr\n"
  43. : "=r" (ulRet));
  44. //
  45. // The return is handled in the inline assembly, but the compiler will
  46. // still complain if there is not an explicit return here (despite the fact
  47. // that this does not result in any code being produced because of the
  48. // naked attribute).
  49. //
  50. return(ulRet);
  51. }
  52. #endif
  53. #if defined(ewarm)
  54. unsigned long
  55. CPUcpsid(void)
  56. {
  57. //
  58. // Read PRIMASK and disable interrupts.
  59. //
  60. __asm(" mrs r0, PRIMASK\n"
  61. " cpsid i\n");
  62. //
  63. // "Warning[Pe940]: missing return statement at end of non-void function"
  64. // is suppressed here to avoid putting a "bx lr" in the inline assembly
  65. // above and a superfluous return statement here.
  66. //
  67. #pragma diag_suppress=Pe940
  68. }
  69. #pragma diag_default=Pe940
  70. #endif
  71. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  72. __asm unsigned long
  73. CPUcpsid(void)
  74. {
  75. //
  76. // Read PRIMASK and disable interrupts.
  77. //
  78. mrs r0, PRIMASK;
  79. cpsid i;
  80. bx lr
  81. }
  82. #endif
  83. #if defined(ccs)
  84. unsigned long
  85. CPUcpsid(void)
  86. {
  87. //
  88. // Read PRIMASK and disable interrupts.
  89. //
  90. __asm(" mrs r0, PRIMASK\n"
  91. " cpsid i\n"
  92. " bx lr\n");
  93. //
  94. // The following keeps the compiler happy, because it wants to see a
  95. // return value from this function. It will generate code to return
  96. // a zero. However, the real return is the "bx lr" above, so the
  97. // return(0) is never executed and the function returns with the value
  98. // you expect in R0.
  99. //
  100. return(0);
  101. }
  102. #endif
  103. //*****************************************************************************
  104. //
  105. // Wrapper function returning the state of PRIMASK (indicating whether
  106. // interrupts are enabled or disabled).
  107. //
  108. //*****************************************************************************
  109. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  110. unsigned long __attribute__((naked))
  111. CPUprimask(void)
  112. {
  113. unsigned long ulRet;
  114. //
  115. // Read PRIMASK and disable interrupts.
  116. //
  117. __asm(" mrs r0, PRIMASK\n"
  118. " bx lr\n"
  119. : "=r" (ulRet));
  120. //
  121. // The return is handled in the inline assembly, but the compiler will
  122. // still complain if there is not an explicit return here (despite the fact
  123. // that this does not result in any code being produced because of the
  124. // naked attribute).
  125. //
  126. return(ulRet);
  127. }
  128. #endif
  129. #if defined(ewarm)
  130. unsigned long
  131. CPUprimask(void)
  132. {
  133. //
  134. // Read PRIMASK and disable interrupts.
  135. //
  136. __asm(" mrs r0, PRIMASK\n");
  137. //
  138. // "Warning[Pe940]: missing return statement at end of non-void function"
  139. // is suppressed here to avoid putting a "bx lr" in the inline assembly
  140. // above and a superfluous return statement here.
  141. //
  142. #pragma diag_suppress=Pe940
  143. }
  144. #pragma diag_default=Pe940
  145. #endif
  146. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  147. __asm unsigned long
  148. CPUprimask(void)
  149. {
  150. //
  151. // Read PRIMASK and disable interrupts.
  152. //
  153. mrs r0, PRIMASK;
  154. bx lr
  155. }
  156. #endif
  157. #if defined(ccs)
  158. unsigned long
  159. CPUprimask(void)
  160. {
  161. //
  162. // Read PRIMASK and disable interrupts.
  163. //
  164. __asm(" mrs r0, PRIMASK\n"
  165. " bx lr\n");
  166. //
  167. // The following keeps the compiler happy, because it wants to see a
  168. // return value from this function. It will generate code to return
  169. // a zero. However, the real return is the "bx lr" above, so the
  170. // return(0) is never executed and the function returns with the value
  171. // you expect in R0.
  172. //
  173. return(0);
  174. }
  175. #endif
  176. //*****************************************************************************
  177. //
  178. // Wrapper function for the CPSIE instruction. Returns the state of PRIMASK
  179. // on entry.
  180. //
  181. //*****************************************************************************
  182. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  183. unsigned long __attribute__((naked))
  184. CPUcpsie(void)
  185. {
  186. unsigned long ulRet;
  187. //
  188. // Read PRIMASK and enable interrupts.
  189. //
  190. __asm(" mrs r0, PRIMASK\n"
  191. " cpsie i\n"
  192. " bx lr\n"
  193. : "=r" (ulRet));
  194. //
  195. // The return is handled in the inline assembly, but the compiler will
  196. // still complain if there is not an explicit return here (despite the fact
  197. // that this does not result in any code being produced because of the
  198. // naked attribute).
  199. //
  200. return(ulRet);
  201. }
  202. #endif
  203. #if defined(ewarm)
  204. unsigned long
  205. CPUcpsie(void)
  206. {
  207. //
  208. // Read PRIMASK and enable interrupts.
  209. //
  210. __asm(" mrs r0, PRIMASK\n"
  211. " cpsie i\n");
  212. //
  213. // "Warning[Pe940]: missing return statement at end of non-void function"
  214. // is suppressed here to avoid putting a "bx lr" in the inline assembly
  215. // above and a superfluous return statement here.
  216. //
  217. #pragma diag_suppress=Pe940
  218. }
  219. #pragma diag_default=Pe940
  220. #endif
  221. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  222. __asm unsigned long
  223. CPUcpsie(void)
  224. {
  225. //
  226. // Read PRIMASK and enable interrupts.
  227. //
  228. mrs r0, PRIMASK;
  229. cpsie i;
  230. bx lr
  231. }
  232. #endif
  233. #if defined(ccs)
  234. unsigned long
  235. CPUcpsie(void)
  236. {
  237. //
  238. // Read PRIMASK and enable interrupts.
  239. //
  240. __asm(" mrs r0, PRIMASK\n"
  241. " cpsie i\n"
  242. " bx lr\n");
  243. //
  244. // The following keeps the compiler happy, because it wants to see a
  245. // return value from this function. It will generate code to return
  246. // a zero. However, the real return is the "bx lr" above, so the
  247. // return(0) is never executed and the function returns with the value
  248. // you expect in R0.
  249. //
  250. return(0);
  251. }
  252. #endif
  253. //*****************************************************************************
  254. //
  255. // Wrapper function for the WFI instruction.
  256. //
  257. //*****************************************************************************
  258. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  259. void __attribute__((naked))
  260. CPUwfi(void)
  261. {
  262. //
  263. // Wait for the next interrupt.
  264. //
  265. __asm(" wfi\n"
  266. " bx lr\n");
  267. }
  268. #endif
  269. #if defined(ewarm)
  270. void
  271. CPUwfi(void)
  272. {
  273. //
  274. // Wait for the next interrupt.
  275. //
  276. __asm(" wfi\n");
  277. }
  278. #endif
  279. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  280. __asm void
  281. CPUwfi(void)
  282. {
  283. //
  284. // Wait for the next interrupt.
  285. //
  286. wfi;
  287. bx lr
  288. }
  289. #endif
  290. #if defined(ccs)
  291. void
  292. CPUwfi(void)
  293. {
  294. //
  295. // Wait for the next interrupt.
  296. //
  297. __asm(" wfi\n");
  298. }
  299. #endif
  300. //*****************************************************************************
  301. //
  302. // Wrapper function for writing the BASEPRI register.
  303. //
  304. //*****************************************************************************
  305. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  306. void __attribute__((naked))
  307. CPUbasepriSet(unsigned long ulNewBasepri)
  308. {
  309. //
  310. // Set the BASEPRI register
  311. //
  312. __asm(" msr BASEPRI, r0\n"
  313. " bx lr\n");
  314. }
  315. #endif
  316. #if defined(ewarm)
  317. void
  318. CPUbasepriSet(unsigned long ulNewBasepri)
  319. {
  320. //
  321. // Set the BASEPRI register
  322. //
  323. __asm(" msr BASEPRI, r0\n");
  324. }
  325. #endif
  326. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  327. __asm void
  328. CPUbasepriSet(unsigned long ulNewBasepri)
  329. {
  330. //
  331. // Set the BASEPRI register
  332. //
  333. msr BASEPRI, r0;
  334. bx lr
  335. }
  336. #endif
  337. #if defined(ccs)
  338. void
  339. CPUbasepriSet(unsigned long ulNewBasepri)
  340. {
  341. //
  342. // Set the BASEPRI register
  343. //
  344. __asm(" msr BASEPRI, r0\n");
  345. }
  346. #endif
  347. //*****************************************************************************
  348. //
  349. // Wrapper function for reading the BASEPRI register.
  350. //
  351. //*****************************************************************************
  352. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  353. unsigned long __attribute__((naked))
  354. CPUbasepriGet(void)
  355. {
  356. unsigned long ulRet;
  357. //
  358. // Read BASEPRI
  359. //
  360. __asm(" mrs r0, BASEPRI\n"
  361. " bx lr\n"
  362. : "=r" (ulRet));
  363. //
  364. // The return is handled in the inline assembly, but the compiler will
  365. // still complain if there is not an explicit return here (despite the fact
  366. // that this does not result in any code being produced because of the
  367. // naked attribute).
  368. //
  369. return(ulRet);
  370. }
  371. #endif
  372. #if defined(ewarm)
  373. unsigned long
  374. CPUbasepriGet(void)
  375. {
  376. //
  377. // Read BASEPRI
  378. //
  379. __asm(" mrs r0, BASEPRI\n");
  380. //
  381. // "Warning[Pe940]: missing return statement at end of non-void function"
  382. // is suppressed here to avoid putting a "bx lr" in the inline assembly
  383. // above and a superfluous return statement here.
  384. //
  385. #pragma diag_suppress=Pe940
  386. }
  387. #pragma diag_default=Pe940
  388. #endif
  389. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  390. __asm unsigned long
  391. CPUbasepriGet(void)
  392. {
  393. //
  394. // Read BASEPRI
  395. //
  396. mrs r0, BASEPRI;
  397. bx lr
  398. }
  399. #endif
  400. #if defined(ccs)
  401. unsigned long
  402. CPUbasepriGet(void)
  403. {
  404. //
  405. // Read BASEPRI
  406. //
  407. __asm(" mrs r0, BASEPRI\n"
  408. " bx lr\n");
  409. //
  410. // The following keeps the compiler happy, because it wants to see a
  411. // return value from this function. It will generate code to return
  412. // a zero. However, the real return is the "bx lr" above, so the
  413. // return(0) is never executed and the function returns with the value
  414. // you expect in R0.
  415. //
  416. return(0);
  417. }
  418. #endif