1:
9:
10:
14:
15:
16:
17:
18:
19:
20:
#include <kernel.h>
21:
#include "uhs_config.h"
22:
#include "user_apiwrapper.h"
23:
#include "usb_hub.h"
24:
#include "usbh_errormon.h"
25:
#include "hcd_com.h"
26:
#include "usbh_resouce.h"
27:
#include "user_apiwrapper_susres.h"
28:
#include "uhs_evproc.h"
29:
30:
#ifdef USBH_MEM_LEAK_CHK
31:
#include "mem_leak_chk.h"
32:
#endif
33:
34:
#ifdef USBH_OS_RES_COUNT
35:
#include "os_res_count.h"
36:
#endif
37:
38:
#ifdef USBH_OS_STACK_CHK
39:
#include "usb_host_stack_chk.h"
40:
#endif
41:
42:
43:
44:
45:
46:
extern usb_host_status g_usbh_status;
47:
extern uhs_status_t Usb_Host_MemoryPoolInit(
void);
48:
extern uhs_status_t Usb_Host_MemoryPoolRelease(
void);
49:
extern uhs_status_t Usb_Host_Init(
void);
50:
extern uhs_status_t Usb_Host_Exit(
void);
51:
extern uhs_status_t Usb_Host_Controller_Init(
void);
52:
extern uhs_status_t Usb_Host_Controller_Exit(
void);
53:
extern uhs_status_t Usbh_Api_ClearHubPortPower(
struct usbd_usb_deviceinfo *usbhub,
const uhs_ubit8_t port_num );
54:
extern usb_wrap_info g_apiwrap_info;
55:
extern usb_common_callback_t g_assert_callback;
56:
#if (USB_HCD_SUPPORT && SUPPORT_HCDEHCI)
57:
extern struct usb_hub_info *ehci_rh;
58:
#endif
59:
60:
61:
62:
63:
64:
65: kernel_context_t g_suspend_reqans_mbox;
66:
67:
68: kernel_context_t g_response_reqans_mbox;
69:
70:
71:
72:
73:
74: uhs_ubit32_t Usbh_chk_apiwrap_alldev_request(
void );
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
105: uhs_status_t
Usbh_Init(
usbh_regist_info init )
106: {
107: uhs_status_t retval =
UDI_OK;
108:
109:
110:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
111: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
112:
return UDI_STAT_INVALID_STATE;
113: }
114:
115:
if((g_usbh_status == USBHSTAT_STARTUP) || (g_usbh_status == USBHSTAT_IDLE)){
116: g_usbh_status = USBHSTAT_INITIAL;
117:
118: 119: 120:
121:
if( USBH_rsc_init() !=
UDI_OK ){
122: uhs_debug_print (DBG_ERR, ("USBH_rsc_init() Error"));
123:
return UDI_STAT_RESOURCE_UNAVAIL;
124: }
125:
126:
127:
#ifdef USBH_MEM_LEAK_CHK
128: 129: USBH_memleak_chk_init();
130:
#endif
131:
132:
133:
#ifdef USBH_OS_RES_COUNT
134: 135: USBH_os_res_cnt_init();
136:
#endif
137:
138:
139:
#ifdef USBH_OS_STACK_CHK
140:
141: USBH_init_stack_chk_all();
142:
#endif
143:
144: 145: g_assert_callback = init.assert_callback;
146:
147:
148:
149:
150: retval = kernel_initialize(
151: &g_apiwrap_info.mpl_osc,
152: USBH_APIWRAPP_MPL_SIZE,
153: USBH_NONCACHE_MEM_TOP_WRAPP
154: );
155:
if ( retval !=
UDI_OK ){
156: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL);
157: uhs_debug_print (DBG_ERR, ("Not Allocate Memory Pool"));
158:
return UDI_STAT_RESOURCE_UNAVAIL;
159: }
160:
161: 162: retval = Usbh_StatusMon_Init( init.logtype );
163:
if ( retval !=
UDI_OK ) {
164: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
165: retval = Usbh_StatusMon_Exit();
166:
if ( retval !=
UDI_OK ) {
167: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
168: }
169:
return UDI_STAT_RESOURCE_UNAVAIL;
170: }
171:
172: 173: retval = Usb_Host_MemoryPoolInit();
174:
if ( retval !=
UDI_OK ){
175: uhs_debug_print (DBG_ERR, ("Not Allocate Memory Pool"));
176: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
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 = kernel_create_semaphore( &g_apiwrap_info.drvinfo_semid, 1, 1);
190:
if(retval !=
UDI_OK){
191: uhs_debug_print (DBG_ERR,(
192: "USB API Wrapper Create Driver List Semaphore error: ercd=%d",
193: retval));
194: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
195: retval = Usb_Host_MemoryPoolRelease();
196:
if ( retval !=
UDI_OK ) {
197: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
198: }
199: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
200:
if ( retval !=
UDI_OK ) {
201: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
202: }
203: retval = Usbh_StatusMon_Exit();
204:
if ( retval !=
UDI_OK ) {
205: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
206: }
207:
return UDI_STAT_RESOURCE_UNAVAIL;
208: }
209:
210:
211: lists_init_List( &g_apiwrap_info.usb_wrap_drvinfo_list );
212: lists_init_List( &g_apiwrap_info.tmp_drvlist );
213: g_apiwrap_info.unknowndev_driver.core_drvreginfo = NULL; 214:
215:
216: g_apiwrap_info.apiwrap_stat = USBWRAP_STAT_CNFSFT_INITCOMP;
217:
218: 219:
if( Usbh_susres_InitMainThread() !=
UDI_OK ){
220: uhs_debug_print (DBG_ERR, ("ERROR : SUSPEND/RESUME Thread create fail !!"));
221: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
222: }
223:
224:
225:
228:
229:
234:
235: 236: 237: retval = Usbh_InitClassDriver( init );
238:
if ( retval !=
UDI_OK ) {
239: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
240: Usbh_UnRegistAllAppCallback();
241: retval = kernel_delete_semaphore(&g_apiwrap_info.drvinfo_semid);
242:
if ( retval !=
UDI_OK ) {
243: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
244: }
245: retval = Usb_Host_MemoryPoolRelease();
246:
if ( retval !=
UDI_OK ) {
247: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
248: }
249: (
void)Usbh_StatusMon_Exit();
250: (
void)kernel_terminate(&g_apiwrap_info.mpl_osc); 251:
252:
return UDI_STAT_DATA_ERROR;
253: }
254:
255:
258:
259:
260:
261:
262: lists_init_List( &g_apiwrap_info.usb_wrap_devinfo_list );
263:
264: 265: 266: retval = kernel_acquisition_semaphore(
267: &(g_apiwrap_info.drvinfo_semid),
268: USB_HOST_SEMTIMEOUT,
269: in_interrupt());
270:
if ( retval !=
UDI_OK ) {
271: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
272: Usbh_UnRegistAllAppCallback();
273: retval = kernel_delete_semaphore(&g_apiwrap_info.drvinfo_semid);
274:
if ( retval !=
UDI_OK ) {
275: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
276: }
277: retval = Usb_Host_MemoryPoolRelease();
278:
if ( retval !=
UDI_OK ) {
279: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
280: }
281: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
282:
if ( retval !=
UDI_OK ) {
283: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
284: }
285: retval = Usbh_StatusMon_Exit();
286:
if ( retval !=
UDI_OK ) {
287: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
288: }
289:
return UDI_STAT_RESOURCE_UNAVAIL;
290: }
291:
292:
293: retval = Usb_Host_Init();
294:
if ( retval !=
UDI_OK ) {
295: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
296: kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
297: Usbh_UnRegistAllAppCallback();
298: retval = kernel_delete_semaphore(&g_apiwrap_info.drvinfo_semid);
299:
if ( retval !=
UDI_OK ) {
300: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
301: }
302: retval = Usb_Host_MemoryPoolRelease();
303:
if ( retval !=
UDI_OK ) {
304: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
305: }
306: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
307:
if ( retval !=
UDI_OK ) {
308: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
309: }
310: retval = Usbh_StatusMon_Exit();
311:
if ( retval !=
UDI_OK ) {
312: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
313: }
314:
return UDI_STAT_INVALID_STATE;
315: }
316:
317: 318: retval = Usb_Host_Controller_Init();
319:
if ( retval !=
UDI_OK ) {
320: CORE_REPORT_ERROR(
USBC_HOST_INIT_ERROR );
321: kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
322: Usbh_UnRegistAllAppCallback();
323: retval = kernel_delete_semaphore(&g_apiwrap_info.drvinfo_semid);
324:
if ( retval !=
UDI_OK ) {
325: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
326: }
327: retval = Usb_Host_MemoryPoolRelease();
328:
if ( retval !=
UDI_OK ) {
329: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
330: }
331: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
332:
if ( retval !=
UDI_OK ) {
333: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
334: }
335: retval = Usbh_StatusMon_Exit();
336:
if ( retval !=
UDI_OK ) {
337: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
338: }
339:
return UDI_STAT_INVALID_STATE;
340: }
341:
342:
343: g_apiwrap_info.apiwrap_stat = USBWRAP_STAT_USBD_INITCOMP;
344:
345:
346: g_apiwrap_info.bus_stat = USBWRAP_STAT_USBBUS_ACTIVE;
347:
348:
349: retval = kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
350:
if ( retval !=
UDI_OK ) {
351: CORE_REPORT_ERROR(
USBC_HOST_INIT_ERROR );
352: kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
353: Usbh_UnRegistAllAppCallback();
354: retval = kernel_delete_semaphore(&g_apiwrap_info.drvinfo_semid);
355:
if ( retval !=
UDI_OK ) {
356: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
357: }
358: retval = Usb_Host_MemoryPoolRelease();
359:
if ( retval !=
UDI_OK ) {
360: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
361: }
362: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
363:
if ( retval !=
UDI_OK ) {
364: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
365: }
366: retval = Usbh_StatusMon_Exit();
367:
if ( retval !=
UDI_OK ) {
368: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
369: }
370:
return UDI_STAT_INVALID_STATE;
371: }
372:
373: CORE_REPORT_MILESTONE(
USBC_INIT_COMP );
374:
375: g_usbh_status = USBHSTAT_RUN;
376: }
else{
377:
return UDI_STAT_INVALID_STATE;
378: }
379:
380:
return UDI_OK;
381:
382: }
383:
384:
#define USBH_EXIT_WAITNODEVICE_TIMEOUT (6000)
385:
397: uhs_status_t
Usbh_Exit(
void )
398: {
399: uhs_status_t retval =
UDI_OK;
400:
int i = 0;
401: uhs_ubit32_t timeout = 0;
402:
403:
404:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
405: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
406:
return UDI_STAT_INVALID_STATE;
407: }
408:
409:
if(g_usbh_status == USBHSTAT_RUN){
410: g_usbh_status = USBHSTAT_TERMINATE;
411:
412:
413:
for (i=1; i<=USB_HW_PORT_NUM; i++) {
414:
Usbh_Api_SetPortPower( ehci_rh->usbdev, i,
USBH_RH_PORT_POWER_OFF );
415: }
416:
417:
418:
419:
while ( !lists_ListEmpty(&g_apiwrap_info.usb_wrap_devinfo_list) ) {
420: kernel_wait(NULL, 10);
421: timeout++;
422:
if ( timeout > USBH_EXIT_WAITNODEVICE_TIMEOUT ) {
423: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
424:
break;
425: }
426: }
427: kernel_wait(NULL, 100); 428:
429:
430: g_apiwrap_info.bus_stat = USBWRAP_STAT_USBBUS_NON_ACTIVE;
431:
432: 433: Usbh_susres_ExitMainThread();
434:
435:
438:
439:
440: Usbh_UnRegistAllAppCallback();
441:
442:
443:
446:
447: 448: retval = Usb_Host_Controller_Exit();
449:
if ( retval !=
UDI_OK ) {
450:
451:
452: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
453:
return UDI_STAT_INVALID_STATE;
454: }
455:
456: 457: retval = Usb_Host_Exit();
458:
if ( retval !=
UDI_OK ) {
459: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
460:
return UDI_STAT_INVALID_STATE;
461: }
462:
463:
464: retval = kernel_delete_semaphore( &g_apiwrap_info.drvinfo_semid );
465:
if ( retval !=
UDI_OK ) {
466: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
467:
return UDI_STAT_INVALID_STATE;
468: }
469:
470:
471: retval = Usb_Host_MemoryPoolRelease();
472:
if ( retval !=
UDI_OK ) {
473: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
474:
return UDI_STAT_INVALID_STATE;
475: }
476:
477:
478: CORE_REPORT_MILESTONE(
USBC_EXIT_COMP );
479: kernel_wait( NULL , 100 );
480:
481: 482: retval = Usbh_StatusMon_Exit();
483:
if ( retval !=
UDI_OK ) {
484: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
485: }
486:
487:
488: retval = kernel_terminate(&g_apiwrap_info.mpl_osc);
489:
if ( retval !=
UDI_OK ) {
490: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
491:
return UDI_STAT_INVALID_STATE;
492: }
493:
494: 495:
if( USBH_rsc_exit() !=
UDI_OK ){
496: uhs_debug_print (DBG_ERR, ("USBH_rsc_exit() Error"));
497:
return UDI_STAT_RESOURCE_UNAVAIL;
498: }
499:
500:
501: g_apiwrap_info.apiwrap_stat = USBWRAP_STAT_INIT_NOT_START;
502:
503: g_usbh_status = USBHSTAT_IDLE;
504:
505:
506:
#ifdef USBH_OS_STACK_CHK
507:
508: USBH_stack_chk_stop();
509:
#endif
510:
511:
512:
#ifdef USBH_MEM_LEAK_CHK
513: 514: USBH_memleak_chk_exit();
515:
#endif
516:
517:
518: }
else{
519:
return UDI_STAT_INVALID_STATE;
520: }
521:
522:
return UDI_OK;
523: }
524:
525:
543: uhs_status_t
Usbh_Api_DriverRegister(
struct class_driver_reginfo * driver_info)
544: {
545: uhs_status_t retval =
UDI_OK;
546:
547:
548:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
549: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
550: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
551:
return UDI_STAT_INVALID_STATE;
552: }
553:
554:
if ( driver_info == NULL ) {
555: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER);
556:
return UDI_STAT_DATA_ERROR;
557: }
558:
559: 560: retval = kernel_acquisition_semaphore(
561: &(g_apiwrap_info.drvinfo_semid),
562: USB_HOST_SEMTIMEOUT,
563: in_interrupt());
564:
if ( retval !=
UDI_OK ) {
565:
566: 567:
568: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
569:
570:
return UDI_STAT_INVALID_STATE; 571: }
572:
573:
if ( g_apiwrap_info.apiwrap_stat != USBWRAP_STAT_USBD_INITCOMP ) {
574:
577:
578:
579: lists_addition_ListTail(
580: &g_apiwrap_info.tmp_drvlist,
581: driver_info );
582:
583: }
else {
584:
587: retval = Usbh_DriverRegister( driver_info );
588:
if ( retval !=
UDI_OK ) {
589: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
590:
591:
592: retval = kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
593:
if( retval !=
UDI_OK ) {
594: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
595: }
596:
597:
return UDI_STAT_INVALID_STATE;
598: }
599: }
600:
601:
602: retval = kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
603:
if( retval !=
UDI_OK ) {
604: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
605:
return UDI_STAT_INVALID_STATE;
606: }
607:
608:
return UDI_OK;
609: }
610:
611:
619:
void Usbh_Api_DriverUnRegister(
struct class_driver_reginfo * driver_info)
620: {
621: uhs_status_t retval =
UDI_OK;
622:
struct class_driver_reginfo * tmp_reginfo = NULL;
623:
624:
625:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
626: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
627: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
628:
return;
629: }
630:
631:
if ( driver_info == NULL ) {
632: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER);
633:
return;
634: }
635:
636: 637: retval = kernel_acquisition_semaphore(
638: &(g_apiwrap_info.drvinfo_semid),
639: USB_HOST_SEMTIMEOUT,
640: in_interrupt());
641:
if ( retval !=
UDI_OK ) {
642:
643: 644:
645: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
646:
647:
return; 648: }
649:
650:
if ( g_apiwrap_info.apiwrap_stat != USBWRAP_STAT_USBD_INITCOMP ) {
651:
654:
655: tmp_reginfo = (
struct class_driver_reginfo *)lists_get_FirstElement( &g_apiwrap_info.tmp_drvlist );
656:
while ( lists_get_RoopIsEnd(tmp_reginfo) == FALSE ) {
657:
if ( tmp_reginfo == driver_info ) {
658:
659: lists_delet_FromList( &g_apiwrap_info.tmp_drvlist, (
void*)tmp_reginfo );
660:
break;
661: }
662:
663:
664: tmp_reginfo = (
struct class_driver_reginfo *)lists_get_NextElement(&g_apiwrap_info.tmp_drvlist, tmp_reginfo);
665: }
666:
667: }
else {
668:
671: retval = Usbh_DriverUnRegister( driver_info );
672:
if ( retval !=
UDI_OK ) {
673: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
674: }
675: }
676:
677:
678: retval = kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
679:
if( retval !=
UDI_OK ) {
680: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
681: }
682:
683:
return;
684: }
685:
686:
698: uhs_status_t
Usbh_Api_OpenPipe(
struct usb_control_block* ucb)
699: {
700: uhs_status_t retval =
UDI_OK;
701:
702:
703:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
704: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
705: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
706:
return UDI_STAT_INVALID_STATE;
707: }
708:
709:
if ( ucb == NULL ) {
710: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
711:
return UDI_STAT_DATA_ERROR;
712: }
713:
714: retval = Usbc_Api_OpenPipe( ucb );
715:
if ( retval !=
UDI_OK ) {
716: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
717: }
718:
719:
return retval;
720: }
721:
722:
732: uhs_status_t
Usbh_Api_ClosePipe(
struct usb_control_block* ucb)
733: {
734: uhs_status_t retval =
UDI_OK;
735:
736:
737:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
738: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
739: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
740:
return UDI_STAT_INVALID_STATE;
741: }
742:
743:
if ( ucb == NULL ) {
744: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
745:
return UDI_STAT_DATA_ERROR;
746: }
747:
748: retval = Usbc_Api_ClosePipe( ucb );
749:
if ( retval !=
UDI_OK ) {
750: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
751: }
752:
753:
return retval;
754: }
755:
756:
773: uhs_status_t
Usbh_Api_ControlMsg(
struct usb_control_block* ucb)
774: {
775: uhs_status_t retval =
UDI_OK;
776:
777:
778:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
779: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
780: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
781:
return UDI_STAT_INVALID_STATE;
782: }
783:
784:
if (( ucb == NULL ) || ( ucb->complete_func == NULL ) || ( ucb->data_len > USB_REQ_MAX_LENGTH )) {
785: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
786:
return UDI_STAT_DATA_ERROR;
787: }
788:
789:
if ( Usbc_Api_GetPipeEpType( ucb->pipe ) !=
USB_TRANS_CONTROL ) {
790: CORE_REPORT_ERROR(
USBC_INVALID_PIPE );
791:
return UDI_STAT_DATA_ERROR;
792: }
793:
794:
801:
if( (ucb->setup_data->bmRequestType & USB_DEVICE_REEQUEST_TYPE_TYPE_MASK) == USB_DEVICE_REQUEST_TYPE_STANDARD_TYPE ){
802:
switch ( ucb->setup_data->bRequest ) {
803:
case USB_DEVICE_REQUEST_SET_CONFIGURATION:
804:
case USB_DEVICE_REQUEST_SET_INTERFACE:
805: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER);
806:
return UDI_STAT_DATA_ERROR;
807:
default:
808:
break;
809: }
810: }
811:
812: 813: retval = Usbh_SendRequest(
814: (
void*)ucb,
815: ucb->usbdev->usbdev_DevNum,
816: USBWRAP_MSG_REQUEST_ISSUE,
817: USBWRAP_SUBMSG_CTLREQ );
818:
if( retval !=
UDI_OK) {
819: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
820: }
821:
822:
return retval;
823: }
824:
825:
842: uhs_status_t
Usbh_Api_BulkMsg(
struct usb_control_block* ucb)
843: {
844: uhs_status_t retval =
UDI_OK;
845:
846:
847:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
848: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
849: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
850:
return UDI_STAT_INVALID_STATE;
851: }
852:
853:
if (( ucb == NULL ) || ( ucb->complete_func == NULL ) || ( ucb->data_len > USB_REQ_MAX_LENGTH )) {
854: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
855:
return UDI_STAT_DATA_ERROR;
856: }
857:
858:
if ( Usbc_Api_GetPipeEpType( ucb->pipe ) !=
USB_TRANS_BULK ) {
859: CORE_REPORT_ERROR(
USBC_INVALID_PIPE );
860:
return UDI_STAT_DATA_ERROR;
861: }
862:
863: 864: retval = Usbh_SendRequest(
865: (
void*)ucb,
866: ucb->usbdev->usbdev_DevNum,
867: USBWRAP_MSG_REQUEST_ISSUE,
868: USBWRAP_SUBMSG_BLKREQ );
869:
870:
if( retval !=
UDI_OK) {
871: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
872: }
873:
874:
return retval;
875: }
876:
877:
893: uhs_status_t
Usbh_Api_IntMsg(
struct usb_control_block* ucb)
894: {
895: uhs_status_t retval =
UDI_OK;
896:
897:
898:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
899: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
900: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
901:
return UDI_STAT_INVALID_STATE;
902: }
903:
904:
if (( ucb == NULL ) || ( ucb->complete_func == NULL ) || ( ucb->data_len > USB_REQ_MAX_LENGTH )) {
905: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
906:
return UDI_STAT_DATA_ERROR;
907: }
908:
909:
if ( Usbc_Api_GetPipeEpType( ucb->pipe ) !=
USB_TRANS_INTERRUPT ) {
910: CORE_REPORT_ERROR(
USBC_INVALID_PIPE );
911:
return UDI_STAT_DATA_ERROR;
912: }
913:
914: 915: retval = Usbh_SendRequest(
916: (
void*)ucb,
917: ucb->usbdev->usbdev_DevNum,
918: USBWRAP_MSG_REQUEST_ISSUE,
919: USBWRAP_SUBMSG_INTREQ );
920:
if( retval !=
UDI_OK) {
921: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
922: }
923:
924:
return retval;
925: }
926:
927:
952: uhs_status_t
Usbh_Api_SyncControlMsg(
953:
struct usb_control_block* ucb,
954:
const udi_ubit8_t bmRequestType,
955:
const udi_ubit8_t bRequest,
956:
const udi_ubit8_t wValue0,
957:
const udi_ubit8_t wValue1,
958:
const udi_ubit8_t wIndex0,
959:
const udi_ubit8_t wIndex1,
960:
void *buf,
961:
const uhs_ubit32_t size
962: )
963: {
964: uhs_status_t retval =
UDI_OK;
965: usb_device_request_t* devreq = NULL;
966:
967:
968:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
969: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
970: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
971:
return UDI_STAT_INVALID_STATE;
972: }
973:
974:
if ( ucb == NULL ) {
975: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
976:
return UDI_STAT_DATA_ERROR;
977: }
978:
979:
980: devreq = Usbh_AllocDevReqInfo();
981:
if ( devreq == NULL ) {
982: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
983:
return UDI_STAT_RESOURCE_UNAVAIL;
984: }
else {
985: devreq->bmRequestType = bmRequestType;
986: devreq->bRequest = bRequest;
987: devreq->wValue0 = wValue0;
988: devreq->wValue1 = wValue1;
989: devreq->wIndex0 = wIndex0;
990: devreq->wIndex1 = wIndex1;
991: devreq->wLength0 = size & 0xffU;
992: devreq->wLength1 = (size >> 8) & 0xffU;
993: }
994:
995: 996: Usbh_Setup_Ucb(
997: ucb,
998: buf,
999: size,
1000: devreq,
1001: NULL,
1002: ucb->time_out );
1003:
1004: 1005: retval = Usbh_ProcSyncRequest( ucb, USBWRAP_SUBMSG_CTLREQ );
1006:
if ( retval !=
UDI_OK ) {
1007: Usbh_FreeDevReqInfo( devreq );
1008: ucb->setup_data = NULL;
1009: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1010:
return retval;
1011: }
1012:
1013:
1014: Usbh_FreeDevReqInfo( devreq );
1015: ucb->setup_data = NULL;
1016:
1017:
return UDI_OK;
1018: }
1019:
1020:
1036: uhs_status_t
Usbh_Api_SyncBulkMsg(
struct usb_control_block* ucb )
1037: {
1038: uhs_status_t retval =
UDI_OK;
1039:
1040:
1041:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1042: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1043: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1044:
return UDI_STAT_INVALID_STATE;
1045: }
1046:
1047: 1048: retval = Usbh_ProcSyncRequest( ucb, USBWRAP_SUBMSG_BLKREQ );
1049:
if( retval !=
UDI_OK) {
1050: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1051: }
1052:
1053:
return retval;
1054: }
1055:
1056:
1071: uhs_status_t
Usbh_Api_CancelPipe(
struct usb_control_block* ucb)
1072: {
1073: uhs_status_t retval =
UDI_OK;
1074: usb_wrap_msgsubtype msgsubtype = USBWRAP_SUBMSG_NONE;
1075:
1076:
1077:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1078: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1079: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1080:
return UDI_STAT_INVALID_STATE;
1081: }
1082:
1083:
if ( ucb == NULL ) {
1084: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
1085:
return UDI_STAT_DATA_ERROR;
1086: }
1087:
1088:
switch ( Usbc_Api_GetPipeEpType( ucb->pipe ) ) {
1089:
case USB_TRANS_CONTROL:
1090: msgsubtype = USBWRAP_SUBMSG_CTLREQ_CANCEL;
1091:
break;
1092:
case USB_TRANS_BULK:
1093: msgsubtype = USBWRAP_SUBMSG_BLKREQ_CANCEL;
1094:
break;
1095:
case USB_TRANS_INTERRUPT:
1096: msgsubtype = USBWRAP_SUBMSG_INTREQ_CANCEL;
1097:
break;
1098:
case USB_TRANS_ISOCHRONOUS:
1099: msgsubtype = USBWRAP_SUBMSG_ISOREQ_CANCEL;
1100:
break;
1101:
default:
1102: CORE_REPORT_ERROR(
USBC_INVALID_PIPE );
1103:
return UDI_STAT_DATA_ERROR;
1104: }
1105:
1106: 1107: retval = Usbh_SendRequest(
1108: (
void*)ucb,
1109: ucb->usbdev->usbdev_DevNum,
1110: USBWRAP_MSG_REQUEST_CANCEL,
1111: msgsubtype );
1112:
1113:
if( retval !=
UDI_OK) {
1114: 1115: 1116:
1117: }
1118:
1119:
return retval;
1120: }
1121:
1122:
1142: uhs_status_t
Usbh_Api_GetDescriptor(
1143:
struct usb_control_block* ucb,
1144:
struct usbd_usb_deviceinfo* usbdev,
1145:
const uhs_ubit8_t type,
1146:
const uhs_ubit8_t index,
1147:
const uhs_ubit16_t wIndex,
1148:
void *buf,
1149:
const uhs_ubit32_t size
1150: )
1151: {
1152: uhs_status_t retval =
UDI_OK;
1153:
1154:
1155:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1156: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1157: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1158:
return UDI_STAT_INVALID_STATE;
1159: }
1160:
1161:
if (( ucb == NULL ) || ( usbdev == NULL ) || ( buf == NULL )) {
1162: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
1163:
return UDI_STAT_DATA_ERROR;
1164: }
1165:
1166: 1167:
Usbh_Api_FixupPipeInfo(
1168: &ucb->pipe,
1169: ucb->usbdev->usbdev_DevNum,
1170:
USB_DEFAULT_EP_NUM,
1171:
USB_PACKETID_IN,
1172:
USB_TRANS_CONTROL, 1173: ucb->usbdev->usbdev_EpMaxpktOut[
USB_DEFAULT_EP_NUM]
1174: );
1175:
1176: retval =
Usbh_Api_SyncControlMsg(
1177: ucb,
1178: USB_DEVICE_REQUEST_TYPE_DEVICE_TO_HOST |
1179: USB_DEVICE_REQUEST_TYPE_STANDARD_TYPE |
1180: USB_DEVICE_REQUEST_TYPE_DEVICE_RECIPIENT,
1181: USB_DEVICE_REQUEST_GET_DESCRIPTOR,
1182: index,
1183: type,
1184: wIndex & 0xffU,
1185: wIndex >> 8,
1186: buf,
1187: size );
1188:
1189:
if( retval !=
UDI_OK) {
1190: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1191: }
1192:
1193:
return retval;
1194: }
1195:
1196:
1216: uhs_status_t
Usbh_Api_SetDescriptor(
1217:
struct usb_control_block* ucb,
1218:
struct usbd_usb_deviceinfo* usbdev,
1219:
const uhs_ubit8_t type,
1220:
const uhs_ubit8_t index,
1221:
const uhs_ubit16_t wIndex,
1222:
void *buf,
1223:
const uhs_ubit32_t size
1224: )
1225: {
1226: uhs_status_t retval =
UDI_OK;
1227:
1228:
1229:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1230: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1231: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1232:
return UDI_STAT_INVALID_STATE;
1233: }
1234:
1235:
if (( ucb == NULL ) || ( usbdev == NULL ) || ( buf == NULL )) {
1236: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
1237:
return UDI_STAT_DATA_ERROR;
1238: }
1239:
1240: 1241:
Usbh_Api_FixupPipeInfo(
1242: &ucb->pipe,
1243: ucb->usbdev->usbdev_DevNum,
1244:
USB_DEFAULT_EP_NUM,
1245:
USB_PACKETID_OUT,
1246:
USB_TRANS_CONTROL, 1247: ucb->usbdev->usbdev_EpMaxpktOut[
USB_DEFAULT_EP_NUM]
1248: );
1249:
1250: retval =
Usbh_Api_SyncControlMsg(
1251: ucb,
1252: USB_DEVICE_REQUEST_TYPE_HOST_TO_DEVICE |
1253: USB_DEVICE_REQUEST_TYPE_STANDARD_TYPE |
1254: USB_DEVICE_REQUEST_TYPE_DEVICE_RECIPIENT,
1255: USB_DEVICE_REQUEST_SET_DESCRIPTOR,
1256: index,
1257: type,
1258: wIndex & 0xffU,
1259: wIndex >> 8,
1260: buf,
1261: size );
1262:
1263:
if( retval !=
UDI_OK) {
1264: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1265: }
1266:
1267:
return retval;
1268: }
1269:
1270:
1289: uhs_status_t
Usbh_Api_ClearFeature(
1290:
struct usb_control_block* ucb,
1291:
struct usbd_usb_deviceinfo* usbdev,
1292:
const uhs_ubit8_t bmRequest,
1293:
const uhs_ubit16_t feature_select,
1294:
const uhs_ubit16_t wIndex
1295: )
1296: {
1297: uhs_status_t retval =
UDI_OK;
1298:
1299:
1300:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1301: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1302: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1303:
return UDI_STAT_INVALID_STATE;
1304: }
1305:
1306:
if (( ucb == NULL ) || ( usbdev == NULL )) {
1307: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
1308:
return UDI_STAT_DATA_ERROR;
1309: }
1310:
1311: 1312:
Usbh_Api_FixupPipeInfo(
1313: &ucb->pipe,
1314: ucb->usbdev->usbdev_DevNum,
1315:
USB_DEFAULT_EP_NUM,
1316:
USB_PACKETID_OUT,
1317:
USB_TRANS_CONTROL, 1318: ucb->usbdev->usbdev_EpMaxpktOut[
USB_DEFAULT_EP_NUM]
1319: );
1320:
1321: retval =
Usbh_Api_SyncControlMsg(
1322: ucb,
1323: bmRequest,
1324: USB_DEVICE_REQUEST_CLEAR_FEATURE,
1325: feature_select & 0xffU,
1326: feature_select >> 8,
1327: wIndex & 0xffU,
1328: wIndex >> 8,
1329: NULL,
1330: 0 );
1331:
1332:
if( retval !=
UDI_OK) {
1333: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1334: }
1335:
1336:
return retval;
1337: }
1338:
1339:
1358: uhs_status_t
Usbh_Api_SetFeature(
1359:
struct usb_control_block* ucb,
1360:
struct usbd_usb_deviceinfo* usbdev,
1361:
const uhs_ubit8_t bmRequest,
1362:
const uhs_ubit16_t feature_select,
1363:
const uhs_ubit16_t wIndex
1364: )
1365: {
1366: uhs_status_t retval =
UDI_OK;
1367:
1368:
1369:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1370: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1371: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1372:
return UDI_STAT_INVALID_STATE;
1373: }
1374:
1375:
if (( ucb == NULL ) || ( usbdev == NULL )) {
1376: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
1377:
return UDI_STAT_DATA_ERROR;
1378: }
1379:
1380: 1381:
Usbh_Api_FixupPipeInfo(
1382: &ucb->pipe,
1383: ucb->usbdev->usbdev_DevNum,
1384:
USB_DEFAULT_EP_NUM,
1385:
USB_PACKETID_OUT,
1386:
USB_TRANS_CONTROL, 1387: ucb->usbdev->usbdev_EpMaxpktOut[
USB_DEFAULT_EP_NUM]
1388: );
1389:
1390: retval =
Usbh_Api_SyncControlMsg(
1391: ucb,
1392: bmRequest,
1393: USB_DEVICE_REQUEST_SET_FEATURE,
1394: feature_select & 0xffU,
1395: feature_select >> 8,
1396: wIndex & 0xffU,
1397: wIndex >> 8,
1398: NULL,
1399: 0 );
1400:
1401:
if( retval !=
UDI_OK) {
1402: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1403: }
1404:
1405:
return retval;
1406: }
1407:
1408:
1430: uhs_status_t
Usbh_Api_GetStatus(
1431:
struct usb_control_block* ucb,
1432:
struct usbd_usb_deviceinfo* usbdev,
1433:
const uhs_ubit8_t bmRequest,
1434:
const uhs_ubit16_t wIndex,
1435:
void *buf
1436: )
1437: {
1438: uhs_status_t retval =
UDI_OK;
1439:
1440:
1441:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1442: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1443: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1444:
return UDI_STAT_INVALID_STATE;
1445: }
1446:
1447:
if (( ucb == NULL ) || ( usbdev == NULL ) || ( buf == NULL )) {
1448: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
1449:
return UDI_STAT_DATA_ERROR;
1450: }
1451:
1452: 1453:
Usbh_Api_FixupPipeInfo(
1454: &ucb->pipe,
1455: ucb->usbdev->usbdev_DevNum,
1456:
USB_DEFAULT_EP_NUM,
1457:
USB_PACKETID_IN,
1458:
USB_TRANS_CONTROL, 1459: ucb->usbdev->usbdev_EpMaxpktOut[
USB_DEFAULT_EP_NUM]
1460: );
1461:
1462: retval =
Usbh_Api_SyncControlMsg(
1463: ucb,
1464: bmRequest,
1465: USB_DEVICE_REQUEST_GET_STATUS,
1466: 0,
1467: 0,
1468: wIndex & 0xffU,
1469: wIndex >> 8,
1470: buf,
1471: 2 );
1472:
1473:
if( retval !=
UDI_OK) {
1474: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1475: }
1476:
1477:
return retval;
1478: }
1479:
1480:
1495: uhs_status_t
Usbh_Api_SetAddress(
1496:
struct usb_control_block* ucb,
1497:
struct usbd_usb_deviceinfo* usbdev,
1498:
const uhs_ubit16_t address
1499: )
1500: {
1501: uhs_status_t retval =
UDI_OK;
1502:
1503:
1504:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1505: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1506: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1507:
return UDI_STAT_INVALID_STATE;
1508: }
1509:
1510:
if (( ucb == NULL ) || ( usbdev == NULL )) {
1511: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
1512:
return UDI_STAT_DATA_ERROR;
1513: }
1514:
1515: 1516:
Usbh_Api_FixupPipeInfo(
1517: &ucb->pipe,
1518: ucb->usbdev->usbdev_DevNum,
1519:
USB_DEFAULT_EP_NUM,
1520:
USB_PACKETID_OUT,
1521:
USB_TRANS_CONTROL, 1522: ucb->usbdev->usbdev_EpMaxpktOut[
USB_DEFAULT_EP_NUM]
1523: );
1524:
1525: retval =
Usbh_Api_SyncControlMsg(
1526: ucb,
1527: USB_DEVICE_REQUEST_TYPE_HOST_TO_DEVICE |
1528: USB_DEVICE_REQUEST_TYPE_STANDARD_TYPE |
1529: USB_DEVICE_REQUEST_TYPE_DEVICE_RECIPIENT,
1530: USB_DEVICE_REQUEST_SET_ADDRESS,
1531: address & 0xffU,
1532: address >> 8,
1533: 0,
1534: 0,
1535: NULL,
1536: 0 );
1537:
1538:
if( retval !=
UDI_OK) {
1539: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1540: }
1541:
1542:
return retval;
1543: }
1544:
1545:
1561: uhs_status_t
Usbh_Api_GetConfiguration(
1562:
struct usb_control_block* ucb,
1563:
struct usbd_usb_deviceinfo* usbdev,
1564:
void *buf
1565: )
1566: {
1567: uhs_status_t retval =
UDI_OK;
1568:
1569:
1570:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1571: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1572: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1573:
return UDI_STAT_INVALID_STATE;
1574: }
1575:
1576:
if (( ucb == NULL ) || ( usbdev == NULL ) || ( buf == NULL )) {
1577: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
1578:
return UDI_STAT_DATA_ERROR;
1579: }
1580:
1581: 1582:
Usbh_Api_FixupPipeInfo(
1583: &ucb->pipe,
1584: ucb->usbdev->usbdev_DevNum,
1585:
USB_DEFAULT_EP_NUM,
1586:
USB_PACKETID_IN,
1587:
USB_TRANS_CONTROL, 1588: ucb->usbdev->usbdev_EpMaxpktOut[
USB_DEFAULT_EP_NUM]
1589: );
1590:
1591: retval =
Usbh_Api_SyncControlMsg(
1592: ucb,
1593: USB_DEVICE_REQUEST_TYPE_DEVICE_TO_HOST |
1594: USB_DEVICE_REQUEST_TYPE_STANDARD_TYPE |
1595: USB_DEVICE_REQUEST_TYPE_DEVICE_RECIPIENT,
1596: USB_DEVICE_REQUEST_GET_CONFIGURATION,
1597: 0,
1598: 0,
1599: 0,
1600: 0,
1601: buf,
1602: 1 );
1603:
1604:
if( retval !=
UDI_OK) {
1605: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1606: }
1607:
1608:
return retval;
1609: }
1610:
1611:
1626: uhs_status_t
Usbh_Api_SetConfiguration(
1627:
struct usb_control_block* ucb,
1628:
struct usbd_usb_deviceinfo* usbdev,
1629:
const uhs_ubit16_t config_num
1630: )
1631: {
1632: uhs_status_t retval =
UDI_OK;
1633:
1634:
1635:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1636: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1637: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1638:
return UDI_STAT_INVALID_STATE;
1639: }
1640:
1641:
if (( ucb == NULL ) || ( usbdev == NULL )) {
1642: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
1643:
return UDI_STAT_DATA_ERROR;
1644: }
1645:
1646: 1647:
Usbh_Api_FixupPipeInfo(
1648: &ucb->pipe,
1649: ucb->usbdev->usbdev_DevNum,
1650:
USB_DEFAULT_EP_NUM,
1651:
USB_PACKETID_OUT,
1652:
USB_TRANS_CONTROL, 1653: ucb->usbdev->usbdev_EpMaxpktOut[
USB_DEFAULT_EP_NUM]
1654: );
1655:
1656: retval =
Usbh_Api_SyncControlMsg(
1657: ucb,
1658: USB_DEVICE_REQUEST_TYPE_HOST_TO_DEVICE |
1659: USB_DEVICE_REQUEST_TYPE_STANDARD_TYPE |
1660: USB_DEVICE_REQUEST_TYPE_DEVICE_RECIPIENT,
1661: USB_DEVICE_REQUEST_SET_CONFIGURATION,
1662: config_num & 0xffU,
1663: config_num >> 8,
1664: 0,
1665: 0,
1666: NULL,
1667: 0 );
1668:
1669:
if( retval !=
UDI_OK) {
1670: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1671: }
1672:
1673:
return retval;
1674: }
1675:
1676:
1693: uhs_status_t
Usbh_Api_GetInterface(
1694:
struct usb_control_block* ucb,
1695:
struct usbd_usb_deviceinfo* usbdev,
1696:
const uhs_ubit16_t wIndex,
1697:
void *buf
1698: )
1699: {
1700: uhs_status_t retval =
UDI_OK;
1701:
1702:
1703:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1704: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1705: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1706:
return UDI_STAT_INVALID_STATE;
1707: }
1708:
1709:
if (( ucb == NULL ) || ( usbdev == NULL ) || ( buf == NULL )) {
1710: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
1711:
return UDI_STAT_DATA_ERROR;
1712: }
1713:
1714: 1715:
Usbh_Api_FixupPipeInfo(
1716: &ucb->pipe,
1717: ucb->usbdev->usbdev_DevNum,
1718:
USB_DEFAULT_EP_NUM,
1719:
USB_PACKETID_IN,
1720:
USB_TRANS_CONTROL, 1721: ucb->usbdev->usbdev_EpMaxpktOut[
USB_DEFAULT_EP_NUM]
1722: );
1723:
1724: retval =
Usbh_Api_SyncControlMsg(
1725: ucb,
1726: USB_DEVICE_REQUEST_TYPE_DEVICE_TO_HOST |
1727: USB_DEVICE_REQUEST_TYPE_STANDARD_TYPE |
1728: USB_DEVICE_REQUEST_TYPE_INTERFACE_RECIPIENT,
1729: USB_DEVICE_REQUEST_GET_INTERFACE,
1730: 0,
1731: 0,
1732: wIndex & 0xffU,
1733: wIndex >> 8,
1734: buf,
1735: 1 );
1736:
1737:
if( retval !=
UDI_OK) {
1738: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1739: }
1740:
1741:
return retval;
1742: }
1743:
1744:
1760: uhs_status_t
Usbh_Api_SetInterface(
1761:
struct usb_control_block* ucb,
1762:
struct usbd_usb_deviceinfo* usbdev,
1763:
const uhs_ubit16_t intf_num,
1764:
const uhs_ubit16_t alt_num
1765: )
1766: {
1767: uhs_status_t retval =
UDI_OK;
1768:
1769:
1770:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
1771: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
1772: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
1773:
return UDI_STAT_INVALID_STATE;
1774: }
1775:
1776:
if (( ucb == NULL ) || ( usbdev == NULL )) {
1777: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
1778:
return UDI_STAT_DATA_ERROR;
1779: }
1780:
1781: 1782:
Usbh_Api_FixupPipeInfo(
1783: &ucb->pipe,
1784: ucb->usbdev->usbdev_DevNum,
1785:
USB_DEFAULT_EP_NUM,
1786:
USB_PACKETID_OUT,
1787:
USB_TRANS_CONTROL, 1788: ucb->usbdev->usbdev_EpMaxpktOut[
USB_DEFAULT_EP_NUM]
1789: );
1790:
1791: retval =
Usbh_Api_SyncControlMsg(
1792: ucb,
1793: USB_DEVICE_REQUEST_TYPE_HOST_TO_DEVICE |
1794: USB_DEVICE_REQUEST_TYPE_STANDARD_TYPE |
1795: USB_DEVICE_REQUEST_TYPE_INTERFACE_RECIPIENT,
1796: USB_DEVICE_REQUEST_SET_INTERFACE,
1797: alt_num & 0xffU,
1798: alt_num >> 8,
1799: intf_num & 0xffU,
1800: intf_num >> 8,
1801: NULL,
1802: 0 );
1803:
1804:
if( retval !=
UDI_OK) {
1805: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
1806: }
1807:
1808:
return retval;
1809: }
1810:
1811:
1822: uhs_status_t
Usbh_Api_AllocUsbCtrlBlock(
struct usb_control_block ** ucb)
1823: {
1824:
1825:
return Usbc_Api_AllocUsbCtrlBlock( ucb );
1826: }
1827:
1828:
1838: uhs_status_t
Usbh_Api_FreeUsbCtrlBlock(
struct usb_control_block * ucb)
1839: {
1840:
1841:
return Usbc_Api_FreeUsbCtrlBlock( ucb );
1842: }
1843:
1844:
1858:
void Usbh_Api_FixupUsbCtrlBlock(
1859:
struct usb_control_block * ucb,
1860:
struct usbd_usb_deviceinfo* usbdev,
1861:
const uhs_ubit32_t pipe,
1862: usb_device_request_t *setup_data,
1863:
void *data_buf,
1864:
const uhs_ubit32_t data_len,
1865:
const uhs_ubit8_t interval,
1866:
usb_common_callback_t complete_func,
1867:
void *context )
1868: {
1869:
1870: Usbc_Api_FixupUsbCtrlBlock( ucb, usbdev, pipe, setup_data, data_buf, data_len, interval, complete_func, context );
1871: }
1872:
1873:
1885:
void Usbh_Api_FixupPipeInfo( uhs_ubit32_t *pipe,
const uhs_ubit8_t usb_addr,
const uhs_ubit8_t ep_num,
const uhs_ubit8_t packet_id,
const uhs_ubit8_t ep_type,
const uhs_ubit32_t maxpkt_size)
1886: {
1887:
1888: Usbc_Api_FixupPipeInfo( pipe, usb_addr, ep_num, packet_id, ep_type, maxpkt_size );
1889: }
1890:
1891:
1900: uhs_boolean_t
Usbh_Api_PipeIsOpened(
struct usb_control_block* ucb)
1901: {
1902:
1903:
return Usbc_Api_PipeIsOpened( ucb );
1904: }
1905:
1906:
1913: uhs_ubit32_t
Usbh_Api_GetPipeAddr(
const uhs_ubit32_t pipe )
1914: {
1915:
1916:
return Usbc_Api_GetPipeAddr( pipe );
1917: }
1918:
1919:
1926: uhs_ubit32_t
Usbh_Api_GetPipeEpNum(
const uhs_ubit32_t pipe )
1927: {
1928:
1929:
return Usbc_Api_GetPipeEpNum( pipe );
1930: }
1931:
1932:
1939: uhs_ubit32_t
Usbh_Api_GetPipePID(
const uhs_ubit32_t pipe )
1940: {
1941:
1942:
return Usbc_Api_GetPipePID( pipe );
1943: }
1944:
1945:
1953: uhs_boolean_t
Usbh_Api_GetPipeDirIn(
const uhs_ubit32_t pipe )
1954: {
1955:
1956:
return Usbc_Api_GetPipeDirIn( pipe );
1957: }
1958:
1959:
1968: uhs_ubit32_t
Usbh_Api_GetPipeEpType(
const uhs_ubit32_t pipe )
1969: {
1970:
1971:
return Usbc_Api_GetPipeEpType( pipe );
1972: }
1973:
1974:
1981: uhs_ubit32_t
Usbh_Api_GetPipeMaxPktSize(
const uhs_ubit32_t pipe )
1982: {
1983:
1984:
return Usbc_Api_GetPipeMaxPktSize( pipe );
1985: }
1986:
1987:
1996: uhs_ubit8_t
Usbh_Api_GetPortPower(
struct usbd_usb_deviceinfo *usbhub,
const uhs_ubit8_t port_num )
1997: {
1998: uhs_status_t retval =
UDI_OK;
1999:
struct usbh_port_status port_status;
2000: uhs_ubit8_t port_power = 0;
2001:
struct usb_hub_info *hub_info = NULL;
2002:
2003: port_status.port_status = 0;
2004: port_status.port_change_status = 0;
2005:
2006:
if ( ehci_rh->usbdev == usbhub ) {
2007: hub_info = ehci_rh;
2008: }
else {
2009: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
2010:
return USBH_RH_PORT_POWER_OFF;
2011: }
2012:
2013: retval =
Usb_HubApi_GetStatus( hub_info, &port_status, port_num );
2014:
if ( retval !=
UDI_OK ) {
2015: CORE_REPORT_WARNING(
USBC_ILLEGAL_ERROR);
2016:
return USBH_RH_PORT_POWER_OFF;
2017: }
2018:
2019:
if ( ( port_status.port_status & PS_PORT_POWER ) == PS_PORT_POWER ) {
2020: port_power =
USBH_RH_PORT_POWER_ON;
2021: }
else {
2022: port_power =
USBH_RH_PORT_POWER_OFF;
2023: }
2024:
2025:
return port_power;
2026: }
2027:
2028:
2037:
void Usbh_Api_SetPortPower(
struct usbd_usb_deviceinfo *usbhub,
const uhs_ubit8_t port_num,
const uhs_ubit8_t stat )
2038: {
2039: uhs_ubit8_t port_power = 0;
2040:
2041:
2042:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
2043: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
2044: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2045:
return;
2046: }
2047:
2048:
if (( usbhub == NULL ) || ( port_num > USB_HW_PORT_NUM )) {
2049: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
2050:
return;
2051: }
2052:
2053: port_power =
Usbh_Api_GetPortPower( usbhub, port_num );
2054:
2055:
if ( port_power == stat ) {
2056: 2057:
return;
2058: }
2059:
2060:
switch ( stat ) {
2061:
case USBH_RH_PORT_POWER_ON:
2062: Usbh_Rh_Set_PortPower( port_num );
2063:
break;
2064:
case USBH_RH_PORT_POWER_OFF:
2065: Usbh_Rh_Clear_PortPower( port_num );
2066:
break;
2067:
default:
2068:
break;
2069: }
2070:
2071: }
2072:
2073:
2084:
struct usbd_usb_deviceinfo *
Usbh_Api_EnumRootHub(
struct usbd_usb_deviceinfo * pRootHub )
2085: {
2086:
struct usbd_usb_deviceinfo * rh = NULL;
2087:
2088:
#ifdef SUPPORT_HCDEHCI
2089:
2090:
2091:
2092:
if (( pRootHub == NULL ) && ( ehci_rh != NULL )) {
2093: rh = (
struct usbd_usb_deviceinfo *)ehci_rh->usbdev;
2094: }
2095:
else {
2096: rh = NULL;
2097: }
2098:
#endif
2099:
2100:
return rh;
2101: }
2102:
2103:
2117:
struct usbd_usb_deviceinfo *
Usbh_Api_EnumDevice(
struct usbd_usb_deviceinfo * pParent,
struct usbd_usb_deviceinfo * pChild )
2118: {
2119:
int i = 0;
2120:
struct usbd_usb_deviceinfo * dev = NULL;
2121:
2122:
if ( pParent == NULL) {
2123: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
2124:
return NULL;
2125: }
2126:
2127:
if ( pChild == NULL ) {
2128:
2129:
for ( i=1; i<USB_ENUMDEV_MAXDEV; i++ ) {
2130:
if ( pParent->usbdev_LowerHub[i] != NULL ) {
2131: dev = pParent->usbdev_LowerHub[i];
2132:
break;
2133: }
2134: }
2135: }
else {
2136: 2137:
for ( i=1; i<USB_ENUMDEV_MAXDEV; i++ ) {
2138:
if ( pParent->usbdev_LowerHub[i] == pChild ) {
2139:
break;
2140: }
2141: }
2142:
if ( i >= USB_ENUMDEV_MAXDEV ) {
2143: 2144: dev = NULL;
2145: }
else {
2146: 2147:
for ( i++; i<USB_ENUMDEV_MAXDEV; i++ ) {
2148:
if ( pParent->usbdev_LowerHub[i] != NULL ) {
2149: dev = pParent->usbdev_LowerHub[i];
2150: }
2151: }
2152: }
2153: }
2154:
2155:
return dev;
2156: }
2157:
2158:
#define USB_GETDEVTYPE_MAXLOOP (255)
2159:
2172: uhs_ubit8_t
Usbh_Api_GetDeviceType(
struct usbd_usb_deviceinfo * pDev )
2173: {
2174: uhs_ubit8_t devtype;
2175:
2176:
if (( pDev == NULL ) || ( pDev->usbdev_DevDescriptor == NULL )) {
2177: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
2178:
return 0x00;
2179: }
2180:
2181:
if ( pDev->usbdev_DevDescriptor->bDeviceClass == USBDI_BASECLASS_DEVICE ) {
2182:
2183:
2184: 2185: devtype = pDev->Drv_ConfDescriptor->interfaces->act_alt->intf_desc->bInterfaceClass;
2186: }
else {
2187: devtype = pDev->usbdev_DevDescriptor->bDeviceClass;
2188: }
2189:
2190:
return devtype;
2191: }
2192:
2193:
2203: uhs_boolean_t
Usbh_Api_GetVidPid(
struct usbd_usb_deviceinfo * pDev, udi_ubit16_t *pVid, udi_ubit16_t *pPid )
2204: {
2205:
if (( pDev == NULL ) || ( pVid == NULL ) || ( pPid == NULL ) || ( pDev->usbdev_DevDescriptor == NULL )) {
2206: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER);
2207:
return FALSE;
2208: }
2209:
2210: *pVid = (((udi_ubit16_t)pDev->usbdev_DevDescriptor->idVendor1) << 8) + pDev->usbdev_DevDescriptor->idVendor0;
2211: *pPid = (((udi_ubit16_t)pDev->usbdev_DevDescriptor->idProduct1) << 8) + pDev->usbdev_DevDescriptor->idProduct0;
2212:
2213:
return TRUE;
2214: }
2215:
2216:
2235: uhs_boolean_t
Usbh_Api_GetSerial(
struct usbd_usb_deviceinfo * pDev, udi_ubit8_t *pSerial, udi_ubit8_t bufsize )
2236: {
2237: udi_ubit8_t size = 0;
2238:
2239:
if (( pDev == NULL ) || ( pSerial == NULL ) || ( bufsize == 0 ) || ( pDev->usbdev_StringSerial == NULL )) {
2240: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
2241:
return FALSE;
2242: }
2243:
2244:
if ( bufsize < pDev->usbdev_StringSerial[0] ) {
2245: size = bufsize;
2246: }
else {
2247: size = pDev->usbdev_StringSerial[0];
2248: }
2249:
2250: memcpy( pSerial, pDev->usbdev_StringSerial, size );
2251:
2252:
return TRUE;
2253: }
2254:
2255:
2265: uhs_status_t
Usbh_Api_RegistAppCallback(
usbh_regist_info init )
2266: {
2267:
int i = 0;
2268: uhs_status_t retval =
UDI_OK;
2269:
app_callback_info * app_cb = NULL;
2270:
2271:
2272:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
2273: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
2274: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2275:
return UDI_STAT_INVALID_STATE;
2276: }
2277:
2278:
if(g_usbh_status == USBHSTAT_RUN){
2279:
2280: Usbh_RegistGetStatusCallback( init.status_notify_callback );
2281:
2282:
2283: Usbh_RegistOverCurrentCallback( init.overload_callback );
2284:
2285:
2286: Usbh_RegistSplitErrNotifyCallback( init.split_err_notify_callback );
2287:
2288:
if ( init.app_callback == NULL ) {
2289:
return UDI_OK;
2290: }
else {
2291: app_cb = init.app_callback;
2292: }
2293:
2294: 2295: 2296: retval = Usbh_RegistAppCallback( &app_cb[i] );
2297:
if ( retval !=
UDI_OK ) {
2298: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2299: }
2300: }
else{
2301:
return UDI_STAT_INVALID_STATE;
2302: }
2303:
2304:
return retval;
2305: }
2306:
2307:
2318: uhs_status_t
Usbh_Api_GetVersion(uhs_ubit8_t* pu8MajorVersion,
2319: uhs_ubit8_t* pu8MinorVersion)
2320: {
2321:
2322:
2323:
2324:
if( (pu8MajorVersion == NULL) ||
2325: (pu8MinorVersion == NULL) ) {
2326: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
2327:
return(
UDI_STAT_DATA_ERROR );
2328: }
2329:
2330:
2331:
2332:
2333:
if(g_apiwrap_info.apiwrap_stat != USBWRAP_STAT_USBD_INITCOMP){
2334: 2335:
return(
UDI_STAT_INVALID_STATE );
2336: }
2337:
2338:
2339: *pu8MajorVersion = USBWRAP_MAJOR_VERSION;
2340:
2341: *pu8MinorVersion = USBWRAP_MINOR_VERSION;
2342:
2343:
return(
UDI_OK );
2344: }
2345:
2346:
2364: uhs_status_t
Usbh_Api_ResetTT(
struct usbd_usb_deviceinfo *usbhub,
const uhs_ubit16_t tt_port )
2365: {
2366: uhs_status_t retval =
UDI_OK;
2367:
2368:
2369:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
2370: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
2371: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2372:
return UDI_STAT_INVALID_STATE;
2373: }
2374:
2375:
if( (usbhub == NULL) || (tt_port == 0) || (tt_port > HUB_MAX_PORT_NUM) ){
2376: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
2377:
return(
UDI_STAT_DATA_ERROR );
2378: }
2379:
else{
2380:
2381:
2382:
2383:
2384: retval =
Usb_HubApi_RESET_TT( usbhub->context , tt_port );
2385: }
2386:
return retval;
2387: }
2388:
2389:
2406: uhs_status_t
Usbh_Api_ClearTTBuffer(
struct usbd_usb_deviceinfo *usbhub,
const uhs_ubit16_t tt_port ,
struct usbd_usb_spliterrinfo *split_err_info)
2407: {
2408: uhs_status_t retval =
UDI_OK;
2409:
2410:
2411:
if( Usbh_susres_get_state() != USBH_SUSRES_STS_IDLE ){
2412: uhs_debug_print (DBG_ERR, ("ERROR : Don't Call Current State!!"));
2413: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2414:
return UDI_STAT_INVALID_STATE;
2415: }
2416:
2417:
if( (usbhub == NULL) || (tt_port == 0) || (tt_port > HUB_MAX_PORT_NUM) || (split_err_info == NULL) ){
2418: CORE_REPORT_ERROR(
USBC_INVALID_PARAMETER );
2419:
return(
UDI_STAT_DATA_ERROR );
2420: }
2421:
else{
2422:
2423:
2424:
2425:
2426: retval =
Usb_HubApi_ClearTTBuffer( usbhub->context, tt_port, split_err_info );
2427: }
2428:
return retval;
2429: }
2430:
2431:
2446: uhs_status_t
Usbh_Api_ReqDisableAttDet(
void )
2447: {
2448: uhs_status_t retval =
UDI_STAT_INVALID_STATE;
2449: uhs_status_t result;
2450: UHS_MSG_APIWRAP_ANS_DIS_ATTDET_FMT *rcv_msg;
2451:
struct usbd_usb_deviceinfo * pRootHub;
2452:
2453: pRootHub =
Usbh_Api_EnumRootHub( NULL );
2454:
2455: 2456:
if( pRootHub->usbdev_LowerHub[1] ){
2457:
2458:
2459:
if( Usbh_susres_get_state() == USBH_SUSRES_STS_IDLE ){
2460:
2461: 2462: kernel_wait(NULL,100);
2463:
2464:
2465: retval = kernel_create_message( &g_suspend_reqans_mbox );
2466:
if(retval !=
UDI_OK){
2467: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
2468:
return UDI_STAT_RESOURCE_UNAVAIL;
2469: }
2470:
2471:
2472:
2473: retval = Usbh_susres_SendMsg_req_susres( &g_suspend_reqans_mbox , USBH_APIWRAP_MSGID_REQ_DIS_ATTDET );
2474:
if(retval !=
UDI_OK){
2475: kernel_delete_message( &g_suspend_reqans_mbox , in_interrupt() );
2476: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
2477:
return UDI_STAT_RESOURCE_UNAVAIL;
2478: }
2479:
2480:
2481: retval = kernel_receive_message(
2482: &g_suspend_reqans_mbox ,
2483: (T_MSG **)&rcv_msg,
2484: WAITFOREVER ,
2485: in_interrupt()
2486: );
2487:
if(retval !=
UDI_OK){
2488: kernel_delete_message( &g_suspend_reqans_mbox , in_interrupt() );
2489: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
2490:
return retval;
2491: }
2492:
2493:
#ifdef USBH_COMMON_DISP_MESSID
2494:
2495: Usbh_common_DisplayMessage( (
void *)rcv_msg , "API_WR_SUSD" );
2496:
#endif
2497:
2498: 2499: retval = rcv_msg->result;
2500:
2501:
2502: result = kernel_mem_free( &g_apiwrap_info.mpl_osc , (
void*)rcv_msg , in_interrupt() );
2503:
if( result !=
UDI_OK ) {
2504: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2505: }
2506:
2507:
2508: result = kernel_delete_message( &g_suspend_reqans_mbox , in_interrupt() );
2509:
if(result !=
UDI_OK){
2510: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2511: }
2512: }
2513:
else{
2514: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2515: uhs_debug_print (DBG_ERR, ("Usbh_Api_ReqDisableAttDet : error stage error !!"));
2516: }
2517: }
2518:
else{
2519: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2520: uhs_debug_print (DBG_ERR, ("Usbh_Api_ReqDiasbleAttDet : error root_hub empty error !!"));
2521: }
2522:
2523:
#ifdef USBH_DBG_ADD_MESSAGE
2524: uhs_debug_print( DBG_ERR, ( "Return Usbh_Api_ReqDisableAttDet (result=%d)",retval) );
2525:
#endif
2526:
return retval;
2527: }
2528:
2529:
2543: uhs_status_t
Usbh_Api_CancelDisableAttDet(
void )
2544: {
2545: uhs_status_t retval =
UDI_STAT_INVALID_STATE;
2546: uhs_status_t result;
2547: UHS_MSG_APIWRAP_ANS_DIS_ATTDET_FMT *rcv_msg;
2548:
2549:
2550:
2551: retval = kernel_create_message( &g_suspend_reqans_mbox );
2552:
if(retval !=
UDI_OK){
2553: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
2554:
return UDI_STAT_RESOURCE_UNAVAIL;
2555: }
2556:
2557:
2558:
2559: retval = Usbh_susres_SendMsg_req_susres( &g_suspend_reqans_mbox , USBH_APIWRAP_MSGID_REQ_CANCEL_DIS_ATTDET );
2560:
if(retval !=
UDI_OK){
2561: kernel_delete_message( &g_suspend_reqans_mbox , in_interrupt() );
2562: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
2563:
return UDI_STAT_RESOURCE_UNAVAIL;
2564: }
2565:
2566:
2567: retval = kernel_receive_message(
2568: &g_suspend_reqans_mbox ,
2569: (T_MSG **)&rcv_msg,
2570: WAITFOREVER ,
2571: in_interrupt()
2572: );
2573:
if(retval !=
UDI_OK){
2574: kernel_delete_message( &g_suspend_reqans_mbox , in_interrupt() );
2575: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
2576:
return retval;
2577: }
2578:
2579:
#ifdef USBH_COMMON_DISP_MESSID
2580:
2581: Usbh_common_DisplayMessage( (
void *)rcv_msg , "API_WR_SUSD" );
2582:
#endif
2583:
2584: 2585: retval = rcv_msg->result;
2586:
2587:
2588: result = kernel_mem_free( &g_apiwrap_info.mpl_osc , (
void*)rcv_msg , in_interrupt() );
2589:
if( result !=
UDI_OK ) {
2590: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2591: }
2592:
2593:
2594: result = kernel_delete_message( &g_suspend_reqans_mbox , in_interrupt() );
2595:
if(result !=
UDI_OK){
2596: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2597: }
2598:
2599:
#ifdef USBH_DBG_ADD_MESSAGE
2600: uhs_debug_print( DBG_ERR, ( "Return Usbh_Api_CancelDisableAttDet (result=%d)",retval) );
2601:
#endif
2602:
return retval;
2603: }
2604:
2605:
2621: uhs_status_t
Usbh_Api_ReqSuspend(
void )
2622: {
2623: uhs_status_t retval =
UDI_STAT_INVALID_STATE;
2624: uhs_status_t result;
2625: UHS_MSG_APIWRAP_ANS_SUSPEND_FMT *rcv_msg;
2626:
2627:
struct usbd_usb_deviceinfo * pRootHub;
2628:
2629: pRootHub =
Usbh_Api_EnumRootHub( NULL );
2630:
2631: 2632:
if( pRootHub->usbdev_LowerHub[1] ){
2633:
2634:
2635:
if( (Usbh_susres_get_state() == USBH_SUSRES_STS_IDLE) && (Usb_Hub_get_suspend_flg() == 1) ){
2636:
2637: 2638: kernel_wait(NULL,100);
2639:
2640:
2641:
if( Usbh_chk_apiwrap_alldev_request() == 0 ){
2642:
2643:
2644: retval = kernel_create_message( &g_suspend_reqans_mbox );
2645:
if(retval !=
UDI_OK){
2646: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
2647:
return UDI_STAT_RESOURCE_UNAVAIL;
2648: }
2649:
2650:
2651:
2652: retval = Usbh_susres_SendMsg_req_susres( &g_suspend_reqans_mbox , USBH_APIWRAP_MSGID_REQ_SUSPEND );
2653:
if(retval !=
UDI_OK){
2654: kernel_delete_message( &g_suspend_reqans_mbox , in_interrupt() );
2655: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
2656:
return UDI_STAT_RESOURCE_UNAVAIL;
2657: }
2658:
2659:
2660: retval = kernel_receive_message(
2661: &g_suspend_reqans_mbox ,
2662: (T_MSG **)&rcv_msg,
2663: WAITFOREVER ,
2664: in_interrupt()
2665: );
2666:
if(retval !=
UDI_OK){
2667: kernel_delete_message( &g_suspend_reqans_mbox , in_interrupt() );
2668: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
2669:
return retval;
2670: }
2671:
2672:
#ifdef USBH_COMMON_DISP_MESSID
2673:
2674: Usbh_common_DisplayMessage( (
void *)rcv_msg , "API_WR_SUSD" );
2675:
#endif
2676:
2677: 2678: retval = rcv_msg->result;
2679:
2680:
2681: result = kernel_mem_free( &g_apiwrap_info.mpl_osc , (
void*)rcv_msg , in_interrupt() );
2682:
if( result !=
UDI_OK ) {
2683: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2684: }
2685:
2686:
2687: result = kernel_delete_message( &g_suspend_reqans_mbox , in_interrupt() );
2688:
if(result !=
UDI_OK){
2689: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2690: }
2691: }
2692:
else{
2693: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2694: uhs_debug_print (DBG_ERR, ("Usbh_Api_ReqSuspend : error request found !!"));
2695: }
2696: }
2697:
else{
2698: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2699: uhs_debug_print (DBG_ERR, ("Usbh_Api_ReqSuspend : error stage error !!"));
2700: }
2701: }
2702:
else{
2703: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2704: uhs_debug_print (DBG_ERR, ("Usbh_Api_ReqSuspend : error root_hub empty error !!"));
2705: }
2706:
2707:
#ifdef USBH_DBG_ADD_MESSAGE
2708: uhs_debug_print( DBG_ERR, ( "Return Usbh_Api_ReqSuspend (result=%d)",retval) );
2709:
#endif
2710:
return retval;
2711: }
2712:
2713:
2729: uhs_status_t
Usbh_Api_ReqResume(
void )
2730: {
2731: uhs_status_t retval =
UDI_STAT_INVALID_STATE;
2732: uhs_status_t result;
2733: UHS_MSG_APIWRAP_ANS_RESUME_FMT *rcv_msg;
2734:
2735:
2736:
if( Usbh_susres_get_state() == USBH_SUSRES_STS_SUSPENDING ){
2737:
2738:
2739: retval = kernel_create_message( &g_response_reqans_mbox );
2740:
if(retval !=
UDI_OK){
2741: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
2742:
return UDI_STAT_RESOURCE_UNAVAIL;
2743: }
2744:
2745:
2746:
2747: retval = Usbh_susres_SendMsg_req_susres( &g_response_reqans_mbox , USBH_APIWRAP_MSGID_REQ_RESUME );
2748:
if(retval !=
UDI_OK){
2749: kernel_delete_message( &g_suspend_reqans_mbox , in_interrupt() );
2750: CORE_REPORT_ERROR(
USBC_RESOURCE_UNAVAIL );
2751:
return UDI_STAT_RESOURCE_UNAVAIL;
2752: }
2753:
2754:
2755: retval = kernel_receive_message(
2756: &g_response_reqans_mbox ,
2757: (T_MSG **)&rcv_msg,
2758: WAITFOREVER ,
2759: in_interrupt()
2760: );
2761:
if(retval !=
UDI_OK){
2762: kernel_delete_message( &g_suspend_reqans_mbox , in_interrupt() );
2763: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR);
2764:
return retval;
2765: }
2766:
2767:
#ifdef USBH_COMMON_DISP_MESSID
2768:
2769: Usbh_common_DisplayMessage( (
void *)rcv_msg , "API_WR_RES" );
2770:
#endif
2771:
2772: 2773: retval = rcv_msg->result;
2774:
2775:
2776: result = kernel_mem_free( &g_apiwrap_info.mpl_osc , (
void*)rcv_msg , in_interrupt() );
2777:
if( result !=
UDI_OK ) {
2778: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2779: }
2780:
2781:
2782: result = kernel_delete_message( &g_response_reqans_mbox , in_interrupt() );
2783:
if(result !=
UDI_OK){
2784: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2785: }
2786: }
2787:
else{
2788: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2789: uhs_debug_print (DBG_ERR, ("Usbh_Api_ReqResume : error stage error !!"));
2790: }
2791:
2792:
#ifdef USBH_DBG_ADD_MESSAGE
2793: uhs_debug_print( DBG_ERR, ( "Return Usbh_Api_ReqResume (result=%d)",retval) );
2794:
#endif
2795:
return retval;
2796: }
2797:
2798:
2816: uhs_ubit32_t Usbh_chk_apiwrap_alldev_request(
void )
2817: {
2818: uhs_ubit32_t ret = 0;
2819: uhs_status_t retval;
2820: usb_wrap_devinfo *devinfo = NULL;
2821:
2822:
2823: 2824: retval = kernel_acquisition_semaphore( &(g_apiwrap_info.drvinfo_semid), USB_HOST_SEMTIMEOUT, in_interrupt());
2825:
if ( retval !=
UDI_OK ) {
2826: uhs_debug_print (DBG_ERR, ("------------------- : acq sem error: ercd=%d", retval));
2827: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2828: }
2829:
2830:
2831: 2832:
if ( lists_ListEmpty(&g_apiwrap_info.usb_wrap_devinfo_list) == FALSE ) {
2833:
2834: 2835: devinfo = (usb_wrap_devinfo *)lists_get_FirstElement(&g_apiwrap_info.usb_wrap_devinfo_list);
2836:
2837: 2838:
while(lists_get_RoopIsEnd( devinfo ) == FALSE){
2839:
2840: 2841:
if( lists_ListEmpty( &(devinfo->requcb_list) ) == FALSE ){
2842: ret++;
2843:
break;
2844: }
2845:
2846:
2847: devinfo = (usb_wrap_devinfo *)lists_get_NextElement(&g_apiwrap_info.usb_wrap_devinfo_list, devinfo);
2848: }
2849: }
2850:
2851:
2852: retval = kernel_release_semaphore(&(g_apiwrap_info.drvinfo_semid), in_interrupt());
2853:
if ( retval !=
UDI_OK ) {
2854: uhs_debug_print (DBG_ERR, ("------------------- : rel sem error: ercd=%d", retval));
2855: CORE_REPORT_ERROR(
USBC_ILLEGAL_ERROR );
2856: }
2857:
2858:
return ret;
2859: }
2860:
2861: