示例#1
0
static int write_ep0_fifo(struct rt_ep_struct *rt_ep, struct rt_request *req)
{
	u8	*buf;
	int	length, i;
	u32 maxpacket;

DBG;
	xprintk("q.l=%d, q.a=%d, maxp=%d\n", req->req.length, req->req.actual, rt_ep->ep.maxpacket);

	buf = req->req.buf + req->req.actual;
	maxpacket = (u32)(rt_ep->ep.maxpacket);
	length = min(req->req.length - req->req.actual, maxpacket);

	req->req.actual += length;

	if (!length && req->req.zero)
		FATAL_ERROR("zlp");

	if(!in_irq())
		FATAL_ERROR("Not in irq context");

	//write to ep0in fifo
	for (i=0; i< length; i++)
		usb_write(EP0INDAT+i, *buf++);

	// arm ep0in
	usb_write(IN0BC, length);
	if(length != rt_ep->ep.maxpacket)
		usb_write(EP0CS, 0x2);		// clear NAK bit to ACK host.

	return length;
}
示例#2
0
/*
 * 	udc_disable - disable USB device controller
 */
static void udc_disable(struct lh7a40x_udc *dev)
{
	DEBUG("%s, %p\n", __FUNCTION__, dev);

	udc_set_address(dev, 0);

	/* Disable interrupts */
	usb_write(0, USB_IN_INT_EN);
	usb_write(0, USB_OUT_INT_EN);
	usb_write(0, USB_INT_EN);

	/* Disable the USB */
	usb_write(0, USB_PM);

#ifdef CONFIG_ARCH_LH7A404
	/* Disable USB power */
	set_portc_dr(1, 0);
#endif

	/* if hardware supports it, disconnect from usb */
	/* make_usb_disappear(); */

	dev->ep0state = WAIT_FOR_SETUP;
	dev->gadget.speed = USB_SPEED_UNKNOWN;
	dev->usb_address = 0;
}
示例#3
0
static void rt_all_eps_reset(void)
{
	// reset(toggle & fifo) all 16 IN & 16 OUT endpoints
	usb_write(ENDPRST, 0x10);
	usb_write(ENDPRST, 0x70);
	usb_write(ENDPRST, 0x00);
	usb_write(ENDPRST, 0x60);
}
示例#4
0
static void write_epcs(struct rt_ep_struct *rt_ep, u8 val)
{
	int idx = EP_NO(rt_ep);
	int dir = EP_DIR(rt_ep);

	if(idx == 0)
		usb_write(EP0CS, val);
	else
		(dir == EP_IN ? /*IN */ usb_write(0x7 + idx*8, val) : usb_write(0x3 + idx*8, val) );
}
示例#5
0
u16 cdc_tx(u8 *buf, u16 size){
  static __bit require_ZLP = FALSE;
#ifdef CDC_IS_REPLACED_BY_FTDI
#define TX_BUF_HEADER 2
  static __xdata u8 tx_packet[CDC_DATA_EP_IN_PACKET_SIZE-1] = {
      (HEADER0_SIGN | HEADER0_RI),    // 0x41 
      (HEADER1_THRE | HEADER1_TEMT)}; // 0x60
#else
#define TX_BUF_HEADER 0
  static __xdata u8 tx_packet[CDC_DATA_EP_IN_PACKET_SIZE];
#endif
  static __xdata u8 margin = sizeof(tx_packet) - TX_BUF_HEADER;
  u16 written = 0;
  u8 retry;
  if(size == 0){ // flush
    if(margin < (sizeof(tx_packet) - TX_BUF_HEADER)){
      if(usb_write(tx_packet, sizeof(tx_packet) - margin, CDC_DATA_EP_IN) > 0){
        if((sizeof(tx_packet) == CDC_DATA_EP_IN_PACKET_SIZE) && (margin == 0)){
          require_ZLP = TRUE;
        }else{
          require_ZLP = FALSE;
        }
        margin = sizeof(tx_packet) - TX_BUF_HEADER;
      }
    }
    if(require_ZLP){
      require_ZLP = FALSE;
      usb_write(NULL, 0, CDC_DATA_EP_IN);
    }
    return 0;
  }
  do{
    if(size < margin){
      memcpy(&(tx_packet[sizeof(tx_packet) - margin]), buf, size);
      written += size;
      margin -= size;
      break;
    }
    memcpy(&(tx_packet[sizeof(tx_packet) - margin]), buf, margin);
    buf += margin;
    size -= margin;
    for(retry = 0; retry < 200; ++retry){ // timeout is approximately 1ms.
      if(usb_write(tx_packet, sizeof(tx_packet), CDC_DATA_EP_IN)){
        if(sizeof(tx_packet) == CDC_DATA_EP_IN_PACKET_SIZE){
          require_ZLP = TRUE;
        }
        break;
      }
      wait_us(5);
    }
    written += margin;
    margin = sizeof(tx_packet) - TX_BUF_HEADER;
  }while(size);
  return written;
}
示例#6
0
int usb_boot(
	struct usb_handle *usb, void *data, unsigned sz, const char *rootfs)
{
	const uint32_t msg_boot  = 0xF0030002;
	uint32_t msg_size = sz;
	int i;
	pthread_t thread;
	struct thread_vars vars;
	struct termios tn;
	struct file_data fd_vector[MAX_OPEN_FILES];

