New work version with additional functions

Dependencies:   4DGL-UC ConfigFile MODSERIAL mbed mbos

Fork of CDU_Mbed_35 by Engravity-CDU

Revision:
20:2d6ac4577e68
Parent:
17:b3545e9d38f7
--- a/main.cpp	Thu Aug 28 14:39:32 2014 +0000
+++ b/main.cpp	Wed Oct 08 14:14:52 2014 +0000
@@ -8,20 +8,23 @@
 #include "mbos.h"
 #include "mbos_def2.h"   // : Mbos tasks, timer and resource definitions
 #include "pins.h"
+#include "main.h"
 
 // Setup USB communication defined by Mbed USB TX and RX lines
 // with TX and RX ringbuffers :
-MODSERIAL USB(USBTX, USBRX, 256, 1024);
+MODSERIAL USB(USBTX, USBRX, 256, 1024);    //256, 1024
 DigitalOut alive_led( HEARTBEAT ); // : LED 1 on Mbed board toggles when CDU is alive
-
-//void test_update_flags(); // << for testing only << !!!!!!!
+DigitalOut PWR_led( PWR_ON );      // : LED 4 on Mbed board is ON when external power applied to board
+InterruptIn PWR_MON( PWR_IN );     // : Power monitor: input is connected to +5V and indirect to +12V
+ 
+ //void test_update_flags(); // << for testing only << !!!!!!!
 
 // --- Debug only ----------------------------------------
 // extra serial port to show debug info :
   MODSERIAL SERIAL_DEBUG(MODSERIAL_TX, MODSERIAL_RX, 512, 64);  //: tx, rx
 // -------------------------------------------------------
 
-int CDU_FS_interface = 0;   // : defines interface to FS: 0 = USB, 1 = Ethernet
+int CDU_FS_interface = Serial_USB;   // : defines interface to FS: 0 = Serial_USB, 1 = Ethernet
 extern int key_hit_ID;
 extern PwmOut BGL_LED;
 
@@ -50,10 +53,17 @@
 void CDU_InitDisplay(void);
 void CDU_ScreenAlign(void);
 void CDU_StartScreen(void);
+void CDU_LogoScreen(void);
+void CDU_Waiting(void);
 void CDU_Page(void);
 void CDU_DSP_CSS(void);
 void CDU_displayclear(void);
 
+void CDU_Screens();
+
+void CDU_BOOT();    //reboot CDU
+
+
 //------ USB buffer overflow interrupt handling: -------------
 void rx_buf_overflow(MODSERIAL_IRQ_INFO *q)
 {   // This functiom will be called when RX buffer overflows.
@@ -78,22 +88,51 @@
     USB.attach(&tx_buf_overflow, MODSERIAL::TxOvIrq); // : attach function to call when USB TX buffer overflows
 }
 
+char CheckExtPower()
+{
+    char ExtPower =0;
+    ExtPower = PWR_MON; //check on power input: if +5V is ON return 1 else 0
+    //PWR_led  = ExtPower;
+    return ExtPower;
+}
+
+void EXT_PWR_DN()
+{
+    //external power failed, reboot CDU!
+    CDU_BOOT();
+}
+
+
+
 main() // : MBOS main() 
 {
+    /* Check for a valid external power flag during boot sequence
+       When no external power is applied the VGA board and Keyboard chip are not operational
+       After initialization disconnecting external power will trigger interrupt to reboot.
+    */  
+    
+    PWR_MON.mode( PullDown );    //create a solid 0 when no external power supplied
+    while (! CheckExtPower() );  //wait for external power to come up
+    PWR_led = PWR_MON ;          //switch on LED for external power indicator
+    PWR_MON.fall(&EXT_PWR_DN);   //Bind function to handle interrupt when external power fails
+    
     init_USB();  // : setup USB communication to FS
      
-    // CDU keyboard initialisation and keyboard interrrupt setup:
+    // CDU keyboard initialisation and keyboard interrupt setup:
     CDU_KB_COMM_INIT();
     CDU_KB_INT_START();
     BGL_LED.period(0.01);
     
     // CDU display initialisation:
     CDU_InitDisplay();
-    CDU_StartScreen();
-    wait(0.2);
+    //CDU_StartScreen();
+    //CDU_LogoScreen();
+    wait(2);
+    //CDU_Screens();
+    CDU_Waiting();
     //CDU_Page();
-    CDU_ScreenAlign();
-            
+    //CDU_ScreenAlign();
+    //        
     set_initial_data(); //: fill FS datastructures with initial data
 
     // -- debug only -------------------------------------