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

📄 main_mcbsp1.c

📁 开发TI C6000 DSP需要的Chip Support Library
💻 C
📖 第 1 页 / 共 2 页
字号:

    MCBSP_XCR_XWDLEN1_32BIT, /* Transmit element length in phase 1(XWDLEN1)
                             MCBSP_XCR_XWDLEN1_8BIT  -   8 bits                     
                             MCBSP_XCR_XWDLEN1_12BIT -  12 bits                     
                             MCBSP_XCR_XWDLEN1_16BIT -  16 bits                     
                             MCBSP_XCR_XWDLEN1_20BIT -  20 bits                      
                             MCBSP_XCR_XWDLEN1_24BIT -  24 bits                     
                             MCBSP_XCR_XWDLEN1_32BIT -  32 bits                */  

   MCBSP_XCR_XWDREVRS_DISABLE /* Transmit 32-bit bit reversal feature
                              MCBSP_XCR_XWDREVRS_DISABLE - 32-bit reversal
                                   disabled.
                              MCBSP_XCR_XWDREVRS_ENABLE  - 32-bit reversal 
                                   enabled. 32-bit data is transmitted LSB first.
                                   XWDLEN should be set for 32-bit operation.
                                   XCOMPAND should be set to 01b; else operation
                                   is undefined.                               */  
   
  ),
  
  /*serial port sample rate generator register(SRGR) */
  MCBSP_SRGR_RMK( 
  
    MCBSP_SRGR_GSYNC_FREE,/* Sample rate generator clock synchronization(GSYNC).
                             MCBSP_SRGR_GSYNC_FREE - The sample rate generator 
                                  clock CLKG) is free running.
                             MCBSP_SRGR_GSYNC_SYNC - (CLKG) is running but is 
                                   resynchronized, and the frame sync signal
                                   (FSG)is generated only after the receive
                                   frame synchronization signal(FSR)is detected.
                                   Also,the frame period (FPER) is a don抰 care 
                                   because the period is dictated by the external
                                   frame sync pulse.                            */
                             
    MCBSP_SRGR_CLKSP_RISING,/* CLKS polarity clock edge select(CLKSP)
                              MCBSP_SRGR_CLKSP_RISING  - The rising edge of CLKS 
                                   generates CLKG and FSG.
                              MCBSP_SRGR_CLKSP_FALLING - The falling edge of CLKS
                                   generates CLKG and FSG.                      */
    MCBSP_SRGR_CLKSM_INTERNAL,/* MCBSP sample rate generator clock mode(CLKSM)
                              MCBSP_SRGR_CLKSM_CLKS   - The sample rate generator
                                   clock is derived from CLKS. 
                              MCBSP_SRGR_CLKSM_INTERNAL - (Default value) The
                                   sample rate generator clock is derived from
                                   the internal clock source.                   */

    MCBSP_SRGR_FSGM_DXR2XSR,/*Sample rate generator transmit frame synchronization
                               mode.(FSGM)
                              MCBSP_SRGR_FSGM_DXR2XSR  - The transmit frame sync
                                   signal (FSX) is generated on every DXR to XSR
                                   copy.                                                        
                              MCBSP_SRGR_FSGM_FSG      - The transmit frame sync
                                   signal is driven by the sample rate generator
                                   frame sync signal, FSG.                      */
   
    MCBSP_SRGR_FPER_OF(63),/* Frame period(FPER)
                              Valid values: 0 to 4095                           */    
    
    MCBSP_SRGR_FWID_OF(31),/* Frame width(FWID)
                              Valid values: 0 to 255                            */
                              
    MCBSP_SRGR_CLKGDV_OF(15)/* Sample rate generator clock divider(CLKGDV)
                              Valid values: 0 to 255                            */
    
  ),
  
  MCBSP_MCR_DEFAULT, /* Using default value of MCR register */
  MCBSP_RCER_DEFAULT,/* Using default value of RCER register */
  MCBSP_XCER_DEFAULT,/* Using default value of XCER register */
  
  /* serial port pin control register(PCR) */
  MCBSP_PCR_RMK(   
  
    MCBSP_PCR_XIOEN_SP, /* Transmitter in general-purpose I/O mode - only when 
                           XRST = 0 in SPCR - (XIOEN)
                           MCBSP_PCR_XIOEN_SP    -  CLKS pin is not a general 
                                purpose input. DX pin is not a general purpose
                                output.FSX and CLKX are not general-purpose I/Os.
                           MCBSP_PCR_XIOEN_GPIO  -  CLKS pin is a general-purpose
                                input. DX pin is a general-purpose output. 
                                FSX and CLKX are general-purpose I/Os. These
                                serial port pins do not perform serial port
                                operation.                                     */
    MCBSP_PCR_RIOEN_SP, /* Receiver in general-purpose I/O mode - only when 
                           RRST = 0 in SPCR -(RIOEN)
                           MCBSP_PCR_RIOEN_SP    - DR and CLKS pins are not 
                                general-purpose inputs. FSR and CLKR are not 
                                general-purpose I/Os and perform serial port 
                                operation.
                           MCBSP_PCR_RIOEN_GPIO  - DR and CLKS pins are 
                                general-purpose inputs. FSR and CLKR are 
                                general-purpose I/Os. These serial port pins do
                                not perform serial port operation.            */  
    MCBSP_PCR_FSXM_INTERNAL, /* Transmit frame synchronization mode(FSXM)
                             MCBSP_PCR_FSXM_EXTERNAL - Frame synchronization 
                                  signal is provided by an external source. FSX
                                  is an input pin. 
                             MCBSP_PCR_FSXM_INTERNAL - Frame synchronization 
                                  generation is determined by the sample rate 
                                  generator frame synchronization mode bit FSGM
                                  in the SRGR.                                */
    
    MCBSP_PCR_FSRM_EXTERNAL, /* Receive frame synchronization mode (FSRM)
                             MCBSP_PCR_FSRM_EXTERNAL  - Frame synchronization 
                                  signals are generated by an external device.
                                  FSR is an input pin.                              
                             MCBSP_PCR_FSRM_INTERNAL  - Frame synchronization 
                                  signals are generated internally by the sample
                                  rate generator. FSR is an output pin except 
                                  when GSYNC = 1 in SRGR.                     */     
    
    MCBSP_PCR_CLKXM_OUTPUT, /* Transmitter clock mode (CLKXM)
                             MCBSP_PCR_CLKXM_INPUT    -  Transmitter clock is 
                                  driven by an external clock with CLKX as an
                                  input pin.
                             MCBSP_PCR_CLKXM_OUTPUT   - CLKX is an output pin
                                   and is driven by the internal sample rate
                                   generator.
                             
                             During SPI mode :
                             MCBSP_PCR_CLKXM_INPUT    -  McBSP is a slave and 
                                  (CLKX) is driven by the SPI master in the 
                                   system. CLKR is internally driven by CLKX.
                             MCBSP_PCR_CLKXM_OUTPUT   - McBSP is a master and 
                                  generates the transmitter clock (CLKX) to
                                  drive its receiver clock (CLKR) and the shift
                                  clock of the SPI-compliant slaves in the 
                                  system.                                     */  
    MCBSP_PCR_CLKRM_INPUT, /* Receiver clock mode (CLKRM)
                              
                              Case 1: Digital loopback mode not set in SPCR
                              
                              MCBSP_PCR_CLKRM_INPUT - Receive clock (CLKR) is 
                                   an input driven by an external clock.
                                   
                              MCBSP_PCR_CLKRM_OUTPUT -  CLKR is an output pin 
                                   and is driven by the sample rate generator.
                              
                              Case 2: Digital loopback mode set  in SPCR
                              
                              MCBSP_PCR_CLKRM_INPUT - Receive clock  is driven
                                   by the transmit clock (CLKX), which is based
                                   on the CLKXM bit in PCR. CLKR is in high 
                                   impedance.
                              MCBSP_PCR_CLKRM_INPUT - CLKR is an output pin and
                                   is driven by the transmit clock. The transmit
                                   clock is derived from CLKXM bit in the PCR.*/
    
    
    MCBSP_PCR_CLKSSTAT_0, /*  CLKS pin status(CLKSSTAT)
                              MCBSP_PCR_CLKSSTAT_0  
                              MCBSP_PCR_CLKSSTAT_1                            */
    
    MCBSP_PCR_DXSTAT_0,   /*  DX pin status(DXSTAT)
                              MCBSP_PCR_DXSTAT_0
                              MCBSP_PCR_DXSTAT_1                              */
    
    MCBSP_PCR_FSXP_ACTIVEHIGH, /* Transmit frame synchronization polarity(FSXP)
                              MCBSP_PCR_FSXP_ACTIVEHIGH - Frame synchronization
                                       pulse FSX is active high
                              MCBSP_PCR_FSXP_ACTIVELOW  - Frame synchronization
                                   pulse FSX is active low                    */
    MCBSP_PCR_FSRP_ACTIVEHIGH, /* Receive frame synchronization polarity(FSRP)
                              MCBSP_PCR_FSRP_ACTIVEHIGH - Frame synchronization
                                   pulse FSR is active high
                              MCBSP_PCR_FSRP_ACTIVELOW  - Frame synchronization 
                                   pulse FSR is active low                    */
    MCBSP_PCR_CLKXP_RISING, /* Transmit clock polarity(CLKXP)
                              MCBSP_PCR_CLKXP_RISING - Transmit data driven on 
                                   rising edge of CLKX
                              MCBSP_PCR_CLKXP_FALLING - Transmit data driven on
                                    falling edge of CLKX                      */
    MCBSP_PCR_CLKRP_FALLING /* Receive clock polarity(CLKRP)
                              MCBSP_PCR_CLKRP_FALLING - Receive data sampled on
                                   falling edge of CLKR
                              MCBSP_PCR_CLKRP_RISING - Receive data sampled on
                                    rising edge of CLKR                       */
  )
}; 

