1: uhs_status_t Usbh_Init(
usbh_regist_info init )
2: {
3: uhs_status_t retval =
UDI_OK;
4:
5:
6:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
7: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
8:
return UDI_STAT_INVALID_STATE;
9: }
10:
11:
if((g_usbh_status == USBHSTAT_STARTUP) || (g_usbh_status == USBHSTAT_IDLE)){
12: g_usbh_status = USBHSTAT_INITIAL;
13:
14: 15: 16:
17:
if( USBH_rsc_init() !=
UDI_OK ){
18: uhs_debug_print (DBG_ERR, ("USBH_rsc_init() Error"));
19:
return UDI_STAT_RESOURCE_UNAVAIL;
20: }
21:
22:
23:
#ifdef USBH_MEM_LEAK_CHK
24: 25: USBH_memleak_chk_init();
26:
#endif
27:
28:
29:
#ifdef USBH_OS_RES_COUNT
30: 31: USBH_os_res_cnt_init();
32:
#endif
33:
34:
35:
#ifdef USBH_OS_STACK_CHK
36:
37: USBH_init_stack_chk_all();
38:
#endif
39:
40: 41: g_assert_callback = init.assert_callback;
42:
43:
44:
45:
46: retval = kernel_initialize(
47: &g_apiwrap_info.mpl_osc,
48: USBH_APIWRAPP_MPL_SIZE,
49: USBH_NONCACHE_MEM_TOP_WRAPP
50: );
51:
if ( retval !=
UDI_OK ){
52: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL);
53: uhs_debug_print (DBG_ERR, ("Not Allocate Memory Pool"));
54:
return UDI_STAT_RESOURCE_UNAVAIL;
55: }
56:
57: 58: retval = Usbh_StatusMon_Init( init.logtype );
59:
if ( retval !=
UDI_OK ) {
60: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
61: retval = Usbh_StatusMon_Exit();
62:
if ( retval !=
UDI_OK ) {
63: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
64: }
65:
return UDI_STAT_RESOURCE_UNAVAIL;
66: }
67:
68: 69: retval = Usb_Host_MemoryPoolInit();
70:
if ( retval !=
UDI_OK ){
71: uhs_debug_print (DBG_ERR, ("Not Allocate Memory Pool"));
72: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
73: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
74:
if ( retval !=
UDI_OK ) {
75: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
76: }
77: retval = Usbh_StatusMon_Exit();
78:
if ( retval !=
UDI_OK ) {
79: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
80: }
81:
return UDI_STAT_RESOURCE_UNAVAIL;
82: }
83:
84:
85: retval = kernel_create_semaphore( &g_apiwrap_info.drvinfo_semid, 1, 1);
86:
if(retval !=
UDI_OK){
87: uhs_debug_print (DBG_ERR,(
88: "USB API Wrapper Create Driver List Semaphore error: ercd=%d",
89: retval));
90: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
91: retval = Usb_Host_MemoryPoolRelease();
92:
if ( retval !=
UDI_OK ) {
93: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
94: }
95: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
96:
if ( retval !=
UDI_OK ) {
97: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
98: }
99: retval = Usbh_StatusMon_Exit();
100:
if ( retval !=
UDI_OK ) {
101: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
102: }
103:
return UDI_STAT_RESOURCE_UNAVAIL;
104: }
105:
106:
107: lists_init_List( &g_apiwrap_info.usb_wrap_drvinfo_list );
108: lists_init_List( &g_apiwrap_info.tmp_drvlist );
109: g_apiwrap_info.unknowndev_driver.core_drvreginfo = NULL; 110:
111:
112: g_apiwrap_info.apiwrap_stat = USBWRAP_STAT_CNFSFT_INITCOMP;
113:
114: 115:
if( Usbh_susres_InitMainThread() !=
UDI_OK ){
116: uhs_debug_print (DBG_ERR, ("ERROR : SUSPEND/RESUME Thread create fail !!"));
117: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
118: }
119:
120:
121:
124:
125:
130:
131: 132: 133: retval = Usbh_InitClassDriver( init );
134:
if ( retval !=
UDI_OK ) {
135: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
136: Usbh_UnRegistAllAppCallback();
137: retval = kernel_delete_semaphore(&g_apiwrap_info.drvinfo_semid);
138:
if ( retval !=
UDI_OK ) {
139: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
140: }
141: retval = Usb_Host_MemoryPoolRelease();
142:
if ( retval !=
UDI_OK ) {
143: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
144: }
145: (
void)Usbh_StatusMon_Exit();
146: (
void)kernel_terminate(&g_apiwrap_info.mpl_osc); 147:
148:
return UDI_STAT_DATA_ERROR;
149: }
150:
151:
154:
155:
156:
157:
158: lists_init_List( &g_apiwrap_info.usb_wrap_devinfo_list );
159:
160: 161: 162: retval = kernel_acquisition_semaphore(
163: &(g_apiwrap_info.drvinfo_semid),
164: USB_HOST_SEMTIMEOUT,
165: in_interrupt());
166:
if ( retval !=
UDI_OK ) {
167: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
168: Usbh_UnRegistAllAppCallback();
169: retval = kernel_delete_semaphore(&g_apiwrap_info.drvinfo_semid);
170:
if ( retval !=
UDI_OK ) {
171: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
172: }
173: retval = Usb_Host_MemoryPoolRelease();
174:
if ( retval !=
UDI_OK ) {
175: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
176: }
177: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
178:
if ( retval !=
UDI_OK ) {
179: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
180: }
181: retval = Usbh_StatusMon_Exit();
182:
if ( retval !=
UDI_OK ) {
183: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
184: }
185:
return UDI_STAT_RESOURCE_UNAVAIL;
186: }
187:
188:
189: retval = Usb_Host_Init();
190:
if ( retval !=
UDI_OK ) {
191: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
192: kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
193: Usbh_UnRegistAllAppCallback();
194: retval = kernel_delete_semaphore(&g_apiwrap_info.drvinfo_semid);
195:
if ( retval !=
UDI_OK ) {
196: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
197: }
198: retval = Usb_Host_MemoryPoolRelease();
199:
if ( retval !=
UDI_OK ) {
200: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
201: }
202: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
203:
if ( retval !=
UDI_OK ) {
204: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
205: }
206: retval = Usbh_StatusMon_Exit();
207:
if ( retval !=
UDI_OK ) {
208: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
209: }
210:
return UDI_STAT_INVALID_STATE;
211: }
212:
213: 214: retval = Usb_Host_Controller_Init();
215:
if ( retval !=
UDI_OK ) {
216: CORE_REPORT_ERROR(
USBC_HOST_INIT_ERROR );
217: kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
218: Usbh_UnRegistAllAppCallback();
219: retval = kernel_delete_semaphore(&g_apiwrap_info.drvinfo_semid);
220:
if ( retval !=
UDI_OK ) {
221: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
222: }
223: retval = Usb_Host_MemoryPoolRelease();
224:
if ( retval !=
UDI_OK ) {
225: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
226: }
227: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
228:
if ( retval !=
UDI_OK ) {
229: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
230: }
231: retval = Usbh_StatusMon_Exit();
232:
if ( retval !=
UDI_OK ) {
233: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
234: }
235:
return UDI_STAT_INVALID_STATE;
236: }
237:
238:
239: g_apiwrap_info.apiwrap_stat = USBWRAP_STAT_USBD_INITCOMP;
240:
241:
242: g_apiwrap_info.bus_stat = USBWRAP_STAT_USBBUS_ACTIVE;
243:
244:
245: retval = kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
246:
if ( retval !=
UDI_OK ) {
247: CORE_REPORT_ERROR(
USBC_HOST_INIT_ERROR );
248: kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
249: Usbh_UnRegistAllAppCallback();
250: retval = kernel_delete_semaphore(&g_apiwrap_info.drvinfo_semid);
251:
if ( retval !=
UDI_OK ) {
252: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
253: }
254: retval = Usb_Host_MemoryPoolRelease();
255:
if ( retval !=
UDI_OK ) {
256: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
257: }
258: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
259:
if ( retval !=
UDI_OK ) {
260: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
261: }
262: retval = Usbh_StatusMon_Exit();
263:
if ( retval !=
UDI_OK ) {
264: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
265: }
266:
return UDI_STAT_INVALID_STATE;
267: }
268:
269: CORE_REPORT_MILESTONE(
USBC_INIT_COMP );
270:
271: g_usbh_status = USBHSTAT_RUN;
272: }
else{
273:
return UDI_STAT_INVALID_STATE;
274: }
275:
276:
return UDI_OK;
277:
278: }