Beispiel #1
0
void uhi_cdc_sof(bool b_micro)
{
	uint8_t port = 0;
	uhi_cdc_port_t *ptr_port;
	UNUSED(b_micro);

	if (uhi_cdc_dev.dev == NULL) {
		return; // No interface to installed
	}

	if (!uhi_cdc_dev.b_enabled) {
		return; // Interface not enabled
	}

	// Update transfers on each port
	while (1) {
		ptr_port = uhi_cdc_get_port(port++);

		if (ptr_port == NULL)
			break;

		uhi_cdc_rx_update(&ptr_port->line_rx);
		uhi_cdc_tx_update(&ptr_port->line_tx);
	}
}
Beispiel #2
0
uint32_t uhi_cdc_read_buf(uint8_t port, void *buf, uint32_t size)
{
	uhi_cdc_port_t *ptr_port;
	uhi_cdc_line_t *line;
	uhi_cdc_buf_t *cdc_buf;
	uint32_t copy_nb;

	// Select port
	ptr_port = uhi_cdc_get_port(port);

	if (ptr_port == NULL)
		return false;

	line = &ptr_port->line_rx;


uhi_cdc_read_buf_loop_wait:
	// Check available data
	cdc_buf = &line->buffer[line->buf_sel];

	while (cdc_buf->pos >= cdc_buf->nb) {
		if (NULL == uhi_cdc_get_port(port))
			return 0;

		uhi_cdc_rx_update(line);
		goto uhi_cdc_read_buf_loop_wait;
	}

	// Read data
	copy_nb = cdc_buf->nb - cdc_buf->pos;

	if (copy_nb > size)
		copy_nb = size;

	memcpy(buf, &cdc_buf->ptr[cdc_buf->pos], copy_nb);
	cdc_buf->pos += copy_nb;
	buf = (uint8_t *)buf + copy_nb;
	size -= copy_nb;

	uhi_cdc_rx_update(line);

	if (size)
		goto uhi_cdc_read_buf_loop_wait;

	return 0;
}
Beispiel #3
0
int uhi_cdc_getc(uint8_t port)
{
	uhi_cdc_port_t *ptr_port;
	uhi_cdc_line_t *line;
	uhi_cdc_buf_t *buf;
	int rx_data = 0;
	bool b_databit_9;

	// Select port
	ptr_port = uhi_cdc_get_port(port);

	if (ptr_port == NULL)
		return false;

	line = &ptr_port->line_rx;

	b_databit_9 = (9 == ptr_port->conf.bDataBits);

uhi_cdc_getc_process_one_byte:
	// Check available data
	buf = &line->buffer[line->buf_sel];

	while (buf->pos >= buf->nb) {
		if (NULL == uhi_cdc_get_port(port))
			return 0;

		uhi_cdc_rx_update(line);
		goto uhi_cdc_getc_process_one_byte;
	}

	// Read data
	rx_data |= buf->ptr[buf->pos];
	buf->pos++;

	uhi_cdc_rx_update(line);

	if (b_databit_9) {
		// Receive MSB
		b_databit_9 = false;
		rx_data = rx_data << 8;
		goto uhi_cdc_getc_process_one_byte;
	}

	return rx_data;
}
Beispiel #4
0
static void uhi_cdc_rx_received(
	USBHS_Add_t add,
	USBHS_Ep_t ep,
	USBH_XfrStatus_t status,
	uint32_t nb_transferred)
{
	uint8_t port = 0;
	uhi_cdc_port_t *ptr_port;
	uhi_cdc_line_t *line;
	uhi_cdc_buf_t *buf;
	UNUSED(add);

	// Search port corresponding at endpoint
	while (1) {
		ptr_port = uhi_cdc_get_port(port++);

		if (ptr_port == NULL)
			return;

		line = &ptr_port->line_rx;

		if (ep == line->ep_data) {
			break; // Port found
		}
	}

	if (UHD_TRANS_NOERROR != status) {
		// Abort transfer
		line->b_trans_ongoing  = false;
		return;
	}

	// Update SOF tag, if it is a short packet
	if (nb_transferred != line->buffer_size) {
		if (uhi_cdc_dev.dev->speed == UHD_SPEED_HIGH)
			line->sof = USBH_HAL_GetMicroFrameNum();
		else
			line->sof = USBH_HAL_GetFrameNum();
	}

	USBHS_SCB_InvalidateDCache_by_Addr((uint32_t *) line->buffer[line->buf_sel].ptr,
									   nb_transferred);

	// Update buffer structure
	buf = &line->buffer[(line->buf_sel == 0) ? 1 : 0];
	buf->pos = 0;
	buf->nb = nb_transferred;
	line->b_trans_ongoing  = false;

	// Manage new transfer
	uhi_cdc_rx_update(line);
}
Beispiel #5
0
static void uhi_cdc_rx_received(
		usb_add_t add,
		usb_ep_t ep,
		uhd_trans_status_t status,
		iram_size_t nb_transferred)
{
	uint8_t port = 0;
	uhi_cdc_port_t *ptr_port;
	uhi_cdc_line_t *line;
	uhi_cdc_buf_t *buf;
	UNUSED(add);

	// Search port corresponding at endpoint
	while (1) {
		ptr_port = uhi_cdc_get_port(port++);
		if (ptr_port == NULL) {
			return;
		}
		line = &ptr_port->line_rx;
		if (ep == line->ep_data) {
			break; // Port found
		}
	}

	if ((UHD_TRANS_TIMEOUT == status) && nb_transferred) {
		// Save transfered
	}
	else if (UHD_TRANS_NOERROR != status) {
		// Abort transfer
		line->b_trans_ongoing  = false;
		return;
	}

	// Update SOF tag, if it is a short packet
	if (nb_transferred != line->buffer_size) {
		if (uhi_cdc_dev.dev->speed == UHD_SPEED_HIGH) {
			line->sof = uhd_get_microframe_number();
		} else {
			line->sof = uhd_get_frame_number();
		}
	}

	// Update buffer structure
	buf = &line->buffer[(line->buf_sel == 0) ? 1 : 0];
	buf->pos = 0;
	buf->nb = nb_transferred;
	line->b_trans_ongoing  = false;

	// Manage new transfer
	uhi_cdc_rx_update(line);
}