예제 #1
0
파일: TAM.c 프로젝트: jjturn/lb-boards
uint8 i_vos_dev_read(BYTE ThreadID, VOS_HANDLE h, BYTE* buffer, WORD len, WORD* read) {
    uint8 Value;
    CallVOS(ThreadID);
    Value = vos_dev_read(h, buffer, len, read);
    ThreadRunning(ThreadID);
    return Value;
    }
예제 #2
0
파일: TAM.c 프로젝트: jjturn/lb-boards
void CallVOS(BYTE ThreadID) {
// The thread is calling VOS and could loose the CPU
    BYTE PortData;
    vos_dev_read(hDevice[LA_In], &PortData, 1, NULL);
    PortData &= (ThreadID ^ 0xFF);
    vos_dev_write(hDevice[LA_Out], &PortData, 1, NULL);
    }
예제 #3
0
파일: TAM.c 프로젝트: jjturn/lb-boards
void ThreadRunning(BYTE ThreadID) {
// The thread now has the CPU
    BYTE PortData;
    vos_dev_read(hDevice[LA_In], &PortData, 1, NULL);
    PortData |= ThreadID;
    vos_dev_write(hDevice[LA_Out], &PortData, 1, NULL);
    }
예제 #4
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);
			}
		}
	}
	
}
예제 #5
0
//////////////////////////////////////////////////////////////////////
//
// SET LED
//
//////////////////////////////////////////////////////////////////////
void setLed(unsigned char mask, unsigned char value)
{
	unsigned char leds;
	vos_dev_read(hGpioA,&leds,1,NULL);
	if(value)
		leds |= mask;
	else
		leds &= ~mask;
	vos_dev_write(hGpioA,&leds,1,NULL);
}
예제 #6
0
파일: Host.c 프로젝트: jjturn/lb-boards
void GetIntIn(BYTE* BufferPtr, WORD BufferLength) {
    usbhost_xfer_t xfer;
    BYTE Status;
    vos_memset(&xfer, 0, sizeof(usbhost_xfer_t));
    xfer.s = &IntTransferComplete;
    xfer.ep = IntIn;
    xfer.buf = BufferPtr;
    xfer.len = BufferLength;
// Wait for a response packet from X10 controller
    Status = vos_dev_read(hDevice[Host], (BYTE*)&xfer, sizeof(usbhost_xfer_t), NULL);
    if (Status != USBHOST_OK) dprint("Get X10 packet Error (%d)\n", &Status);
    }
