Exemplo n.º 1
0
void usb_char_send(char c) {
    if (!is_usb_available()) {
        //USBCBSendResume();
        return;
    }
    while (!USBUSARTIsTxTrfReady()) CDCTxService();
    putUSBUSART(&c, 1);
    CDCTxService();
}
Exemplo n.º 2
0
uint8_t usb_char_get(char *c) {
    if (!is_usb_available()) {
        //USBCBSendResume();
        return 0;
    }
    while (!USBUSARTIsTxTrfReady()) CDCTxService();
    uint8_t ans;
    ans = getsUSBUSART(c, 1);
    CDCTxService();
    return ans;
}
Exemplo n.º 3
0
int main(void){   
	unsigned long timer;
	#define longDelay(x) timer=x; while(timer--)
    CLKDIV = 0x0000;    // Set PLL prescaler (1:1)
    init();			//setup the crystal, pins, hold the FPGA in reset
	usbbufflush();	//setup the USB byte buffer
	

    USBDeviceInit();//setup usb

    while(1){
        USBDeviceTasks(); 

    	if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) continue;
		usbbufservice();//load any USB data into byte buffer

			//send data from the FPGA receive buffer to USB
			//if((mUSBUSARTIsTxTrfReady()) && (uartincnt > 0)){
			//	putUSBUSART(&buf[0], uartincnt);
			//}

    	CDCTxService();

    }//end while

}//end main
Exemplo n.º 4
0
void ProcessIO(void)
{   
    BYTE numBytesRead;

    //Blink the LEDs according to the USB device status
    BlinkUSBStatus();
    // User Application USB tasks
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

    if(buttonPressed)
    {
        if(stringPrinted == FALSE)
        {
            if(mUSBUSARTIsTxTrfReady())
            {
                putrsUSBUSART("Button Pressed data-- \r\n");
                stringPrinted = TRUE;
            }
        }
    }
    else
    {
        stringPrinted = FALSE;
    }

    if(USBUSARTIsTxTrfReady())
    {
		numBytesRead = getsUSBUSART(USB_Out_Buffer,64);
		if(numBytesRead != 0)
		{
			BYTE i;
	        
			for(i=0;i<numBytesRead;i++)
			{
				switch(USB_Out_Buffer[i])
				{
					case 0x0A:
					case 0x0D:
						putUSBUSART(&USB_Out_Buffer[i],numBytesRead);
						break;
                                        case 0x53://letter S to start sampling
                                                ReadADC();
                                                putUSBUSART(ADC_sample,SAMPLE_SIZE);
                                                break;
                                        case 0x51: //letter Q to stop

                                                break;
					default:
						putUSBUSART(&USB_Out_Buffer[i],numBytesRead);
						break;
				}

			}

			//putUSBUSART(USB_In_Buffer,numBytesRead);
		}
	}

    CDCTxService();
}		//end ProcessIO
Exemplo n.º 5
0
void SendUSBMessage(char *message, unsigned int len)
{
    BYTE tosend;

    // give up if the other end isn't listening!
    if(!USBUSARTIsTxTrfReady())
        return;

    while (len)
    {
        if(len <= (int) 255)
            tosend= (BYTE) len;
        else
            tosend= (BYTE) 255;

        putUSBUSART(message, tosend);
        message += tosend;
        len -= tosend;

        // don't return until message is sent otherwise we get problems
        // with buffer being overwitten - e.g. LIST
        while (!USBUSARTIsTxTrfReady())
            CDCTxService();
    }
}
Exemplo n.º 6
0
void ProcessIO(void)
{	
	//Blink	the	LEDs according to the USB device status
	BlinkUSBStatus();
	// User	Application	USB	tasks
	if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1))	return;

	// only check	for	new	USB	buffer if the old RS232	buffer is
	// empty.	 This will cause additional	USB	packets	to be NAK'd

	// RS232_送信バッファに HostPC から届いたデータをFillする.
	if (LastRS232Out == 0) {						  
		LastRS232Out = getsUSBUSART(RS232_Out_Data,64);	//until	the	buffer is free.
		if(LastRS232Out	> 0) {
//			RS232_Out_Data_Rdy = 1;	 //	signal buffer full
			RS232cp	= 0;  // Reset the current position
		}
	}

	if(LastRS232Out && (NextUSBOut==0)) {
		//エコーバック専用:
		memcpy(USB_Out_Buffer,RS232_Out_Data,LastRS232Out);
		NextUSBOut = LastRS232Out;
		LastRS232Out = 0;
	}

	//可能なら、RS232_受信バッファの内容をHostPCに送る.
	if((USBUSARTIsTxTrfReady())	&& (NextUSBOut > 0)){
		putUSBUSART(&USB_Out_Buffer[0],	NextUSBOut);
		NextUSBOut = 0;
	}

	CDCTxService();
}
/********************************************************************
 * Function:        void ProcessUSBData(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessUSBData(void)
{
    // User Application USB tasks
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

    if(USBUSARTIsTxTrfReady())
    {
        if(currentMode != PR_NOREQUEST)
        {
            continueWithCurrentMode();
        }
        else
        {
            if(dataAvailable==0)
            {
                loadNewData();
            }
            if(dataAvailable > 0)
            {
                UINT8 oldCurrentByte = currentByte;
            	currentByte = (currentByte+1)%BUFFER_SIZE;
                dataAvailable--;

                handleProcessRequest(USB_In_Buffer[oldCurrentByte]);
            }
        }
        
    }

    CDCTxService();
}		//end ProcessIO
Exemplo n.º 8
0
unsigned int usb_tty_loop(void){
    USB_BUFFER usb_task;

    /* regiao critica */
    portENTER_CRITICAL();

    if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1)){
        portEXIT_CRITICAL();
        return 0;
    }

    if (USBUSARTIsTxTrfReady()){
        if (buffer_entrada_cont == 0) {
            buffer_entrada_cont = getsUSBUSART((char *)buffer_entrada, sizeof(buffer_entrada));
        }

        if(xQueueReceive(usb_buffer_queue, &usb_task, ( portTickType ) 10)){
            putUSBUSART((char *)usb_task.out, usb_task.co);
        }
    }

    CDCTxService();

    portEXIT_CRITICAL();

    return 1;
}
Exemplo n.º 9
0
/*
 * Main program entry point.
 */
