Ignore:
Timestamp:
2014-01-18T21:34:32Z (11 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a5361fb
Parents:
e26a9d95
Message:

uhci,ohci, ehci: Move interrupt replacement fibril to libusbhost

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/src/ddf_helpers.c

    re26a9d95 r3e200736  
    717717
    718718        assert(device);
    719         assert(hw_res);
    720         assert(handler);
    721         assert(gen_irq_code);
     719        if (!handler || !gen_irq_code)
     720                return ENOTSUP;
    722721
    723722        irq_code_t irq_code = {0};
     
    768767        hcd->driver.irq_hook(hcd, status);
    769768}
     769
     770static int interrupt_polling(void *arg)
     771{
     772        hcd_t *hcd = arg;
     773        assert(hcd);
     774        if (!hcd->driver.status_hook || !hcd->driver.irq_hook)
     775                return ENOTSUP;
     776        uint32_t status = 0;
     777        while (hcd->driver.status_hook(hcd, &status) == EOK) {
     778                hcd->driver.irq_hook(hcd, status);
     779                status = 0;
     780                /* We should wait 1 frame - 1ms here, but this polling is a
     781                 * lame crutch anyway so don't hog the system. 10ms is still
     782                 * good enough for emergency mode */
     783                async_usleep(10000);
     784        }
     785        return EOK;
     786}
     787
    770788/** Initialize hc and rh DDF structures and their respective drivers.
    771789 *
     
    816834        const int irq = hcd_ddf_setup_interrupts(device, &hw_res, irq_handler,
    817835            gen_irq_code);
    818         if (irq < 0) {
     836        if (!(irq < 0)) {
     837                usb_log_debug("Hw interrupts enabled.\n");
     838        }
     839
     840        /* Init hw driver */
     841        hcd_t *hcd = dev_to_hcd(device);
     842        ret = driver_init(hcd, &hw_res, !(irq < 0));
     843        hw_res_list_parsed_clean(&hw_res);
     844        if (ret != EOK) {
     845                usb_log_error("Failed to init uhci_hcd: %s.\n", str_error(ret));
     846                goto irq_unregister;
     847        }
     848
     849        /* Need working irq replacement to setup root hub */
     850        if ((irq < 0) && hcd->driver.status_hook) {
     851                hcd->polling_fibril = fibril_create(interrupt_polling, hcd);
     852                if (hcd->polling_fibril == 0) {
     853                        usb_log_error("Failed to create polling fibril\n");
     854                        ret = ENOMEM;
     855                        goto irq_unregister;
     856                }
     857                fibril_add_ready(hcd->polling_fibril);
    819858                usb_log_warning("Failed to enable interrupts: %s."
    820859                    " Falling back to polling.\n", str_error(irq));
    821         } else {
    822                 usb_log_debug("Hw interrupts enabled.\n");
    823         }
    824 
    825         /* Init hw driver */
    826         ret = driver_init(dev_to_hcd(device), &hw_res, !(irq < 0));
    827         hw_res_list_parsed_clean(&hw_res);
    828         if (ret != EOK) {
    829                 usb_log_error("Failed to init uhci_hcd: %s.\n", str_error(ret));
    830                 goto irq_unregister;
    831860        }
    832861
Note: See TracChangeset for help on using the changeset viewer.