diff options
| author | guo <[email protected]> | 2022-12-03 12:07:44 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-12-03 12:07:44 +0800 |
| commit | ecf2d8215961ca7c539132b62a72df6072cc3e14 (patch) | |
| tree | 59005f0f74f2593c0435059264f624c862a89f55 /src/device.c | |
| parent | aaf5462c6d4ae9466a0a8cd2a4bb00cfe1fef2f2 (diff) | |
sync branch rt-smart. (#6641)
* Synchronize the code of the rt mart branch to the master branch.
* TTY device
* Add lwP code from rt-smart
* Add vnode in DFS, but DFS will be re-write for rt-smart
* There are three libcpu for rt-smart:
* arm/cortex-a, arm/aarch64
* riscv64
Co-authored-by: Rbb666 <[email protected]>
Co-authored-by: zhkag <[email protected]>
Diffstat (limited to 'src/device.c')
| -rw-r--r-- | src/device.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/device.c b/src/device.c index 1079e2c38f..beba062952 100644 --- a/src/device.c +++ b/src/device.c @@ -457,4 +457,87 @@ rt_err_t rt_device_set_tx_complete(rt_device_t dev, } RTM_EXPORT(rt_device_set_tx_complete); +#ifdef RT_USING_DM +/** + * This function bind drvier and device + * + * @param driver the pointer of driver structure + * @param device the pointer of device structure + * @param node the pointer of fdt node structure + * + * @return the error code, RT_EOK on successfully. + */ +rt_err_t rt_device_bind_driver(rt_device_t device, rt_driver_t driver, void *node) +{ + if((!driver) || (!device)) + { + return -RT_EINVAL; + } + + device->drv = driver; +#ifdef RT_USING_DEVICE_OPS + device->ops = driver->dev_ops; +#endif + device->dtb_node = node; + + return RT_EOK; +} +RTM_EXPORT(rt_device_bind_driver); + +/** + * This function create rt_device according to driver infomation + * + * @param drv the pointer of driver structure + * @param device_id specify the ID of the rt_device + * + * @return the error code, RT_EOK on successfully. + */ +rt_device_t rt_device_create_since_driver(rt_driver_t drv,int device_id) +{ + rt_device_t device; + if (!drv) + { + return RT_NULL; + } + + device = (rt_device_t)rt_calloc(1,drv->device_size); + if(device == RT_NULL) + { + return RT_NULL; + } + device->device_id = device_id; + rt_snprintf(device->parent.name, sizeof(device->parent.name), "%s%d", drv->name, device_id); + return device; +} +RTM_EXPORT(rt_device_create_since_driver); + +/** + * This function rt_device probe and init + * + * @param device the pointer of rt_device structure + * @return the error code, RT_EOK on successfully. + */ +rt_err_t rt_device_probe_and_init(rt_device_t device) +{ + int ret = -RT_ERROR; + if (!device) + { + return -RT_EINVAL; + } + if(!device->drv) + { + return -RT_ERROR; + } + if(device->drv->probe) + { + ret = device->drv->probe((rt_device_t)device); + } + if(device->drv->probe_init) + { + ret = device->drv->probe_init((rt_device_t)device); + } + return ret; +} +RTM_EXPORT(rt_device_probe_and_init); +#endif /* RT_USING_DM */ #endif /* RT_USING_DEVICE */ |
