Esempio n. 1
0
/** Handler for the CMD_SET_PARAMETER and CMD_GET_PARAMETER commands from the host, setting or
 *  getting a device parameter's value from the parameter table.
 *
 *  \param[in] V2Command  Issued V2 Protocol command byte from the host
 */
static void V2Protocol_GetSetParam(const uint8_t V2Command)
{
	uint8_t ParamID = Endpoint_Read_8();
	uint8_t ParamValue;

	if (V2Command == CMD_SET_PARAMETER)
	  ParamValue = Endpoint_Read_8();

	Endpoint_ClearOUT();
	Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);
	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	Endpoint_Write_8(V2Command);

	uint8_t ParamPrivs = V2Params_GetParameterPrivileges(ParamID);

	if ((V2Command == CMD_SET_PARAMETER) && (ParamPrivs & PARAM_PRIV_WRITE))
	{
		Endpoint_Write_8(STATUS_CMD_OK);
		V2Params_SetParameterValue(ParamID, ParamValue);
	}
	else if ((V2Command == CMD_GET_PARAMETER) && (ParamPrivs & PARAM_PRIV_READ))
	{
		Endpoint_Write_8(STATUS_CMD_OK);
		Endpoint_Write_8(V2Params_GetParameterValue(ParamID));
	}
	else
	{
		Endpoint_Write_8(STATUS_CMD_FAILED);
	}

	Endpoint_ClearIN();
}
Esempio n. 2
0
void usbGetButtons()
{
	Endpoint_ClearSETUP();//ack setup packet
	u8 sendData = 0;
	while (sendData < 3)
	{
		while (!Endpoint_IsINReady())
		{
			//wait until host is ready
		}
		u8 state = stateButton(but1);;
		Endpoint_Write_8(state);
		sendData++;
		state = stateButton(but2);;
		Endpoint_Write_8(state);
		sendData++;
		state = stateButton(but3);;
		Endpoint_Write_8(state);
		sendData++;
		Endpoint_ClearIN();
	}
	//while (!Endpoint_IsOUTReceived())
	{
		//wait for host to send status
	}
	//Endpoint_ClearOUT();//send message
	//Endpoint_ClearStatusStage();//success :D
}
Esempio n. 3
0
/** Handler for the CMD_LEAVE_ISP command, which releases the target from programming mode. */
void ISPProtocol_LeaveISPMode(void)
{
    struct
    {
        uint8_t PreDelayMS;
        uint8_t PostDelayMS;
    } Leave_ISP_Params;

    Endpoint_Read_Stream_LE(&Leave_ISP_Params, sizeof(Leave_ISP_Params), NULL);

    Endpoint_ClearOUT();
    Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR);
    Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

    /* Perform pre-exit delay, release the target /RESET, disable the SPI bus and perform the post-exit delay */
    ISPProtocol_DelayMS(Leave_ISP_Params.PreDelayMS);
    ISPTarget_ChangeTargetResetLine(false);
    ISPTarget_DisableTargetISP();
    ISPProtocol_DelayMS(Leave_ISP_Params.PostDelayMS);

    Endpoint_Write_8(CMD_LEAVE_PROGMODE_ISP);
    Endpoint_Write_8(STATUS_CMD_OK);
    Endpoint_ClearIN();

    ISPActive = false;
}
Esempio n. 4
0
/** Handler for the CMD_RESET_PROTECTION command, implemented as a dummy ACK function as
 *  no target short-circuit protection is currently implemented.
 */
static void V2Protocol_ResetProtection(void)
{
	Endpoint_ClearOUT();
	Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);
	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	Endpoint_Write_8(CMD_RESET_PROTECTION);
	Endpoint_Write_8(STATUS_CMD_OK);
	Endpoint_ClearIN();
}
Esempio n. 5
0
/** Handler for the XPROG CRC command to read a specific memory space's CRC value for comparison between the
 *  attached device's memory and a data set on the host.
 */
