Add to 11U68 11E68

Dependencies:   DirectoryList MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Fri Sep 20 02:21:58 2013 +0000
Parent:
29:96e28bc1bd99
Child:
31:1a4d59d7bd72
Commit message:
** version 0.95. redundant code and files are removed

Changed in this revision

command_interface.cpp Show annotated file Show diff for this revision Revisions of this file
error_code.h Show diff for this revision Revisions of this file
ika.h Show diff for this revision Revisions of this file
isp.cpp Show annotated file Show diff for this revision Revisions of this file
isp.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
serial_utilities.cpp Show annotated file Show diff for this revision Revisions of this file
serial_utilities.h Show annotated file Show diff for this revision Revisions of this file
verification.cpp Show annotated file Show diff for this revision Revisions of this file
writing.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/command_interface.cpp	Fri Sep 20 01:48:26 2013 +0000
+++ b/command_interface.cpp	Fri Sep 20 02:21:58 2013 +0000
@@ -1,7 +1,6 @@
 #include    "mbed.h"
 #include    "command_interface.h"
 #include    "serial_utilities.h"
-#include    "ika.h"
 #include    "_user_settings.h"
 
 
@@ -19,8 +18,6 @@
     if ( result && !mode )
         error( "command failed\r\n" );
 
-    error_state |= result;
-
     return ( result );
 }
 
@@ -40,8 +37,6 @@
     if ( result && !mode )
         error( "command failed\r\n" );
 
-    error_state |= result;
-
     return ( result );
 }
 
