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

📄 post.c

📁 使用于DSK6711中的很多好用的例子,源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
  }
  input_reg = *(unsigned volatile int *)McBSP0_DRR;
  return input_reg;
}

/*******************************************************************************
* FUNCTION : mcbsp0_test
*
* ARGUMENTS :
*   VOID
*   
* DESCRIPTION :
*   Tests multi-channel serial port 0 in internal loopback mode after setting
*   up its own clock.
*   
* OUTPUTS :
*   INT 0                 <-- If successful
*   
*******************************************************************************/
int mcbsp0_test()
{
  /* Setup McBSP0 */
  volatile unsigned int temp = 0, temp1;

  /* Reset serial port */
  *(unsigned volatile int *)McBSP0_SPCR = 0;

  /* Set baud rate to 1MHz */
  *(unsigned volatile int *)McBSP0_SRGR = 0x2014004A;

  /* Set pin control reg */
  *(unsigned volatile int *)McBSP0_PCR = 0xA00;

  /* Set rx control reg one 16 bit data/frame */
  *(unsigned volatile int *)McBSP0_RCR = 0x10040;

  /* Set tx control reg one 16 bit data/frame */
  *(unsigned volatile int *)McBSP0_XCR = 0x10040;

  /* Setup SP control reg */
  *(unsigned volatile int *)McBSP0_SPCR = 0xC1A001;

  *(unsigned volatile int *)McBSP0_DXR = 0xAAAA;

  temp1 = *(unsigned volatile int *)McBSP0_DRR;
  temp1 = mcbsp0_read(); 
  mcbsp0_write(0x5555);
  temp = mcbsp0_read();
  temp &= 0xffff;
  if (temp != 0x5555)
  {
    temp = 1;
    return temp;
  }

  mcbsp0_write(0xaaaa);
  temp = mcbsp0_read();
  temp &= 0xffff;
  if (temp != 0xaaaa)
  {
    temp = 1;
    return temp;
  }
  return 0;
}

/*******************************************************************************
* FUNCTION : led_blink
*
* ARGUMENTS :
*   INT count             <-- Number of times to blink the LEDs
*   INT ms_period         <-- Time the LED(s) is(are) active (illuminated)
*   
* DESCRIPTION :
*   Toggles the user LEDs for a given count and period (in milliseconds).
*   
* OUTPUTS :
*   VOID
*   
*******************************************************************************/
void led_blink(int count, int ms_period)
{
  int i;
  
  for (i=0;i<count;i++)
  {
    *(unsigned volatile int *)IO_PORT = 0x0;        /* Turn on all user LEDs */
    delay_msec(ms_period/2);
    *(unsigned volatile int *)IO_PORT = 0x07000000; /* Turn off all user LEDs*/
    delay_msec(ms_period/2);
  }
  *(unsigned volatile int *)IO_PORT = 0x7000000;   /* Turn off all user LEDs */
}

/*******************************************************************************
* FUNCTION : delay_msec
*
* ARGUMENTS :
*   SHORT msec            <-- Period to delay in milliseconds
*
* DESCRIPTION :
*
*
* OUTPUTS :
*   VOID
*
*******************************************************************************/
void delay_msec(short msec)
{
  /* Assume 150 MHz CPU, timer peirod = 4/150 MHz */
  int timer_limit = (msec*9375)<<2;
  int time_start;

  timer0_start();
  time_start = timer0_read();
  while ((timer0_read()-time_start) < timer_limit);
}
 
/*******************************************************************************
* FUNCTION : timer0_read
*
* ARGUMENTS :
*   VOID
*
* DESCRIPTION :
*   Read and return the count in timer 0.
*
* OUTPUTS :
*   INT                   <-- Returns the count in timer 0
*
*******************************************************************************/
int timer0_read()
{
  int i;

  i = *(unsigned volatile int *)TIMER0_COUNT;
  return i;
}

/*******************************************************************************
* FUNCTION : timer0_start
*
* ARGUMENTS :
*   VOID
* 
* DESCRIPTION :
*   Start timer 0 after initializing it for 32-bit count and no interrupt.
* 
* OUTPUTS :
*   VOID
*
*******************************************************************************/
void timer0_start()
{
  /* Hold the timer */
  *(unsigned volatile int *)TIMER0_CTRL &= 0xff3f;

  /* Use CPU CLK/4 */
  *(unsigned volatile int *)TIMER0_CTRL |= 0x200;

  /* Set for 32 bit counter */
  *(unsigned volatile int *)TIMER0_PRD  |= 0xffffffff;

  /* Start the timer */
  *(unsigned volatile int *)TIMER0_CTRL |= 0xC0;
}

