signal.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*-------------------------------------------------------------------------
  2. signal.h - Signal handler header
  3. Copyright (C) 2005, Vangelis Rokas <vrokas AT otenet.gr>
  4. This library is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. 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
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this library; see the file COPYING. If not, write to the
  14. Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
  15. MA 02110-1301, USA.
  16. As a special exception, if you link this library with other files,
  17. some of which are compiled with SDCC, to produce an executable,
  18. this library does not by itself cause the resulting executable to
  19. be covered by the GNU General Public License. This exception does
  20. not however invalidate any other reasons why the executable file
  21. might be covered by the GNU General Public License.
  22. -------------------------------------------------------------------------*/
  23. #ifndef __SIGNAL_H__
  24. #define __SIGNAL_H__
  25. /* interrupt testing arguments */
  26. #define SIG_RB SIG_RBIF
  27. #define SIG_INT0 SIG_INT0IF
  28. #define SIG_INT1 SIG_INT1IF
  29. #define SIG_INT2 SIG_INT2IF
  30. #define SIG_CCP1 SIG_CCP1IF
  31. #define SIG_CCP2 SIG_CCP2IF
  32. #define SIG_TMR0 SIG_TMR0IF
  33. #define SIG_TMR1 SIG_TMR1IF
  34. #define SIG_TMR2 SIG_TMR2IF
  35. #define SIG_TMR3 SIG_TMR3IF
  36. #define SIG_EE SIG_EEIF
  37. #define SIG_BCOL SIG_BCOLIF
  38. #define SIG_LVD SIG_LVDIF
  39. #define SIG_PSP SIG_PSPIF
  40. #define SIG_AD SIG_ADIF
  41. #define SIG_RC SIG_RCIF
  42. #define SIG_TX SIG_TXIF
  43. #define SIG_SSP SIG_SSPIF
  44. #define SIG_MSSP SIG_SSPIF /* just an alias */
  45. #define SIG_USB SIG_USBIF
  46. /* define name to be the interrupt handler for interrupt #vecno */
  47. #define DEF_ABSVECTOR(vecno, name) \
  48. void __ivt_ ## name(void) __interrupt(vecno) __naked \
  49. { \
  50. __asm goto _ ## name __endasm; \
  51. }
  52. /* Define name to be the handler for high priority interrupts,
  53. * use like this:
  54. * DEF_INTHIGH(high_handler)
  55. * DEF_HANDLER(SIG_TMR0, timer0_handler)
  56. * DEF_HANDLER2(SIG_TMR1, SIG_TMR1IE, timer1_handler)
  57. * ...
  58. * END_DEF
  59. *
  60. * SIGHANDLER(timer0_handler)
  61. * {
  62. * // code to handle timer0 interrupts
  63. * }
  64. * SIGHANDLER(timer1_handler)
  65. * {
  66. * // code to handle timer1 interrupts
  67. * }
  68. */
  69. #define DEF_INTHIGH(name) \
  70. DEF_ABSVECTOR(1, name) \
  71. void name(void) __naked __interrupt \
  72. {
  73. /* Define name to be the handler for high priority interrupts,
  74. * use like this:
  75. * DEF_INTLOW(low_handler)
  76. * DEF_HANDLER(SIG_RB, portb_handler)
  77. * DEF_HANDLER2(SIG_LVD, SIG_LVDIE, lowvolt_handler)
  78. * ...
  79. * END_DEF
  80. *
  81. * SIGHANDLER(portb_handler)
  82. * {
  83. * // code to handle PORTB change interrupts
  84. * }
  85. * SIGHANDLER(lowvolt_handler)
  86. * {
  87. * // code to handle low voltage interrupts
  88. * }
  89. */
  90. #define DEF_INTLOW(name) \
  91. DEF_ABSVECTOR(2, name) \
  92. void name(void) __naked __interrupt \
  93. {
  94. /* finish an interrupt handler definition */
  95. #define END_DEF \
  96. __asm retfie __endasm; \
  97. }
  98. /* Declare handler to be the handler function for the given signal.
  99. * sig should be one of SIG_xxx from above, handler should be a
  100. * function defined using SIGHANDLER(handler) or
  101. * SIGHANDLERNAKED(handler).
  102. * ATTENTION: This macro ignores the signal's enable bit!
  103. * Use DEF_HANDLER2(SIG_xxx, SIGxxxIE, handler) instead!
  104. * To be used together with DEF_INTHIGH and DEF_INTLOW.
  105. */
  106. #define DEF_HANDLER(sig, handler) \
  107. __asm btfsc sig, 0 __endasm; \
  108. __asm goto _ ## handler __endasm;
  109. /* Declare handler to be the handler function for the given signal.
  110. * sig should be one of SIG_xxx from above,
  111. * sig2 should also be a signal (probably SIG_xxxIE from below) and
  112. * handler should be a function defined using SIGHANDLER(handler)
  113. * or SIGHANDLERNAKED(handler).
  114. * To be used together with DEF_INTHIGH and DEF_INTLOW.
  115. */
  116. #define DEF_HANDLER2(sig1,sig2,handler) \
  117. __asm btfss sig1, 0 __endasm; \
  118. __asm bra $+8 __endasm; \
  119. __asm btfsc sig2, 0 __endasm; \
  120. __asm goto _ ## handler __endasm;
  121. /* Declare or define an interrupt handler function. */
  122. #define SIGHANDLER(handler) void handler (void) __interrupt
  123. #define SIGHANDLERNAKED(handler) void handler (void) __naked __interrupt
  124. /*
  125. * inline assembly compatible bit definitions
  126. */
  127. #define SIG_RBIF _INTCON, 0
  128. #define SIG_RBIE _INTCON, 3
  129. #define SIG_RBIP _INTCON2, 0
  130. #define SIG_INT0IF _INTCON, 1
  131. #define SIG_INT0IE _INTCON, 4
  132. /*#define SIG_INT0IP not selectable, always ? */
  133. #define SIG_TMR0IF _INTCON, 2
  134. #define SIG_TMR0IE _INTCON, 5
  135. #define SIG_TMR0IP _INTCON2, 2
  136. #define SIG_INT1IF _INTCON3, 0
  137. #define SIG_INT1IE _INTCON3, 3
  138. #define SIG_INT1IP _INTCON3, 6
  139. #define SIG_INT2IF _INTCON3, 1
  140. #define SIG_INT2IE _INTCON3, 4
  141. #define SIG_INT2IP _INTCON3, 7
  142. /* device dependent -- should be moved to pic18f*.h */
  143. #define SIG_TMR1IDX 0
  144. #define SIG_TMR1SUF 1
  145. #define SIG_TMR2IDX 1
  146. #define SIG_TMR2SUF 1
  147. #define SIG_CCP1IDX 2
  148. #define SIG_CCP1SUF 1
  149. #define SIG_SSPIDX 3
  150. #define SIG_SSPSUF 1
  151. #define SIG_TXIDX 4
  152. #define SIG_TXSUF 1
  153. #define SIG_RCIDX 5
  154. #define SIG_RCSUF 1
  155. #define SIG_ADIDX 6
  156. #define SIG_ADSUF 1
  157. #define SIG_PSPIDX 7
  158. #define SIG_PSPSUF 1
  159. #define SIG_CCP2IDX 0
  160. #define SIG_CCP2SUF 2
  161. #define SIG_TMR3IDX 1
  162. #define SIG_TMR3SUF 2
  163. #define SIG_LVDIDX 2
  164. #define SIG_LVDSUF 2
  165. #define SIG_BCOLIDX 3
  166. #define SIG_BCOLSUF 2
  167. #define SIG_EEIDX 4
  168. #define SIG_EESUF 2
  169. #define SIG_USBIDX 5
  170. #define SIG_USBSUF 2
  171. /* device independent */
  172. #define __concat(a,b) __concat2(a,b)
  173. #define __concat2(a,b) a ## b
  174. #define SIG_PIR(suf) __concat(_PIR,suf)
  175. #define SIG_PIE(suf) __concat(_PIE,suf)
  176. #define SIG_IPR(suf) __concat(_IPR,suf)
  177. #define SIG_TMR1IF SIG_PIR(SIG_TMR1SUF), SIG_TMR1IDX
  178. #define SIG_TMR1IE SIG_PIE(SIG_TMR1SUF), SIG_TMR1IDX
  179. #define SIG_TMR1IP SIG_IPR(SIG_TMR1SUF), SIG_TMR1IDX
  180. #define SIG_TMR2IF SIG_PIR(SIG_TMR2SUF), SIG_TMR2IDX
  181. #define SIG_TMR2IE SIG_PIE(SIG_TMR2SUF), SIG_TMR2IDX
  182. #define SIG_TMR2IP SIG_IPR(SIG_TMR2SUF), SIG_TMR2IDX
  183. #define SIG_CCP1IF SIG_PIR(SIG_CCP1SUF), SIG_CCP1IDX
  184. #define SIG_CCP1IE SIG_PIE(SIG_CCP1SUF), SIG_CCP1IDX
  185. #define SIG_CCP1IP SIG_IPR(SIG_CCP1SUF), SIG_CCP1IDX
  186. #define SIG_SSPIF SIG_PIR(SIG_SSPSUF), SIG_SSPIDX
  187. #define SIG_SSPIE SIG_PIE(SIG_SSPSUF), SIG_SSPIDX
  188. #define SIG_SSPIP SIG_IPR(SIG_SSPSUF), SIG_SSPIDX
  189. /* aliases: MSSP */
  190. #define SIG_MSSPIF SIG_SSPIF //SIG_PIR(SIG_SSPSUF), SIG_SSPIDX
  191. #define SIG_MSSPIE SIG_SSPIE //SIG_PIE(SIG_SSPSUF), SIG_SSPIDX
  192. #define SIG_MSSPIP SIG_SSPIP //SIG_IPR(SIG_SSPSUF), SIG_SSPIDX
  193. #define SIG_TXIF SIG_PIR(SIG_TXSUF), SIG_TXIDX
  194. #define SIG_TXIE SIG_PIE(SIG_TXSUF), SIG_TXIDX
  195. #define SIG_TXIP SIG_IPR(SIG_TXSUF), SIG_TXIDX
  196. #define SIG_RCIF SIG_PIR(SIG_RCSUF), SIG_RCIDX
  197. #define SIG_RCIE SIG_PIE(SIG_RCSUF), SIG_RCIDX
  198. #define SIG_RCIP SIG_IPR(SIG_RCSUF), SIG_RCIDX
  199. #define SIG_ADIF SIG_PIR(SIG_ADSUF), SIG_ADIDX
  200. #define SIG_ADIE SIG_PIE(SIG_ADSUF), SIG_ADIDX
  201. #define SIG_ADIP SIG_IPR(SIG_ADSUF), SIG_ADIDX
  202. #define SIG_PSPIF SIG_PIR(SIG_PSPSUF), SIG_PSPIDX
  203. #define SIG_PSPIE SIG_PIE(SIG_PSPSUF), SIG_PSPIDX
  204. #define SIG_PSPIP SIG_IPR(SIG_PSPSUF), SIG_PSPIDX
  205. #define SIG_CCP2IF SIG_PIR(SIG_CCP2SUF), SIG_CCP2IDX
  206. #define SIG_CCP2IE SIG_PIE(SIG_CCP2SUF), SIG_CCP2IDX
  207. #define SIG_CCP2IP SIG_IPR(SIG_CCP2SUF), SIG_CCP2IDX
  208. #define SIG_TMR3IF SIG_PIR(SIG_TMR3SUF), SIG_TMR3IDX
  209. #define SIG_TMR3IE SIG_PIE(SIG_TMR3SUF), SIG_TMR3IDX
  210. #define SIG_TMR3IP SIG_IPR(SIG_TMR3SUF), SIG_TMR3IDX
  211. #define SIG_LVDIF SIG_PIR(SIG_LVDSUF), SIG_LVDIDX
  212. #define SIG_LVDIE SIG_PIE(SIG_LVDSUF), SIG_LVDIDX
  213. #define SIG_LVDIP SIG_IPR(SIG_LVDSUF), SIG_LVDIDX
  214. #define SIG_BCOLIF SIG_PIR(SIG_BCOLSUF), SIG_BCOLIDX
  215. #define SIG_BCOLIE SIG_PIE(SIG_BCOLSUF), SIG_BCOLIDX
  216. #define SIG_BCOLIP SIG_IPR(SIG_BCOLSUF), SIG_BCOLIDX
  217. #define SIG_EEIF SIG_PIR(SIG_EESUF), SIG_EEIDX
  218. #define SIG_EEIE SIG_PIE(SIG_EESUF), SIG_EEIDX
  219. #define SIG_EEIP SIG_IPR(SIG_EESUF), SIG_EEIDX
  220. #define SIG_USBIF SIG_PIR(SIG_USBSUF), SIG_USBIDX
  221. #define SIG_USBIE SIG_PIE(SIG_USBSUF), SIG_USBIDX
  222. #define SIG_USBIP SIG_IPR(SIG_USBSUF), SIG_USBIDX
  223. #endif /* __SIGNAL_H__ */