Chris Styles / Mbed 2 deprecated aaaaa_ISPREFLASH

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "Objects.h"
00002 #include "Helper.h"
00003 #include "Tests.h"
00004 
00005 
00006 //#define AUDIO // it beeps at the end
00007 
00008 #define TEST_DELAY 0.001
00009 
00010 
00011 // ============================
00012 // Tests
00013 // The numbers are used to trigger
00014 // The test on the DUT
00015 // ============================
00016 // 1. VoltageCurrent
00017 // 2. DUTSetupTest
00018 // 3. IOTest
00019 // 4. Resettest
00020 // 5. BatteryTest
00021 // 6. EthernetTest
00022 // ============================
00023 // Assumptions
00024 // ============================
00025 // All tests run off the initial VUSB power up
00026 //    Vin test explicity fiddles the power
00027 // ============================
00028 
00029 int wibble=1;
00030 
00031 int main() {
00032 
00033    DutReset(1);
00034   
00035    
00036    char result=0;
00037    
00038    pc.printf("mbed-005.1 Production test jig\n");
00039 
00040       lcd.cls();
00041       lcd.locate(0,0);
00042       lcd.printf("Reflash jig");
00043       lcd.locate(0,1);
00044       lcd.printf("Press GREEN");
00045 
00046 
00047    DutISPConnect();
00048    
00049    wait(0.5);
00050 
00051    while (wibble) {
00052    
00053       // wait for the button to be pressed
00054       while (!gbtn) {}     
00055       // Power up 
00056       DutUsbPowerUp();
00057       wait (1.0);
00058    
00059 
00060       // wait for the button to be pressed
00061       while (!gbtn) {}     
00062       // Power down
00063       DutUsbPowerDown();
00064       wait (1.0);
00065    
00066    
00067    
00068    }
00069 
00070 
00071    while (1) {
00072        
00073        
00074        
00075        
00076        
00077       lcd.cls();
00078       lcd.locate(0,0);
00079       lcd.printf("mbed-005.1 Test");
00080       lcd.locate(0,1);
00081       lcd.printf("Press GREEN");
00082    
00083       // wait for the button to be pressed
00084       while (!gbtn) {}
00085      
00086       // Power up USB and connect
00087       DutUsbPowerUp();
00088       wait (0.1);
00089 
00090 
00091 
00092 // Connect the USB after the current test
00093 // this stops the spiking currents during enumeration from 
00094 // giving false readings
00095 //      DutUsbConnect();
00096 //      wait (0.5);
00097 
00098 
00099 // ========================
00100 // Voltage and current test
00101 // ========================
00102             
00103 
00104 
00105       lcd.locate(0,1);
00106       lcd.printf("VCTest          ");
00107       wait (TEST_DELAY);
00108 
00109       result |= VCTest ();
00110       pc.printf("VCTest 0x%x\n",result);
00111 
00112       gled=0; rled=0; wait (0.05);
00113       if (result == 0 ) {gled = 1; rled=0;} else {gled = 0; rled=1;}
00114 
00115 
00116 // ========================
00117 // Connect USB
00118 // ========================
00119 
00120       DutUsbConnect();
00121       wait (0.5);
00122                     
00123       lcd.cls();
00124       lcd.locate(0,0);
00125       lcd.printf("Copy TestDUT.bin");
00126       lcd.locate(0,1);
00127       lcd.printf("Press GREEN");
00128       wait(0.5);
00129       
00130       // wait for the button to be pressed
00131       while (!gbtn) {}   
00132     
00133       // turn off the board and USB, and power it up using VIN
00134       DutUsbPowerDown();
00135       DutUsbDisconnect();
00136       
00137       wait (0.2);
00138       DutVinPowerUp();
00139 
00140       // Turn on the VB power, this is so it can stablise
00141       DutVB(1);
00142       VBatGnd=1;
00143 
00144       // this covers the debug case when the board
00145       // remains powered by USB
00146       DUT_NR = 0;
00147       wait (0.1);
00148       DUT_NR = 1;
00149       
00150 
00151       lcd.cls();
00152       lcd.locate(0,0);
00153       lcd.printf("Waiting for DUT");
00154       
00155       
00156       // this is where the DUT power up... it will take a bunch of time
00157       // for the binary to be programmed
00158       // We should wait for a "R" to be sent by the DUT
00159 
00160       DutBufferFlush();  
00161       // wait here until 
00162       while (!Dut.readable()) {
00163           led4 = !led4;
00164           wait (0.05);
00165       }
00166         
00167       char tmp = Dut.getc();
00168 
00169       if ( tmp != 'R' ) {
00170       }
00171 
00172 
00173       // Start the test
00174       lcd.locate(0,1);
00175       lcd.printf("Testing...");
00176 
00177 
00178 
00179 
00180 //// ///////////////////////////////////////////////////////
00181 //// This is where we do the grunt work of running the tests
00182 //// ///////////////////////////////////////////////////////
00183 
00184 
00185 
00186 
00187     
00188 
00189 
00190     
00191 // ========================
00192 // Dut setup
00193 // ========================
00194     
00195       lcd.locate(0,1);
00196       lcd.printf("DutSetupTest");
00197       result |= DutSetupTest ();    
00198       pc.printf("DutSetup 0x%x\n",result);
00199       wait (TEST_DELAY);
00200 
00201       gled=0; rled=0; wait (0.05);
00202       if (result == 0 ) {gled = 1; rled=0;} else {gled = 0; rled=1;}
00203 
00204 
00205 // ========================
00206 // IO Test
00207 // ========================
00208       
00209       lcd.locate(0,1);
00210       lcd.printf("IOTest          ");
00211       result |= IOTest ();
00212       pc.printf("IOTest 0x%x\n",result);
00213       wait (TEST_DELAY);
00214 
00215       gled=0; rled=0; wait (0.05);
00216       if (result == 0 ) {gled = 1; rled=0;} else {gled = 0; rled=1;}
00217 
00218 
00219 // ========================
00220 // Reset Test
00221 // ========================
00222 
00223       lcd.cls(); lcd.locate(0,0);
00224       lcd.printf("ResetTest");
00225       result |= ResetTest ();
00226       pc.printf("ResetTest 0x%x\n",result);
00227       wait (TEST_DELAY);
00228 
00229       gled=0; rled=0; wait (0.05);
00230       if (result == 0 ) {gled = 1; rled=0;} else {gled = 0; rled=1;}
00231 
00232 
00233 // ========================
00234 // Ethernet test
00235 // ========================
00236 
00237 
00238       lcd.cls(); lcd.locate(0,0);
00239       lcd.printf("EthernetTest");
00240       result |= EthernetTest ();
00241       pc.printf("EthernetTest 0x%x\n",result);
00242       wait (TEST_DELAY);
00243 
00244       gled=0; rled=0; wait (0.05);
00245       if (result == 0 ) {gled = 1; rled=0;} else {gled = 0; rled=1;}
00246 
00247 
00248 
00249 // ========================
00250 // RTC Test
00251 // ========================
00252 
00253 
00254       lcd.cls(); lcd.locate(0,0);
00255       lcd.printf("RTC test");
00256       
00257       result |= RTCTest ();
00258       pc.printf("RTCtTest 0x%x\n",result);
00259       wait (TEST_DELAY);
00260 
00261       gled=0; rled=0; wait (0.05);
00262       if (result == 0 ) {gled = 1; rled=0;} else {gled = 0; rled=1;}
00263 
00264 
00265 
00266 
00267 // ========================
00268 // VBat Test
00269 // ========================
00270 
00271 
00272 // make sure the clock still has a sensible value
00273 
00274       lcd.cls(); lcd.locate(0,0);
00275       lcd.printf("VBat test");
00276             
00277       // Turn off all other power
00278       DutVinPowerDown();
00279       
00280       // wait for 1 second
00281       wait(0.1);
00282       
00283       // power back on
00284       DutVinPowerUp();
00285       wait (0.1);
00286 
00287       // flush the buffer (there will be an "R")
00288       DutBufferFlush();      
00289       
00290       result |= BatteryTest ();
00291       pc.printf("VBatTest 0x%x\n",result);
00292       wait (TEST_DELAY);
00293 
00294       gled=0; rled=0; wait (0.05);
00295       if (result == 0 ) {gled = 1; rled=0;} else {gled = 0; rled=1;}
00296 
00297 
00298 
00299 
00300 
00301 
00302 
00303     
00304 // ========================
00305 // Clean up
00306 // ========================
00307     
00308       lcd.cls(); lcd.locate(0,0);
00309       if (result==0) {
00310           result |= CleanUp ();
00311       }
00312 
00313 
00314 
00315       gled=0; rled=0; wait (0.05);
00316       if (result == 0 ) {gled = 1; rled=0;} else {gled = 0; rled=1;}
00317 
00318     
00319       // non-zero, Dut failed
00320       if (result) {
00321           lcd.cls(); lcd.locate(0,0);
00322           lcd.printf("Failed : 0x%x",result);   
00323           gled = 0; rled=1;
00324           lcd.locate(0,1);
00325           lcd.printf("Info in Test.log",result);   
00326 
00327 
00328 
00329           // Power up USB and connect
00330           DutUsbPowerUp();
00331           wait (0.1);
00332           DutUsbConnect();
00333           wait (0.5);
00334 
00335 
00336           #ifdef AUDIO
00337               Beep(500,0.5);
00338           #endif
00339           
00340        
00341 
00342           
00343       } else {
00344           lcd.cls(); 
00345           lcd.locate(0,0);
00346           lcd.printf("Passed! :-)");
00347 
00348           lcd.locate(0,1);
00349           lcd.printf("Press GREEN");
00350           gled = 1; rled=0;
00351           
00352           #ifdef AUDIO
00353               Beep(4000,0.5);
00354           #endif
00355       }
00356 
00357 //// ///////////////////////////////////////////////////////
00358 //// 
00359 //// ///////////////////////////////////////////////////////
00360 
00361       
00362       // wait for the button to be pressed
00363       while (!gbtn) {}
00364       wait(0.1);
00365 
00366       // Clean up for the next pass
00367       result = 0;       
00368       rled=0;
00369       gled=0;
00370       DutUsbPowerDown ();
00371       DutUsbDisconnect ();
00372       DutVinPowerDown ();
00373       DutReset (1);
00374       DutVB (0);
00375       
00376       
00377    
00378    } // end of while
00379    
00380 }  // end of main
00381 
00382 
00383 
00384 
00385 
00386 
00387 
00388 
00389 
00390 
00391 
00392 
00393 
00394 
00395 
00396 
00397 
00398 
00399 
00400