/* ---------------------------------------------------------------------------*/  
void main() {

  MCBSP_Handle hMcbsp;  
  volatile Uint32 x,y;
  int success = 1;
  
  /* Initialize the chip support library, must when using CSL */
  CSL_init();

  /* Let's open up serial port 1 */
  hMcbsp = MCBSP_open(MCBSP_DEV1, MCBSP_OPEN_RESET);
  
  /* We'll set it up for digital loopback, 32bit mode. We have   */
  /* to setup the sample rate generator to allow self clocking.  */
  MCBSP_config(hMcbsp,&ConfigLoopback);

  /* Now that the port is setup, let's enable it in steps. */
  MCBSP_start(hMcbsp,MCBSP_RCV_START | MCBSP_XMIT_START |
   					 MCBSP_SRGR_START| MCBSP_SRGR_FRAMESYNC,
   			  MCBSP_SRGR_DEFAULT_DELAY);
     

  /* Now we'll loop for a while writing values out to the port */
  /* then reading them back in. This should take a few seconds.*/
  for (y=0; y<0x00080000; y++) {  
  
    /* wait until the transmitter is ready for a sample then write to it */
    while (!MCBSP_xrdy(hMcbsp));                       
    MCBSP_write(hMcbsp,y);
  
    /* now wait until the value is received then read it */
    while (!MCBSP_rrdy(hMcbsp));           
    x = MCBSP_read(hMcbsp);
    
    /* check to make sure they match */
    if (x != y) {
      success = 0;
      printf("\nTEST FAILED");
      break;
    } 
  }
  
  /* All done now, close the port. */
  MCBSP_close(hMcbsp); 
  if(success)  
    printf("\nTEST PASSED\n");
}

⌨️ 快捷键说明

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