⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbin.c

📁 三星S3C2460 USB DEVICE /USB HOST 监控代码
💻 C
字号:
/****************************************************************
 NAME: usbin.c
 DESC: usb bulk-IN operation
 HISTORY:

 ****************************************************************/
#include <string.h>

#include "Option.h"
#include "2460addr.h"
#include "2460lib.h"

#include "2460usb.h"
#include "usbmain.h"
#include "usb.h"
#include "usblib.h"
#include "usbsetup.h"
#include "usbin.h"



static void PrintEpiPkt(unsigned char *pt,int cnt);


// ===================================================================
// 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. 

unsigned char ep1Buf[EP1_PKT_SIZE];
int transferIndex=0;

extern void DbgPrintf(char * fmt,...);

void PrepareEp1Fifo(void) 
{
    	int i;
    	unsigned char in_csr1;
    	rINDEX_REG=1;
    	in_csr1=rIN_CSR1_REG;
    	for(i=0;i<EP1_PKT_SIZE;i++)ep1Buf[i]=(unsigned char)(transferIndex+i); // test data
    	WrPktEp1(ep1Buf,EP1_PKT_SIZE);
    	SET_EP1_IN_PKT_READY();  // after writing a packet of data into the fifo
    							    // USB clears this bit once the packet has been successfully sent to the host
    							    // An interrupt is generated when the USB clears this bit.
}


void Ep1Handler(void)
{
    	unsigned char in_csr1;
    	int i;
    	rINDEX_REG=1;
    	in_csr1=rIN_CSR1_REG;
      
    	DbgPrintf("<1:%x]",in_csr1);

    	//I think that EPI_SENT_STALL will not be set to 1.
    	if(in_csr1 & EPI_SENT_STALL)
    	{   
   		DbgPrintf("[STALL]");
   		CLR_EP1_SENT_STALL();
   		return;
    	}	

    	//IN_PKT_READY is cleared
    
    	//The data transfered was ep1Buf[] which was already configured 

    	PrintEpiPkt(ep1Buf,EP1_PKT_SIZE); 
    
    	transferIndex++;

    	PrepareEp1Fifo(); 
    	//IN_PKT_READY is set   
    	//This packit will be used for next IN packit.	

    	return;
}


    
void PrintEpiPkt(unsigned char *pt,int cnt)
{
    int i;
    DbgPrintf("[B_IN:%d:",cnt);
    for(i=0;i<cnt;i++)
    	DbgPrintf("%x,",pt[i]);
    DbgPrintf("]");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -