code:interrupt_driven_tsip
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
code:interrupt_driven_tsip [2008/06/21 09:26] – laurenceb | code:interrupt_driven_tsip [2008/10/11 11:28] (current) – laurenceb | ||
---|---|---|---|
Line 2: | Line 2: | ||
//global(s) | //global(s) | ||
extern gps_type Gps; | extern gps_type Gps; | ||
+ | |||
// Interrupt driven TSIP (lassen iq) parser for Atmel AVR (state machine based) | // Interrupt driven TSIP (lassen iq) parser for Atmel AVR (state machine based) | ||
+ | |||
#define ETX 0x03 //as defined in TSIP specs | #define ETX 0x03 //as defined in TSIP specs | ||
#define DLE 0x10 | #define DLE 0x10 | ||
- | |||
- | //8O1 send routine for initial setup | ||
- | void suart_send(char c) | + | //8O1 send routine for initial setup |
+ | |||
+ | int suart_send(char c) | ||
{ | { | ||
u08 n; | u08 n; | ||
- | u08 p=FALSE; | + | u08 p=FALSE; //odd parity |
- | clear; | + | CLEAR; |
delay; | delay; | ||
for(n=0; | for(n=0; | ||
Line 20: | Line 20: | ||
if(c & 0x01) | if(c & 0x01) | ||
{ | { | ||
- | set; //update parity | + | SET; //update parity |
p=!p; | p=!p; | ||
} | } | ||
else | else | ||
{ | { | ||
- | clear; | + | CLEAR; |
} | } | ||
- | c>> | + | c>>=1; |
delay; | delay; | ||
} | } | ||
if(p) // | if(p) // | ||
{ | { | ||
- | set; | + | SET; |
} | } | ||
else | else | ||
{ | { | ||
- | clear; | + | CLEAR; |
} | } | ||
delay; | delay; | ||
- | set; //stop bit | + | SET; //stop bit |
delay; | delay; | ||
+ | return 0; | ||
} | } | ||
+ | |||
ISR(USART_RX_vect) // | ISR(USART_RX_vect) // | ||
{ | { | ||
static u08 id; | static u08 id; | ||
- | static u08 placemark; | + | static u08 placemarker; |
static gps_type gps; | static gps_type gps; | ||
- | static u08 *d; | ||
static u08 state; | static u08 state; | ||
+ | u08 *d=(u08*)& | ||
if(UCSR0A & (BV(FE0)|BV(UPE0))) // | if(UCSR0A & (BV(FE0)|BV(UPE0))) // | ||
{ | { | ||
Line 55: | Line 56: | ||
} | } | ||
char c=UDR0; | char c=UDR0; | ||
- | switch(state) | + | if(state==2 || state==4) // |
+ | { | ||
+ | if(!placemarker && id==0x6D) // | ||
+ | { | ||
+ | gps.status= c & 0x0F; | ||
+ | gps.nosats=(c & 0xF0)>> | ||
+ | } | ||
+ | else if(id==0x4A) // | ||
+ | { | ||
+ | if(placemarker< | ||
+ | { | ||
+ | d[27-placemarker]=c; | ||
+ | } | ||
+ | if(placemarker> | ||
+ | { | ||
+ | d[31-placemarker]=c; | ||
+ | } | ||
+ | } | ||
+ | else if(id==0x56 && placemarker< | ||
+ | { | ||
+ | d[11-placemarker]=c; | ||
+ | } | ||
+ | else if(placemarker> | ||
+ | { | ||
+ | state=0; | ||
+ | } | ||
+ | placemarker++; | ||
+ | } | ||
+ | switch(state) //run the state machine | ||
{ | { | ||
case 0: | case 0: | ||
Line 70: | Line 99: | ||
id=c; | id=c; | ||
} | } | ||
- | else //unknown or not something we are interested in | + | else //unknown or not something we are interested in |
{ | { | ||
state=0; | state=0; | ||
Line 84: | Line 113: | ||
if(c==ETX) | if(c==ETX) | ||
{ | { | ||
- | toggle_pin; //toggles pin D5 - flashing LED tells us gps is working | + | state=0; //end of packet |
- | if(!Gps.packetflag) //main has unlocked | + | if(id==0x6D) //the 0x6D packet is sent after a fix calculation or at 1Hz |
{ | { | ||
- | Gps.packetflag=TRUE; | + | gps.packetflag=TRUE;// |
- | Gps=gps; | + | toggle_pin; |
- | VENU=FALSE; | + | if(!Gps.packetflag) // |
+ | { | ||
+ | Gps=gps; | ||
+ | } | ||
} | } | ||
} | } | ||
Line 96: | Line 128: | ||
state=4; | state=4; | ||
} | } | ||
- | else //this shouldnt happen | + | else //this shouldnt happen |
{ | { | ||
state=0; | state=0; | ||
Line 102: | Line 134: | ||
break; | break; | ||
case 4: | case 4: | ||
- | if(c==ETX || c==DLE) //state 4 shouldnt get either of these | + | if(c==ETX || c==DLE) //state 4 shouldnt get either of these |
{ | { | ||
state=0; | state=0; | ||
} | } | ||
break; | break; | ||
- | default: //something wrong, go to 0 | + | default: //something wrong, go to 0 |
state=0; | state=0; | ||
- | } | ||
- | if(state==2 || state==4) // | ||
- | { | ||
- | if(!placemarker && id==0x6D) // | ||
- | { | ||
- | gps.status= c & 0x07; | ||
- | } | ||
- | else if(placemarker< | ||
- | { | ||
- | if(id==0x4A) | ||
- | { | ||
- | switch(placemarker) // | ||
- | { | ||
- | case 0: | ||
- | d=& | ||
- | break; | ||
- | case 4: | ||
- | d=& | ||
- | break; | ||
- | case 8: | ||
- | d=& | ||
- | break; | ||
- | default: | ||
- | } | ||
- | if(d==& | ||
- | { | ||
- | memcpy(d+placemarker,& | ||
- | } | ||
- | if(d==& | ||
- | { | ||
- | memcpy(d+placemarker-4,& | ||
- | } | ||
- | if(d==& | ||
- | { | ||
- | memcpy(d+placemarker-8,& | ||
- | } | ||
- | } | ||
- | else if(id==0x56) | ||
- | { | ||
- | switch(placemarker) | ||
- | { | ||
- | case 0: | ||
- | d=& | ||
- | break; | ||
- | case 4: | ||
- | d=& | ||
- | break; | ||
- | case 8: | ||
- | d=& | ||
- | break; | ||
- | default: | ||
- | } | ||
- | if(d==& | ||
- | { | ||
- | memcpy(d+placemarker,& | ||
- | } | ||
- | if(d==& | ||
- | { | ||
- | memcpy(d+placemarker-4,& | ||
- | } | ||
- | if(d==& | ||
- | { | ||
- | memcpy(d+placemarker-8,& | ||
- | } | ||
- | } | ||
- | } | ||
- | else if(placemarker> | ||
- | { | ||
- | state=0; | ||
- | } | ||
- | placemarker++; | ||
} | } | ||
}</ | }</ |
code/interrupt_driven_tsip.1214040414.txt.gz · Last modified: 2008/07/19 23:31 (external edit)