cpu.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. //*****************************************************************************
  2. //
  3. // cpu.c - Instruction wrappers for special CPU instructions needed by the
  4. // drivers.
  5. //
  6. // Copyright (c) 2006-2009 Luminary Micro, Inc. All rights reserved.
  7. // Software License Agreement
  8. //
  9. // Luminary Micro, Inc. (LMI) is supplying this software for use solely and
  10. // exclusively on LMI's microcontroller products.
  11. //
  12. // The software is owned by LMI and/or its suppliers, and is protected under
  13. // applicable copyright laws. All rights are reserved. You may not combine
  14. // this software with "viral" open-source software in order to form a larger
  15. // program. Any use in violation of the foregoing restrictions may subject
  16. // the user to criminal sanctions under applicable laws, as well as to civil
  17. // liability for the breach of the terms and conditions of this license.
  18. //
  19. // THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  20. // OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  21. // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  22. // LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  23. // CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  24. //
  25. // This is part of revision 4694 of the Stellaris Peripheral Driver Library.
  26. //
  27. //*****************************************************************************
  28. #include "driverlib/cpu.h"
  29. //*****************************************************************************
  30. //
  31. // Wrapper function for the CPSID instruction. Returns the state of PRIMASK
  32. // on entry.
  33. //
  34. //*****************************************************************************
  35. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  36. unsigned long __attribute__((naked))
  37. CPUcpsid(void)
  38. {
  39. unsigned long ulRet;
  40. //
  41. // Read PRIMASK and disable interrupts.
  42. //
  43. __asm(" mrs %0, PRIMASK\n"
  44. " cpsid i\n"
  45. " bx lr\n"
  46. : "=r" (ulRet));
  47. //
  48. // The return is handled in the inline assembly, but the compiler will
  49. // still complain if there is not an explicit return here (despite the fact
  50. // that this does not result in any code being produced because of the
  51. // naked attribute).
  52. //
  53. return(ulRet);
  54. }
  55. #endif
  56. #if defined(ewarm)
  57. unsigned long
  58. CPUcpsid(void)
  59. {
  60. //
  61. // Read PRIMASK and disable interrupts.
  62. //
  63. __asm(" mrs r0, PRIMASK\n"
  64. " cpsid i\n");
  65. //
  66. // "Warning[Pe940]: missing return statement at end of non-void function"
  67. // is suppressed here to avoid putting a "bx lr" in the inline assembly
  68. // above and a superfluous return statement here.
  69. //
  70. #pragma diag_suppress=Pe940
  71. }
  72. #pragma diag_default=Pe940
  73. #endif
  74. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  75. __asm unsigned long
  76. CPUcpsid(void)
  77. {
  78. //
  79. // Read PRIMASK and disable interrupts.
  80. //
  81. mrs r0, PRIMASK;
  82. cpsid i;
  83. bx lr
  84. }
  85. #endif
  86. //*****************************************************************************
  87. //
  88. // Wrapper function for the CPSIE instruction. Returns the state of PRIMASK
  89. // on entry.
  90. //
  91. //*****************************************************************************
  92. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  93. unsigned long __attribute__((naked))
  94. CPUcpsie(void)
  95. {
  96. unsigned long ulRet;
  97. //
  98. // Read PRIMASK and enable interrupts.
  99. //
  100. __asm(" mrs %0, PRIMASK\n"
  101. " cpsie i\n"
  102. " bx lr\n"
  103. : "=r" (ulRet));
  104. //
  105. // The return is handled in the inline assembly, but the compiler will
  106. // still complain if there is not an explicit return here (despite the fact
  107. // that this does not result in any code being produced because of the
  108. // naked attribute).
  109. //
  110. return(ulRet);
  111. }
  112. #endif
  113. #if defined(ewarm)
  114. unsigned long
  115. CPUcpsie(void)
  116. {
  117. //
  118. // Read PRIMASK and enable interrupts.
  119. //
  120. __asm(" mrs r0, PRIMASK\n"
  121. " cpsie i\n");
  122. //
  123. // "Warning[Pe940]: missing return statement at end of non-void function"
  124. // is suppressed here to avoid putting a "bx lr" in the inline assembly
  125. // above and a superfluous return statement here.
  126. //
  127. #pragma diag_suppress=Pe940
  128. }
  129. #pragma diag_default=Pe940
  130. #endif
  131. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  132. __asm unsigned long
  133. CPUcpsie(void)
  134. {
  135. //
  136. // Read PRIMASK and enable interrupts.
  137. //
  138. mrs r0, PRIMASK;
  139. cpsie i;
  140. bx lr
  141. }
  142. #endif
  143. //*****************************************************************************
  144. //
  145. // Wrapper function for the WFI instruction.
  146. //
  147. //*****************************************************************************
  148. #if defined(codered) || defined(gcc) || defined(sourcerygxx)
  149. void __attribute__((naked))
  150. CPUwfi(void)
  151. {
  152. //
  153. // Wait for the next interrupt.
  154. //
  155. __asm(" wfi\n"
  156. " bx lr\n");
  157. }
  158. #endif
  159. #if defined(ewarm)
  160. void
  161. CPUwfi(void)
  162. {
  163. //
  164. // Wait for the next interrupt.
  165. //
  166. __asm(" wfi\n");
  167. }
  168. #endif
  169. #if defined(rvmdk) || defined(__ARMCC_VERSION)
  170. __asm void
  171. CPUwfi(void)
  172. {
  173. //
  174. // Wait for the next interrupt.
  175. //
  176. wfi;
  177. bx lr
  178. }
  179. #endif