	if (read_asic_id(usb))
		return -1;

	printf("sending xload to target...\n");
	usleep(1000);
	usb_write(usb, &msg_boot, sizeof(msg_boot));
	usleep(1000);
	usb_write(usb, &msg_size, sizeof(msg_size));
	usleep(1000);
	usb_write(usb, data, sz);
	usleep(100000);
	munmap(data, msg_size);
	for (i = 0; i < MAX_OPEN_FILES; i++)
		fd_vector[i].data = NULL;

	vars.usb = usb;
	pthread_mutex_init(&vars.usb_mutex, NULL);
	tcgetattr(STDIN_FILENO, &vars.t_restore);
	tn = vars.t_restore;
	tn.c_lflag &= ~(ICANON | ECHO);
	printf(TFORMAT, TARGET_FORMAT);
	tcsetattr(STDIN_FILENO, TCSANOW, &tn);
	if (pthread_create(&thread, NULL, listenerTask, &vars))
		host_print("listenerTask failed\n");
	for (;;) {
		usleep(100);
		if (usb_read(usb, &i, 4) != 4)
			break;
		if (i == USBBOOT_FS_MAGIC) {
			usleep(100);
			pthread_mutex_lock(&vars.usb_mutex);
			process_file(usb, rootfs, fd_vector, &vars.t_restore);
			pthread_mutex_unlock(&vars.usb_mutex);
			continue;
		}
		printf("%c", i);
		fflush(stdout);
	}
	usb_close(usb);
	pthread_mutex_destroy(&vars.usb_mutex);
	tcsetattr(STDIN_FILENO, TCSANOW, &vars.t_restore);
	printf(HFORMAT, HOST_FORMAT);
	return 0;
}
示例#7
0
uint8_t custom_command(struct u2f_hid_msg * msg)
{
	struct atecc_response res;
	uint8_t ec;

	if (msg->cid != U2FHID_BROADCAST) return 0;

	switch(msg->pkt.init.cmd)
	{
		case U2F_CUSTOM_GET_RNG:
			if (atecc_send_recv(ATECC_CMD_RNG,ATECC_RNG_P1,ATECC_RNG_P2,
				NULL, 0,
				appdata.tmp,
				sizeof(appdata.tmp), &res) == 0 )
			{
				memmove(msg->pkt.init.payload, res.buf, 32);
				U2FHID_SET_LEN(msg, 32);
				usb_write((uint8_t*)msg, 64);
			}
			else
			{
				U2FHID_SET_LEN(msg, 0);
				usb_write((uint8_t*)msg, 64);
			}

			break;
		case U2F_CUSTOM_SEED_RNG:
			ec = atecc_send_recv(ATECC_CMD_NONCE,ATECC_NONCE_RNG_UPDATE,0,
							msg->pkt.init.payload, 20,
							appdata.tmp,
							sizeof(appdata.tmp), &res);
			U2FHID_SET_LEN(msg, 1);
			msg->pkt.init.payload[0] = ec == 0 ? 1 : 0;
			usb_write((uint8_t*)msg, 64);
			break;
		case U2F_CUSTOM_WIPE_KEYS:

			U2FHID_SET_LEN(msg, 1);
			ec=u2f_wipe_keys();
			msg->pkt.init.payload[0] = ec == 0 ? 1 : 0;
			usb_write((uint8_t*)msg, 64);

			break;

		case U2F_CUSTOM_WINK:

			app_wink(U2F_COLOR_WINK);

			break;

		default:
			return 0;
	}
	return 1;
}
示例#8
0
static void rt_ep_rst(struct rt_ep_struct *rt_ep)
{
	u8 reg = 0;
	u8 idx = EP_NO(rt_ep);
	u8 dir = EP_DIR(rt_ep);
	if(dir == EP_IN )
		reg |= ENDPRST_IO | idx;
	usb_write(ENDPRST, reg);

	reg |= ENDPRST_TOGRST | ENDPRST_FIFORST;
	usb_write(ENDPRST, reg);	        
}
示例#9
0
static void rt_udc_init_fifo(struct rt_udc_struct *rt_usb)
{
	// fifo control
	usb_write(FIFOCTRL, 0x11);	// INEP1, Autoin = 0
	usb_write(FIFOCTRL, 0x12);	// INEP2, Autoin = 0
	usb_write(FIFOCTRL, 0x01);	// OUTEP1, Autoin = 0
	usb_write(FIFOCTRL, 0x02);	// OUTEP2, Autoin = 0
	//usb_write(FIFOCTRL, 0x03);// OUTEP3, Autoin = 0
	//usb_write(FIFOCTRL, 0x04);// OUTEP4, Autoin = 0

	usb_write(FIFOCTRL, 0x80);	// Access by CPU
}
bool UsbConnection::Write(apacket* packet) {
    int size = packet->msg.data_length;

    if (usb_write(handle_, &packet->msg, sizeof(packet->msg)) != sizeof(packet->msg)) {
        PLOG(ERROR) << "remote usb: 1 - write terminated";
        return false;
    }

    if (packet->msg.data_length != 0 && usb_write(handle_, packet->payload.data(), size) != size) {
        PLOG(ERROR) << "remote usb: 2 - write terminated";
        return false;
    }

    return true;
}
示例#11
0
void on_msc_sent(EP_CLASS ep, void *param)
{
	USB_MSC* msc = (USB_MSC*)param;
	unsigned int block_size;
	switch (msc->state)
	{
	case MSC_STATE_DATA:
		queue_release_buffer(msc->queue, msc->current_buf);
		msc->current_buf = NULL;
		if (msc->scsi_transferred < msc->scsi_requested)
		{
			ASSERT(!queue_is_empty(msc->queue));
			msc->current_buf = queue_pull_ms(msc->queue, INFINITE);
			block_size = msc->scsi_requested - msc->scsi_transferred;
			if (block_size > msc->block_size)
				block_size = msc->block_size;
			msc->scsi_transferred += block_size;
			usb_write(usbd_get_usb(msc->usbd), EP_IN(msc->ep_num), msc->current_buf, block_size);
		}
		else
			event_set(msc->event);
		break;
	case MSC_STATE_CSW:
		msc->state = MSC_STATE_CSW_SENT;
		msc_send_csw(msc);
		break;
	case MSC_STATE_CSW_SENT:
		msc->state = MSC_STATE_CBW;
		//same buffer will be used for next cbw
		usb_read(usbd_get_usb(msc->usbd), EP_OUT(msc->ep_num), msc->current_buf, CBW_SIZE);
		break;
	default:
		break;
	}
}
示例#12
0
void usbd_on_out_readed(EP_CLASS ep, void* param)
{
	USBD* usbd = (USBD*)param;
#if (USB_DEBUG_FLOW)
	printf("USB EP0 OUT RX\n\r");
#endif
	switch (usbd->setup_state)
	{
	case USB_SETUP_STATE_DATA_OUT:
		usbd->setup_state = USB_SETUP_STATE_STATUS_IN;
		usb_write(usbd->idx, EP_IN0, NULL, 0);
		break;
	case USB_SETUP_STATE_STATUS_OUT:
		usbd->setup_state = USB_SETUP_STATE_REQUEST;
		usb_read(USB_1, EP_OUT0, usbd->control.buf, usbd->ep0_size);
		usbd_request_completed(usbd);
		break;
	default:
		usbd->setup_state = USB_SETUP_STATE_REQUEST;
		usb_read(USB_1, EP_OUT0, usbd->control.buf, usbd->ep0_size);
#if (USB_DEBUG_ERRORS)
		dbg_invalid_state(USB_SETUP_STATE_DATA_OUT, usbd->setup_state);
#endif
		break;
	}
}
void mlo_erase()
{
	static unsigned MSG = 0xaabbccdd;
	int ret = 0;
	u8 val;
	/*Enable USB mux pin cfg  enable USB clock */	
	enable_irqs();
	if (usb_open(&usbdev))
		return -1;

	ret = mmc_init(1);
	if (ret != 0){
		printf("\n MMC init failed \n");
		goto error;
	}

	ret = mmc_erase(1, (1024*128/MMC_BLOCK_SIZE), 1024*128);

	usb_write(&usbdev, &MSG, 4);
	/*power off  PMIC */
	printf("erase ret %d Powering off!\n", ret);
	select_bus(CFG_I2C_BUS, CFG_I2C_SPEED);
	val = SWITCH_OFF;
	i2c_write(TWL6030_PMC_ID, PHOENIX_DEV_ON, 1, &val, 1);
	/* we should never get here */
error:
	hang();
}
示例#14
0
void write_pedal(pedal_data *pedal) {
    unsigned char data[8];
    int arr_ind = 0, data_ind = 0;

    usb_write(pedal->header);
    memset(data, 0, 8);
    while (arr_ind < pedal->data_len) {
        if (data_ind == 8) {
            usb_write(data);
            memset(data, 0, 8);
            data_ind = 0;
        }
        data[data_ind++] = pedal->data[arr_ind++];
    }
    usb_write(data);
}
示例#15
0
/**********************************************
 函数说明:初始化usb看门狗
**********************************************/
int usb_watchdog_start(struct ys_usb_handle *handle,unsigned char flag)
{
    unsigned int headersize;
    unsigned int *head_ptr;
    unsigned char *buffer;
    
    headersize = sizeof(struct usb_app_header);
    buffer = (unsigned char *)malloc(headersize);
    if(buffer==NULL){
        //ysprint();
        return -1;
    }
    memset(buffer,0,headersize);
    head_ptr = (unsigned int *)buffer;
        
    if(flag==1){
        head_ptr[0] = CMD_WATCHDOG_START;
        head_ptr[1] = 0;
        head_ptr[2] = 0;
        head_ptr[3] = 0;  
    }else if(flag==2){
        head_ptr[0] = CMD_HEADER1;
        head_ptr[1] = CMD_HEADER2;
        head_ptr[2] = CMD_WATCHDOG_START;
        head_ptr[3] = 0;        
    }  
    
    usb_write(handle,buffer,headersize);  
    
    free(buffer);
    buffer = NULL;    
    
    return 0;
}
示例#16
0
/*
 * handle_epinirq()
*/
static int write_ep_fifo(struct rt_ep_struct *rt_ep, struct rt_request *req)
{
	u8	*buf, epcs;
	int	length, i, ep_no = EP_NO(rt_ep);

DBG;
	xprintk("w ep%d req=%p,r.l=%d,r.a=%d\n",EP_NO(rt_ep),&req->req,req->req.length,req->req.actual);
	epcs = read_epcs(rt_ep);
	if(epcs & EP_CS_BSY)
		FATAL_ERROR("EP%d busy. epcs=%x\n", ep_no, epcs);

	/* check INEP byte count is zero? */
	if(read_inbc(ep_no))
		FATAL_ERROR("EP%d bc=%d\n", ep_no, read_inbc(ep_no));

	buf = req->req.buf + req->req.actual;
	length = (req->req.length - req->req.actual) < rt_ep->ep.maxpacket ? (req->req.length - req->req.actual) : rt_ep->ep.maxpacket;
	req->req.actual += length;
	if (!length) {	/* zlp */
		// for debug
		xprintk("<%s> zero packet\n", __func__);
		write_ep_fifo_zlp(rt_ep);
		return 0;
	}

	// write to ep in fifo
	for (i=0; i< length; i++)
		usb_write(0x80+ep_no*4, *buf++);

	epcs = read_epcs(rt_ep);
	write_epcs(rt_ep, epcs);

	return length;
}
示例#17
0
/* Inline code */
static __inline__ int write_packet(struct s3c_ep *ep,
				   struct s3c_request *req, int max)
{
	u16 *buf;
	int length, count;
	u32 fifo = ep->fifo;

