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

📄 post.c

📁 使用于DSK6711中的很多好用的例子,源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************
* $Source$
* $Revision$
* $Date$
*
* Copyright (C) 1990-2000 Texas Instruments Incorporated.
* All rights reserved.
*******************************************************************************/
/*******************************************************************************
* FILENAME
*   post.c
*
* DESCRIPTION
*   Power-On Self-Test code programmed into the TMS320C6211/6711 DSK Flash ROM.
*
* !!NOTE!!
*  Any future revision of this code should reorder the tests such that the
*  timer test is conducted first. In its present form the timer is used in all
*  tests (delay_msec()) prior to its own specific test. This could allow a timer
*  failure to be misdiagnosed as another test's failure(code displayed on LEDs).
* !!NOTE!!
*
* PUBLIC FUNCTIONS
*   None.
*
* PRIVATE FUNCTIONS
*   All.
*
* AUTHOR
*   Zhaohong Zhang
*
* NOTES
*   This source code is ultimately used to create a JEDEC programming file used
*   to program the Flash ROM on the 'C6211 DSK.
*
* UPDATE
*   Changed SDRAM parameters.
*   Reduced time for tests by 90%
*
*******************************************************************************/
#include <stdio.h>
#include <c6x.h>
#include "c6211dsk.h"
 
/*******************************************************************************
* Function prototypes
*******************************************************************************/
int  mem_test (int pattern, int start_adress, int size_in_word );
void mcbsp0_init();
void mcbsp0_write(int out_data);
int  mcbsp0_read();
int  mcbsp0_test();
void led_blink(int count, int ms_period);
void delay_msec(short msec);
int  timer0_read();
void timer0_start();
void timer0_init();
void play_codec(int number, int tone_playbk);

short sin_table[] = {0, 23170>>2, 32767>>2, 23170>>2,0, -23170>>2, -32767>>2, -23170>>2}; 