static void XPROGProtocol_ReadCRC(void)
{
	uint8_t ReturnStatus = XPROG_ERR_OK;

	struct
	{
		uint8_t CRCType;
	} ReadCRC_XPROG_Params;

	Endpoint_Read_Stream_LE(&ReadCRC_XPROG_Params, sizeof(ReadCRC_XPROG_Params), NULL);

	Endpoint_ClearOUT();
	Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR);
	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	uint32_t MemoryCRC;

	if (XPROG_SelectedProtocol == XPROG_PROTOCOL_PDI)
	{
		uint8_t CRCCommand;

		/* Determine which NVM command to send to the device depending on the memory to CRC */
		switch (ReadCRC_XPROG_Params.CRCType)
		{
			case XPROG_CRC_APP:
				CRCCommand = XMEGA_NVM_CMD_APPCRC;
				break;
			case XPROG_CRC_BOOT:
				CRCCommand = XMEGA_NVM_CMD_BOOTCRC;
				break;
			default:
				CRCCommand = XMEGA_NVM_CMD_FLASHCRC;
				break;
		}

		/* Perform and retrieve the memory CRC, indicate timeout if occurred */
		if (!(XMEGANVM_GetMemoryCRC(CRCCommand, &MemoryCRC)))
		  ReturnStatus = XPROG_ERR_TIMEOUT;
	}
	else
	{
		/* TPI does not support memory CRC */
		ReturnStatus = XPROG_ERR_FAILED;
	}

	Endpoint_Write_8(CMD_XPROG);
	Endpoint_Write_8(XPROG_CMD_CRC);
	Endpoint_Write_8(ReturnStatus);

	if (ReturnStatus == XPROG_ERR_OK)
	{
		Endpoint_Write_8(MemoryCRC >> 16);
		Endpoint_Write_16_LE(MemoryCRC & 0xFFFF);
	}
Esempio n. 6
0
/** Handler for the CMD_SIGN_ON command, returning the programmer ID string to the host. */
static void V2Protocol_SignOn(void)
{
	Endpoint_ClearOUT();
	Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);
	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	Endpoint_Write_8(CMD_SIGN_ON);
	Endpoint_Write_8(STATUS_CMD_OK);
	Endpoint_Write_8(sizeof(PROGRAMMER_ID) - 1);
	Endpoint_Write_Stream_LE(PROGRAMMER_ID, (sizeof(PROGRAMMER_ID) - 1), NULL);
	Endpoint_ClearIN();
}
Esempio n. 7
0
/** Command processing for an issued SCSI MODE SENSE (6) command. This command returns various informational pages about
 *  the SCSI device, as well as the device's Write Protect status.
 *
 *  \param[in] MSInterfaceInfo  Pointer to the Mass Storage class interface structure that the command is associated with
 *
 *  \return Boolean true if the command completed successfully, false otherwise.
 */
static bool SCSI_Command_ModeSense_6(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
{
	/* Send an empty header response with the Write Protect flag status */
	Endpoint_Write_8(0x00);
	Endpoint_Write_8(0x00);
	Endpoint_Write_8(DISK_READ_ONLY ? 0x80 : 0x00);
	Endpoint_Write_8(0x00);
	Endpoint_ClearIN();

	/* Update the bytes transferred counter and succeed the command */
	MSInterfaceInfo->State.CommandBlock.DataTransferLength -= 4;

	return true;
}
/** Command processing for an issued SCSI MODE SENSE (6) command. This command returns various informational pages about
 *  the SCSI device, as well as the device's Write Protect status.
 *
 *  \return Boolean true if the command completed successfully, false otherwise.
 */
static bool SCSI_Command_ModeSense_6(void)
{
	/* Send an empty header response with the Write Protect flag status */
	Endpoint_Write_8(0x00);
	Endpoint_Write_8(0x00);
	Endpoint_Write_8(DISK_READ_ONLY ? 0x80 : 0x00);
	Endpoint_Write_8(0x00);
	Endpoint_ClearIN();

	/* Update the bytes transferred counter and succeed the command */
	CommandBlock.DataTransferLength -= 4;

	return true;
}
Esempio n. 9
0
/** Handler for the CMD_LOAD_ADDRESS command, loading the given device address into a
 *  global storage variable for later use, and issuing LOAD EXTENDED ADDRESS commands
 *  to the attached device as required.
 */
static void V2Protocol_LoadAddress(void)
{
	Endpoint_Read_Stream_BE(&CurrentAddress, sizeof(CurrentAddress), NULL);

	Endpoint_ClearOUT();
	Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);
	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	if (CurrentAddress & (1UL << 31))
	  MustLoadExtendedAddress = true;

	Endpoint_Write_8(CMD_LOAD_ADDRESS);
	Endpoint_Write_8(STATUS_CMD_OK);
	Endpoint_ClearIN();
}
Esempio n. 10
0
/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to
 *  the device from the USB host before passing along unhandled control requests to the library for processing
 *  internally.
 */
void EVENT_USB_Device_ControlRequest(void)
{
    /* Process UFI specific control requests */
    switch (USB_ControlRequest.bRequest)
    {
    case MS_REQ_MassStorageReset:
        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
        {
            Endpoint_ClearSETUP();
            Endpoint_ClearStatusStage();

            /* Indicate that the current transfer should be aborted */
            IsMassStoreReset = true;
        }

        break;
    case MS_REQ_GetMaxLUN:
        if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
        {
            Endpoint_ClearSETUP();

            /* Indicate to the host the number of supported LUNs (virtual disks) on the device */
            Endpoint_Write_8(TOTAL_LUNS - 1);

            Endpoint_ClearIN();
            Endpoint_ClearStatusStage();
        }

        break;
    }
}
uint8_t CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
                            const uint8_t Data)
{
	uint8_t status = 0;
	if ((USB_DeviceState == DEVICE_STATE_Configured) &&	(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS != 0))
	{

		Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpoint.Address);

		if (Endpoint_IsReadWriteAllowed())
		{
			Endpoint_Write_8(Data);
			status = ENDPOINT_READYWAIT_NoError;
		}
		else
		{
			Endpoint_ClearIN();
			status = Endpoint_WaitUntilReady();
		}
	}
	else
	{
		status = ENDPOINT_RWSTREAM_DeviceDisconnected;
	}

	return status;

}
Esempio n. 12
0
void usbGetTemperature()
{
	Endpoint_ClearSETUP();//ack setup packet
	u8 sendData = 0;
	measureTemperature();
	while (sendData < 2)
	{
		while (!Endpoint_IsINReady())
		{
			//wait until host is ready
		}
		u16 value = measureTemperature();
		Endpoint_Write_8(value>>8);
		sendData++;
		Endpoint_Write_8(value & 0xff);
		sendData++;
		Endpoint_ClearIN();
	}
	//while (!Endpoint_IsOUTReceived())
	{
		//wait for host to send status
	}
	//Endpoint_ClearOUT();//send message
	//Endpoint_ClearStatusStage();//success :D

}
Esempio n. 13
0
size_t USBSerial::write(uint8_t c)
{
        /* only try to send bytes if the high-level CDC connection itself 
         is open (not just the pipe) - the OS should set lineState when the port
         is opened and clear lineState when the port is closed.
         bytes sent before the user opens the connection or after
         the connection is closed are lost - just like with a UART. */
        
        // TODO - ZE - check behavior on different OSes and test what happens if an
        // open connection isn't broken cleanly (cable is yanked out, host dies
        // or locks up, or host virtual serial port hangs)
        if (LineState > 0) {
                Endpoint_SelectEndpoint(CDC_TX_EPADDR);
                
                if (!Endpoint_IsReadWriteAllowed()) {
                        Endpoint_ClearIN();
                        while (!Endpoint_IsINReady() && USB_DeviceState == DEVICE_STATE_Configured) {
                                USB_USBTask();
                        }
                }
                
                set_blink_LED();
                Endpoint_Write_8(c);
                
                return 1;
        } else {
                setWriteError();
                return 0;
        }
}
Esempio n. 14
0
void MS_Device_ProcessControlRequest(USB_ClassInfo_MS_Device_t* const MSInterfaceInfo)
{
	if (!(Endpoint_IsSETUPReceived()))
	  return;

	if (USB_ControlRequest.wIndex != MSInterfaceInfo->Config.InterfaceNumber)
	  return;

	switch (USB_ControlRequest.bRequest)
	{
		case MS_REQ_MassStorageReset:
			if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
			{
				Endpoint_ClearSETUP();
				Endpoint_ClearStatusStage();

				MSInterfaceInfo->State.IsMassStoreReset = true;
			}

			break;
		case MS_REQ_GetMaxLUN:
			if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
			{
				Endpoint_ClearSETUP();
				while (!(Endpoint_IsINReady()));
				Endpoint_Write_8(MSInterfaceInfo->Config.TotalLUNs - 1);
				Endpoint_ClearIN();
				Endpoint_ClearStatusStage();
			}

			break;
	}
}
Esempio n. 15
0
void cdc_send_USB_data( USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo ){
    
	// process outgoing USB data
	Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpoint.Address); // select IN endpoint to restore its registers
	if ( UEINTX & (1<<TXINI) ){ // if we can write on the outgoing data bank
		uint8_t BufferCount = RingBuffer_GetCount(&ToUSB_Buffer);
		
		if (BufferCount) {
			uint8_t bank_size = CDCInterfaceInfo->Config.DataINEndpoint.Size;
	
			// if there are more bytes in the buffer than what can be put in the data bank OR there are a few bytes and they have been waiting for too long
			if ( BufferCount >= bank_size || (TIFR0 & (1 << TOV0)) ){
				// Clear flush timer expiry flag
			    TIFR0 |= (1 << TOV0);
				
				// load the IN data bank until full or until we loaded all the bytes we know we have
				uint8_t nb_to_write = min(BufferCount, bank_size );					
				while (nb_to_write--){
                	uint8_t Data = RingBuffer_Remove(&ToUSB_Buffer);
					Endpoint_Write_8(Data);
				}
				
				// if the bank is full (== we can't write to it anymore), we might need an empty packet after this one
				needEmptyPacket = ! Endpoint_IsReadWriteAllowed();
				
				Endpoint_ClearIN(); // allow the hardware to send the content of the bank
			}
		} else if (needEmptyPacket) {
			// send an empty packet to end the transfer
			needEmptyPacket = false;
			Endpoint_ClearIN(); // allow the hardware to send the content of the bank
		}
		
	}
}
Esempio n. 16
0
/** Handler for the CMD_RESET_PROTECTION command, implemented as a dummy ACK function as
 *  no target short-circuit protection is currently implemented.
 */
