📄 testuart.c
字号:
/*
* Copyright 2003 by Spectrum Digital Incorporated.
* All rights reserved. Property of Spectrum Digital Incorporated.
*/
/*
* ======== test.c ========
*
* This test program performs a confidence test on severl of the DM642 EVM
* board components. The following tests are performed:
*
* Index Description
* 1 LEDs
* 2 SPDIF/APLL/VCXO
* 3 Synchronous Bus
* 4 SDRAM
* 5 Flash ID
* 6 Flash (entire contents)
* 7 I2C EEPROM
* 8 UARTA Loopback
* 9 UARTB Loopback
* 10 PCI EEPROM
*/
/*
* 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 "testuartcfg.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 <stdio.h>
#include <std.h>
#include <sys.h>
#include <csl.h>
#include <csl_mcbsp.h>
#include <csl_timer.h>
#include <csl_edma.h>
#include <csl_vic.h>
#include <csl_mcasp.h>
#include <csl_gpio.h>
#include <csl_pci.h>
/*
* The DM642 EVM Board Support Library is divided into several modules, each
* of which has its own include file. The file evmdm642.h must be included
* in every program that uses the BSL. This example also includes
* evmdm642_aic23.h, evmdm642_led.h and evmdm642_flash.h because it uses
* their respective BSL modules.
*/
#include "evmdm642.h"
#include "evmdm642_led.h"
#include "evmdm642_aic23.h"
#include "evmdm642_flash.h"
#include "evmdm642_eeprom.h"
#include "evmdm642_uart.h"
#include "evmdm642_apll.h"
#include "evmdm642_pci.h"
/* Length of sine wave table */
#define SINE_TABLE_SIZE 48
/* Number of elements for DMA and McBSP loopback tests */
#define N 16
/* Define source and destination arrays for DMA and loopback tests */
Uint16 src[N], dst[N], buffer[256];
volatile Uint32 sleepCount = 0;
void sleepIsr()
{
sleepCount++;
}
Int16 TEST_uartA()
{
Int16 i;
EVMDM642_UART_Handle hUart;
EVMDM642_UART_Config uartcfg = {
0x00, // IER
0x57, // FCR - FIFO Mode, 16 character trigger level
0x03, // LCR - 8 bits, no parity, 1 stop
0x00 // MCR
};
/* Open UART */
hUart = EVMDM642_UART_open(EVMDM642_UARTA, EVMDM642_UART_BAUD19200, &uartcfg);
/* Loop through 256 bytes */
for (i = 0; i < 256; i++)
{
EVMDM642_UART_putChar(hUart, (i + 1) & 0xff);
// printf("%x\n", buffer[i]);
buffer[i] = EVMDM642_UART_getChar(hUart);
}
//printf("%x\n", buffer[5]);
/* Verify data */
for (i = 0; i < 256; i++)
{
if (buffer[i] != ((i+1) & 0xff))
return 1;
}
return 0;
}
Int16 TEST_uartB()
{
Int16 i;
EVMDM642_UART_Handle hUart;
EVMDM642_UART_Config uartcfg = {
0x00, // IER
0x57, // FCR - FIFO Mode, 16 character trigger level
0x03, // LCR - 8 bits, no parity, 1 stop
0x00 // MCR
};
/* Open UART */
hUart = EVMDM642_UART_open(EVMDM642_UARTB, EVMDM642_UART_BAUD19200, &uartcfg);
/* Loop through 256 bytes */
for (i = 0; i < 256; i++)
{
EVMDM642_UART_putChar(hUart, (i + 1) & 0xff);
buffer[i] = EVMDM642_UART_getChar(hUart);
}
/* Verify data */
for (i = 0; i < 256; i++)
{
if (buffer[i] != ((i + 1) & 0xff))
return 1;
}
return 0;
}
Int16 TEST_uart()
{
Int32 count = 0;
while(1)
{
if (TEST_uartA() != 0)
asm(" .long 0x10000000");
else
count++;
EVMDM642_LED_toggle(0);
}
}
Int16 TEST_pciregs()
{
Uint16 i, n;
Uint16 configregs[13] = {
0x104c, // 0
0x9065, // 1
0x0000, // 2
0xff00, // 3
0x1652, // 4
0x0642, // 5
0x0000, // 6
0x0000, // 7
0x0000, // 8
0x0000, // 9
0x0000, // 10
0x0000, // 11
0x0000 // 12
};
EVMDM642_PCI_config(configregs);
/* Read test values */
for (i = 0; i < 13; i++)
{
n = PCI_eepromRead(i);
if (n != configregs[i])
return 1;
}
return 0;
}
Int16 TEST_null()
{
return 0;
}
/* ------------------ Start Debug Code -------------------------------*/
void DEBUG_memLoop()
{
volatile Uint8 *pdata, data;
pdata = (Uint8 *)0x90080000;
while(1)
{
data = *pdata;
}
}
/* ------------------ End Debug Code --------------------------------*/
void TEST_execute(Int16 (*funchandle)(), char *testname, Int16 ledmask, Int16 insertdelay)
{
Int16 status;
/* Display test ID */
printf("%02d Testing %s...\n", ledmask, testname);
/* Call test function */
status = funchandle();
/* Check for test fail */
if (status > 0)
{
/* Print error message */
printf(" FAIL... error code %d... quitting\n", status, testname);
/* Software breakpoint */
asm(" .long 0x10000000");
} else
{
/* Print error message */
printf(" PASS\n", testname);
}
}
main()
{
/* Call BSL init */
EVMDM642_init();
/* Set initial LED state */
EVMDM642_LED_init();
/* Run the tests sequentially */
// TEST_execute(TEST_led, "LEDs", 1, 0);
// TEST_execute(TEST_audioclks, "SPDIF/APLL/VCXO", 2, 0);
// TEST_execute(TEST_syncbus, "Sync Bus", 3, 0);
// TEST_execute(TEST_extMem, "SDRAM", 4, 0);
// TEST_execute(TEST_flashID, "Flash ID", 5, 1);
// TEST_execute(TEST_flashall, "Flash", 6, 0);
// TEST_execute(TEST_eeprom, "I2C EEPROM", 7, 0);
TEST_execute(TEST_uartA, "UARTA", 8, 0);
TEST_execute(TEST_uartB, "UARTB", 9, 0);
// TEST_execute(TEST_pciregs, "PCI EEPROM", 10, 1);
/* Success */
printf("\n*** All tests PASS ***\n");
/* Disable interrupts */
IRQ_globalDisable();
/* Software breakpoint */
asm(" .long 0x10000000");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -