From c537aabdefd636252a43d0d25f797e9b8d992436 Mon Sep 17 00:00:00 2001 From: quanzhao Date: Sat, 5 Dec 2020 18:12:26 +0800 Subject: [PATCH] Add NULL device driver. --- components/drivers/Kconfig | 12 +++-- components/drivers/misc/SConscript | 11 +++-- components/drivers/misc/rt_null.c | 75 ++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 components/drivers/misc/rt_null.c diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index 2415b45f32..5cc039d245 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -8,7 +8,7 @@ if RT_USING_DEVICE_IPC config RT_PIPE_BUFSZ int "Set pipe buffer size" default 512 - + config RT_USING_SYSTEM_WORKQUEUE bool "Using system default workqueue" default n @@ -118,7 +118,11 @@ config RT_USING_ADC config RT_USING_DAC bool "Using DAC device drivers" default n - + +config RT_USING_NULL + bool "Using NULL device drivers" + default n + config RT_USING_PWM bool "Using PWM device drivers" default n @@ -202,7 +206,7 @@ config RT_USING_SPI bool "Using SPI Bus/Device device drivers" default n - if RT_USING_SPI + if RT_USING_SPI config RT_USING_QSPI bool "Enable QSPI mode" default n @@ -226,7 +230,7 @@ config RT_USING_SPI config RT_SFUD_USING_FLASH_INFO_TABLE bool "Using defined supported flash chip information table" default y - + config RT_SFUD_USING_QSPI bool "Using QSPI mode support" select RT_USING_QSPI diff --git a/components/drivers/misc/SConscript b/components/drivers/misc/SConscript index 72058eeeca..338a6e3cd0 100644 --- a/components/drivers/misc/SConscript +++ b/components/drivers/misc/SConscript @@ -1,28 +1,31 @@ from building import * cwd = GetCurrentDir() -src = [] +src = [] CPPPATH = [cwd + '/../include'] group = [] if GetDepend(['RT_USING_PIN']): src = src + ['pin.c'] - + if GetDepend(['RT_USING_ADC']): src = src + ['adc.c'] - + if GetDepend(['RT_USING_DAC']): src = src + ['dac.c'] if GetDepend(['RT_USING_PWM']): src = src + ['rt_drv_pwm.c'] - + if GetDepend(['RT_USING_PULSE_ENCODER']): src = src + ['pulse_encoder.c'] if GetDepend(['RT_USING_INPUT_CAPTURE']): src = src + ['rt_inputcapture.c'] +if GetDepend(['RT_USING_NULL']): + src = src + ['rt_null.c'] + if len(src): group = DefineGroup('DeviceDrivers', src, depend = [''], CPPPATH = CPPPATH) diff --git a/components/drivers/misc/rt_null.c b/components/drivers/misc/rt_null.c new file mode 100644 index 0000000000..b895c47da4 --- /dev/null +++ b/components/drivers/misc/rt_null.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2011-2020, Shanghai Real-Thread Electronic Technology Co.,Ltd + * + * Change Logs: + * Date Author Notes + * 2020-12-03 quanzhao the first version + */ + +#include +#include +#include + +static struct rt_device null_dev; + +static rt_size_t null_read (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size) +{ + rt_memset(buffer, 0, size); + return size; +} + +static rt_size_t null_write (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size) +{ + return size; +} + +static rt_err_t null_control (rt_device_t dev, int cmd, void *args) +{ + return RT_EOK; +} + +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops null_ops = +{ + RT_NULL, + RT_NULL, + RT_NULL, + null_read, + null_write, + null_control +}; +#endif + +int null_device_init(void) +{ + static rt_bool_t init_ok = RT_FALSE; + + if (init_ok) + { + return 0; + } + RT_ASSERT(!rt_device_find("null")); + null_dev.type = RT_Device_Class_Miscellaneous; + +#ifdef RT_USING_DEVICE_OPS + null_dev.ops = &null_ops; +#else + null_dev.init = RT_NULL; + null_dev.open = RT_NULL; + null_dev.close = RT_NULL; + null_dev.read = null_read; + null_dev.write = null_write; + null_dev.control = null_control; +#endif + + /* no private */ + null_dev.user_data = RT_NULL; + + rt_device_register(&null_dev, "null", RT_DEVICE_FLAG_RDWR); + + init_ok = RT_TRUE; + + return 0; +} +INIT_DEVICE_EXPORT(null_device_init); + -- Gitee