static void V2Protocol_ResetProtection(void)
{
	Endpoint_ClearOUT();

	if ( use_libusb == true ) {
		Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM__LIBUSB);

	} else {
		Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM__DEFAULT);
	}

	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	Endpoint_Write_8(CMD_RESET_PROTECTION);
	Endpoint_Write_8(STATUS_CMD_OK);
	Endpoint_ClearIN();
}
Esempio n. 17
0
/** Handler for unknown V2 protocol commands. This discards all sent data and returns a
 *  STATUS_CMD_UNKNOWN status back to the host.
 *
 *  \param[in] V2Command  Issued V2 Protocol command byte from the host
 */
static void V2Protocol_UnknownCommand(const uint8_t V2Command)
{
	/* Discard all incoming data */
	while (Endpoint_BytesInEndpoint() == AVRISP_DATA_EPSIZE)
	{
		Endpoint_ClearOUT();
		Endpoint_WaitUntilReady();
	}

	Endpoint_ClearOUT();
	Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM);
	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	Endpoint_Write_8(V2Command);
	Endpoint_Write_8(STATUS_CMD_UNKNOWN);
	Endpoint_ClearIN();
}
Esempio n. 18
0
void PRNT_Device_ProcessControlRequest(USB_ClassInfo_PRNT_Device_t* const PRNTInterfaceInfo)
{
	if (!(Endpoint_IsSETUPReceived()))
	  return;

	if (USB_ControlRequest.wIndex != PRNTInterfaceInfo->Config.InterfaceNumber)
	  return;

	switch (USB_ControlRequest.bRequest)
	{
		case PRNT_REQ_GetDeviceID:
			if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
			{
				Endpoint_ClearSETUP();

				while (!(Endpoint_IsINReady()))
				{
					if (USB_DeviceState == DEVICE_STATE_Unattached)
					  return;
				}

				uint16_t IEEEStringLen = strlen(PRNTInterfaceInfo->Config.IEEE1284String);
				Endpoint_Write_16_BE(IEEEStringLen);
				Endpoint_Write_Control_Stream_LE(PRNTInterfaceInfo->Config.IEEE1284String, IEEEStringLen);
				Endpoint_ClearStatusStage();
			}

			break;
		case PRNT_REQ_GetPortStatus:
			if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
			{
				Endpoint_ClearSETUP();

				while (!(Endpoint_IsINReady()))
				{
					if (USB_DeviceState == DEVICE_STATE_Unattached)
					  return;
				}

				Endpoint_Write_8(PRNTInterfaceInfo->State.PortStatus);
				Endpoint_ClearStatusStage();
			}

			break;
		case PRNT_REQ_SoftReset:
			if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
			{
				Endpoint_ClearSETUP();
				Endpoint_ClearStatusStage();

				PRNTInterfaceInfo->State.IsPrinterReset = true;

				EVENT_PRNT_Device_SoftReset(PRNTInterfaceInfo);
			}

			break;
	}
}
Esempio n. 19
0
/** Handler for the XPROG ENTER_PROGMODE command to establish a connection with the attached device. */
static void XPROGProtocol_EnterXPROGMode(void)
{
	Endpoint_ClearOUT();
	Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR);
	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	bool NVMBusEnabled = false;

	if (XPROG_SelectedProtocol == XPROG_PROTOCOL_PDI)
	  NVMBusEnabled = XMEGANVM_EnablePDI();
	else if (XPROG_SelectedProtocol == XPROG_PROTOCOL_TPI)
	  NVMBusEnabled = TINYNVM_EnableTPI();

	Endpoint_Write_8(CMD_XPROG);
	Endpoint_Write_8(XPROG_CMD_ENTER_PROGMODE);
	Endpoint_Write_8(NVMBusEnabled ? XPROG_ERR_OK : XPROG_ERR_FAILED);
	Endpoint_ClearIN();
}
static void USB_Device_GetConfiguration(void)
{
	Endpoint_ClearSETUP();

	Endpoint_Write_8(USB_Device_ConfigurationNumber);
	Endpoint_ClearIN();

	Endpoint_ClearStatusStage();
}
static void USB_Device_GetConfiguration(uint8_t corenum)
{
	Endpoint_ClearSETUP(corenum);

	Endpoint_Write_8(corenum, USB_Device_ConfigurationNumber);
	Endpoint_ClearIN(corenum);

	Endpoint_ClearStatusStage(corenum);
}
Esempio n. 22
0
/** Handler for the CMD_XPROG_SETMODE command, which sets the programmer-to-target protocol used for PDI/TPI
 *  programming.
 */
void XPROGProtocol_SetMode(void)
{
	struct
	{
		uint8_t Protocol;
	} SetMode_XPROG_Params;

	Endpoint_Read_Stream_LE(&SetMode_XPROG_Params, sizeof(SetMode_XPROG_Params), NULL);

	Endpoint_ClearOUT();
	Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR);
	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	XPROG_SelectedProtocol = SetMode_XPROG_Params.Protocol;

	Endpoint_Write_8(CMD_XPROG_SETMODE);
	Endpoint_Write_8((SetMode_XPROG_Params.Protocol != XPROG_PROTOCOL_JTAG) ? STATUS_CMD_OK : STATUS_CMD_FAILED);
	Endpoint_ClearIN();
}
Esempio n. 23
0
/** Handler for the CMD_SIGN_ON command, returning the programmer ID string to the host. */
static void V2Protocol_SignOn(void)
{
	Endpoint_ClearOUT();

	if ( use_libusb == true ) {
		Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM__LIBUSB);

	} else {
		Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPNUM__DEFAULT);
	}

	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	Endpoint_Write_8(CMD_SIGN_ON);
	Endpoint_Write_8(STATUS_CMD_OK);
	Endpoint_Write_8(sizeof(PROGRAMMER_ID) - 1);
	Endpoint_Write_Stream_LE(PROGRAMMER_ID, (sizeof(PROGRAMMER_ID) - 1), NULL);
	Endpoint_ClearIN();
}
Esempio n. 24
0
/** Handler for the XPROG READ_MEMORY command to read data from a specific address space within the
 *  attached device.
 */
static void XPROGProtocol_ReadMemory(void)
{
	uint8_t ReturnStatus = XPROG_ERR_OK;

	struct
	{
		uint8_t  MemoryType;
		uint32_t Address;
		uint16_t Length;
	} ReadMemory_XPROG_Params;

	Endpoint_Read_Stream_LE(&ReadMemory_XPROG_Params, sizeof(ReadMemory_XPROG_Params), NULL);
	ReadMemory_XPROG_Params.Address = SwapEndian_32(ReadMemory_XPROG_Params.Address);
	ReadMemory_XPROG_Params.Length  = SwapEndian_16(ReadMemory_XPROG_Params.Length);

	Endpoint_ClearOUT();
	Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR);
	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	uint8_t ReadBuffer[256];

	if (XPROG_SelectedProtocol == XPROG_PROTOCOL_PDI)
	{
		/* Read the PDI target's memory, indicate timeout if occurred */
		if (!(XMEGANVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length)))
		  ReturnStatus = XPROG_ERR_TIMEOUT;
	}
	else
	{
		/* Read the TPI target's memory, indicate timeout if occurred */
		if (!(TINYNVM_ReadMemory(ReadMemory_XPROG_Params.Address, ReadBuffer, ReadMemory_XPROG_Params.Length)))
		  ReturnStatus = XPROG_ERR_TIMEOUT;
	}

	Endpoint_Write_8(CMD_XPROG);
	Endpoint_Write_8(XPROG_CMD_READ_MEM);
	Endpoint_Write_8(ReturnStatus);

	if (ReturnStatus == XPROG_ERR_OK)
	  Endpoint_Write_Stream_LE(ReadBuffer, ReadMemory_XPROG_Params.Length, NULL);

	Endpoint_ClearIN();
}
Esempio n. 25
0
uint8_t Device_SendByte(USB_EPInfo_Device_t* EPInfo, const uint8_t Data)
{
	if (USB_DeviceState != DEVICE_STATE_Configured) return ENDPOINT_RWSTREAM_DeviceDisconnected;
	// USB_DeviceState 
	// USBTask.h
	// Indicates the current device state machine state. When in device mode, 
	// this indicates the state via one of the values of the 
	// USB_Device_States_t enum values.
	//
	// DEVICE_STATE_Configured(4)
	// Device.h
	// This state indicates that the device has been enumerated by the host 
	// and is ready for USB communications to begin.
	//
	// ENDPOINT_RWSTREAM_DeviceDisconnected(2)
	// EndpointStream.h
	// Device was disconnected from the host during the transfer.
	
	Endpoint_SelectEndpoint(EPInfo->DataINEPAddress);
	// Endpoint_AVR8.h
	// Select the given endpoint address.
	if (!(Endpoint_IsReadWriteAllowed()))
	// Endpoint_AVR8.h
	// Determines if the currently selected endpoint may be read from 
	// (if data is waiting in the endpoint bank and the endpoint is an OUT 
	// direction, or if the bank is not yet full if the endpoint is an IN 
	// direction). This function will return false if an error has occurred in 
	// the endpoint, if the endpoint is an OUT direction and no packet (or an 
	// empty packet) has been received, or if the endpoint is an IN direction 
	// and the endpoint bank is full.
	{
		Endpoint_ClearIN();
		// Endpoint_AVR8.h
		// Sends an IN packet to the host on the currently selected endpoint, freeing up the endpoint for the next packet and switching to the alternative endpoint bank if double banked
		
		uint8_t ErrorCode;

		if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError)
		// Endpoint_WaitUntilReady
		// Endpoint_AVR8.h
		// Spin-loops until the currently selected non-control endpoint is 
		// ready for the next packet of data to be read or written to it.
		//
		// ENDPOINT_READYWAIT_NoError(0)
		// Endpoint_AVR8.h
		// Endpoint is ready for next packet, no error.
			return ErrorCode;
	}

	Endpoint_Write_8(Data);
	// Endpoint_AVR8.h
	// Writes one byte to the currently selected endpoint's bank, for IN direction endpoints.
	return ENDPOINT_READYWAIT_NoError;
}
Esempio n. 26
0
uint8_t Endpoint_Write_Stream_BE(const void* const Buffer,
			                                 uint16_t Length,
			                                 uint16_t* const BytesProcessed)
{
	uint16_t i;

	for(i=0;i<Length;i++)
	{
		Endpoint_Write_8(((uint8_t*)Buffer)[Length -1 -i]);
	}
	return ENDPOINT_RWSTREAM_NoError;
}
Esempio n. 27
0
/** Handler for the XPROG LEAVE_PROGMODE command to terminate the PDI programming connection with
 *  the attached device.
 */
