Exemple #1
0
static void PIOS_USB_CDC_CTRL_EP_IN_Callback(void)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	PIOS_Assert(valid);

	/* Give back UART State Bitmap */
	/* UART State Bitmap
	 *   15-7: reserved
	 *      6:  bOverRun    overrun error
	 *      5:  bParity     parity error
	 *      4:  bFraming    framing error
	 *      3:  bRingSignal RI
	 *      2:  bBreak      break reception
	 *      1:  bTxCarrier  DSR
	 *      0:  bRxCarrier  DCD
	 */
	uart_state.bmUartState = htousbs(0x0003);

	UserToPMABufferCopy((uint8_t *) &uart_state,
			GetEPTxAddr(usb_cdc_dev->cfg->ctrl_tx_ep),
			sizeof(uart_state));
	SetEPTxCount(usb_cdc_dev->cfg->ctrl_tx_ep, PIOS_USB_BOARD_CDC_MGMT_LENGTH);
	SetEPTxValid(usb_cdc_dev->cfg->ctrl_tx_ep);
}
Exemple #2
0
static void PIOS_USB_CDC_DATA_EP_IN_Callback(void)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	PIOS_Assert(valid);

	PIOS_USB_CDC_SendData(usb_cdc_dev);
}
Exemple #3
0
RESULT PIOS_USB_CDC_SetLineCoding(void)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	PIOS_Assert(valid);

	return USB_SUCCESS;
}
Exemple #4
0
static bool PIOS_USB_CDC_Available (uintptr_t usbcdc_id)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)usbcdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	PIOS_Assert(valid);

	return (PIOS_USB_CheckAvailable(usb_cdc_dev->lower_id) &&
		(control_line_state & USB_CDC_CONTROL_LINE_STATE_DTE_PRESENT));
}
Exemple #5
0
static void PIOS_USB_CDC_DATA_EP_OUT_Callback(void)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	PIOS_Assert(valid);

	uint32_t DataLength;

	/* Get the number of received data on the selected Endpoint */
	DataLength = GetEPRxCount(usb_cdc_dev->cfg->data_rx_ep);
	if (DataLength > sizeof(usb_cdc_dev->rx_packet_buffer)) {
		usb_cdc_dev->rx_oversize++;
		DataLength = sizeof(usb_cdc_dev->rx_packet_buffer);
	}

	/* Use the memory interface function to read from the selected endpoint */
	PMAToUserBufferCopy((uint8_t *) usb_cdc_dev->rx_packet_buffer,
			GetEPRxAddr(usb_cdc_dev->cfg->data_rx_ep),
			DataLength);

	if (!usb_cdc_dev->rx_in_cb) {
		/* No Rx call back registered, disable the receiver */
		SetEPRxStatus(usb_cdc_dev->cfg->data_rx_ep, EP_RX_NAK);
		return;
	}

	uint16_t headroom;
	bool need_yield = false;
	uint16_t rc;
	rc = (usb_cdc_dev->rx_in_cb)(usb_cdc_dev->rx_in_context,
				usb_cdc_dev->rx_packet_buffer,
				DataLength,
				&headroom,
				&need_yield);

	if (rc < DataLength) {
		/* Lost bytes on rx */
		usb_cdc_dev->rx_dropped += (DataLength - rc);
	}

	if (headroom >= sizeof(usb_cdc_dev->rx_packet_buffer)) {
		/* We have room for a maximum length message */
		SetEPRxStatus(usb_cdc_dev->cfg->data_rx_ep, EP_RX_VALID);
	} else {
		/* Not enough room left for a message, apply backpressure */
		SetEPRxStatus(usb_cdc_dev->cfg->data_rx_ep, EP_RX_NAK);
	}

#if defined(PIOS_INCLUDE_FREERTOS)
	if (need_yield) {
		vPortYieldFromISR();
	}
#endif	/* PIOS_INCLUDE_FREERTOS */
}
Exemple #6
0
static void PIOS_USB_CDC_RegisterTxCallback(uintptr_t usbcdc_id, pios_com_callback tx_out_cb, uintptr_t context)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)usbcdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	PIOS_Assert(valid);

	/* 
	 * Order is important in these assignments since ISR uses _cb
	 * field to determine if it's ok to dereference _cb and _context
	 */
	usb_cdc_dev->tx_out_context = context;
	usb_cdc_dev->tx_out_cb = tx_out_cb;
}
Exemple #7
0
const uint8_t *PIOS_USB_CDC_GetLineCoding(uint16_t Length)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	PIOS_Assert(valid);

	if (Length == 0) {
		pInformation->Ctrl_Info.Usb_wLength = sizeof(line_coding);
		return NULL;
	} else {
		return ((uint8_t *) &line_coding);
	}
}
Exemple #8
0
RESULT PIOS_USB_CDC_SetControlLineState(void)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	PIOS_Assert(valid);

	static uint16_t control_line_state;

	uint8_t wValue0 = pInformation->USBwValue0;
	uint8_t wValue1 = pInformation->USBwValue1;

	control_line_state = wValue1 << 8 | wValue0;

	return USB_SUCCESS;
}
Exemple #9
0
RESULT PIOS_USB_CDC_SetControlLineState(void)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	if (!valid) {
		/* No CDC interface is configured */
		return USB_UNSUPPORT;
	}

	uint8_t wValue0 = pInformation->USBwValue0;
	uint8_t wValue1 = pInformation->USBwValue1;

	control_line_state = wValue1 << 8 | wValue0;

	return USB_SUCCESS;
}
Exemple #10
0
static void PIOS_USB_CDC_TxStart(uintptr_t usbcdc_id, uint16_t tx_bytes_avail)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)usbcdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	PIOS_Assert(valid);

	if (!PIOS_USB_CheckAvailable(usb_cdc_dev->lower_id)) {
		return;
	}

	if (GetEPTxStatus(usb_cdc_dev->cfg->data_tx_ep) == EP_TX_VALID) {
		/* Endpoint is already transmitting */
		return;
	}

	PIOS_USB_CDC_SendData(usb_cdc_dev);
}
Exemple #11
0
static void PIOS_USB_CDC_RxStart(uintptr_t usbcdc_id, uint16_t rx_bytes_avail) {
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)usbcdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	PIOS_Assert(valid);

	if (!PIOS_USB_CheckAvailable(usb_cdc_dev->lower_id)) {
		return;
	}

	// If endpoint was stalled and there is now space make it valid
	PIOS_IRQ_Disable();
	if ((GetEPRxStatus(usb_cdc_dev->cfg->data_rx_ep) != EP_RX_VALID) && 
		(rx_bytes_avail >= sizeof(usb_cdc_dev->rx_packet_buffer))) {
		SetEPRxStatus(usb_cdc_dev->cfg->data_rx_ep, EP_RX_VALID);
	}
	PIOS_IRQ_Enable();
}
Exemple #12
0
uint8_t *PIOS_USB_CDC_SetLineCoding(uint16_t Length)
{
	struct pios_usb_cdc_dev * usb_cdc_dev = (struct pios_usb_cdc_dev *)pios_usb_cdc_id;

	bool valid = PIOS_USB_CDC_validate(usb_cdc_dev);
	if (!valid) {
		/* No CDC interface is configured */
		return NULL;
	}

	if (Length == 0) {
		/* Report the number of bytes we're prepared to consume */
		pInformation->Ctrl_Info.Usb_wLength = sizeof(line_coding);
		pInformation->Ctrl_Info.Usb_rLength = sizeof(line_coding);
		return NULL;
	} else {
		/* Give out a pointer to the data struct */
		return ((uint8_t *) &line_coding);
	}
}