⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 这是一个串口测试程序
💻 C
字号:
#include "testcfg.h"

#include <stdio.h>
#include <std.h>
#include <sys.h>
#include <csl.h>
#include <csl_edma.h>
#include <csl_gpio.h>

#include "evmdm642.h"
#include "evmdm642_uart.h"

#define ICETEKDM642PCI_UART_BAUD115200     10
#define ICETEKDM642PCI_UART_BAUD57600      20
#define ICETEKDM642PCI_UART_BAUD38400      30
#define ICETEKDM642PCI_UART_BAUD19200      60
#define ICETEKDM642PCI_UART_BAUD9600       120
#define ICETEKDM642PCI_UART_BAUD4800       240
#define ICETEKDM642PCI_UART_BAUD2400       480
#define ICETEKDM642PCI_UART_BAUD1200       960

/* Flag to make sure POST only runs once after power cycle */
Uint32 testflag;

Int16 TEST_uartA()
{
    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, ICETEKDM642PCI_UART_BAUD115200, &uartcfg);

    while ( 1 )
    {
        EVMDM642_UART_putChar(hUart, EVMDM642_UART_getChar(hUart));
    }
    
    return 0;
}

Int16 TEST_uart()
{
    Int32 count = 0;
    
    while(1)
    {
        if (TEST_uartA() != 0)
            asm(" .long 0x10000000");
        else
            count++;
        EVMDM642_LED_toggle(0);
    }
}

/* ------------------  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_uartA,     "UARTA",           8, 0);

    /* Disable interrupts */
    IRQ_globalDisable();

    /* Software breakpoint */
    asm(" .long 0x10000000");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -