Mercurial > ~darius > hgwebdir.cgi > hwmon
comparison io/io.c @ 0:c34b37680055 default tip
Inital commit of random SuperIO code.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Thu, 20 Oct 2011 16:48:24 +1030 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c34b37680055 |
---|---|
1 #include <stdio.h> | |
2 #include <errno.h> | |
3 #include <string.h> | |
4 #include <fcntl.h> | |
5 #include <stdlib.h> | |
6 #include <sys/types.h> | |
7 #include <machine/cpufunc.h> | |
8 | |
9 void | |
10 usage(char *name) { | |
11 fprintf(stderr, | |
12 "Bad usage\n" | |
13 "\t%s adr [data]\n" | |
14 "\n" | |
15 "Read/write adr with data\n", name); | |
16 exit(1); | |
17 } | |
18 | |
19 int | |
20 main(int argc, char **argv) { | |
21 int fd, adr, data; | |
22 | |
23 if (argc != 2 && argc != 3) | |
24 usage(argv[0]); | |
25 | |
26 if ((fd = open("/dev/io", O_RDWR)) == -1) { | |
27 fprintf(stderr, "Can't open /dev/io: %s\n", strerror(errno)); | |
28 exit(1); | |
29 } | |
30 | |
31 adr = strtol(argv[1], NULL, 0) & 0xffff; | |
32 | |
33 if (argc == 3) { | |
34 data = strtol(argv[2], NULL, 0) & 0xff; | |
35 printf("0x%02x <- 0x%02x\n", adr, data); | |
36 outb(adr, data); | |
37 } else | |
38 printf("0x%02x -> 0x%02x\n", adr, inb(adr)); | |
39 | |
40 exit(0); | |
41 } | |
42 |