|
|
1.1 ! root 1: #include <libc.h> ! 2: #include <fio.h> ! 3: #include <sysent.h> ! 4: #include <string.h> ! 5: #include <errno.h> ! 6: #include "crossbar.h" ! 7: ! 8: extern int verbose; ! 9: static ntilt; ! 10: #define MAXTILT 5 ! 11: ! 12: Dynasty::Dynasty(char *dkname, int n, int depth) : (dkname, n, depth) ! 13: { ! 14: } ! 15: ! 16: void ! 17: Dynasty::startup() ! 18: { ! 19: char buf[256]; ! 20: extern int opendk(char *); ! 21: ! 22: fd = opendk(dial); ! 23: tocontrol(); ! 24: } ! 25: ! 26: void ! 27: Dynasty::tocontrol() ! 28: { ! 29: for(;;){ ! 30: put1(0xAC); ! 31: if(get1(0xFB) == 0) ! 32: break; ! 33: sleep(1); ! 34: } ! 35: } ! 36: ! 37: void ! 38: Dynasty::config() ! 39: { ! 40: int i, j; ! 41: ! 42: imap = new int[nouts]; ! 43: ntilt = 0; ! 44: for(i = 0; i < nouts; i++){ ! 45: again: ! 46: if(ntilt > MAXTILT){ ! 47: fprint(2, "vsw: too many (%d) tilts, exiting\n", ntilt); ! 48: exit(1); ! 49: } ! 50: put1(0xDA); ! 51: putn(i); ! 52: if(get1(0xAB)){ ! 53: sleep(1); ! 54: tocontrol(); ! 55: goto again; ! 56: } ! 57: j = getn(8); ! 58: put1(0xFB); ! 59: imap[i] = j; ! 60: } ! 61: } ! 62: ! 63: int ! 64: Dynasty::connect(int input, Crossbar *c, int output, int nw) ! 65: { ! 66: char buf[256]; ! 67: ! 68: if(fd < 0) ! 69: startup(); ! 70: if(c != this){ ! 71: if(nextc->connect(nextl, c, output, nw) == 0) ! 72: return(0); ! 73: output = froml; ! 74: } ! 75: nw = (nw+nwires-1)/nwires; ! 76: while(nw-- > 0){ ! 77: put1(0xCF); ! 78: putn(output); ! 79: putn(input); ! 80: if(get1(0xFB)){ ! 81: fprint(2, "%s.con %d->%d failed\n", name(), input, output); ! 82: return(0); ! 83: } ! 84: input++, output++; ! 85: } ! 86: return(1); ! 87: } ! 88: ! 89: void ! 90: Dynasty::put1(unsigned char x) ! 91: { ! 92: if(write(fd, (char *)&x, 1) != 1) ! 93: perror("WRITE"); ! 94: } ! 95: ! 96: void ! 97: Dynasty::putn(int i) ! 98: { ! 99: unsigned char wbuf[2]; ! 100: ! 101: wbuf[0] = i/100; ! 102: wbuf[1] = i%10 | (((i/10)%10)<<4); ! 103: if(write(fd, (char *)wbuf, 2) != 2) ! 104: perror("putn"); ! 105: } ! 106: ! 107: int ! 108: Dynasty::get1(unsigned char x) ! 109: { ! 110: unsigned char r; ! 111: char buf[60]; ! 112: ! 113: alarm(2); ! 114: if(read(fd, (char *)&r, 1) != 1){ ! 115: if(errno != EINTR) ! 116: perror("READ"); ! 117: else ! 118: fprint(2, "vsw: timeout, retrying\n"), tocontrol(); ! 119: return(1); ! 120: } ! 121: alarm(0); ! 122: if(r != x){ ! 123: switch(r) ! 124: { ! 125: case 0xF0: ! 126: ntilt++; ! 127: break; ! 128: case 0xAB: ! 129: alarm(2); ! 130: read(fd, buf, 8); ! 131: alarm(0); ! 132: print("continue(#%ux#%ux#%ux#%ux#%ux#%ux#%ux#%ux)\n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]); ! 133: break; ! 134: case 0xAD: ! 135: alarm(2); ! 136: read(fd, buf, 10); ! 137: alarm(0); ! 138: print("autostatus(#%ux#%ux#%ux#%ux#%ux#%ux#%ux#%ux#%ux#%ux)\n",buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7],buf[8],buf[9]); ! 139: break; ! 140: default: ! 141: fprint(2, "READ(#%2.2x): got #%2.2x\n", x, r); ! 142: break; ! 143: } ! 144: return(1); ! 145: } ! 146: return(0); ! 147: } ! 148: ! 149: int ! 150: Dynasty::getn(int n) ! 151: { ! 152: unsigned char r[64]; ! 153: ! 154: if(read(fd, (char *)r, n) != n) ! 155: perror("getn"); ! 156: return((r[0]&0xF)*100 + ((r[1]>>4)&0xF)*10 + (r[1]&0xF)); ! 157: } ! 158: ! 159: #ifdef CRAP ! 160: ! 161: int verbose; ! 162: int rfs; ! 163: ! 164: #define WRITE(x) { char wbuf[1]; wbuf[0] = x; if(write(rfs, wbuf, 1) != 1) perror("WRITE"); } ! 165: ! 166: WRITEN(i) ! 167: { ! 168: unsigned char wbuf[2]; ! 169: ! 170: wbuf[0] = i/100; ! 171: wbuf[1] = i%10 | (((i/10)%10)<<4); ! 172: if(write(rfs, wbuf, 2) != 2) ! 173: perror("WRITEN"); ! 174: } ! 175: ! 176: READ(x) ! 177: { ! 178: unsigned char rbuf[1]; ! 179: if(read(rfs, rbuf, 1) != 1) ! 180: perror("READ"); ! 181: if(rbuf[0] != x){ ! 182: fprint(2, "READ(#%2.2x): got #%2.2x\n", x, rbuf[0]); ! 183: return(1); ! 184: } ! 185: return(0); ! 186: } ! 187: ! 188: READN(buf, n) ! 189: unsigned char buf[]; ! 190: { ! 191: int i; ! 192: ! 193: for(i = 0; i < n; i++) ! 194: if(read(rfs, &buf[i], 1) != 1){ ! 195: perror("READ"); ! 196: return(1); ! 197: } ! 198: return(0); ! 199: } ! 200: ! 201: main(argc, argv) ! 202: char **argv; ! 203: { ! 204: int i, n, in, out; ! 205: char buf[256]; ! 206: struct sgttyb vvec; ! 207: extern int tty_ld; ! 208: ! 209: if((argc = getflags(argc, argv, "dcrvpPi", 0)) < 0) ! 210: usage("[ iopair ... ]"); ! 211: verbose = flag['v'] != 0; ! 212: sprint(buf, "/cs/dk!%s", "vswrgb2"); ! 213: rfs = ipcopen(buf, "light"); ! 214: if(rfs < 0){ ! 215: perror(buf); ! 216: exit(1); ! 217: } ! 218: if(ioctl(rfs, FIOLOOKLD, 0) != tty_ld){ ! 219: if(ioctl(rfs, FIOPUSHLD, &tty_ld) < 0){ ! 220: perror("tty_ld"); ! 221: exit(1); ! 222: } ! 223: } ! 224: vvec.sg_flags = RAW; ! 225: vvec.sg_erase = 0; ! 226: vvec.sg_kill = 0; ! 227: if(ioctl(rfs, TIOCSETP, &vvec) < 0){ ! 228: perror("ioctl"); ! 229: exit(1); ! 230: } ! 231: tocontrol(); ! 232: print("in control:\n"); ! 233: status(); ! 234: exit(0); ! 235: } ! 236: ! 237: tocontrol() ! 238: { ! 239: WRITE(0xAC); ! 240: return(READ(0xFB)); ! 241: } ! 242: ! 243: status() ! 244: { ! 245: int i, n; ! 246: unsigned char buf[8]; ! 247: ! 248: for(i = 0; i < 5; i++){ ! 249: n = status1(i, buf); ! 250: print("%d: status1 ret=%d; %x %x %x %x %x %x %x %x\n", i, n, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]); ! 251: } ! 252: } ! 253: ! 254: status1(i, buf) ! 255: unsigned char *buf; ! 256: { ! 257: WRITE(0xDA); ! 258: WRITEN(i); ! 259: if(i = READ(0xAB)) ! 260: return(i); ! 261: if(i = READN(buf, 8)) ! 262: return(i); ! 263: WRITE(0xFB); ! 264: sleep(1); ! 265: return(0); ! 266: } ! 267: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.