-
Notifications
You must be signed in to change notification settings - Fork 0
/
devrtc.c
122 lines (104 loc) · 1.84 KB
/
devrtc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "../port/error.h"
#include "io.h"
enum{
Qdir,
Qrtc,
};
static Dirtab rtctab[]={
".", {Qdir,0,QTDIR}, 0, 0555,
"rtc", {Qrtc}, NUMSIZE, 0664,
};
extern ulong boottime;
static void
rtcreset(void)
{
}
static Chan*
rtcattach(char *spec)
{
return devattach('r', spec);
}
static Walkqid*
rtcwalk(Chan *c, Chan *nc, char **name, int nname)
{
return devwalk(c, nc, name, nname, rtctab, nelem(rtctab), devgen);
}
static int
rtcstat(Chan *c, uchar *dp, int n)
{
return devstat(c, dp, n, rtctab, nelem(rtctab), devgen);
}
static Chan*
rtcopen(Chan *c, int omode)
{
return devopen(c, omode, rtctab, nelem(rtctab), devgen);
}
static void
rtcclose(Chan*)
{
}
static long
rtcread(Chan *c, void *buf, long n, vlong off)
{
ulong secs, *ps = uncached(&secs);
if(c->qid.type & QTDIR)
return devdirread(c, buf, n, rtctab, nelem(rtctab), devgen);
switch((ulong)c->qid.path){
case Qrtc:
*ps = 1;
nbfifoput(F9TSystem|F9Sysrrtc, (ulong)ps);
while(*ps == 1); /* wait for arm7 write */
return readnum(off, buf, n, *ps, NUMSIZE);
}
error(Egreg);
return 0; /* not reached */
}
static long
rtcwrite(Chan *c, void *buf, long n, vlong off)
{
ulong offset = off;
ulong secs;
char *cp, sbuf[32];
switch((ulong)c->qid.path){
case Qrtc:
if(offset != 0 || n >= sizeof(sbuf)-1)
error(Ebadarg);
memmove(sbuf, buf, n);
sbuf[n] = '\0';
cp = sbuf;
while(*cp){
if(*cp>='0' && *cp<='9')
break;
cp++;
}
secs = strtoul(cp, 0, 0);
fifoput(F9TSystem|F9Syswrtc, (ulong)(&secs));
return n;
}
error(Egreg);
return 0; /* not reached */
}
Dev rtcdevtab = {
'r',
"rtc",
rtcreset,
devinit,
devshutdown,
rtcattach,
rtcwalk,
rtcstat,
rtcopen,
devcreate,
rtcclose,
rtcread,
devbread,
rtcwrite,
devbwrite,
devremove,
devwstat,
};