⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 device.c.svn-base

📁 RT-Thread是发展中的下一代微内核嵌入式实时操作系统
💻 SVN-BASE
字号:
/* * File      : device.c * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2006, RT-Thread Development Team * * The license and distribution terms for this file may be * found in the file LICENSE in this distribution or at * http://openlab.rt-thread.com/license/LICENSE * * Change Logs: * Date           Author       Notes * 2007-01-21     Bernard      the first version */#include <rtthread.h>#include "kservice.h"#ifdef RT_USING_DEVICE/** * This function initialize device system. */rt_err_t rt_device_system_init(){	return RT_EOK;}/** * This function register a device driver with specified name. *  * @param dev the pointer of device driver structure * @param name the device driver's name * * @return the error code, RT_EOK on initialize successfully. */rt_err_t rt_device_register(rt_device_t dev, const char* name, rt_uint8 flags){	if (dev == RT_NULL) return -RT_ERROR;	rt_object_init(&(dev->parent), RT_Object_Class_Device, name);	dev->flag = flags;	return RT_EOK;}/** * This function  *  * @param p description * * @return  */rt_err_t rt_device_unregister(rt_device_t dev){	RT_ASSERT(dev != RT_NULL);	rt_object_detach(&(dev->parent));		return RT_EOK;}rt_err_t rt_device_init_all(){	struct rt_device* device;	struct rt_list_node* node;	struct rt_object_information *information;	register rt_err_t result;		extern struct rt_object_information rt_object_container[];	information = &rt_object_container[RT_Object_Class_Device];	/* for each device */	for (node = information->object_list.next; node != &(information->object_list); node = node->next)	{		rt_err_t (*init)(rt_device_t dev);		device = (struct rt_device*)rt_list_entry(node, struct rt_object, list);		/* get device init handler */		init = device->init;		if (init != RT_NULL)		{			result = init(device);			if (result != RT_EOK)			{				rt_kprintf("init device:%s error:\n", device->parent.name);				rt_kprintf("error code:%d\n", result);			}		}	}	return RT_EOK;}rt_device_t rt_device_find(const char* name){	/* try to find device object */	return (struct rt_device*) rt_object_find (RT_Object_Class_Device, 		name);}rt_err_t rt_device_open(rt_device_t dev){	rt_err_t (*open) (rt_device_t dev);		RT_ASSERT(dev != RT_NULL);	/* call device open interface */	open = dev->open;	if (open != RT_NULL)	{		return open(dev);	}	return -RT_ENOSYS;}rt_err_t rt_device_close(rt_device_t dev){	rt_err_t (*close)(rt_device_t dev);	RT_ASSERT(dev != RT_NULL);	/* call device close interface */	close = dev->close;	if (close != RT_NULL)	{		return close(dev);	}	return -RT_ENOSYS;}rt_err_t rt_device_read (rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size){	rt_err_t (*read)(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size);	RT_ASSERT(dev != RT_NULL);	/* call device read interface */	read = dev->read;	if (read != RT_NULL)	{		return read(dev, pos, buffer, size);	}	return -RT_ENOSYS;}rt_err_t rt_device_write(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size){	rt_err_t (*write)(rt_device_t dev, rt_off_t pos, const void* buffer, rt_size_t size);	RT_ASSERT(dev != RT_NULL);	/* call device write interface */	write = dev->write;	if (write != RT_NULL)	{		return write(dev, pos, buffer, size);	}	return -RT_ENOSYS;}rt_err_t rt_device_control(rt_device_t dev, rt_uint8 cmd, void* arg){	rt_err_t (*control)(rt_device_t dev, rt_uint8 cmd, void* arg);	RT_ASSERT(dev != RT_NULL);	/* call device write interface */	control = dev->control;	if (control != RT_NULL)	{		return control(dev, cmd, arg);	}	return -RT_ENOSYS;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -