home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / ibm / pc / hardware / 24131 < prev    next >
Encoding:
Text File  |  1992-09-13  |  2.8 KB  |  130 lines

  1. Xref: sparky comp.sys.ibm.pc.hardware:24131 comp.sys.ibm.pc.programmer:412
  2. Newsgroups: comp.sys.ibm.pc.hardware,comp.sys.ibm.pc.programmer
  3. Path: sparky!uunet!mcsun!sun4nl!dutrun!donau!zen!wolff
  4. From: wolff@zen.et.tudelft.nl (Rogier Wolff)
  5. Subject: Serial line interrupts.
  6. Message-ID: <1992Sep13.093415.10243@donau.et.tudelft.nl>
  7. Originator: wolff@zen.et.tudelft.nl
  8. Sender: news@donau.et.tudelft.nl (UseNet News System)
  9. Nntp-Posting-Host: zen.et.tudelft.nl
  10. Reply-To: wolff@zen.et.tudelft.nl (Rogier Wolff)
  11. Organization: Delft University of Technology, Dept. of Electrical Engineering
  12. Date: Sun, 13 Sep 1992 09:34:15 GMT
  13. Lines: 115
  14.  
  15.  
  16. Hi everyone,
  17.  
  18. I'm trying to make a simple program using interrupts to read the serial
  19. ports. However it seems as if I can't get the interrupts enabled to such
  20. a level that my interrupt routine gets called. Does anybody out there know
  21. any other bits that I should twiddle before I can receive interrupts?
  22. (I had expected some trouble in getting the write interrupt to work,
  23. turning it on and off at the rigth time. However I don't get any interrupts
  24. at all!)
  25.  
  26. The interrupt handling part of the program is below, the rest is
  27. chopped off for brevity. (Yes I _do_ call initirq)
  28.  
  29.  
  30. #include <dos.h>
  31.  
  32. #define BUFSIZE 128
  33.  
  34. #define READ_READY 0x01
  35. #define WRITE_READY 0x20
  36.  
  37. static int wqis=BUFSIZE,wqos=0;
  38. static char wq[BUFSIZE];
  39. static int wqhead=0;
  40. static int wqtail=0;
  41.  
  42. static int rqis=BUFSIZE,rqos=0;
  43. static char rq[BUFSIZE];
  44. static int rqhead= 0;
  45. static int rqtail= 0;
  46.  
  47. int base = 0x2f8;
  48.  
  49. interrupt anyint (void);
  50. void read_int (void);
  51. void write_int (void);
  52.  
  53. static int test=0;
  54.  
  55. void initirq (int port)
  56. {
  57. union REGS inregs,outregs;
  58. struct SREGS sregs;
  59.  
  60. static int bases[]= { 0x3f8,0x2f8,0x3e8,0x2e8};
  61. #define IRQNUM 3
  62. base = bases[port-1];
  63.  
  64. inregs.h.ah = 0x25;
  65. inregs.h.al = 0x0b;
  66. inregs.x.dx = FP_OFF (anyint);
  67. segread (&sregs);
  68. sregs.ds = FP_SEG (anyint);
  69. intdosx (&inregs,&outregs,&sregs);
  70. /*  *(long *) (MK_FP(0,0xb*4)) = anyint; */
  71. outportb (base+1,03);
  72. outportb (0x21,1 << IRQNUM);
  73. }
  74.  
  75. void ackit (int irq)
  76. {
  77. int tmp;
  78. static int t;
  79.  
  80.  
  81. tmp = inportb (0x21);
  82. t++;t++;
  83. outportb (0x21,tmp | (1<< irq));
  84. t++;t++;
  85. outportb (0x20,0x20);
  86. }
  87.  
  88. void unblk (int irq)
  89. {
  90. int tmp;
  91. static int t;
  92.  
  93. tmp = inportb (0x21);
  94. t++;t++;
  95. outportb (0x21, tmp & ~(1<< irq));
  96. }
  97.  
  98. interrupt anyint ()
  99. {
  100. int st;
  101.  
  102. /* I know, I shouldn't use printf in interrupts: it crashes the machine.
  103.    Which is the effect I hoped to provoke... */
  104. /*printf ("Hello world! \n"); */
  105. test++;
  106. ackit (3);
  107. st = inportb (base+5);
  108. if (st & WRITE_READY)
  109.     write_int ();
  110. if (st & READ_READY)
  111.     read_int ();
  112. unblk (3);
  113. return 0;
  114. }
  115.  
  116.  
  117. void disablewirq (void)
  118. {
  119. outportb (base+1,01);
  120. }
  121.  
  122. void restartirq (void)
  123. {
  124. outportb (base+1,03);
  125. }
  126.  
  127. -- 
  128. ****   a 486 in V86 mode is like a VW buggy with a 6 litre V12 motor.  ****
  129. EMail:  wolff@duteca.et.tudelft.nl   ** Tel  +31-15-783644 or +31-15-142371
  130.