/** * @brief Notification of data removed from the input queue. */ static void inotify(GenericQueue *qp) { size_t n, maxsize; BulkUSBDriver *bdup = chQGetLink(qp); /* If the USB driver is not in the appropriate state then transactions must not be started.*/ if ((usbGetDriverStateI(bdup->config->usbp) != USB_ACTIVE) || (bdup->state != BDU_READY)) return; /* If there is in the queue enough space to hold at least one packet and a transaction is not yet started then a new transaction is started for the available space.*/ maxsize = bdup->config->usbp->epc[bdup->config->bulk_out]->out_maxsize; if (!usbGetReceiveStatusI(bdup->config->usbp, bdup->config->bulk_out) && ((n = chIQGetEmptyI(&bdup->iqueue)) >= maxsize)) { chSysUnlock(); n = (n / maxsize) * maxsize; usbPrepareQueuedReceive(bdup->config->usbp, bdup->config->bulk_out, &bdup->iqueue, n); chSysLock(); usbStartReceiveI(bdup->config->usbp, bdup->config->bulk_out); } }
/** * @brief Default data received callback. * @details The application must use this function as callback for the OUT * data endpoint. * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number */ void bduDataReceived(USBDriver *usbp, usbep_t ep) { size_t n, maxsize; BulkUSBDriver *bdup = usbp->out_params[ep - 1]; if (bdup == NULL) return; chSysLockFromIsr(); chnAddFlagsI(bdup, CHN_INPUT_AVAILABLE); /* Writes to the input queue can only happen when there is enough space to hold at least one packet.*/ maxsize = usbp->epc[ep]->out_maxsize; if ((n = chIQGetEmptyI(&bdup->iqueue)) >= maxsize) { /* The endpoint cannot be busy, we are in the context of the callback, so a packet is in the buffer for sure.*/ chSysUnlockFromIsr(); n = (n / maxsize) * maxsize; usbPrepareQueuedReceive(usbp, ep, &bdup->iqueue, n); chSysLockFromIsr(); usbStartReceiveI(usbp, ep); } chSysUnlockFromIsr(); }
/** * @brief Notification of data removed from the input queue. * * @param[in] qp the queue pointer. */ static void inotify(io_queue_t *qp) { size_t n, maxsize; SerialUSBDriver *sdup = qGetLink(qp); /* If the USB driver is not in the appropriate state then transactions must not be started.*/ if ((usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) || (sdup->state != SDU_READY)) { return; } /* If there is in the queue enough space to hold at least one packet and a transaction is not yet started then a new transaction is started for the available space.*/ maxsize = sdup->config->usbp->epc[sdup->config->bulk_out]->out_maxsize; if (!usbGetReceiveStatusI(sdup->config->usbp, sdup->config->bulk_out)) { if ((n = iqGetEmptyI(&sdup->iqueue)) >= maxsize) { osalSysUnlock(); n = (n / maxsize) * maxsize; usbPrepareQueuedReceive(sdup->config->usbp, sdup->config->bulk_out, &sdup->iqueue, n); osalSysLock(); (void) usbStartReceiveI(sdup->config->usbp, sdup->config->bulk_out); } } }
/** * @brief Default data received callback. * @details The application must use this function as callback for the OUT * data endpoint. * * @param[in] usbp pointer to the @p USBDriver object * @param[in] ep endpoint number */ void sduDataReceived(USBDriver *usbp, usbep_t ep) { size_t n, maxsize; SerialUSBDriver *sdup = usbp->param; (void)ep; chSysLockFromIsr(); chnAddFlagsI(sdup, CHN_INPUT_AVAILABLE); /* Writes to the input queue can only happen when there is enough space to hold at least one packet.*/ maxsize = usbp->epc[USB_CDC_DATA_AVAILABLE_EP]->out_maxsize; if ((n = chIQGetEmptyI(&sdup->iqueue)) >= maxsize) { /* The endpoint cannot be busy, we are in the context of the callback, so a packet is in the buffer for sure.*/ chSysUnlockFromIsr(); n = (n / maxsize) * maxsize; usbPrepareQueuedReceive(usbp, ep, &sdup->iqueue, n); chSysLockFromIsr(); usbStartReceiveI(usbp, ep); } chSysUnlockFromIsr(); }
/** * @brief Notification of data removed from the input queue. */ static void inotify(GenericQueue *qp) { size_t n, maxsize; SerialUSBDriver *sdup = chQGetLink(qp); /* If the USB driver is not in the appropriate state then transactions must not be started.*/ if (usbGetDriverStateI(sdup->config->usbp) != USB_ACTIVE) return; /* If there is in the queue enough space to hold at least one packet and a transaction is not yet started then a new transaction is started for the available space.*/ maxsize = sdup->config->usbp->epc[USB_CDC_DATA_AVAILABLE_EP]->out_maxsize; if (!usbGetReceiveStatusI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP) && ((n = chIQGetEmptyI(&sdup->iqueue)) >= maxsize)) { chSysUnlock(); n = (n / maxsize) * maxsize; usbPrepareQueuedReceive(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP, &sdup->iqueue, n); chSysLock(); usbStartReceiveI(sdup->config->usbp, USB_CDC_DATA_AVAILABLE_EP); } }
/** * @brief USB device configured handler. * * @param[in] bdup pointer to a @p BulkUSBDriver object * * @iclass */ void bduConfigureHookI(BulkUSBDriver *bdup) { USBDriver *usbp = bdup->config->usbp; chIQResetI(&bdup->iqueue); chOQResetI(&bdup->oqueue); chnAddFlagsI(bdup, CHN_CONNECTED); /* Starts the first OUT transaction immediately.*/ usbPrepareQueuedReceive(usbp, bdup->config->bulk_out, &bdup->iqueue, usbp->epc[bdup->config->bulk_out]->out_maxsize); usbStartReceiveI(usbp, bdup->config->bulk_out); }
/** * @brief USB device configured handler. * * @param[in] sdup pointer to a @p SerialUSBDriver object * * @iclass */ void sduConfigureHookI(SerialUSBDriver *sdup) { USBDriver *usbp = sdup->config->usbp; iqResetI(&sdup->iqueue); oqResetI(&sdup->oqueue); chnAddFlagsI(sdup, CHN_CONNECTED); /* Starts the first OUT transaction immediately.*/ usbPrepareQueuedReceive(usbp, sdup->config->bulk_out, &sdup->iqueue, usbp->epc[sdup->config->bulk_out]->out_maxsize); (void) usbStartReceiveI(usbp, sdup->config->bulk_out); }