/*******************************************************************************
* FUNCTION : main
*
* ARGUMENTS :
*   VOID
*
* DESCRIPTION :
*   The code, at power-up, executes to perform a series of tests. The LEDs on
*   the DSK display progress codes during execution and a diagnostic or pass
*   code upon detection of an error or completion.
*
* OUTPUTS :
*   
*   LED Diagnostic Codes: (0=off, 1=on)
*   C     L L L
*   O     E E E
*   D     D D D
*   E     2 1 0
*   -     - - -
*   0     0 0 0 Start state
*   1     0 0 1 TEST 1: DSP internal SRAM test
*   2     0 1 0 TEST 2: External SDRAM test
*   3     0 1 1 TEST 3: DSP McBSP0 loopback test
*   4     1 0 0 TEST 4: External codec read/write test
*   5     1 0 1 TEST 5: External codec tone generation test
*   6     1 1 0 TEST 6: External LED and DSP timer tests
*   7     1 1 1 TEST 7: UNUSED/AVAILABLE FOR FUTURE TEST USE
*   BLINK ALL   All tests completed successfully
*
*   INT 0
*
*******************************************************************************/
int main()
{
  /* DSP initialization                                                       */
  CSR=0x100;                           /* Disable all interrupts              */
  IER=1;                               /* Disable all interrupts except NMI   */
  ICR=0xffff;                          /* Clear all pending interrupts        */

/*************************************************************************
* Standard 6211/6711 DSK includes 2 MT48LC1M16A1-7 devices = 4MB SDRAM   *
* For these devices use the following parameter:                         *
*   EMIF_SDCTRL=0x07126000                                               *
* If MT48LC1M16A1-10 devices are installed use the following parameter:  *
*   EMIF_SDCTRL=0x07227000                                               *
* /|\ 16Mb parts = 4MB SDRAM /|\   *-------------------------------------*
*----------------------------------*   \|/ 64Mb parts = 16MB SDRAM \|/   *
* If MT48LC4M16A2-10 devices are installed use the following parameter:  *
*   EMIF_SDCTRL=0x57227000                                               *
*************************************************************************/

  *(unsigned volatile int *)EMIF_GCR = 0x3300;    /* EMIF global control      */
  *(unsigned volatile int *)EMIF_CE1 = CE1_32;    /* EMIF CE1 control, 32bit  */
  *(unsigned volatile int *)EMIF_SDCTRL = 0x07126000; /* EMIF SDRAM control   */ 
  *(unsigned volatile int *)EMIF_CE0 = 0x30;      /* EMIF CE0 control         */
  *(unsigned volatile int *)EMIF_SDRP = 0x61a;    /* EMIF SDRM refresh period */
  *(unsigned volatile int *)EMIF_SDEXT= 0x54529;  /* EMIF SDRM extension      */

  /*****************************************************************************
   * Start state
   ****************************************************************************/
  delay_msec(50);
  *(unsigned volatile int *)IO_PORT = 0x07000000; /* Turn off all user LEDs*/
  delay_msec(50);

  /*****************************************************************************
   * TEST 1: DSP internal SRAM test
   ****************************************************************************/
  *(unsigned volatile int *)IO_PORT = 0x0e000000;   /* Display test # on LEDs */
  delay_msec(50);

  if(mem_test(ALL_5,INTERNAL_MEM_START,INTERNAL_MEM_SIZE) != 0)
  {
     exit(0);
  } 

  if(mem_test(ALL_A,INTERNAL_MEM_START,INTERNAL_MEM_SIZE) != 0)
  {
     exit(0);
  } 

  /*****************************************************************************
   * TEST 2: External SDRAM test
   ****************************************************************************/
  *(unsigned volatile int *)IO_PORT = 0x0D000000;   /* Display test # on LEDs */
  delay_msec(50);

  if(mem_test(ALL_5,EXTERNAL_MEM_START,EXTERNAL_MEM_SIZE) != 0)
  {
     exit(0);
  } 
 
  if(mem_test(ALL_A,EXTERNAL_MEM_START,EXTERNAL_MEM_SIZE) != 0)
  {
    exit(0);
  } 
 
  /*****************************************************************************
   * TEST 3: DSP McBSP0 loopback test
   ****************************************************************************/
  *(unsigned volatile int *)IO_PORT = 0x0C000000;   /* Display test # on LEDs */ 
  delay_msec(50);
 
   if (mcbsp0_test () != 0) 
   {
      exit(0);
   } 
 
  /*****************************************************************************
   * TEST 4: External codec read/write test
   ****************************************************************************/
  *(unsigned volatile int *)IO_PORT = 0x0B000000;   /* Display test # on LEDs */ 
  delay_msec(50);

  mcbsp0_init();
  play_codec(5000, 0);
  
  /*****************************************************************************
   * TEST 5: External codec tone generation test
   ****************************************************************************/
  *(unsigned volatile int *)IO_PORT = 0x0A000000;   /* Display test # on LEDs */ 
  delay_msec(50);

  mcbsp0_init();
  play_codec(200, 1); /* generate 1KHz tone for 1 sec */

  /*****************************************************************************
  * TEST 6: External LED and DSP timer tests
  *****************************************************************************/
  *(unsigned volatile int *)IO_PORT = 0x09000000;    /* Display test # on LEDs */  
  delay_msec(100);

  /*****************************************************************************
  * TEST 7: UNUSED/AVAILABLE FOR FUTURE TEST USE
  *****************************************************************************/

  /*****************************************************************************
  * All tests completed successfully
  *****************************************************************************/
  led_blink(5, 100);
 
  return(0);

}

/*******************************************************************************
* FUNCTION : mem_test
*
* ARGUMENTS :
*   INT pattern           <-- Pattern to be written or read from the memory
*   INT start_address     <-- Address from which to start testing memory
*   INT size_in_word      <-- Number of words to test in memory
*
* DESCRIPTION :
*   Write the pattern to memory beginning at the start_address through the
*   number of locations specified by size_in_word. Read the same locations
*   and generate an error if the value read back differs from the pattern
*   written.
*
* OUTPUTS :
*   INT error             <-- True if value read differs from pattern written
*
*******************************************************************************/
int mem_test (int pattern, int start_address, int size_in_word )
{
  int i;
  int error = 0;
  int *mem_ptr = (int *)start_address;

  /* Write pattern to the memory */
  for(i=0;i<size_in_word;i++)
  {
    *mem_ptr++ = pattern;
  }

  /* Read memory and compare contents to the pattern written */
  mem_ptr = (int *)start_address;
  for(i=0;i<size_in_word;i++)
  {
    if ( *mem_ptr++ != pattern) error++;
  }
  return error;
}

/*******************************************************************************
* FUNCTION : mcbsp0_init
*
* ARGUMENTS :
*   VOID
*
* DESCRIPTION :
*   Initializes multi-channel serial port 0 for 16 bits of data per frame in 
*   slave mode.
*
* OUTPUTS :
*   VOID
*
*******************************************************************************/
void mcbsp0_init()
{
  /* Setup McBSP0 */
  volatile unsigned int temp =0;

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

  /* Set pin control reg */
  *(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;

⌨️ 快捷键说明

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