📄 ieee1284.c
字号:
if (!dsr_wait (WAITTIME, DSR_PERROR | DSR_SELECT | DSR_NFAULT, DSR_NACK)) return 0; assert_dcr (DCR_STROBE); deassert_dcr (DCR_STROBE | DCR_AUTOFD); if (!dsr_wait (WAITTIME, DSR_NBUSY | DSR_SELECT, DSR_PERROR)) return 0; if (!dsr_wait (WAITTIME, DSR_NACK, 0)) return 0; assert_dcr (DCR_AUTOFD); if (!dsr_wait (WAITTIME, DSR_PERROR, 0)) return 0; return 1;}static voidfoo (void){#ifdef DEBUG printf ("foo\n");#endif set_dcr (0xc);//Something about setting AUTOFD if //0x78 and not 0xa0}intieee1284_writebyte (unsigned char b){#ifdef DEBUG printf ("1284_writebyte(%x)\n", b);#endif if (!dsr_wait (WAITTIME, DSR_NBUSY, 0)) return 0; write_data (b); assert_dcr (DCR_STROBE); if (!dsr_wait (WAITTIME, 0, DSR_NBUSY)) { MOAN ("ieee1284_writebyte: failed\n"); return 0; } deassert_dcr (DCR_STROBE | DCR_AUTOFD); if (!dsr_wait (WAITTIME, DSR_NBUSY, 0)) { MOAN ("ieee1284_writebyte: failed\n"); return 0; } assert_dcr (DCR_AUTOFD); return 1;}intieee1284_ftor (void){#ifdef DEBUG printf ("1284_ftor()\n");#endif assert_dcr (DCR_DIRECTION); assert_dcr (DCR_AUTOFD); DIRWAIT; deassert_dcr (DCR_NINIT); if (!dsr_wait (LWAITTIME, 0, DSR_PERROR)) { MOAN ("ieee1284_ftor: failed\n"); return 0; } return 1;}intieee1284_readbyte (unsigned char *i){#ifdef DEBUG printf ("1284_readbyte()="); fflush (stdout);#endif assert_dcr (DCR_AUTOFD); if (!dsr_wait (LWAITTIME, 0, DSR_NACK)) {#ifdef DEBUG printf ("Failed\n");#endif MOAN ("ieee1284_readbyte: failed\n"); return 0; } *i = read_data (); deassert_dcr (DCR_AUTOFD); if (!dsr_wait (LWAITTIME, DSR_NACK, 0)) {#ifdef DEBUG printf ("Failed\n");#endif MOAN ("ieee1284_readbyte: failed\n"); return 0; } assert_dcr (DCR_AUTOFD);#ifdef DEBUG printf ("%02x\n", *i);#endif return 1;}intieee1284_rtof (void){#ifdef DEBUG printf ("1284_ftor()\n");#endif assert_dcr (DCR_NINIT); DIRWAIT; if (!dsr_wait (WAITTIME, DSR_PERROR | DSR_NBUSY | DSR_NACK, 0)) { MOAN ("ieee1284_rtof: failed\n"); return 0; } deassert_dcr (DCR_DIRECTION); return 1;}intieee1284_term (void){#ifdef DEBUG printf ("1284_term\n");#endif deassert_dcr (DCR_AUTOFD); assert_dcr (DCR_SELECTIN); if (!dsr_wait (WAITTIME, DSR_PERROR, 0)) return 0;#if 0 if (!dsr_wait (WAITTIME, DSR_NACK, 0)) return 0;#endif assert_dcr (DCR_AUTOFD | DCR_NINIT);#if 0 if (!dsr_wait (WAITTIME, DSR_NACK, 0)) return 0; deassert_dcr (DCR_AUTOFD);#endif return 1;}intyepp_wakeupandping (void){ unsigned char j; int trys = 0; do { fprintf (stderr, "yepp_wakeupandping: try %d\n", ++trys); foo (); if (!ieee1284_negsetup (0x10)) not1284_setup (); if (ieee1284_writebyte (0xa)) { j = 0; if (((read_dsr () & 0xa0) == 0xa0)) { // FIXME: ieee1284_ftor (); ieee1284_readbyte (&j); ieee1284_rtof (); } ieee1284_term (); if (j == 1) { fprintf (stderr, "yepp_wakeupandping: success\n"); return 1; } } foo (); sleep (2); usleep (10000); set_dcr (0xe); usleep (10000); set_dcr (0xc); } while (trys < 4); MOAN ("yepp_wakeupandping: failed\n"); return 0;}intyepp_phase1 (void){ foo (); if (!ieee1284_negsetup (0x10)) { MOAN ("yepp_phase1: failed\n"); return 0; } return 1;}intyepp_phase2 (void){ if (!ieee1284_ftor ()) { MOAN ("yepp_phase2: failed\n"); return 0; } return 1;}intyepp_phase3 (void){ if (!ieee1284_rtof ()) { MOAN ("yepp_phase3: failed\n"); return 0; } return 1;}voidyepp_phase4 (void){ ieee1284_term (); deassert_dcr (DCR_AUTOFD);//set_dcr(0x0c);}voidyepp_release (void){ write_data (0x0); set_dcr (0x0c); set_dcr (0x0b);}intyepp_read (char *buf, int i){ int red = 0;#ifdef DEBUG printf ("Yeppread %d...", i); fflush (stdout);#endif while (i--) { if (!ieee1284_readbyte (buf)) {#ifdef DEBUG printf ("%d (Failed)\n", red);#endif MOAN ("yepp_read: short (%d/%d) write\n", red, i); return red; } red++; buf++; }#ifdef DEBUG printf ("%d (OK)\n", red);#endif return red;}static intyepp_ecp_write (char *buf, int i){ int red;#ifdef DEBUG printf ("ECP Yeppwrite %d...", i); fflush (stdout);#endif red = 0; if (!dsr_wait (WAITTIME, DSR_NBUSY, 0)) {#ifdef DEBUG printf ("%d (Failed)\n", red);#endif MOAN ("yepp_ecp_write: short (%d/%d) write\n", red, i); return red; } write_ecr (ECR_NERRINTREN | ECR_SERVICEINTR | ECR_MODE_ECP); deassert_dcr (DCR_AUTOFD); while (i--) { if (!ecr_wait (WAITTIME, 0, ECR_FULL)) {#ifdef DEBUG printf ("%d (Failed)\n", red);#endif assert_dcr (DCR_AUTOFD); write_ecr (ECR_NERRINTREN | ECR_SERVICEINTR | ECR_MODE_EPP); MOAN ("yepp_ecp_write: short (%d/%d) write\n", red, i); return red; } outb (*buf, ECPDFIFO); red++; buf++; } ecr_wait (WAITTIME, ECR_EMPTY, 0); assert_dcr (DCR_AUTOFD); write_ecr (ECR_NERRINTREN | ECR_SERVICEINTR | ECR_MODE_EPP);#ifdef DEBUG printf ("%d (OK)\n", red);#endif return red;}intyepp_write (char *buf, int i){ int red = 0; if (ecp) return yepp_ecp_write (buf, i);#ifdef DEBUG printf ("Yeppwrite %d...", i); fflush (stdout);#endif while (i--) { if (!ieee1284_writebyte (*buf)) {#ifdef DEBUG printf ("%d (Failed)\n", red);#endif MOAN ("yepp_write: short (%d/%d) write\n", red, i); return red; } red++; buf++; }#ifdef DEBUG printf ("%d (OK)\n", red);#endif return red;}static intieee1284_probe (void){//Incase direction==in fprintf (stderr, "ieee1284_probe: probing at 0x%04x\n", base); write_ecr (ECR_NERRINTREN | ECR_SERVICEINTR | ECR_MODE_EPP); deassert_dcr (DCR_DIRECTION); write_data (0x55); if (read_data () != 0x55) return 0; write_data (0xaa); if (read_data () != 0xaa) return 0;//Ok port exists check for PS2 mode write_ecr (ECR_NERRINTREN | ECR_SERVICEINTR | ECR_MODE_EPP); assert_dcr (DCR_DIRECTION); write_data (0x55); if (read_data () == 0x55) { deassert_dcr (DCR_DIRECTION); fprintf (stderr, "ieee1284_probe: port at 0x%04x is not bidirectional\n", base); return 0; } deassert_dcr (DCR_DIRECTION); write_ecr (ECR_NERRINTREN | ECR_SERVICEINTR | ECR_MODE_ECP); if ((read_ecr () & 0xe0) != 0x60) { fprintf (stderr, "ieee1284_probe: PS2 style port at 0x%04x\n", base); return 1; } write_ecr (ECR_NERRINTREN | ECR_SERVICEINTR | ECR_MODE_EPP); if ((read_ecr () & 0xe0) != 0x20) { fprintf (stderr, "ieee1284_probe: PS2 style port at 0x%04x\n", base); return 1; } write_ecr (ECR_NERRINTREN | ECR_SERVICEINTR | ECR_MODE_SPP); if ((read_ecr () & 0xe0) != 0x00) { fprintf (stderr, "ieee1284_probe: PS2 style port at 0x%04x\n", base); return 1; } fprintf (stderr, "ieee1284_probe: ECP port at 0x%04x\n", base); ecp++; write_ecr (ECR_NERRINTREN | ECR_SERVICEINTR | ECR_MODE_EPP); return 1;}intieee1284_init (int port){ int ports[] = { 0x3bc, 0x378, 0x278, 0 }; int *portp = ports; if (!iopl (3)) { fprintf (stderr, "ieee1284: may have failed to get access to hardware\n"); fprintf (stderr, "ieee1284: code must run as superuser\n"); } if (port) { base = port; if (ieee1284_probe ()) return 1; return 0; } while (*portp) { base = *portp; if (ieee1284_probe ()) return 1; portp++; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -