コード例 #1
0
/////////////////////////////////////////////////////////////////////////////
// WAITING
int SMQWaiting()
{
    int result = 0;
    vos_lock_mutex(&mAccess);
    if(head != tail)
        result = 1;
    vos_unlock_mutex(&mAccess);
    return result;
}
コード例 #2
0
/////////////////////////////////////////////////////////////////////////////
// READ
void SMQRead(SMQ_MSG *msg)
{
    vos_wait_semaphore(&semAvailable);
    vos_lock_mutex(&mAccess);
    if(head == tail)
    {
        vos_unlock_mutex(&mAccess);
    }
    else
    {
        msg->status = queue[tail].status;
        msg->param1 = queue[tail].param1;
        msg->param2 = queue[tail].param2;
        if(++tail >= SMQ_LEN)
            tail = 0;
        vos_unlock_mutex(&mAccess);
    }
}
コード例 #3
0
ファイル: Playpad.c プロジェクト: hotchk155/Playpad-Shield
void fifo_write(FIFO_TYPE *pfifo, unsigned char *data, int count)
{	
	int i;
	for(i=0; i<count; ++i)
	{
		vos_wait_semaphore(&pfifo->semWrite);	
		vos_lock_mutex(&pfifo->mutex);
		pfifo->data[pfifo->head] = data[i]; 
		pfifo->head = FIFO_INC(pfifo->head);
		vos_unlock_mutex(&pfifo->mutex);
	}
	vos_signal_semaphore(&pfifo->semRead);	
}
コード例 #4
0
ファイル: Playpad.c プロジェクト: hotchk155/Playpad-Shield
int fifo_read(FIFO_TYPE *pfifo, unsigned char *data, int size)
{
	int count = 0;
	vos_wait_semaphore(&pfifo->semRead);	
	vos_lock_mutex(&pfifo->mutex);
	while(count < size && pfifo->tail != pfifo->head)
	{
		data[count] = pfifo->data[pfifo->tail];		
		pfifo->tail = FIFO_INC(pfifo->tail);	
		vos_signal_semaphore(&pfifo->semWrite);	
		++count;
	}
	vos_unlock_mutex(&pfifo->mutex);
	return count;
}
コード例 #5
0
int incHead(int oldHe

/////////////////////////////////////////////////////////////////////////////
// WRITE
            void SMQWrite(uint8 tag, uint8 device, int size, uint8 *data)
{
    int newHead;
    vos_lock_mutex(&mAccess);

    newHead = head + 1;
    if(newHead >= SMQ_LEN)
        newHead = 0;
    if(newHead != tail)
    {
        queue[head].status = msg->status;
        queue[head].param1 = msg->param1;
        queue[head].param2 = msg->param2;
        head = newHead;
        vos_signal_semaphore(&semAvailable);
    }
    vos_unlock_mutex(&mAccess);
}
コード例 #6
0
// handle requests for a descriptor
void get_descriptor_request(usbSlaveBoms_context *ctx)
{
	unsigned char *buffer;  // buffer for pass thru to drive
	usbhost_ioctl_cb_t hc_ioctl;
	usbslave_ioctl_cb_t iocb;
	usb_deviceRequest_t *devReq;
	unsigned char hValue; // high byte of the descriptor requested
	unsigned char lValue; // low byte of the descriptor requested
	unsigned short wLength;
	unsigned short siz;
	uint32 ul_siz;
	unsigned char *src;
	unsigned char cond;
	tmr_ioctl_cb_t tmr_iocb;

	devReq = (usb_deviceRequest_t *) ctx->setup_buffer;

	hValue = devReq->wValue >> 8; // shift away the low byte
	lValue = devReq->wValue & 0xff; // and away the high byte

	wLength = devReq->wLength;

	switch (hValue) // the high byte determines type of descriptor requested
	{
	case USB_DESCRIPTOR_TYPE_DEVICE:
		ul_siz = (uint32) wLength;
		iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER;
		iocb.handle = ctx->in_ep0;
		// update the device descriptor VID/PID from our list
		vos_lock_mutex(&vidPidMutex);
		device_descriptor[8] = vidPid[currentVidPidIndex] & 0xff;
		device_descriptor[9] = vidPid[currentVidPidIndex] >> 8;
		device_descriptor[10] = vidPid[currentVidPidIndex+1] & 0xff;
		device_descriptor[11] = vidPid[currentVidPidIndex+1] >> 8;
		vos_unlock_mutex(&vidPidMutex);
		//updated LCD
		update_lcd_vidpid();

		iocb.request.setup_or_bulk_transfer.buffer = device_descriptor;
		iocb.request.setup_or_bulk_transfer.size = (int16) ul_siz;
		vos_dev_ioctl(ctx->handle, &iocb);

		// start this timer and if it is not killed then the next VID/PID will be selected
		// this is done to detect an unsuccessful enumeration which is assumed
		// to result from endpoint security blocking
		if (autoMode)
		{
			tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_START;
			vos_dev_ioctl(hTimer, &tmr_iocb);
		}
		return;
		break;

	case USB_DESCRIPTOR_TYPE_CONFIGURATION:
		// host will initially ask for first 9 bytes of configuration descriptor
		// this descriptor header has the size of the full descriptor which
		// is actually a composite of the configuration/interface/endpoints.
		// Once host knows the complete descriptor size it makes a second
		// request for the whole thing
		siz = wLength == 9?9:sizeof(config_descriptor);
		ul_siz = (uint32) siz;

		iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER;
		iocb.handle = ctx->in_ep0;
		iocb.request.setup_or_bulk_transfer.buffer = config_descriptor;
		iocb.request.setup_or_bulk_transfer.size = (int16) ul_siz;
		vos_dev_ioctl(ctx->handle, &iocb);

		// stop the timer because we are being asked to enumerate
		if(autoMode)
		{
			tmr_iocb.ioctl_code = VOS_IOCTL_TIMER_STOP;
			vos_dev_ioctl(hTimer, &tmr_iocb);
		}
		return;

	case USB_DESCRIPTOR_TYPE_STRING:

		if (lValue == 0) // language type
		{
			src = str0_descriptor;
			siz = sizeof(str0_descriptor);
		}
		else if (lValue == 1) // manufacturer
		{
			src = str1_descriptor;
			siz = sizeof(str1_descriptor);
		}
		else if (lValue == 2) // product
		{
			src = str2_descriptor;
			siz = sizeof(str2_descriptor);
		}
		else if (lValue == 3) // serial number
		{
			src = str3_descriptor;
			siz = sizeof(str3_descriptor);
		}

		cond = (unsigned char) (wLength != siz);

		if (siz > wLength) // don't return more than was asked for
			siz = wLength;

		ul_siz = (uint32) siz;

		iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER;
		iocb.handle = ctx->in_ep0;
		iocb.request.setup_or_bulk_transfer.buffer = src;
		iocb.request.setup_or_bulk_transfer.size = (int16) ul_siz;
		vos_dev_ioctl(ctx->handle, &iocb);
		return;

	default:
		// if drive is connected get descriptor from it
		if (ctx->flashConnected)
		{
			buffer = vos_malloc(wLength);
			hc_ioctl.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER;
			hc_ioctl.handle.ep = hostBomsCtx->epCtrl;
			hc_ioctl.set = &(ctx->setup_buffer[0]);
			hc_ioctl.get = buffer; // descriptor from drive
			vos_dev_ioctl(hostBomsCtx->hc, &hc_ioctl);

			iocb.ioctl_code = VOS_IOCTL_USBSLAVE_SETUP_TRANSFER;
			iocb.handle = ctx->in_ep0;
			iocb.request.setup_or_bulk_transfer.buffer = buffer;
			iocb.request.setup_or_bulk_transfer.size = wLength;
			vos_dev_ioctl(ctx->handle, &iocb);

			vos_free(buffer);
		} else {
			// respond with Request Error
			set_control_ep_halt(ctx);
		}
	}
}