Ejemplo n.º 1
0
////////////////////////////////////////////////////////////////////
// Main application thread
void RunPlaypad()
{
	SMQ_MSG msg;	
	
	// wait for setup to complete
	vos_wait_semaphore(&setupSem);
	vos_signal_semaphore(&setupSem);
		
	arpie_init();
	
	for(;;)
	{
		SMQRead(&msg);
		switch(msg.status)
		{
			case 0x80:
			case 0x90:
				if(msg.status == 0x80 || msg.param2 == 0)
				{
					arpie_event(EVENT_KEYUP, msg.param1/16, msg.param1%16);
				}
				else
				{
					arpie_event(EVENT_KEYDOWN, msg.param1/16, msg.param1%16);
				}
				break;
			case 0xf8: // clock tick
				arpie_event(EVENT_TICK, 0, 0);
				break;
		}
	}
}
Ejemplo n.º 2
0
void CreateKeystrokes(BYTE ThreadID) {
// Wait for the keyboard to be enumerated then send keystrokes
// Owns KeyboardMessage at startup
    vos_semaphore_t ReturnedSemaphore;
    BYTE Report[8];
    BYTE i = 0;
    memset(&Report[0], 0, sizeof(Report));
    WaitForDevicesStarted();
    vos_init_semaphore(&ReturnedSemaphore, 0);
    vos_wait_semaphore(&EnumerationComplete);
    dprint("\nEnumeration complete, sending keystrokes ", 0);
    KeyboardMessage.ReportBuffer = &Report[0];
    KeyboardMessage.ReportLength = sizeof(Report);
    KeyboardMessage.ResponseSemaphore = &ReturnedSemaphore;
    while (1) {
        Report[0] = ModifierCodes[i];
        Report[2] = UsageCodes[i];
        i_vos_signal_semaphore(ThreadID, &SendKeyboardReport);  // Keydown
        i_vos_wait_semaphore(ThreadID, &ReturnedSemaphore);
        i_vos_delay_msecs(ThreadID, 50);
        Report[0] = 0;
        Report[2] = 0;
        i_vos_signal_semaphore(ThreadID, &SendKeyboardReport);  // Keyup
        i_vos_wait_semaphore(ThreadID, &ReturnedSemaphore);
        i_vos_delay_msecs(ThreadID, 200);
        if (++i >= sizeof(UsageCodes)) {
            i=0;
            i_vos_delay_msecs(ThreadID, 1000);
            }
        }
    }
Ejemplo n.º 3
0
//////////////////////////////////////////////////////////////////////
//
// THREAD FUNCTION TO RUN MIDI INPUT
//
//////////////////////////////////////////////////////////////////////
void RunMIDIInput()
{
	SMQ_MSG msg;
	unsigned short num_read;
	byte uch;
	
	// wait for setup to complete
	vos_wait_semaphore(&setupSem);
	vos_signal_semaphore(&setupSem);
	
	for(;;)
	{
		vos_dev_read(hUART, &uch, 1, &num_read);
		if(num_read > 0)
		{
			if(uch == 0xf8)
			{
				msg.status = 0xf8;
				msg.param1 = 0x00;
				msg.param2 = 0x00;
				SMQWrite(&msg);
			}
		}
	}
	
}
Ejemplo n.º 4
0
void HelloWorld(void) {
    BYTE Counter = 0;
    vos_wait_semaphore(&DevicesStarted);
    vos_signal_semaphore(&DevicesStarted);
    dprint("Hello World has started\n", 0);
    while (1) {
        vos_delay_msecs(1000);
        dprint("Hello World %d ", &Counter++);
        }
    }
