2 * Entry point for USBD service, that handles USB HCDs
5 #include <ddekit/ddekit.h> /* ddekit_init */
6 #include <ddekit/thread.h> /* DDEKit threading */
8 #include <libdde/usb_server.h> /* DDEKit USB server */
10 #include <minix/devman.h> /* Initializing 'devman' */
11 #include <minix/sef.h> /* SEF handling */
13 #include <usb/usb_common.h>
14 #include <usb/usbd_interface.h>
17 /*===========================================================================*
18 * Local declarations *
19 *===========================================================================*/
20 static int usbd_sef_handler(int, sef_init_info_t
*);
21 static void usbd_signal_handler(int);
22 static int usbd_start(void);
23 static void usbd_init(void);
24 static void usbd_server_thread(void *);
26 /* TODO: No headers for these... */
27 extern void ddekit_minix_wait_exit(void); /* dde.c */
28 extern void ddekit_shutdown(void); /* dde.c */
31 /*===========================================================================*
33 *===========================================================================*/
35 main(int UNUSED(argc
), char * UNUSED(argv
[]))
39 USB_MSG("Starting USBD");
40 USB_DBG("Built: %s %s", __DATE__
, __TIME__
);
42 /* Basic SEF,DDE,... initialization */
45 /* Assume failure unless usbd_start exits gracefully */
46 ret_val
= EXIT_FAILURE
;
48 /* USB host controllers initialization */
49 if (EXIT_SUCCESS
== usbd_init_hcd()) {
51 /* Try initializing 'devman' */
52 if (EXIT_SUCCESS
== devman_init()) {
54 /* Run USB driver (actually DDEKit threads)
55 * until this call returns: */
56 ret_val
= usbd_start();
59 USB_MSG("Initializing devman, failed");
61 /* Clean whatever was initialized */
65 USB_MSG("Initializing HCDs, failed");
71 /*===========================================================================*
73 *===========================================================================*/
75 usbd_sef_handler(int type
, sef_init_info_t
* UNUSED(info
))
81 USB_MSG("Initializing");
85 USB_MSG("Updating, not implemented");
88 case SEF_INIT_RESTART
:
89 USB_MSG("Restarting, not implemented");
93 USB_MSG("illegal SEF type");
99 /*===========================================================================*
100 * usbd_signal_handler *
101 *===========================================================================*/
103 usbd_signal_handler(int UNUSED(signo
))
107 USB_MSG("Signal received, exiting USBD...");
109 /* Try graceful DDEKit exit */
112 /* Unreachable, when ddekit_shutdown works correctly */
113 USB_ASSERT(0, "Calling ddekit_shutdown failed!");
117 /*===========================================================================*
119 *===========================================================================*/
123 ddekit_thread_t
* usbd_th
;
127 /* Driver's "main loop" is within DDEKit server thread */
128 usbd_th
= ddekit_thread_create(usbd_server_thread
, NULL
, "USBD");
130 /* After spawning, allow server thread to work */
131 if (NULL
!= usbd_th
) {
132 /* This will lock current thread until DDEKit exits */
133 ddekit_minix_wait_exit();
136 ddekit_thread_terminate(usbd_th
);
144 /*===========================================================================*
146 *===========================================================================*/
152 /* Set one handler for all messages */
153 sef_setcb_init_fresh(usbd_sef_handler
);
154 sef_setcb_init_lu(usbd_sef_handler
);
155 sef_setcb_init_restart(usbd_sef_handler
);
156 sef_setcb_signal_handler(usbd_signal_handler
);
158 /* Initialize DDEkit (involves sef_startup()) */
163 /*===========================================================================*
164 * usbd_server_thread *
165 *===========================================================================*/
167 usbd_server_thread(void * UNUSED(unused
))
171 ddekit_usb_server_init();