📄 test.c
字号:
}
for (i = 0; i < 256; i++)
buffer[i] = 0;
/* Verify the pattern */
for (page = 0; page < EVM5502_SROM_SIZE >> 8 ; page++)
{
EVM5502_SROM_read(page << 8, (Uint32)buffer, 256);
pdata = (Uint16 *)buffer;
for (i = 0; i < 256; i++)
if ((*pdata++ & 0xff) != ((page + i) & 0xff))
return 1; // Fail
}
return 0;
}
void switchdisplay(Int16 keynum, Uint16 *keyimage)
{
EVM5502_LCD_rawPos(9 + (((keymatrix[keynum] & 0xf) << 1) << 3),
((keymatrix[keynum] & 0xf0) >> 4), keyimage, 7);
}
Int16 TEST_keypad()
{
Int16 i;
Uint16 value;
// /* Initialize keypad */
// EVM5502_LCD_init();
/* Clear screen */
EVM5502_LCD_fillScreen(0);
EVM5502_LCD_textPos(4, 0, "Evm5502 Test");
EVM5502_LCD_textPos(4, 1, "Keypad Test");
EVM5502_LCD_textPos(5, 3, "POT1=");
EVM5502_LCD_textPos(5, 4, "POT2=");
EVM5502_LCD_textPos(5, 5, " SW=");
/* Display keyboard */
for (i = 1; i <= 9; i++)
switchdisplay(i, open_key);
EVM5502_LCD_rawPos(115, 5, arrow, 5);
/* Sample keys */
while(1)
{
value = EVM5502_KEYPAD_readKey();
if (value > 0)
switchdisplay(value, closed_key);
else
{
for (i = 1; i <= 9; i++)
switchdisplay(i, open_key);
}
if (value == 9)
break;
/* Display POT #1 */
value = EVM5502_KEYPAD_readPot(1);
EVM5502_LCD_hexPos(10, 3, value);
/* Display POT #2 */
value = EVM5502_KEYPAD_readPot(2);
EVM5502_LCD_hexPos(10, 4, value);
/* Display Switch */
value = EVM5502_KEYPAD_readSW();
switch (value) {
case 1:
EVM5502_LCD_textPos(10, 5, "1");
break;
case 2:
EVM5502_LCD_textPos(10, 5, "2");
break;
case 3:
EVM5502_LCD_textPos(10, 5, "3");
break;
default:
EVM5502_LCD_textPos(10, 5, "0");
}
// EVM5502_LCD_hexPos(10, 5, value);
EVM5502_waitusec(10000);
}
// /* Clear screen */
// EVM5502_LCD_fillScreen(0);
return 0;
}
Int16 TEST_timer()
{
/* Wait for 100 timer interrupts */
TEST_sleep(100);
return 0;
}
Int16 TEST_null()
{
return 0;
}
void TEST_execute(Int16 (*funchandle)(), Int16 ledmask, char *str, Int16 insertdelay)
{
Int16 status,k;
/* Display test ID */
LED_binary(ledmask);
/* Display selfcheck status */
EVM5502_LCD_textPos(4, 1, "Evm5502 Test");
/* Display test Content */
EVM5502_LCD_textPos(4, 4, str);
/* Call test function */
status = funchandle();
/* Pause so LEDs can be read */
if (insertdelay)
for(k=0;k<insertdelay;k++)
// TEST_sleep(500);
Wait(500);
/* Check for test fail */
if (status)
LED_error(ledmask);
/* Clear the screen */
EVM5502_LCD_fillScreen(0);
}
/* ------------------------Helper Functions ----------------------------- */
/*
* initMcbsp() - Initialize the McBSP for codec data transfers using the
* configuration define at the top of this file.
*/
void initMcbsp()
{
/* Open the codec data McBSP */
hMcbsp1 = MCBSP_open(MCBSP_PORT1, MCBSP_OPEN_RESET);
/* Configure the codec to match the AIC23 data format */
MCBSP_config(hMcbsp1, &mcbspCfg1);
/* Clear any garbage from the codec data port */
if (MCBSP_rrdy(hMcbsp1))
MCBSP_read16(hMcbsp1);
/* Start the McBSP running */
MCBSP_start(hMcbsp1, MCBSP_XMIT_START | MCBSP_RCV_START |
MCBSP_SRGR_START | MCBSP_SRGR_FRAMESYNC, 220);
}
/*
* initIrq() - Initialize and enable the DMA receive interrupt using the CSL.
* The interrupt service routine for this interrupt is hwiDma.
*/
void initIrq(void)
{
// Get Event ID associated with DMA channel interrupt. Event IDs are a
// CSL abstraction that lets code describe a logical event that gets
// mapped to a real physical event at run time. This helps to improve
// code portability.
eventIdRcv = DMA_getEventId(hDmaRcv);
eventIdXmt = DMA_getEventId(hDmaXmt);
// Clear any pending receive channel interrupts (IFR)
IRQ_clear(eventIdRcv);
IRQ_clear(eventIdXmt);
// Enable receive DMA interrupt (IMR)
IRQ_enable(eventIdRcv);
// Make sure global interrupts are enabled
IRQ_globalEnable();
}
/*
* initDma() - Initialize the DMA controller.
*/
void initDma(void)
{
volatile Int16 i;
/* Set transmit and receive buffer addresses in config structures */
dmaCfgReceive.dmacdsal = (DMA_AdrPtr)(((Uint32)(&gBufferRcvPing) << 1) & 0xFFFF);
dmaCfgReceive.dmacdsau = (Uint16)((Uint32)(&gBufferRcvPing) >> 15);
dmaCfgTransmit.dmacssal = (DMA_AdrPtr)(((Uint32)(&gBufferXmtPing) << 1) & 0xFFFF);
dmaCfgTransmit.dmacssau = (Uint16)((Uint32)(&gBufferXmtPing) >> 15);
/* Open DMA channels */
hDmaXmt = DMA_open(DMA_CHA5, DMA_OPEN_RESET);
hDmaRcv = DMA_open(DMA_CHA4, DMA_OPEN_RESET);
/* Configure DMA channels */
DMA_config(hDmaXmt, &dmaCfgTransmit);
DMA_config(hDmaRcv, &dmaCfgReceive);
/* Clear the DMA status registers to receive new interrupts */
i = DMA_RGETH(hDmaRcv, DMACSR);
i = DMA_RGETH(hDmaXmt, DMACSR);
DMA_RSET(DMAGCR, 0x4);
/* Clear any garbage from the codec data port */
if (MCBSP_rrdy(hMcbsp1))
MCBSP_read16(hMcbsp1);
// Start the DMA
DMA_start(hDmaRcv);
DMA_start(hDmaXmt);
}
/*
* copyData() - Copy one buffer with length elements to another.
*/
void copyData(Int16 *inbuf, Int16 *outbuf, Int16 length)
{
Int16 i = 0;
for (i = 0; i < length; i++) {
outbuf[i] = inbuf[i];
}
}
/* ------------------------------- Threads ------------------------------ */
/*
* processBuffer() - Process audio data once it has been received.
*/
void processBuffer(void)
{
Uint32 addr;
Int16 pingPong;
// Wait until transmit DMA is finished too
// while(!IRQ_test(eventIdXmt));
// Pong-pong state passed through mailbox from dmaHwi()
pingPong = SWI_getmbox();
// Determine which ping-pong state we're in
if (pingPong == PING)
{
copyData(gBufferRcvPing, gBufferXmtPing, BUFFSIZE);
// Configure the receive channel for ping input data
addr = ((Uint32)gBufferRcvPing) << 1;
DMA_RSETH(hDmaRcv, DMACDSAL, addr & 0xffff);
DMA_RSETH(hDmaRcv, DMACDSAU, (addr >> 16) & 0xffff);
// Configure the transmit channel for ping output data
addr = ((Uint32)gBufferXmtPing) << 1;
DMA_RSETH(hDmaXmt, DMACSSAL, addr & 0xffff);
DMA_RSETH(hDmaXmt, DMACSSAU, (addr >> 16) & 0xffff);
}
else {
copyData(gBufferRcvPong, gBufferXmtPong, BUFFSIZE);
// Configure the receive channel for pong input data
addr = ((Uint32)gBufferRcvPong) << 1;
DMA_RSETH(hDmaRcv, DMACDSAL, addr & 0xffff);
DMA_RSETH(hDmaRcv, DMACDSAU, (addr >> 16) & 0xffff);
// Configure the transmit channel for pong output data
addr = ((Uint32)gBufferXmtPong) << 1;
DMA_RSETH(hDmaXmt, DMACSSAL, addr & 0xffff);
DMA_RSETH(hDmaXmt, DMACSSAU, (addr >> 16) & 0xffff);
}
// Start the DMA
DMA_start(hDmaRcv);
DMA_start(hDmaXmt);
if ( MCBSP_xrdy(hMcbsp1) )
MCBSP_write16(hMcbsp1, 0);
// MCBSP_read16(hMcbsp1);
}
/* ---------------------- Interrupt Service Routines -------------------- */
/*
* dmaHwi() - Interrupt service routine for the DMA transfer. It is triggered
* when a DMA complete receive frame has been transferred. The
* dmaHwi ISR is inserted into the interrupt vector table at
* compile time through a setting in the DSP/BIOS configuration
* under Scheduling --> HWI --> HWI_INT9. dmaHwi uses the DSP/BIOS
* Dispatcher to save register state and make sure the ISR
* co-exists with other DSP/BIOS functions.
*/
void dmaHwi(void)
{
// Ping-pong state. Initialized to PING initially but declared static so
// contents are preserved as dmaHwi() is called repeatedly like a global.
static Int16 pingOrPong = PING;
// Determine if current state is PING or PONG
if (pingOrPong == PING) {
// Post SWI thread to process PING data
SWI_or(&processBufferSwi, PING);
// Set new state to PONG
pingOrPong = PONG;
}
else {
// Post SWI thread to process PONG data
SWI_or(&processBufferSwi, PONG);
// Set new state to PING
pingOrPong = PING;
}
// Read the DMA status register to clear it so new interrupts will be seen
DMA_RGETH(hDmaRcv, DMACSR);
count++;
}
main()
{
/* Call BSL init */
EVM5502_init();
/* Enable I2C signals on the expansion connector */
EVM5502_rset(EVM5502_BOARD, 0x4);
/* Set initial LED state */
EVM5502_LED_init();
// EVM5502_DIP_init();
/* Set initial LCD state */
EVM5502_LCD_init();
/* Run the tests sequentially */
// TEST_execute(TEST_intMem, 1, "Internal Memory", 5); /* Internal memory */
// TEST_execute(TEST_sdram, 2, "SDRAM Test " , 0); /* SDRAM */
TEST_execute(TEST_flashID, 3, "Flash ID Test" , 5); /* Flash ID */
TEST_execute(TEST_flash, 4, "Flash Content" , 0); /* Flash contents */
// TEST_execute(TEST_sbsram, 5, "SBSRAM Test" , 1); /* SBSRAM */
// TEST_execute(TEST_mcbsp0, 6, "Mcbsp0 Loopback" , 5);/* McBSP0 loopback */
// TEST_execute(TEST_dma, 7, "DMA Test" , 5); /* DMA test */
// TEST_execute(TEST_eeprom, 8, "I2C EEPROM" , 0); /* I2C EEPROM test */
//// TEST_execute(TEST_timer, 9, "Timer1 Test" , 5); /* Timer test */
// TEST_execute(TEST_srom, 9, "SPI FLASH ROM " , 0); /* SROM test */
//// TEST_execute(TEST_codec, 10, "Codec 1KHz Sine" , 0);/* Codec test */
// TEST_execute(TEST_keypad, 10, "Keypad Test" , 0); /* Keypad test */
// TEST_execute(TEST_uart, 11, "UART LoopBack" , 5); /* UART test */
/* All tests complete, board passes */
LED_blink(0xf, 3);
/* Leave all LEDs on */
LED_binary(0xf);
// LED_binary(0);
/* Display selfcheck status */
EVM5502_LCD_textPos(4, 1, "Evm5502 Test");
EVM5502_LCD_textPos(3, 4, "FLASH Test OK");
/* Disable interrupts */
IRQ_globalDisable();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -