devices_init ()

参考部分1:http://blog.chinaunix.net/uid-20799298-id-99663.html

参考部分2:uboot源码,uboot版本:1.1.6

PS:还有一些问题没有搞清楚,有问题请指出。个人感觉device的定义、存储、查找有一种数组方法的感觉,个人认为采用链表比较好。

定义链表头:

typedef struct ListStructTag
    {
    int signature;              /* debugging aid */
    int percentIncrease;        /* %of current size to increase by when list is out of space */
    int minNumItemsIncrease;    /* fixed number of items to increase by when list is out of space */
    int listSize;               /* number of items than can fit in the currently allocated memory */
    int itemSize;               /* the size of each item in the list (same for every item) */
    int numItems;               /* number of items currently in the list */
    unsigned char itemList[1];  /* resizable array of list elements */
    } ListStruct;

typedef struct ListStructTag **list_t;        /* The list abstract data type */

定义device链表的头。


    int percentIncrease;        /* %of current size to increase by when list is out of space */
    int minNumItemsIncrease;    /* fixed number of items to increase by when list is out of space */

这两个定义不甚懂

int listSize;       //链表中的device个数
int itemSize;       //device的大小
numItems;         //真正的device个数,一般情况下,两个变量相等。在创建空间时先增加listsize,增加device后增加itemsize。
unsigned char itemList[1]; 指针指向device


 handlerecord:ptr指向设备链,size标记大小。

    typedef struct
    {
        void            *ptr;
        unsigned int    size;
    } HandleRecord;



定义device结构体:设备结构体包含设备名字,设备标记、一些借口函数。

/* Device information */
typedef struct {
	int	flags;			/* Device flags: input/output/system	*/
	int	ext;			/* Supported extensions			*/
	char	name[16];		/* Device name				*/

/* GENERAL functions */

	int (*start) (void);		/* To start the device			*/
	int (*stop) (void);		/* To stop the device			*/

/* OUTPUT functions */

	void (*putc) (const char c);	/* To put a char			*/
	void (*puts) (const char *s);	/* To put a string (accelerator)	*/

/* INPUT functions */

	int (*tstc) (void);		/* To test if a char is ready...	*/
	int (*getc) (void);		/* To get that char			*/

/* Other functions */

	void *priv;			/* Private extensions			*/
} device_t;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值