Пример #1
0
/*
M0 Core Manage USB 
*/
int main(void)
{
  iap_cmd_res_t iap_cmd_res;
  usb_descriptor_serial_number_t serial_number;
  airspy_usb_req_init();

  usb_set_configuration_changed_cb(usb_configuration_changed);
  usb_peripheral_reset();
  
  usb_device_init(0, &usb_device);
  
  usb_queue_init(&usb_endpoint_control_out_queue);
  usb_queue_init(&usb_endpoint_control_in_queue);
  usb_queue_init(&usb_endpoint_bulk_out_queue);
  usb_queue_init(&usb_endpoint_bulk_in_queue);

  usb_endpoint_init(&usb_endpoint_control_out);
  usb_endpoint_init(&usb_endpoint_control_in);

  /* Read IAP Serial Number Identification */
  iap_cmd_res.cmd_param.command_code = IAP_CMD_READ_SERIAL_NO;
  iap_cmd_call(&iap_cmd_res);
  if(iap_cmd_res.status_res.status_ret == CMD_SUCCESS)
  { 
    /* Only retrieve 2 last 32bits for Serial Number */
    serial_number.sn_32b[0] = iap_cmd_res.status_res.iap_result[2];
    serial_number.sn_32b[1] = iap_cmd_res.status_res.iap_result[3];
    usb_descriptor_fill_string_serial_number(serial_number);
  }

  nvic_set_priority(NVIC_USB0_IRQ, 255);
  
  nvic_set_priority(NVIC_M4CORE_IRQ, 1);
  nvic_enable_irq(NVIC_M4CORE_IRQ);

  usb_run(&usb_device);

  while(true)
  {
    signal_wfe();

    if( (get_usb_buffer_offset() >= 16384) && 
        (phase == 1) )
    {
      usb_transfer_schedule_block(&usb_endpoint_bulk_in, &usb_bulk_buffer[0x0000], 0x4000, NULL, NULL);
      phase = 0;
    }

    if( (get_usb_buffer_offset() < 16384) && 
        (phase == 0) )
    {
      usb_transfer_schedule_block(&usb_endpoint_bulk_in, &usb_bulk_buffer[0x4000], 0x4000, NULL, NULL);
      phase = 1;  
    }
  }
}
Пример #2
0
void usb_init(void)
{
        usb_queue_init(&usb_endpoint_control_in_queue);
        usb_queue_init(&usb_endpoint_control_out_queue);
        usb_queue_init(&usb_endpoint_bulk_cmd_in_queue);
        usb_queue_init(&usb_endpoint_bulk_cmd_out_queue);
        usb_queue_init(&usb_endpoint_bulk_data_in_queue);

        usb_set_configuration_changed_cb(usb_configuration_changed);
        usb_peripheral_reset();
        usb_device_init(0, &usb_device);
        usb_endpoint_init(&usb_endpoint_control_out);
        usb_endpoint_init(&usb_endpoint_control_in);
        nvic_set_priority(NVIC_USB0_IRQ, 255);
        usb_run(&usb_device);
}
Пример #3
0
struct usb_endp *usb_endp_alloc(struct usb_dev *dev,
                                const struct usb_desc_endpoint *endp_desc) {
    struct usb_endp *endp = pool_alloc(&usb_endps);
    struct usb_hcd *hcd = dev->hcd;
    int endp_num;

    if (!endp) {
        return NULL;
    }

    endp->dev = dev;

    usb_endp_fill_from_desc(endp, endp_desc);

    usb_queue_init(&endp->req_queue);

    for (endp_num = 0; endp_num < USB_DEV_MAX_ENDP; endp_num++) {
        struct usb_endp *dendp = dev->endpoints[endp_num];
        if (!dendp) {
            break;
        }

        assert(dendp->address != endp->address ||
               dendp->direction != endp->direction);
    }

    assert(endp_num < USB_DEV_MAX_ENDP);

    dev->endpoints[endp_num] = endp;

    if (hcd->ops->endp_hci_alloc) {
        endp->hci_specific = hcd->ops->endp_hci_alloc(endp);
        if (!hcd->hci_specific) {
            pool_free(&usb_endps, endp);
            return NULL;
        }
    }

    return endp;
}
Пример #4
0
struct usb_hcd *usb_hcd_alloc(struct usb_hcd_ops *ops, void *args) {
    struct usb_hcd *hcd = pool_alloc(&usb_hcds);

    if (!hcd) {
        return NULL;
    }

    hcd->ops = ops;
    index_init(&hcd->enumerator, 1, USB_HC_MAX_DEV, &hcd->idx_data);

    dlist_head_init(&hcd->lnk);
    usb_queue_init(&hcd->reset_queue);

    if (ops->hcd_hci_alloc) {
        hcd->hci_specific = ops->hcd_hci_alloc(hcd, args);
        if (!hcd->hci_specific) {
            pool_free(&usb_hcds, hcd);
            return NULL;
        }
    }

    return hcd;
}