specific_instructions.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. specific_instructions.h - RX specific functions
  3. Copyright (c) 2014 Nozomu Fujita. All right reserved.
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. */
  16. /*
  17. Modified 12 July 2018 by Yuuki Okamiya for GR-ROSE
  18. */
  19. #ifndef _SPECIFIC_INSTRUCTIONS_H_
  20. #define _SPECIFIC_INSTRUCTIONS_H_
  21. #if 0
  22. #define sei() \
  23. do { \
  24. __asm __volatile("setpsw i\n"); \
  25. } while (0)
  26. #define cli() \
  27. do { \
  28. __asm __volatile("clrpsw i\n"); \
  29. } while (0)
  30. #define isNoInterrupts() \
  31. ({ \
  32. bool ret; \
  33. __asm __volatile( \
  34. "mvfc psw, %0\n" \
  35. "btst #16, %0\n" \
  36. "sceq.l %0\n" \
  37. : "=r" (ret) \
  38. : \
  39. : \
  40. ); \
  41. ret; \
  42. })
  43. #else
  44. #define sei() __builtin_rx_setpsw('I')
  45. #define cli() __builtin_rx_clrpsw('I')
  46. #define isNoInterrupts() (!(__builtin_rx_mvfc(0x0) && 0x00010000))
  47. #endif
  48. #define pushi() \
  49. { \
  50. bool _di = isNoInterrupts();
  51. #define popi() \
  52. if (_di) { \
  53. cli(); \
  54. } else { \
  55. sei(); \
  56. } \
  57. }
  58. #if 0
  59. #define BSET(port, bit) \
  60. do { \
  61. volatile byte* _port = (port); \
  62. int _bit = (bit); \
  63. __asm __volatile( \
  64. "bset %1, [%0].b\n" \
  65. : \
  66. : "r" (_port), "r" (_bit) \
  67. : \
  68. ); \
  69. } while (0)
  70. #define BCLR(port, bit) \
  71. do { \
  72. volatile byte* _port = (port); \
  73. int _bit = (bit); \
  74. __asm __volatile( \
  75. "bclr %1, [%0].b\n" \
  76. : \
  77. : "r" (_port), "r" (_bit) \
  78. : \
  79. ); \
  80. } while (0)
  81. #define BTST(port, bit) \
  82. ({ \
  83. volatile byte* _port = (port); \
  84. int _bit = (bit); \
  85. int ret; \
  86. __asm __volatile( \
  87. "btst %2, [%1].b\n" \
  88. "scnz.l %0\n" \
  89. : "=r" (ret) \
  90. : "r" (_port), "r" (_bit) \
  91. : \
  92. ); \
  93. ret; \
  94. })
  95. #else
  96. #define BSET(port, bit) \
  97. do { \
  98. *port = *port | (1 << bit); \
  99. } while (0)
  100. #define BCLR(port, bit) \
  101. do { \
  102. *port = *port & ~(1 << bit); \
  103. } while (0)
  104. #endif
  105. #define sbi(port, bit) BSET((port), (bit))
  106. #define cbi(port, bit) BCLR((port), (bit))
  107. #endif/*_SPECIFIC_INSTRUCTIONS_H_*/