参考部分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;