14IRX_ID(
"USB_driver", 2, 4);
18static int usbdModuleUnload(
void);
23 {
"dev=", &usbConfig.m_maxDevices, NULL},
24 {
"ed=", &usbConfig.m_maxEndpoints, NULL},
25 {
"gtd=", &usbConfig.m_maxTransfDesc, NULL},
26 {
"itd=", &usbConfig.m_maxIsoTransfDesc, NULL},
27 {
"ioreq=", &usbConfig.m_maxIoReqs, NULL},
28 {
"conf=", &usbConfig.m_maxStaticDescSize, NULL},
29 {
"hub=", &usbConfig.m_maxHubDevices, NULL},
30 {
"port=", &usbConfig.m_maxPortsPerHub, NULL},
31 {
"thpri=", &usbConfig.m_hcdThreadPrio, &usbConfig.m_cbThreadPrio},
32 {
"reportd=", &usbConfig.m_curDescNum, NULL},
74static int usbdIntrHandler(
void *arg)
79 iSetEventFlag(kernelResources->m_hcdIrqEvent, 1u);
83static void hcdIrqThread(
void *arg)
90 WaitEventFlag(usbKernelResources.m_hcdIrqEvent, 1u, WEF_OR | WEF_CLEAR, &efres);
94 PostIntrEnableFunction();
99static void callbackThreadFunc(
void *arg)
109 WaitEventFlag(usbKernelResources.m_callbackEvent, 1u, WEF_OR | WEF_CLEAR, &efres);
117 req->m_next->m_prev = req->m_prev;
119 cbListEnd = req->m_prev;
121 req->m_prev->m_next = req->m_next;
123 cbListStart = req->m_next;
132 if ( reqCopy.m_userCallbackProc )
135 SetGP(reqCopy.m_gpSeg);
137 if ( reqCopy.m_req.bNumPackets )
138 reqCopy.m_userCallbackProcMultiIsochronous(reqCopy.m_resultCode, &reqCopy.m_req, reqCopy.m_userCallbackArg);
140 reqCopy.m_userCallbackProcRegular(reqCopy.m_resultCode, reqCopy.m_transferedBytes, reqCopy.m_userCallbackArg);
149void usbdReboot(
int ac)
151 if ( (
unsigned int)ac < 2 )
155static void ParseOptionInput(
const UsbdArgOption_t *option,
const char *arguments)
163 for ( p_1 = arguments; *p_1 && *p_1 !=
','; p_1 += 1 )
165 if ( (
unsigned int)(*p_1 -
'0') >= 9 )
167 value_1 = 10 * value_1 + (*p_1 -
'0');
169 if ( option->value2 ? (*p_1 !=
',') : (*p_1 ==
',') )
171 if ( arguments < p_1 )
172 *option->value = value_1;
173 if ( !option->value2 )
178 for ( p_2 = p_1 + 1; *p_2; p_2 += 1 )
180 if ( (
unsigned int)(*p_2 -
'0') >= 9 )
182 value_2 = 10 * value_2 + (*p_2 -
'0');
185 *option->value2 = value_2;
188int _start(
int ac,
char *av[],
void *startaddr,
ModuleInfo_t *mi)
201 return usbdModuleUnload();
202 for ( i = 1; i < ac; i += 1 )
204 for ( args_ptr = SupportedArgs; args_ptr->param; args_ptr += 1 )
207 for ( j = 0, pParam = args_ptr->param, pArgs = av[i]; pParam[j] && pParam[j] == pArgs[j]; j += 1 )
212 ParseOptionInput(args_ptr, pArgs);
217 dbg_printf(
"Intr handler...\n");
221 if ( intrstate == IOP_IRQ_USB )
224 return MODULE_NO_RESIDENT_END;
229 dbg_printf(
"library entries...\n");
230 if ( !RegisterLibraryEntries(&_exp_usbd) )
232 dbg_printf(
"Threads and events...\n");
234 sema.attr = SA_THPRI;
238 usbKernelResources.m_usbdSema = CreateSema(&sema);
239 if ( usbKernelResources.m_usbdSema >= 0 )
244 usbKernelResources.m_hcdIrqEvent = CreateEventFlag(&ef);
245 if ( usbKernelResources.m_hcdIrqEvent >= 0 )
247 dbg_printf(
"HCD thread...\n");
249 thparam.thread = hcdIrqThread;
251 thparam.stacksize = 0x4000;
253 thparam.stacksize = 0x0800;
256 thparam.priority = usbConfig.m_hcdThreadPrio;
257 usbKernelResources.m_hcdTid = CreateThread(&thparam);
258 if ( usbKernelResources.m_hcdTid >= 0 && !StartThread(usbKernelResources.m_hcdTid, NULL) )
263 usbKernelResources.m_callbackEvent = CreateEventFlag(&ef);
264 if ( usbKernelResources.m_callbackEvent >= 0 )
266 dbg_printf(
"Callback thread...\n");
268 thparam.thread = callbackThreadFunc;
270 thparam.stacksize = 0x4000;
272 thparam.stacksize = 0x0800;
275 thparam.priority = usbConfig.m_cbThreadPrio;
276 usbKernelResources.m_callbackTid = CreateThread(&thparam);
278 usbKernelResources.m_callbackTid >= 0 && !StartThread(usbKernelResources.m_callbackTid, NULL)
279 && usbdInitInner() >= 0 )
281 dbg_printf(
"Enabling interrupts...\n");
283 dbg_printf(
"Init done\n");
285 return MODULE_REMOVABLE_END;
287 if ( mi && ((mi->
newflags & 2) != 0) )
289 return MODULE_RESIDENT_END;
299 dbg_printf(
"RegisterLibraryEntries failed\n");
301 if ( usbKernelResources.m_callbackTid > 0 )
302 DeleteThread(usbKernelResources.m_callbackTid);
303 if ( usbKernelResources.m_callbackEvent > 0 )
304 DeleteEventFlag(usbKernelResources.m_callbackEvent);
305 if ( usbKernelResources.m_hcdTid > 0 )
306 DeleteThread(usbKernelResources.m_hcdTid);
307 if ( usbKernelResources.m_hcdIrqEvent > 0 )
308 DeleteEventFlag(usbKernelResources.m_hcdIrqEvent);
309 if ( usbKernelResources.m_usbdSema > 0 )
310 DeleteSema(usbKernelResources.m_usbdSema);
313 return MODULE_NO_RESIDENT_END;
316static int usbdModuleUnload(
void)
320 if ( ReleaseLibraryEntries(&_exp_usbd) == 0 )
322 return MODULE_REMOVABLE_END;
326 TerminateThread(usbKernelResources.m_hcdTid);
327 TerminateThread(usbKernelResources.m_callbackTid);
328 DeleteThread(usbKernelResources.m_hcdTid);
329 DeleteThread(usbKernelResources.m_callbackTid);
330 DeleteEventFlag(usbKernelResources.m_hcdIrqEvent);
331 DeleteEventFlag(usbKernelResources.m_callbackEvent);
332 DeleteSema(usbKernelResources.m_usbdSema);
335 return MODULE_NO_RESIDENT_END;
int CpuResumeIntr(int state)
int RegisterIntrHandler(int irq, int mode, int(*handler)(void *), void *arg)
int ReleaseIntrHandler(int irq)
int DisableIntr(int irq, int *res)
int CpuSuspendIntr(int *state)