Ika Shouyu Poppoyaki - LPC82x supported

Dependencies:   MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Committer:
okano
Date:
Sat Aug 24 06:57:50 2013 +0000
Revision:
0:6baefda2e511
Child:
1:54e619428ae6
code for ISP function test. just very dirty code ;)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
okano 0:6baefda2e511 1 #include "mbed.h"
okano 0:6baefda2e511 2
okano 0:6baefda2e511 3 DigitalOut led1(LED1);
okano 0:6baefda2e511 4 DigitalOut led2(LED2);
okano 0:6baefda2e511 5
okano 0:6baefda2e511 6 DigitalOut reset_pin( p26 );
okano 0:6baefda2e511 7 DigitalOut isp_pin( p25 );
okano 0:6baefda2e511 8
okano 0:6baefda2e511 9 Serial pc (USBTX,USBRX);
okano 0:6baefda2e511 10 Serial target (p28,p27);
okano 0:6baefda2e511 11
okano 0:6baefda2e511 12 LocalFileSystem local("local");
okano 0:6baefda2e511 13 #define SOURCE_FILE "/local/bin"
okano 0:6baefda2e511 14
okano 0:6baefda2e511 15 #define STR_BUFF_SIZE 128
okano 0:6baefda2e511 16
okano 0:6baefda2e511 17 void put_string( char *s );
okano 0:6baefda2e511 18 void get_string( char *s );
okano 0:6baefda2e511 19
okano 0:6baefda2e511 20
okano 0:6baefda2e511 21 int try_and_check( char *command, char *expected_return_str, int mode )
okano 0:6baefda2e511 22 {
okano 0:6baefda2e511 23 char rtn_str[ STR_BUFF_SIZE ];
okano 0:6baefda2e511 24
okano 0:6baefda2e511 25 put_string( command );
okano 0:6baefda2e511 26 get_string( rtn_str );
okano 0:6baefda2e511 27
okano 0:6baefda2e511 28 return ( strcmp( expected_return_str, rtn_str ) );
okano 0:6baefda2e511 29 }
okano 0:6baefda2e511 30
okano 0:6baefda2e511 31 int try_and_check2( char *command, char *expected_return_str, int mode )
okano 0:6baefda2e511 32 {
okano 0:6baefda2e511 33 char rtn_str[ STR_BUFF_SIZE ];
okano 0:6baefda2e511 34
okano 0:6baefda2e511 35 put_string( command );
okano 0:6baefda2e511 36
okano 0:6baefda2e511 37 get_string( rtn_str ); // just readout echoback
okano 0:6baefda2e511 38 printf( " RTN0=%s\r\n", rtn_str );
okano 0:6baefda2e511 39 get_string( rtn_str );
okano 0:6baefda2e511 40 printf( " RTN1=%s\r\n", rtn_str );
okano 0:6baefda2e511 41
okano 0:6baefda2e511 42 return ( strcmp( expected_return_str, rtn_str ) );
okano 0:6baefda2e511 43 }
okano 0:6baefda2e511 44
okano 0:6baefda2e511 45 char read_byte( void )
okano 0:6baefda2e511 46 {
okano 0:6baefda2e511 47 while ( !target.readable() )
okano 0:6baefda2e511 48 ;
okano 0:6baefda2e511 49
okano 0:6baefda2e511 50 return ( target.getc() );
okano 0:6baefda2e511 51 }
okano 0:6baefda2e511 52 char uue_table[ 64 ];
okano 0:6baefda2e511 53
okano 0:6baefda2e511 54 void initialize_uue_table( void )
okano 0:6baefda2e511 55 {
okano 0:6baefda2e511 56 int i;
okano 0:6baefda2e511 57
okano 0:6baefda2e511 58 uue_table[0] = 0x60; // 0x20 is translated to 0x60 !
okano 0:6baefda2e511 59
okano 0:6baefda2e511 60 for (i = 1; i < 64; i++) {
okano 0:6baefda2e511 61 uue_table[i] = (char)(0x20 + i);
okano 0:6baefda2e511 62 }
okano 0:6baefda2e511 63 }
okano 0:6baefda2e511 64
okano 0:6baefda2e511 65 long bin2uue( char *bin, char *str )
okano 0:6baefda2e511 66 {
okano 0:6baefda2e511 67 unsigned long v;
okano 0:6baefda2e511 68 long check_sum = 0;
okano 0:6baefda2e511 69 int strpos = 0;
okano 0:6baefda2e511 70
okano 0:6baefda2e511 71 *(str + strpos++) = ' ' + 45;
okano 0:6baefda2e511 72
okano 0:6baefda2e511 73 for ( int i = 0; i < 45; i += 3 ) {
okano 0:6baefda2e511 74 check_sum += *(bin + i + 0) + *(bin + i + 1) + *(bin + i + 2);
okano 0:6baefda2e511 75 v = (*(bin + i + 0) << 16) | (*(bin + i + 1) << 8) | (*(bin + i + 2) << 0);
okano 0:6baefda2e511 76 *(str + strpos++) = uue_table[ (v >> 18) & 0x3F ];
okano 0:6baefda2e511 77 *(str + strpos++) = uue_table[ (v >> 12) & 0x3F ];
okano 0:6baefda2e511 78 *(str + strpos++) = uue_table[ (v >> 6) & 0x3F ];
okano 0:6baefda2e511 79 *(str + strpos++) = uue_table[ (v >> 0) & 0x3F ];
okano 0:6baefda2e511 80 }
okano 0:6baefda2e511 81 *(str + strpos++) = '\n';
okano 0:6baefda2e511 82 *(str + strpos++) = '\0';
okano 0:6baefda2e511 83
okano 0:6baefda2e511 84 return check_sum;
okano 0:6baefda2e511 85 }
okano 0:6baefda2e511 86
okano 0:6baefda2e511 87
okano 0:6baefda2e511 88 #define FLASH_WRITING_SIZE 1024
okano 0:6baefda2e511 89 #define TRANSFER_SIZE (24 * 45)
okano 0:6baefda2e511 90
okano 0:6baefda2e511 91 char b[ TRANSFER_SIZE ];
okano 0:6baefda2e511 92
okano 0:6baefda2e511 93 void sending_data( FILE *fp )
okano 0:6baefda2e511 94 {
okano 0:6baefda2e511 95 char command_str[ STR_BUFF_SIZE ];
okano 0:6baefda2e511 96 long check_sum = 0;
okano 0:6baefda2e511 97 int transfer_count = 0;
okano 0:6baefda2e511 98 int size;
okano 0:6baefda2e511 99
okano 0:6baefda2e511 100 initialize_uue_table();
okano 0:6baefda2e511 101
okano 0:6baefda2e511 102 for ( int i = FLASH_WRITING_SIZE; i < TRANSFER_SIZE; i++ )
okano 0:6baefda2e511 103 b[ i ] = 0;
okano 0:6baefda2e511 104
okano 0:6baefda2e511 105 while ( size = fread( b, sizeof( char ), FLASH_WRITING_SIZE, fp ) ) {
okano 0:6baefda2e511 106
okano 0:6baefda2e511 107 sprintf( command_str, "W %ld %ld\r\n", 0x10000300L, 1080 );
okano 0:6baefda2e511 108 printf( "\"%s\" %s\r\n", command_str, try_and_check( command_str, "0", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 109
okano 0:6baefda2e511 110 for ( int i = 0; i < 24; i++ ) {
okano 0:6baefda2e511 111 check_sum += bin2uue( b + (i * 45), command_str );
okano 0:6baefda2e511 112 printf( "%02d %s\r\n", i, command_str );
okano 0:6baefda2e511 113 put_string( command_str );
okano 0:6baefda2e511 114 if ( (i == 19) || (i == 23) ) {
okano 0:6baefda2e511 115 sprintf( command_str, "%ld\n", check_sum );
okano 0:6baefda2e511 116 printf( " %ld %s\r\n", check_sum, command_str );
okano 0:6baefda2e511 117 printf( "\"%s\" %s\r\n", command_str, try_and_check( command_str, "OK", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 118
okano 0:6baefda2e511 119 check_sum = 0;
okano 0:6baefda2e511 120 }
okano 0:6baefda2e511 121 }
okano 0:6baefda2e511 122
okano 0:6baefda2e511 123 printf( "\"P 0 0\" %s\r\n", try_and_check( "P 0 0\r\n", "0", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 124
okano 0:6baefda2e511 125 sprintf( command_str, "C %ld %ld %ld\r\n", FLASH_WRITING_SIZE * transfer_count++, 0x10000300L, FLASH_WRITING_SIZE );
okano 0:6baefda2e511 126 printf( "\"%s\" %s\r\n", command_str, try_and_check( command_str, "0", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 127
okano 0:6baefda2e511 128
okano 0:6baefda2e511 129 }
okano 0:6baefda2e511 130 printf( "\"G 0 T\" %s\r\n", try_and_check( "G 0 T\r\n", "0", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 131 }
okano 0:6baefda2e511 132
okano 0:6baefda2e511 133 int main()
okano 0:6baefda2e511 134 {
okano 0:6baefda2e511 135 FILE *fp;
okano 0:6baefda2e511 136 char str_buf0[ STR_BUFF_SIZE ];
okano 0:6baefda2e511 137 char str_buf1[ STR_BUFF_SIZE ];
okano 0:6baefda2e511 138
okano 0:6baefda2e511 139 pc.baud(9600);
okano 0:6baefda2e511 140 target.baud(9600);
okano 0:6baefda2e511 141
okano 0:6baefda2e511 142 if ( NULL == (fp = fopen( SOURCE_FILE, "rb" )) ) {
okano 0:6baefda2e511 143 error( "couldn't open source file" );
okano 0:6baefda2e511 144 return ( 1 );
okano 0:6baefda2e511 145 }
okano 0:6baefda2e511 146
okano 0:6baefda2e511 147 printf( "\r\n\r\ntarget RESET\r\n" );
okano 0:6baefda2e511 148
okano 0:6baefda2e511 149 reset_pin = 1;
okano 0:6baefda2e511 150 isp_pin = 0;
okano 0:6baefda2e511 151 wait_ms( 100 );
okano 0:6baefda2e511 152 reset_pin = 0;
okano 0:6baefda2e511 153 wait_ms( 100 );
okano 0:6baefda2e511 154 reset_pin = 1;
okano 0:6baefda2e511 155 wait_ms( 100 );
okano 0:6baefda2e511 156
okano 0:6baefda2e511 157 printf( "\"?\" >> \"Synchronized\" %s\r\n", try_and_check( "?", "Synchronized", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 158 printf( "\"Synchronized\\r\\n\" %s\r\n", try_and_check2( "Synchronized\r\n", "OK", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 159 printf( "\"12000\" %s\r\n", try_and_check2( "12000\r\n", "OK", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 160 printf( "\"U 23130\" %s\r\n", try_and_check2( "U 23130\r\n", "0", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 161 printf( "\"A 0\" %s\r\n", try_and_check2( "A 0\r\n", "0", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 162
okano 0:6baefda2e511 163 printf( "\"K\" %s\r\n", try_and_check( "K\r\n", "0", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 164 get_string( str_buf0 );
okano 0:6baefda2e511 165 get_string( str_buf1 );
okano 0:6baefda2e511 166 printf( " result of \"K\" = %s %s\r\n", str_buf0, str_buf1 );
okano 0:6baefda2e511 167
okano 0:6baefda2e511 168 printf( "\"J\" %s\r\n", try_and_check( "J\r\n", "0", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 169 get_string( str_buf0 );
okano 0:6baefda2e511 170 printf( " result of \"J\" = %s\r\n", str_buf0 );
okano 0:6baefda2e511 171
okano 0:6baefda2e511 172 #if 0
okano 0:6baefda2e511 173 printf( "\"N\" %s\r\n", try_and_check( "N\r\n", "0", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 174 get_string( str_buf0 );
okano 0:6baefda2e511 175 printf( " result of \"N\" = %s %lX\r\n", str_buf0, atol( str_buf0 ) );
okano 0:6baefda2e511 176 get_string( str_buf0 );
okano 0:6baefda2e511 177 printf( " result of \"N\" = %s %lX\r\n", str_buf0, atol( str_buf0 ) );
okano 0:6baefda2e511 178 get_string( str_buf0 );
okano 0:6baefda2e511 179 printf( " result of \"N\" = %s %lX\r\n", str_buf0, atol( str_buf0 ) );
okano 0:6baefda2e511 180 get_string( str_buf0 );
okano 0:6baefda2e511 181 printf( " result of \"N\" = %s %lX\r\n", str_buf0, atol( str_buf0 ) );
okano 0:6baefda2e511 182 #endif
okano 0:6baefda2e511 183 printf( "\"P 0 0\" %s\r\n", try_and_check( "P 0 0\r\n", "0", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 184 printf( "\"E 0 0\" %s\r\n", try_and_check( "E 0 0\r\n", "0", 0 ) ? "Fail" : "Pass" );
okano 0:6baefda2e511 185
okano 0:6baefda2e511 186 sending_data( fp );
okano 0:6baefda2e511 187 fclose( fp );
okano 0:6baefda2e511 188
okano 0:6baefda2e511 189 while ( 1 )
okano 0:6baefda2e511 190 ;
okano 0:6baefda2e511 191 }
okano 0:6baefda2e511 192
okano 0:6baefda2e511 193 void put_string( char *s )
okano 0:6baefda2e511 194 {
okano 0:6baefda2e511 195 char c;
okano 0:6baefda2e511 196
okano 0:6baefda2e511 197 while ( (c = *s++) )
okano 0:6baefda2e511 198 target.putc( c );
okano 0:6baefda2e511 199 }
okano 0:6baefda2e511 200
okano 0:6baefda2e511 201 void get_string( char *s )
okano 0:6baefda2e511 202 {
okano 0:6baefda2e511 203 int i = 0;
okano 0:6baefda2e511 204 char c = 0;
okano 0:6baefda2e511 205
okano 0:6baefda2e511 206 do {
okano 0:6baefda2e511 207 do {
okano 0:6baefda2e511 208 if ( target.readable() ) {
okano 0:6baefda2e511 209 c = target.getc();
okano 0:6baefda2e511 210
okano 0:6baefda2e511 211 if ( ( c == '\n') || (c == '\r') )
okano 0:6baefda2e511 212 break;
okano 0:6baefda2e511 213
okano 0:6baefda2e511 214 *s++ = c;
okano 0:6baefda2e511 215 i++;
okano 0:6baefda2e511 216 led2 = !led2;
okano 0:6baefda2e511 217
okano 0:6baefda2e511 218 }
okano 0:6baefda2e511 219 } while ( 1 );
okano 0:6baefda2e511 220 } while ( !i );
okano 0:6baefda2e511 221 *s = '\0';
okano 0:6baefda2e511 222 }
okano 0:6baefda2e511 223