this transfers data (which is stored in "bin" file in mbed storage) into LPC1114, LPC1115, LPC81x, LPC82x, LPC1768/LPC1769 and LPC11U68/LPC11E68 internal flash memory through ISP.

Dependencies:   mbed MODSERIAL DirectoryList

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers command_interface.cpp Source File

command_interface.cpp

00001 #include    "mbed.h"
00002 #include    "command_interface.h"
00003 #include    "serial_utilities.h"
00004 #include    "_user_settings.h"
00005 
00006 
00007 int try_and_check( char *command, char *expected_return_str )
00008 {
00009     char    rtn_str[ STR_BUFF_SIZE ];
00010     int     result  = 1;
00011 
00012     print_command( command );
00013     put_string( command );
00014 
00015     get_string( rtn_str );
00016     print_result( result  = strcmp( expected_return_str, rtn_str ) );
00017 
00018 //    if ( result && !mode )
00019 //        error( "command failed\r\n" );
00020 
00021     return ( result );
00022 }
00023 
00024 
00025 int try_and_check2( char *command, char *expected_return_str )
00026 {
00027     char    rtn_str[ STR_BUFF_SIZE ];
00028     int     result  = 1;
00029 
00030     print_command( command );
00031     put_string( command );
00032 
00033     get_string( rtn_str );  // just readout echoback
00034     get_string( rtn_str );
00035     print_result( result  = strcmp( expected_return_str, rtn_str ) );
00036 
00037 //    if ( result && !mode )
00038 //        error( "command failed\r\n" );
00039 
00040     return ( result );
00041 }
00042 
00043 
00044 void print_command( char *command )
00045 {
00046 #ifndef SUPPRESS_COMMAND_RESULT_MESSAGE
00047 
00048     char    s[ STR_BUFF_SIZE ];
00049     char    *pos;
00050 
00051     strcpy( s, command );
00052 
00053     if ( pos    = strchr( s, '\r' ) )
00054         *pos    = '\0';
00055 
00056     if ( pos    = strchr( s, '\n' ) )
00057         *pos    = '\0';
00058 
00059     printf( "  command - %-22s : ", s );
00060 
00061 #endif  //SUPPRESS_COMMAND_RESULT_MESSAGE
00062 }
00063 
00064 
00065 void print_result( int r )
00066 {
00067 #ifndef SUPPRESS_COMMAND_RESULT_MESSAGE
00068     printf( "%s\r\n", r ? "Fail" : "Pass" );
00069 #endif  //SUPPRESS_COMMAND_RESULT_MESSAGE
00070 }
00071 
00072 
00073 int send_RAM_transfer_checksum( int checksum )
00074 {
00075     char    command[ 16 ];
00076 
00077     sprintf( command, "%d\n", checksum );
00078 
00079     return ( try_and_check( command, "OK" ) );
00080 }
00081 
00082 
00083 int erase_sectors( int last_sector )
00084 {
00085     char    command_str[ STR_BUFF_SIZE ];
00086 
00087     sprintf( command_str, "P 0 %d\r\n", last_sector );
00088     if ( try_and_check( command_str, "0" ) )
00089         return ( 1 );
00090 
00091     *(command_str)  = 'E';
00092     return ( try_and_check( command_str, "0" ) );
00093 }
00094 
00095