Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "LPC214x.h"
00030 #include "system.h"
00031 #include "main.h"
00032 #include "uart1.h"
00033 #include "irq.h"
00034 #include "hardware.h"
00035 #include "gpsmath.h"
00036 #include "ssp.h"
00037 #include "sdk.h"
00038 #include "ublox.h"
00039
00040 unsigned char packets;
00041 unsigned char DataOutputsPerSecond;
00042 unsigned int uart_cnt;
00043
00044 unsigned char data_requested=0;
00045 extern int ZeroDepth;
00046
00047 unsigned short current_chksum;
00048 unsigned char chksum_to_check=0;
00049 unsigned char chksum_trigger=1;
00050
00051 unsigned char transmission1_running=0;
00052 unsigned char trigger_transmission=0;
00053
00054 volatile unsigned char baudrate1_change=0;
00055
00056 unsigned char send_buffer[16];
00057 unsigned char *tx_buff;
00058 unsigned char UART1_syncstate=0;
00059 unsigned int UART1_rxcount=0;
00060 unsigned char *UART1_rxptr;
00061
00062 unsigned char UART_CalibDoneFlag = 0;
00063
00064 static volatile unsigned char rb_busy=0;
00065
00066 unsigned char startstring[]={'>','*','>'};
00067 unsigned char stopstring[]={'<','#','<'};
00068
00069
00070 void uart1ISR(void) __irq
00071 {
00072 unsigned char t;
00073 IENABLE;
00074 unsigned iir = U1IIR;
00075
00076 switch ((iir >> 1) & 0x7)
00077 {
00078 case 1:
00079
00080 if (ringbuffer1(RBREAD, &t, 1))
00081 {
00082 transmission1_running=1;
00083 UART1WriteChar(t);
00084 }
00085 else
00086 {
00087 transmission1_running=0;
00088 }
00089 break;
00090 case 2:
00091
00092 uBloxReceiveHandler(U1RBR);
00093 break;
00094 case 3:
00095
00096 break;
00097 case 6:
00098
00099 break;
00100 }
00101 IDISABLE;
00102 VICVectAddr = 0;
00103 }
00104
00105
00106
00107
00108
00109 void UART1Initialize(unsigned int baud)
00110 {
00111 unsigned int divisor = peripheralClockFrequency() / (16 * baud);
00112
00113 U1LCR = 0x83;
00114 U1DLL = divisor & 0xFF;
00115 U1DLM = (divisor >> 8) & 0xFF;
00116 U1LCR &= ~0x80;
00117 U1FCR = 1;
00118 }
00119
00120
00121
00122
00123 void UART1WriteChar(unsigned char ch)
00124 {
00125 while ((U1LSR & 0x20) == 0);
00126 U1THR = ch;
00127 }
00128
00129
00130
00131 unsigned char UART1ReadChar(void)
00132 {
00133 while ((U1LSR & 0x01) == 0);
00134 return U1RBR;
00135 }
00136
00137
00138
00139 void UART1_send(unsigned char *buffer, unsigned char length)
00140 {
00141 unsigned char cnt=0;
00142 while(length--)
00143 {
00144 while (!(U1LSR & 0x20));
00145 U1THR = buffer[cnt++];
00146 }
00147 }
00148
00149
00150
00151
00152 void UART1_send_ringbuffer(void)
00153 {
00154 unsigned char t;
00155 if(!transmission1_running)
00156 {
00157 if(ringbuffer1(RBREAD, &t, 1))
00158 {
00159 transmission1_running=1;
00160 UART1WriteChar(t);
00161 }
00162 }
00163 }
00164
00165 int ringbuffer1(unsigned char rw, unsigned char *data, unsigned int count)
00166 {
00167 static volatile unsigned char buffer[RINGBUFFERSIZE];
00168
00169 static volatile unsigned int read_pointer, write_pointer;
00170 static volatile unsigned int content=0;
00171 unsigned int p=0;
00172 unsigned int p2=0;
00173
00174 if(rw==RBWRITE)
00175 {
00176 if(count<RINGBUFFERSIZE-content)
00177 {
00178 while(p<count)
00179 {
00180 buffer[write_pointer++]=data[p++];
00181 }
00182 content+=count;
00183 return(1);
00184 }
00185 }
00186 else if(rw==RBREAD)
00187 {
00188 if(content>=count)
00189 {
00190 while(p2<count)
00191 {
00192 data[p2++]=buffer[read_pointer++];
00193 }
00194 content-=count;
00195 if(!content)
00196 {
00197 write_pointer=0;
00198 read_pointer=0;
00199 }
00200 return(1);
00201 }
00202 }
00203 else if(rw==RBFREE)
00204 {
00205 if(content) return 0;
00206 else return(RINGBUFFERSIZE-11);
00207 }
00208
00209 return(0);
00210 }