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

📄 uart.c

📁 smdk40100 40mhz test code
💻 C
字号:
#include <string.h>
#include <stdlib.h>
#include "..\include\k401.h"
#include "..\include\k401lib.h"
#include "..\include\def.h"

char Uart_IntGetKey(void);

void __irq Uart_RxInt(void);
void __irq Uart_TxFifoInt(void);
void __irq Dma0UartDone(void);


//static U8 keyBuf[];
//volatile static int keyBufRdPt=0;
//volatile static int keyBufWrPt=0;
static char *uartTxStr;
volatile unsigned char *downPt;
int error;
volatile int uartfifostop;

void __irq Uart_RxInt(void)
{
    rINTPND=(~BIT_URX);
    *downPt++=rURXH;
}

void __irq Uart_Error(void)
{
    rINTPND&=~(BIT_UERR);		// Clear pending bits
    error=(int)rUSTAT;
}

void __irq Uart_TxFifoInt(void)
{
    rINTPND=~BIT_UTX;

    while( !(rUFSTAT & 0x80) && (*uartTxStr != '\0') )
    {
	rUTXH_B=*uartTxStr++;
    }
    if(*uartTxStr == '\0')
	rINTMSK&=~BIT_UTX;
}

void __irq Uart_RxFifoInt(void)
{
    rINTPND=~BIT_URX;
    while((rUFSTAT&0x7)>0)
    {
	*downPt++=rURXH_B;
    }
    uartfifostop=1;
}

void Test_UartFifo(void)
{
    int i;
    unsigned short int checkSum=0,dnCS;
    unsigned char *uartRxStr;
    unsigned int fileSize;

    //keyBufRdPt=keyBufWrPt=0;

    pISR_UTX=(unsigned)Uart_TxFifoInt;

    Uart_Printf("[Uart Tx FIFO Interrupt Test]\n");
    uartTxStr="0123456789abcdefghijklmnopqrstuvwxyz\r\n";

    Uart_TxEmpty();			// Wait until tx shifter is empty.

    //rUCON=rUCON&0xf3|0x8;
    //rUCON=rUCON&0xf3|0x4;		// You have need of resetting for the transmit mode

    rUFCON=(00<<6)|(3<<4)|7;		// FIFO trigger level: Tx=4byte, Rx=4byte, Tx/Rx FIFO reset, FIFO enable


    rSYSCON|=BIT_GLOBAL;
    rINTMSK=BIT_UTX;

    Delay(3000);

// ========== UART Tx FIFO Interrupt Test Complete ==========

    Uart_Printf("\n[Uart FIFO Tx Test by DMA0(SRC=Increase)]\n");
    uartTxStr="0123456789abcdefghijklmnopqrstuvwxyz\r\n";

    Uart_TxEmpty();
    rUCON=0x49;				// Rx mode=Int/polling, Tx mode=DMA0, Rx status int. enable

    rDMASRC0=(unsigned int)uartTxStr;
    rDMADST0=UTXH_B;
    rDMACNT0=strlen(uartTxStr);
    rDMACON0=0x49;			// SRC=Increase, DST=fix, Mode=UART, No stop, Single, Transfer width=Byte

    while(rDMACON0&0x2);

// ========== UART FIFO Tx Test by DMA0(SRC=Increase) complete ==========

    Uart_TxEmpty();
    rUCON=0x45;				// UART Control register initilize

    Uart_Printf("\n[Uart FIFO Tx Test by DMA1(SRC=Decrease)]\n");
    uartTxStr="\n\rzyxwvutsrqponmlkjihgfedcba9876543210";

    Uart_TxEmpty();
    rUCON=0x4d;				// Rx mode=Int/polling, Tx mode=DMA1, Rx status int. enable

    rDMASRC1=(unsigned int)(uartTxStr+strlen(uartTxStr));
    rDMADST1=UTXH_B;
    rDMACNT1=strlen(uartTxStr);
    rDMACON1=0x69;			// SRC=Decrease, DST=fix, Mode=UART, No stop, Single, Transfer width=Byte

    while(rDMACON1&0x2);

// ========== UART FIFO Tx Test by DMA1(SRC=Decrease) complete ==========

    rUFCON=(2<<6)|(1<<4)|(6)|0;	// FIFO disable
    Uart_TxEmpty();

    //rUCON0=0x45|0x80;         //tx:int rx:int rcv_time_out enabled
    Uart_Printf("\n[Uart Rx Interrupt Test]\n");

    uartRxStr=(unsigned char *)malloc(0x1000);
    downPt=(unsigned char *)uartRxStr;
    Uart_Printf("downPt=0x%x, uartRxStr=0x%x\n",downPt, uartRxStr);

    pISR_URX=(unsigned)Uart_RxInt;
    pISR_UERR=(unsigned)Uart_Error;

    Uart_Printf("Download the plain binary file(test.bin)\n");
    Uart_Printf("To transmit .BIN file: wkocm2 test.bin /2 /d:1\n");
    Uart_Printf("Download methods: COM:8Bit,NP,1STOP\n");

    rINTPND=0x0;
    rINTMSK=(BIT_URX|BIT_UERR);		// Default value=0x0



    while((unsigned int)downPt-(int)uartRxStr<4);

    fileSize=*((unsigned char *)(uartRxStr))+
	     (*((unsigned char *)(uartRxStr+1))<<8)+
	     (*((unsigned char *)(uartRxStr+2))<<16)+
	     (*((unsigned char *)(uartRxStr+3))<<24);

    Uart_Printf("fileSize=0x%x\n",fileSize);

    while((unsigned int)downPt<fileSize);
    i=0;
    checkSum=0;
    for(i=4;i<(fileSize-2);i++)
    {
	checkSum+=*((unsigned char *)(i+uartRxStr));
    }
    dnCS=*((unsigned char *)(uartRxStr+fileSize-2))+
	 (*( (unsigned char *)(uartRxStr+fileSize-1) )<<8);

    if(checkSum!=dnCS)
    {
	Uart_Printf("Checksum Error!!! MEM:%x DN:%x\n",checkSum,dnCS);
    }

    Uart_Printf("UART FIFO Rx Interrupt Test O.K.\n");
    free(uartRxStr);
    rINTMSK=0x0;

// ========== UART Rx Interrupt Test complete =========

    Uart_Printf("[Uart FIFO Rx Test by DMA0]\n");
    uartRxStr=(unsigned char *)malloc(0x1000);

    downPt=(unsigned char *)uartRxStr;

    pISR_URX=(unsigned)Uart_RxFifoInt;

    rUCON=0xc5;				// Rx mode=DMA0, Tx mode=Int, Rx FIFO timeout=enable, Rx status Int.=enable
    rUFCON=(2<<6)|(1<<4)|(6)|1;

    Uart_Printf("Download the plain binary file(test.bin)\n");
    Uart_Printf("Follow these steps to transmit\n");
    Uart_Printf(" 1. Select transmit of Text file from the Transmit menu\n");
    Uart_Printf("    The open file dialog box is display\n");
    Uart_Printf(" 2. Select ~/401test/test.bin\n");

    uartfifostop=0;
    rINTPND=0x0;
    rINTMSK=BIT_URX;

    while(uartfifostop==0);

    i=0;
    checkSum=0;
    for(i=0;i<(fileSize-0x6);i++)
    {
	checkSum+=*((unsigned char *)(i+uartRxStr));
	Uart_Printf("Data=0x%x\n",*((unsigned char *)(i+uartRxStr)));
    }
    if(checkSum!=dnCS)
    {
	Uart_Printf("Checksum Error!!! MEM:0x%x DN:0x%x\n",checkSum,dnCS);
    }

    rUFCON=(2<<6)|(1<<4)|(6)|0;	// FIFO disable

    rINTMSK=0x0;
    rSYSCON&=~BIT_GLOBAL;
    rUCON=0x45;			//rcv_time_out disabled
    free(uartRxStr);
}

⌨️ 快捷键说明

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