Official support library for using mbed as a programmable coprocessor in the Innomatix DAP-III+ telematics platform

Revision:
10:5fbe72ffb725
Parent:
8:a6311d40c5a2
--- a/Main.cpp	Fri Sep 30 17:14:01 2016 +0000
+++ b/Main.cpp	Wed Sep 06 19:17:07 2017 +0000
@@ -18,65 +18,92 @@
 #include "InnomatixCanAPI.h"
 #include "InnomatixMeta.h"
 
-#define APPVERS       "1.0.5"
+/******************************************************************************/
+extern "C" void HardFault_Handler() { error("Innnomatix Coprocessor: Hard Fault!\n"); }
+extern "C" void mbed_reset();
+extern void DoExample( char *zVersion );
+
+
+
+/******************************************************************************/
+#define APPVERS       "1.0.7"
 #define APPDESC       "Coprocessor example application"
 
+// v1.0.7  Remove retry loop from SystemUpdate() in favor of letting the library
+//              handle timeouts.  Rework the example app to be RDS-centric so
+//              users do not need CAN channels wired in order to try it.
+// v1.0.6  initial release
+//=================================================================
 
+
+/******************************************************************************/
 // Create variables using the metadata macros to embed metadata the in the compiled
 // application.  When the application is uploaded to the InnomatixData host,
 // the host will scan the file and extract the metadata info.
-const char *UserApplicationVersion = TFVERSION( APPVERS );
-const char *UserApplicationDescription = TFDESCRIPTION( APPDESC );
+const char *VersionMeta = TFVERSION( APPVERS );
+char dummyV = *VersionMeta;
+const char *DescriptionMeta = TFDESCRIPTION( APPDESC );
+char dummyD = *DescriptionMeta;
 
 
-
-extern "C" void mbed_reset();
-extern void DoExample( char *zVersion );
-
+/******************************************************************************/
+// Use the LEDs to report status during system updates
+DigitalOut led1( LED1 );
+DigitalOut led2( LED2 );
+DigitalOut led3( LED3 );
+DigitalOut led4( LED4 );
 
 /*************************************************************************/
 void SystemUpdate()
 {
 	UpdateStatus_e eUpdateResult = statusNoUpdate;
-	int count = 0;
 
+    // Make the file system object local to the funciton so it is cleaned
+    // up when we exit
+	LocalFileSystem tmpfs("local");		
+
+    led1 = 1;
     /*====================================================================*/
     // UpdateInit params are not used by the MBED implementation
     eUpdateResult = UpdateInit( "usb", 0 );
     printf( "Innomatix Update API initialization: %s\r\n", (statusSuccess == eUpdateResult ? "INITIALIZED" : "FAILED") );
 
+
     /*====================================================================*/
     if( statusSuccess == eUpdateResult )
     {
+		led2 = 1;
 		printf( "Innomatix Coprocessor Checking for Firmware Update\r\n" );
 
         // The coprocessor gets to this point much quicker than the DAP
         // gets started and launches the coprocessor update server, we'll
-        // wait here until he is ready.
-        while( count < 15 )
+        // wait here until he is ready.  Timeout is in milliseconds
+        eUpdateResult = PerformUpdate( 15000 );
+        
+        // Go ahead and close the update library here, we're done
+        // with it regardless of the outcome
+		led3 = 1;
+        UpdateClose();
+
+
+		if( statusSuccess == eUpdateResult )
         {
-            eUpdateResult = PerformUpdate( 1000 );
-            if( statusNoConnection == eUpdateResult )
-            {
-                // timeout connecting to server, try again
-                count++;
-            }else if( statusSuccess == eUpdateResult )
-            {
-                printf( "    Update performed, restarting\r\n" );
-                wait_ms( 1000 );
-                mbed_reset();
-                break;
-            }else
-            {
-                printf( "    Update skipped, reason: %s\r\n", UpdateStatusNames[ eUpdateResult ] );
-				break;
-            }
+			led4 = 1;
+            printf( "    Update performed, restarting\r\n" );
+            wait_ms( 1000 );
+            mbed_reset();
+
+        }else if( statusNoConnection == eUpdateResult )
+        {
+            printf( "    Update failed, no remote connection\r\n" );
+        }else
+        {
+            printf( "    Update skipped, reason: (%d)%s\r\n", eUpdateResult, UpdateStatusNames[ eUpdateResult ] );
         }
-        UpdateClose();
     }
+    led1 = led2 = led3 = led4 = 0;
 }
 
-
 /*************************************************************************/
 // Only need to define this so that we can change the baud rate
 // Else the default baud rate on the USB console is 9600
@@ -98,7 +125,7 @@
 
     DoExample( APPVERS );
 
-	error( "Coprocessor exited main loop, waiting to die\r\n" );
+	error( "Coprocessor exited main loop, waiting for system reset\r\n" );
 
     return( 0 );
 }