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

📄 main.c

📁 atmelsam7s64的usb数据传输例程
💻 C
字号:
//*--------------------------------------------------------------------------------------
//*      ATMEL Microcontroller Software Support  -  ROUSSET  -
//*--------------------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*--------------------------------------------------------------------------------------
//* File Name           : main.c
//* Object              : Testr USB device
//* Translator          :
//* 1.0 19/03/01 HI     : Creation
//* 1.1 02/10/02 FB     : Add on Svc DataFlash
//* 1.2 13/Sep/04 JPP	: Add DBGU
//* 1.3 16/Dec/04 JPP	: Add USART and enable reset
//* 1.4 27/Apr/05 JPP   : Unset the USART_COM and suppress displaying data
//*--------------------------------------------------------------------------------------

#include "board.h"
#include "dbgu.h"
#include "cdc_enumerate.h"

#define MSG_SIZE 				64   
#define UDP_INTERRUPT_LEVEL		2   
#define SOFT_INTERRUPT_LEVEL	5


//#define USART_COM

//* external function

extern void Usart_init ( void );
extern void AT91F_US_Put( char *buffer); // \arg pointer to a string ending by \0
extern void Trace_Toggel_LED( unsigned int led) ;

struct _AT91S_CDC 	pCDC; 
AT91PS_CDC pCdc;
char data[MSG_SIZE],i; 
unsigned char flag;
AT91PS_AIC     pAic; 

//*----------------------------------------------------------------------------
//* \fn    AT91F_USB_Open
//* \brief This function Open the USB device
//*----------------------------------------------------------------------------
void AT91F_USB_Open(void)
{
    // Set the PLL USB Divider
    AT91C_BASE_CKGR->CKGR_PLLR |= AT91C_CKGR_USBDIV_1 ;

    // Specific Chip USB Initialisation
    // Enables the 48MHz USB clock UDPCK and System Peripheral USB Clock
    AT91C_BASE_PMC->PMC_SCER = AT91C_PMC_UDP;
    AT91C_BASE_PMC->PMC_PCER = (1 << AT91C_ID_UDP);

    // Enable UDP PullUp (USB_DP_PUP) : enable & Clear of the corresponding PIO
    // Set in PIO mode and Configure in Output
   // AT91F_PIO_CfgOutput(AT91C_BASE_PIOA,AT91C_PIO_PA16);
    // Clear for set the Pul up resistor
   // AT91F_PIO_ClearOutput(AT91C_BASE_PIOA,AT91C_PIO_PA16);

    // CDC Open by structure initialization
    AT91F_CDC_Open(&pCDC, AT91C_BASE_UDP);
}
  
void Aic_Soft_Test(void)
{
    *AT91C_PIOA_CODR  =   LED1; 
}
void Pcwirte_Handler(void)
{       
	unsigned int nbBytesRcv=0 ;
       //  currentReceiveBank= AT91C_UDP_CSR[1];             
        if( AT91C_UDP_CSR[1] & 0x42) 
        {  
          while(nbBytesRcv  < 64)
	  {  
          data[nbBytesRcv++] =AT91C_UDP_FDR[1];    
	  } 
          AT91C_UDP_CSR[1] &= 0xfffffffbd;  
          flag=1; 
          AT91F_AIC_DisableIt (pAic, AT91C_ID_UDP);   
        } 
}
//*--------------------------------------------------------------------------------------
//* Function Name       : main
//* Object              :
//*--------------------------------------------------------------------------------------
int main ( void )
{
      flag=0;

      pAic = AT91C_BASE_AIC;   
      // Enable User Reset and set its minimal assertion to 960 us
     AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4<<8) | (unsigned int)(0xA5<<24);

    // Init USB device
    AT91F_USB_Open(); 

         //open  usb interrupt
        AT91F_AIC_ConfigureIt ( pAic,AT91C_ID_UDP , UDP_INTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, Pcwirte_Handler);
        *AT91C_UDP_IER=  AT91C_UDP_EPINT1 ; 
    
     // Init USB device
    while (1)
   {     
	// Check enumeration
	if (pCDC.IsConfigured(&pCDC)) {  
            AT91F_AIC_EnableIt (pAic, AT91C_ID_UDP);
           while(!flag) ;
          pCDC.Write(&pCDC,data, 64);  
         flag=0;
	}
   }
}


⌨️ 快捷键说明

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