📄 test.c
字号:
/*
* Copyright 2002 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*/
/*
* ======== test.c ========
*
* This is a test program that uses 5502 EVM Board Support Library to
* perform a confidence test on a 5502 EVM. While it is running, it
* will display the current test index in binary on the LEDs. If it
* fails a test, the test index will blink indefinitely to alert you to
* the failure. If all tests pass, all of the LEDs will blink 3 times
* then stay on.
*
* The following tests are performed:
*
* Index Description
* 1 Internal memory
* 2 SDRAM
* 3 Flash ID
* 4 Flash contents (erases and overwrites all but first page)
* 5 SBSRAM
* 6 McBSP0 internal loopback
* 7 DMA internal transfer
* 8 I2C EEPROM
* 9 Timer
* 10 SPI serial Flash
* 11 Codec (requires headphone to hear output)
* 12 Keypad (keypad module must be plugged in)
* 13 UART (requires loopback connector)
*
* Please see the 5502 EVM help file under Software/Examples for more
* detailed information.
*/
/*
* DSP/BIOS is configured using the DSP/BIOS configuration tool. Settings
* for this example are stored in a configuration file called test.cdb. At
* compile time, Code Composer will auto-generate DSP/BIOS related files
* based on these settings. A header file called testcfg.h contains the
* results of the autogeneration and must be included for proper operation.
* The name of the file is taken from test.cdb and adding cfg.h.
*/
#include "testcfg.h"
#include "test.h"
#include "aic23.h"
/*
* The test uses the Chip Support Library for basic definitions as well as
* McBSP manipulation. Programs that use the CSL must include the
* appropriate header files.
*/
#include <csl.h>
#include <csl_mcbsp.h>
#include <csl_dma.h>
#include <csl_irq.h>
/*
* The 5502 EVM Board Support Library is divided into several modules, each
* of which has its own include file. The file evm5502.h must be included
* in every program that uses the BSL. This example also includes
* BSL header files for each module it uses.
*/
#include "evm5502.h"
#include "evm5502_led.h"
#include "evm5502_dip.h"
#include "evm5502_aic23.h"
#include "evm5502_flash.h"
#include "evm5502_eeprom.h"
#include "evm5502_uart.h"
#include "evm5502_srom.h"
#include "evm5502_keypad.h"
#include "evm5502_lcd.h"
/* Length of sine wave table */
#define SINE_TABLE_SIZE 48
/* Number of elements for DMA and McBSP loopback tests */
#define N 16
/* Pre-generated sine wave data, 16-bit signed samples */
int sinetable[SINE_TABLE_SIZE] = {
0x0000, 0x10b4, 0x2120, 0x30fb, 0x3fff, 0x4dea, 0x5a81, 0x658b,
0x6ed8, 0x763f, 0x7ba1, 0x7ee5, 0x7ffd, 0x7ee5, 0x7ba1, 0x76ef,
0x6ed8, 0x658b, 0x5a81, 0x4dea, 0x3fff, 0x30fb, 0x2120, 0x10b4,
0x0000, 0xef4c, 0xdee0, 0xcf06, 0xc002, 0xb216, 0xa57f, 0x9a75,
0x9128, 0x89c1, 0x845f, 0x811b, 0x8002, 0x811b, 0x845f, 0x89c1,
0x9128, 0x9a76, 0xa57f, 0xb216, 0xc002, 0xcf06, 0xdee0, 0xef4c
};
/* Codec configuration settings */
EVM5502_AIC23_Config config = { \
0x001c, /* 0 EVM5502_AIC23_LEFTINVOL Left line input channel volume 7.5db*/ \
0x001c, /* 1 EVM5502_AIC23_RIGHTINVOL Right line input channel volume 7.5 */\
0x01f9, /* 2 EVM5502_AIC23_LEFTHPVOL Left channel headphone volume 0db*/ \
0x01f9, /* 3 EVM5502_AIC23_RIGHTHPVOL Right channel headphone volume 0db*/ \
0x0010, /* 4 EVM5502_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 EVM5502_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 EVM5502_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 EVM5502_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 EVM5502_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 EVM5502_AIC23_DIGACT Digital interface activation */ \
};
/* Define source and destination arrays for DMA and loopback tests */
Uint16 src[N], dst[N], buffer[256];
/* Used for switch test */
Uint16 open_key[] = {0x1c22, 0x4141, 0x4122, 0x1c00};
Uint16 closed_key[] = {0x1c2a, 0x5d5d, 0x5d2a, 0x1c00};
Uint16 arrow[] = {0x081c, 0x3e08, 0x0800};
unsigned short keymatrix[10] = {
0x00, 0x71, 0x72, 0x73, 0x74, 0x75, 0x66, 0x60,
0x50, 0x56};
/* Variables used by the TEST_sleep() funciton */
Uint16 eventId1;
volatile Uint16 sleepCount = 0;
//extern
/*---- Timer ---------------------------------------------------------------*/
typedef struct c55xx_timer
{
Uint16 gptpid1; /* Peripheral ID register 1 */
Uint16 gptpid2; /* Peripheral ID register 2 */
Uint16 gptemu; /* Emulation management register */
Uint16 gptclk; /* Timer clock speed register */
Uint16 gptgpint; /* GPIO interrupt control register */
Uint16 gptgpen; /* GPIO enable register */
Uint16 gptgpdat; /* GPIO data register */
Uint16 gptgpdir; /* GPIO direction register */
Uint16 gptcnt1; /* Counter 1 register */
Uint16 gptcnt2; /* Counter 2 register */
Uint16 gptcnt3; /* Counter 3 register */
Uint16 gptcnt4; /* Counter 4 register */
Uint16 gptprd1; /* Period register 1 */
Uint16 gptprd2; /* Period register 2 */
Uint16 gptprd3; /* Period register 3 */
Uint16 gptprd4; /* Period register 4 */
Uint16 gptctl1; /* Timer control register 1 */
Uint16 gptctl2; /* Timer control register 2 */
Uint16 gptgctl; /* Global control register */
} C55XX_TIMER;
typedef ioport volatile C55XX_TIMER * PC55XX_TIMER;
#define C55XX_TIM1_ADDR 0x2400
/*
* Interrupt Service Routines
*/
void sleepIsr()
{
sleepCount++;
}
/*
* Accessory functions
*/
void TEST_sleep(Int16 sleeptime)
{
PC55XX_TIMER pTIMER1 = (PC55XX_TIMER)C55XX_TIM1_ADDR;
sleepCount = 0;
/* Configure timer for millisecond delay */
pTIMER1 -> gptgctl = 0; // Put timer in reset
pTIMER1 -> gptclk = 0x0001; // Internal clock source is CPU_CLK/1
pTIMER1 -> gptprd1 = 0x93E0; // Divide by 300000 (from 300MHz input clock)
pTIMER1 -> gptprd2 = 0x0004;
pTIMER1 -> gptctl1 = 0x0080; // Internal clock, one-shot, continuous mode
pTIMER1 -> gptgctl = 0x0003; // 64-bit single timer, enabled
/* Get Event Id associated with Timer 1, for use with */
/* CSL interrupt enable functions. */
eventId1 = IRQ_EVT_TINT1;
/* Map the logical event to a physical interrupt */
IRQ_map(eventId1);
/* Clear any pending Timer interrupts */
IRQ_clear(eventId1);
/* Enable timer interrupt */
IRQ_enable(eventId1);
/* Make sure global interrupts are enabled */
IRQ_globalEnable();
while(sleepCount < sleeptime);
/* Put timer back in reset */
pTIMER1 -> gptgctl = 0;
/* Disable timer interrupt */
IRQ_disable(eventId1);
}
void Wait(Int16 millisecondnum)
{
Int16 i, j;
for (i = 0; i < millisecondnum; i++)
{
for (j = 0; j < 500; j++)
EVM5502_waitusec(1);
}
}
void LED_binary(Int16 ledmask)
{
Int16 i, bit;
/* Walk through the bits in num setting corresponding LEDs */
bit = 1;
for (i = 0; i < 4; i++)
{
if (ledmask & bit)
EVM5502_LED_on(i);
else
EVM5502_LED_off(i);
bit = bit << 1;
}
}
void LED_blink(Int16 ledmask, Int16 count)
{
while (count > 0)
{
LED_binary(ledmask);
// TEST_sleep(100);
Wait(100);
LED_binary(0);
// TEST_sleep(150);
Wait(150);
count--;
}
}
void LED_error(Int16 ledmask)
{
while(1)
LED_blink(ledmask, 1);
}
void blinkLED()
{
/* Toggle LED #2 and #3 */
EVM5502_LED_toggle(2);
EVM5502_LED_toggle(3);
}
void blinkLED0()
{
/* Check DIP switch #0 and light LED #0 accordingly, 0 = switch pressed */
if (EVM5502_DIP_get(0) == 0)
/* Switch pressed, togglw LED #0 */
EVM5502_LED_toggle(0);
else
/* Switch not pressed, turn LED #0 off */
EVM5502_LED_off(0);
}
/*
* Memory functions
*/
Int16 MEM_fill(Uint32 start, Uint32 len, Uint32 val)
{
Uint32 i, end;
/* Calculate end of range */
end = start + len;
/* Fill a range with a value */
for (i = start; i < end; i+=2)
{
*((Uint32 *)i) = val;
}
/* Verify the data */
for (i = start; i < end; i+=2)
{
if (*((Uint32 *)i) != val)
return 1;
}
return 0;
}
Int16 MEM_addr(Uint32 start, Uint32 len)
{
Uint32 i, end;
/* Calculate end of range */
end = start + len;
/* Fill the range with its address */
for (i = start; i < end; i+=2)
{
*((Uint32 *)i) = i;
}
/* Verify the data */
for (i = start; i < end; i+=2)
if (*((Uint32 *)i) != i)
return 1;
return 0;
}
Int16 MEM_addrInv(Uint32 start, Uint32 len)
{
Uint32 i, end;
/* Calculate end of range */
end = start + len;
/* Fill the range with its address */
for (i = start; i < end; i+=2)
{
*((Uint32 *)i) = ~i;
}
/* Verify the data */
for (i = start; i < end; i+=2)
if (*((Uint32 *)i) != (~i))
return 1;
return 0;
}
Int16 MEM_walking(Uint32 add)
{
Int16 i;
Uint32 mask, *pdata;
pdata = (Uint32 *)add;
/* Walking ones and zeros */
mask = 1;
for (i = 0; i < 32; i++)
{
/* Test one in bit position i */
*pdata = mask;
if (*pdata != mask)
return 1;
/* Test zero in bit position i */
*pdata = ~mask;
if (*pdata != (~mask))
return 1;
mask = mask << 1;
}
return 0;
}
Int16 MEM_test(Uint32 start, Uint32 len, Int16 patterntype)
{
Int16 status = 0;
if (!patterntype)
{
/* Run the fill tests */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -