Пример #1
0
void stm32fx07_poll(usbd_device *usbd_dev)
{
	/* Read interrupt status register. */
	uint32_t intsts = REBASE(OTG_GINTSTS);
	int i;

	if (intsts & OTG_GINTSTS_ENUMDNE) {
		/* Handle USB RESET condition. */
		REBASE(OTG_GINTSTS) = OTG_GINTSTS_ENUMDNE;
		usbd_dev->fifo_mem_top = usbd_dev->driver->rx_fifo_size;
		_usbd_reset(usbd_dev);
		return;
	}

	/* Note: RX and TX handled differently in this device. */
	if (intsts & OTG_GINTSTS_RXFLVL) {
		/* Receive FIFO non-empty. */
		uint32_t rxstsp = REBASE(OTG_GRXSTSP);
		uint32_t pktsts = rxstsp & OTG_GRXSTSP_PKTSTS_MASK;
		if ((pktsts != OTG_GRXSTSP_PKTSTS_OUT) &&
		    (pktsts != OTG_GRXSTSP_PKTSTS_SETUP)) {
			return;
		}

		uint8_t ep = rxstsp & OTG_GRXSTSP_EPNUM_MASK;
		uint8_t type;
		if (pktsts == OTG_GRXSTSP_PKTSTS_SETUP) {
			type = USB_TRANSACTION_SETUP;
		} else {
			type = USB_TRANSACTION_OUT;
		}

		/* Save packet size for stm32f107_ep_read_packet(). */
		usbd_dev->rxbcnt = (rxstsp & OTG_GRXSTSP_BCNT_MASK) >> 4;

#if 0
		/*
		 * FIXME: Why is a delay needed here?
		 * This appears to fix a problem where the first 4 bytes
		 * of the DATA OUT stage of a control transaction are lost.
		 */
		for (i = 0; i < 1000; i++) {
			__asm__("nop");
		}
#endif

		if (usbd_dev->user_callback_ctr[ep][type]) {
			usbd_dev->user_callback_ctr[ep][type] (usbd_dev, ep);
		}

		/* Discard unread packet data. */
		for (i = 0; i < usbd_dev->rxbcnt; i += 4) {
			(void)*REBASE_FIFO(ep);
		}

		usbd_dev->rxbcnt = 0;
	}
Пример #2
0
static void stm32f107_poll(void)
{
	/* Read interrupt status register. */
	u32 intsts = OTG_FS_GINTSTS;
	int i;

	if (intsts & OTG_FS_GINTSTS_ENUMDNE) {
		/* Handle USB RESET condition. */
		OTG_FS_GINTSTS = OTG_FS_GINTSTS_ENUMDNE;
		fifo_mem_top = RX_FIFO_SIZE;
		_usbd_reset();
		return;
	}

	/* Note: RX and TX handled differently in this device. */
	if (intsts & OTG_FS_GINTSTS_RXFLVL) {
		/* Receive FIFO non-empty. */
		u32 rxstsp = OTG_FS_GRXSTSP;
		u32 pktsts = rxstsp & OTG_FS_GRXSTSP_PKTSTS_MASK;
		if ((pktsts != OTG_FS_GRXSTSP_PKTSTS_OUT) &&
		    (pktsts != OTG_FS_GRXSTSP_PKTSTS_SETUP))
			return;

		u8 ep = rxstsp & OTG_FS_GRXSTSP_EPNUM_MASK;
		u8 type;
		if (pktsts == OTG_FS_GRXSTSP_PKTSTS_SETUP)
			type = USB_TRANSACTION_SETUP;
		else
			type = USB_TRANSACTION_OUT;

		/* Save packet size for stm32f107_ep_read_packet(). */
		rxbcnt = (rxstsp & OTG_FS_GRXSTSP_BCNT_MASK) >> 4;

		/*
		 * FIXME: Why is a delay needed here?
		 * This appears to fix a problem where the first 4 bytes
		 * of the DATA OUT stage of a control transaction are lost.
		 */
		for (i = 0; i < 1000; i++)
			__asm__("nop");

		if (_usbd_device.user_callback_ctr[ep][type])
			_usbd_device.user_callback_ctr[ep][type] (ep);

		/* Discard unread packet data. */
		for (i = 0; i < rxbcnt; i += 4)
			(void)*OTG_FS_FIFO(ep);

		rxbcnt = 0;
	}