cc3200_asm.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * This file is part of the MicroPython project, http://micropython.org/
  3. *
  4. * The MIT License (MIT)
  5. *
  6. * Copyright (c) 2015 Daniel Campora
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. */
  26. #ifndef CC3200_ASM_H_
  27. #define CC3200_ASM_H_
  28. // We have inlined IRQ functions for efficiency (they are generally
  29. // 1 machine instruction).
  30. //
  31. // Note on IRQ state: you should not need to know the specific
  32. // value of the state variable, but rather just pass the return
  33. // value from disable_irq back to enable_irq. If you really need
  34. // to know the machine-specific values, see irq.h.
  35. #ifndef __disable_irq
  36. #define __disable_irq() __asm__ volatile ("cpsid i");
  37. #endif
  38. #ifndef DEBUG
  39. __attribute__(( always_inline ))
  40. static inline void __WFI(void) {
  41. __asm volatile (" dsb \n"
  42. " isb \n"
  43. " wfi \n");
  44. }
  45. #else
  46. // For some reason the debugger gets disconnected when entering any of the sleep modes
  47. __attribute__(( always_inline ))
  48. static inline void __WFI(void) {
  49. __asm volatile (" dsb \n"
  50. " isb \n");
  51. }
  52. #endif
  53. __attribute__(( always_inline ))
  54. static inline uint32_t __get_PRIMASK(void) {
  55. uint32_t result;
  56. __asm volatile ("mrs %0, primask" : "=r" (result));
  57. return(result);
  58. }
  59. __attribute__(( always_inline ))
  60. static inline void __set_PRIMASK(uint32_t priMask) {
  61. __asm volatile ("msr primask, %0" : : "r" (priMask) : "memory");
  62. }
  63. __attribute__(( always_inline ))
  64. static inline uint32_t __get_BASEPRI(void) {
  65. uint32_t result;
  66. __asm volatile ("mrs %0, basepri" : "=r" (result));
  67. return(result);
  68. }
  69. __attribute__(( always_inline ))
  70. static inline void __set_BASEPRI(uint32_t value) {
  71. __asm volatile ("msr basepri, %0" : : "r" (value) : "memory");
  72. }
  73. __attribute__(( always_inline ))
  74. static inline void enable_irq(mp_uint_t state) {
  75. __set_PRIMASK(state);
  76. }
  77. __attribute__(( always_inline ))
  78. static inline mp_uint_t disable_irq(void) {
  79. mp_uint_t state = __get_PRIMASK();
  80. __disable_irq();
  81. return state;
  82. }
  83. #endif /* CC3200_ASM_H_ */