From 608b79bef07a3c51e2088fcd7c63934274eb86b8 Mon Sep 17 00:00:00 2001 From: Jinliang Li Date: Tue, 9 Nov 2021 13:45:14 +0800 Subject: [PATCH] BugID:37778403: remove old device management framework [Detail] Remove old device management framework. [Verified Cases] Build Pass: Test Pass: Change-Id: I64f5039fbc25824c45a21548b9d112482ee8242e Signed-off-by: Jinliang Li --- device/device.c | 543 ------------------------------------ device/object.c | 417 --------------------------- device/vfs_adapter.c | 160 ----------- include/device/aos_device.h | 298 -------------------- include/device/object.h | 91 ------ package.yaml | 6 - 6 files changed, 1515 deletions(-) delete mode 100644 device/device.c delete mode 100644 device/object.c delete mode 100644 device/vfs_adapter.c delete mode 100644 include/device/aos_device.h delete mode 100644 include/device/object.h diff --git a/device/device.c b/device/device.c deleted file mode 100644 index ba11888..0000000 --- a/device/device.c +++ /dev/null @@ -1,543 +0,0 @@ -/* - * Copyright (C) 2015-2020 Alibaba Group Holding Limited - */ - -#include -#include -#include "device/aos_device.h" -#include -#include -#include - -#include "k_api.h" - -#define TAG "aos_device_bridge" - -#define device_init (dev->init) -#define device_open (dev->open) -#define device_close (dev->close) -#define device_read (dev->read) -#define device_write (dev->write) -#define device_control (dev->control) - -extern struct file_ops m_dev_fops; -extern void aos_object_detach(aos_object_t object); - -#ifndef AOS_DEVICE_BRIDGE_USE_VFS - -static int bridge_device_probe (struct u_platform_device *pdev) { - LOGW(TAG, "%s", __func__); - return 0; -} - -static int bridge_device_remove (struct u_platform_device *pdev) { - LOGW(TAG, "%s", __func__); - return 0; -} - -static void bridge_device_shutdown (struct u_platform_device *pdev) { - LOGW(TAG, "%s", __func__); - return; -} - -static int bridge_device_suspend (struct u_platform_device *pdev, int /*pm_message_t */state) { - LOGW(TAG, "%s", __func__); - return 0; -} - -static int bridge_device_resume (struct u_platform_device *pdev) { - LOGW(TAG, "%s", __func__); - return 0; -} - -int bridge_device_init (struct u_platform_device *pdev) { - return 0; -} - -int bridge_device_deinit (struct u_platform_device *pdev) { - return 0; -} - -int bridge_device_pm (struct u_platform_device *pdev, u_pm_ops_t state) { - return 0; -} - -static struct subsys_drv bridge_device_drv = { - .drv_name = "bridge_drv", - .init = bridge_device_init, - .deinit = bridge_device_deinit, - .pm = bridge_device_pm, -#if 0 - .probe = bridge_device_probe, - .remove = bridge_device_remove, - .shutdown = bridge_device_shutdown, - .suspend = bridge_device_suspend, - .resume = bridge_device_resume, -#endif -}; - -static int aos_device_bridge_reg(const char *name, subsys_file_ops_t *fops, aos_device_t udata) -{ - int ret = 0; - int node_name_len = 0; - struct subsys_dev *ppsdev = NULL; - - LOGI(TAG, "vfs driver init starts"); - - node_name_len = strlen(name) + 2 + 1; // 2 for %d, 1 for '\0' - LOGI(TAG, "node_name_len:%d", node_name_len); - - ppsdev = malloc(sizeof(struct subsys_dev) + node_name_len); - if (!ppsdev) { - LOGI(TAG, "malloc failed, ppsdev:%p", ppsdev); - goto err; - } - - memset(ppsdev, 0x0, sizeof(struct subsys_dev)+node_name_len); - - ppsdev->node_name = (char *)((ppsdev) + 1); - snprintf((ppsdev)->node_name, node_name_len, "%s", name); - LOGD(TAG, "ppsdev:%p, (ppsdev) + 1:%p, node_name:%s, sizeof(struct subsys_dev):%d", - ppsdev, (ppsdev) + 1, (ppsdev)->node_name, sizeof(struct subsys_dev)); - ppsdev->permission = 0; - // please refer to definitions in enum SUBSYS_BUS_TYPE - ppsdev->type = BUS_TYPE_PLATFORM; - // user_data will be passed to open operation via node->i_arg - ppsdev->user_data = (void *)udata; - udata->user_data2 = ppsdev; - - ret = aos_dev_reg(ppsdev, fops, &bridge_device_drv); - if (ret) { - LOGE(TAG, "aos_dev_reg for failed, ret:%d", ret); - goto err; - } - - LOGI(TAG, "%s vfs driver init finish, ret:%d", __func__, ret); - return 0; - -err: - if (ppsdev) { - // shall uninstall devices who are already registered - aos_dev_unreg(ppsdev); - LOGI(TAG, "free memory"); - free(ppsdev); - ppsdev = NULL; - } - - LOGE(TAG, "%s vfs driver init failed, ret:%d", __func__, ret); - - return ret; -} -#endif - -/** - * This function registers a device driver with specified name. - * - * @param dev the pointer of device driver structure - * @param name the device's name - * @param flags the capabilities flag of device - * - * @return the error code, 0 on initialization successfully. - */ -int aos_device_register(aos_device_t dev, - const char *name, - uint16_t flags) -{ - if (dev == NULL) - return -1; - - if (aos_device_find(name) != NULL) - return -1; - - aos_object_init(&(dev->parent), AOS_Object_Class_Device, name); - dev->flag = flags; - dev->ref_count = 0; - dev->open_flag = 0; - -#ifdef AOS_DEVICE_BRIDGE_USE_VFS - if (0 != aos_register_driver(name, &m_dev_fops, (void *)dev)) { -#else - LOGD(TAG, "%s dev %p name %s", __func__, dev, name); - if (0 != aos_device_bridge_reg(name, &m_dev_fops, dev)) { -#endif - return -1; - } - - return 0; -} - -/** - * This function removes a previously registered device driver - * - * @param dev the pointer of device driver structure - * - * @return the error code, 0 on successfully. - */ -int aos_device_unregister(aos_device_t dev) -{ - struct subsys_dev *ppsdev; - - DEV_ASSERT(dev != NULL); - DEV_ASSERT(aos_object_get_type(&dev->parent) == AOS_Object_Class_Device); - DEV_ASSERT(aos_object_is_systemobject(&dev->parent)); - - ppsdev = dev->user_data2; - if (ppsdev) { - aos_dev_unreg(ppsdev); - free(ppsdev); - ppsdev = NULL; - } - - aos_object_detach(&(dev->parent)); - - return 0; -} - -/** - * This function finds a device driver by specified name. - * - * @param name the device driver's name - * - * @return the registered device driver on successful, or NULL on failure. - */ -aos_device_t aos_device_find(const char *name) -{ - struct aos_object *object; - dlist_t *node; - struct aos_object_information *information; - - CPSR_ALLOC(); - - RHINO_CRITICAL_ENTER(); - - /* try to find device object */ - information = aos_object_get_information(AOS_Object_Class_Device); - DEV_ASSERT(information != NULL); - for (node = information->object_list.next; - node != &(information->object_list); - node = node->next) - { - object = dlist_entry(node, struct aos_object, list); - if (strncmp(object->name, name, AOS_OBJ_NAME_MAX) == 0) - { - /* leave critical */ - RHINO_CRITICAL_EXIT(); - - return (aos_device_t)object; - } - } - - /* leave critical */ - RHINO_CRITICAL_EXIT(); - - /* not found */ - return NULL; -} - -/** - * This function creates a device object with user data size. - * - * @param type, the kind type of this device object. - * @param attach_size, the size of user data. - * - * @return the allocated device object, or NULL when failed. - */ -aos_device_t aos_device_create(int type, int attach_size) -{ - int size; - aos_device_t device; - - size = AOS_ALIGN(sizeof(struct aos_device), AOS_ALIGN_SIZE); - attach_size = AOS_ALIGN(attach_size, AOS_ALIGN_SIZE); - /* use the total size */ - size += attach_size; - - device = (aos_device_t)aos_malloc(size); - if (device) - { - memset(device, 0x0, sizeof(struct aos_device)); - device->type = (enum aos_device_class_type)type; - } - - return device; -} - -/** - * This function destroy the specific device object. - * - * @param dev, the specific device object. - */ -void aos_device_destroy(aos_device_t dev) -{ - DEV_ASSERT(dev != NULL); - DEV_ASSERT(aos_object_get_type(&dev->parent) == AOS_Object_Class_Device); - DEV_ASSERT(aos_object_is_systemobject(&dev->parent) == false); - - aos_object_detach(&(dev->parent)); - - /* release this device object */ - aos_free(dev); -} - -/** - * This function will initialize the specified device - * - * @param dev the pointer of device driver structure - * - * @return the result - */ -int aos_device_init(aos_device_t dev) -{ - int result = 0; - - DEV_ASSERT(dev != NULL); - - /* get device_init handler */ - if (device_init != NULL) - { - if (!(dev->flag & AOS_DEVICE_FLAG_ACTIVATED)) - { - result = device_init(dev); - if (result != 0) - { - LOGD(TAG,"To initialize device:%s failed. The error code is %d", - dev->parent.name, result); - } - else - { - dev->flag |= AOS_DEVICE_FLAG_ACTIVATED; - } - } - } - - return result; -} - -/** - * This function will open a device - * - * @param dev the pointer of device driver structure - * @param oflag the flags for device open - * - * @return the result - */ -int aos_device_open(aos_device_t dev, uint16_t oflag) -{ - int result = 0; - - DEV_ASSERT(dev != NULL); - DEV_ASSERT(aos_object_get_type(&dev->parent) == AOS_Object_Class_Device); - - /* if device is not initialized, initialize it. */ - if (!(dev->flag & AOS_DEVICE_FLAG_ACTIVATED)) - { - if (device_init != NULL) - { - result = device_init(dev); - if (result != 0) - { - //printf("To initialize device:%s failed. The error code is %d\n",dev->parent.name, result); - return result; - } - } - - dev->flag |= AOS_DEVICE_FLAG_ACTIVATED; - } - - /* device is a stand alone device and opened */ - if ((dev->flag & AOS_DEVICE_FLAG_STANDALONE) && - (dev->open_flag & AOS_DEVICE_OFLAG_OPEN)) - { - return -1; // EBUSY - } - - /* call device_open interface */ - if (device_open != NULL) - { - result = device_open(dev, oflag); - } else { - /* set open flag */ - dev->open_flag = (oflag & AOS_DEVICE_OFLAG_MASK); - } - - /* set open flag */ - if (result == 0) { - dev->open_flag |= AOS_DEVICE_OFLAG_OPEN; - - dev->ref_count++; - /* don't let bad things happen silently. If you are bitten by this assert, - * please set the ref_count to a bigger type. */ - DEV_ASSERT(dev->ref_count != 0); - } - - return result; -} - -/** - * This function will close a device - * - * @param dev the pointer of device driver structure - * - * @return the result - */ -int aos_device_close(aos_device_t dev) -{ - int result = 0; - - DEV_ASSERT(dev != NULL); - DEV_ASSERT(aos_object_get_type(&dev->parent) == AOS_Object_Class_Device); - - if (dev->ref_count == 0) - return -1; - - dev->ref_count--; - - if (dev->ref_count != 0) - return 0; - - /* call device_close interface */ - if (device_close != NULL) { - result = device_close(dev); - } - - /* set open flag */ - if (result == 0) - dev->open_flag = AOS_DEVICE_OFLAG_CLOSE; - - return result; -} - -/** - * This function will read some data from a device. - * - * @param dev the pointer of device driver structure - * @param pos the position of reading - * @param buffer the data buffer to save read data - * @param size the size of buffer - * - * @return the actually read size on successful, otherwise negative returned. - * - * @note since 0.4.0, the unit of size/pos is a block for block device. - */ -size_t aos_device_read(aos_device_t dev, - long pos, - void *buffer, - size_t size) -{ - DEV_ASSERT(dev != NULL); - DEV_ASSERT(aos_object_get_type(&dev->parent) == AOS_Object_Class_Device); - - if (dev->ref_count == 0) { - return 0; - } - - /* call device_read interface */ - if (device_read != NULL) - { - return device_read(dev, pos, buffer, size); - } - - return 0; -} - -/** - * This function will write some data to a device. - * - * @param dev the pointer of device driver structure - * @param pos the position of written - * @param buffer the data buffer to be written to device - * @param size the size of buffer - * - * @return the actually written size on successful, otherwise negative returned. - * - * @note since 0.4.0, the unit of size/pos is a block for block device. - */ -size_t aos_device_write(aos_device_t dev, - long pos, - const void *buffer, - size_t size) -{ - DEV_ASSERT(dev != NULL); - DEV_ASSERT(aos_object_get_type(&dev->parent) == AOS_Object_Class_Device); - - if (dev->ref_count == 0) { - /* set error code -ENOSYS */ - return 0; - } - - /* call device_write interface */ - if (device_write != NULL) { - return device_write(dev, pos, buffer, size); - } - - /* set error code -ENOSYS */ - - return 0; -} - -/** - * This function will perform a variety of control functions on devices. - * - * @param dev the pointer of device driver structure - * @param cmd the command sent to device - * @param arg the argument of command - * - * @return the result - */ -int aos_device_control(aos_device_t dev, int cmd, void *arg) -{ - LOGD(TAG, "%s entry, cmd %d, dev %p", __func__, cmd, dev); - DEV_ASSERT(dev != NULL); - DEV_ASSERT(aos_object_get_type(&dev->parent) == AOS_Object_Class_Device); - - /* call device_write interface */ - if (device_control != NULL) - { - return device_control(dev, cmd, arg); - } else { - LOGD(TAG, "%s dev %p device_control is NULL\r\n", __func__, dev); - } - - return -1; -} - -/** - * This function will set the reception indication callback function. This callback function - * is invoked when this device receives data. - * - * @param dev the pointer of device driver structure - * @param rx_ind the indication callback function - * - * @return 0 - */ -int aos_device_set_rx_indicate(aos_device_t dev, - int (*rx_ind)(aos_device_t dev, size_t size)) -{ - DEV_ASSERT(dev != NULL); - DEV_ASSERT(aos_object_get_type(&dev->parent) == AOS_Object_Class_Device); - - dev->rx_indicate = rx_ind; - - return 0; -} - - -/** - * This function will set the indication callback function when device has - * written data to physical hardware. - * - * @param dev the pointer of device driver structure - * @param tx_done the indication callback function - * - * @return 0 - */ -int aos_device_set_tx_complete(aos_device_t dev, - int (*tx_done)(aos_device_t dev, void *buffer)) -{ - DEV_ASSERT(dev != NULL); - DEV_ASSERT(aos_object_get_type(&dev->parent) == AOS_Object_Class_Device); - - dev->tx_complete = tx_done; - - return 0; -} diff --git a/device/object.c b/device/object.c deleted file mode 100644 index a073e93..0000000 --- a/device/object.c +++ /dev/null @@ -1,417 +0,0 @@ -/* - * Copyright (C) 2015-2020 Alibaba Group Holding Limited - */ - - -#include "device/object.h" -#include "device/aos_device.h" - -#include "aos/kernel.h" -#include "k_api.h" - -#define OBJ_ASSERT(test) -#define AOS_USING_DEVICE - -#ifdef AOS_USING_HOOK -static void (*aos_object_attach_hook)(struct aos_object *object); -static void (*aos_object_detach_hook)(struct aos_object *object); -#endif - -/* - * define object_info for the number of aos_object_container items. - */ -enum aos_object_info_type -{ - AOS_Object_Info_Thread = 0, /**< The object is a thread. */ -#ifdef AOS_USING_SEMAPHORE - AOS_Object_Info_Semaphore, /**< The object is a semaphore. */ -#endif -#ifdef AOS_USING_MUTEX - AOS_Object_Info_Mutex, /**< The object is a mutex. */ -#endif -#ifdef AOS_USING_EVENT - AOS_Object_Info_Event, /**< The object is a event. */ -#endif -#ifdef AOS_USING_MAILBOX - AOS_Object_Info_MailBox, /**< The object is a mail box. */ -#endif -#ifdef AOS_USING_MESSAGEQUEUE - AOS_Object_Info_MessageQueue, /**< The object is a message queue. */ -#endif -#ifdef AOS_USING_MEMHEAP - AOS_Object_Info_MemHeap, /**< The object is a memory heap */ -#endif -#ifdef AOS_USING_MEMPOOL - AOS_Object_Info_MemPool, /**< The object is a memory pool. */ -#endif -#ifdef AOS_USING_DEVICE - AOS_Object_Info_Device, /**< The object is a device */ -#endif - AOS_Object_Info_Timer, /**< The object is a timer. */ -#ifdef AOS_USING_MODULE - AOS_Object_Info_Module, /**< The object is a module. */ -#endif - AOS_Object_Info_Unknown, /**< The object is unknown. */ -}; - -#define _OBJ_CONTAINER_LIST_INIT(c) \ - {&(aos_object_container[c].object_list), &(aos_object_container[c].object_list)} -static struct aos_object_information aos_object_container[AOS_Object_Info_Unknown] = -{ - /* initialize object container - thread */ - {AOS_Object_Class_Thread, _OBJ_CONTAINER_LIST_INIT(AOS_Object_Info_Thread), sizeof(aos_task_t)}, -#ifdef AOS_USING_SEMAPHORE - /* initialize object container - semaphore */ - {AOS_Object_Class_Semaphore, _OBJ_CONTAINER_LIST_INIT(AOS_Object_Info_Semaphore), sizeof(aos_semt_t)}, -#endif -#ifdef AOS_USING_MUTEX - /* initialize object container - mutex */ - {AOS_Object_Class_Mutex, _OBJ_CONTAINER_LIST_INIT(AOS_Object_Info_Mutex), sizeof(aos_mutex_t)}, -#endif -#ifdef AOS_USING_EVENT - /* initialize object container - event */ - {AOS_Object_Class_Event, _OBJ_CONTAINER_LIST_INIT(AOS_Object_Info_Event), sizeof(aos_event_t)}, -#endif -#ifdef AOS_USING_MAILBOX - /* initialize object container - mailbox */ - {AOS_Object_Class_MailBox, _OBJ_CONTAINER_LIST_INIT(AOS_Object_Info_MailBox), sizeof(aos_queue_t)}, -#endif -#ifdef AOS_USING_MESSAGEQUEUE - /* initialize object container - message queue */ - {AOS_Object_Class_MessageQueue, _OBJ_CONTAINER_LIST_INIT(AOS_Object_Info_MessageQueue), sizeof(struct aos_messagequeue)}, -#endif -#ifdef AOS_USING_MEMHEAP - /* initialize object container - memory heap */ - {AOS_Object_Class_MemHeap, _OBJ_CONTAINER_LIST_INIT(AOS_Object_Info_MemHeap), sizeof(struct memheap)}, -#endif -#ifdef AOS_USING_MEMPOOL - /* initialize object container - memory pool */ - {AOS_Object_Class_MemPool, _OBJ_CONTAINER_LIST_INIT(AOS_Object_Info_MemPool), sizeof(struct aos_mempool)}, -#endif -#ifdef AOS_USING_DEVICE - /* initialize object container - device */ - {AOS_Object_Class_Device, _OBJ_CONTAINER_LIST_INIT(AOS_Object_Info_Device), sizeof(struct aos_device)}, -#endif - /* initialize object container - timer */ - {AOS_Object_Class_Timer, _OBJ_CONTAINER_LIST_INIT(AOS_Object_Info_Timer), sizeof(aos_timer_t)}, -#ifdef AOS_USING_MODULE - /* initialize object container - module */ - {AOS_Object_Class_Module, _OBJ_CONTAINER_LIST_INIT(AOS_Object_Info_Module), sizeof(struct aos_dlmodule)}, -#endif -}; - -#ifdef AOS_USING_HOOK -static void (*aos_object_attach_hook)(struct aos_object *object); -static void (*aos_object_detach_hook)(struct aos_object *object); -void (*aos_object_trytake_hook)(struct aos_object *object); -void (*aos_object_take_hook)(struct aos_object *object); -void (*aos_object_put_hook)(struct aos_object *object); - -/** - * @addtogroup Hook - */ - -/**@{*/ - -/** - * This function will set a hook function, which will be invoked when object - * attaches to kernel object system. - * - * @param hook the hook function - */ -void aos_object_attach_sethook(void (*hook)(struct aos_object *object)) -{ - aos_object_attach_hook = hook; -} - -/** - * This function will set a hook function, which will be invoked when object - * detaches from kernel object system. - * - * @param hook the hook function - */ -void aos_object_detach_sethook(void (*hook)(struct aos_object *object)) -{ - aos_object_detach_hook = hook; -} - -/** - * This function will set a hook function, which will be invoked when object - * is taken from kernel object system. - * - * The object is taken means: - * semaphore - semaphore is taken by thread - * mutex - mutex is taken by thread - * event - event is received by thread - * mailbox - mail is received by thread - * message queue - message is received by thread - * - * @param hook the hook function - */ -void aos_object_trytake_sethook(void (*hook)(struct aos_object *object)) -{ - aos_object_trytake_hook = hook; -} - -/** - * This function will set a hook function, which will be invoked when object - * have been taken from kernel object system. - * - * The object have been taken means: - * semaphore - semaphore have been taken by thread - * mutex - mutex have been taken by thread - * event - event have been received by thread - * mailbox - mail have been received by thread - * message queue - message have been received by thread - * timer - timer is started - * - * @param hook the hook function - */ -void aos_object_take_sethook(void (*hook)(struct aos_object *object)) -{ - aos_object_take_hook = hook; -} - -/** - * This function will set a hook function, which will be invoked when object - * is put to kernel object system. - * - * @param hook the hook function - */ -void aos_object_put_sethook(void (*hook)(struct aos_object *object)) -{ - aos_object_put_hook = hook; -} - -/**@}*/ -#endif - -/** - * @ingroup SystemInit - * - * This function will initialize system object management. - * - * @deprecated since 0.3.0, this function does not need to be invoked - * in the system initialization. - */ -void aos_system_object_init(void) -{ -} - -/** - * @addtogroup KernelObject - */ - -/**@{*/ - -/** - * This function will return the specified type of object information. - * - * @param type the type of object - * @return the object type information or NULL - */ -struct aos_object_information * -aos_object_get_information(enum aos_object_class_type type) -{ - int index; - - for (index = 0; index < AOS_Object_Info_Unknown; index ++) - if (aos_object_container[index].type == type) return &aos_object_container[index]; - - return NULL; -} - - -/** - * This function will initialize an object and add it to object system - * management. - * - * @param object the specified object to be initialized. - * @param type the object type. - * @param name the object name. In system, the object's name must be unique. - */ -void aos_object_init(struct aos_object *object, - enum aos_object_class_type type, - const char *name) -{ - struct dlist_s *node = NULL; - struct aos_object_information *information; -#ifdef AOS_USING_MODULE - struct aos_dlmodule *module = dlmodule_self(); -#endif - - CPSR_ALLOC(); - - /* get object information */ - information = aos_object_get_information(type); - OBJ_ASSERT(information != NULL); - - /* check object type to avoid re-initialization */ - - RHINO_CRITICAL_ENTER(); - - /* try to find object */ - for (node = information->object_list.next; - node != &(information->object_list); - node = node->next) - { - struct aos_object *obj; - - obj = dlist_entry(node, struct aos_object, list); - if (obj) /* skip warning when disable debug */ - { - OBJ_ASSERT(obj != object); - } - } - /* leave critical */ - RHINO_CRITICAL_EXIT(); - - /* initialize object's parameters */ - /* set object type to static */ - object->type = type | AOS_Object_Class_Static; - /* copy name */ - strncpy(object->name, name, AOS_OBJ_NAME_MAX - 1); - -#ifdef AOS_USING_HOOK - AOS_OBJECT_HOOK_CALL(aos_object_attach_hook, (object)); -#endif - - /* lock interrupt */ - RHINO_CRITICAL_ENTER(); - -#ifdef AOS_USING_MODULE - if (module) - { - dlist_add_tail(&(module->object_list), &(object->list)); - object->module_id = (void *)module; - } - else -#endif - { - /* insert object into information object list */ - dlist_add_tail( &(object->list),&(information->object_list)); - } - - /* unlock interrupt */ - RHINO_CRITICAL_EXIT(); -} - -/** - * This function will detach a static object from object system, - * and the memory of static object is not freed. - * - * @param object the specified object to be detached. - */ -void aos_object_detach(aos_object_t object) -{ - /* object check */ - OBJ_ASSERT(object != NULL); - -#ifdef AOS_USING_HOOK - AOS_OBJECT_HOOK_CALL(aos_object_detach_hook, (object)); -#endif - - CPSR_ALLOC(); - - /* reset object type */ - object->type = 0; - - /* enter critical */ - RHINO_CRITICAL_ENTER(); - - /* remove from old list */ - dlist_del(&(object->list)); - - RHINO_CRITICAL_EXIT(); -} - -/** - * This function will judge the object is system object or not. - * Normally, the system object is a static object and the type - * of object set to RT_Object_Class_Static. - * - * @param object the specified object to be judged. - * - * @return RT_TRUE if a system object, RT_FALSE for others. - */ -bool aos_object_is_systemobject(aos_object_t object) -{ - /* object check */ - OBJ_ASSERT(object != NULL); - - if (object->type & AOS_Object_Class_Static) - return true; - - return false; -} - -/** - * This function will return the type of object without - * RT_Object_Class_Static flag. - * - * @param object the specified object to be get type. - * - * @return the type of object. - */ -uint8_t aos_object_get_type(aos_object_t object) -{ - /* object check */ - OBJ_ASSERT(object != NULL); - - return object->type & ~AOS_Object_Class_Static; -} - -/** - * This function will find specified name object from object - * container. - * - * @param name the specified name of object. - * @param type the type of object - * - * @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. - */ -aos_object_t aos_object_find(const char *name, uint8_t type) -{ - aos_object_t object = NULL; - struct dlist_s *node = NULL; - struct aos_object_information *information = NULL; - - CPSR_ALLOC(); - - /* parameter check */ - if ((name == NULL) || (type > AOS_Object_Class_Unknown)) - return NULL; - - /* enter critical */ - RHINO_CRITICAL_ENTER(); - - /* try to find object */ - if (information == NULL) - { - information = aos_object_get_information((enum aos_object_class_type)type); - OBJ_ASSERT(information != NULL); - } - for (node = information->object_list.next; - node != &(information->object_list); - node = node->next) - { - object = dlist_entry(node, struct aos_object, list); - if (strncmp(object->name, name, AOS_OBJ_NAME_MAX) == 0) - { - /* leave critical */ - RHINO_CRITICAL_EXIT(); - - return object; - } - } - - /* leave critical */ - RHINO_CRITICAL_EXIT(); - - return NULL; -} - -/**@}*/ diff --git a/device/vfs_adapter.c b/device/vfs_adapter.c deleted file mode 100644 index 61d738b..0000000 --- a/device/vfs_adapter.c +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2015-2020 Alibaba Group Holding Limited - */ - -#include "aos/vfs.h" -#include "device/aos_device.h" -#include "ulog/ulog.h" - -#define TAG "VFS_ADAPTER" - -static int _device_open(inode_t *node, file_t *fp) -{ - aos_device_t dev = NULL; - - DEV_ASSERT(fp != NULL); - DEV_ASSERT(fp->node != NULL); - DEV_ASSERT(fp->node->i_name != NULL); - - /* find device */ -#ifdef AOS_DEVICE_BRIDGE_USE_VFS - dev = aos_device_find(fp->node->i_name); -#else - dev = fp->node->i_arg; -#endif - if (NULL == dev) { - return -1; - } - - return aos_device_open(dev, fp->node->i_flags); -} - -static int _device_close(file_t *fp) -{ - aos_device_t dev = NULL; - - DEV_ASSERT(fp != NULL); - DEV_ASSERT(fp->node != NULL); - DEV_ASSERT(fp->node->i_name != NULL); - - /* find device */ -#ifdef AOS_DEVICE_BRIDGE_USE_VFS - dev = aos_device_find(fp->node->i_name); -#else - dev = fp->node->i_arg; -#endif - if (NULL == dev) { - return -1; - } - - return aos_device_close(dev); -} - -static int _device_read(file_t *fp, void *buf, size_t nbytes) -{ - int ret; - aos_device_t dev = NULL; - - DEV_ASSERT(fp != NULL); - DEV_ASSERT(buf != NULL); - DEV_ASSERT(fp->node != NULL); - DEV_ASSERT(fp->node->i_name != NULL); - - /* find device */ -#ifdef AOS_DEVICE_BRIDGE_USE_VFS - dev = aos_device_find(fp->node->i_name); -#else - dev = fp->node->i_arg; -#endif - if (NULL == dev) { - return -1; - } - - ret = aos_device_read(dev, fp->offset, buf, nbytes); - if (ret >= 0) { - fp->offset += ret; - } - - return ret; -} - -static ssize_t _device_write(file_t *fp, const void *buf, size_t nbytes) -{ - int ret; - aos_device_t dev = NULL; - - DEV_ASSERT(fp != NULL); - DEV_ASSERT(buf != NULL); - DEV_ASSERT(fp->node != NULL); - DEV_ASSERT(fp->node->i_name != NULL); - - /* find device */ -#ifdef AOS_DEVICE_BRIDGE_USE_VFS - dev = aos_device_find(fp->node->i_name); -#else - dev = fp->node->i_arg; -#endif - if (NULL == dev) { - return -1; - } - - ret = aos_device_write(dev, fp->offset, buf, nbytes); - if (ret >= 0) { - fp->offset += ret; - } - - return ret; -} - -static int _device_ioctl(file_t *fp, int cmd, unsigned long arg) -{ - aos_device_t dev = NULL; - - DEV_ASSERT(fp != NULL); - DEV_ASSERT(fp->node != NULL); - DEV_ASSERT(fp->node->i_name != NULL); - - /* find device */ -#ifdef AOS_DEVICE_BRIDGE_USE_VFS - dev = aos_device_find(fp->node->i_name); -#else - dev = fp->node->i_arg; -#endif - if (NULL == dev) { - return -1; - } - - return aos_device_control(dev, cmd, (void *)arg); -} - -static uint32_t _device_lseek(file_t *fp, int64_t off, int32_t whence) -{ - aos_device_t dev = NULL; - - DEV_ASSERT(fp != NULL); - DEV_ASSERT(fp->node != NULL); - DEV_ASSERT(fp->node->i_name != NULL); - - /* find device */ -#ifdef AOS_DEVICE_BRIDGE_USE_VFS - dev = aos_device_find(fp->node->i_name); -#else - dev = fp->node->i_arg; -#endif - if (NULL == dev) { - return -1; - } - - fp->offset = off; - - return 0; -} - -struct file_ops m_dev_fops = { - .open = _device_open, - .close = _device_close, - .read = _device_read, - .write = _device_write, - .ioctl = _device_ioctl, - .lseek = _device_lseek, - }; diff --git a/include/device/aos_device.h b/include/device/aos_device.h deleted file mode 100644 index e855c22..0000000 --- a/include/device/aos_device.h +++ /dev/null @@ -1,298 +0,0 @@ -/* - * Copyright (C) 2015-2020 Alibaba Group Holding Limited - */ - -#ifndef _AOS_DEVICE_H -#define _AOS_DEVICE_H - -#include -#include -#include - -#include "object.h" - -#include "aos/kernel.h" -#include "aos/vfs.h" - -#ifdef __cplusplus -extern "C" { -#endif - -//#define AOS_USING_DEVICE_OPS - -#define DEV_ASSERT(test) -#define AOS_DEVICE(device) ((aos_device_t)device) - -/** - * device flags defitions - */ -#define AOS_DEVICE_FLAG_DEACTIVATE 0x000 /**< device is not not initialized */ - -#define AOS_DEVICE_FLAG_RDONLY 0x001 /**< read only */ -#define AOS_DEVICE_FLAG_WRONLY 0x002 /**< write only */ -#define AOS_DEVICE_FLAG_RDWR 0x003 /**< read and write */ - -#define AOS_DEVICE_FLAG_REMOVABLE 0x004 /**< removable device */ -#define AOS_DEVICE_FLAG_STANDALONE 0x008 /**< standalone device */ -#define AOS_DEVICE_FLAG_ACTIVATED 0x010 /**< device is activated */ -#define AOS_DEVICE_FLAG_SUSPENDED 0x020 /**< device is suspended */ -#define AOS_DEVICE_FLAG_STREAM 0x040 /**< stream mode */ - -#define AOS_DEVICE_FLAG_INT_RX 0x100 /**< INT mode on Rx */ -#define AOS_DEVICE_FLAG_DMA_RX 0x200 /**< DMA mode on Rx */ -#define AOS_DEVICE_FLAG_INT_TX 0x400 /**< INT mode on Tx */ -#define AOS_DEVICE_FLAG_DMA_TX 0x800 /**< DMA mode on Tx */ - -#define AOS_DEVICE_OFLAG_CLOSE 0x000 /**< device is closed */ -#define AOS_DEVICE_OFLAG_RDONLY 0x001 /**< read only access */ -#define AOS_DEVICE_OFLAG_WRONLY 0x002 /**< write only access */ -#define AOS_DEVICE_OFLAG_RDWR 0x003 /**< read and write */ -#define AOS_DEVICE_OFLAG_OPEN 0x008 /**< device is opened */ -#define AOS_DEVICE_OFLAG_MASK 0xf0f /**< mask of open flag */ - -#define AOS_DEVICE_CTRL_CHAR_STREAM 0x10 /**< stream mode on char device */ -#define AOS_DEVICE_CTRL_BLK_GETGEOME 0x10 /**< get geometry information */ -#define AOS_DEVICE_CTRL_BLK_SYNC 0x11 /**< flush data to block device */ -#define AOS_DEVICE_CTRL_BLK_ERASE 0x12 /**< erase block on block device */ -#define AOS_DEVICE_CTRL_BLK_AUTOREFRESH 0x13 /**< block device : enter/exit auto refresh mode */ -#define AOS_DEVICE_CTRL_NETIF_GETMAC 0x10 /**< get mac address */ -#define AOS_DEVICE_CTRL_MTD_FORMAT 0x10 /**< format a MTD device */ -#define AOS_DEVICE_CTRL_RTC_GET_TIME 0x10 /**< get time */ -#define AOS_DEVICE_CTRL_RTC_SET_TIME 0x11 /**< set time */ -#define AOS_DEVICE_CTRL_RTC_GET_ALARM 0x12 /**< get alarm */ -#define AOS_DEVICE_CTRL_RTC_SET_ALARM 0x13 /**< set alarm */ - -enum aos_device_class_type -{ - AOS_Device_Class_Char = 0, /**< character device */ - AOS_Device_Class_Block, /**< block device */ - AOS_Device_Class_NetIf, /**< net interface */ - AOS_Device_Class_MTD, /**< memory device */ - AOS_Device_Class_CAN, /**< CAN device */ - AOS_Device_Class_RTC, /**< RTC device */ - AOS_Device_Class_Sound, /**< Sound device */ - AOS_Device_Class_Graphic, /**< Graphic device */ - AOS_Device_Class_I2CBUS, /**< I2C bus device */ - AOS_Device_Class_USBDevice, /**< USB slave device */ - AOS_Device_Class_USBHost, /**< USB host bus */ - AOS_Device_Class_SPIBUS, /**< SPI bus device */ - AOS_Device_Class_SPIDevice, /**< SPI device */ - AOS_Device_Class_SDIO, /**< SDIO bus device */ - AOS_Device_Class_PM, /**< PM pseudo device */ - AOS_Device_Class_Pipe, /**< Pipe device */ - AOS_Device_Class_Portal, /**< Portal device */ - AOS_Device_Class_Timer, /**< Timer device */ - AOS_Device_Class_Miscellaneous, /**< Miscellaneous device */ - AOS_Device_Class_Sensor, /**< Sensor device */ - AOS_Device_Class_Touch, /**< Touch device */ - AOS_Device_Class_Unknown /**< unknown device */ -}; - -typedef struct aos_device * aos_device_t; - -/** - * Device structure - */ -struct aos_device -{ - struct aos_object parent; /**< inherit from aos_object */ - - enum aos_device_class_type type; /**< device type */ - uint16_t flag; /**< device flag */ - uint16_t open_flag; /**< device open flag */ - - uint8_t ref_count; /**< reference count */ - uint8_t device_id; /**< 0 - 255 */ - - /* device call back */ - int (*rx_indicate)(aos_device_t dev, size_t size); - int (*tx_complete)(aos_device_t dev, void *buffer); - -#ifdef AOS_USING_DEVICE_OPS - const struct aos_device_ops *ops; -#else - /* common device interface */ - int (*init) (aos_device_t dev); - int (*open) (aos_device_t dev, uint16_t oflag); - int (*close) (aos_device_t dev); - size_t (*read) (aos_device_t dev, long pos, void *buffer, size_t size); - size_t (*write) (aos_device_t dev, long pos, const void *buffer, size_t size); - int (*control)(aos_device_t dev, int cmd, void *args); -#endif - -#if defined(AOS_USING_POSIX) - const struct file_ops *fops; -#endif - - void *user_data; /**< device private data */ - void *user_data2; /**< device private data2 */ - - void *wait_queue; -}; - -#ifdef AOS_USING_DEVICE_OPS -struct aos_device_ops -{ - /* common device interface */ - long (*init) (aos_device_t dev); - long (*open) (aos_device_t dev, uint16_t oflag); - long (*close) (aos_device_t dev); - size_t (*read) (aos_device_t dev, off_t pos, void *buffer, size_t size); - size_t (*write) (aos_device_t dev, off_t pos, const void *buffer, size_t size); - long (*control)(aos_device_t dev, int cmd, void *args); -}; -#endif - -/** - * This function registers a device driver with specified name. - * - * @param dev the pointer of device driver structure - * @param name the device driver's name - * @param flags the capabilities flag of device - * - * @return the error code, 0 on initialization successfully. - */ -int aos_device_register(aos_device_t dev, - const char *name, - uint16_t flags); - -/** - * This function removes a previously registered device driver - * - * @param dev the pointer of device driver structure - * - * @return the error code, 0 on successfully. - */ -int aos_device_unregister(aos_device_t dev); - -/** - * This function finds a device driver by specified name. - * - * @param name the device driver's name - * - * @return the registered device driver on successful, or NULL on failure. - */ -aos_device_t aos_device_find(const char *name); - -/** - * This function creates a device object with user data size. - * - * @param type, the kind type of this device object. - * @param attach_size, the size of user data. - * - * @return the allocated device object, or NULL when failed. - */ -aos_device_t aos_device_create(int type, int attach_size); - -/** - * This function destroy the specific device object. - * - * @param dev, the specific device object. - */ -void aos_device_destroy(aos_device_t dev); - -/** - * This function will initialize the specified device - * - * @param dev the pointer of device driver structure - * - * @return the result - */ -int aos_device_init(aos_device_t dev); - -/** - * This function will open a device - * - * @param dev the pointer of device driver structure - * @param oflag the flags for device open - * - * @return the result - */ -int aos_device_open(aos_device_t dev, uint16_t oflag); - -/** - * This function will close a device - * - * @param dev the pointer of device driver structure - * - * @return the result - */ -int aos_device_close(aos_device_t dev); - -/** - * This function will read some data from a device. - * - * @param dev the pointer of device driver structure - * @param pos the position of reading - * @param buffer the data buffer to save read data - * @param size the size of buffer - * - * @return the actually read size on successful, otherwise negative returned. - * - * @note since 0.4.0, the unit of size/pos is a block for block device. - */ -size_t aos_device_read(aos_device_t dev, - long pos, - void *buffer, - size_t size); - -/** - * This function will write some data to a device. - * - * @param dev the pointer of device driver structure - * @param pos the position of written - * @param buffer the data buffer to be written to device - * @param size the size of buffer - * - * @return the actually written size on successful, otherwise negative returned. - * - * @note since 0.4.0, the unit of size/pos is a block for block device. - */ -size_t aos_device_write(aos_device_t dev, - long pos, - const void *buffer, - size_t size); - -/** - * This function will perform a variety of control functions on devices. - * - * @param dev the pointer of device driver structure - * @param cmd the command sent to device - * @param arg the argument of command - * - * @return the result - */ -int aos_device_control(aos_device_t dev, int cmd, void *arg); - - -/** - * This function will set the reception indication callback function. This callback function - * is invoked when this device receives data. - * - * @param dev the pointer of device driver structure - * @param rx_ind the indication callback function - * - * @return 0 - */ -int aos_device_set_rx_indicate(aos_device_t dev, - int (*rx_ind)(aos_device_t dev, size_t size)); - -/** - * This function will set the indication callback function when device has - * written data to physical hardware. - * - * @param dev the pointer of device driver structure - * @param tx_done the indication callback function - * - * @return 0 - */ -int aos_device_set_tx_complete(aos_device_t dev, - int (*tx_done)(aos_device_t dev, void *buffer)); - - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/include/device/object.h b/include/device/object.h deleted file mode 100644 index 31be718..0000000 --- a/include/device/object.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2015-2020 Alibaba Group Holding Limited - */ - -#ifndef _AOS_OBJECT_H -#define _AOS_OBJECT_H - -#include -#include -#include - -#include "aos/list.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef AOS_OBJ_NAME_MAX -#define AOS_OBJ_NAME_MAX 10 -#endif - -#ifndef AOS_ALIGN -#define AOS_ALIGN(size, align) (((size) + (align) - 1) & ~((align) - 1)) -#endif - -#ifndef AOS_ALIGN_SIZE -#define AOS_ALIGN_SIZE 4 -#endif - -enum aos_object_class_type -{ - AOS_Object_Class_Null = 0, /**< The object is not used. */ - AOS_Object_Class_Thread, /**< The object is a thread. */ - AOS_Object_Class_Semaphore, /**< The object is a semaphore. */ - AOS_Object_Class_Mutex, /**< The object is a mutex. */ - AOS_Object_Class_Event, /**< The object is a event. */ - AOS_Object_Class_MailBox, /**< The object is a mail box. */ - AOS_Object_Class_MessageQueue, /**< The object is a message queue. */ - AOS_Object_Class_MemHeap, /**< The object is a memory heap */ - AOS_Object_Class_MemPool, /**< The object is a memory pool. */ - AOS_Object_Class_Device, /**< The object is a device */ - AOS_Object_Class_Timer, /**< The object is a timer. */ - AOS_Object_Class_Module, /**< The object is a module. */ - AOS_Object_Class_Unknown, /**< The object is unknown. */ - AOS_Object_Class_Static = 0x80 /**< The object is a static object. */ -}; - -struct aos_object -{ - char name[AOS_OBJ_NAME_MAX]; /**< name of kernel object */ - uint8_t type; /**< type of kernel object */ - uint8_t flag; /**< flag of kernel object */ - -#ifdef AOS_USING_MODULE - void *module_id; /**< id of application module */ -#endif - dlist_t list; /**< list node of kernel object */ -}; - -typedef struct aos_object *aos_object_t; - -/** - * The information of the kernel object - */ -struct aos_object_information -{ - enum aos_object_class_type type; /**< object class type */ - dlist_t object_list; /**< object list */ - size_t object_size; /**< object size */ -}; - - -void aos_object_init(struct aos_object *object, - enum aos_object_class_type type, - const char *name); - -struct aos_object_information * -aos_object_get_information(enum aos_object_class_type type); - -#ifdef AOS_USING_MODULE -struct aos_dlmodule { - /* modeule definition */ -}; -#endif - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/package.yaml b/package.yaml index 8cfbb4a..9c70436 100644 --- a/package.yaml +++ b/package.yaml @@ -70,11 +70,6 @@ source_file: # os driver entry - devicevfs/src/u_driver_hub.c ? -# aos device framework - - device/device.c ? - - device/object.c ? - - device/vfs_adapter.c ? - ## 第五部分:配置信息 # def_config: # 组件的可配置项 # CONFIG_DEBUG: y @@ -83,7 +78,6 @@ source_file: def_config: CONFIG_DRV_CORE: 1 CONFIG_DRV_PLATFORM: 1 - CONFIG_DRV_DEVICE: 1 CONFIG_DRV_VFS: 1 -- Gitee