Example #1
0
vsf_err_t usbtomicrowire_transport(uint8_t index,
								uint32_t opcode, uint8_t opcode_bitlen,
								uint32_t addr, uint8_t addr_bitlen,
								uint32_t data, uint8_t data_bitlen,
								uint8_t *reply, uint8_t reply_bitlen)
{
	uint8_t reply_bytelen = (reply_bitlen + 7) / 8;
	uint16_t offset;
	
#if PARAM_CHECK
	if (index > 7)
	{
		LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, index);
		return VSFERR_FAIL;
	}
	if ((opcode_bitlen > 32) || (addr_bitlen > 32) ||
		(data_bitlen > 32) || (reply_bitlen > 32))
	{
		return VSFERR_FAIL;
	}
#endif
	
	usbtoxxx_info->cmd_buff[0] = opcode_bitlen;
	usbtoxxx_info->cmd_buff[1] = addr_bitlen;
	usbtoxxx_info->cmd_buff[2] = data_bitlen;
	usbtoxxx_info->cmd_buff[3] = reply_bitlen;
	
	offset = 4;
	if (opcode_bitlen)
	{
		SET_LE_U32(&usbtoxxx_info->cmd_buff[offset], opcode);
		offset += 4;
	}
	if (addr_bitlen)
	{
		SET_LE_U32(&usbtoxxx_info->cmd_buff[offset], addr);
		offset += 4;
	}
	if (data_bitlen)
	{
		SET_LE_U32(&usbtoxxx_info->cmd_buff[offset], data);
		offset += 4;
	}
	
	return usbtoxxx_inout_command(USB_TO_MICROWIRE, index,
		usbtoxxx_info->cmd_buff, offset, reply_bytelen, reply,
		0, reply_bytelen, 1);
}
Example #2
0
RESULT usbtojtagraw_execute(uint8_t interface_index, uint8_t *tdi,
							uint8_t *tms, uint8_t *tdo, uint32_t bitlen)
{
	uint16_t bytelen;
	
#if PARAM_CHECK
	if (interface_index > 7)
	{
		LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
		return ERROR_FAIL;
	}
#endif
	
	if (bitlen > 8 * 0xFFFF)
	{
		return ERROR_FAIL;
	}
	bytelen = (uint16_t)((bitlen + 7) >> 3);
	
	SET_LE_U32(&versaloon_cmd_buf[0], bitlen);
	memcpy(versaloon_cmd_buf + 4, tdi, bytelen);
	memcpy(versaloon_cmd_buf + 4 + bytelen, tms, bytelen);
	
	return usbtoxxx_inout_command(USB_TO_JTAG_RAW, interface_index,
			versaloon_cmd_buf, 4 + bytelen * 2, bytelen, tdo, 0, bytelen, 0);
}
Example #3
0
static vsf_err_t vsfusbd_CDCACMControl_request_prepare(struct vsfusbd_device_t *device)
{
	struct vsfusbd_ctrl_handler_t *ctrl_handler = &device->ctrl_handler;
	struct vsf_buffer_t *buffer = &ctrl_handler->bufstream.mem.buffer;
	struct usb_ctrlrequest_t *request = &ctrl_handler->request;
	uint8_t iface = request->wIndex;
	struct vsfusbd_config_t *config = &device->config[device->configuration];
	struct vsfusbd_CDCACM_param_t *param =
		(struct vsfusbd_CDCACM_param_t *)config->iface[iface].protocol_param;
	struct usb_CDCACM_line_coding_t *line_coding = &param->line_coding;

	switch (request->bRequest)
	{
	case USB_CDCACMREQ_SET_LINE_CODING:
		if ((request->wLength != 7) || (request->wValue != 0))
		{
			return VSFERR_FAIL;
		}
		buffer->buffer = param->line_coding_buffer;
		buffer->size = 7;
		break;
	case USB_CDCACMREQ_GET_LINE_CODING:
		if ((request->wLength != 7) || (request->wValue != 0))
		{
			return VSFERR_FAIL;
		}
		SET_LE_U32(&param->line_coding_buffer[0], line_coding->bitrate);
		param->line_coding_buffer[4] = line_coding->stopbittype;
		param->line_coding_buffer[5] = line_coding->paritytype;
		param->line_coding_buffer[6] = line_coding->datatype;
		buffer->buffer = param->line_coding_buffer;
		buffer->size = 7;
		break;
	case USB_CDCACMREQ_SET_CONTROL_LINE_STATE:
		if ((request->wLength != 0) ||
			(request->wValue & ~USBCDCACM_CONTROLLINE_MASK))
		{
			return VSFERR_FAIL;
		}
		param->control_line = (uint8_t)request->wValue;
		if ((param->callback.set_control_line != NULL) &&
			(param->callback.set_control_line(param->control_line)))
		{
			return VSFERR_FAIL;
		}
		break;
	case USB_CDCACMREQ_SEND_BREAK:
		if ((request->wLength != 0) ||
			((param->callback.send_break != NULL) &&
			 	param->callback.send_break()))
		{
			return VSFERR_FAIL;
		}
		break;
	default:
		return vsfusbd_CDCControl_class.request_prepare(device);
	}
	ctrl_handler->data_size = buffer->size;
	return VSFERR_NONE;
}
Example #4
0
static vsf_err_t vsfusbd_CDCACMControl_GetLineCoding_prepare(
	struct vsfusbd_device_t *device, struct vsf_buffer_t *buffer,
		uint8_t* (*data_io)(void *param))
{
	struct usb_ctrl_request_t *request = &device->ctrl_handler.request;
	uint8_t iface = request->index;
	struct vsfusbd_config_t *config = &device->config[device->configuration];
	struct vsfusbd_CDCACM_param_t *param = 
		(struct vsfusbd_CDCACM_param_t *)config->iface[iface].protocol_param;
	struct vsfusbd_CDCACM_line_coding_t *line_coding = &param->line_coding;
	
	if ((NULL == param) || (request->length != 7) || (request->value != 0))
	{
		return VSFERR_FAIL;
	}
	
	SET_LE_U32(&param->line_coding_buffer[0], line_coding->bitrate);
	param->line_coding_buffer[4] = line_coding->stopbittype;
	param->line_coding_buffer[5] = line_coding->paritytype;
	param->line_coding_buffer[6] = line_coding->datatype;
	buffer->buffer = param->line_coding_buffer;
	buffer->size = 7;
	
	return VSFERR_NONE;
}
Example #5
0
vsf_err_t usbtoclko_config(uint8_t index, uint32_t kHz)
{
	uint8_t cmdbuf[4];
	
	SET_LE_U32(cmdbuf, kHz);
	return usbtoxxx_conf_command(USB_TO_CLKO, index, cmdbuf, 4);
}
Example #6
0
static vsf_err_t vsfusbd_MSCBOT_SendCSW(struct vsfusbd_device_t *device, 
							struct vsfusbd_MSCBOT_param_t *param)
{
	struct interface_usbd_t *drv = device->drv;
	uint8_t CSW_buffer[USBMSC_CSW_SIZE];
	
