📄 post.c
字号:
/*******************************************************************************
* $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
* chenhao
*
* 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"
#define LED 0x90090011 //指示灯的地址,实验证明其地址不是唯一
/*******************************************************************************
* Function prototypes
*******************************************************************************/
/*******************************************************************************
* 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 0000 Start state
* 1 0001 TEST 1: DSP internal SRAM test
* 2 0010 TEST 2: External SDRAM test
* 3 0011 TEST 3: DSP McBSP0 loopback test
* 4 0100 TEST 4: External codec read/write test
* 5 0101 TEST 5: External codec tone generation test
* 6 0110 TEST 6: External LED and DSP timer tests
* 7 0111 TEST 7: UNUSED/AVAILABLE FOR FUTURE TEST USE
* linkfunction: All tests completed successfully
* 0 1111
* 1 1110
* 2 1101
* 3 1100
* 4 1011
* 5 1010
* 6 1001
* 7 1000
* 8 0111
* INT 0
*******************************************************************************/
void main()
{
while(1)
{
/* DSP initialization*/
unsigned char data;
volatile unsigned char* ledflash = (volatile unsigned char *) LED ;
CSR=0x100; /* Disable all interrupts */
IER=1; /* Disable all interrupts except NMI */
ICR=0xffff; /* Clear all pending interrupts */
/*************************************************************************
* Standard 6211/6711 DSK includes 2 MT48LC4M16A2TG-7E_H 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 = 0x3360; /* EMIF global control */
*(unsigned volatile int *)EMIF_CE1 = CE1_8; /* EMIF CE1 control, 32bit */
*(unsigned volatile int *)EMIF_SDCTRL = 0x07126000; /* EMIF SDRAM control */
*(unsigned volatile int *)EMIF_CE0 = 0xFFFFFF33; /* 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(500); /*延时500ms*/
data=0x0f; /* 赋给灯地址单元的值 */
ledplayer(ledflash,data); /* Turn off all user LEDs*/
delay_msec(500); /*延时500ms*/
/*****************************************************************************
* TEST 1: DSP internal SRAM test
****************************************************************************/
data=0x0e; /* 赋给灯地址单元的值 */
ledplayer(ledflash,data); /* 赋给灯地址单元的值 ,使第一个灯亮 */
delay_msec(500);
/*L2内部存储器读写检查*/
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
****************************************************************************/
data=0x0d; /* 赋给灯地址单元的值 */
ledplayer(ledflash,data); /* 赋给灯地址单元的值,使第二个灯亮 */
delay_msec(500);
/*EMIF接口CE0外部存储器SDRAM读写检查*/
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
****************************************************************************/
data=0x0c;
ledplayer(ledflash,data);
delay_msec(500);
if (mcbsp0_test () != 0) /*串行口数据接收检查*/
{
exit(0);
}
/*****************************************************************************
* TEST 4: External codec read/write test
****************************************************************************/
data=0x0b;
ledplayer(ledflash,data);
delay_msec(500);
mcbsp0_init(); /*串行口初始化*/
//play_codec(5000, 0);
/*****************************************************************************
* TEST 5: External codec tone generation test
****************************************************************************/
data=0x0a;
ledplayer(ledflash,data);
delay_msec(500);
mcbsp0_init();
// play_codec(200, 1);/*generate 1KHz tone for 1 sec */
/*****************************************************************************
* TEST 6: External LED and DSP timer tests
*****************************************************************************/
data=0x09;
ledplayer(ledflash,data);
delay_msec(100);
/*****************************************************************************
* TEST 7: UNUSED/AVAILABLE FOR FUTURE TEST USE
*****************************************************************************/
/*****************************************************************************
* All tests completed successfully
*****************************************************************************/
led_blink(8, 1000,ledflash);
}
}
/*******************************************************************************
* 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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -