forked from phoenix-rtos/phoenix-rtos-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusrv.c
More file actions
123 lines (95 loc) · 1.82 KB
/
usrv.c
File metadata and controls
123 lines (95 loc) · 1.82 KB
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
123
/*
* Phoenix-RTOS
*
* Operating system kernel
*
* User server
*
* Copyright 2022 Phoenix Systems
* Authors: Hubert Buczynski
*
* This file is part of Phoenix-RTOS.
*
* %LICENSE%
*/
#include "hal/hal.h"
#include "usrv.h"
#include "log/log.h"
#include "include/ioctl.h"
#include "proc/threads.h"
#include "proc/msg.h"
#include "proc/ports.h"
#define USRV_ID_LOG 0
static struct {
oid_t oid;
} usrv_common;
static int usrv_oidGet(const msg_t *msg, oid_t *oid)
{
int err = EOK;
ioctl_in_t *ioctl;
switch (msg->type) {
case mtOpen:
case mtClose:
oid->id = msg->i.openclose.oid.id;
break;
case mtRead:
case mtWrite:
case mtTruncate:
oid->id = msg->i.io.oid.id;
break;
case mtCreate:
oid->id = msg->i.create.dir.id;
break;
case mtDestroy:
oid->id = msg->i.destroy.oid.id;
break;
case mtGetAttr:
case mtSetAttr:
oid->id = msg->i.attr.oid.id;
break;
case mtLookup:
oid->id = msg->i.lookup.dir.id;
break;
case mtDevCtl:
ioctl = (ioctl_in_t *)msg->i.raw;
oid->id = ioctl->id;
break;
default:
err = -EINVAL;
break;
}
return err;
}
static void usrv_msgthr(void *arg)
{
msg_t msg;
unsigned long int rid;
oid_t oid = usrv_common.oid;
for (;;) {
/* TODO: when the oid_t is added to the msg_t then usrv_oidGet should be removed */
if (proc_recv(oid.port, &msg, &rid) != 0 || usrv_oidGet(&msg, &oid) != 0) {
continue;
}
switch (oid.id) {
case USRV_ID_LOG:
log_msgHandler(&msg, oid, rid);
break;
default:
msg.o.io.err = -ENOSYS;
proc_respond(oid.port, &msg, rid);
break;
}
}
}
void _usrv_start(void)
{
/* Create port 0 for /dev/kmsg */
if (proc_portCreate(&usrv_common.oid.port) != 0) {
return;
}
proc_threadCreate(NULL, usrv_msgthr, NULL, 4, 2048, NULL, 0, NULL);
}
void _usrv_init(void)
{
_log_init();
}