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

📄 uarttest.c

📁 DM642支持4个串口的驱动代码
💻 C
字号:
/*
 *  Copyright 2003 by Texas Instruments Incorporated.
 *  All rights reserved. Property of Texas Instruments Incorporated.
 *  Restricted rights to use, duplicate or disclose this code are
 *  granted through contract.
 *  
 */
/* "@(#) DDK 1.10.00.23 07-02-03 (ddk-b12)" */
/*
 *  ======== uarttest.c ========
 */

#include <std.h>
#include <stdio.h>
#include <stdlib.h>
#include <log.h>
#include <gio.h>
#include <iom.h>
#include "tsk.h"

#ifdef _6x_
extern far LOG_Obj trace;
#else
extern LOG_Obj trace;
#endif

#define SENDDATASIZE 800


/*
 *  ======== main ========
 */
Void main()
{
    printf( "UART Test started!\n");
}

/*
 *  ======== echo =========
 */
Void echo0()
{
    GIO_Handle  outChan0, inChan0;
    Char        bufout0[SENDDATASIZE] = "This is UART0";
    Char        bufin0[SENDDATASIZE] = "AT\r";
    Uns         outsize0 = 13; //SENDDATASIZE;
    Uns         insize0 = 1; //SENDDATASIZE;
    Int         status0;

    printf( "This is echo0!\n");
    inChan0 = GIO_create("/uart0", IOM_INPUT, NULL, NULL, NULL);
    outChan0 = GIO_create("/uart0", IOM_OUTPUT, NULL, NULL, NULL);


    if (outChan0 == NULL) {
        LOG_printf(&trace, "GIO_create failed");
        SYS_abort("GIO_create");
    }
    bufin0[1] = 0;    
    status0 = GIO_write(outChan0, bufout0, &outsize0);
    
    for (;;) {
        status0 = GIO_read(inChan0, bufin0, &insize0);

        if (status0 < 0) {
            LOG_printf(&trace, "GIO_write error");
            SYS_abort("GIO_read");
        }
        else
            printf("0: %c\n", bufin0[0]);        	

//		TSK_sleep(1000);
    }


}

/*
 *  ======== echo1 =========
 */
Void echo1()
{
    GIO_Handle  outChan1, inChan1;
    Char        bufout1[SENDDATASIZE] = "This is UART1";
    Char        bufin1[SENDDATASIZE] = "AT\r";
    Uns         outsize1 = 13; //SENDDATASIZE;
    Uns         insize1 = 1; //SENDDATASIZE;
    Int         status1;

    printf( "This is echo1!\n");
    inChan1 = GIO_create("/uart1", IOM_INPUT, NULL, NULL, NULL);
    outChan1 = GIO_create("/uart1", IOM_OUTPUT, NULL, NULL, NULL);


    if (outChan1 == NULL) {
        LOG_printf(&trace, "GIO_create failed");
        SYS_abort("GIO_create");
    }
    bufin1[1] = 0;    
	status1 = 0;
    status1 = GIO_write(outChan1, bufout1, &outsize1);
//        
    for (;;) {
        status1 = GIO_read(inChan1, bufin1, &insize1);

    
        if (status1 < 0) {
            LOG_printf(&trace, "GIO_write error");
            SYS_abort("GIO_read");
        }
        else
            printf("1: %c\n", bufin1[0]);        	

		TSK_sleep(10);
    }
}


/*
 *  ======== echo2 =========
 */
Void echo2()
{
    GIO_Handle  outChan2, inChan2;
    Char        bufout2[SENDDATASIZE] = "This is UART2";
    Char        bufin2[SENDDATASIZE] = "AT\r";
    Uns         outsize2 = 13; //SENDDATASIZE;
    Uns         insize2 = 1; //SENDDATASIZE;
    Int         status2;

    printf( "This is echo2!\n");
    inChan2 = GIO_create("/uart2", IOM_INPUT, NULL, NULL, NULL);
    outChan2 = GIO_create("/uart2", IOM_OUTPUT, NULL, NULL, NULL);


    if (outChan2 == NULL) {
        LOG_printf(&trace, "GIO_create failed");
        SYS_abort("GIO_create");
    }
    bufin2[1] = 0;    
	status2 = 0;
    status2 = GIO_write(outChan2, bufout2, &outsize2);
//        
    for (;;) {
        status2 = GIO_read(inChan2, bufin2, &insize2);

    
        if (status2 < 0) {
            LOG_printf(&trace, "GIO_write error");
            SYS_abort("GIO_read");
        }
        else
            printf("2: %c\n", bufin2[0]);        	

		TSK_sleep(10);
    }
}

/*
 *  ======== echo3 =========

Void echo3()
{
    GIO_Handle  outChan3, inChan3;
    Char        bufout3[SENDDATASIZE] = "This is UART3";
    Char        bufin3[SENDDATASIZE] = "AT\r";
    Uns         outsize3 = 13; //SENDDATASIZE;
    Uns         insize3 = 1; //SENDDATASIZE;
    Int         status3;

    printf( "This is echo3!\n");
    inChan3 = GIO_create("/uart3", IOM_INPUT, NULL, NULL, NULL);
    outChan3 = GIO_create("/uart3", IOM_OUTPUT, NULL, NULL, NULL);


    if (outChan3 == NULL) {
        LOG_printf(&trace, "GIO_create failed");
        SYS_abort("GIO_create");
    }
    bufin3[1] = 0;    
	status3 = 0;
    status3 = GIO_write(outChan3, bufout3, &outsize3);
//        
    for (;;) {
        status3 = GIO_read(inChan3, bufin3, &insize3);

    
        if (status3 < 0) {
            LOG_printf(&trace, "GIO_write error");
            SYS_abort("GIO_read");
        }
        else
            printf("3: %c\n", bufin3[0]);        	

		TSK_sleep(10);
    }
}
 */

⌨️ 快捷键说明

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