#include "common.h"
/*
* v1.0 start to use version to manageme the code
*
*
*
*/
int main(int argc, char **argv) {
int i = 0, rd = 0;
fd_set readFds;
int retval;
unsigned int count = 0, pos = 0;
int mctrl = 0x8000; //TIOCM_LOOP;
struct timeval respTime;
unsigned char input_buf[bufsize], output_buf[bufsize], data_dev[64];
unsigned long long size = 0;
int sendsize, sleeptime=0;
int bitrate = 0;
int j,error=0;
/* to handle ctrl +c */
if(signal(SIGINT, signalHandler) == SIG_ERR) {
printf("ERROR : Failed to register signal handler\n");
exit(1);
}
if (argc != 7 && argc != 8) {
display_intro();
exit(1);
}
j = sscanf(argv[3],"%li",&ut.baudrate);
if (j != 1)
error = 1;
j = sscanf(argv[4],"%i",&ut.flow_cntrl);
if (j != 1)
error = 1;
j = sscanf(argv[5],"%i",&ut.max_delay);
if (j != 1)
error = 1;
if (!(ut.max_delay >= 0 && ut.max_delay <= 100))
error = 1;
j = sscanf(argv[6],"%i",&ut.random_enable);
if (j != 1)
error = 1;
if (error){
printf("\n Invalid command line argument [argv] \n");
display_intro();
exit(1);
}
if(argv[7] == NULL){
ut.fd = open(UART_DEV_NAME, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK );
}else{
ut.fd = open(argv[7], O_RDWR);
}
if (ut.fd == -1) {
printf("open_port: Unable to open port - %s ", argv[7]);
exit(1);
} else
fcntl(ut.fd, F_SETFL, 0);
printf("Existing port baud=%d \n", getbaud(ut.fd));
/* save current port settings */
tcgetattr(ut.fd, &oldtio);
initport(ut.fd, ut.baudrate, ut.flow_cntrl);
printf("Configured port for New baud=%d\n", getbaud(ut.fd));
sscanf(argv[1],"%c",&tx_rx);
//disable loopback mode
mctrl = 0x0000; //TIOCM_LOOP;
ioctl(ut.fd, 0x5418, &mctrl); //TIOCMSET
switch (tx_rx) {
case 't':
printf("enter uart test mode\n");
#if 1
system("cat /sys/kernel/debug/clk/clk_summary | grep uart");
system("io -4 -l 0x100 0xff0e0004");
system("io -4 0xff0e000c 0x83");
system("io -4 0xff0e0000");
system("io -4 0xff0e0004");
system("io -4 0xff0e000c 0x03");
//system("io -4 0xff000088");
//system("io -4 -l 0x500 0xff500000");
#endif
break;
case 'r':
read_flag = 0;
#if 0
fd1 = open("/mnt/sdcard/uart.log", O_RDWR | O_CREAT);
if(fd1 == -1) {
printf("\n cannot open %s\n","/mnt/sdcard/uart.log");
}
#endif
while(1) {
FD_ZERO(&readFds);
FD_SET(ut.fd, &readFds);
respTime.tv_sec = 10;
respTime.tv_usec = 0;
gettimeofday(&ut.start_time, NULL);
/* Sleep for command timeout and expect the response to be ready. */
#if 0
retval = select(FD_SETSIZE, &readFds, NULL, NULL, &respTime);
if (retval == 0 ) {
if (read_flag == 0) {
printf("\n Waited until timeout; no data was available to read. Exiting... \n");
if (unlink(argv[2]) == -1)
printf("\n Failed to delete the file %s \n",argv[2]);
close_port();
}
else {
//printf("\n select() timed out... waiting for more data\n");
continue; /*skip this loop because FD_SET doesn't have any data */
}
}
else if (retval == ERROR)
printf("\n select: error :: %d\n",retval);
/* Read data, abort if read fails. */
if(FD_ISSET(ut.fd, &readFds) != 0) {
//fcntl(ut.fd, F_SETFL, FNDELAY);
/* printf("\n entering readport func \n"); */
if(read_flag == 0) {
//gettimeofday(&ut.start_time, NULL);
read_flag = 1;
printf("\n Reading data from port to file...\n");
}
rd = readport(&ut.fd, output_buf);
if (ERROR == rd) {
printf("Read Port failed\n");
close_port();
}
}
#endif
//rd = readport(&ut.fd, output_buf);
rd = 0;
usleep(10000);
gettimeofday(&ut.end_time, NULL);
timersub(&ut.end_time, &ut.start_time, &ut.diff_time);
//if (ut.diff_time.tv_usec > 15000)
// printf("\n gap:%dus\n", ut.diff_time.tv_sec * 1000000 + ut.diff_time.tv_usec);
//if(rd == 0)
// break;
#if 1
for (i = 0; i < rd; i++) {
if (output_buf[i] != 0x55) {
count++;
printf("error[%d] is %02x\n", i, output_buf[i]);
}
}
#endif
size += rd;
//i = writeport(&ut.fd, output_buf, rd);
#if 0
if (rd != 0)
printf("#Read %d bytes from port , total error:%d total:%lld\n",rd, count, size);
#endif
#if 0
gettimeofday(&ut.start_time, NULL);
sprintf(data_dev, "/mnt/sdcard/%lld.txt", (ut.start_time.tv_sec * 1000000 + ut.start_time.tv_usec));
fd1 = open(data_dev, O_RDWR | O_CREAT);
if(fd1 == -1) {
printf("\n cannot open %s\n",data_dev);
} else {
printf("\n write %d data to file %s...\n", rd, data_dev);
}
write(fd1, output_buf, rd);
close(fd1);
#else
//write(fd1, output_buf, rd);
#endif
memset(output_buf, 0, bufsize);
}
//gettimeofday(&ut.end_time,NULL);
printf("\n Read %lld bytes from port error:%d \n",size, count);
FD_CLR(ut.fd, &readFds);
break;
case 's':
fd1 = open(argv[2],O_RDONLY);
if(fd1 == -1) {
printf("\n cannot open %s, send 0x55 instead\n",argv[2]);
} else {
printf("\n Sending data from file to port...\n");
}
if (fd1 > 0)
gettimeofday(&ut.start_time, NULL);
while(1) {
if (ut.random_enable != 0)
sendsize = get_rand_value(bufsize);
else
sendsize = bufsize;
if (fd1 > 0) {
rd = read(fd1, &input_buf, sendsize);
if(rd == 0)
break;
} else {
memset(input_buf, 0x55, sendsize);
rd = sendsize;
}
//printf("\n Read from input file %d bytes \n",rd);
FD_ZERO(&readFds);
FD_SET(ut.fd, &readFds);
respTime.tv_sec = 10;
respTime.tv_usec = 0;
fcntl(ut.fd, F_SETFL, 0);
/* Sleep for command timeout and expect the response to be ready. */
retval = select(FD_SETSIZE, NULL, &readFds, NULL, &respTime);
if (retval == 0 ) {
printf("\n Waited tx until timeout... \n");
while(1) {
sleep(10);
}
} else if (retval == ERROR) {
printf("\n select: error :: %d\n",retval);
}
if(FD_ISSET(ut.fd, &readFds) != 0) {
if (fd1 <= 0)
gettimeofday(&ut.start_time,NULL);
if (writeport(&ut.fd, input_buf, rd) < 0) {
printf("\n Writing to port failed\n");
close_port();
} else
size += rd;
if (fd1 <= 0)
gettimeofday(&ut.end_time,NULL);
}
#ifdef ANDROID_FS
/* tcdrain not available on ANDROID */
ioctl(ut.fd, TCSBRK, 1); //equivalent to tcdrain(). perhaps permanent replacement?
#else
if(ERROR == tcdrain(ut.fd))
printf("\n tcdrain failure \n");
#endif
memset(input_buf,0,bufsize);
if (ut.max_delay) {
sleeptime = get_rand_value(ut.max_delay);
printf("\n Sleeping for %u seconds...\n",sleeptime);
sleep(sleeptime); /*sleep for a maximum of X random secs */
system("echo 1 > /sys/devices/platform/serial8250.0/uart1_rts_toggle");
}
if (fd1 <= 0)
break;
}
if (fd1 > 0)
gettimeofday(&ut.end_time,NULL);
timersub(&ut.end_time, &ut.start_time, &ut.diff_time);
bitrate = size * 10 * 1000000 / (ut.diff_time.tv_sec * 1000000 + ut.diff_time.tv_usec);
printf("\n Written %lld bytes to port, dbitrate is: %d bps\n",size, bitrate);
//use to check baudrate
/* Wait for 5 seconds for Transmitting to complete before sending the Break sequence */
sleep(1);
break;
case 'm':
#if 1
//set loopback mode
mctrl = 0x8000;
ioctl(ut.fd, 0x5418, &mctrl); //TIOCMSET
#endif
fd1 = open(argv[2], O_RDONLY);
if(fd1 == -1) {
printf("\n cannot open %s \n",argv[2]);
for (i = 0; i < bufsize; i++)
input_buf[i] = i % 256;
rd = bufsize;
} else {
rd = read(fd1, &input_buf, bufsize);
printf("Read %d bytes data from file\n", rd);
printf("Sending data from file to port...\n");
}
printf("Sending 0.1..255 data to port...\n");
gettimeofday(&ut.start_time, NULL);
size = 0;
while(1) {
if (ut.random_enable != 0)
sendsize = get_rand_value(bufsize);
else
sendsi
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
Examples: Sending data (no delays) ts_uart s init.rc 1500000 0 0 0 /dev/ttyS0 loop back mode: ts_uart m init.rc 1500000 0 0 0 /dev/ttyS0 receive, data must be 0x55 ts_uart r init.rc 1500000 0 0 0 /dev/ttyS0
资源推荐
资源详情
资源评论
收起资源包目录
ts_uart.zip (83个子文件)
ts_uart
ts_uart 2.68MB
common.o 14KB
ts_uart.o 15KB
soc.o 3KB
ts_uart_x86 887KB
backup
ts_uart 2.68MB
Makefile 464B
Android.mk 351B
soc.h 70B
ts_uart.c 10KB
.git
index 577B
HEAD 23B
refs
heads
master 41B
tags
stash 41B
COMMIT_EDITMSG 336B
objects
19
0b3866765fc19063ccd5e0623b90b9893fd361 234B
c3
92d343fc50910e106edaeb4e85b0ac4d50ac37 3KB
0f
681ce2ee35870cf2f4a7d17d9a75037d0b14f6 209B
a2
f7a4964c2a18a030b27378bc3debed5955f35a 3KB
f8e2d1bb1b46bd7573085559480ed8ae02cb5d 177B
56
c6c5cad30c4ae690b6b6b9fe7e1b23d922acee 3KB
3c1425a9543bdc7fabab2b5e775621fe5cc733 210B
09
490e2c2cbee884f5af8bf0a20a702e46880b6b 181B
9d
f692dfd280e7d04e0ab02ebbad62dbf04b7b77 232B
60
378b6b97495b29b15ea187230618de0a304263 3KB
f3
2664cc9789c0966ec275d1bc26b43c8cef188e 816B
43
b769f06c6fe2687078248809317e04a1682777 184B
45
580d6278649b84db4e4853ca6f3815b2828a6d 243B
37
36ae5eed87a30c5a3c6902f227cee4b7d8b369 177B
3c
391b45f6322456ae1c8e997811b76760825671 3KB
f9
dda6ea4548add661a5db09868d6372335df448 236B
ac898251403c452cc2b82b4452930023c6ae63 235B
82
7d1f5cc495bda22763a2b64d09bc87e5138622 153B
67
14a0d2c5f40a7b67bf02f7c42ab8c8cb925c37 209B
d0
56ddaf181128b81f4481ef7cc497d69fe49365 211B
33
b4f42903656f2e39ace4012bc40cf72468fb1f 3KB
91
96ab005f48f8dc6cf600cfd27919ce9bf62be1 163B
8a
9150c8b4846f541675ede791815ebb7c27e094 178B
ed
48f3b776d5cbac9577b344e09481589bb65ede 67B
49
ba6be1e0b8a60de620b17fe3c47893316d2c80 178B
30
91228ade1c72273322683c254c25bfef06a9be 163B
4b
57662797b98204099e95bd7064601b870e9e7f 248B
9c
ed43d083c7ef2ebf597991a2aac2c986103556 4KB
c9
b577b5881b65d029e42c22079d42c8b6c457b6 183B
54a9355f3cdb4af53ae4d77fa3cd7ba14a2937 212B
b6
e6586792a74ed8db49a009b2cb4f4ae408c2be 233B
a7
ff77258c632bda1cbd0efa485ca20def40aba3 3KB
pack
54
5ccc8df7c339e438ce81c415e7a8d57d7bc96c 235B
ab
df4439c67c27b2f650b22bf2b3d75ddb7b8275 182B
bf
4fd20e76c66e8c9a3dd2d91c15347f16eb6842 214B
info
ba
c5b02749eb110dbf3fe272c2221c608fe6899c 185B
88
8524a7e7bf154174783a17f6af2c453e4e9e61 284B
ac
b8444ad61156ce020afb846ee33191e7528983 236B
5b
91937b554ec5b22561c9e69970866366bb0afb 261B
47
d12273e604845b30d76549459aee1014336815 244B
7c
807c00041760676a75d885a2ee6fd6545751f9 210B
14
051acbba424bb82ba8cb59eb358e2ff1361aee 155B
ee
d66880881ac4ea2bde95fd748463db6627e8bc 161B
b7
f76c360311d3a9d5e424d185a3b93bc450e0bf 184B
90
7670ed403b2c9a9e042a82b3ca4a3e9268be56 182B
ce
99866f4da61d02f9e81a21c37836bad8ec96d3 185B
fd
9a18a9f2936ed677ae8a79561ab471521c41ef 183B
9a
bd04695d9356a518d775ed15d9d7a71975f716 236B
description 73B
info
exclude 240B
logs
HEAD 1KB
refs
heads
master 1021B
stash 181B
hooks
post-update.sample 189B
prepare-commit-msg.sample 1KB
commit-msg.sample 896B
update.sample 4KB
pre-commit.sample 2KB
pre-rebase.sample 5KB
applypatch-msg.sample 452B
pre-applypatch.sample 398B
pre-push.sample 1KB
ORIG_HEAD 41B
config 92B
branches
common.c 9KB
soc.c 291B
common.h 2KB
.gitignore 15B
共 83 条
- 1
资源评论
24k纯拽
- 粉丝: 53
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 最全空间计量实证方法(空间杜宾模型和检验以及结果解释文档).txt
- 5uonly.apk
- 蓝桥杯Python组的历年真题
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 2023-04-06-项目笔记 - 第一百十九阶段 - 4.4.2.117全局变量的作用域-117 -2024.04.30
- 前端开发技术实验报告:内含4四实验&实验报告
- Highlight Plus v20.0.1
- 林周瑜-论文.docx
- 基于MIC+NE555光敏电阻的声光控电路Multisim仿真原理图
- 基于JSP毕业设计-基于WEB操作系统课程教学网站的设计与实现(源代码+论文).zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功