#include <time.h>
002
#include <fcntl.h>
003
#include <stdio.h>
004
#include <ctype.h>
005
#include <errno.h>
006
#include <stdlib.h>
007
#include <string.h>
008
#include <unistd.h>
009
#include <signal.h>
010
#include <termio.h>
011
#include <syslog.h>
012
#include <pthread.h>
013
#include <sys/ipc.h>
014
#include <sys/msg.h>
015
#include <sys/wait.h>
016
#include <sys/stat.h>
017
#include <sys/time.h>
018
#include <semaphore.h>
019
#include <arpa/inet.h>
020
#include <sys/types.h>
021
#include <sys/socket.h>
022
#include <bits/signum.h>
023
#include <sys/resource.h>
024
025
int
uart_init(
int
arg,
int
baud)
026
{
027
int
fd;
028
char
port[20];
029
struct
termios Opt;
030
int
uartbiit[50]= {B115200,B9600,B19200,B4800,B2400,B1200};
031
032
sprintf
(port,
"/dev/s3c2410_serial%d"
,arg);
033
printf
(
"Use port: %s \n"
, port);
034
fd = open(port, O_RDWR);
035
if
(fd<0)
036
{
037
return
-1;
038
}
039
040
tcgetattr(fd,&Opt);
041
tcflush(fd,TCIFLUSH);
042
cfsetispeed(&Opt,uartbiit[baud]);
043
cfsetospeed(&Opt,uartbiit[baud]);
044
045
Opt.c_cflag |= CS8;
046
Opt.c_cflag &= ~PARENB;
047
Opt.c_oflag &= ~(OPOST);
048
Opt.c_cflag &= ~CSTOPB;
049
Opt.c_lflag &= ~(ICANON|ISIG|ECHO|IEXTEN);
050
Opt.c_iflag &= ~(INPCK|BRKINT|ICRNL|ISTRIP|IXON);
051
052
Opt.c_cc[VMIN] = 64;
053
Opt.c_cc[VTIME] = 1;
054
055
if
(tcsetattr(fd,TCSANOW,&Opt) != 0)
056
{
057
perror
(
"SetupSerial!\n"
);
058
close(fd);
059
return
-1;
060
}
061
return
(fd);
062
063
}
064
065
int
main()
066
{
067
int
fd, len = 0, i=0;
068
char
buf[300];
069
070
if
((fd = uart_init(1, 0)) <0)
071
{
072
printf
(
"Open uart err \n"
);
073
return
-1;
074
}
075
sprintf
(buf,
"Hello world !\n"
);
076
077
while
(1)
078
{
079
memset
(buf, 0 ,
sizeof
(buf));
080
081
#if 0
082
while
((len = read(fd,buf,64))>0)
083
{
084
printf
(
"%s\n"
,buf);
085
}
086
#endif
087
088
089
#if 1
090
int
nread;
091
while
((nread = read(fd, buf, 300))>0)
092
{
093
094
095
printf
(
"%s\n"
,buf);
096
write(fd,buf,
sizeof
(buf));
097
098
}
099
#endif
100
}
101
102
103
return
0;
104
}