Ejemplo n.º 5
0
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);	
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
void RunUSBSend()
{
	unsigned char attached;
	uint8 msg[3];
	int param = 1;	
	int i;
	unsigned short bytes_written;
	VOS_HANDLE hUSB;
	
	// wait for setup to complete
	vos_wait_semaphore(&setupSem);
	vos_signal_semaphore(&setupSem);
	
	msg[0] = 0;
	while(1)
	{
		int count = fifo_read(&stSPIReadFIFO, usbSendBuffer, 64);
		for(i=0;i<count;++i)
		{
			if(usbSendBuffer[i]&0x80)
			{				
				msg[0] = usbSendBuffer[i];
				param = 1;
			}
			else if(param == 1)
			{
				msg[1] = usbSendBuffer[i];
				param = 2;
			}
			else if(param == 2)
			{
				msg[2] = usbSendBuffer[i];
				param = 1;
				if(msg[0])
				{
					VOS_ENTER_CRITICAL_SECTION;
					hUSB = PortA.hUSBHOSTGENERIC;
					VOS_EXIT_CRITICAL_SECTION;
					if(hUSB)
					{
						vos_dev_write(hUSB, msg, 3, &bytes_written);						
					}
				}
			}		
		}
	}
}
Ejemplo n.º 8
0
void RunSPISend()
{
	unsigned short bytes_written;
	
	
	// wait for setup to complete
	vos_wait_semaphore(&setupSem);
	vos_signal_semaphore(&setupSem);

	while(1)
	{
		int count = fifo_read(&stSPIWriteFIFO, spiSendBuffer, 64);		
		vos_dev_write(hSPISlave, spiSendBuffer, (unsigned short)count, &bytes_written);		
		setGpioA(LED_SIGNAL,0); 
		setGpioA(LED_SIGNAL,LED_SIGNAL|LED_ACTIVITY); 		
		
	}
}
Ejemplo n.º 9
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);
    }
}
Ejemplo n.º 10
0
void RunSPIReceive()
{
	unsigned short bytes_read;
	
	common_ioctl_cb_t spi_iocb;
	
	// wait for setup to complete
	vos_wait_semaphore(&setupSem);
	vos_signal_semaphore(&setupSem);

	while(1)
	{
		spi_iocb.ioctl_code = VOS_IOCTL_COMMON_GET_RX_QUEUE_STATUS;
		vos_dev_ioctl(hSPISlave, &spi_iocb);
		if(spi_iocb.get.queue_stat)
		{
			if(0==vos_dev_read(hSPISlave, (char*)spiRxBuffer, spi_iocb.get.queue_stat, &bytes_read))
				fifo_write(&stSPIReadFIFO, spiRxBuffer, (int)bytes_read);
		}
	}
}
Ejemplo n.º 11
0
/////////////////////////////////////////////////////////////////////
// Thread to dispatch tick events to the playpad thread
// at timed intervals
void RunMetronome() 
{
	SMQ_MSG tick;		
	
	// wait for setup to complete
	vos_wait_semaphore(&setupSem);
	vos_signal_semaphore(&setupSem);
	
	// Prepare standard tick message
	tick.status = 0xf8;
	tick.param1 = 0x00;
	tick.param2 = 0x00;
	
	// Start the metronome
	MetroStart(&metro, VOS_DEV_TIMER0, 120);
	for(;;) 
	{
		// run!
		SMQWrite(&tick);
		MetroDelay(&metro);
	}
}
Ejemplo n.º 12
0
void i_vos_wait_semaphore(BYTE ThreadID, vos_semaphore_t* s) {
    CallVOS(ThreadID);
    vos_wait_semaphore(s);
    ThreadRunning(ThreadID);
    }