	buf = req->req.buf + req->req.actual;
	prefetch(buf);

	length = req->req.length - req->req.actual;
	length = min(length, max);
	req->req.actual += length;

	DEBUG("%s: Write %d (max %d), fifo=0x%x\n",
		__FUNCTION__, length, max, fifo);

	usb_write(length, (u32) S3C_UDC_BYTE_WRITE_CNT_REG, ep_index(ep));


	for (count=0;count<length;count+=2) {
	  		__raw_writel(*buf++, fifo);
	}
	
	return length;
}
static int remote_write(apacket *p, atransport *t)
{
    unsigned size = p->msg.data_length;

    if(usb_write(t->usb, &p->msg, sizeof(amessage))) {
        D("remote usb: 1 - write terminated\n");
        return -1;
    }
    if(p->msg.data_length == 0) return 0;
    if(usb_write(t->usb, &p->data, size)) {
        D("remote usb: 2 - write terminated\n");
        return -1;
    }

    return 0;
}
示例#19
0
u16 cdc_tx(u8 *buf, u16 size){
#ifdef CDC_IS_REPLACED_BY_FTDI
#define TX_BUF_HEADER 2
  static __xdata u8 tx_packet[CDC_DATA_EP_IN_PACKET_SIZE-1] = {
      (HEADER0_SIGN | HEADER0_RI),    // 0x41 
      (HEADER1_THRE | HEADER1_TEMT)}; // 0x60
#else
#define TX_BUF_HEADER 0
  static __xdata u8 tx_packet[CDC_DATA_EP_IN_PACKET_SIZE-1];
#endif
  static __xdata u8 margin = sizeof(tx_packet) - TX_BUF_HEADER;
  u16 written = 0;
  u8 retry;
  while(size){
    if(size < margin){
      memcpy(&(tx_packet[sizeof(tx_packet) - margin]), buf, size);
      written += size;
      margin -= size;
      break;
    }
    memcpy(&(tx_packet[sizeof(tx_packet) - margin]), buf, margin);
    buf += margin;
    size -= margin;
    for(retry = 0; retry < 20; ++retry){ // timeout is approximately 1ms.
      if(usb_write(tx_packet, sizeof(tx_packet), CDC_DATA_EP_IN)){break;}
      wait_us(50);
    }
    written += margin;
    margin = sizeof(tx_packet) - TX_BUF_HEADER;
  }
  return written;
}
示例#20
0
/* Send an arbitrary frame, consisting of an 8 byte header and an optional
 * packet body. */
