Official support library for using mbed as a programmable coprocessor in the Innomatix DAP-III+ telematics platform
Main.cpp@1:c7920c8bc557, 2016-04-17 (annotated)
- Committer:
- Innomatix
- Date:
- Sun Apr 17 15:49:58 2016 +0000
- Revision:
- 1:c7920c8bc557
- Parent:
- 0:b9e1003fbee7
- Child:
- 4:fd93c4cb05df
v1.0.3 Fix problem in USB layer which prevents opening the port a second time and thus Remote DataStore doesnt connect after SystemUpdate has run.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Innomatix | 0:b9e1003fbee7 | 1 | /******************************************************************* |
Innomatix | 0:b9e1003fbee7 | 2 | * |
Innomatix | 0:b9e1003fbee7 | 3 | * File: main.cpp |
Innomatix | 0:b9e1003fbee7 | 4 | * |
Innomatix | 0:b9e1003fbee7 | 5 | * Description: Example of using Innomatix Coprocessor Support functionality |
Innomatix | 0:b9e1003fbee7 | 6 | * |
Innomatix | 0:b9e1003fbee7 | 7 | * Copyright 2015 Innomatix, LLC., All Rights Reserved |
Innomatix | 0:b9e1003fbee7 | 8 | * |
Innomatix | 0:b9e1003fbee7 | 9 | * THIS DOCUMENT AND ITS CONTENTS ARE INTELLECTUAL PROPERTY |
Innomatix | 0:b9e1003fbee7 | 10 | * OF INNOMATIX, LLC. ANY DUPLICATION IN PART OR WHOLE |
Innomatix | 0:b9e1003fbee7 | 11 | * WITHOUT PRIOR WRITTEN CONSENT IS STRICTLY PROHIBITED. |
Innomatix | 0:b9e1003fbee7 | 12 | * |
Innomatix | 0:b9e1003fbee7 | 13 | *******************************************************************/ |
Innomatix | 0:b9e1003fbee7 | 14 | #include "mbed.h" |
Innomatix | 0:b9e1003fbee7 | 15 | |
Innomatix | 0:b9e1003fbee7 | 16 | #include "UpdateClientAPI.h" |
Innomatix | 0:b9e1003fbee7 | 17 | #include "RemoteDataStoreAPI.h" |
Innomatix | 0:b9e1003fbee7 | 18 | #include "InnomatixCanAPI.h" |
Innomatix | 0:b9e1003fbee7 | 19 | #include "InnomatixMeta.h" |
Innomatix | 0:b9e1003fbee7 | 20 | |
Innomatix | 1:c7920c8bc557 | 21 | #define APPVERS "1.0.3" |
Innomatix | 0:b9e1003fbee7 | 22 | #define APPDESC "Coprocessor example application" |
Innomatix | 0:b9e1003fbee7 | 23 | |
Innomatix | 0:b9e1003fbee7 | 24 | |
Innomatix | 0:b9e1003fbee7 | 25 | // Create variables using the metadata macros to embed metadata the in the compiled |
Innomatix | 0:b9e1003fbee7 | 26 | // application. When the application is uploaded to the InnomatixData host, |
Innomatix | 0:b9e1003fbee7 | 27 | // the host will scan the file and extract the metadata info. |
Innomatix | 0:b9e1003fbee7 | 28 | const char *UserApplicationVersion = TFVERSION( APPVERS ); |
Innomatix | 0:b9e1003fbee7 | 29 | const char *UserApplicationDescription = TFDESCRIPTION( APPDESC ); |
Innomatix | 0:b9e1003fbee7 | 30 | |
Innomatix | 0:b9e1003fbee7 | 31 | |
Innomatix | 0:b9e1003fbee7 | 32 | |
Innomatix | 0:b9e1003fbee7 | 33 | extern "C" void mbed_reset(); |
Innomatix | 0:b9e1003fbee7 | 34 | extern void DoExample( char *zVersion ); |
Innomatix | 0:b9e1003fbee7 | 35 | |
Innomatix | 0:b9e1003fbee7 | 36 | |
Innomatix | 0:b9e1003fbee7 | 37 | /*************************************************************************/ |
Innomatix | 0:b9e1003fbee7 | 38 | void SystemUpdate() |
Innomatix | 0:b9e1003fbee7 | 39 | { |
Innomatix | 0:b9e1003fbee7 | 40 | UpdateStatus_e eUpdateResult = statusNoUpdate; |
Innomatix | 0:b9e1003fbee7 | 41 | int count = 0; |
Innomatix | 0:b9e1003fbee7 | 42 | |
Innomatix | 0:b9e1003fbee7 | 43 | /*====================================================================*/ |
Innomatix | 0:b9e1003fbee7 | 44 | // UpdateInit params are not used by the MBED implementation |
Innomatix | 0:b9e1003fbee7 | 45 | eUpdateResult = UpdateInit( "usb", 0 ); |
Innomatix | 0:b9e1003fbee7 | 46 | printf( "Innomatix Update API initialization: %s\r\n", (statusSuccess == eUpdateResult ? "INITIALIZED" : "FAILED") ); |
Innomatix | 0:b9e1003fbee7 | 47 | |
Innomatix | 0:b9e1003fbee7 | 48 | /*====================================================================*/ |
Innomatix | 0:b9e1003fbee7 | 49 | if( statusSuccess == eUpdateResult ) |
Innomatix | 0:b9e1003fbee7 | 50 | { |
Innomatix | 0:b9e1003fbee7 | 51 | printf( "Innomatix Coprocessor Checking for Firmware Update\r\n" ); |
Innomatix | 0:b9e1003fbee7 | 52 | |
Innomatix | 0:b9e1003fbee7 | 53 | // The coprocessor gets to this point much quicker than the DAP |
Innomatix | 0:b9e1003fbee7 | 54 | // gets started and launches the coprocessor update server, we'll |
Innomatix | 0:b9e1003fbee7 | 55 | // wait here until he is ready. |
Innomatix | 0:b9e1003fbee7 | 56 | while( count < 15 ) |
Innomatix | 0:b9e1003fbee7 | 57 | { |
Innomatix | 0:b9e1003fbee7 | 58 | eUpdateResult = PerformUpdate( 1000 ); |
Innomatix | 0:b9e1003fbee7 | 59 | if( statusNoConnection == eUpdateResult ) |
Innomatix | 0:b9e1003fbee7 | 60 | { |
Innomatix | 0:b9e1003fbee7 | 61 | // timeout connecting to server, try again |
Innomatix | 0:b9e1003fbee7 | 62 | count++; |
Innomatix | 0:b9e1003fbee7 | 63 | }else if( statusSuccess == eUpdateResult ) |
Innomatix | 0:b9e1003fbee7 | 64 | { |
Innomatix | 0:b9e1003fbee7 | 65 | printf( " Update performed, restarting\r\n" ); |
Innomatix | 0:b9e1003fbee7 | 66 | wait_ms( 1000 ); |
Innomatix | 0:b9e1003fbee7 | 67 | mbed_reset(); |
Innomatix | 0:b9e1003fbee7 | 68 | break; |
Innomatix | 0:b9e1003fbee7 | 69 | }else |
Innomatix | 0:b9e1003fbee7 | 70 | { |
Innomatix | 0:b9e1003fbee7 | 71 | printf( " Update skipped, reason: %s\r\n", UpdateStatusNames[ eUpdateResult ] ); |
Innomatix | 0:b9e1003fbee7 | 72 | break; |
Innomatix | 0:b9e1003fbee7 | 73 | } |
Innomatix | 0:b9e1003fbee7 | 74 | } |
Innomatix | 0:b9e1003fbee7 | 75 | UpdateClose(); |
Innomatix | 0:b9e1003fbee7 | 76 | } |
Innomatix | 0:b9e1003fbee7 | 77 | } |
Innomatix | 0:b9e1003fbee7 | 78 | |
Innomatix | 0:b9e1003fbee7 | 79 | |
Innomatix | 0:b9e1003fbee7 | 80 | /*************************************************************************/ |
Innomatix | 0:b9e1003fbee7 | 81 | // Only need to define this so that we can change the baud rate |
Innomatix | 0:b9e1003fbee7 | 82 | // Else the default baud rate on the USB console is 9600 |
Innomatix | 0:b9e1003fbee7 | 83 | Serial console(USBTX, USBRX); |
Innomatix | 0:b9e1003fbee7 | 84 | |
Innomatix | 0:b9e1003fbee7 | 85 | /*************************************************************************/ |
Innomatix | 0:b9e1003fbee7 | 86 | int main() |
Innomatix | 0:b9e1003fbee7 | 87 | { |
Innomatix | 0:b9e1003fbee7 | 88 | char str[ 128 ] = {0}; |
Innomatix | 0:b9e1003fbee7 | 89 | int count = 0; |
Innomatix | 0:b9e1003fbee7 | 90 | |
Innomatix | 0:b9e1003fbee7 | 91 | console.baud(115200); |
Innomatix | 0:b9e1003fbee7 | 92 | |
Innomatix | 0:b9e1003fbee7 | 93 | printf( "===========================================\r\n" ); |
Innomatix | 0:b9e1003fbee7 | 94 | printf( "Starting Coprocessor Support Example App\r\n" ); |
Innomatix | 0:b9e1003fbee7 | 95 | printf( "Built at %s on %s\r\n", __TIME__, __DATE__ ); |
Innomatix | 0:b9e1003fbee7 | 96 | printf( "Version: %s\r\n", APPVERS ); |
Innomatix | 0:b9e1003fbee7 | 97 | printf( "Description: %s\r\n", APPDESC ); |
Innomatix | 0:b9e1003fbee7 | 98 | printf( "===========================================\r\n" ); |
Innomatix | 0:b9e1003fbee7 | 99 | |
Innomatix | 0:b9e1003fbee7 | 100 | SystemUpdate(); |
Innomatix | 0:b9e1003fbee7 | 101 | |
Innomatix | 0:b9e1003fbee7 | 102 | DoExample( APPVERS ); |
Innomatix | 0:b9e1003fbee7 | 103 | |
Innomatix | 0:b9e1003fbee7 | 104 | error( "Coprocessor exited main loop, waiting to die\r\n" ); |
Innomatix | 0:b9e1003fbee7 | 105 | |
Innomatix | 0:b9e1003fbee7 | 106 | return( 0 ); |
Innomatix | 0:b9e1003fbee7 | 107 | } |