コード例 #1
0
ファイル: libnero.c プロジェクト: makestuff/libnero
// Receive a chunk of data from the micro.
//
static NeroStatus doReceive(
	struct NeroHandle *handle, uint8 *receivePtr, uint16 chunkSize, const char **error)
{
	NeroStatus returnCode = NERO_SUCCESS;
	int uStatus = usbBulkRead(
		handle->device,
		handle->inEndpoint,  // read from in endpoint
		receivePtr,          // read into the receive buffer
		chunkSize,           // read this many bytes
		5000,                // timeout in milliseconds
		error
	);
	CHECK_STATUS(uStatus, "doReceive()", NERO_RECEIVE);
cleanup:
	return returnCode;
}
コード例 #2
0
ファイル: libfpgalink.c プロジェクト: FrankBuss/libfpgalink
// Read some raw bytes from the device.
//
FLStatus flRead(
	struct FLContext *handle, uint8 *buffer, uint32 count, uint32 timeout, const char **error)
{
	FLStatus retVal = FL_SUCCESS;
	USBStatus uStatus = usbBulkRead(
		handle->device,
		handle->commInEP,  // endpoint to read
		buffer,            // space for data
		count,             // number of bytes
		timeout,
		error
	);
	CHECK_STATUS(uStatus, FL_USB_ERR, cleanup, "flRead()");
cleanup:
	return retVal;
}
コード例 #3
0
void Sdr1kUsb::usbThread()
{
	lock();
	while (usbStatus >= 0) {
		waitUpdate();
		if (usbStatus >= 0) {
			usbStatus = usbBulkWrite(outEP, outbuf, outcount);
			outcount = 0;
			if (usbStatus >= 0) {
				usbStatus = usbBulkRead(inEP, inbuf, 3);
				if (inbuf[0] != pstatus) {
					pstatus = inbuf[0];
					signalInput();
				}
			}
		}
	}
	signalInput();
	unlock();
}
コード例 #4
0
int Sdr1kUsb::Open(BOOL rfe, BOOL adc, int select)
{
	if (usbStatus >= 0) Close();
	GetNumDevs();
	int idx = select;
	if (select < 0) idx = 0;
	while (idx < devcount) {
		if (usbOpen(device[idx])) {
			if (usbSetConfiguration(1) == 0
				&& usbClaimInterface(0) == 0
				&& usbSetAltinterface(1) == 0)
			{
				usbStatus = 0;
				break;
			}
			usbClose();
		}
		if (select < 0) idx++;
		else return usbStatus;
	}
	if (usbStatus < 0) return usbStatus;

#ifdef SDR1KUSB_INFO
	printf("device %d: %s\n", idx, device[idx]->filename);
	printf("hardware: %s\n", hw[idx]->name);
#endif

	inEP = hw[idx]->inEP;
	outEP = hw[idx]->outEP;
	usbClearHalt(inEP);
	usbClearHalt(outEP);

	int* fwSize = hw[idx]->fwSize;
	int* fwAddr = hw[idx]->fwAddr;
	BYTE** fwBytes = hw[idx]->fwBytes;
	for (int i = 0; fwSize[i] > 0; i++) {
		ezusbFirmwareDownload(fwAddr[i], fwBytes[i], fwSize[i]);
	}

	int eepromSize = hw[idx]->eepromSize;
	if (eepromSize == 16) {
		BYTE eeprom[16];
		usbBulkRead(inEP, eeprom, 16);
#ifdef SDR1KUSB_INFO
		printf("EEPROM:");
		for (int i = 0; i < 16; i++) {
			printf(" %02X", eeprom[i]);
		}
		printf("\n");
#endif
	}

	inputEvent = 0;
	usbUpdatePeriod = USB_UPDATE_DEFAULT;

	outcount = 0;
	startUsbThread();

	Latch(0x0F, 0);
	DDSReset();

	rfeEnabled = rfe;
	if (rfeEnabled) {
		LatchBpf(0);	// bpfBits |= 0x24
		adcEnabled = adc;
		SRLoadIC11(0);
		SRLoadIC7(0);
		SRLoadIC10(0);
		SRLoadIC9(0);
	}
	else adcEnabled = 0;

	if (Commit() < 0) {
		Close();
		return usbStatus;
	}
	return idx;
}