	param->poll = false;
	
	SET_LE_U32(&CSW_buffer[0], USBMSC_CSW_SIGNATURE);
	SET_LE_U32(&CSW_buffer[4], param->CBW.dCBWTag);
	SET_LE_U32(&CSW_buffer[8], 
		param->CBW.dCBWDataTransferLength - 
		(param->page_size * param->cur_usb_page + param->tbuffer.position));
	CSW_buffer[12] = param->dCSWStatus;
	param->cur_usb_page = param->tbuffer.position = 0;
	param->page_size = USBMSC_CSW_SIZE;
	param->page_num = 1;
	param->tbuffer.buffer.buffer = CSW_buffer;
	param->bot_status = VSFUSBD_MSCBOT_STATUS_CSW;
	
	drv->ep.write_IN_buffer(param->ep_in, CSW_buffer, USBMSC_CSW_SIZE);
	drv->ep.set_IN_count(param->ep_in, USBMSC_CSW_SIZE);
	return VSFERR_NONE;
}
Example #7
0
RESULT usbtojtagraw_config(uint8_t interface_index, uint32_t kHz)
{
	uint8_t cfg_buf[4];

#if PARAM_CHECK
	if (interface_index > 7) {
		LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
		return ERROR_FAIL;
	}
#endif

	SET_LE_U32(&cfg_buf[0], kHz);

	return usbtoxxx_conf_command(USB_TO_JTAG_RAW, interface_index, cfg_buf, 4);
}
Example #8
0
vsf_err_t usbtoswim_wotf(uint8_t index, uint8_t *data, uint16_t bytelen,
						uint32_t addr)
{
#if PARAM_CHECK
	if (index > 7)
	{
		LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, index);
		return VSFERR_FAIL;
	}
