Prof Greg Egan / Mbed 2 deprecated UAVXArm-GKE

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers harness.c Source File

harness.c

00001 // ===============================================================================================
00002 // =                              UAVXArm Quadrocopter Controller                                =
00003 // =                           Copyright (c) 2008 by Prof. Greg Egan                             =
00004 // =                 Original V3.15 Copyright (c) 2007 Ing. Wolfgang Mahringer                   =
00005 // =                           http://code.google.com/p/uavp-mods/                               =
00006 // ===============================================================================================
00007 
00008 //    This is part of UAVXArm.
00009 
00010 //    UAVXArm is free software: you can redistribute it and/or modify it under the terms of the GNU
00011 //    General Public License as published by the Free Software Foundation, either version 3 of the
00012 //    License, or (at your option) any later version.
00013 
00014 //    UAVXArm is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without
00015 //    even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00016 //    See the GNU General Public License for more details.
00017 
00018 //    You should have received a copy of the GNU General Public License along with this program.
00019 //    If not, see http://www.gnu.org/licenses/
00020 
00021 #include "UAVXArm.h"
00022 
00023 void UpdateRTC(void);
00024 void InitHarness(void);
00025 
00026 LocalFileSystem Flash("local");
00027 
00028 const uint8 mbed1768Pins[32] = { // Maping of mbed pins to LPC 1768 "port" pins
00029     255,255,255,255,255,9,8,7,6,0,
00030     1,18,17,15,16,23,24,25,26,62,
00031     63,69,68,67,66,65,64,11,10,5,
00032     4,255
00033 };
00034 
00035 /*
00036 const uint32 mbed1768Ports[8] = { 
00037     LPC_GPIO0_BASE,
00038     LPC_GPIO1_BASE,
00039     LPC_GPIO2_BASE,
00040     LPC_GPIO3_BASE,
00041     LPC_GPIO4_BASE
00042 };
00043 */
00044 
00045 // connections to ARM
00046 // 1 GND
00047 // 2 4.5-9V
00048 // 3 VBat
00049 // 4 NReset
00050 
00051 //SPI SPI0(p5, p6, p7);                 // 5 SPI MOSI, 6 SPI MOSO, 7 SPI CLK
00052 //DigitalOut SPICS(p8);                 // 8
00053 SDFileSystem SDCard(p5, p6, p7, p8, "SDCard");
00054 
00055 //I2C I2C1(p9, p10);                    // 9 Tx / I2C SDA, 10 Rx / I2C SCL
00056 SerialBuffered TelemetrySerial(p9, p10);
00057 DigitalIn Armed(p11);                   // 11 SPI MOSI
00058 DigitalOut PWMCamPitch(p12);            // 12 SPI MOSO
00059 
00060 Serial GPSSerial(p13, p14);             // 13 Tx1 / SPI CLK, 14 Rx1
00061 
00062 AnalogIn PitchADC(p15);                 // 15 AN0
00063 AnalogIn RollADC(p16);                  // 16 AN1
00064 AnalogIn YawADC(p18);                   // 17 AN2 (has DAC capability)
00065 
00066 AnalogIn RangefinderADC(p17);           // 18 AN3
00067 AnalogIn BatteryCurrentADC(p19);        // 19 AN4
00068 AnalogIn BatteryVoltsADC(p20);          // 20 AN5
00069 
00070 PwmOut Out0(p21);                       // 21
00071 PwmOut Out1(p22);                       // 22
00072 PwmOut Out2(p23);                       // 23
00073 PwmOut Out3(p24);                       // 24
00074 
00075 //PwmOut Out4(p25);                       // 25
00076 //PwmOut Out5(p26);                       // 26
00077 
00078 DigitalOut DebugPin(p25);                  // 25
00079 
00080 #ifdef SW_I2C
00081 
00082 MyI2C I2C0;
00083 
00084 #define I2C0SDASet (1<<mbed1768Pins[28&0x1f]) // 10
00085 #define I2C0SDAPort (mbed1768Pins[28&0x0f]>>5)
00086 PortInOut I2C0SDA(Port0, I2C0SDASet );
00087 
00088 #define I2C0SCLSet (1<<mbed1768Pins[27&0x1f]) // 11
00089 #define I2C0SCLPort (mbed1768Pins[27&0x0f]>>5)
00090 PortInOut I2C0SCL(Port0, I2C0SCLSet );
00091 
00092 #else
00093 
00094 I2C I2C0(p28, p27);                     // 27, 28
00095 
00096 #endif // SW_I2C
00097 
00098 DigitalIn RCIn(p29);                    // 29 CAN
00099 DigitalOut PWMCamRoll(p30);             // 30 CAN
00100 
00101 //Serial TelemetrySerial(USBTX, USBRX);
00102 // 31 USB +, 32 USB -
00103 // 34 -37 Ethernet
00104 // 38 IF +
00105 // 39 IF -
00106 // 40 3.3V Out
00107 
00108 // order L-R end of card
00109 DigitalOut BlueLED(LED1);
00110 DigitalOut GreenLED(LED2);
00111 DigitalOut RedLED(LED3);
00112 DigitalOut YellowLED(LED4);
00113 
00114 InterruptIn RCInterrupt(p29);
00115 
00116 char RTCString[32], RTCLogfile[32];
00117 struct tm* RTCTime;
00118 
00119 void UpdateRTC(void) {
00120     time_t s = time(NULL);
00121     RTCTime = localtime(&s);
00122     strftime(RTCString, 32, "%a %b %d %H:%M:%S %Y", RTCTime );
00123 } // UpdateRTCString
00124 
00125 void InitHarness(void) {
00126 
00127     I2C0.frequency(I2C_MAX_RATE_HZ);
00128 
00129     TelemetrySerial.baud(115200);
00130     TelemetrySerial.set_tx_buffer_size(512);
00131 
00132     GPSSerial.baud(115200); // reduce baud rate to lighten interrupt traffic?
00133 
00134     PWMCamRoll.write(false);
00135     PWMCamPitch.write(false);
00136 
00137     Armed.mode(PullUp);
00138 
00139     CheckSDCardValid();
00140 
00141     UpdateRTC();
00142 
00143 } // InitHarness