Innomatix Support / InnomatixSupport
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Main.cpp Source File

Main.cpp

00001 /*******************************************************************
00002  *
00003  *  File: main.cpp
00004  *
00005  *  Description: Example of using Innomatix Coprocessor Support functionality
00006  *
00007  *  Copyright 2015 Innomatix, LLC., All Rights Reserved
00008  *
00009  *  THIS DOCUMENT AND ITS CONTENTS ARE INTELLECTUAL PROPERTY
00010  *  OF INNOMATIX, LLC.  ANY DUPLICATION IN PART OR WHOLE
00011  *  WITHOUT PRIOR WRITTEN CONSENT IS STRICTLY PROHIBITED.
00012  *
00013  *******************************************************************/
00014 #include "mbed.h"
00015 
00016 #include "UpdateClientAPI.h"
00017 #include "RemoteDataStoreAPI.h"
00018 #include "InnomatixCanAPI.h"
00019 #include "InnomatixMeta.h"
00020 
00021 /******************************************************************************/
00022 extern "C" void HardFault_Handler() { error("Innnomatix Coprocessor: Hard Fault!\n"); }
00023 extern "C" void mbed_reset();
00024 extern void DoExample( char *zVersion );
00025 
00026 
00027 
00028 /******************************************************************************/
00029 #define APPVERS       "1.0.7"
00030 #define APPDESC       "Coprocessor example application"
00031 
00032 // v1.0.7  Remove retry loop from SystemUpdate() in favor of letting the library
00033 //              handle timeouts.  Rework the example app to be RDS-centric so
00034 //              users do not need CAN channels wired in order to try it.
00035 // v1.0.6  initial release
00036 //=================================================================
00037 
00038 
00039 /******************************************************************************/
00040 // Create variables using the metadata macros to embed metadata the in the compiled
00041 // application.  When the application is uploaded to the InnomatixData host,
00042 // the host will scan the file and extract the metadata info.
00043 const char *VersionMeta = TFVERSION( APPVERS );
00044 char dummyV = *VersionMeta;
00045 const char *DescriptionMeta = TFDESCRIPTION( APPDESC );
00046 char dummyD = *DescriptionMeta;
00047 
00048 
00049 /******************************************************************************/
00050 // Use the LEDs to report status during system updates
00051 DigitalOut led1( LED1 );
00052 DigitalOut led2( LED2 );
00053 DigitalOut led3( LED3 );
00054 DigitalOut led4( LED4 );
00055 
00056 /*************************************************************************/
00057 void SystemUpdate()
00058 {
00059     UpdateStatus_e eUpdateResult = statusNoUpdate;
00060 
00061     // Make the file system object local to the funciton so it is cleaned
00062     // up when we exit
00063     LocalFileSystem tmpfs("local");     
00064 
00065     led1 = 1;
00066     /*====================================================================*/
00067     // UpdateInit params are not used by the MBED implementation
00068     eUpdateResult = UpdateInit( "usb", 0 );
00069     printf( "Innomatix Update API initialization: %s\r\n", (statusSuccess == eUpdateResult ? "INITIALIZED" : "FAILED") );
00070 
00071 
00072     /*====================================================================*/
00073     if( statusSuccess == eUpdateResult )
00074     {
00075         led2 = 1;
00076         printf( "Innomatix Coprocessor Checking for Firmware Update\r\n" );
00077 
00078         // The coprocessor gets to this point much quicker than the DAP
00079         // gets started and launches the coprocessor update server, we'll
00080         // wait here until he is ready.  Timeout is in milliseconds
00081         eUpdateResult = PerformUpdate( 15000 );
00082         
00083         // Go ahead and close the update library here, we're done
00084         // with it regardless of the outcome
00085         led3 = 1;
00086         UpdateClose();
00087 
00088 
00089         if( statusSuccess == eUpdateResult )
00090         {
00091             led4 = 1;
00092             printf( "    Update performed, restarting\r\n" );
00093             wait_ms( 1000 );
00094             mbed_reset();
00095 
00096         }else if( statusNoConnection == eUpdateResult )
00097         {
00098             printf( "    Update failed, no remote connection\r\n" );
00099         }else
00100         {
00101             printf( "    Update skipped, reason: (%d)%s\r\n", eUpdateResult, UpdateStatusNames[ eUpdateResult ] );
00102         }
00103     }
00104     led1 = led2 = led3 = led4 = 0;
00105 }
00106 
00107 /*************************************************************************/
00108 // Only need to define this so that we can change the baud rate
00109 // Else the default baud rate on the USB console is 9600
00110 Serial console(USBTX, USBRX);
00111 
00112 /*************************************************************************/
00113 int main()
00114 {
00115     console.baud(115200);
00116 
00117     printf( "===========================================\r\n" );
00118     printf( "Starting Coprocessor Support Example App\r\n" );
00119     printf( "Built at %s on %s\r\n", __TIME__, __DATE__ );
00120     printf( "Version: %s\r\n", APPVERS );
00121     printf( "Description: %s\r\n", APPDESC );
00122     printf( "===========================================\r\n" );
00123 
00124     SystemUpdate();
00125 
00126     DoExample( APPVERS );
00127 
00128     error( "Coprocessor exited main loop, waiting for system reset\r\n" );
00129 
00130     return( 0 );
00131 }