static bool __hfa_send_frame(struct cgpu_info *hashfast, uint8_t opcode, int tx_length,
			     uint8_t *packet)
{
	struct hashfast_info *info = hashfast->device_data;
	int ret, amount, id = hashfast->device_id;
	bool retried = false;

	if (unlikely(hashfast->usbinfo.nodev))
		return false;

	info->last_send = time(NULL);
	applog(LOG_DEBUG, "%s %d: Sending %s frame", hashfast->drv->name, hashfast->device_id, hfa_cmds[opcode].cmd_name);
retry:
	ret = usb_write(hashfast, (char *)packet, tx_length, &amount,
			hfa_cmds[opcode].usb_cmd);
	if (unlikely(ret < 0 || amount != tx_length)) {
		if (hashfast->usbinfo.nodev)
			return false;
		if (!retried) {
			applog(LOG_ERR, "%s %d: hfa_send_frame: USB Send error, ret %d amount %d vs. tx_length %d, retrying",
			       hashfast->drv->name, id, ret, amount, tx_length);
			retried = true;
			goto retry;
		}
		applog(LOG_ERR, "%s %d: hfa_send_frame: USB Send error, ret %d amount %d vs. tx_length %d",
		       hashfast->drv->name, id, ret, amount, tx_length);
		return false;
	}

	if (retried)
		applog(LOG_ERR, "%s %d: hfa_send_frame: recovered OK", hashfast->drv->name, id);

	return true;
}
示例#21
0
bool cmd_send(uint32_t cmd, uint32_t arg0, uint32_t arg1, uint32_t arg2, void* data, size_t len) {

	UsbCommand txcmd;

	// 0x00 the whole command.
	for (size_t i=0; i < sizeof(UsbCommand); i++)
		((byte_t*)&txcmd)[i] = 0x00;

	// Compose the outgoing command frame
	txcmd.cmd = cmd;
	txcmd.arg[0] = arg0;
	txcmd.arg[1] = arg1;	
	txcmd.arg[2] = arg2;

	// Add the (optional) content to the frame, with a maximum size of USB_CMD_DATA_SIZE
	if (data && len) {
		len = MIN(len, USB_CMD_DATA_SIZE);
		for (size_t i=0; i<len; i++) {
			txcmd.d.asBytes[i] = ((byte_t*)data)[i];
		}
	}

	// Send frame and make sure all bytes are transmitted
	if ( usb_write( (byte_t*)&txcmd, sizeof(UsbCommand)) != 0)
		return false;

	return true;
}
示例#22
0
static void rt_ep_irq_disable(struct rt_ep_struct *rt_ep)
{
	u8 reg;
	u8 idx = EP_NO(rt_ep);
	u8 dir = EP_DIR(rt_ep);

	if(idx == 0 /* ep0 */){
		usb_write(IN07IEN, (usb_read(IN07IEN) & ~(0x1)) );
		usb_write(OUT07IEN, (usb_read(OUT07IEN) & ~(0x1)) );
	}else{
		reg = usb_read(dir ? IN07IEN : OUT07IEN);
		reg = reg & ~(0x1 << idx);
		usb_write(dir == EP_IN ? IN07IEN : OUT07IEN, reg);
		reg = usb_read(dir ? IN07IEN : OUT07IEN);
	}
}
示例#23
0
/**********************************************
 函数说明:判断当前程序处于bootloader还是app!返回
 1表示当前在bootloader,返回2表示当前在app。
**********************************************/
int At_UBLorAPP(struct ys_usb_handle *handle)
{
    int ret,actual_length;
    unsigned int headersize;
    unsigned int *head_ptr;
    unsigned char *buffer,rxdata[1];
    
    headersize = sizeof(struct usb_app_header);
    buffer = (unsigned char *)malloc(headersize);
    if(buffer==NULL){
        //ysprint();
        return -1;
    }
    memset(buffer,0,headersize);
    head_ptr = (unsigned int *)buffer;
        
    head_ptr[0] = CMD_ATUBLORNOT;
    head_ptr[1] = 0;
    head_ptr[2] = 0;
    head_ptr[3] = 0;  
    
    usb_write(handle,buffer,headersize);  
    
    free(buffer);
    buffer = NULL;    

    //等待dsp返回
	ret = libusb_bulk_transfer(handle->libusb_handle,handle->Endpoint_in,rxdata,sizeof(rxdata),&actual_length,100);
	if(ret<0){
		return 2;
	}else{
		if(rxdata[0]==10) return 1;
		else return 0;
	}   
}
示例#24
0
static bool hfa_send_frame(struct cgpu_info *hashfast, uint8_t opcode, uint16_t hdata,
                           uint8_t *data, int len)
{
    int tx_length, ret, amount, id = hashfast->device_id;
    uint8_t packet[256];
    struct hf_header *p = (struct hf_header *)packet;

    p->preamble = HF_PREAMBLE;
    p->operation_code = hfa_cmds[opcode].cmd;
    p->chip_address = HF_GWQ_ADDRESS;
    p->core_address = 0;
    p->hdata = htole16(hdata);
    p->data_length = len / 4;
    p->crc8 = hfa_crc8(packet);

    if (len)
        memcpy(&packet[sizeof(struct hf_header)], data, len);
    tx_length = sizeof(struct hf_header) + len;

    applog(LOG_DEBUG, "HFA %d: Sending %s frame", hashfast->device_id, hfa_cmds[opcode].cmd_name);
    ret = usb_write(hashfast, (char *)packet, tx_length, &amount,
                    hfa_cmds[opcode].usb_cmd);
    if (unlikely(ret < 0 || amount != tx_length)) {
        applog(LOG_ERR, "HFA %d: hfa_send_frame: USB Send error, ret %d amount %d vs. tx_length %d",
               id, ret, amount, tx_length);
        return false;
    }
    return true;
}
示例#25
0
static void bitforce_flash_led(struct cgpu_info *bitforce)
{
	int err, amount;

	/* Do not try to flash the led if we're polling for a result to
	 * minimise the chance of interleaved results */
	if (bitforce->polling)
		return;

	/* It is not critical flashing the led so don't get stuck if we
	 * can't grab the mutex now */
	if (mutex_trylock(&bitforce->device_mutex))
		return;

	if ((err = usb_write(bitforce, BITFORCE_FLASH, BITFORCE_FLASH_LEN, &amount, C_REQUESTFLASH)) < 0 || amount != BITFORCE_FLASH_LEN) {
		applog(LOG_ERR, "%s%i: flash request failed (%d:%d)",
			bitforce->drv->name, bitforce->device_id, amount, err);
	} else {
		/* However, this stops anything else getting a reply
		 * So best to delay any other access to the BFL */
		sleep(4);
	}

	/* Once we've tried - don't do it until told to again */
	bitforce->flash_led = false;

	mutex_unlock(&bitforce->device_mutex);

	return; // nothing is returned by the BFL
}
示例#26
0
static int gc3355_write_data(struct cgpu_info *gridseed, unsigned char *data, int size)
{
	int err, wrote;

#if 1
	if (!opt_quiet && opt_debug) {
		int i;
#ifndef WIN32
		printf(" >>> %d : ", size);
#else
		set_text_color(FOREGROUND_RED|FOREGROUND_GREEN);
		printf(" >>> %d : ", size);
		set_text_color(FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
#endif
		for(i=0; i<size; i++) {
			printf("%02x", data[i]);
			if (i==3)
				printf(" ");
		}
		printf("\n");
	}
#endif
	err = usb_write(gridseed, data, size, &wrote, C_SENDWORK);
	if (err != LIBUSB_SUCCESS || wrote != size)
		return -1;
	return 0;
}
void cmd_download(const char *arg, void *data, unsigned sz)
{
	char response[MAX_RSP_SIZE];
	unsigned len = hex2unsigned(arg);
	u32 available_memory=0;
	int r;

	init_display_xy();
	download_size = 0;
	available_memory = memory_size()-(u32)download_base;

	dprintf(DBG_LV, "Enter cmd_download Data Length:%d, available_memory:%d\n", len, available_memory);

	if (len > download_max)
	{
		dprintf(DBG_LV, "Data is larger than all partitions size in target.\n");
		fastboot_fail_wrapper("Data is larger than all partitions size in target");
		return;
	}

	if(is_use_ex_download())
	{
		if(available_memory < MEMORY_SIZE_REQ)
		{
			dprintf(DBG_LV, "Insufficient memory for DCACHE\n");
			fastboot_fail_wrapper("Insufficient memory for DCACHE");
			return;
		}
	}
	else
	{
		if (len > available_memory)
		{
			dprintf(DBG_LV, "Insufficient memory for whole image\n");
			fastboot_fail_wrapper("Insufficient memory for whole image");
			return;
		}
	}


	snprintf(response, MAX_RSP_SIZE, "DATA%08x", len);
	if (usb_write(response, strlen(response)) < 0)
	{
		return;
	}

	if(is_use_ex_download())
	{
		//use ex download
		download_ex(len);
	}
	else
	{
		//use normal download
		download_standard(len);
	}

	return;
}
示例#28
0
// writes what has been buffered and clears memory
void u2f_hid_flush()
{
	if (_hid_offset)
	{
		usb_write(_hid_pkt, HID_PACKET_SIZE);
	}
	u2f_hid_reset_packet();
}
void
Xbox360WirelessController::set_led_real(uint8_t status)
{
  //                                +--- Why not just status?
  //                                v
  uint8_t ledcmd[] = { 0x00, 0x00, 0x08, 0x40 + (status % 0x0e), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  usb_write(m_endpoint, ledcmd, sizeof(ledcmd));
}
void
Xbox360WirelessController::set_rumble_real(uint8_t left, uint8_t right)
{
  //                                       +-- typo? might be 0x0c, i.e. length
  //                                       v
  uint8_t rumblecmd[] = { 0x00, 0x01, 0x0f, 0xc0, 0x00, left, right, 0x00, 0x00, 0x00, 0x00, 0x00 };
  usb_write(m_endpoint, rumblecmd, sizeof(rumblecmd));
}