cpu.c 12 KB

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