00001
00009 #include <stdio.h>
00010 #include <fcntl.h>
00011 #include "gp3lib.h"
00012
00013 #include <asm/termios.h>
00014
00015 #define BAUDRATE B57600
00016 #define DEBUGOUT 0
00017 #if DEBUGOUT
00018 #define DEBUG(tag,x) printf("DEBUG: %s=%02X\n",tag,x)
00019 #else
00020 #define DEBUG(tag,x)
00021 #endif
00022
00023
00024
00025
00026 static int fd;
00027 static struct termios oldtio;
00028
00029
00030
00031 int gp3openport(char *port)
00032 {
00033 struct termios tio;
00034 int i;
00035 fd=open(port,O_RDWR|O_NOCTTY);
00036 if (fd<0)
00037 {
00038 return -1;
00039 }
00040 tcgetattr(fd,&oldtio);
00041 memset(&tio,0,sizeof(tio));
00042
00043 tio.c_cflag=BAUDRATE|CS8|CLOCAL|CREAD|CRTSCTS;
00044 tio.c_iflag=IGNPAR;
00045 tio.c_oflag=0;
00046 tio.c_lflag=0;
00047 for (i=0;i<NCCS;i++) tio.c_cc[i]=0;
00048 tio.c_cc[VMIN]=1;
00049 tcflush(fd,TCIFLUSH);
00050 tcsetattr(fd,TCSANOW,&tio);
00051 return 0;
00052 }
00053
00054
00055 void gp3closeport()
00056 {
00057 tcsetattr(fd,TCSANOW,&oldtio);
00058 close(fd);
00059 }
00060
00061
00062 int gp3write(int byte)
00063 {
00064 char c=(char)byte;
00065 DEBUG("write",byte);
00066 return write(fd,&c,1);
00067 }
00068
00069
00070
00071 unsigned int gp3read(void)
00072 {
00073 char c;
00074 unsigned int rv;
00075 read(fd,&c,1);
00076 rv=((unsigned int)c) & 0xFF;;
00077 DEBUG("read",rv);
00078 return rv;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093 int gp3ready(void)
00094 {
00095 int s;
00096 usleep(100);
00097 ioctl(fd,TIOCMGET,&s);
00098 return (s&TIOCM_CTS)==TIOCM_CTS;
00099 }
00100
00101
00102
00103
00104