Ejemplo n.º 13
0
//////////////////////////////////////////////////////////////////////
//
// RUN USB HOST PORT
//
//////////////////////////////////////////////////////////////////////
void RunHostPort(HOST_PORT_DATA *pHostData)
{
	int i;
	int midiParam;
	unsigned char status;
	unsigned char buf[64];	
	unsigned short num_bytes;
	unsigned int handle;
	usbhostGeneric_ioctl_t generic_iocb;
	usbhostGeneric_ioctl_cb_attach_t genericAtt;
	usbhost_device_handle_ex ifDev;
	usbhost_ioctl_cb_t hc_iocb;
	usbhost_ioctl_cb_vid_pid_t hc_iocb_vid_pid;
	gpio_ioctl_cb_t gpio_iocb;
	VOS_HANDLE hUSB;

	// wait for setup to complete
	vos_wait_semaphore(&setupSem);
	vos_signal_semaphore(&setupSem);
	
	// Open the base USB Host driver
	pHostData->hUSBHOST = vos_dev_open(pHostData->uchDeviceNumberBase);
	
	// loop forever
	while(1)
	{
		vos_delay_msecs(10);
		// is the device enumerated on this port?
		if (usbhost_connect_state(pHostData->hUSBHOST) == PORT_STATE_ENUMERATED)
		{
			// user ioctl to find first hub device
			hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_NEXT_HANDLE;
			hc_iocb.handle.dif = NULL;
			hc_iocb.set = NULL;
			hc_iocb.get = &ifDev;
			if (vos_dev_ioctl(pHostData->hUSBHOST, &hc_iocb) == USBHOST_OK)
			{
				// query the device VID/PID
				hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_VID_PID;
				hc_iocb.handle.dif = ifDev;
				hc_iocb.get = &hc_iocb_vid_pid;
				
				// Load the function driver
				hUSB = vos_dev_open(pHostData->uchDeviceNumber);
				
				// Attach the function driver to the base driver
				genericAtt.hc_handle = pHostData->hUSBHOST;
				genericAtt.ifDev = ifDev;
				generic_iocb.ioctl_code = VOS_IOCTL_USBHOSTGENERIC_ATTACH;
				generic_iocb.set.att = &genericAtt;
				if (vos_dev_ioctl(hUSB, &generic_iocb) == USBHOSTGENERIC_OK)
				{					
					// Turn on the LED for this port
					setGpioA(pHostData->uchActivityLed, pHostData->uchActivityLed);

					// flag that the port is attached
					VOS_ENTER_CRITICAL_SECTION;
					pHostData->hUSBHOSTGENERIC = hUSB;
					VOS_EXIT_CRITICAL_SECTION;
										
					// now we loop until the launchpad is detached
					while(1)
					{
						// listen for data from launchpad
						uint16 result = vos_dev_read(hUSB, buf, 64, &num_bytes);
						if(0 != result)
							break; // break when the launchpad is detached						
						fifo_write(&stSPIWriteFIFO, buf, (int)num_bytes); 
					}					
					
					// flag that the port is no longer attached
					VOS_ENTER_CRITICAL_SECTION;
					pHostData->hUSBHOSTGENERIC = NULL;
					VOS_EXIT_CRITICAL_SECTION;
					
					// turn off the activity LED
					setGpioA(pHostData->uchActivityLed, 0);
				}
				
				// close the function driver
				vos_dev_close(hUSB);
			}
		}
	}
}	
Ejemplo n.º 14
0
// This function is run inside the thread created in init
// It will respond to standard USB requests
// some of the requests are forwarded to the flash drive when appropriate
void usbslaveboms_setup(usbSlaveBoms_context *ctx)
{
	usbslave_ioctl_cb_t iocb; // this is a structure used by underlying VOS driver
	usb_deviceRequest_t *devReq; // this struct is defined in usb.h and is used to store the 9 byte setup request
	unsigned char bmRequestType; // The request type is defined by USB standard
	unsigned char state = UNATTACHED;  // assume unattached at the start

	// This will wait till the flash drive is enumed so we don't
	// start responding to commands right away
	vos_wait_semaphore(&ctx->enumed);
	vos_signal_semaphore(&ctx->enumed);

	vos_wait_semaphore(&setupDoneSemaphore); // wait for setup to complete
	vos_signal_semaphore(&setupDoneSemaphore); // reset semaphore for next guy

	while (1)
	{
		switch (state)
		{
		case UNATTACHED:

			if (!ctx->attached)
				vos_delay_msecs(100); // this delay is to avoid a tight loop
			else
			{
				state = ATTACHED;
			}

			break;

		case ATTACHED:

			if (!ctx->attached) // check to see if we somehow became unattached
			{
				state = UNATTACHED;
				break;
			}

			// we now make a blocking call requesting the 9 byte setup
			// packet on the control endpoint
			iocb.ioctl_code = VOS_IOCTL_USBSLAVE_WAIT_SETUP_RCVD;
			iocb.request.setup_or_bulk_transfer.buffer = ctx->setup_buffer;
			iocb.request.setup_or_bulk_transfer.size = 9;
			vos_dev_ioctl(ctx->handle, &iocb);

			// decode the raw data by pointing to our structure
			devReq = (usb_deviceRequest_t *) ctx->setup_buffer;
			// valid types here are standard, class, and vendor
			// BOMS devices do not have vendor specific calls
			// even if they did, we wouldn't support them.
			bmRequestType = devReq->bmRequestType & (USB_BMREQUESTTYPE_STANDARD | USB_BMREQUESTTYPE_CLASS);

			// we only need to handle standard and class requests for BOMS
			if (bmRequestType == USB_BMREQUESTTYPE_STANDARD)
			{
				standard_request(ctx); // standard request that all USB devices support
			}
			else if (bmRequestType == USB_BMREQUESTTYPE_CLASS)
			{
				class_request(ctx); // the request is specific to this device class (only 2 in our case)
			}

			break;

		default:
			asm {HALT}; // if we somehow got here the fecal matter has hit the turbine
			break;
		}
	}

	return;
}
Ejemplo n.º 15
0
void WaitForDevicesStarted(void) {
    vos_wait_semaphore(&DevicesStarted);
    vos_signal_semaphore(&DevicesStarted);
    }
