Ika Shouyu Poppoyaki - LPC82x supported
Fork of ika_shouyu_poppoyaki by
Diff: main.cpp
- Revision:
- 30:e0d7524661ca
- Parent:
- 29:96e28bc1bd99
- Child:
- 31:1a4d59d7bd72
--- 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); -} - -