Add to 11U68 11E68
Dependencies: DirectoryList MODSERIAL mbed
Fork of ika_shouyu_poppoyaki by
Diff: writing.cpp
- Revision:
- 28:689c3880e0e4
- Parent:
- 27:2b5c1eb39bb5
- Child:
- 29:96e28bc1bd99
--- a/writing.cpp Thu Sep 19 01:08:20 2013 +0000 +++ b/writing.cpp Fri Sep 20 00:40:08 2013 +0000 @@ -5,6 +5,7 @@ #include "uu_coding.h" #include "serial_utilities.h" #include "ika.h" +#include "error_code.h" int write_uuencoded_data( FILE *fp, int ram_size, int sector_size, unsigned int ); @@ -45,7 +46,7 @@ // char b[ transfer_size ]; // this can be done in mbed-compiler. but I should do it in common way if ( NULL == (b = (char *)malloc( transfer_size * sizeof( char ) )) ) - error( "malloc error happened\r\n" ); + return( ERROR_AT_MALLOC_FOR_WRITE_BUFF ); for ( int i = flash_writing_size; i < transfer_size; i++ ) b[ i ] = 0; // this is not neccesary but just stuffing stuffing bytes @@ -71,17 +72,21 @@ put_string( command_str ); if ( !((i + 1) % 20) ) { - send_RAM_transfer_checksum( checksum ); + if ( send_RAM_transfer_checksum( checksum ) ) + return ( ERROR_AT_SENDING_CHECKSUM ); + checksum = 0; } } - send_RAM_transfer_checksum( checksum ); + if ( send_RAM_transfer_checksum( checksum ) ) + return ( ERROR_AT_SENDING_CHECKSUM ); + checksum = 0; sprintf( command_str, "P %d %d\r\n", total_size / sector_size, total_size / sector_size ); if ( try_and_check( command_str, "0", 0 ) ) - return ( ERROR_AT_P_COMMAND ); + return ( ERROR_AT_PREPARE_COMMAND ); sprintf( command_str, "C %d %d %d\r\n", total_size, ram_start, flash_writing_size ); if ( try_and_check( command_str, "0", 0 ) ) @@ -107,7 +112,7 @@ flash_writing_size = 256; if ( NULL == (b = (char *)malloc( flash_writing_size * sizeof( char ) )) ) - error( "malloc error happened\r\n" ); + return( ERROR_AT_MALLOC_FOR_WRITE_BUFF ); while ( size = fread( b, sizeof( char ), flash_writing_size, fp ) ) { @@ -126,7 +131,7 @@ sprintf( command_str, "P %d %d\r\n", total_size / sector_size, total_size / sector_size ); if ( try_and_check( command_str, "0", 0 ) ) - return ( ERROR_AT_P_COMMAND ); + return ( ERROR_AT_PREPARE_COMMAND ); sprintf( command_str, "C %d %d %d\r\n", total_size, ram_start, flash_writing_size ); if ( try_and_check( command_str, "0", 0 ) ) @@ -184,4 +189,14 @@ } return ( flash_writing_size[ i ] ); -} \ No newline at end of file +} + + +int post_writing_process( target_param *tpp ) +{ + if ( tpp->write_type == UUENCODE ) + return ( try_and_check( "G 0 T\r\n", "0", 0 ) ); + else + return ( 0 ); +} +