Пример #1
0
void __visible
USB_Handler(void)
{
    uint8_t s = USB->DEVICE.INTFLAG.reg;
    if (s & USB_DEVICE_INTFLAG_EORST) {
        USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_EORST;
        // Enable endpoint 0 irqs
        EP0.EPINTENSET.reg = (
            USB_DEVICE_EPINTENSET_TRCPT0 | USB_DEVICE_EPINTENSET_TRCPT1
            | USB_DEVICE_EPINTENSET_RXSTP);
    }

    uint16_t ep = USB->DEVICE.EPINTSMRY.reg;
    if (ep & (1<<0)) {
        uint8_t sts = EP0.EPINTFLAG.reg;
        EP0.EPINTFLAG.reg = sts;
        if (set_address && sts & USB_DEVICE_EPINTFLAG_TRCPT1) {
            // Apply address after last "in" message transmitted
            USB->DEVICE.DADD.reg = set_address;
            set_address = 0;
        }
        usb_notify_setup();
    }
    if (ep & (1<<USB_CDC_EP_BULK_OUT)) {
        uint8_t sts = EP_BULKOUT.EPINTFLAG.reg;
        EP_BULKOUT.EPINTFLAG.reg = sts;
        usb_notify_bulk_out();
    }
    if (ep & (1<<USB_CDC_EP_BULK_IN)) {
        uint8_t sts = EP_BULKIN.EPINTFLAG.reg;
        EP_BULKIN.EPINTFLAG.reg = sts;
        usb_notify_bulk_in();
    }
}
Пример #2
0
// Encode and transmit a "response" message
void
console_sendf(const struct command_encoder *ce, va_list args)
{
    // Verify space for message
    uint_fast8_t tpos = transmit_pos, max_size = READP(ce->max_size);
    if (tpos + max_size > sizeof(transmit_buf))
        // Not enough space for message
        return;

    // Generate message
    uint8_t *buf = &transmit_buf[tpos];
    uint_fast8_t msglen = command_encode_and_frame(buf, ce, args);

    // Start message transmit
    transmit_pos = tpos + msglen;
    usb_notify_bulk_in();
}
Пример #3
0
void
usb_bulk_in_task(void)
{
    if (!sched_check_wake(&usb_bulk_in_wake))
        return;
    uint_fast8_t tpos = transmit_pos;
    if (!tpos)
        return;
    uint_fast8_t max_tpos = (tpos > USB_CDC_EP_BULK_IN_SIZE
                             ? USB_CDC_EP_BULK_IN_SIZE : tpos);
    int_fast8_t ret = usb_send_bulk_in(transmit_buf, max_tpos);
    if (ret <= 0)
        return;
    uint_fast8_t needcopy = tpos - ret;
    if (needcopy) {
        memmove(transmit_buf, &transmit_buf[ret], needcopy);
        usb_notify_bulk_in();
    }
    transmit_pos = needcopy;
}