1 /*
2 ********************************************************************************************************************
3 * usb host driver
4 *
5 * (c) Copyright 2007-2010, javen.China
6 * All Rights Reserved
7 *
8 * File Name : usb_list.c
9 *
10 * Author : javen
11 *
12 * Version : 2.0
13 *
14 * Date : 2010.03.02
15 *
16 * Description : 预先分配256个list head给list使用
17 *
18 * History :
19 *
20 ********************************************************************************************************************
21 */
22
23 #include "usb_host_base_types.h"
24 #include "usb_os_platform.h"
25 #include "usb_list.h"
26
27 #include "Horse.h"
28
29
30 static void *list_memory_base = NULL;
31
32 #define MAX_LIST_BLOCK_NUM 256
33
34 /*
35 *******************************************************************************
36 * ListMemoryInit
37 *
38 * Description:
39 * 预先分配256个list head
40 *
41 * Parameters:
42 * void
43 *
44 * Return value:
45 * 0 : success
46 * !0 : fail
47 *
48 * note:
49 * void
50 *
51 *******************************************************************************
52 */
ListMemoryInit(void)53 __s32 ListMemoryInit(void)
54 {
55 list_memory_base = HorseHeadInit(sizeof(struct list_head), MAX_LIST_BLOCK_NUM);
56
57 if (list_memory_base == NULL)
58 {
59 DMSG_PANIC("ERR: HorseHeadInit failed\n");
60 return -1;
61 }
62
63 return 0;
64 }
65
66 /*
67 *******************************************************************************
68 * ListMemoryExit
69 *
70 * Description:
71 * 释放分配的256个list head
72 *
73 * Parameters:
74 * void
75 *
76 * Return value:
77 * 0 : success
78 * !0 : fail
79 *
80 * note:
81 * void
82 *
83 *******************************************************************************
84 */
ListMemoryExit(void)85 __s32 ListMemoryExit(void)
86 {
87 if (list_memory_base)
88 {
89 HorseHeadExit(list_memory_base);
90 list_memory_base = NULL;
91 }
92
93 return 0;
94 }
95
96 /*
97 *******************************************************************************
98 * ListMemoryMalloc
99 *
100 * Description:
101 * 从事先分配好的256个list head中取出没有使用的list head。
102 *
103 * Parameters:
104 * void
105 *
106 * Return value:
107 * 返回可用的list head的地址
108 *
109 * note:
110 * void
111 *
112 *******************************************************************************
113 */
ListMemoryMalloc(__u32 size,u8 * file_name,u32 line_nr)114 void *ListMemoryMalloc(__u32 size, u8 *file_name, u32 line_nr)
115 {
116 void *addr = NULL;
117 addr = HorseBlockMalloc(list_memory_base);
118
119 if (addr == NULL)
120 {
121 addr = USB_OS_MALLOC(size, file_name, line_nr);
122 DMSG_INFO("HorseBlockMalloc failed, must USB_OS_MALLOC, addr = %x\n", addr);
123 }
124
125 return addr;
126 }
127
128 /*
129 *******************************************************************************
130 * ListMemoryFree
131 *
132 * Description:
133 * 释放ListMemoryMalloc分配的list head
134 *
135 * Parameters:
136 * void
137 *
138 * Return value:
139 * void
140 *
141 * note:
142 * void
143 *
144 *******************************************************************************
145 */
ListMemoryFree(void * addr,u8 * file_name,u32 line_nr)146 void ListMemoryFree(void *addr, u8 *file_name, u32 line_nr)
147 {
148 if (addr)
149 {
150 if (HorseBlockFree(list_memory_base, addr) != 0)
151 {
152 DMSG_INFO("HorseBlockFree failed, must USB_OS_FREE, addr = %x\n", addr);
153 USB_OS_FREE(addr);
154 }
155 }
156 }
157
158
159
160
161
162
163
164