AlcapDAQ  1
floppy_ttl.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 
4 #include <unistd.h>
5 #include <sys/io.h>
6 
7 #include "midas.h"
8 
9 #include "crate.h"
10 #include "diag.h"
11 
12 INT floppy_ttl_init();
16 
18  floppy_ttl_init, // init
19  NULL, // exit
20  NULL, // pre_bor
21  NULL, // bor
22  NULL, // eor
23  floppy_ttl_poll_live, // poll_live
24  floppy_ttl_poll_dead, // poll_dead
25  floppy_ttl_start_block, // start_block
26  NULL, // stop_block
27  NULL, // read
28 };
29 
30 /*
31  * floppy_ttl_init
32  *
33  * Called at the beginning of the run to discover SIS3600 modules
34  * and initialize them.
35  */
37 {
38  int status = iopl( 3 );
39 
40  if (status < 0) {
41  diag_print(0, "Unable to get permission to access I/O ports\n");
42  }
43 
44  // turn off output
45  outb(0x1d, 0x3f2);
46 
47  return SUCCESS;
48 }
49 
50 /*
51  * floppy_ttl_start_block
52  *
53  */
55 {
56  // Produce a quick pulse on the output
57  outb(0x0d, 0x3f2);
58  outb(0x1d, 0x3f2);
59 
60  bool ready = false;
61  DWORD start_waiting = ss_millitime();
62  while(!ready && ss_millitime() < start_waiting + 1000) {
63 // while(!ready) {
64  int input = inb(0x3f7);
65  if((input & 0x80)) {
66  ready = true;
67  }
68  }
69 
70  if(!ready) {
71  printf("\n\n\nNot ready, start times out\n");
72  }
73 
74  return SUCCESS;
75 }
76 
77 /*
78  * floppy_ttl_poll_live()
79  *
80  * Called periodically while a block is active; performs active readout.
81  *
82  * Returns:
83  * - ordinarily 0,
84  * - a request for a "soft stop" end-of-block, or
85  * - an error code
86  */
88 {
89  int input = inb(0x3f7);
90 
91  // high bit of input: 1 = TTL LOW, 0 = TTL HIGH
92  if(!(input & 0x80)) {
93  return FE_END_BLOCK;
94  } else {
95  return SUCCESS;
96  }
97 }
98 
100 {
101  return FE_NEED_START;
102 }