📄 post.c
字号:
/*
* Copyright 2003 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*/
/*
* ======== post.c ========
*
* The Power On Self Test (POST) is a small program that uses the 6713 DSK
* Board Support Library to perform basic tests on the DSP and board
* peripherals. It is typically programmed into the Flash memory so it
* runs on boot. The following tests are perfored:
*
* Index Description
* 1 Internal memory
* 2 External memory typical (SDRAM)
* 3 External memory special (Flash)
* 4 McBSP0 in loopback mode
* 5 McBSP1 in loopback mode
* 6 Internal DMA transfer
* 7 Codec test
* 8 LED and timer test
*
* The POST displays the index of the test being run on the LEDs. If an
* error is detected while running the test, the test index will blink
* continuously. If all tests complete successfully, all 4 LEDs will blink
* three times and stop will all LEDs on.
*
* This code will only work when built with the large memory model because
* of the need to access the external SDRAM.
*
* Please see the 6713 DSK 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 post.cdb. At
* compile time, Code Composer will auto-generate DSP/BIOS related files
* based on these settings. A header file called postcfg.h contains the
* results of the autogeneration and must be included for proper operation.
* The name of the file is taken from post.cdb and adding cfg.h.
*/
#include "postcfg.h"
/*
* The POST 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_timer.h>
#include <csl_edma.h>
/*
* The 6713 DSK Board Support Library is divided into several modules, each
* of which has its own include file. The file dsk6713.h must be included
* in every program that uses the BSL. This example also includes
* dsk6713_aic23.h, dsk6713_led.h and dsk6713_flash.h because it uses
* their respective BSL modules.
*/
#include "dsk6713.h"
#include "dsk6713_led.h"
#include "dsk6713_aic23.h"
#include "dsk6713_flash.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 */
DSK6713_AIC23_Config config = { \
0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */ \
0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */\
0x00d8, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */ \
0x00d8, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */ \
0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */ \
0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */ \
0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */ \
0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */ \
0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */ \
0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */ \
};
/* Define source and destination arrays for DMA and loopback tests */
Uint16 src[N], dst[N];
/* Variables used by the TEST_sleep() funciton */
Uint16 eventId1;
volatile Uint16 sleepCount = 0;
/*
* Interrupt Service Routines
*/
void sleepIsr()
{
sleepCount++;
}
/*
* Accessory functions
*/
void TEST_sleep(Int16 sleeptime)
{
TIMER_Handle hTimer1;
TIMER_Config timerCfg1 = {
TIMER_FMKS(CTL, INVINP, NO) |
TIMER_FMKS(CTL, CLKSRC, CPUOVR4) |
TIMER_FMKS(CTL, CP, PULSE) |
TIMER_FMKS(CTL, HLD, YES) |
TIMER_FMKS(CTL, GO, NO) |
TIMER_FMKS(CTL, PWID, ONE) |
TIMER_FMKS(CTL, DATOUT, 0) |
TIMER_FMKS(CTL, INVOUT, NO) |
TIMER_FMKS(CTL, FUNC, TOUT),
TIMER_FMKS(PRD, PRD, OF(75000)),
TIMER_FMKS(CNT, CNT, OF(0))
};
/* Open the timer */
hTimer1 = TIMER_open(TIMER_DEV1, TIMER_OPEN_RESET);
/* Configure the timer in one-shot mode */
TIMER_config(hTimer1, &timerCfg1);
/* Get Event Id associated with Timer 1, for use with */
/* CSL interrupt enable functions. */
eventId1 = TIMER_getEventId(hTimer1);
/* Map the logical event to a physical interrupt */
IRQ_map(eventId1, 15);
/* Clear any pending Timer interrupts */
IRQ_clear(eventId1);
/* Enable timer interrupt */
IRQ_enable(eventId1);
/* Make sure global interrupts are enabled */
IRQ_globalEnable();
/* Clear sleep count */
sleepCount = 0;
/* Start timer 1 */
TIMER_start(hTimer1);
while(sleepCount < sleeptime);
/* Disable timer interrupt */
IRQ_disable(eventId1);
TIMER_close(hTimer1);
}
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)
DSK6713_LED_on(i);
else
DSK6713_LED_off(i);
bit = bit << 1;
}
}
void LED_blink(Int16 ledmask, Int16 count)
{
while (count > 0)
{
LED_binary(ledmask);
TEST_sleep(100);
LED_binary(0);
TEST_sleep(150);
count--;
}
}
void LED_error(Int16 ledmask)
{
while(1)
LED_blink(ledmask, 1);
}
/*
* 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+=4)
{
*((Uint32 *)i) = val;
}
/* Verify the data */
for (i = start; i < end; i+=4)
{
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+=4)
{
*((Uint32 *)i) = i;
}
/* Verify the data */
for (i = start; i < end; i+=4)
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+=4)
{
*((Uint32 *)i) = ~i;
}
/* Verify the data */
for (i = start; i < end; i+=4)
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 */
status |= MEM_fill(start, len, 0x00000000);
status |= MEM_fill(start, len, 0x55555555);
status |= MEM_fill(start, len, 0xAAAAAAAA);
status |= MEM_fill(start, len, 0xFFFFFFFF);
} else
{
/* Run the address tests */
status |= MEM_addr(start, len);
status |= MEM_addrInv(start, len);
}
return status;
}
/*
* POST tests
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -