mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-22 19:44:24 +08:00
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 <zhangbingru@rt-thread.com>
Co-authored-by: zhkag <zhkag@foxmail.com>
This commit is contained in:
@@ -23,6 +23,17 @@
|
||||
#include <dlmodule.h>
|
||||
#endif /* RT_USING_MODULE */
|
||||
|
||||
#ifdef RT_USING_LWP
|
||||
#include <lwp.h>
|
||||
#endif
|
||||
|
||||
struct rt_custom_object
|
||||
{
|
||||
struct rt_object parent;
|
||||
rt_err_t (*destroy)(void *);
|
||||
void *data;
|
||||
};
|
||||
|
||||
/*
|
||||
* define object_info for the number of _object_container items.
|
||||
*/
|
||||
@@ -59,6 +70,12 @@ enum rt_object_info_type
|
||||
#endif
|
||||
#ifdef RT_USING_HEAP
|
||||
RT_Object_Info_Memory, /**< The object is a memory. */
|
||||
#endif
|
||||
#ifdef RT_USING_LWP
|
||||
RT_Object_Info_Channel, /**< The object is a IPC channel */
|
||||
#endif
|
||||
#ifdef RT_USING_HEAP
|
||||
RT_Object_Info_Custom, /**< The object is a custom object */
|
||||
#endif
|
||||
RT_Object_Info_Unknown, /**< The object is unknown. */
|
||||
};
|
||||
@@ -112,6 +129,11 @@ static struct rt_object_information _object_container[RT_Object_Info_Unknown] =
|
||||
/* initialize object container - small memory */
|
||||
{RT_Object_Class_Memory, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Memory), sizeof(struct rt_memory)},
|
||||
#endif
|
||||
#ifdef RT_USING_LWP
|
||||
/* initialize object container - module */
|
||||
{RT_Object_Class_Channel, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Channel), sizeof(struct rt_channel)},
|
||||
{RT_Object_Class_Custom, _OBJ_CONTAINER_LIST_INIT(RT_Object_Info_Custom), sizeof(struct rt_custom_object)},
|
||||
#endif
|
||||
};
|
||||
|
||||
#ifndef __on_rt_object_attach_hook
|
||||
@@ -607,4 +629,60 @@ rt_object_t rt_object_find(const char *name, rt_uint8_t type)
|
||||
return RT_NULL;
|
||||
}
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
/**
|
||||
* This function will create a custom object
|
||||
* container.
|
||||
*
|
||||
* @param name the specified name of object.
|
||||
* @param type the type of object
|
||||
* @param data the custom data
|
||||
* @param data_destroy the custom object destroy callback
|
||||
*
|
||||
* @return the found object or RT_NULL if there is no this object
|
||||
* in object container.
|
||||
*
|
||||
* @note this function shall not be invoked in interrupt status.
|
||||
*/
|
||||
|
||||
rt_object_t rt_custom_object_create(const char *name, void *data, rt_err_t (*data_destroy)(void *))
|
||||
{
|
||||
struct rt_custom_object *cobj = RT_NULL;
|
||||
|
||||
cobj = (struct rt_custom_object *)rt_object_allocate(RT_Object_Class_Custom, name);
|
||||
if (!cobj)
|
||||
{
|
||||
return RT_NULL;
|
||||
}
|
||||
cobj->destroy = data_destroy;
|
||||
cobj->data = data;
|
||||
return (struct rt_object *)cobj;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will destroy a custom object
|
||||
* container.
|
||||
*
|
||||
* @param obj the specified name of object.
|
||||
*
|
||||
* @note this function shall not be invoked in interrupt status.
|
||||
*/
|
||||
rt_err_t rt_custom_object_destroy(rt_object_t obj)
|
||||
{
|
||||
rt_err_t ret = -1;
|
||||
|
||||
struct rt_custom_object *cobj = (struct rt_custom_object *)obj;
|
||||
|
||||
if (obj && obj->type == RT_Object_Class_Custom)
|
||||
{
|
||||
if (cobj->destroy)
|
||||
{
|
||||
ret = cobj->destroy(cobj->data);
|
||||
}
|
||||
rt_object_delete(obj);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**@}*/
|
||||
|
||||
Reference in New Issue
Block a user