Ika Shouyu Poppoyaki - LPC82x supported

Dependencies:   MODSERIAL mbed

Fork of ika_shouyu_poppoyaki by Tedd OKANO

Files at this revision

API Documentation at this revision

Comitter:
okano
Date:
Fri Sep 13 03:09:09 2013 +0000
Parent:
20:98d7b5878e3e
Child:
22:bd98a782fba6
Commit message:
"command_utilities" module made

Changed in this revision

command_utilities.cpp Show annotated file Show diff for this revision Revisions of this file
command_utilities.h Show annotated file Show diff for this revision Revisions of this file
ika.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
user_settings.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/command_utilities.cpp	Fri Sep 13 03:09:09 2013 +0000
@@ -0,0 +1,122 @@
+#include    "mbed.h"
+#include    "command_utilities.h"
+#include    "ika.h"
+
+Serial          pc ( USBTX,USBRX );
+
+#if 0
+Serial          target( p28, p27 );
+#else
+#define MODSERIAL_DEFAULT_RX_BUFFER_SIZE 512
+#define MODSERIAL_DEFAULT_TX_BUFFER_SIZE 512
+#include "MODSERIAL.h"
+MODSERIAL       target( p28, p27 ); //
+#endif
+
+void set_target_baud_rate( int baud_rate )
+{
+    target.baud( baud_rate );
+}
+
+
+void usb_serial_bridge_operation( void )
+{
+    while (1) {
+
+        if ( pc.readable() ) {
+            target.putc( pc.getc() );
+        }
+
+        if ( target.readable() ) {
+            pc.putc( target.getc() );
+        }
+    }
+}
+
+
+void put_string( char *s )
+{
+    char            c;
+    static int      i   = 0;
+
+    while ( c = *s++ ) {
+        target.putc( c );
+        set_leds( i++ & 0x1 );
+    }
+}
+
+
+void put_binary( char *b, int size )
+{
+    for ( int i = 0; i < size; i++ )
+        target.putc( *b++ );
+}
+
+
+Timeout timeout;
+
+int timeout_flag    = 0;
+
+void set_flag()
+{
+    timeout_flag    = 1;
+}
+
+
+void get_string( char *s )
+{
+    int     i   = 0;
+    char    c   = 0;
+    timeout_flag    = 0;
+
+    timeout.attach( &set_flag, 1 );
+
+    do {
+        do {
+            if ( target.readable() ) {
+                c  = target.getc();
+
+                if ( ( c == '\n') || (c == '\r') )
+                    break;
+
+                *s++    = c;
+                i++;
+            }
+
+            if ( timeout_flag )
+                return;
+        } while ( 1 );
+    } while ( !i );
+
+    *s  = '\0';
+}
+
+
+int get_binary( char *b, int length )
+{
+    int i;
+
+    timeout_flag    = 0;
+    timeout.attach( &set_flag, 1 );
+
+    for ( i = 0; i < length; i++ ) {
+        if ( target.readable() )
+            *b++    = target.getc();
+
+        if ( timeout_flag )
+            return ( i );
+    }
+
+    return ( i );
+}
+
+
+char read_byte( void )
+{
+    while ( !target.readable() )
+        ;
+
+    return ( target.getc() );
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/command_utilities.h	Fri Sep 13 03:09:09 2013 +0000
@@ -0,0 +1,9 @@
+
+void    set_target_baud_rate( int baud_rate );
+void    usb_serial_bridge_operation( void );
+
+void    put_string( char *s );
+void    put_binary( char *b, int size );
+void    get_string( char *s );
+int     get_binary( char *b, int length );
+char    read_byte( void );
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ika.h	Fri Sep 13 03:09:09 2013 +0000
@@ -0,0 +1,4 @@
+
+#pragma diag_suppress 1293  //  surpressing a warning message of "assignment in condition" ;)
+
+void set_leds( char v );
--- a/main.cpp	Fri Sep 13 02:50:11 2013 +0000
+++ b/main.cpp	Fri Sep 13 03:09:09 2013 +0000
@@ -23,23 +23,17 @@
 
 #include    "mbed.h"
 #include    "target_table.h"
+#include    "command_utilities.h"
+#include    "ika.h"
+
 
 BusOut          leds( LED4, LED3, LED2, LED1 );
 DigitalOut      reset_pin( p26 );
 DigitalOut      isp_pin( p25 );
-Serial          pc ( USBTX,USBRX );
 LocalFileSystem local( "local" );
 Ticker          success;
 
 
-#if 0
-Serial          target( p28, p27 );
-#else
-#define MODSERIAL_DEFAULT_RX_BUFFER_SIZE 512
-#define MODSERIAL_DEFAULT_TX_BUFFER_SIZE 512 
-#include "MODSERIAL.h"
-MODSERIAL       target( p28, p27 ); //
-#endif
 
 
 
@@ -89,10 +83,7 @@
 int     get_flash_writing_size( int ram_size, unsigned int ram_start );
 void    add_isp_checksum( char *b );
 void    send_RAM_transfer_checksum( int checksum );
-void    put_string( char *s );
-void    put_binary( char *b, int size );
-void    get_string( char *s );
-int     get_binary( char *b, int length );
+
 void    success_indicator();
 
 
@@ -152,7 +143,7 @@
 
 #define AUTO_PROGRAM_START
 #ifdef  AUTO_PROGRAM_START
-    target.baud( TARGET_OPERATION_BAUD_RATE );
+    set_target_baud_rate( TARGET_OPERATION_BAUD_RATE );
 
     reset_target( NO_ISP_MODE );
     printf( "  ** The program in flash has been started!!\r\n" );
@@ -162,16 +153,7 @@
 
     success.attach( &success_indicator, 0.1 );
 
-    while (1) {
-
-        if ( pc.readable() ) {
-            target.putc( pc.getc() );
-        }
-
-        if ( target.readable() ) {
-            pc.putc( target.getc() );
-        }
-    }
+    usb_serial_bridge_operation();  //  doesn't return. infinite loop in this function
 }
 
 
