UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


code:interrupt_driven_tsip

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
code:interrupt_driven_tsip [2008/06/17 11:54] laurencebcode: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
 + 
 +int suart_send(char c)
 +{
 + u08 n;
 + u08 p=FALSE; //odd parity
 + CLEAR; //start bit
 + delay;
 + for(n=0;n<8;n++) //the data
 + {
 + if(c & 0x01)
 + {
 + SET; //update parity
 + p=!p;
 + }
 + else
 + {
 + CLEAR;
 + }
 + c>>=1;
 + delay;
 + }
 + if(p) //the parity
 + {
 + SET;
 + }
 + else
 + {
 + CLEAR;
 + }
 + delay;
 + SET; //stop bit
 + delay;
 + return 0;
 +}
    
 ISR(USART_RX_vect) //UART interrupt on mega xx8 series ISR(USART_RX_vect) //UART interrupt on mega xx8 series
 { {
  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; //state machine  static u08 state; //state machine
 + u08 *d=(u08*)&gps; //points to our data
  if(UCSR0A & (BV(FE0)|BV(UPE0))) //a framing or parity error causes us to drop the packet  if(UCSR0A & (BV(FE0)|BV(UPE0))) //a framing or parity error causes us to drop the packet
  {  {
Line 20: Line 56:
  }  }
  char c=UDR0;  char c=UDR0;
- switch(state)+ if(state==2 || state==4) //the two states where we can write something 
 +
 + if(!placemarker && id==0x6D) //start of packet - the status byte 
 +
 + gps.status= c & 0x0F; //number from 0 to 7, 0=undefined, 7=ground station,4 3D 
 + gps.nosats=(c & 0xF0)>>4; //number of tracked satellites 
 +
 + else if(id==0x4A) //lla(time) packet - 4 floats 
 +
 + if(placemarker<12) //lla 
 +
 + d[27-placemarker]=c; 
 +
 + if(placemarker>15 && placemarker<20) //time 
 +
 + d[31-placemarker]=c; //time of fix 
 +
 +
 + else if(id==0x56 && placemarker<12)  //enu packet - 3 floats 
 +
 + d[11-placemarker]=c; 
 +
 + else if(placemarker>27) //max 7 floats 
 +
 + state=0; //we had too much data, something is wrong 
 +
 + placemarker++; //incr placeholder 
 +
 + switch(state) //run the state machine
  {  {
  case 0:  case 0:
Line 35: 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 49: 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 we arent in one 
- if(!Gps.packetflag) //main has unlocked the data+ if(id==0x6D) //the 0x6D packet is sent after a fix calculation or at 1Hz
  {  {
- Gps.packetflag=TRUE; //this is usually the last interesting part of the fix info to come through + gps.packetflag=TRUE;//TRUE==1 
- Gps=gps; //copy into the global variable + toggle_pin; //toggles pin D5 - flashing LED tells us gps is working 
- VENU=FALSE; //dont need to run again+ if(!Gps.packetflag) //main has unlocked the data 
 +
 + Gps=gps; //copy into the global variable 
 + }
  }  }
  }  }
Line 61: Line 128:
  state=4;  state=4;
  }  }
- else //this shouldnt happen+ else //this shouldnt happen
  {  {
  state=0;  state=0;
Line 67: 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) //the two states where we can write something 
- { 
- if(!placemarker && id==0x6D) //the status byte 
- { 
- gps.status= c & 0x07; //number from 0 to 7, 0=undefined, 7=ground station,4 3D 
- } 
- else if(placemarker<12) //we only get first 3 floats 
- { 
- if(id==0x4A) 
- { 
- switch(placemarker) //we copy the UART into ram with memcpy 
- { 
- case 0: 
- d=&gps.latitude; 
- break; 
- case 4: 
- d=&gps.longitude; 
- break; 
- case 8: 
- d=&gps.altitude; 
- break; 
- default: 
- }  
- if(d==&gps.latitude) 
- { 
- memcpy(d+placemarker,&c,1); 
- } 
- if(d==&gps.longitude) 
- { 
- memcpy(d+placemarker-4,&c,1); 
- } 
- if(d==&gps.latitude) 
- { 
- memcpy(d+placemarker-8,&c,1); 
- } 
- } 
- else if(id==0x56) 
- { 
- switch(placemarker) 
- { 
- case 0: 
- d=&gps.veast; 
- break; 
- case 4: 
- d=&gps.vnorth; 
- break; 
- case 8: 
- d=&gps.vup; 
- break; 
- default: 
- }  
- if(d==&gps.veast) 
- { 
- memcpy(d+placemarker,&c,1); 
- } 
- if(d==&gps.vnorth) 
- { 
- memcpy(d+placemarker-4,&c,1); 
- } 
- if(d==&gps.vup) 
- { 
- memcpy(d+placemarker-8,&c,1); 
- } 
- } 
- } 
- else if(placemarker>27) //max 7 floats 
- { 
- state=0; //we had too much data, something is wrong 
- } 
- placemarker++; //incr placeholder 
  }  }
 }</code> }</code>
code/interrupt_driven_tsip.1213703678.txt.gz · Last modified: 2008/07/19 23:31 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki