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

📄 post.c

📁 TMS320C6711的上电自检 This source code is ultimately used to create a JEDEC programming file used * to p
💻 C
📖 第 1 页 / 共 2 页
字号:
  *(unsigned volatile int *)McBSP0_PCR = 0;

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

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

  *(unsigned volatile int *)McBSP0_DXR = 0;

  /* Setup SP control reg */
  *(unsigned volatile int *)McBSP0_SPCR = 0x12001;
}
 
/*******************************************************************************
* FUNCTION : mcbsp0_write
*
* ARGUMENTS :
*   INT out_data          <-- Value to write to McBSP0
*
* DESCRIPTION :
*   Checks to see if output register is empty. If empty write new data to it.
*
* OUTPUTS :
*   VOID
*
*******************************************************************************/
void mcbsp0_write(int out_data)
{
  int output_reg;
  output_reg = *(unsigned volatile int *)McBSP0_SPCR & 0x20000;
  while ( output_reg == 0)
  {
    output_reg = *(unsigned volatile int *)McBSP0_SPCR & 0x20000;
  }
  *(unsigned volatile int *)McBSP0_DXR = out_data;
}

/*******************************************************************************
* FUNCTION : mcbsp0_read
*
* ARGUMENTS :
*   VOID
*
* DESCRIPTION :
*   Checks to see if input register is full. If full read data from it.
*   
*
* OUTPUTS :
*   INT                   <-- Data read from input register
*
*******************************************************************************/
int mcbsp0_read()
{
  int input_reg;
  input_reg = *(unsigned volatile int *)McBSP0_SPCR & 0x2;
  while ( input_reg== 0 )
  {
    input_reg = *(unsigned volatile int *)McBSP0_SPCR & 0x2;
  }
  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(unsigned  char count, int ms_period,unsigned volatile char *ledadr)
{
  unsigned  char i;
  
  for (i=0;i<=count;i++)
  {
    ledplayer(ledadr,i);      
    delay_msec(ms_period/2);
    
  }
}

/*******************************************************************************
* 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;   /*每9537*4的CPU脉冲,时间计数计就+1 */
  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 : ledplayer(volatile unsigned char *ledadr,unsigned char number)
*
* ARGUMENTS :
*   VOID
*
* DESCRIPTION :
*   把指示灯的值赋给灯的地址
*  
*
* OUTPUTS :
*   NONE
*
******************************************************************/
void ledplayer(volatile unsigned char *ledadr,unsigned char number)
{
 * ledadr = number;
}



/* END OF FILE */

⌨️ 快捷键说明

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