@@ -181,7 +163,7 @@
     char            str_buf0[ STR_BUFF_SIZE ];
     char            str_buf1[ STR_BUFF_SIZE ];
 
-    target.baud( baud_date );
+    set_target_baud_rate( baud_date );
     
     reset_target( ENTER_TO_ISP_MODE );
     
@@ -324,15 +306,6 @@
 }
 
 
-char read_byte( void )
-{
-    while ( !target.readable() )
-        ;
-
-    return ( target.getc() );
-}
-
-
 void erase_sectors( int last_sector )
 {
     char    command_str[ STR_BUFF_SIZE ];
@@ -769,82 +742,6 @@
 }
 
 
-void put_string( char *s )
-{
-    char            c;
-    static int      i   = 0;
-
-    while ( c = *s++ ) {
-        target.putc( c );
-        leds    = i++ & 0x1;
-    }
-}
-
-
-void put_binary( char *b, int size )
-{
-    for ( int i = 0; i < size; i++ )
-        target.putc( *b++ );
-}
-
-
-Timeout timeout;
-
-int timeout_flag    = 0;
-
-void set_flag()
-{
-    timeout_flag    = 1;
-}
-
-
-void get_string( char *s )
-{
-    int     i   = 0;
-    char    c   = 0;
-    timeout_flag    = 0;
-
-    timeout.attach( &set_flag, 1 );
-
-    do {
-        do {
-            if ( target.readable() ) {
-                c  = target.getc();
-
-                if ( ( c == '\n') || (c == '\r') )
-                    break;
-
-                *s++    = c;
-                i++;
-            }
-
-            if ( timeout_flag )
-                return;
-        } while ( 1 );
-    } while ( !i );
-
-    *s  = '\0';
-}
-
-
-int get_binary( char *b, int length )
-{
-    int i;
-
-    timeout_flag    = 0;
-    timeout.attach( &set_flag, 1 );
-
-    for ( i = 0; i < length; i++ ) {
-        if ( target.readable() )
-            *b++    = target.getc();
-
-        if ( timeout_flag )
-            return ( i );
-    }
-
-    return ( i );
-}
-
 
 void success_indicator()
 {
@@ -852,3 +749,9 @@
     
     leds    = 0x1 << (i++ & 0x3);
 }
+
+
+void set_leds( char v )
+{
+    leds    = v;
+}