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

Committer:
Innomatix
Date:
Wed Sep 06 19:17:07 2017 +0000
Revision:
10:5fbe72ffb725
Parent:
8:a6311d40c5a2
Innomatix Support Library v1.0.7

Who changed what in which revision?

UserRevisionLine numberNew 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 10:5fbe72ffb725 21 /******************************************************************************/
Innomatix 10:5fbe72ffb725 22 extern "C" void HardFault_Handler() { error("Innnomatix Coprocessor: Hard Fault!\n"); }
Innomatix 10:5fbe72ffb725 23 extern "C" void mbed_reset();
Innomatix 10:5fbe72ffb725 24 extern void DoExample( char *zVersion );
Innomatix 10:5fbe72ffb725 25
Innomatix 10:5fbe72ffb725 26
Innomatix 10:5fbe72ffb725 27
Innomatix 10:5fbe72ffb725 28 /******************************************************************************/
Innomatix 10:5fbe72ffb725 29 #define APPVERS "1.0.7"
Innomatix 0:b9e1003fbee7 30 #define APPDESC "Coprocessor example application"
Innomatix 0:b9e1003fbee7 31
Innomatix 10:5fbe72ffb725 32 // v1.0.7 Remove retry loop from SystemUpdate() in favor of letting the library
Innomatix 10:5fbe72ffb725 33 // handle timeouts. Rework the example app to be RDS-centric so
Innomatix 10:5fbe72ffb725 34 // users do not need CAN channels wired in order to try it.
Innomatix 10:5fbe72ffb725 35 // v1.0.6 initial release
Innomatix 10:5fbe72ffb725 36 //=================================================================
Innomatix 0:b9e1003fbee7 37
Innomatix 10:5fbe72ffb725 38
Innomatix 10:5fbe72ffb725 39 /******************************************************************************/
Innomatix 0:b9e1003fbee7 40 // Create variables using the metadata macros to embed metadata the in the compiled
Innomatix 0:b9e1003fbee7 41 // application. When the application is uploaded to the InnomatixData host,
Innomatix 0:b9e1003fbee7 42 // the host will scan the file and extract the metadata info.
Innomatix 10:5fbe72ffb725 43 const char *VersionMeta = TFVERSION( APPVERS );
Innomatix 10:5fbe72ffb725 44 char dummyV = *VersionMeta;
Innomatix 10:5fbe72ffb725 45 const char *DescriptionMeta = TFDESCRIPTION( APPDESC );
Innomatix 10:5fbe72ffb725 46 char dummyD = *DescriptionMeta;
Innomatix 0:b9e1003fbee7 47
Innomatix 0:b9e1003fbee7 48
Innomatix 10:5fbe72ffb725 49 /******************************************************************************/
Innomatix 10:5fbe72ffb725 50 // Use the LEDs to report status during system updates
Innomatix 10:5fbe72ffb725 51 DigitalOut led1( LED1 );
Innomatix 10:5fbe72ffb725 52 DigitalOut led2( LED2 );
Innomatix 10:5fbe72ffb725 53 DigitalOut led3( LED3 );
Innomatix 10:5fbe72ffb725 54 DigitalOut led4( LED4 );
Innomatix 0:b9e1003fbee7 55
Innomatix 0:b9e1003fbee7 56 /*************************************************************************/
Innomatix 0:b9e1003fbee7 57 void SystemUpdate()
Innomatix 0:b9e1003fbee7 58 {
Innomatix 0:b9e1003fbee7 59 UpdateStatus_e eUpdateResult = statusNoUpdate;
Innomatix 0:b9e1003fbee7 60
Innomatix 10:5fbe72ffb725 61 // Make the file system object local to the funciton so it is cleaned
Innomatix 10:5fbe72ffb725 62 // up when we exit
Innomatix 10:5fbe72ffb725 63 LocalFileSystem tmpfs("local");
Innomatix 10:5fbe72ffb725 64
Innomatix 10:5fbe72ffb725 65 led1 = 1;
Innomatix 0:b9e1003fbee7 66 /*====================================================================*/
Innomatix 0:b9e1003fbee7 67 // UpdateInit params are not used by the MBED implementation
Innomatix 0:b9e1003fbee7 68 eUpdateResult = UpdateInit( "usb", 0 );
Innomatix 0:b9e1003fbee7 69 printf( "Innomatix Update API initialization: %s\r\n", (statusSuccess == eUpdateResult ? "INITIALIZED" : "FAILED") );
Innomatix 0:b9e1003fbee7 70
Innomatix 10:5fbe72ffb725 71
Innomatix 0:b9e1003fbee7 72 /*====================================================================*/
Innomatix 0:b9e1003fbee7 73 if( statusSuccess == eUpdateResult )
Innomatix 0:b9e1003fbee7 74 {
Innomatix 10:5fbe72ffb725 75 led2 = 1;
Innomatix 0:b9e1003fbee7 76 printf( "Innomatix Coprocessor Checking for Firmware Update\r\n" );
Innomatix 0:b9e1003fbee7 77
Innomatix 0:b9e1003fbee7 78 // The coprocessor gets to this point much quicker than the DAP
Innomatix 0:b9e1003fbee7 79 // gets started and launches the coprocessor update server, we'll
Innomatix 10:5fbe72ffb725 80 // wait here until he is ready. Timeout is in milliseconds
Innomatix 10:5fbe72ffb725 81 eUpdateResult = PerformUpdate( 15000 );
Innomatix 10:5fbe72ffb725 82
Innomatix 10:5fbe72ffb725 83 // Go ahead and close the update library here, we're done
Innomatix 10:5fbe72ffb725 84 // with it regardless of the outcome
Innomatix 10:5fbe72ffb725 85 led3 = 1;
Innomatix 10:5fbe72ffb725 86 UpdateClose();
Innomatix 10:5fbe72ffb725 87
Innomatix 10:5fbe72ffb725 88
Innomatix 10:5fbe72ffb725 89 if( statusSuccess == eUpdateResult )
Innomatix 0:b9e1003fbee7 90 {
Innomatix 10:5fbe72ffb725 91 led4 = 1;
Innomatix 10:5fbe72ffb725 92 printf( " Update performed, restarting\r\n" );
Innomatix 10:5fbe72ffb725 93 wait_ms( 1000 );
Innomatix 10:5fbe72ffb725 94 mbed_reset();
Innomatix 10:5fbe72ffb725 95
Innomatix 10:5fbe72ffb725 96 }else if( statusNoConnection == eUpdateResult )
Innomatix 10:5fbe72ffb725 97 {
Innomatix 10:5fbe72ffb725 98 printf( " Update failed, no remote connection\r\n" );
Innomatix 10:5fbe72ffb725 99 }else
Innomatix 10:5fbe72ffb725 100 {
Innomatix 10:5fbe72ffb725 101 printf( " Update skipped, reason: (%d)%s\r\n", eUpdateResult, UpdateStatusNames[ eUpdateResult ] );
Innomatix 0:b9e1003fbee7 102 }
Innomatix 0:b9e1003fbee7 103 }
Innomatix 10:5fbe72ffb725 104 led1 = led2 = led3 = led4 = 0;
Innomatix 0:b9e1003fbee7 105 }
Innomatix 0:b9e1003fbee7 106
Innomatix 0:b9e1003fbee7 107 /*************************************************************************/
Innomatix 0:b9e1003fbee7 108 // Only need to define this so that we can change the baud rate
Innomatix 0:b9e1003fbee7 109 // Else the default baud rate on the USB console is 9600
Innomatix 0:b9e1003fbee7 110 Serial console(USBTX, USBRX);
Innomatix 0:b9e1003fbee7 111
Innomatix 0:b9e1003fbee7 112 /*************************************************************************/
Innomatix 0:b9e1003fbee7 113 int main()
Innomatix 0:b9e1003fbee7 114 {
Innomatix 0:b9e1003fbee7 115 console.baud(115200);
Innomatix 0:b9e1003fbee7 116
Innomatix 0:b9e1003fbee7 117 printf( "===========================================\r\n" );
Innomatix 0:b9e1003fbee7 118 printf( "Starting Coprocessor Support Example App\r\n" );
Innomatix 0:b9e1003fbee7 119 printf( "Built at %s on %s\r\n", __TIME__, __DATE__ );
Innomatix 0:b9e1003fbee7 120 printf( "Version: %s\r\n", APPVERS );
Innomatix 0:b9e1003fbee7 121 printf( "Description: %s\r\n", APPDESC );
Innomatix 0:b9e1003fbee7 122 printf( "===========================================\r\n" );
Innomatix 0:b9e1003fbee7 123
Innomatix 0:b9e1003fbee7 124 SystemUpdate();
Innomatix 4:fd93c4cb05df 125
Innomatix 0:b9e1003fbee7 126 DoExample( APPVERS );
Innomatix 0:b9e1003fbee7 127
Innomatix 10:5fbe72ffb725 128 error( "Coprocessor exited main loop, waiting for system reset\r\n" );
Innomatix 0:b9e1003fbee7 129
Innomatix 0:b9e1003fbee7 130 return( 0 );
Innomatix 0:b9e1003fbee7 131 }