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

📄 dspboard.c

📁 使用5509A的usb的程序代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <std.h>

#include <log.h>
#include <hst.h>
#include <pip.h>
#include <swi.h>
#include <csl_gpio.h>
#include <csl_irq.h>
#include <csl_emif.h>


#include "DspBoard_const.h"

#include "DspSyscfg.h"



/************* Macro defination **********************************/
//#define HalfFIFO  2048 
//#define PulseSize 512  //default is 512
//#define PulseAmount HalfFIFO/PulseSize
//#define ChannelAmount 16384
//#define RealChannelAmount 8192


//#define FullSDRAM 1000
//#define TransferUsbSize  4096



/******************************************************************************/
/*                   Endpoint Data Buffers                                    */
/*                                                                            */
/******************************************************************************/


// Endpt2BuffLen以byte为单位,为方面后面usb传输用 ----by mark
//#define Endpt2BuffLen 0x0200
Uint16 Endpt2BuffLen = 512;
Uint16 Endpt2Buff[257];

/* Spectrum Data */
Uint32 mcaData[ ChannelAmount ] ; // ChannelAmount == 16384 , 32-k byte,16-k word
Uint32 mcaData512[ 512 ];      
Uint32 mcaData1024[ 1024 ];    
Uint32 mcaData2048[ 2048 ];    
Uint32 mcaDataCRC[ 16 ] ;      // 64 byte for fit bulk transfer packet
Uint16  mcaTranLength = 1024;
Uint16  nTranContent = 1 ;   // 1 for junk transfer, 2 for Data transfer, 3 for CRC transfer
Uint16  indexUSB = 0 ;

#pragma DATA_SECTION(databuffer0,"my_sect0")
Int16 databuffer0[HalfFIFO] ;// HalfFIFO == 2048 , 4-k byte,2-k word
#pragma DATA_SECTION(databuffer1,"my_sect1")
Int16 databuffer1[HalfFIFO] ;// HalfFIFO == 2048 , 4-k byte,2-k word
#pragma DATA_SECTION(databuffer2,"my_sect2")
Int16 databuffer2 ;

/*  Processing Method  */
Uint16 indicatorOfProcMeth = PROCESSING_TOP_VALUE ;

/*   intput polarity */
Uint16 indicatorOfPolarity = POLARITY_POS ;

/*  Buffer Written Flag:  bit0 represents the status of buffer0,bit 1 represents buffer 1  */
/*                   :  x...x00b means both buffer ready */
/*                   :  x...x01b means buffer0 is no longer ready ,but buffer1 ready */
/*                   :  x...x10b means buffer0 is ready ,but buffer1 is not ready */
/*                   :  x...x11b means both buffers are not ready */
Uint16 iBufferReady = 0 ;

/*   buffer written flag  */
//#define BUFFER_IS_READY    0x0003    /*  Anded combination of Data Ready Flag  */
//#define BUFFER_0_WRITTEN   0x0001    /*  Ored combination of Data Ready Flag   */
//#define BUFFER_1_WRITTEN   0x0002    /*  Ored combination of Data Ready Flag  */
//#define BUFFER_0_READY     0xFFFE    /*  Anded combination of Data Ready Flag  */
//#define BUFFER_1_READY     0xFFFD    /*  Anded combination of Data Ready Flag  */

/* Variable to indicate whether collecting is going */
Bool bCollectingIsOn ;    /* TRUE indicate collecting is on */

/*  Variable to record the variable counts of the events */ 
Uint32 nRecordMissed = 0 ;
Uint32 nRecordOverFlow =0 ;
Uint32 nRecordCorrect = 0 ;
Uint32 nRecordDMA0Miss = 0 ;
Uint32 nRecordDMA1Miss = 0 ;
Uint32 nRecordDMA2Miss = 0 ;

/* Variable to assist the Time function */
Uint32 nRecordTime = 0 ;    // Record elapsed time for collecting, 1ms resolution
//Uint16 uiLed ;
Uint16 uiSecond=0;          // Timer1 func calls back at every 1ms and uiSecond++, which reached 1000 for 1s


Bool   bDMA0On ;
Bool   bDMA1On ;
Bool   bDMA2On ;

Uint32 i32 ;
Uint16 i , j ;
//Uint16 indexI ;
int * sourceAddr;



Uint16 na ,nb ,nc ,nf ;
Uint16 k ;

extern Void Buffer0Processing();
extern Void Buffer1Processing();
extern Void GenerateH ( Uint16 na , Uint16 nb , Uint16 nc , Uint16 nf , Uint16 * h );

extern USB_EpObj* myUsbConfig[];




