Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: freemaster_lib mbed
main.cpp
00001 #include "mbed.h" 00002 #include "freemaster_class.h" 00003 //Initialize FreeMASTER driver 00004 Freemaster fm(USBTX, USBRX); 00005 00006 //Add global variables 00007 /* Test variables, will be displayed in the FreeMASTER application */ 00008 volatile unsigned char var8; 00009 volatile unsigned short var16; 00010 volatile unsigned short var16inc = 100; 00011 volatile unsigned long var32; 00012 volatile unsigned long var32inc = 100; 00013 volatile unsigned char nAppCmdCounter; 00014 00015 /* 00016 * Test structure types - demonstrates the "TSA" feature thanks to which the 00017 * FreeMASTER is able to load a variable and type information directly from 00018 * the embedded application. 00019 * 00020 */ 00021 00022 typedef struct { 00023 00024 unsigned short aa; 00025 unsigned long bb[2]; 00026 unsigned short cc; 00027 unsigned long dd[3]; 00028 unsigned char ee; 00029 unsigned char ff[5]; 00030 } INNER_STRUCT; 00031 00032 typedef struct { 00033 00034 unsigned short a; 00035 unsigned long b; 00036 INNER_STRUCT inA[4]; 00037 INNER_STRUCT inB; 00038 } OUTER_STRUCT; 00039 00040 /* Structure type information will be available in the FreeMASTER application (TSA) */ 00041 OUTER_STRUCT so1, so2; 00042 INNER_STRUCT si1, si2; 00043 00044 /* buffer for runtime definition of the TSA table */ 00045 static unsigned long tsatable[(4*20)]; //up to 20 variables to register 00046 00047 ///////////////////////////////////////////////////////////////////////// 00048 00049 FMSTR_APPCMD_RESULT myhandler(FMSTR_APPCMD_CODE /*nAppcmd*/, FMSTR_APPCMD_PDATA /*pData*/, FMSTR_SIZE /*nDataLen*/); 00050 00051 /* 00052 * With TSA enabled, the user describes the global and static variables using 00053 * so-called TSA tables. There can be any number of tables defined in 00054 * the project files. Each table does have the identifier which should be 00055 * unique across the project. 00056 * 00057 * Note that you can declare variables as Read-Only or Read-Write. 00058 * The FreeMASTER driver denies any write access to the Read-Only variables 00059 * when TSA_SAFETY is enabled. 00060 */ 00061 00062 FMSTR_TSA_TABLE_BEGIN(first_table) 00063 FMSTR_TSA_RW_VAR(var8, FMSTR_TSA_UINT8) 00064 FMSTR_TSA_RO_VAR(var32, FMSTR_TSA_UINT32) 00065 FMSTR_TSA_RW_VAR(var32inc, FMSTR_TSA_UINT32) 00066 FMSTR_TSA_RW_VAR(so1, FMSTR_TSA_USERTYPE(OUTER_STRUCT)) 00067 FMSTR_TSA_RW_VAR(si1, FMSTR_TSA_USERTYPE(INNER_STRUCT)) 00068 00069 FMSTR_TSA_STRUCT(OUTER_STRUCT) 00070 FMSTR_TSA_MEMBER(OUTER_STRUCT, a, FMSTR_TSA_UINT16) 00071 FMSTR_TSA_MEMBER(OUTER_STRUCT, b, FMSTR_TSA_UINT32) 00072 FMSTR_TSA_MEMBER(OUTER_STRUCT, inA, FMSTR_TSA_USERTYPE(INNER_STRUCT)) 00073 FMSTR_TSA_MEMBER(OUTER_STRUCT, inB, FMSTR_TSA_USERTYPE(INNER_STRUCT)) 00074 00075 FMSTR_TSA_STRUCT(INNER_STRUCT) 00076 FMSTR_TSA_MEMBER(INNER_STRUCT, aa, FMSTR_TSA_UINT16) 00077 FMSTR_TSA_MEMBER(INNER_STRUCT, bb, FMSTR_TSA_UINT32) 00078 FMSTR_TSA_MEMBER(INNER_STRUCT, cc, FMSTR_TSA_SINT16) 00079 FMSTR_TSA_MEMBER(INNER_STRUCT, dd, FMSTR_TSA_SINT32) 00080 FMSTR_TSA_MEMBER(INNER_STRUCT, ee, FMSTR_TSA_UINT8) 00081 FMSTR_TSA_MEMBER(INNER_STRUCT, ff, FMSTR_TSA_SINT8) 00082 FMSTR_TSA_TABLE_END() 00083 00084 /* 00085 * This is an example of another TSA table. Typically, you put one table 00086 * to each .c file where your global or static variables are instantiated. 00087 */ 00088 00089 FMSTR_TSA_TABLE_BEGIN(next_table) 00090 FMSTR_TSA_RO_VAR(so2, FMSTR_TSA_USERTYPE(OUTER_STRUCT)) 00091 FMSTR_TSA_RO_VAR(si2, FMSTR_TSA_USERTYPE(INNER_STRUCT)) 00092 FMSTR_TSA_TABLE_END() 00093 00094 //Registration of all variables to observe in the FreeMASTER tool 00095 FMSTR_TSA_TABLE_LIST_BEGIN() 00096 //Register all TSA tables 00097 FMSTR_TSA_TABLE(first_table) 00098 FMSTR_TSA_TABLE(next_table) 00099 FMSTR_TSA_TABLE_LIST_END() 00100 00101 /* 00102 * This function is registerred as a application command handler (see 00103 * main() below. It gets automatically invoked when the FreeMASTER 00104 * application sends appropriate application command. 00105 * 00106 */ 00107 00108 FMSTR_APPCMD_RESULT myhandler(FMSTR_APPCMD_CODE nAppcmd, FMSTR_APPCMD_PDATA pData, FMSTR_SIZE nDataLen) 00109 { 00110 // the return value is used as the application command result code 00111 return 0x10; 00112 } 00113 00114 00115 int main() { 00116 //change baudrate to 9600 00117 fm.baud(9600); 00118 //register global or static variables to FreeMASTER driver 00119 fm.TsaAddVar(FMSTR_TSA_RW_VAR_CFG(var16inc,FMSTR_TSA_UINT16)); 00120 //register read only variable to FreeMASTER driver 00121 fm.TsaAddVar(FMSTR_TSA_RO_VAR_CFG(var16,FMSTR_TSA_UINT8)); 00122 00123 while(1) { 00124 //execute demo code 00125 unsigned short nAppCmdCode; 00126 // scope variables 00127 var16 += var16inc; 00128 var32 += var32inc; 00129 00130 // the application commands not registered with callback handlers 00131 // can be detected and processed using the API calls below 00132 00133 // first, check if a new command has been received 00134 nAppCmdCode = fm.GetAppCmd(); 00135 00136 // when a new command arrives, the nAppCmdCode contains the application 00137 // command code. In other case, the "NOCMD" special value is returned 00138 if (nAppCmdCode != FMSTR_APPCMDRESULT_NOCMD) 00139 { 00140 nAppCmdCounter++; 00141 00142 // each command may have different processing and different 00143 // result code. The command processing is finished by 00144 // calling FMSTR_AppCmdAck() with the result code value 00145 switch(nAppCmdCode) 00146 { 00147 case 1: fm.AppCmdAck(var8); break; 00148 case 2: fm.AppCmdAck((unsigned char) ~var8); break; 00149 default: fm.AppCmdAck(0); break; 00150 } 00151 } 00152 00153 // This call should be placed in the timer interrupt or anywhere where 00154 // the recorder sampling should occur. 00155 fm.Recorder(); 00156 00157 // The FreeMASTER poll call must be called in the main application loop 00158 // to handle the communication interface and protocol. 00159 // In LONG_INTR FreeMASTER interrupt mode, all the processing is done 00160 // during the communication interrupt routine and the FMSTR_Poll() is 00161 // compiled empty. 00162 fm.Poll(); 00163 wait(0.0025); 00164 } 00165 }
Generated on Sun Jul 17 2022 05:04:37 by
1.7.2