starboard_orange test code for TextLCD, SD, USB and Ethernet

Dependencies:   mbed MSCFileSystem_Lib SDFileSystem

Committer:
nxpfan
Date:
Wed Aug 04 05:09:28 2010 +0000
Revision:
0:bdbcdf6f3e8a

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nxpfan 0:bdbcdf6f3e8a 1 #include "mbed.h"
nxpfan 0:bdbcdf6f3e8a 2
nxpfan 0:bdbcdf6f3e8a 3 ////////////////////////////////////////
nxpfan 0:bdbcdf6f3e8a 4 //////// general setting ////////
nxpfan 0:bdbcdf6f3e8a 5 ////////////////////////////////////////
nxpfan 0:bdbcdf6f3e8a 6 //#define USE_TextLCD_20x4
nxpfan 0:bdbcdf6f3e8a 7 #define USE_FIXED_IP
nxpfan 0:bdbcdf6f3e8a 8
nxpfan 0:bdbcdf6f3e8a 9 ////////////////////////////////////////
nxpfan 0:bdbcdf6f3e8a 10 //////// For TextLCD ////////
nxpfan 0:bdbcdf6f3e8a 11 ////////////////////////////////////////
nxpfan 0:bdbcdf6f3e8a 12 #include "TextLCD.h"
nxpfan 0:bdbcdf6f3e8a 13 #ifdef USE_TextLCD_20x4
nxpfan 0:bdbcdf6f3e8a 14 //TextLCD lcd( p24, p26, p27, p28, p29, p30, TextLCD::LCD20x4 ); // rs, e, d0-d3
nxpfan 0:bdbcdf6f3e8a 15 #else
nxpfan 0:bdbcdf6f3e8a 16 TextLCD lcd( p24, p26, p27, p28, p29, p30 ); // rs, e, d0-d3
nxpfan 0:bdbcdf6f3e8a 17 #endif
nxpfan 0:bdbcdf6f3e8a 18
nxpfan 0:bdbcdf6f3e8a 19 ////////////////////////////////////////
nxpfan 0:bdbcdf6f3e8a 20 //////// For SD_card ////////
nxpfan 0:bdbcdf6f3e8a 21 ////////////////////////////////////////
nxpfan 0:bdbcdf6f3e8a 22 #include "SDFileSystem.h"
nxpfan 0:bdbcdf6f3e8a 23 //SDFileSystem sd(p5, p6, p7, p13, "sd"); // mosi, miso, sclk, cs, name
nxpfan 0:bdbcdf6f3e8a 24 SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs, name (HW modification candidate)
nxpfan 0:bdbcdf6f3e8a 25
nxpfan 0:bdbcdf6f3e8a 26 ////////////////////////////////////////
nxpfan 0:bdbcdf6f3e8a 27 //////// For USB storage ////////
nxpfan 0:bdbcdf6f3e8a 28 ////////////////////////////////////////
nxpfan 0:bdbcdf6f3e8a 29 #include "MSCFileSystem.h"
nxpfan 0:bdbcdf6f3e8a 30 MSCFileSystem usb("usb");
nxpfan 0:bdbcdf6f3e8a 31
nxpfan 0:bdbcdf6f3e8a 32 ////////////////////////////////////////
nxpfan 0:bdbcdf6f3e8a 33 //////// For Ethernet test ////////
nxpfan 0:bdbcdf6f3e8a 34 ////////////////////////////////////////
nxpfan 0:bdbcdf6f3e8a 35 #include "EthernetNetIf.h"
nxpfan 0:bdbcdf6f3e8a 36 #include "HTTPServer.h"
nxpfan 0:bdbcdf6f3e8a 37 #ifdef USE_FIXED_IP
nxpfan 0:bdbcdf6f3e8a 38 EthernetNetIf eth(
nxpfan 0:bdbcdf6f3e8a 39 IpAddr(192,168,0,7), //IP Address
nxpfan 0:bdbcdf6f3e8a 40 IpAddr(255,255,255,0), //Network Mask
nxpfan 0:bdbcdf6f3e8a 41 IpAddr(192,168,0,1), //Gateway
nxpfan 0:bdbcdf6f3e8a 42 IpAddr(192,168,0,1) //DNS
nxpfan 0:bdbcdf6f3e8a 43 );
nxpfan 0:bdbcdf6f3e8a 44 #else
nxpfan 0:bdbcdf6f3e8a 45 EthernetNetIf eth;
nxpfan 0:bdbcdf6f3e8a 46 #endif
nxpfan 0:bdbcdf6f3e8a 47 HTTPServer svr;
nxpfan 0:bdbcdf6f3e8a 48 LocalFileSystem web("local");
nxpfan 0:bdbcdf6f3e8a 49
nxpfan 0:bdbcdf6f3e8a 50
nxpfan 0:bdbcdf6f3e8a 51 void test_TextLCD( void );
nxpfan 0:bdbcdf6f3e8a 52 void test_file_write( char *title, char *path );
nxpfan 0:bdbcdf6f3e8a 53 void test_httpserver( void );
nxpfan 0:bdbcdf6f3e8a 54 int position( void );
nxpfan 0:bdbcdf6f3e8a 55
nxpfan 0:bdbcdf6f3e8a 56 int main() {
nxpfan 0:bdbcdf6f3e8a 57 test_TextLCD();
nxpfan 0:bdbcdf6f3e8a 58 wait( 1 );
nxpfan 0:bdbcdf6f3e8a 59 test_file_write( "SD card", "/sd/star_bd.txt" );
nxpfan 0:bdbcdf6f3e8a 60 wait( 1 );
nxpfan 0:bdbcdf6f3e8a 61 test_file_write( "USB storage", "/usb/star_bd.txt" );
nxpfan 0:bdbcdf6f3e8a 62 wait( 1 );
nxpfan 0:bdbcdf6f3e8a 63 test_httpserver();
nxpfan 0:bdbcdf6f3e8a 64 }
nxpfan 0:bdbcdf6f3e8a 65
nxpfan 0:bdbcdf6f3e8a 66
nxpfan 0:bdbcdf6f3e8a 67 void test_TextLCD( void ) {
nxpfan 0:bdbcdf6f3e8a 68 // TextLCD test
nxpfan 0:bdbcdf6f3e8a 69
nxpfan 0:bdbcdf6f3e8a 70 #ifdef USE_TextLCD_20x4
nxpfan 0:bdbcdf6f3e8a 71 lcd.locate( 0, 0 );
nxpfan 0:bdbcdf6f3e8a 72 for ( int i = 0, c = '0'; i < 20; i++, c++ )
nxpfan 0:bdbcdf6f3e8a 73 lcd.putc( c );
nxpfan 0:bdbcdf6f3e8a 74
nxpfan 0:bdbcdf6f3e8a 75 for ( int i = 0, c = 'A'; i < 20; i++, c++ )
nxpfan 0:bdbcdf6f3e8a 76 lcd.putc( c );
nxpfan 0:bdbcdf6f3e8a 77
nxpfan 0:bdbcdf6f3e8a 78 for ( int i = 0, c = 'a'; i < 20; i++, c++ )
nxpfan 0:bdbcdf6f3e8a 79 lcd.putc( c );
nxpfan 0:bdbcdf6f3e8a 80 for ( int i = 0, c = '0' - 10; i < 20; i++, c++ )
nxpfan 0:bdbcdf6f3e8a 81 lcd.putc( c );
nxpfan 0:bdbcdf6f3e8a 82 exit( 0 );
nxpfan 0:bdbcdf6f3e8a 83 wait( 300 );
nxpfan 0:bdbcdf6f3e8a 84 lcd.cls();
nxpfan 0:bdbcdf6f3e8a 85 #endif // USE_TextLCD_20x4
nxpfan 0:bdbcdf6f3e8a 86
nxpfan 0:bdbcdf6f3e8a 87 lcd.locate( 0, 0 );
nxpfan 0:bdbcdf6f3e8a 88 lcd.printf( "TextLCD: OK?" );
nxpfan 0:bdbcdf6f3e8a 89 lcd.locate( 0, 1 );
nxpfan 0:bdbcdf6f3e8a 90 lcd.printf( "" );
nxpfan 0:bdbcdf6f3e8a 91
nxpfan 0:bdbcdf6f3e8a 92 }
nxpfan 0:bdbcdf6f3e8a 93
nxpfan 0:bdbcdf6f3e8a 94 void test_file_write( char *title, char *path ) {
nxpfan 0:bdbcdf6f3e8a 95 // SD card test
nxpfan 0:bdbcdf6f3e8a 96 lcd.locate( 0, position() );
nxpfan 0:bdbcdf6f3e8a 97 lcd.printf( "%s: ", title );
nxpfan 0:bdbcdf6f3e8a 98
nxpfan 0:bdbcdf6f3e8a 99 FILE *fp = fopen( path, "w" );
nxpfan 0:bdbcdf6f3e8a 100 if ( fp == NULL ) {
nxpfan 0:bdbcdf6f3e8a 101 lcd.printf( "error" );
nxpfan 0:bdbcdf6f3e8a 102 error( "Could not open file for write\n" );
nxpfan 0:bdbcdf6f3e8a 103 }
nxpfan 0:bdbcdf6f3e8a 104 fprintf( fp, "The mbed writing a file through the star board orange (%s)!", title );
nxpfan 0:bdbcdf6f3e8a 105 fclose( fp );
nxpfan 0:bdbcdf6f3e8a 106
nxpfan 0:bdbcdf6f3e8a 107 lcd.printf( "OK." );
nxpfan 0:bdbcdf6f3e8a 108 }
nxpfan 0:bdbcdf6f3e8a 109
nxpfan 0:bdbcdf6f3e8a 110
nxpfan 0:bdbcdf6f3e8a 111 void test_httpserver( void ) {
nxpfan 0:bdbcdf6f3e8a 112 DigitalOut led1( LED1 );
nxpfan 0:bdbcdf6f3e8a 113
nxpfan 0:bdbcdf6f3e8a 114 lcd.locate( 0, position() );
nxpfan 0:bdbcdf6f3e8a 115 lcd.printf( "HTTP srv: " );
nxpfan 0:bdbcdf6f3e8a 116
nxpfan 0:bdbcdf6f3e8a 117 Base::add_rpc_class<DigitalOut>();
nxpfan 0:bdbcdf6f3e8a 118
nxpfan 0:bdbcdf6f3e8a 119 printf("Setting up...n");
nxpfan 0:bdbcdf6f3e8a 120 EthernetErr ethErr = eth.setup();
nxpfan 0:bdbcdf6f3e8a 121 if ( ethErr ) {
nxpfan 0:bdbcdf6f3e8a 122 lcd.printf( "error" );
nxpfan 0:bdbcdf6f3e8a 123 error( "error @ eth.setup()\n" );
nxpfan 0:bdbcdf6f3e8a 124 }
nxpfan 0:bdbcdf6f3e8a 125 lcd.printf("OK ");
nxpfan 0:bdbcdf6f3e8a 126
nxpfan 0:bdbcdf6f3e8a 127 FSHandler::mount("/local", "/"); //Mount /webfs path on web root path
nxpfan 0:bdbcdf6f3e8a 128 FSHandler::mount("/sd", "/sd"); //Mount /webfs path on web sd path
nxpfan 0:bdbcdf6f3e8a 129 FSHandler::mount("/usb", "/usb"); //Mount /webfs path on web usb path
nxpfan 0:bdbcdf6f3e8a 130
nxpfan 0:bdbcdf6f3e8a 131 svr.addHandler<FSHandler>("/"); //Default handler
nxpfan 0:bdbcdf6f3e8a 132 svr.addHandler<FSHandler>("/sd");
nxpfan 0:bdbcdf6f3e8a 133 svr.addHandler<FSHandler>("/usb");
nxpfan 0:bdbcdf6f3e8a 134 //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
nxpfan 0:bdbcdf6f3e8a 135
nxpfan 0:bdbcdf6f3e8a 136 svr.bind(80);
nxpfan 0:bdbcdf6f3e8a 137
nxpfan 0:bdbcdf6f3e8a 138 lcd.locate( 5, position() -1 );
nxpfan 0:bdbcdf6f3e8a 139 lcd.printf("Listening");
nxpfan 0:bdbcdf6f3e8a 140
nxpfan 0:bdbcdf6f3e8a 141 Timer tm;
nxpfan 0:bdbcdf6f3e8a 142 tm.start();
nxpfan 0:bdbcdf6f3e8a 143 //Listen indefinitely
nxpfan 0:bdbcdf6f3e8a 144 while (true) {
nxpfan 0:bdbcdf6f3e8a 145 Net::poll();
nxpfan 0:bdbcdf6f3e8a 146 if (tm.read()>.5) {
nxpfan 0:bdbcdf6f3e8a 147 led1=!led1; //Show that we are alive
nxpfan 0:bdbcdf6f3e8a 148 tm.start();
nxpfan 0:bdbcdf6f3e8a 149 }
nxpfan 0:bdbcdf6f3e8a 150 }
nxpfan 0:bdbcdf6f3e8a 151 }
nxpfan 0:bdbcdf6f3e8a 152
nxpfan 0:bdbcdf6f3e8a 153
nxpfan 0:bdbcdf6f3e8a 154 int position( void ) {
nxpfan 0:bdbcdf6f3e8a 155 static int p = 0;
nxpfan 0:bdbcdf6f3e8a 156
nxpfan 0:bdbcdf6f3e8a 157 #ifdef USE_TextLCD_20x4
nxpfan 0:bdbcdf6f3e8a 158 return( ++p % 4 );
nxpfan 0:bdbcdf6f3e8a 159 #else
nxpfan 0:bdbcdf6f3e8a 160 return( ++p % 2 );
nxpfan 0:bdbcdf6f3e8a 161 #endif
nxpfan 0:bdbcdf6f3e8a 162 }
nxpfan 0:bdbcdf6f3e8a 163