summaryrefslogtreecommitdiff
path: root/components/utilities
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2018-06-10 17:59:17 +0800
committerBernard Xiong <[email protected]>2018-06-10 17:59:17 +0800
commit884fb70fe9973eaf01a7df04941cbcb0475ba8d5 (patch)
tree7c8e3f42629e46b3d7ecb0c8507f67934d9fae47 /components/utilities
parentbca65f30a90857287dc1371ddbc8d5f165691c7f (diff)
[Kernel] Add device ops feature.
Diffstat (limited to 'components/utilities')
-rw-r--r--components/utilities/logtrace/log_file.c16
-rw-r--r--components/utilities/logtrace/log_trace.c16
2 files changed, 32 insertions, 0 deletions
diff --git a/components/utilities/logtrace/log_file.c b/components/utilities/logtrace/log_file.c
index 4e4e158969..42d1f6e7a9 100644
--- a/components/utilities/logtrace/log_file.c
+++ b/components/utilities/logtrace/log_file.c
@@ -112,6 +112,18 @@ static rt_err_t fdevice_control(rt_device_t dev, int cmd, void *arg)
return RT_EOK;
}
+#ifdef RT_USING_DEVICE_OPS
+const static struct rt_device_ops log_trace_ops =
+{
+ RT_NULL,
+ fdevice_open,
+ fdevice_close,
+ RT_NULL,
+ fdevice_write,
+ fdevice_control
+};
+#endif
+
void log_trace_file_init(const char *filename)
{
rt_device_t device;
@@ -123,11 +135,15 @@ void log_trace_file_init(const char *filename)
_file_device.parent.type = RT_Device_Class_Char;
+#ifdef RT_USING_DEVICE_OPS
+ _file_device.parent.ops = &log_trace_ops;
+#else
_file_device.parent.init = RT_NULL;
_file_device.parent.open = fdevice_open;
_file_device.parent.close = fdevice_close;
_file_device.parent.write = fdevice_write;
_file_device.parent.control = fdevice_control;
+#endif
rt_device_register(&_file_device.parent, "logfile", O_RDWR);
}
diff --git a/components/utilities/logtrace/log_trace.c b/components/utilities/logtrace/log_trace.c
index 79bcde2075..4ea0ff13fd 100644
--- a/components/utilities/logtrace/log_trace.c
+++ b/components/utilities/logtrace/log_trace.c
@@ -383,17 +383,33 @@ static rt_err_t _log_control(rt_device_t dev, int cmd, void *arg)
return rt_device_control(_traceout_device, cmd, arg);
}
+#ifdef RT_USING_DEVICE_OPS
+const static struct rt_device_ops log_device_ops =
+{
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ RT_NULL,
+ _log_write,
+ _log_control
+};
+#endif
+
int log_trace_init(void)
{
rt_memset(&_log_device, 0x00, sizeof(_log_device));
_log_device.type = RT_Device_Class_Char;
+#ifdef RT_USING_DEVICE_OPS
+ _log_device.ops = &log_device_ops;
+#else
_log_device.init = RT_NULL;
_log_device.open = RT_NULL;
_log_device.close = RT_NULL;
_log_device.read = RT_NULL;
_log_device.write = _log_write;
_log_device.control = _log_control;
+#endif
/* no indication and complete callback */
_log_device.rx_indicate = RT_NULL;