diff options
author | Stef Walter <stef@thewalter.net> | 2008-11-28 16:36:58 +0000 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2008-11-28 16:36:58 +0000 |
commit | 378985a6c3007d9128fc32416cb2666f44dcf260 (patch) | |
tree | 3e91122983d6202f57b4690f6c1463423002a030 /env4526.c |
Import project for detecting environment variables on net4826 and
net4526 boxes.
Diffstat (limited to 'env4526.c')
-rw-r--r-- | env4526.c | 213 |
1 files changed, 213 insertions, 0 deletions
diff --git a/env4526.c b/env4526.c new file mode 100644 index 0000000..a97c68c --- /dev/null +++ b/env4526.c @@ -0,0 +1,213 @@ +#include <err.h> +#include <errno.h> +#include <unistd.h> +#include <stdio.h> +#include <fcntl.h> +#include <sys/param.h> +#include <sys/mman.h> + +uint16_t *mmcr; +static int dir; + +static void +usage() +{ + fprintf(stderr, "usage: env4526 [-i seconds]\n"); + exit(2); +} + +static void +W(int a, unsigned d) +{ + mmcr[a / 2] = d; +} + +static unsigned +R(int a) +{ + return (mmcr[a/2]); +} + +static void +BO(int i) +{ + u_int u; + + if (i) + W(0xc34, 0x0080); + else + W(0xc38, 0x0080); + if (dir == 0) { + u = R(0xc2a); + W(0xc2a, u | 0x0080); + dir = 1; + } + W(0xc34, 0x0100); + W(0xc34, 0x0100); + W(0xc34, 0x0100); + W(0xc34, 0x0100); + W(0xc38, 0x0100); + W(0xc38, 0x0100); + W(0xc38, 0x0100); + W(0xc38, 0x0100); +} + +static int +BI(void) +{ + u_int u; + + if (dir == 1) { + u = R(0xc2a); + W(0xc2a, u & ~0x0080); + dir = 0; + } + W(0xc34, 0x0100); + W(0xc34, 0x0100); + W(0xc34, 0x0100); + W(0xc34, 0x0100); + u = R(0xc30) & 0x0080; + W(0xc38, 0x0100); + W(0xc38, 0x0100); + W(0xc38, 0x0100); + W(0xc38, 0x0100); + return (u ? 1 : 0); +} + +static void +START(void) +{ + u_int u; + + W(0xc34, 0x0180); + if (dir == 0) { + u = R(0xc2a); + W(0xc2a, u | 0x0080); + dir = 1; + } + W(0xc38, 0x0080); + W(0xc38, 0x0100); + W(0xc38, 0x0100); +} + +static void +STOP(void) +{ + u_int u; + + W(0xc38, 0x0080); + if (dir == 0) { + u = R(0xc2a); + W(0xc2a, u | 0x0080); + dir = 1; + } + W(0xc34, 0x0100); + W(0xc34, 0x0100); + W(0xc34, 0x0100); + W(0xc34, 0x0100); + W(0xc34, 0x0080); +} + +static void +read_temp() +{ + int i; + u_int j, u; + char buf1[20]; + char buf2[20]; + + u = R(0xc2a); + W(0xc2a, u | 0x0180); + W(0xc34, 0x0180); + + u = 0; + START(); + BO(1); + BO(0); + BO(0); + BO(1); + BO(u & 4); + BO(u & 2); + BO(u & 1); + BO(0); + BI(); + for (i = 0; i < 6; i++) + BO(0); + BO(0); + BO(0); + BI(); + STOP(); + + START(); + BO(1); + BO(0); + BO(0); + BO(1); + BO(u & 4); + BO(u & 2); + BO(u & 1); + BO(1); + for (i = 0; i < 9; i++) + buf1[i] = BI(); + BO(0); + for (i = 0; i < 8; i++) + buf2[i] = BI(); + BO(1); + STOP(); + + j = 0; + for (i = 1; i < 9; i++) { + j |= buf1[i]; + j += j; + } + for (i = 0; i < 8; i++) { + j |= buf2[i]; + j += j; + } + + printf("lm75: %.2fC\n", j / 512.0); +} + +int +main(int argc, char **argv) +{ + int seconds = 0; + char *t; + FILE *f; + int ch; + int fd; + + while ((ch = getopt (argc, argv, "i:")) != -1) { + switch(ch) { + case 'i': + seconds = strtol (optarg, &t, 10); + if (*t || seconds < 0) + usage (); + break; + default: + usage (); + break; + } + } + + argc -= optind; + argv += optind; + + if (argc != 0) + usage (); + + fd = open ("/dev/elan-mmcr", O_RDWR); + if (fd < 0) + err (1, "couldn't open: /dev/elan-mmcr"); + mmcr = mmap (NULL, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + + for (;;) { + read_temp (); + fflush (stdout); + if (!seconds) + break; + sleep (seconds); + } + + return 0; +} |