www.pudn.com > S3C2410_USB_Device.rar > usbin.c


/**************************************************************** 
 NAME: usbin.c 
 DESC: usb bulk-IN operation 
 HISTORY: 
 Mar.25.2002:purnnamu: ported for S3C2410X. 
 ****************************************************************/ 
#include "../inc/def.h" 
#include "../inc/config.h" 
#include "../inc/board.h" 
#include "../inc/2410addr.h" 
 
#include "2410usb.h" 
#include "usblib.h" 
#include "usbsetup.h" 
#include "usbout.h" 
#include "usbin.h" 
 
#ifdef	USB_DOWNLOAD_SUPPORT 
 
// =================================================================== 
// All following commands will operate in case  
// - in_csr1 is valid. 
// =================================================================== 
 
#define SET_EP1_IN_PKT_READY()  rIN_CSR1_REG= ( in_csr1 &(~ EPI_WR_BITS)\ 
					| EPI_IN_PKT_READY )	  
#define SET_EP1_SEND_STALL()	rIN_CSR1_REG= ( in_csr1 & (~EPI_WR_BITS)\ 
					| EPI_SEND_STALL) ) 
#define CLR_EP1_SENT_STALL()	rIN_CSR1_REG= ( in_csr1 & (~EPI_WR_BITS)\ 
					&(~EPI_SENT_STALL) ) 
#define FLUSH_EP1_FIFO() 	rIN_CSR1_REG= ( in_csr1 & (~EPI_WR_BITS)\ 
					| EPI_FIFO_FLUSH) ) 
 
 
// *************************** 
// *** VERY IMPORTANT NOTE *** 
// *************************** 
// Prepare the code for the packit size constraint!!! 
 
// EP1 = IN end point.  
 
extern U32 UsbState; 
extern U32 UsbInLength; 
extern U8 *UsbTxAddr; 
 
U8 ep1Buf[EP1_PKT_SIZE]; 
int transferIndex=0; 
 
 
void PrepareEp1Fifo(void)  
{ 
    int i; 
    U8 in_csr1;    
     
    rINDEX_REG=1; 
    in_csr1=rIN_CSR1_REG; 
     
	for(i=0;iEP1_PKT_SIZE)?EP1_PKT_SIZE:UsbInLength); 
   	if(!UsbInLength) 
   		UsbState = 0; 
    SET_EP1_IN_PKT_READY();  
} 
 
 
void Ep1Handler(void) 
{ 
    U8 in_csr1; 
     
    rINDEX_REG = 1;     
    in_csr1 = rIN_CSR1_REG;    
 
    //I think that EPI_SENT_STALL will not be set to 1. 
    if(in_csr1 & EPI_SENT_STALL) 
    {    
//		DbgOut("[STALL]"); 
	   	CLR_EP1_SENT_STALL(); 
   		return; 
    }	 
 
    //IN_PKT_READY is cleared 
     
    //The data transfered was ep1Buf[] which was already configured   
     
	transferIndex++;		 
			 
	if(UsbState==0x01234567)	 
		PrepareEp1Fifo(); 
    		    	 
     
    	//IN_PKT_READY is set    
    	//This packit will be used for next IN packit.	 
 
    return; 
}    
 
#endif