示例#1
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();
}
示例#2
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();
}
示例#3
0
文件: main.c 项目: Athuli7/Microchip
/********************************************************************
 * 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
示例#4
0
文件: main.c 项目: iruka-/ORANGEpico
/********************************************************************
 * 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
示例#5
0
文件: usart.c 项目: jeffhuys/IvIBot
void putcUSART(char c) {
//    PORTB = 0x0f;
    while(!mTxRdyUSART());
	TXREG = c;
//    PORTB = 0x0;
}