static void XPROGProtocol_LeaveXPROGMode(void)
{
	Endpoint_ClearOUT();
	Endpoint_SelectEndpoint(AVRISP_DATA_IN_EPADDR);
	Endpoint_SetEndpointDirection(ENDPOINT_DIR_IN);

	if (XPROG_SelectedProtocol == XPROG_PROTOCOL_PDI)
	  XMEGANVM_DisablePDI();
	else
	  TINYNVM_DisableTPI();

	#if defined(XCK_RESCUE_CLOCK_ENABLE) && defined(ENABLE_ISP_PROTOCOL)
	/* If the XCK rescue clock option is enabled, we need to restart it once the
	 * XPROG mode has been exited, since the XPROG protocol stops it after use. */
	ISPTarget_ConfigureRescueClock();
	#endif

	Endpoint_Write_8(CMD_XPROG);
	Endpoint_Write_8(XPROG_CMD_LEAVE_PROGMODE);
	Endpoint_Write_8(XPROG_ERR_OK);
	Endpoint_ClearIN();
}
Esempio n. 28
0
uint8_t Endpoint_Null_Stream(uint16_t Length,
                             uint16_t* const BytesProcessed)
{
	uint32_t i;

	while ( !Endpoint_IsINReady() ) /*-- Wait until ready --*/
	{
		Delay_MS(2);
	}
	for (i=0; i < Length; i++)
	{
		Endpoint_Write_8(0);	
	}
	return ENDPOINT_RWSTREAM_NoError;
}
Esempio n. 29
0
// pure usb transmit takes 15secs (1040KB/s) for 16MB
void speedtest_send(void) {
	uint8_t k;
	uint32_t i = 0;

	/* Select the IN stream endpoint */
	Endpoint_SelectEndpoint(IN_EP);

	while (i < NOR_BSS_128) {
		/* Check if the current endpoint can be written to and that the next sample should be stored */
		while (!Endpoint_IsINReady()) USB_USBTask();

		for (k = 0; k < TX_BUFFER_SIZE; ++k) {
			Endpoint_Write_8(0);
		}

		Endpoint_ClearIN();

		i += TX_BUFFER_SIZE;
	}
}
Esempio n. 30
0
uint8_t CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
                            const uint8_t Data)
{
	if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
	  return ENDPOINT_RWSTREAM_DeviceDisconnected;

	Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);

	if (!(Endpoint_IsReadWriteAllowed()))
	{
		Endpoint_ClearIN();

		uint8_t ErrorCode;

		if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError)
		  return ErrorCode;
	}

	Endpoint_Write_8(Data);
	return ENDPOINT_READYWAIT_NoError;
}