summaryrefslogtreecommitdiff
path: root/content/demo-programme/raider.c
diff options
context:
space:
mode:
Diffstat (limited to 'content/demo-programme/raider.c')
-rw-r--r--content/demo-programme/raider.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/content/demo-programme/raider.c b/content/demo-programme/raider.c
new file mode 100644
index 0000000..6669c2b
--- /dev/null
+++ b/content/demo-programme/raider.c
@@ -0,0 +1,109 @@
+#include <ieee1284.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define SHOW(st,bits) printf(#bits" %s\n", ( st & bits) ?"on":"off")
+
+void dump_cap(int cap)
+{
+
+ SHOW(cap,CAP1284_RAW);
+ SHOW(cap,CAP1284_NIBBLE);
+ SHOW(cap,CAP1284_BYTE);
+ SHOW(cap,CAP1284_COMPAT);
+ SHOW(cap,CAP1284_BECP);
+ SHOW(cap,CAP1284_ECP);
+ SHOW(cap,CAP1284_ECPRLE);
+ SHOW(cap,CAP1284_ECPSWE);
+ SHOW(cap,CAP1284_EPP);
+ SHOW(cap,CAP1284_EPPSL);
+ SHOW(cap,CAP1284_EPPSWE);
+ SHOW(cap,CAP1284_IRQ);
+ SHOW(cap,CAP1284_DMA) ;
+
+
+}
+
+
+
+void pperror(int ret)
+{
+ switch(ret)
+ {
+ case E1284_NOMEM:
+ puts("There is not enough memory");
+ break;
+
+ case E1284_INVALIDPORT:
+ puts("The port is invalid");
+ break;
+
+ case E1284_SYS:
+ perror("E1284_SYS");
+ break;
+
+ default:
+ printf("unknown error %d",ret);
+ }
+
+}
+
+int main()
+{
+ int ret;
+ int fd;
+ int flags,cap,i;
+ unsigned char dat;
+
+ struct parport_list *plist=calloc(1,sizeof(*plist));
+ struct parport *pport;
+
+
+ ret = ieee1284_find_ports( plist, 0);
+
+ if ( ( ret != E1284_OK ) || (plist->portc < 1) ) /* cannot find parports */
+ return -1;
+
+ pport = plist->portv[0];
+
+
+ //flags=F1284_EXCL; //causes CLAIM to fail is mod lp is loaded
+ flags=0;
+ printf("going to open %s\n",pport->filename);
+ ret=ieee1284_open(pport,flags,&cap);
+ if (ret != E1284_OK )
+ goto no_open;
+
+ //
+ dump_cap(cap);
+
+ ret = ieee1284_claim ( pport );
+ if ( ret != E1284_OK )
+ {
+ printf("could not claim port\n");
+ pperror( ret );
+ goto no_claim;
+ }
+
+ /* set data direction */
+ ieee1284_data_dir( pport,0);
+
+
+ for(i=0;i<8;i++)
+ {
+ dat=1<<i;
+ ieee1284_write_data(pport,dat);
+ printf("write and wait %x\n",dat);
+ usleep(100000);
+ }
+
+ ieee1284_write_data(pport,0);
+
+ ieee1284_release(pport);
+no_claim:
+ ieee1284_close(pport);
+no_open:
+ ieee1284_free_ports(plist);
+
+ return 0;
+}