irqstack.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef _DEV_IRQSTACK_H_
  2. #define _DEV_IRQSTACK_H_
  3. /*
  4. * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  23. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * $Log: irqstack.h,v $
  36. * Revision 1.6 2005/09/17 09:22:53 drsung
  37. * More program space saving implementation
  38. *
  39. * Revision 1.5 2005/02/05 20:39:43 haraldkipp
  40. * Force compiler error for leftover debug prints.
  41. *
  42. * Revision 1.4 2004/09/22 08:15:56 haraldkipp
  43. * Speparate IRQ stack configurable
  44. *
  45. * Revision 1.3 2004/04/25 17:06:17 drsung
  46. * Separate IRQ stack now compatible with nested interrupts.
  47. *
  48. * Revision 1.2 2004/02/03 11:28:41 drsung
  49. * Modified to support different target platforms.
  50. *
  51. * Revision 1.1 2004/01/30 17:00:46 drsung
  52. * Separate interrupt stack for avr-gcc only added.
  53. *
  54. */
  55. #include <cfg/dev.h>
  56. #ifdef IRQSTACK_SIZE
  57. #include <sys/types.h>
  58. #define _irq_prolog \
  59. asm volatile ("push r24" "\n\t" /* save r24 to current stack */ \
  60. "push r25" "\n\t" /* save r25 to current stack */ \
  61. "in r24,__SREG__" "\n\t" /* load SREG into r24 */ \
  62. "push r24" "\n\t"); /* and push it to current stack */
  63. #define _irq_epilog \
  64. asm volatile ("pop r24" "\n\t" /* restore r24 from stack */ \
  65. "out __SREG__, r24" "\n\t" /* write it to SREG */ \
  66. "pop r25" "\n\t" /* load byte from stack to r25 */ \
  67. "pop r24" "\n\t"); /* load byte from stack to r24 */
  68. #define NUTSIGNAL(signame,handler) \
  69. void signame (void) __attribute__ ((naked)); \
  70. void signame (void) \
  71. { \
  72. _irq_prolog \
  73. asm volatile ("ldi r24, lo8(%0)" "\n\t" \
  74. "ldi r25, hi8(%0)" "\n\t" \
  75. "jmp _irq_interrupt" "\n\t" \
  76. :: "i" (&handler)); \
  77. }
  78. #else /* IRQSTACK_SIZE */
  79. #define NUTSIGNAL(signame,handler) \
  80. SIGNAL(signame) \
  81. { CallHandler (&handler); }
  82. #endif /* !IRQSTACK_SIZE */
  83. #endif