summaryrefslogtreecommitdiff
path: root/sys/src/9/port/led.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@localhost>2011-07-10 14:14:23 +0200
committercinap_lenrek <cinap_lenrek@localhost>2011-07-10 14:14:23 +0200
commitc2fc2fad133d51bc7dc86af015a20aed11a1817f (patch)
tree8366e17787c48975b1ce1401c731d80763c94629 /sys/src/9/port/led.c
parentae00ac74659e69a1aee9dc3e3ab20d5ec70b8126 (diff)
merge sd changes from 9atom
Diffstat (limited to 'sys/src/9/port/led.c')
-rw-r--r--sys/src/9/port/led.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/sys/src/9/port/led.c b/sys/src/9/port/led.c
new file mode 100644
index 000000000..8456d32cc
--- /dev/null
+++ b/sys/src/9/port/led.c
@@ -0,0 +1,62 @@
+#include "u.h"
+#include "../port/lib.h"
+#include "mem.h"
+#include "dat.h"
+#include "../port/error.h"
+#include "fns.h"
+#include "led.h"
+
+static char *ibpinames[Ibpilast] = {
+[Ibpinone] "none",
+[Ibpinormal] "normal",
+[Ibpilocate] "locate",
+[Ibpifail] "fail",
+[Ibpirebuild] "rebuild",
+[Ibpipfa] "pfa",
+[Ibpispare] "spare",
+[Ibpicritarray] "critarray",
+[Ibpifailarray] "failarray",
+};
+
+char*
+ledname(int c)
+{
+ if(c >= 0 && c < Ibpilast)
+ return ibpinames[c];
+ return "bad index";
+}
+
+ int
+name2led(char *s)
+{
+ int i;
+
+ for(i = 0; i < nelem(ibpinames); i++)
+ if(strcmp(ibpinames[i], s) == 0)
+ return i;
+ return -1;
+}
+
+long
+ledr(Ledport *p, Chan*, void *a, long n, vlong off)
+{
+ char buf[64];
+
+ snprint(buf, sizeof buf, "%s\n", ledname(p->led));
+ return readstr(off, a, n, buf);
+}
+
+long
+ledw(Ledport *p, Chan*, void *a, long n, vlong)
+{
+ int i;
+ Cmdbuf *cb;
+
+ cb = parsecmd(a, n);
+ i = name2led(cb->f[0]);
+ free(cb);
+ if(i == -1)
+ error(Ebadarg);
+ p->led = i;
+ return n;
+}