[Kernel] Add device ops feature.

This commit is contained in:
Bernard Xiong
2018-06-10 17:59:17 +08:00
parent bca65f30a9
commit 884fb70fe9
37 changed files with 795 additions and 200 deletions

View File

@@ -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);
}

View File

@@ -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;