Ejemplo n.º 16
0
//////////////////////////////////////////////////////////////////////
//
// THREAD FUNCTION TO RUN USB HOST PORT
//
//////////////////////////////////////////////////////////////////////
void RunHostPort(HOST_PORT_DATA *pHostData)
{
	unsigned char status;
	unsigned char buf[64];
	unsigned short num_read;
	unsigned int handle;
	usbhostGeneric_ioctl_t generic_iocb;
	usbhostGeneric_ioctl_cb_attach_t genericAtt;
	usbhost_device_handle_ex ifDev;
	usbhost_ioctl_cb_t hc_iocb;
	usbhost_ioctl_cb_vid_pid_t hc_iocb_vid_pid;
	gpio_ioctl_cb_t gpio_iocb;

	SMQ_MSG msg;
	msg.status = 0x90;

	// wait for setup to complete
	vos_wait_semaphore(&setupSem);
	vos_signal_semaphore(&setupSem);

	// loop forever
	while(1)
	{
		// is the device enumerated on this port?
		if (usbhost_connect_state(pHostData->hUSBHOST) == PORT_STATE_ENUMERATED)
		{
			// user ioctl to find first hub device
			hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_NEXT_HANDLE;
			hc_iocb.handle.dif = NULL;
			hc_iocb.set = NULL;
			hc_iocb.get = &ifDev;
			if (vos_dev_ioctl(pHostData->hUSBHOST, &hc_iocb) == USBHOST_OK)
			{

				hc_iocb.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_VID_PID;
				hc_iocb.handle.dif = ifDev;
				hc_iocb.get = &hc_iocb_vid_pid;
				
				// attach the Launchpad device to the USB host device
				pHostData->hUSBHOSTGENERIC = vos_dev_open(pHostData->uchDeviceNumber);
				genericAtt.hc_handle = pHostData->hUSBHOST;
				genericAtt.ifDev = ifDev;
				generic_iocb.ioctl_code = VOS_IOCTL_USBHOSTGENERIC_ATTACH;
				generic_iocb.set.att = &genericAtt;
				if (vos_dev_ioctl(pHostData->hUSBHOSTGENERIC, &generic_iocb) == USBHOSTGENERIC_OK)
				{
					setLed(pHostData->uchActivityLed, 1);
					
					// now we loop until the launchpad is detached
					while(1)
					{
						int pos = 0;
						byte param = 1;
						
						// read data
						status = vos_dev_read(pHostData->hUSBHOSTGENERIC, buf, 64, &num_read);
						if(status != USBHOSTGENERIC_OK)
							break;
							
						setLed(pHostData->uchActivityLed, 0);

						// interpret MIDI data and pass to application thread
						
						while(pos < num_read)
						{
							if(buf[pos] & 0x80)
							{
								msg.status = buf[pos];
								param = 1;
							}
							else if(param == 1)
							{
								msg.param1 = buf[pos];
								param = 2;
							}
							else if(param == 2)
							{
								msg.param2 = buf[pos];
								SMQWrite(&msg);										
								param = 1;
							}
							++pos;
						}
						
						setLed(pHostData->uchActivityLed, 1);
					}					
				}
				vos_dev_close(pHostData->hUSBHOSTGENERIC);
			}
		}
		setLed(pHostData->uchActivityLed, 0);
	}
}