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

📄 uart_test.c

📁 三星mcu S3C4510B评估板的原码
💻 C
字号:
/*************************************************************************/
/*                                                                       */
/* FILE NAME                                      VERSION                */
/*                                                                       */
/* source\uart_test.c                              1.0                   */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*     UART TEST CODE for S3C4510B0                                      */
/*                                                                       */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/* FUNCTIONS : UART test                                                 */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*                                                                       */
/* NAME:    Nicolas Park           					 */
/* The last Modification date:  18-April-2002                            */
/* REMARKS:  Created initial version 1.0                                 */
/*                                                                       */
/*                                Copyright (C) 2002 AIJISYSTEM CO.,LTD  */
/*************************************************************************/

#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "std.h"
#include "apdialog.h"
#include "s3c4510b0.h"
#include "memory.h"
#include "uart.h"
#include "dma.h"
#include "isr.h"
#include "pollio.h"
#include "sysconf.h"


void UartTest(void)
{

     void PrintUartItems(void);
     char items;


     do {
           IOPDATA= ~0xc;  //in UART test mode

           PrintUartItems(); // Main memu for cache test

           do { 
                 Print("\nSelect Number?_");
                 items = get_byte();
           }while(is_space(items));

           if(is_xdigit(to_upper(items))) {

               switch(to_upper(items)) {
                      case '1': UARTConfigView();  break;
                      case '2': UARTAutoLoopBack();  break;
                      case '3': StringEcho(CONSOLE);  break; 
                      default : break;
              }
           }
           Print("\nPress any key to continue.\r");
           while(!is_space(get_byte()));

     } while((items!='q')&&(items!='Q'));

}


uint32 UARTAutoLoopBack(void)
{
	uint32  ascii;
	uint32  LoopBackFlag0=0, LoopBackFlag1=0; 
	uint8   ch;

        /* Transmit complete */

	UARTRxIntOff(SERIAL_DEV0); UARTTxIntOff(SERIAL_DEV0);
        Print("\nUART internal Loopback test...");
        UARTTxComplete(UARTSTAT0);

    	/* Set Loopback test mode */
	UARTCONT0 |= UCON_LOOPBACK;
        
    	for(ascii = 48; ascii < 123 ; ascii++) {
        	put_char(SERIAL_DEV0, (char)ascii);
        	ch = get_char(SERIAL_DEV0);
        	if(ch != (char)ascii) LoopBackFlag0 = 1;
	}

        UARTCONT0 &= ~UCON_LOOPBACK; //clear loopback for print
	if (LoopBackFlag0) Print("\n $$$ UART0 internal loopback FAIL(POLL)!!!") ;
	else Print("\n $$$ UART0 internal loopback PASS(POLL)!!!") ;


	UARTRxIntOff(SERIAL_DEV1); UARTTxIntOff(SERIAL_DEV1);
        /* Transmit complete */
        UARTTxComplete(UARTSTAT1);

    	/* Set Loopback test mode */
	UARTCONT1 |= UCON_LOOPBACK;

    	for(ascii = 48; ascii < 123 ; ascii++) {
        	put_char(SERIAL_DEV1,(char)ascii);
        	ch = get_char(SERIAL_DEV1);
        	if(ch != (char)ascii) LoopBackFlag1 = 1;
    	}
	
        UARTCONT1 &= ~UCON_LOOPBACK; //clear loopback for print
	if (LoopBackFlag1) Print("\n $$$ UART1 internal loopback FAIL(POLL)!!!") ;
	else Print("\n $$$ UART1 internal loopback PASS(POLL)!!!") ;

	if (!(LoopBackFlag0 || LoopBackFlag1)) return 1 ;
	else return 0 ;
}


void StringEcho(uint32 channel)
{
    uint8    *bp;    /* UART test memory pointer */
    uint32   sz,i;     /* Input string size */
    uint8    ch;
   
    i = 0;

    do {
          Print("\n\r\rString echo for interrupt test.");
          Print("\nInput characters will be echoed on Console");
          Print("\n\rInput %d : ",i);

          bp  = (uint8 *)UartTxbuff;

          do {
               while((ch = i_getc(channel)) == NULL); 
               *bp++ = ch;
               sz++;
          }while(ch != CR);

          bp  = (uint8 *)UartTxbuff;
          Print("\nEcho %d: ",i);

          while((ch = *bp++) != CR) 
          {
                while(!i_putc(channel,ch)); 
          }

          Print("\nTo escape, enter ESC key : ");
          while((ch = i_getc(channel)) == NULL); 
          i++;

    }while(ch != ESC);
}


void PrintUartItems(void)
{
        Print("\n\n");
	Print("+---------------------------------------------------+\n") ;
        Print("|                  UART TEST ITEMS                  |\n") ;
	Print("+---------------------------------------------------+\n") ;
	Print("| 1. UART configurations viewer.                    |\n") ;
	Print("| 2. Internal Loopback test.(POLL)                  |\n") ;
	Print("| 3. String echo (INTERRUPT)                        |\n") ;
	Print("| Q. QUIT - Return to main menu.                    |\n") ;
	Print("+---------------------------------------------------+\n") ;
}


uint32 getchannel(void)
{
  char ch;

     do { 
           Print("\nSelect UART Channel[0/1]?_");
           ch = get_byte();
     }while((ch!= '1') && (ch != '0'));
    
     if(ch == '1') return(1);
     else  return(0);
}



void PrintStatus(int Ldisp, char Udisp)
{
     char temp;

     temp =  Udisp; 
     put_byte(temp);
     put_byte('\b') ;
     IOPDATA = Ldisp ;
}

void UARTConfigView(void)
{
 
   if(getchannel()) {
        Print("\n");
        Print("------------------------------\n");
        Print(" <<< UART1 REGISTER STATUS >>>\n");
        Print("------------------------------\n");
        Print("UARTLCON1[0x%x] = 0x%x\n",&UARTLCON1,UARTLCON1);
        Print("UARTCONT1[0x%x] = 0x%x\n",&UARTCONT1,UARTCONT1);
        Print("UARTSTAT1[0x%x] = 0x%x\n",&UARTSTAT1,UARTSTAT1);
        Print("UARTBRD1 [0x%x] = 0x%x\n",&UARTBRD1,UARTBRD1);


   }
   else {
        Print("\n");
        Print("------------------------------\n");
        Print(" <<< UART0 REGISTER STATUS >>>\n");
        Print("------------------------------\n");
        Print("UARTLCON0[0x%x] = 0x%x\n",&UARTLCON0,UARTLCON0);
        Print("UARTCONT0[0x%x] = 0x%x\n",&UARTCONT0,UARTCONT0);
        Print("UARTSTAT0[0x%x] = 0x%x\n",&UARTSTAT0,UARTSTAT0);
        Print("UARTBRD0 [0x%x] = 0x%x\n",&UARTBRD0,UARTBRD0);
   }
}

⌨️ 快捷键说明

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