int main (void)
{
	AD1PCFG = 0xFFFF;

	//Initialize all of the LED pins
	LATE |= 0x000F;
	TRISE &= 0xFFF0;

	USBDeviceInit();	//usb_device.c.  Initializes USB module SFRs and firmware
    				//variables to known states.
	PMCON = 0;

	for (;;) {
		// Check bus status and service USB interrupts.
		USBDeviceTasks(); // Interrupt or polling method.  If using polling, must call
        			  // this function periodically.  This function will take care
        			  // of processing and responding to SETUP transactions
        			  // (such as during the enumeration process when you first
        			  // plug in).  USB hosts require that USB devices should accept
        			  // and process SETUP packets in a timely fashion.  Therefore,
        			  // when using polling, this function should be called
        			  // frequently (such as once about every 100 microseconds) at any
        			  // time that a SETUP packet might reasonably be expected to
        			  // be sent by the host to your device.  In most cases, the
        			  // USBDeviceTasks() function does not take very long to
        			  // execute (~50 instruction cycles) before it returns.

		// Application-specific tasks.
		// Blink the LEDs according to the USB device status
		BlinkUSBStatus();

		// User Application USB tasks
		if (USBDeviceState >= CONFIGURED_STATE && ! (U1PWRC & PIC32_U1PWRC_USUSPEND)) {
			unsigned nbytes_read;
			static unsigned char inbuf[64], outbuf[64];
			static unsigned led3_count = 0;

			// Pull in some new data if there is new data to pull in
			nbytes_read = getsUSBUSART ((char*) inbuf, 64);
			if (nbytes_read != 0) {
				snprintf (outbuf, sizeof(outbuf),
					"Received %d bytes: %02x...\r\n",
					nbytes_read, inbuf[0]);
				putUSBUSART ((char*) outbuf, strlen (outbuf));
				mLED_2_Toggle();
				mLED_3_On();
				led3_count = 10000;
			}
			if (led3_count) {
				// Turn off LED3 when timeout expired.
				led3_count--;
				if (led3_count == 0)
					mLED_3_Off();
			}

			CDCTxService();
		}
	}
}
Exemplo n.º 10
0
static uint8_t USB_CDC_get(void) {
    uint8_t numBytesRead;
    if (USBUSARTIsTxTrfReady() == true) {
        numBytesRead = getsUSBUSART(readBuffer, sizeof (readBuffer));
    }
    CDCTxService();
    return numBytesRead;
}
Exemplo n.º 11
0
/********************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessIO(void)
{   
    BYTE numBytesRead;

    //Blink the LEDs according to the USB device status

    //
    // User Application USB tasks
    //

    // If suspended, do nothing.
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

    // If character received, echo it
    if(mUSBUSARTIsTxTrfReady())
    {
        numBytesRead = getsUSBUSART(USB_Out_Buffer,64);
        if(numBytesRead != 0)
        {
            BYTE i;
            
            #ifdef NETV
            
            #else            
            for(i=0;i<numBytesRead;i++)
            {
            	USB_In_Buffer[i] = USB_Out_Buffer[i];    
            }
    
    		//Test: Send SPI word to control motor
    		if(USB_In_Buffer[0] == 'u')
    		{
		    	motor_speed += 250;
		    	if(motor_speed > 3000)
		    	motor_speed = 3000;
		    	SpiChnPutC(4, motor_speed);   
	    	}
	    	else if(USB_In_Buffer[0] == 'i')
	    	{
		    	motor_speed -= 250;
		    	if(motor_speed < -3000)
		    	motor_speed = -3000;
		    	SpiChnPutC(4, motor_speed);  
	    	}
	    	
            putUSBUSART(USB_In_Buffer,numBytesRead);	//Echo
            HBLED1 ^= 1; //Toggle LEDs
            HBLED2 ^= 1;
            #endif
        }
    }

    // Service the USB CDC driver
    CDCTxService();

} // End ProcessIO
Exemplo n.º 12
0
/** Procesamiento de información USB  */
void USB_process(void) {
    static char RTCC_CONF[] = "rtccconfig";
    static char RTCC_TEST[] = "rtcctest";
    static char XBEE_JOIN[] = "xbeejoin";
    static char ADC_TEST[] = "adctest";
    // Sht-11 test commands
    static char SHT[] = "shttest";

    BYTE numBytesRead;

    // Init payloads
    Payload_init(&usbInputBuffer);
    Payload_init(&usbOutputBuffer);

    // User Application USB tasks
    if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1)) {
        return;
    }
    // Recibe un buffer de tamaño determinado
    numBytesRead = getsUSBUSART((char*)usbOutputBuffer.data, 64);

    // Si ha leído datos
    if (numBytesRead != 0) {
        if (strncmp((char*)usbOutputBuffer.data, RTCC_CONF, strlen(RTCC_CONF)) == 0) {
            Rtc_readInputStream(&usbOutputBuffer);
            Rtc_writeFormattedTimestamp(&usbInputBuffer);
        } else if (strncmp((char*)usbOutputBuffer.data, RTCC_TEST, strlen(RTCC_TEST)) == 0) {
            Rtc_readTimestamp();
            Rtc_writeFormattedTimestamp(&usbInputBuffer);
        } else if (strncmp((char*)usbOutputBuffer.data, XBEE_JOIN, strlen(XBEE_JOIN)) == 0) {
            XBee_join();
            Payload_putString(&usbInputBuffer, (UINT8*) "Join request sent");
        } else if (strncmp((char*)usbOutputBuffer.data, ADC_TEST, strlen(ADC_TEST)) == 0) {
           // TODO
            Payload_putString(&usbInputBuffer, (UINT8*) "Adc test received");
        } else if (strncmp((char*)usbOutputBuffer.data, SHT, strlen(SHT)) == 0) {
#if SHT_ENABLED
            Sht11_measure(&sht);
            Sht11_addMeasuresCalculatedToPayload(&sht, &usbInputBuffer);
#else
            Payload_putString(&usbInputBuffer, (UINT8*) "SHT11 not installed");
#endif
        } else {
            // Si el comando es erróneo, muestra un mensaje de error
            Payload_putString(&usbInputBuffer, (UINT8*) "Comando desconocido");
        }
        // Si está preparado para enviar datos
        if (USBUSARTIsTxTrfReady() && usbInputBuffer.size != 0) {
            putUSBUSART((char*)usbInputBuffer.data, (BYTE) usbInputBuffer.size);
        }
    }

    CDCTxService();
}
Exemplo n.º 13
0
void ProcessIO(void)
{	
	uchar i;
	BlinkUSBStatus();		//Blink	the	LEDs according to the USB device status
	// User	Application	USB	tasks
	if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1))	return;

	// only check	for	new	USB	buffer if the old RS232	buffer is
	// empty.	 This will cause additional	USB	packets	to be NAK'd

	// RS232_送信バッファに HostPC から届いたデータをFillする.
	if( mDataRdyUSART() < 32 ) 

	if (LastRS232Out == 0) {						  
		LastRS232Out = getsUSBUSART(RS232_Out_Data,64);	//until	the	buffer is free.
		if(LastRS232Out	> 0) {
//			RS232_Out_Data_Rdy = 1;	 //	signal buffer full
			RS232cp	= 0;  // Reset the current position
		}
	}

