2022-12-03 12:07:44 +08:00
|
|
|
/*
|
2023-06-22 14:16:03 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2022-12-03 12:07:44 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
2023-07-13 14:49:35 +08:00
|
|
|
#include <drivers/core/bus.h>
|
2023-06-22 14:16:03 +08:00
|
|
|
|
2023-07-13 14:49:35 +08:00
|
|
|
#if defined(RT_USING_POSIX_DEVIO)
|
|
|
|
#include <rtdevice.h> /* for wqueue_init */
|
2022-12-03 12:07:44 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
2023-07-13 14:49:35 +08:00
|
|
|
* This function attach a driver to bus
|
2022-12-03 12:07:44 +08:00
|
|
|
*
|
2023-07-13 14:49:35 +08:00
|
|
|
* @param drv the driver to be attached
|
2022-12-03 12:07:44 +08:00
|
|
|
*/
|
2023-07-13 14:49:35 +08:00
|
|
|
rt_err_t rt_driver_register(rt_driver_t drv)
|
2022-12-03 12:07:44 +08:00
|
|
|
{
|
2023-07-13 14:49:35 +08:00
|
|
|
rt_err_t ret;
|
|
|
|
struct rt_bus *bus = RT_NULL;
|
|
|
|
|
|
|
|
RT_ASSERT(drv != RT_NULL);
|
|
|
|
|
|
|
|
if (drv->bus)
|
2022-12-03 12:07:44 +08:00
|
|
|
{
|
2023-07-13 14:49:35 +08:00
|
|
|
bus = drv->bus;
|
|
|
|
ret = rt_bus_add_driver(bus, drv);
|
2022-12-03 12:07:44 +08:00
|
|
|
}
|
2023-07-13 14:49:35 +08:00
|
|
|
else
|
2022-12-03 12:07:44 +08:00
|
|
|
{
|
2023-07-13 14:49:35 +08:00
|
|
|
ret = -RT_EINVAL;
|
2022-12-03 12:07:44 +08:00
|
|
|
}
|
2023-07-13 14:49:35 +08:00
|
|
|
|
2022-12-03 12:07:44 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2023-07-13 14:49:35 +08:00
|
|
|
RTM_EXPORT(rt_driver_register);
|
2022-12-03 12:07:44 +08:00
|
|
|
|
|
|
|
/**
|
2023-07-13 14:49:35 +08:00
|
|
|
* This function remove driver from system.
|
2022-12-03 12:07:44 +08:00
|
|
|
*
|
2023-07-13 14:49:35 +08:00
|
|
|
* @param drv the driver to be removed
|
2022-12-03 12:07:44 +08:00
|
|
|
*/
|
2023-07-13 14:49:35 +08:00
|
|
|
rt_err_t rt_driver_unregister(rt_driver_t drv)
|
2022-12-03 12:07:44 +08:00
|
|
|
{
|
2023-07-13 14:49:35 +08:00
|
|
|
rt_err_t ret;
|
2022-12-03 12:07:44 +08:00
|
|
|
|
2023-07-13 14:49:35 +08:00
|
|
|
ret = rt_bus_remove_driver(drv);
|
2022-12-03 12:07:44 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2024-06-26 23:25:23 +08:00
|
|
|
RTM_EXPORT(rt_driver_unregister);
|