在进行UART端口验证时,需要对UART端口进行参数配置,同时在进行验证时,可以采用短接UART,直接进行数据的收发验证,以此来达到测试端口是否OK的目的。
测试程序的代码:
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h> //文件控制定义
#include <termios.h>//终端控制定义
#include <errno.h>
#define BAUDRATE B115200
#define FALSE -1
#define TRUE 0
int serial_fd = 0;
const char uartbuf[]="/dev/tty";
int test_uart_port(FILE* pFile, char* cDeviceName, int iUartIndex);
int main(int argc, char **argv){
int fd;
int data_tx = 0x58FF;
char cDeviceName[20] = {0};
int iUartNum = -1;
FILE *pFile = fopen("ap-result.txt","a+");
switch (*argv[1]) {
case 'A':
case 'a':
//UART12
sprintf(cDeviceName, "%sHSL0", uartbuf);
test_uart_port(pFile, cDeviceName, 12);
//UART5
sprintf(cDeviceName, "%sHSL1", uartbuf);
test_uart_port(pFile, cDeviceName, 5);
//UART9
sprintf(cDeviceName, "%sHSL2", uartbuf);
test_uart_port(pFile, cDeviceName, 9);
break;