#if	USART_USE_TX_INTERRUPT		// 送信割り込みを使用する.
	//USARTが送信可であれば RS232_送信バッファの内容を USARTに 1文字送る.
	if(LastRS232Out && mTxRdyUSART())	{
//		PIR1bits.TXIF = 0;			// 送信割り込みフラグ.
		PIE1bits.TXIE = 1;			// 送信割り込み許可.
	}
#else
	//USARTが送信可であれば RS232_送信バッファの内容を USARTに 1文字送る.
	if(LastRS232Out && mTxRdyUSART())	{
		putcUSART(RS232_Out_Data[RS232cp]);	//1文字送る.
		++RS232cp;
		if (RS232cp	== LastRS232Out) {
//			RS232_Out_Data_Rdy = 0;
			LastRS232Out=0;
			RS232cp=0;
		}
	}
#endif

	//可能なら、RS232_受信バッファの内容をHostPCに送る.
	if((USBUSARTIsTxTrfReady())	&& (mDataRdyUSART())){
		i=0;
		while( mDataRdyUSART() ) {
			if(i>=CDC_DATA_OUT_EP_SIZE) break;
			USB_Out_Buffer[i++]=getcUSART();
		}
		putUSBUSART(&USB_Out_Buffer[0],	i);
		NextUSBOut = 0;
	}

	CDCTxService();
}
/**
 * シリアル・ポートの Ready を待つ
 * timer1 を使ってオーバフローならば 0 を返す
 * Ready になれば 1 を返す
 */