#endif
	
	SET_LE_U16(&usbtoxxx_info->cmd_buff[0], bytelen);
	SET_LE_U32(&usbtoxxx_info->cmd_buff[2], addr);
	memcpy(&usbtoxxx_info->cmd_buff[6], data, bytelen);
	
	return usbtoxxx_out_command(USB_TO_SWIM, index,
								usbtoxxx_info->cmd_buff, bytelen + 6, 0);
}
Example #9
0
void USB_TO_ADC_ProcessCmd(uint8_t *dat, uint16_t len)
{
	uint16_t index, length;
	uint8_t command, device_idx;
	
	uint32_t clock_hz;
	uint8_t mode;
	uint8_t channel;
	uint8_t cycles;
	uint32_t adc_result;
	
	index = 0;
	while(index < len)
	{
		command = dat[index] & USB_TO_XXX_CMDMASK;
		device_idx = dat[index] & USB_TO_XXX_IDXMASK;
		length = GET_LE_U16(&dat[index + 1]);
		index += 3;
		
		switch(command)
		{
		case USB_TO_XXX_INIT:
			if (0 == device_idx)
			{
				interfaces->adc.init(0);
				buffer_reply[rep_len++] = USB_TO_XXX_OK;
			}
			else
			{
				buffer_reply[rep_len++] = USB_TO_XXX_FAILED;
			}
			break;
		case USB_TO_XXX_CONFIG:
			if (0 == device_idx)
			{
				clock_hz = GET_LE_U32(&dat[index]);
				mode = dat[index + 4];
				interfaces->adc.config(0, clock_hz, mode);
				buffer_reply[rep_len++] = USB_TO_XXX_OK;
			}
			else
			{
				buffer_reply[rep_len++] = USB_TO_XXX_FAILED;
			}
			break;
		case USB_TO_XXX_FINI:
			if (0 == device_idx)
			{
				interfaces->adc.fini(0);
				buffer_reply[rep_len++] = USB_TO_XXX_OK;
			}
			else
			{
				buffer_reply[rep_len++] = USB_TO_XXX_FAILED;
			}
			break;
		case USB_TO_XXX_IN_OUT:
			if (0 == device_idx)
			{
				channel = dat[index + 0];
				interfaces->adc.sample(0, channel, &adc_result);
				buffer_reply[rep_len++] = USB_TO_XXX_OK;
				SET_LE_U32(&buffer_reply[rep_len], adc_result);
			}
			else
			{
				buffer_reply[rep_len++] = USB_TO_XXX_FAILED;
			}
			rep_len += 4;
			break;
		case USB_TO_XXX_OUT:
			if (0 == device_idx)
			{
				channel = dat[index + 0];
				cycles = dat[index + 1];
				interfaces->adc.config_channel(0, channel, cycles);
				buffer_reply[rep_len++] = USB_TO_XXX_OK;
			}
			else
			{
				buffer_reply[rep_len++] = USB_TO_XXX_FAILED;
			}
			break;
		case USB_TO_XXX_SPECIAL:
			if (0 == device_idx)
			{
				channel = dat[index + 0];
				interfaces->adc.calibrate(0, channel);
				buffer_reply[rep_len++] = USB_TO_XXX_OK;
			}
			else
			{
				buffer_reply[rep_len++] = USB_TO_XXX_FAILED;
			}
			break;
		default:
			buffer_reply[rep_len++] = USB_TO_XXX_CMD_NOT_SUPPORT;
			break;
		}
		index += length;
	}
}