/*******************************************************************************
* FUNCTION : timer0_init
*
* ARGUMENTS :
*   VOID
*
* DESCRIPTION :
*   Start timer 0 after initializing it for a short period (~13.7 micro seconds)
*   with interrupt.
*
* OUTPUTS :
*   VOID
*
*******************************************************************************/
void timer0_init()
{
  /* Hold the timer */
  *(unsigned volatile int *)TIMER0_CTRL &= 0xff3f;

  /* Use CPU CLK/4 */
  *(unsigned volatile int *)TIMER0_CTRL |= 0x200;

  /* Set for a short period */
  *(unsigned volatile int *)TIMER0_PRD   = 0x200;

  /* Start the timer, enable timer0 int */
  *(unsigned volatile int *)TIMER0_CTRL |= 0x3C0;
}
/*******************************************************************************
* FUNCTION : play_codec
*
* ARGUMENTS :
*   INT number         <-- Number of samples
*   INT tone_playbk    <-- Audio in playback if 0, Tone if 1
*
* DESCRIPTION :
*   This function initializes the DSP's McBSP and the AIC's codec before
*   playing the codec input through its output or generating a tone.
*
* OUTPUTS :
*   VOID
*
*******************************************************************************/
void play_codec(int number, int tone_playbk)
{
  int i,j;
  int temp;

// set up control register 3 for S/W reset
  mcbsp0_read();        /* do a dummy read to synchronize read and write */
  mcbsp0_write(0);      /* write 0 to serial port as normal data  */
  mcbsp0_read();        /* do a read to keep write and read synchronized */
  mcbsp0_write(0);      /* write 0 to serial port as normal data  */
  mcbsp0_read();        /* do a read to keep write and read synchronized */
  mcbsp0_write(0);      /* write 0 to serial port as normal data  */
  mcbsp0_read();        /* do a read to keep write and read synchronized */
  mcbsp0_write(1);      /* write 1 to indicating next data is control  */
  mcbsp0_read();        /* do a read to keep write and read synchronized */
  mcbsp0_write(0x0386); /* do a s/w reset */
  mcbsp0_read();        /* do a read to keep write and read synchronized */
  mcbsp0_write(0);      /* write 0 to serial port as normal data  */
  mcbsp0_read();        /* do a read to keep write and read synchronized */
         
// set up control register 3 for mic input
  mcbsp0_write(0);     /* write 0 to serial port as normal data  */
  mcbsp0_read();       /* do a read to keep write and read synchronized */
  mcbsp0_write(0);     /* write 0 to serial port as normal data  */
  mcbsp0_read();       /* do a read to keep write and read synchronized */
  mcbsp0_write(1);     /* write 1 to indicating next data is control  */
  mcbsp0_read();       /* do a read to keep write and read synchronized */
  mcbsp0_write(0x0306); /* set up reg 3 */
  mcbsp0_read();       /* do a read to keep write and read synchronized */
  mcbsp0_write(0);     /* write 0 to serial port as normal data  */
  mcbsp0_read();       /* do a read to keep write and read synchronized */
         
  mcbsp0_write(0);     /* write 0 to serial port as normal data  */
  mcbsp0_read();       /* do a read to keep write and read synchronized */
  mcbsp0_write(1);     /* write 1 to indicating next data is control  */
  mcbsp0_read();       /* do a read to keep write and read synchronized */
  mcbsp0_write(0x2330); /* request reg 3 */
  temp = mcbsp0_read(); /* read reg 3    */
  mcbsp0_write(0x0);  /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(0x0);  /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */

//set up control register 4
  mcbsp0_write(0);    /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(0);    /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(1);    /* write 1 to indicating next data is control  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(0x0400);  /* set up reg 4 */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(0);    /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */

  mcbsp0_write(0);    /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(1);    /* write 1 to indicating next data is control  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(0x2430);  /* request reg 4 */
  temp = mcbsp0_read();  /* read reg 4    */
  mcbsp0_write(0x0);  /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(0x0);  /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */

// set up control register 5
  mcbsp0_write(0);    /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(0);    /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(1);    /* write 1 to indicating next data is control  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(0x0502); /* set up reg 5 */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(0);    /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */

  mcbsp0_write(0);    /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(1);    /* write 1 to indicating next data is control  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(0x2530);  /* request reg 5 */
  temp = mcbsp0_read();  /* read reg 5 */
  mcbsp0_write(0x0);  /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */
  mcbsp0_write(0x0);  /* write 0 to serial port as normal data  */
  mcbsp0_read();      /* do a read to keep write and read synchronized */

  if(tone_playbk)
  {
    for (i=0; i< 8; i++)
    {
      sin_table[i] = sin_table[i] & 0xfffe;
    }
 
    for (i=0;i<number;i++)
    {
      for (j=0;j<8;j++)
      {
        mcbsp0_write((int)sin_table[j]);
      }
    }
  }
  else
  {
    for (i=0;i<number;i++)
    {
      temp = mcbsp0_read();
      temp = temp & 0xfffe;
      mcbsp0_write(temp);
    }
  }
}
/* END OF FILE */

⌨️ 快捷键说明

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