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
00030
00031
00032
00033
00034 #include "LPC214x.h"
00035 #include "main.h"
00036 #include "system.h"
00037 #include "uart.h"
00038 #include "mymath.h"
00039 #include "hardware.h"
00040 #include "irq.h"
00041 #include "i2c.h"
00042 #include "gpsmath.h"
00043 #include "adc.h"
00044 #include "uart.h"
00045 #include "uart1.h"
00046 #include "ssp.h"
00047 #include "LL_HL_comm.h"
00048 #include "sdk.h"
00049 #include "buzzer.h"
00050 #include "ublox.h"
00051 #include "pelican_ptu.h"
00052 #include "declination.h"
00053
00054
00055
00056
00057
00058 void Initialize(void);
00059 void feed(void);
00060 void beeper(unsigned char);
00061
00062
00063
00064
00065 struct HL_STATUS HL_Status;
00066 struct IMU_CALCDATA IMU_CalcData, IMU_CalcData_tmp;
00067 struct GPS_TIME GPS_Time;
00068
00069 volatile unsigned int int_cnt=0, cnt=0, mainloop_cnt=0;
00070 volatile unsigned char mainloop_trigger=0;
00071 volatile unsigned int GPS_timeout=0;
00072 volatile unsigned int trigger_cnt=0;
00073 volatile char SYSTEM_initialized=0;
00074
00075 unsigned int uart_cnt;
00076 unsigned char DataOutputsPerSecond=10;
00077
00078
00079 void timer0ISR(void) __irq
00080 {
00081 T0IR = 0x01;
00082 IENABLE;
00083 trigger_cnt++;
00084 if(trigger_cnt==ControllerCyclesPerSecond)
00085 {
00086 trigger_cnt=0;
00087 HL_Status.up_time++;
00088 HL_Status.cpu_load=mainloop_cnt;
00089
00090 mainloop_cnt=0;
00091 }
00092
00093 if (mainloop_trigger < 10)
00094 mainloop_trigger++;
00095 timestamp += ControllerCyclesPerSecond;
00096
00097 IDISABLE;
00098 VICVectAddr = 0;
00099 }
00100
00101 void timer1ISR(void) __irq
00102 {
00103 T1IR = 0x01;
00104 IENABLE;
00105
00106 IDISABLE;
00107 VICVectAddr = 0;
00108 }
00109
00110
00111
00112
00113 int main (void) {
00114
00115 static int vbat1;
00116
00117 init();
00118 buzzer(OFF);
00119 LL_write_init();
00120 PTU_init();
00121 ADC0triggerSampling(1<<VOLTAGE_1);
00122 sdkInit();
00123
00124 HL_Status.up_time=0;
00125
00126 LED(1,ON);
00127
00128 while(1)
00129 {
00130 if(mainloop_trigger)
00131 {
00132 if(GPS_timeout<ControllerCyclesPerSecond) GPS_timeout++;
00133 else if(GPS_timeout==ControllerCyclesPerSecond)
00134 {
00135 GPS_timeout=ControllerCyclesPerSecond+1;
00136 GPS_Data.status=0;
00137 GPS_Data.numSV=0;
00138 }
00139
00140
00141 ADC0getSamplingResults(0xFF,adcChannelValues);
00142 vbat1=(vbat1*14+(adcChannelValues[VOLTAGE_1]*9872/579))/15;
00143
00144 HL_Status.battery_voltage_1=vbat1;
00145 mainloop_cnt++;
00146 if(!(mainloop_cnt%10)) buzzer_handler(HL_Status.battery_voltage_1, hli_config.battery_warning_voltage);
00147
00148 if(mainloop_trigger) mainloop_trigger--;
00149 mainloop();
00150 }
00151 }
00152 return 0;
00153 }
00154
00155
00156 void mainloop(void)
00157 {
00158 static unsigned char led_cnt=0, led_state=1;
00159
00160
00161 led_cnt++;
00162 if((GPS_Data.status&0xFF)==0x03)
00163 {
00164 LED(0,OFF);
00165 }
00166 else
00167 {
00168 if(led_cnt==150)
00169 {
00170 LED(0,ON);
00171 }
00172 else if(led_cnt==200)
00173 {
00174 led_cnt=0;
00175 LED(0,OFF);
00176 }
00177 }
00178
00179
00180 if (SYSTEM_initialized)
00181 {
00182 if ((!declinationAvailable) && (GPS_Data.horizontal_accuracy<10000) && ((GPS_Data.status&0x03)==0x03))
00183 {
00184 int status;
00185 estimatedDeclination=getDeclination(GPS_Data.latitude,GPS_Data.longitude,GPS_Data.height/1000,2012,&status);
00186 if (estimatedDeclination<-32000) estimatedDeclination=-32000;
00187 if (estimatedDeclination>32000) estimatedDeclination=32000;
00188 declinationAvailable=1;
00189 }
00190 }
00191
00192
00193 if (gpsLEDTrigger)
00194 {
00195 if(led_state)
00196 {
00197 led_state=0;
00198 LED(1,OFF);
00199 }
00200 else
00201 {
00202 LED(1,ON);
00203 led_state=1;
00204 }
00205
00206 RO_ALL_Data.GPS_height=GPS_Data.height;
00207 RO_ALL_Data.GPS_latitude=GPS_Data.latitude;
00208 RO_ALL_Data.GPS_longitude=GPS_Data.longitude;
00209 RO_ALL_Data.GPS_speed_x=GPS_Data.speed_x;
00210 RO_ALL_Data.GPS_speed_y=GPS_Data.speed_y;
00211 RO_ALL_Data.GPS_status=GPS_Data.status;
00212 RO_ALL_Data.GPS_sat_num=GPS_Data.numSV;
00213 RO_ALL_Data.GPS_week=GPS_Time.week;
00214 RO_ALL_Data.GPS_time_of_week=GPS_Time.time_of_week;
00215 RO_ALL_Data.GPS_heading=GPS_Data.heading;
00216 RO_ALL_Data.GPS_position_accuracy=GPS_Data.horizontal_accuracy;
00217 RO_ALL_Data.GPS_speed_accuracy=GPS_Data.speed_accuracy;
00218 RO_ALL_Data.GPS_height_accuracy=GPS_Data.vertical_accuracy;
00219
00220 gpsLEDTrigger=0;
00221 }
00222
00223
00224 uBloxReceiveEngine();
00225
00226
00227 SDK_mainloop();
00228
00229
00230 HL2LL_write_cycle();
00231
00232
00233 PTU_update();
00234
00235
00236 }
00237
00238