dosirq.h
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:4k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*
  2.     Interface for IRQ routines on DOS
  3.     Copyright (C) 1999 by Andrew Zabolotny, <bit@eltech.ru>
  4.     This library is free software; you can redistribute it and/or
  5.     modify it under the terms of the GNU Library General Public
  6.     License as published by the Free Software Foundation; either
  7.     version 2 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.     Library General Public License for more details.
  12.     You should have received a copy of the GNU Library General Public
  13.     License along with this library; if not, write to the Free
  14.     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #ifndef __DOSIRQ_H__
  17. #define __DOSIRQ_H__
  18. #include <pc.h>
  19. #define PIC1_BASE 0x20 /* PIC1 base */
  20. #define PIC2_BASE 0xA0 /* PIC2 base */
  21. typedef struct {
  22. void (*c_handler) (); /* The real interrupt handler */
  23. unsigned long handler_size; /* The size of interrupt handler */
  24. unsigned long handler; /* Interrupt wrapper address */
  25. unsigned long prev_selector; /* Selector of previous handler */
  26. unsigned long prev_offset; /* Offset of previous handler */
  27. unsigned char irq_num; /* IRQ number */
  28. unsigned char int_num; /* Interrupt number */
  29. unsigned char pic_base; /* PIC base (0x20 or 0xA0) */
  30. unsigned char pic_mask; /* Old PIC mask state */
  31. } irq_handle;
  32. /* Return the enabled state for specific IRQ */
  33. static inline unsigned char irq_state(irq_handle * irq)
  34. {
  35. return ((~inportb(irq->pic_base + 1)) & (0x01 << (irq->irq_num & 7)));
  36. }
  37. /* Acknowledge the end of interrupt */
  38. static inline void _irq_ack(int irqno)
  39. {
  40. outportb(irqno > 7 ? PIC2_BASE : PIC1_BASE, 0x60 | (irqno & 7));
  41. /* For second controller we also should acknowledge first controller */
  42. if (irqno > 7)
  43. outportb(PIC1_BASE, 0x20); /* 0x20, 0x62? */
  44. }
  45. /* Acknowledge the end of interrupt */
  46. static inline void irq_ack(irq_handle * irq)
  47. {
  48. outportb(irq->pic_base, 0x60 | (irq->irq_num & 7));
  49. /* For second controller we also should acknowledge first controller */
  50. if (irq->pic_base != PIC1_BASE)
  51. outportb(PIC1_BASE, 0x20); /* 0x20, 0x62? */
  52. }
  53. /* Mask (disable) the particular IRQ given his ordinal */
  54. static inline void _irq_disable(int irqno)
  55. {
  56. unsigned int port_no = (irqno < 8 ? PIC1_BASE : PIC2_BASE) + 1;
  57. outportb(port_no, inportb(port_no) | (1 << (irqno & 7)));
  58. }
  59. /* Unmask (enable) the particular IRQ given its ordinal */
  60. static inline void _irq_enable(int irqno)
  61. {
  62. unsigned int port_no = (irqno < 8 ? PIC1_BASE : PIC2_BASE) + 1;
  63. outportb(port_no, inportb(port_no) & ~(1 << (irqno & 7)));
  64. }
  65. /* Mask (disable) the particular IRQ given its irq_handle structure */
  66. static inline void irq_disable(irq_handle * irq)
  67. {
  68. outportb(irq->pic_base + 1,
  69.                  inportb(irq->pic_base + 1) | (1 << (irq->irq_num & 7)));
  70. }
  71. /* Unmask (enable) the particular IRQ given its irq_handle structure */
  72. static inline void irq_enable(irq_handle * irq)
  73. {
  74. outportb(irq->pic_base + 1,
  75.                  inportb(irq->pic_base + 1) & ~(1 << (irq->irq_num & 7)));
  76. }
  77. /* Check if a specific IRQ is pending: return 0 is no */
  78. static inline int irq_check(irq_handle * irq)
  79. {
  80. outportb(irq->pic_base, 0x0B); /* Read IRR vector */
  81. return (inportb(irq->pic_base) & (1 << (irq->irq_num & 7)));
  82. }
  83. /* Hook a specific IRQ; NOTE: IRQ is disabled upon return, irq_enable() it */
  84. extern irq_handle *irq_hook(int irqno, void (*handler) (),
  85.                             unsigned long size);
  86. /* Unhook a previously hooked IRQ */
  87. extern void irq_unhook(irq_handle * irq);
  88. /* Start IRQ detection process (IRQ list is given with irq mask) */
  89. /* irq_confirm should return "1" if the IRQ really comes from the device */
  90. extern void irq_detect_start(unsigned int irqs,
  91.                              int (*irq_confirm) (int irqno));
  92. /* Finish IRQ detection process */
  93. extern void irq_detect_end();
  94. /* Get the count of specific irqno that happened */
  95. extern int irq_detect_get(int irqno, int *irqmask);
  96. /* Clear IRQ counters */
  97. extern void irq_detect_clear();
  98. /* The size of interrupt stack */
  99. extern unsigned int __irq_stack_size;
  100. /* The number of nested interrupts that can be handled */
  101. extern unsigned int __irq_stack_count;
  102. #endif /* __DOSIRQ_H__ */
  103. /* ex:set ts=4: */