Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 19d21728 in mainline


Ignore:
Timestamp:
2013-09-21T05:22:21Z (8 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master
Children:
772a172
Parents:
6210a333
Message:

libusbhost: Add generic irq setup routine.

Location:
uspace/lib/usbhost
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbhost/include/usb/host/ddf_helpers.h

    r6210a333 r19d21728  
    3737#define LIBUSBHOST_HOST_DDF_HELPERS_H
    3838
     39#include <ddf/interrupt.h>
    3940#include <device/hw_res_parsed.h>
    4041#include <usb/host/hcd.h>
     
    5051int hcd_ddf_enable_interrupts(ddf_dev_t *device);
    5152int hcd_ddf_get_registers(ddf_dev_t *device, hw_res_list_parsed_t *hw_res);
     53int hcd_ddf_setup_interrupts(ddf_dev_t *device, addr_range_t *regs, int irq,
     54    interrupt_handler_t handler, int (*gen_irq_code)(irq_code_t *, addr_range_t *));
    5255
    5356#endif
  • uspace/lib/usbhost/src/ddf_helpers.c

    r6210a333 r19d21728  
    676676        return ret;
    677677}
     678
     679// TODO: move this someplace else
     680static inline void irq_code_clean(irq_code_t *code)
     681{
     682        if (code) {
     683                free(code->ranges);
     684                free(code->cmds);
     685                code->ranges = NULL;
     686                code->cmds = NULL;
     687                code->rangecount = 0;
     688                code->cmdcount = 0;
     689        }
     690}
     691
     692
     693/** Register interrupt handler
     694 *
     695 * @param[in] device Host controller DDF device
     696 * @param[in] regs Register range
     697 * @param[in] irq Interrupt number
     698 * @paran[in] handler Interrupt handler
     699 * @param[in] gen_irq_code IRQ code generator.
     700 *
     701 * @return EOK on success or negative error code
     702 */
     703int hcd_ddf_setup_interrupts(ddf_dev_t *device, addr_range_t *regs, int irq,
     704    interrupt_handler_t handler,
     705    int (*gen_irq_code)(irq_code_t *, addr_range_t *))
     706{
     707
     708        assert(device);
     709        assert(regs);
     710        assert(handler);
     711        assert(gen_irq_code);
     712
     713
     714        irq_code_t irq_code = {0};
     715
     716        int ret = gen_irq_code(&irq_code, regs);
     717        if (ret != EOK) {
     718                usb_log_error("Failed to generate IRQ code: %s.\n",
     719                    str_error(ret));
     720                return ret;
     721        }
     722
     723        /* Register handler to avoid interrupt lockup */
     724        ret = register_interrupt_handler(device, irq, handler, &irq_code);
     725        irq_code_clean(&irq_code);
     726        if (ret != EOK) {
     727                usb_log_error("Failed to register interrupt handler: %s.\n",
     728                    str_error(ret));
     729                return ret;
     730        }
     731
     732        /* Enable interrupts */
     733        ret = hcd_ddf_enable_interrupts(device);
     734        if (ret != EOK) {
     735                usb_log_error("Failed to register interrupt handler: %s.\n",
     736                    str_error(ret));
     737                unregister_interrupt_handler(device, irq);
     738                return ret;
     739        }
     740
     741        return EOK;
     742}
    678743/**
    679744 * @}
Note: See TracChangeset for help on using the changeset viewer.