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

📄 usb_otg_dev_out.tmp.c

📁 三星 S3C2460 USB OTG监控代码
💻 C
字号:
/*******************************************************************************
* File Name    : usb_otg_dev_out.c
* Description  : S3C2460A USB OTG bulk-OUT operation
* Author       : Haksoo Kim
* Dept         : Mobile solution, AP
* Created Date : 2005.06.02
* Version      : 1.0
* History
*   R1.0 (2005.06.02): First Release
********************************************************************************/ 

#include <stdio.h> 
#include <string.h>

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

#include "2460usb_otg_dev.h"
#include "usb_otg_dev_main.h"
#include "usb_otg.h"
#include "usb_otg_dev_lib.h"
#include "usb_otg_dev_setup.h"
#include "usb_otg_dev_out.h"
#include "2460MON.h"

static void RdPktEp3_CheckSum(uint8 *buf,int num);
static void Cal_CheckSum(uint8 *buf,int num);


// ***************************
// *** VERY IMPORTANT NOTE ***
// ***************************
// Prepare for the packit size constraint!!!

// EP3 = OUT end point. 

unsigned char ep3Buf[OTG_EP3_PKT_SIZE];
static unsigned char tempBuf[64+1];

void UsbOtg_Ep3RxHandler(void)
{
	uint32 rxCount;
	unsigned int dest_addr;
	uint32 *tmp_downPtr;
	
	apOTG_TLI_DEV_S->OutEP[3].control &= ~OTG_DEV_RX_FIFOREADY;			  	    
	
	if(apOTG_TLI_DEV_G->rxStatus & OTG_DEV_RX_GOOD_STATUS)
	{
	
		rxCount = ((apOTG_TLI_DEV_G->rxStatus) >> OTG_DEV_RX_COUNT_SHIFT) & OTG_DEV_RX_COUNT_MASK;

		#if USBOTG_DMA
		totalRxCountInDMA += rxCount;
		#endif
				
		if(downloadFileSize==0)
		{
	   		RdPktEp3((uint8 *)downPt,16); 		   		
	   	    
			if(download_run==0)
	   	  	{
				downloadAddress=tempDownloadAddress;
			}
		    else
		    {
		    	downloadAddress=
		    			*((unsigned char *)(downPt+0))+
						(*((unsigned char *)(downPt+1))<<8)+
						(*((unsigned char *)(downPt+2))<<16)+
						(*((unsigned char *)(downPt+3))<<24);
		    }
		    downloadFileSize=
		    		*((unsigned char *)(downPt+4))+
					(*((unsigned char *)(downPt+5))<<8)+
					(*((unsigned char *)(downPt+6))<<16)+
					(*((unsigned char *)(downPt+7))<<24);
		    checkSum=0;
		    
		    tmp_downPtr = (uint32 *)(downPt+8);
		    
		    *(uint32 *)downloadAddress = *tmp_downPtr++;
		    *(uint32 *)(downloadAddress+4) = *tmp_downPtr;		    
		    
		    Cal_CheckSum((uint8 *)(downPt+8),8);
		    
		    downPt=(unsigned char *)(downloadAddress+8);
		    		    	    
	  	   	RdPktEp3_CheckSum((uint8 *)downPt,rxCount-16); //The first 8-bytes are deleted.	
	  	    downPt+=rxCount-16; 
		}
		else
		{
		  #if USBOTG_DMA
			
		   #if USBOTG_UNIT_DMA
		   	if((rxCount >= 4) && (rxCount%4) == 0)
		   #else //burst
		   	if((rxCount >= 16) && (rxCount%16) == 0)		   
		   #endif	
			{
				dest_addr = downloadAddress+totalRxCountInDMA-8-rxCount;
				ConfigEp3DmaMode(dest_addr,rxCount);
		    	downPt+=rxCount;
			
				return;
			}   
			
		  #endif
			
			RdPktEp3_CheckSum((uint8 *)downPt,rxCount); 	    
		    downPt+=rxCount;
		}
	}

	apOTG_TLI_DEV_S->OutEP[3].control |= OTG_DEV_RX_FLUSHFIFO;
	
	//* Initialize pointer to Rx FIFO
	ptrRxFifo = OTG_DEV_RX_FIFO;

	apOTG_TLI_DEV_S->OutEP[3].control |= OTG_DEV_RX_FIFOREADY;
	
	return;
}

void RdPktEp3_CheckSum(uint8 *buf,int num)
{
    int i,j;
    char a,b;
    uint32 temp;
    
    a=num/4;
    b=num%4;
    	
    for(i=0;i<a;i++)
    {
        *((uint32*)buf) = (uint32)*ptrRxFifo++;
        temp = *((uint32*)buf);
        for(j=0;j<4;j++)
        {
	        checkSum += temp & 0xff;
	        temp >>= 8;
	    }
	    ((uint32*)buf)++;
    }
    if(b!=0)
    {
    	temp = (uint32)*ptrRxFifo++;
        for(j=0;j<b;j++)
        {
        	*((uint8 *)buf)++ = temp & 0xff;
	        checkSum += temp & 0xff;
        	temp >>= 8;
	    }
    }  
    
}

void Cal_CheckSum(uint8 *buf,int num)
{
    int i,j;
    char a,b;
    uint32 temp;
    
    a=num/4;
    b=num%4;
    	
    for(i=0;i<a;i++)
    {
        temp = *((uint32*)buf);
        for(j=0;j<4;j++)
        {
	        checkSum += temp & 0xff;
	        temp >>= 8;
	    }
	    ((uint32*)buf)++;
    }
    if(b!=0)
    {
        for(j=0;j<b;j++)
        {
        	*((uint8 *)buf)++ = temp & 0xff;
	        checkSum += temp & 0xff;
        	temp >>= 8;
	    }
    }  
    
}
#if USBOTG_DMA
extern uint8 dma_first;
void __irq IsrOtgDma2(void)
{
    unsigned int i;

    rSUBSRCPND|=BIT_SUB_DMA2;
    ClearPending(BIT_DMA_SBUS);
	
    if(totalRxCountInDMA>=downloadFileSize)
    {
    	totalRxCountInDMA=downloadFileSize;   
    	dma_first = 1;
    }
	
    ConfigEp3IntMode();	
    
    return;
}
#endif


⌨️ 快捷键说明

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