int WaitToReadySerial(void)
{
  PIR1bits.TMR1IF = 0;
  TMR1 = 0;
  PIR1bits.TMR1IF = 0;
  while (PIR1bits.TMR1IF==0) {
    if (mUSBUSARTIsTxTrfReady())
      return 1;
    CDCTxService();
  }
  return 0;
}
Exemplo n.º 15
0
/********************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessIO(void)
{
    //Blink the LEDs according to the USB device status
    BlinkUSBStatus();
    // User Application USB tasks
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;
    if(mUSBUSARTIsTxTrfReady())
    {
        putrsUSBUSART("test123");
    }

    CDCTxService();
}		//end ProcessIO
Exemplo n.º 16
0
int main()
{
	#if defined(PIC32_PINGUINO) || defined(PIC32_PINGUINO_OTG)
	TRISDbits.TRISD9=1;		// because PORTB is shared with SDA on Olimex board
	TRISDbits.TRISD10=1;		// because PORTB is shared with SCL on Olimex board
	#endif	

	SystemConfig(80000000);	// default clock frequency is 80Mhz
									// default peripheral freq. is 40MHz (cf. system.c)

	// All pins of PORTB as digital IOs
#ifdef __32MX220F032D__
	ANSELA = 0;
	ANSELB = 0;
	ANSELC = 0;
#else
	AD1PCFG = 0xFFFF;
#endif
	
	#ifdef __ANALOG__
	analog_init();
	#endif

	#ifdef __MILLIS__
	millis_init();
	#endif

	#ifdef __PWM__
	PWM_init();
	#endif    

	#ifdef __USBCDC
	CDC_init();
	#endif    

	#ifdef __RTCC__
	RTCC_init();
	#endif    
	
	setup();

	while (1)
	{
		#ifdef __USBCDC
		CDCTxService();
		#endif    
		loop();
	}

	return(0);    
}
/******************************************************************************
 * Function:        void USBTasks(void)
 *
 * PreCondition:    InitializeSystem has been called.
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Service loop for USB tasks.
 *
 * Note:            None
 *****************************************************************************/
void USBTasks(void)
{
    /*
     * Servicing Hardware
     */
    USBCheckBusStatus();                    // Must use polling method
    if(UCFGbits.UTEYE!=1)
        USBDriverService();                 // Interrupt or polling method
    
    #if defined(USB_USE_CDC)
    CDCTxService();
    #endif

}// end USBTasks
Exemplo n.º 18
0
int main()
{
	// default peripheral freq. is CPUCoreFrequency / 2 (cf. system.c)
	#if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__)
	SystemConfig(40000000);	// default clock frequency is 40Mhz
	#else
	SystemConfig(80000000);	// default clock frequency is 80Mhz
	#endif

	IOsetSpecial();
	IOsetDigital();
	IOsetRemap();

	#ifdef __ANALOG__
	analog_init();
	#endif

	#ifdef __MILLIS__
	millis_init();
	#endif

	#ifdef __PWM__
	PWM_init();
	#endif    

	#ifdef __USBCDC
	CDC_init();
	#endif    

	#ifdef __RTCC__
	RTCC_init();
	#endif    
	
	setup();

	while (1)
	{
		#ifdef __USBCDC
			#if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__)
				USB_Service( );
			#else
				CDCTxService();
			#endif
		#endif
 
		loop();
	}

	return(0);    
}
Exemplo n.º 19
0
void CDCputs(u8 *buffer, u8 length)
{
    u16 i;
    for (i = 1000; i > 0; --i)
    {
        if (mUSBUSARTIsTxTrfReady())
            break;
        #if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__)
            USB_Service();
        #else
            CDCTxService();
        #endif
    }
    if (i > 0)
    {
        putUSBUSART(buffer, length);
        #if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__)
            USB_Service();
        #else
            CDCTxService();
        #endif
    }
}
unsigned char checkforbyte(void){
	unsigned char inbuf;

	if(usbbufgetbyte(&inbuf)) return 1; //return data
	//wait for more USB data
	//services USB peripheral
	USBDeviceTasks(); 
   	if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)){
		return 1; //goto USB_loop_jump; //USB gone, fail out to main loop
	}
	usbbufservice();//load any USB data into byte buffer
	if(usbbufgetbyte(&inbuf)) return 1; //wait for more data
    CDCTxService();
	return 0;
} 
Exemplo n.º 21
0
void ProcessIO(void)
{	
	uchar cnt;
	//Blink	the	LEDs according to the USB device status
	BlinkUSBStatus();
	// User	Application	USB	tasks
	if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1))	return;

	// only check	for	new	USB	buffer if the old RS232	buffer is
	// empty.	 This will cause additional	USB	packets	to be NAK'd

	// RS232_送信バッファに HostPC から届いたデータをFillする.
	if (LastRS232Out == 0) {						  
		LastRS232Out = getsUSBUSART(RS232_Out_Data,64);	//until	the	buffer is free.
		if(LastRS232Out	> 0) {
			RS232cp	= 0;  // Reset the current position
		}
	}

	for(cnt=0;cnt<32;cnt++) {

		//USARTが送信可であれば RS232_送信バッファの内容を USARTに 1文字送る.
		if(LastRS232Out && mTxRdyUSART())	{
			putcUSART(RS232_Out_Data[RS232cp]);	//1文字送る.
			++RS232cp;
			if (RS232cp	== LastRS232Out) {
				LastRS232Out=0;
				RS232cp=0;
			}
		}

		//USARTがデータを受信済みであれば RS232_受信バッファに溜める.
		if(mDataRdyUSART()) {
			USB_Out_Buffer[NextUSBOut] = getcUSART();
			++NextUSBOut;
			//USB_Out_Buffer[NextUSBOut] = 0;
		}

	}

	//可能なら、RS232_受信バッファの内容をHostPCに送る.
	if((USBUSARTIsTxTrfReady())	&& (NextUSBOut > 0)){
		putUSBUSART(&USB_Out_Buffer[0],	NextUSBOut);
		NextUSBOut = 0;
	}

	CDCTxService();
}
Exemplo n.º 22
0
/********************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessIO(void)
{   
    //Blink the LEDs according to the USB device status
    BlinkUSBStatus();
    // User Application USB tasks
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

	// only check for new USB buffer if the old RS232 buffer is
	// empty.
	// Additional USB packets will be NAK'd
	// until the buffer is free.
	if (RS232_Out_Data_Rdy == 0)
		{
			LastRS232Out = getsUSBUSART(RS232_Out_Data,64);
			
			if(LastRS232Out > 0)
			{
				RS232_Out_Data_Rdy = 1; // signal
										//buffer full
				RS232cp = 0;// Reset the current position
			}
		}
		
	if(RS232_Out_Data_Rdy && mTxRdyUSART())
	{
		putcUSART(RS232_Out_Data[RS232cp]);
		++RS232cp;
		if (RS232cp == LastRS232Out)
			RS232_Out_Data_Rdy = 0;
	}

	if(mDataRdyUSART())
	{
		USB_Out_Buffer[NextUSBOut] = getcUSART();
		++NextUSBOut;
		USB_Out_Buffer[NextUSBOut] = 0;
	}

	if((mUSBUSARTIsTxTrfReady()) && (NextUSBOut > 0))
	{
		putUSBUSART(&USB_Out_Buffer[0], NextUSBOut);
		NextUSBOut = 0;
	}

    CDCTxService();
}		//end ProcessIO
Exemplo n.º 23
0
// *--------------------------------------------------------------------------------*
void ProcessIO(void){   
    BYTE numBytesRead;

    //Blink the LEDs according to the USB device status
    BlinkUSBStatus();
    // User Application USB tasks
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

    if(buttonPressed){
        if(stringPrinted == FALSE){
            if(mUSBUSARTIsTxTrfReady()){
                putrsUSBUSART("Button Pressed -- \r\n");
                stringPrinted = TRUE;
            }
        }
    }else{
        stringPrinted = FALSE;
    }

    if(USBUSARTIsTxTrfReady()){
		numBytesRead = getsUSBUSART(USB_Out_Buffer,64);
		if(numBytesRead != 0){
			BYTE i;
	        
			for(i=0;i<numBytesRead;i++){
				switch(USB_Out_Buffer[i]){
					case 0x0A:
					case 0x0D:
						USB_In_Buffer[i] = USB_Out_Buffer[i];
						break;
					default:
						USB_In_Buffer[i] = USB_Out_Buffer[i] + 1;
						break;
				}
			}
			putUSBUSART(USB_In_Buffer,numBytesRead);
		}
	}

    CDCTxService();
}
Exemplo n.º 24
0
void processUSBData(void) {
    BYTE numBytesRead;
    // User Application USB tasks
    if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1)) {
        return;
    }
    // Si está preparado para recibir datos
    if (mUSBUSARTIsTxTrfReady()) {
        // Recibe un buffer de tamaño determinado
        numBytesRead = getsUSBUSART(USB_Out_Buffer, 64);
        // Si ha leído datos
        if (numBytesRead != 0) {
            // FIXME Usar constantes
            if (strncmppgm2ram(USB_Out_Buffer, RTCC, strlen(RTCC)) == 0) {
                //parseRTCCData(USB_Out_Buffer);
            }
        }
    }

    CDCTxService();
}
Exemplo n.º 25
0
Arquivo: main.c Projeto: z9u2k/remote
/**
 * blink LED, send data on queue
 */
void ProcessIO(void) {

    BlinkUSBStatus();
    
    if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1)) {
        return;
    }

    if (USBUSARTIsTxTrfReady()) {
        int len = 0;
        char temp[QUEUE_SIZE];
        while (QueueHas()) {
            temp[len++] = QueueGet();
        }

		if (len > 0) {
			putUSBUSART(temp, len);
		}
	}

    CDCTxService();
}
Exemplo n.º 26
0
u8 CDCgets(u8 *buffer)
{
    u8 numBytesRead;
        
    #if defined(__32MX220F032D__)||defined(__32MX250F128B__)||defined(__32MX220F032B__)
        USB_Service();
        numBytesRead = USB_Service_CDC_GetString( buffer );
    #else
        CDCTxService();
        numBytesRead = getsUSBUSART(buffer, 64);
    #endif
        return numBytesRead;
/*
    if (mUSBUSARTIsTxTrfReady())
    {
        CDCTxService();
        numBytesRead = getsUSBUSART(buffer, 64);
        CDCTxService();
        return numBytesRead;
    }
*/
}
Exemplo n.º 27
0
void usb_send(const char *format, ...)
{
    //char *usb_msg;
    static unsigned char usb_msg[CDC_DATA_OUT_EP_SIZE];

    va_list args;
    va_start(args,__format);
    sprintf(usb_msg,format,args);
    if (( USBGetDeviceState() < CONFIGURED_STATE ) || ( USBIsDeviceSuspended() == true ))
    {
        return;
    }
    else
    {
        if (mUSBUSARTIsTxTrfReady())
        {
            putUSBUSART(usb_msg,strlen(usb_msg));
        }
        CDCTxService();
    }

}
Exemplo n.º 28
0
/********************************************************************
 * Function:        void ProcessIO(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        This function is a place holder for other user
 *                  routines. It is a mixture of both USB and
 *                  non-USB tasks.
 *
 * Note:            None
 *******************************************************************/