예제 #7
0
// USBHOSTBoms read function
unsigned char usbhostBoms_read(char *buf,
								  unsigned short num_to_read,
								  unsigned short *num_read,
								  usbhostBoms_context_t *ctx)
{
	unsigned short actual_read = 0;
	unsigned char status = USBHOSTBOMS_NOT_FOUND;
	usbhost_xfer_t xfer;
	vos_semaphore_t s;

	if (ctx->hc)
	{
		vos_init_semaphore(&s, 0);

		vos_memset(&xfer, 0, sizeof(usbhost_xfer_t));
		xfer.buf = buf;
		xfer.len = num_to_read;
		xfer.ep = ctx->epBulkIn;
		xfer.s = &s;
		xfer.cond_code = USBHOST_CC_NOTACCESSED;
		xfer.flags = USBHOST_XFER_FLAG_START_BULK_ENDPOINT_LIST | USBHOST_XFER_FLAG_ROUNDING;

		status = vos_dev_read(ctx->hc, (unsigned char *) &xfer, sizeof(usbhost_xfer_t), NULL);

		if (status == USBHOST_OK)
		{
			status = (unsigned char)USBHOSTBOMS_OK;
			actual_read = xfer.len;
		}
		else
		{
			status |= (unsigned char)USBHOSTBOMS_USBHOST_ERROR;
		}
	}

	if (num_read)
	{
		*num_read = actual_read;
	}

	return status;
}
예제 #8
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);
		}
	}
}
예제 #9
0
void firmware()
{
	int i;
	char bufmgk[20];
	int idxMgk = 0;
	FILE *pf;
	
	/* Thread code to be added here */
	vos_delay_msecs(4000);	// 4 second delay for USB key to boot
	open_drivers();
	InitializeUART();
	flash_init();
	InitializeHID();
	printf("DekaBoard Rev: 1B\n");
	vfWriteFlash = 0;
	
PROGRAM:
	

	if (FOpenUSBKey())
	{
		pf = fopen("deka.svf", "r");
		if (pf != NULL)
		{
			ProgramFPGA(pf);
			fclose(pf);
		}
		CloseUSBKey();
	}
	else
	{
		ProgramFPGA(FILE_FLASH);
	}
	
	while(1)
	{
		char tmp;
		
		// First check if PROG button pressed
		vos_dev_read(hGPIO_PORT_B, &tmp, 1, NULL);
		if (!(tmp & 0x20))
			goto PROGRAM;
			
		// Else handle input
		if (FUartData())
		{
			fread(bufmgk, 1, 1, stdin);
			if (bufmgk[0] == STR_MAGIC[idxMgk])
			{
				idxMgk++;
			}
			else
			{
				idxMgk = 0;
			}
			if(idxMgk == 20)
			{
				fwrite(UART_ACK, 1, 3, stdout);
				fgets(bufmgk, 20, stdin);
				if (strcmp(bufmgk, "PROG XSVF") == 0)
				{
					fgets(bufmgk, 20, stdin);
					vfWriteFlash = (strcmp(bufmgk, "FLASH") == 0);
					fwrite(UART_ACK, 1, 3, stdout);
					ProgramFPGA(stdin);
					vfWriteFlash = 0;
					printf("DONE\n");
				}
				else
				{
					printf(UART_NACK);
				}
				idxMgk = 0;
			}
		}
	}
}
예제 #10
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);
			}
		}
	}
}	
예제 #11
0
//////////////////////////////////////////////////////////////////////
//
// GET GPIO
//
//////////////////////////////////////////////////////////////////////
byte getGPIO()
{
	unsigned char gpio;
	vos_dev_read(hGpioA,&gpio,1,NULL);
	return gpio;
}
예제 #12
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);
	}
}	
예제 #13
0
//////////////////////////////////////////////////////////////////////
//
//     MM    MM  IIII  DDDDD   IIII
//    MMM  MMM   II   DD  DD   II
//   MM MM MM   II   DD  DD   II
//  MM    MM   II   DD  DD   II
// MM    MM  IIII  DDDDD   IIII
//
void run_midi_class_host(VOS_HANDLE usb_handle) 
{
	unsigned char state;
	int status;
	usbhost_device_handle_ex interface_handle;
	usbhost_ep_handle_ex tx_endpoint;
	usbhost_ep_handle_ex rx_endpoint;
	usbhost_ep_handle_ex ctrl_endpoint;
	vos_semaphore_t read_completion_event;
	usbhost_ioctl_cb_t usbhost_cmd;
	usbhost_ioctl_cb_class_t device_class;
	usbhost_ioctl_cb_vid_pid_t vid_pid;
	
	usbhost_xfer_t transfer_block;
	usb_deviceRequest_t device_request;
	usbhost_ioctl_cb_ep_info_t endpoint_descriptor;
	
	vos_init_semaphore(&read_completion_event, 0);
	
	device_class.dev_class = USB_CLASS_AUDIO;
	device_class.dev_subclass = USB_SUBCLASS_AUDIO_MIDISTREAMING;
	device_class.dev_protocol = USB_PROTOCOL_ANY;

	usbhost_cmd.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_FIND_HANDLE_BY_CLASS;
	usbhost_cmd.handle.dif = NULL;
	usbhost_cmd.set = &device_class;
	usbhost_cmd.get = &interface_handle;
	status = vos_dev_ioctl(usb_handle, &usbhost_cmd);
	if(USBHOST_OK != status) {
		return;
	}
		

	usbhost_cmd.ioctl_code = VOS_IOCTL_USBHOST_GET_USB_STATE;
	usbhost_cmd.handle.dif = interface_handle;
	usbhost_cmd.get = &state;
	usbhost_cmd.set = NULL;
	status = vos_dev_ioctl(usb_handle, &usbhost_cmd);
	if(USBHOST_OK != status) {
		return;
	}

	usbhost_cmd.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_VID_PID;
	usbhost_cmd.handle.dif = interface_handle;
	usbhost_cmd.get = &vid_pid;
	usbhost_cmd.set = NULL;
	status = vos_dev_ioctl(usb_handle, &usbhost_cmd);
	if(USBHOST_OK != status) {
		return;
	}
	
	usbhost_cmd.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_BULK_OUT_ENDPOINT_HANDLE;
	usbhost_cmd.handle.dif = interface_handle;
	usbhost_cmd.get = &tx_endpoint;
	usbhost_cmd.set = NULL;
	status = vos_dev_ioctl(usb_handle, &usbhost_cmd);
	if(USBHOST_OK != status) {
		return;
	}

	usbhost_cmd.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_BULK_IN_ENDPOINT_HANDLE;
	usbhost_cmd.handle.dif = interface_handle;
	usbhost_cmd.get = &rx_endpoint;
	usbhost_cmd.set = NULL;
	status = vos_dev_ioctl(usb_handle, &usbhost_cmd);
	if(USBHOST_OK != status) {
		return;
	}

	usbhost_cmd.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_GET_CONTROL_ENDPOINT_HANDLE;
	usbhost_cmd.handle.dif = interface_handle;
	usbhost_cmd.get = &ctrl_endpoint;
	usbhost_cmd.set = NULL;
	status = vos_dev_ioctl(usb_handle, &usbhost_cmd);
	if(USBHOST_OK != status) {
		return;
	}

	// send a SetIdle to the device
	device_request.bmRequestType = USB_BMREQUESTTYPE_HOST_TO_DEV |
		USB_BMREQUESTTYPE_CLASS |
		USB_BMREQUESTTYPE_INTERFACE;
	device_request.bRequest = 0x0a;
	device_request.wValue = 0;
	device_request.wIndex = 0;
	device_request.wLength = 0;

	usbhost_cmd.ioctl_code = VOS_IOCTL_USBHOST_DEVICE_SETUP_TRANSFER;
	usbhost_cmd.handle.ep = ctrl_endpoint;
	usbhost_cmd.set = &device_request;
	status = vos_dev_ioctl(usb_handle, &usbhost_cmd);

	while (1)
	{
		vos_memset(&transfer_block, 0, sizeof(transfer_block));
		transfer_block.cond_code = USBHOST_CC_NOTACCESSED;
		transfer_block.flags = USBHOST_XFER_FLAG_START_BULK_ENDPOINT_LIST|USBHOST_XFER_FLAG_ROUNDING;
		transfer_block.s = &read_completion_event;
		transfer_block.ep = rx_endpoint;
		transfer_block.buf = usb_rx_data;
		transfer_block.len = SZ_USB_RX_DATA;

		status =  vos_dev_read(usb_handle, (byte*)&transfer_block, sizeof(transfer_block), NULL);
		if(status != USBHOST_OK) {
			break;
		}
		send_output(usb_rx_data, transfer_block.len);		
	}
}
예제 #14
0
void firmware()
{
	/* Thread code to be added here */

	// communications ioctl request blocks
	common_ioctl_cb_t uart_iocb;

	usbHostHID_ioctl_t	hid_iocb;
	usbhost_device_handle ifDev; 				// device handle
	usbhost_ioctl_cb_t hc_iocb;					// Host Controller ioctl request block
	unsigned char byteCount,status;
	unsigned short num_read;

	do
	{
		open_drivers();
		
		// UART set baud rate
		uart_iocb.ioctl_code = VOS_IOCTL_UART_SET_BAUD_RATE;
		uart_iocb.set.uart_baud_rate = DEF_UART_BAUD;
		vos_dev_ioctl(hUART, &uart_iocb);
		
		do
		{
			vos_delay_msecs(1000);
			// wait for enumeration to complete
//			message("Waiting for enumeration\r\n");
			status = usbhost_connect_state(hUSBHOST_2);
			
		} while (status != PORT_STATE_ENUMERATED);

		if (status == PORT_STATE_ENUMERATED)
		{
//			message("Enumeration complete\r\n");
			vos_gpio_set_port_mode(GPIO_PORT_A, 0b00000100); // A2 на выход
			vos_gpio_write_port(GPIO_PORT_A, 0b00000100); // зажечь светодиод
			
			attach_drivers();
			if (hUSBHOST_HID == NULL)
			{
//				message("No Wingman Found - code ");
//				number(status);
//				message(eol);
				break;
			}


			// get report descriptor
			hid_iocb.descriptorType = USB_DESCRIPTOR_TYPE_REPORT;
			hid_iocb.descriptorIndex = USB_HID_DESCRIPTOR_INDEX_ZERO;
			hid_iocb.Length = 0x40;
			hid_iocb.get.data=&buf[0];
			hid_iocb.ioctl_code = VOS_IOCTL_USBHOSTHID_GET_DESCRIPTOR;
			status = vos_dev_ioctl(hUSBHOST_HID, &hid_iocb);
			if (status != USBHOSTHID_OK)
			{
//				message("Get report descriptor failed - code ");
//				number(status);
//				message(eol);
				break;
			}

			// set idle
			hid_iocb.reportID = USB_HID_REPORT_ID_ZERO;
			hid_iocb.idleDuration = 0x20;
			hid_iocb.ioctl_code = VOS_IOCTL_USBHOSTHID_SET_IDLE;
			status = vos_dev_ioctl(hUSBHOST_HID, &hid_iocb);
			if (status != USBHOSTHID_OK)
			{
//				message("Set Idle failed - code ");
//				number(status);
//				message(eol);
				break;
			}


			// get idle
			hid_iocb.reportID = USB_HID_REPORT_ID_ZERO;
			hid_iocb.get.data=&buf[0];
			hid_iocb.ioctl_code = VOS_IOCTL_USBHOSTHID_GET_IDLE;
			status = vos_dev_ioctl(hUSBHOST_HID, &hid_iocb);
			if (status != USBHOSTHID_OK)
			{
//				message("Get Idle failed - code ");
//				number(status);
//				message(eol);
				break;
			}

			if (status == USBHOSTHID_OK)
			{
					while (1)
					{
						if (vos_dev_read(hUSBHOST_HID, buf, 8, &num_read) == USBHOSTHID_OK)
						{

							for (byteCount = 0; byteCount < num_read; byteCount++)
							{
								number(buf[byteCount]);
							}
//							message(eol);
						}
						else
						{
//							message("USB Read Failed - code ");
//							number(status);
//							message(eol);
							break;
						}
					}


			}

//		message("Disconnected!\r\n");
		vos_gpio_write_port(GPIO_PORT_A, 0b00000000); // погасить все

		} // end of if PORT_STATE_ENUMERATED


		vos_dev_close(hUSBHOST_HID);
		close_drivers();
	} while (1);


}