--- a/error_code.h	Fri Sep 20 01:48:26 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-#ifndef MBED_ISP__ERROR_CODE__
-#define MBED_ISP__ERROR_CODE__
-
-enum {
-    NO_ERROR                            = 0x00,
-
-    ERROR_AT_TARGET_OPEN,
-    ERROR_AT_FILE_OPEN,
-    ERROR_AT_SECTOR_ERASE,
-
-    ERROR_AT_MALLOC_FOR_WRITE_BUFF,
-    ERROR_AT_WRITE_COMMAND,
-    ERROR_AT_PREPARE_COMMAND,
-    ERROR_AT_COPY_COMMAND,
-    ERROR_AT_SENDING_CHECKSUM,
-
-    ERROR_AT_MALLOC_FOR_VERIFY_FILE_BUFF,
-    ERROR_AT_MALLOC_FOR_VERIFY_DATA_BUFF,
-    ERROR_AT_READ_COMMAND,
-
-    ERROR_DATA_DOES_NOT_MATCH
-};
-
-#endif  //  MBED_ISP__ERROR_CODE__
--- a/ika.h	Fri Sep 20 01:48:26 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,7 +0,0 @@
-
-#pragma diag_suppress 1293  //  surpressing a warning message of "assignment in condition" ;)
-
-void toggle_led( char v );
-
-extern int     error_state;
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/isp.cpp	Fri Sep 20 02:21:58 2013 +0000
@@ -0,0 +1,112 @@
+
+#include    "mbed.h"
+#include    "target_table.h"
+#include    "serial_utilities.h"
+#include    "command_interface.h"
+#include    "writing.h"
+#include    "uu_coding.h"
+#include    "target_handling.h"
+#include    "verification.h"
+#include    "isp.h"
+#include    "_user_settings.h"
+
+
+BusOut          leds( LED4, LED3, LED2, LED1 );
+Ticker          success;
+
+
+int     file_size( FILE *fp );
+void    success_indicator();
+
+int isp_flash_write( char *file_name )
+{
+    FILE            *fp;
+    target_param    *tpp;
+    int             data_size;
+    int             last_sector;
+    int             transferred_size;
+    int             err;
+
+    if ( NULL == (tpp = open_target( ISP_BAUD_RATE )) ) {
+        return ( ERROR_AT_TARGET_OPEN );
+    }
+
+    printf( "  target device found : type       = \"%s\"\r\n",     tpp->type_name );
+    printf( "                        ID         = 0x%08X\r\n",     tpp->id );
+    printf( "                        RAM size   = %10d bytes\r\n", tpp->ram_size );
+    printf( "                        flash size = %10d bytes\r\n", tpp->flash_size );
+
+    printf( "  opening file: \"%s\"\r\n", file_name );
+
+    if ( NULL == (fp    = fopen( file_name, "rb" )) ) {
+        return ( ERROR_AT_FILE_OPEN );
+    }
+
+    data_size   = file_size( fp );
+    last_sector = data_size / tpp->sector_size;
+
+    printf( "  data size = %d bytes, it takes %d secotrs in flash area\r\n", data_size, last_sector + 1 );
+    printf( "  resetting target\r\n" );
+
+    if ( erase_sectors( last_sector ) )
+        return ( ERROR_AT_SECTOR_ERASE );
+
+    printf( "\r\n  ==== flash writing ====\r\n" );
+
+    if ( err    = write_flash( fp, tpp, &transferred_size ) )
+        return ( err );
+
+    printf( "  -- %d bytes data are written\r\n", transferred_size );
+
+
+    printf( "\r\n  ==== flash reading and verifying ====\r\n" );
+
+    if ( err    = verify_flash( fp, tpp, &transferred_size ) )
+        return ( err );
+
+    printf( "  -- %d bytes data are read and verified\r\n", transferred_size );
+
+    fclose( fp );
+
+    post_writing_process( tpp );
+
+    return ( 0 );
+}
+
+
+int file_size( FILE *fp )
+{
+    int     size;
+
+    fseek( fp, 0, SEEK_END ); // seek to end of file
+    size    = ftell( fp );       // get current file pointer
+    fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
+
+    return size;
+}
+
+
+void start_target_in_normal_mode( int baud_rate )
+{
+    set_target_baud_rate( baud_rate );
+    reset_target( NO_ISP_MODE );
+}
+
+void start_success_indicator( void )
+{
+    success.attach( &success_indicator, 0.1 );
+}
+
+void success_indicator()
+{
+    static int  i   = 0;
+
+    leds    = 0x1 << (i++ & 0x3);
+}
+
+
+void toggle_led( char v )
+{
+    leds    = leds ^ (0x1 << v);
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/isp.h	Fri Sep 20 02:21:58 2013 +0000
@@ -0,0 +1,33 @@
+#ifndef MBED_ISP__ISP__
+#define MBED_ISP__ISP__
+
+
+int     isp_flash_write( char *file_name );
+void    start_target_in_normal_mode( int baud_rate );
+void    start_success_indicator( void );
+void    toggle_led( char v );
+
+
+enum {
+    NO_ERROR                            = 0x00,
+
+    ERROR_AT_TARGET_OPEN,
+    ERROR_AT_FILE_OPEN,
+    ERROR_AT_SECTOR_ERASE,
+
+    ERROR_AT_MALLOC_FOR_WRITE_BUFF,
+    ERROR_AT_WRITE_COMMAND,
+    ERROR_AT_PREPARE_COMMAND,
+    ERROR_AT_COPY_COMMAND,
+    ERROR_AT_SENDING_CHECKSUM,
+
+    ERROR_AT_MALLOC_FOR_VERIFY_FILE_BUFF,
+    ERROR_AT_MALLOC_FOR_VERIFY_DATA_BUFF,
+    ERROR_AT_READ_COMMAND,
+
+    ERROR_DATA_DOES_NOT_MATCH
+};
+
+
+#endif  //  MBED_ISP__ISP__
+
--- a/main.cpp	Fri Sep 20 01:48:26 2013 +0000
+++ b/main.cpp	Fri Sep 20 02:21:58 2013 +0000
@@ -2,7 +2,7 @@
  *  Sample of ISP operation for NXP MCUs
  *
  *  @author  Tedd OKANO
- *  @version 0.9
+ *  @version 0.95
  *  @date    Sep-2013
  *
  *  This program programs MCU flash memory through UART. It uses
@@ -22,35 +22,22 @@
  */
 
 #include    "mbed.h"
-#include    "target_table.h"
+#include    "isp.h"
 #include    "serial_utilities.h"
-#include    "command_interface.h"
-#include    "writing.h"
-#include    "uu_coding.h"
-#include    "target_handling.h"
-#include    "verification.h"
 #include    "_user_settings.h"
-#include    "ika.h"
-#include    "error_code.h"
 
-BusOut          leds( LED4, LED3, LED2, LED1 );
+
 LocalFileSystem local( "local" );
-Ticker          success;
-
-int     error_state         = 0;
-
-int     isp_flash_write( char *file_name );
-int     file_size( FILE *fp );
-char    read_byte( void );
-void    success_indicator();
 
 
 int main()
 {
     int     err;
-    
+
+    printf( "\r\n\r\n\r\nmbed ISP program : programming LPC device from mbed (v0.95)\r\n" );
+
     err     = isp_flash_write( SOURCE_FILE );
-    
+
     printf( "\r\n  %s\r\n\r\n",
             err ?
             "** The data could not be written :(" :
@@ -61,100 +48,20 @@
         error( "  ** ISP failed\r\n" );
 
 #ifdef  AUTO_PROGRAM_START
-    set_target_baud_rate( TARGET_OPERATION_BAUD_RATE );
+    //set_target_baud_rate( TARGET_OPERATION_BAUD_RATE );
+    //reset_target( NO_ISP_MODE );
+    
+    start_target_in_normal_mode( TARGET_OPERATION_BAUD_RATE );
 
-    reset_target( NO_ISP_MODE );
     printf( "  ** The program in flash has been started!!\r\n" );
 #endif
 
     printf( "     (now the mbed is working in \"serial through mode\")\r\n\r\n" );
 
-    success.attach( &success_indicator, 0.1 );
+//    success.attach( &success_indicator, 0.1 );
+    start_success_indicator();
 
     usb_serial_bridge_operation();  //  doesn't return. infinite loop in this function
 }
 
 
-int isp_flash_write( char *file_name )
-{
-    FILE            *fp;
-    target_param    *tpp;
-    int             data_size;
-    int             last_sector;
-    int             transferred_size;
-    int             err;
-
-    if ( NULL == (tpp = open_target( ISP_BAUD_RATE )) ) {
-        return ( ERROR_AT_TARGET_OPEN );
-    }
-
-    printf( "  target device found : type       = \"%s\"\r\n",     tpp->type_name );
-    printf( "                        ID         = 0x%08X\r\n",     tpp->id );
-    printf( "                        RAM size   = %10d bytes\r\n", tpp->ram_size );
-    printf( "                        flash size = %10d bytes\r\n", tpp->flash_size );
-
-    printf( "  opening file: \"%s\"\r\n", file_name );
-
-    if ( NULL == (fp    = fopen( file_name, "rb" )) ) {
-        return ( ERROR_AT_FILE_OPEN );
-    }
-
-    data_size   = file_size( fp );
-    last_sector = data_size / tpp->sector_size;
-
-    printf( "  data size = %d bytes, it takes %d secotrs in flash area\r\n", data_size, last_sector + 1 );
-    printf( "  resetting target\r\n" );
-
-    if ( erase_sectors( last_sector ) )
-        return ( ERROR_AT_SECTOR_ERASE );
-
-    printf( "\r\n  ==== flash writing ====\r\n" );
-    
-    if ( err    = write_flash( fp, tpp, &transferred_size ) )
-        return ( err );
-
-    printf( "  -- %d bytes data are written\r\n", transferred_size );
-        
-    
-    printf( "\r\n  ==== flash reading and verifying ====\r\n" );
-    
-    if ( err    = verify_flash( fp, tpp, &transferred_size ) )
-        return ( err );
-
-    printf( "  -- %d bytes data are read and verified\r\n", transferred_size );
-
-    fclose( fp );
-
-    post_writing_process( tpp );
-    
-    return ( 0 );
-}
-
-
-
-int file_size( FILE *fp )
-{
-    int     size;
-
-    fseek( fp, 0, SEEK_END ); // seek to end of file
-    size    = ftell( fp );       // get current file pointer
-    fseek( fp, 0, SEEK_SET ); // seek back to beginning of file
-
-    return size;
-}
-
-
-void success_indicator()
-{
-    static int  i   = 0;
-
-    leds    = 0x1 << (i++ & 0x3);
-}
-
-
-void toggle_led( char v )
-{
-    leds    = leds ^ (0x1 << v);
-}
-
-
--- a/serial_utilities.cpp	Fri Sep 20 01:48:26 2013 +0000
+++ b/serial_utilities.cpp	Fri Sep 20 02:21:58 2013 +0000
@@ -1,7 +1,6 @@
 #include    "mbed.h"
 #include    "serial_utilities.h"
-#include    "ika.h"
-#include    "error_code.h"
+#include    "isp.h"
 
 Serial          pc ( USBTX,USBRX );
 
--- a/serial_utilities.h	Fri Sep 20 01:48:26 2013 +0000
+++ b/serial_utilities.h	Fri Sep 20 02:21:58 2013 +0000
@@ -8,3 +8,6 @@
 int     get_binary( char *b, int length );
 char    read_byte( void );
 
+//  next line is not related to "serial feature", but all code affected by this are including this header file
+#pragma diag_suppress 1293  //  surpressing a warning message of "assignment in condition" ;)
+
--- a/verification.cpp	Fri Sep 20 01:48:26 2013 +0000
+++ b/verification.cpp	Fri Sep 20 02:21:58 2013 +0000
@@ -4,8 +4,7 @@
 #include    "uu_coding.h"
 #include    "serial_utilities.h"
 #include    "writing.h"
-#include    "ika.h"
-#include    "error_code.h"
+#include    "isp.h"
 
 
 int     verify_binary_data( FILE *fp, int *transferred_size_p );
@@ -86,8 +85,6 @@
         read_size   += size;
     }
 
-    error_state |= error_flag;
-
     free( bf );
     free( br );
 
@@ -147,7 +144,6 @@
         read_size   += size;
     }
 
-    error_state |= error_flag;
     free( bf );
     free( br );
 
--- a/writing.cpp	Fri Sep 20 01:48:26 2013 +0000
+++ b/writing.cpp	Fri Sep 20 02:21:58 2013 +0000
@@ -4,8 +4,7 @@
 #include    "command_interface.h"
 #include    "uu_coding.h"
 #include    "serial_utilities.h"
-#include    "ika.h"
-#include    "error_code.h"
+#include    "isp.h"
 
 
 int     write_uuencoded_data( FILE *fp, int ram_size, int sector_size, unsigned int ram_start, int *total_size_p );