void ProcessIO(void)
{   
    //Blink the LEDs according to the USB device status
    BlinkUSBStatus();
    // User Application USB tasks
    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;

	if (RS232_Out_Data_Rdy == 0)  // only check for new USB buffer if the old RS232 buffer is
	{						  // empty.  This will cause additional USB packets to be NAK'd
		LastRS232Out = getsUSBUSART(RS232_Out_Data,64); //until the buffer is free.
		if(LastRS232Out > 0)
		{	
			RS232_Out_Data_Rdy = 1;  // signal buffer full
			RS232cp = 0;  // Reset the current position
		}
	}

    //Check if one or more bytes are waiting in the physical UART transmit
    //queue.  If so, send it out the UART TX pin.
	if(RS232_Out_Data_Rdy && mTxRdyUSART())
	{
    	#if defined(USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL)
        	//Make sure the receiving UART device is ready to receive data before 
        	//actually sending it.
        	if(UART_CTS == USB_CDC_CTS_ACTIVE_LEVEL)
        	{
        		putcUSART(RS232_Out_Data[RS232cp]);
        		++RS232cp;
        		if (RS232cp == LastRS232Out)
        			RS232_Out_Data_Rdy = 0;
    	    }
	    #else
	        //Hardware flow control not being used.  Just send the data.
    		putcUSART(RS232_Out_Data[RS232cp]);
    		++RS232cp;
    		if (RS232cp == LastRS232Out)
    			RS232_Out_Data_Rdy = 0;	    
	    #endif
	}

    //Check if we received a character over the physical UART, and we need
    //to buffer it up for eventual transmission to the USB host.
	if(mDataRdyUSART() && (NextUSBOut < (CDC_DATA_OUT_EP_SIZE - 1)))
	{
		USB_Out_Buffer[NextUSBOut] = getcUSART();
		++NextUSBOut;
		USB_Out_Buffer[NextUSBOut] = 0;
	}
	
	#if defined(USB_CDC_SUPPORT_HARDWARE_FLOW_CONTROL)
    	//Drive RTS pin, to let UART device attached know if it is allowed to 
    	//send more data or not.  If the receive buffer is almost full, we 
    	//deassert RTS.
    	if(NextUSBOut <= (CDC_DATA_OUT_EP_SIZE - 5u))
    	{
            UART_RTS = USB_CDC_RTS_ACTIVE_LEVEL;
        }   	
        else
        {
        	UART_RTS = (USB_CDC_RTS_ACTIVE_LEVEL ^ 1);
        }    
    #endif	

    //Check if any bytes are waiting in the queue to send to the USB host.
    //If any bytes are waiting, and the endpoint is available, prepare to
    //send the USB packet to the host.
	if((USBUSARTIsTxTrfReady()) && (NextUSBOut > 0))
	{
		putUSBUSART(&USB_Out_Buffer[0], NextUSBOut);
		NextUSBOut = 0;
	}

    CDCTxService();

}//end ProcessIO
Exemplo n.º 29
0
void ProcessIO(void)
{   
    unsigned short result;
	static char state=VALUES;
	static char count=-1;
	static char adc_nr=0;
	static short adcchannel=0;
	char overflow=0;

    // User Application USB tasks

    if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1)) return;


	if(state == PUTHEADER){
		if( mUSBUSARTIsTxTrfReady() ){
			 putsUSBUSART(USB_Head_Buffer);
			state = VALUES;
		}
	} else {


	if( mUSBUSARTIsTxTrfReady() ){             // Wait for completion

		USB_Out_Buffer[0]++;
		count++;
		if(count>=64){ //max channels
			count=0;
			USB_Out_Buffer[0] = 60; //start character
		}
		

	//	if (count<=11) result = read_register(1, (0x0b+count) ); else
	//	result = read_register(2, (0x0b+count-12) );
		adcchannel++;
		if(adcchannel==16){
 				adcchannel=0;
				overflow=1;
		}
		result = spi_transfer(adc_nr, ( WRITE_REG | (adcchannel<<10) ));

			if(overflow==1){
 				overflow=0;
				adc_nr++;
				if(adc_nr==4) adc_nr=0;
			}

		USB_Out_Buffer[3] = result &0xFF;
		USB_Out_Buffer[2] = (result &0xFF00)>>8;

		putUSBUSART(USB_Out_Buffer,5);
		LED = !LED;
		


	 }
	}




    CDCTxService();
}		//end ProcessIO
Exemplo n.º 30
0
void CDCTasks(void)
{
	BYTE numBytesRead;

	// Blink the LEDs according to the USB device status
	if (blinkStatusValid)
	{
		BlinkUSBStatus();
	}

	// User Application USB tasks
	if ((USBDeviceState < CONFIGURED_STATE) || (USBSuspendControl == 1))
	{
		return;
	}

#if (HILSIM_USB == 1)
	numBytesRead = getsUSBUSART(USB_In_Buffer, sizeof(USB_In_Buffer));
	if (numBytesRead != 0)
	{
		int i = 0;
		while (i < numBytesRead)
		{
			udb_gps_callback_received_byte(USB_In_Buffer[i++]);
		}
	}

	if (mUSBUSARTIsTxTrfReady())
	{
		int i = 0;
		int txchar;
		while ((i < sizeof(USB_Out_Buffer)) && ((txchar = udb_gps_callback_get_byte_to_send()) != -1))
		{
			USB_Out_Buffer[i++] = txchar;
		}
		if (i > 0)
		{
			putUSBUSART(USB_Out_Buffer, i);
		}
	}

#else
	if (mUSBUSARTIsTxTrfReady())
	{
		numBytesRead = getsUSBUSART(USB_Out_Buffer, sizeof(USB_Out_Buffer));
		if (numBytesRead != 0)
		{
			BYTE i;

			for (i = 0; i < numBytesRead; i++)
			{
				switch (USB_Out_Buffer[i])
				{
					case 0x0A:
					case 0x0D:
						USB_In_Buffer[i] = USB_Out_Buffer[i];
						break;
					default:
						USB_In_Buffer[i] = USB_Out_Buffer[i] + 1;
						break;
				}
			}
			putUSBUSART(USB_In_Buffer, numBytesRead);
		}
	}
#endif
	CDCTxService();
}