Void main()
{      
    bDMA0On = FALSE ;
    bDMA1On = FALSE ;
    bDMA2On = FALSE ;
        
    for ( i32 = 0 ; i32 < 257 ; i32 ++ )
        Endpt2Buff[ i32 ] = 0x5555 ;
    // ChannelAmount  == 16384
    
    for (  i32 = 0 ; i32 < ChannelAmount ; i32 ++ )
    {
        //mcaData[ i32 ] = ( i32 & 0x3FC0) << 18 ;
        mcaData[ i32 ] = 0 ;
    }    
        
    for ( i32 = 0 ; i32 < 512 ; i32 ++ )
    {
        mcaData512[ i32 ] = 0 ;            
        //mcaData512[ i32 ] = i32 ;    
    }        
    
    
    for ( i32 = 0 ; i32 < 1024 ; i32 ++ )
    {
        mcaData1024[ i32 ] = 0 ;    
        //mcaData1024[ i32 ] = i32+1000 ;    
    }      
    
      
    for ( i32 = 0 ; i32 < 2048 ; i32 ++ )
    {        
        mcaData2048[ i32 ] = 0 ;
        //mcaData2048[ i32 ] = i32+10000 ;
    }     
    
    i32 = 0 ;   
    for (  ; i32 < 15 ; i32 ++ )
    {
        mcaDataCRC[ i32 ] = 0xFFFFFFFF ;
    }
    mcaDataCRC[ 15 ] = 0 ;
        
    LOG_printf(&trace,"main");     
}



/*************************************************************/
    // LifeTime    : ---Idle---;---Transfer---;---Idle---;----Processing----;---Idle---    
    // iBufferReady:    Ready  Written-----------------------------------Ready    
    // bDMAOn      :    False  True----------False
    //
    // flag   : Int should be with iBufferReady,   
    //                     iBufferReady==Ready--> ok to start DMA
    //        : ProcessFunc should be use iBuffer&bDMAOn
    //                     iBufferReady==Written,bDMAOn==False--> ok to process
/*************************************************************/





Uint16 nDataIOcount;
Void dataIO()
{
    nDataIOcount -- ;

    iBufferReady = iBufferReady | BUFFER_0_WRITTEN ;
    TSK_sleep(2);
    return ;
}


void wait( unsigned int cycles )
{
    //int i;
    for ( i = 0 ; i < cycles ; i++ ){ }
}

void EnableAPLL( )
{
    /* Enusre DPLL is running */
    *( ioport volatile unsigned short* )0x1f00 = 4;

    wait( 25 );

    *( ioport volatile unsigned short* )0x1f00 = 0;

    // MULITPLY
    *( ioport volatile unsigned short* )0x1f00 = 0x3000;

    // COUNT
    *( ioport volatile unsigned short* )0x1f00 |= 0x4F8;

    wait( 25 );

    //*( ioport volatile unsigned short* )0x1f00 |= 0x800

    // MODE
    *( ioport volatile unsigned short* )0x1f00 |= 2;

    wait( 30000 );

    // APLL Select
    *( ioport volatile unsigned short* )0x1e80 = 1;

    // DELAY
    wait( 60000 );
}


Void init_board()
{
    LOG_printf(&trace,"init_board");  
    
    /*  set the ARDYOFF bit  */
    EMIF_reset () ;    
    emifCfg0.egcr = emifCfg0.egcr  | 0x0010;
    EMIF_config(&emifCfg0);

    /* USB related configuration */    
    myUsbConfig[ 4 ] = NULL; 
    EnableAPLL() ;
    USB_setAPIVectorAddress();    
    //USB_initPLL(12, 48, 0);                   //-------------------------------------mark
    USB_init(USB0, myUsbConfig, 0x0);           //        -------------------------------------mark
  
    /*  redundant for DMA trnasfer  */  
    sourceAddr = (int *)0x400000 ;   // not used
    
    /* To handshake with CPLD ,indicating the DSP is on */
    /* GPIO0-2: connected to LED, should be output to indicate status */
    /* GPIO0: flash on/off every second */
    /* GPIO1: "1" indicate INT2 is enabled (collecting status) */
    
    /* GPIO3: connected to GND through resistor, should be output "0" to minimize power consumption?? compare to input??*/
    /* GPIO4: connected to CSn pin of EEPROM, should be output "1" to deselect EEPROM */
    /* GPIO5: handshake with CPLD , temporary output "1" now */
    /* GPIO6: handshake with CPLD */
    /* GPIO7: USBPDEC of usb port , should be input ?? */
    GPIO_RSET( IODIR , 0x7F );     /* all output except GPIO7 */	        
    GPIO_RSET( IODATA , ( (GPIO_RGET( IODATA ) | 0x30) & 0xb7 ) );  /* GPIO6="0" */

	/* Enable IRQs */
	IRQ_enable( IRQ_EVT_INT2 ) ;   
    
    IRQ_clear(IRQ_EVT_USB);
    IRQ_enable(IRQ_EVT_USB);
    
    IRQ_enable(IRQ_EVT_DMAC0);
    IRQ_enable(IRQ_EVT_DMAC1);
    IRQ_enable(IRQ_EVT_DMAC2);
    
    IRQ_enable( IRQ_EVT_TINT1 ) ;  // to be edited
    
    bCollectingIsOn = TRUE ;
  
    /* Place DMA interrupt service addresses at associate vector */
//    IRQ_plug(usbId,&_USB_isr);

    /* Enable all maskable interrupts */
    IRQ_globalEnable();

    // if the USB module configured properly,
    // connect it to up stream port    

    USB_connectDev(USB0);                   //-------------------------------------mark    
    
    TIMER_start ( hTimer1 ) ;    // to be edited
    
    GPIO_RSET( IODATA ,  (GPIO_RGET( IODATA ) | 0x42) );  /* GPIO6="1" , GPIO1 ="1" */
    
    
    nDataIOcount = 1000; // 22157 for Cs16x-070501.conv

⌨️ 快捷键说明

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