Files
mop3/usb/usb.c
kamkow1 482afb47d7
All checks were successful
Build ISO image / build-and-deploy (push) Successful in 3m47s
Build documentation / build-and-deploy (push) Successful in 2m38s
USB driver polling user app, handle only one XHCI controller for now, Implement USB device addressing
2026-03-29 18:59:20 +02:00

58 lines
1.3 KiB
C

#include <device_info.h>
#include <devices.h>
#include <malloc.h>
#include <mprintf.h>
#include <process.h>
#include <process_self.h>
#include <status.h>
#include <string.h>
#include <system.h>
static void usb_poll_driver_proc (void* arg) {
struct device_info* info = arg;
mprintf ("Polling device %s\n", info->key);
for (;;) {
device_do (info->key, XUSBCTRL_POLL_DRIVER, NULL, NULL, NULL, NULL);
sched ();
}
}
void app_main (void) {
libprocess_self_init ();
char commandbuf[32];
memset (commandbuf, 0, sizeof (commandbuf));
if (env_get (process_get_pgid (), "C", (void*)commandbuf, sizeof (commandbuf)) != ST_OK) {
mprintf ("ERROR C=???. No command provided\n");
return;
}
if (strcmp (commandbuf, "poll") == 0) {
struct device_info* infos = malloc (sizeof (struct device_info) * 1024);
memset (infos, 0, sizeof (struct device_info) * 1024);
int device_count = get_device_info (infos, 1024);
for (int dev = 0; dev < device_count; dev++) {
struct device_info* info = &infos[dev];
if (info->type != DEVICE_TYPE_USB_CTRL) {
continue;
}
struct process_data* pdata = process_spawn (&usb_poll_driver_proc, info);
mprintf ("Started USB poller process: PID %d\n", pdata->pid);
}
for (;;)
;
} else {
mprintf ("ERROR unknown command %s\n", commandbuf);
}
}