Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
231 | killagreg | 1 | #include <avr/boot.h> |
2 | |||
3 | #include <avr/io.h> |
||
4 | #include <avr/interrupt.h> |
||
5 | |||
6 | #include "main.h" |
||
7 | #include "timer0.h" |
||
8 | #include "uart0.h" |
||
9 | #include "uart1.h" |
||
10 | #include "fat16.h" |
||
11 | #include "led.h" |
||
12 | #include "menu.h" |
||
13 | #include "printf_P.h" |
||
273 | killagreg | 14 | #include "analog.h" |
274 | killagreg | 15 | #include "ubx.h" |
276 | killagreg | 16 | #include "button.h" |
231 | killagreg | 17 | |
273 | killagreg | 18 | #ifdef USE_FOLLOWME |
19 | int16_t UBat = 120; |
||
20 | #endif |
||
21 | |||
274 | killagreg | 22 | #define GPS_RX_TIMEOUT 0x0001 |
23 | |||
24 | |||
231 | killagreg | 25 | int main (void) |
26 | { |
||
274 | killagreg | 27 | static uint16_t GPS_Timer = 0; |
28 | static uint16_t Error = 0; |
||
29 | |||
231 | killagreg | 30 | // disable interrupts global |
31 | cli(); |
||
32 | |||
33 | // disable watchdog |
||
34 | MCUSR &=~(1<<WDRF); |
||
35 | WDTCSR |= (1<<WDCE)|(1<<WDE); |
||
36 | WDTCSR = 0; |
||
37 | |||
38 | // initalize modules |
||
39 | LED_Init(); |
||
271 | killagreg | 40 | LEDRED_ON; |
231 | killagreg | 41 | TIMER0_Init(); |
42 | USART0_Init(); |
||
274 | killagreg | 43 | UBX_Init(); |
231 | killagreg | 44 | USART1_Init(); |
273 | killagreg | 45 | ADC_Init(); |
276 | killagreg | 46 | Button_Init(); |
231 | killagreg | 47 | // enable interrupts global |
48 | sei(); |
||
297 | killagreg | 49 | |
271 | killagreg | 50 | LEDRED_OFF; |
51 | #ifdef USE_FOLLOWME |
||
52 | LEDGRN_ON; |
||
53 | #endif |
||
231 | killagreg | 54 | |
297 | killagreg | 55 | // try to initialize the FAT 16 filesystem on the SD-Card |
56 | Fat16_Init(); |
||
57 | |||
231 | killagreg | 58 | #ifdef USE_SDLOGGER |
297 | killagreg | 59 | printf("\r\n\r\nHW: SD-Logger"); |
231 | killagreg | 60 | #endif |
61 | #ifdef USE_FOLLOWME |
||
297 | killagreg | 62 | printf("\r\n\r\nHW: Follow-Me"); |
231 | killagreg | 63 | #endif |
297 | killagreg | 64 | printf("\r\nFollow Me\n\rSoftware:V%d.%d%c ",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a'); |
65 | printf("\r\n------------------------------"); |
||
66 | printf("\r\n"); |
||
231 | killagreg | 67 | |
68 | |||
271 | killagreg | 69 | #ifdef USE_FOLLOWME |
70 | BeepTime = 2000; |
||
71 | #endif |
||
72 | |||
231 | killagreg | 73 | LCD_Clear(); |
74 | |||
274 | killagreg | 75 | GPS_Timer = SetDelay(1000); |
231 | killagreg | 76 | while (1) |
77 | { |
||
276 | killagreg | 78 | // check for button action |
294 | killagreg | 79 | if(GetButton()) |
80 | { |
||
81 | //BeepTime = 200; |
||
297 | killagreg | 82 | Fat16_Init(); |
83 | |||
294 | killagreg | 84 | } |
276 | killagreg | 85 | |
273 | killagreg | 86 | // restart ADConversion if ready |
87 | if(ADReady) |
||
88 | { |
||
89 | DebugOut.Analog[0] = Adc0; |
||
90 | DebugOut.Analog[1] = Adc1; |
||
91 | DebugOut.Analog[2] = Adc2; |
||
92 | DebugOut.Analog[3] = Adc3; |
||
93 | DebugOut.Analog[4] = Adc4; |
||
94 | DebugOut.Analog[5] = Adc5; |
||
95 | DebugOut.Analog[6] = Adc6; |
||
96 | DebugOut.Analog[7] = Adc7; |
||
97 | |||
98 | #ifdef USE_FOLLOWME |
||
99 | // AVcc = 5V --> 5V = 1024 counts |
||
100 | // the voltage at the voltage divider reference point is 0.8V less that the UBat |
||
101 | // because of the silicon diode inbetween. |
||
284 | killagreg | 102 | // voltage divider R2=10K, R3=3K9 |
103 | // UAdc4 = R3/(R3+R2)*UBat= 3.9/(3.9+10)*UBat = UBat/3.564 |
||
104 | UBat = (3 * UBat + (64 * Adc4) / 368) / 4; |
||
273 | killagreg | 105 | DebugOut.Analog[8] = UBat; |
106 | #endif |
||
107 | ADReady = 0; |
||
274 | killagreg | 108 | ADC_Enable(); // restart ad conversion sequence |
273 | killagreg | 109 | } |
274 | killagreg | 110 | |
111 | |||
112 | if(GPSData.Status == NEWDATA) |
||
113 | { |
||
114 | Error &= ~GPS_RX_TIMEOUT; // clear possible error |
||
115 | GPS_Timer = SetDelay(1000); // reset timeout |
||
116 | if(CheckGPSOkay >= 5) |
||
117 | { |
||
118 | // trigger transmission of FollowMe message here. |
||
119 | |||
120 | CheckGPSOkay = 0; |
||
121 | } |
||
122 | GPSData.Status = PROCESSED; |
||
123 | } |
||
124 | else // invalid or already processed |
||
125 | { |
||
126 | if(CheckDelay(GPS_Timer)) |
||
127 | { |
||
128 | Error |= GPS_RX_TIMEOUT; |
||
129 | } |
||
130 | } |
||
131 | |||
132 | USART0_ProcessRxData(); |
||
133 | USART0_TransmitTxData(); |
||
231 | killagreg | 134 | } |
135 | return (1); |
||
136 | } |
||
137 |