--- trunk/PIC/Demo trimmet/TFTPcDemo.c 2007/05/25 14:20:54 101 +++ trunk/PIC/Demo trimmet/TFTPcDemo.c 2007/05/25 16:00:14 102 @@ -10,6 +10,7 @@ #include "tcp.h" bit bIsDhcpUp = 0; +char netlevel = 0; // All TFTP command statuts display will be done on first line of LCD. //#define TFTP_COMMAND_DISPLAY_LINE 0 @@ -18,7 +19,7 @@ #define TFTP_COMMAND_RESULT_POSITION 15 -#define STARTUP_MSG "G1_Build_0x00" +/*#define STARTUP_MSG "G1_Build_0x00" ROM char StartupMsg[] = STARTUP_MSG; @@ -30,7 +31,7 @@ // 1234567890123456 //ROM char blankLCDLine[] = " "; - +*/ /* * This is used by other stack elements. * Main application must define this and initialize it with @@ -81,6 +82,8 @@ SockOpen, TcpReadyToSend, TcpSend, + HelloDone, + StregkodeDone, SockClosing, SockClosed } NetworkState; @@ -106,96 +109,142 @@ } +void network_worker(void) +{ + TickGet(); + StackTask(); +} + +void network_wait(unsigned char n) +{ + int i; + for (i=0; i= 0; i--) - { - TCPPut(tsock1, stregkode ); - } - TCPFlush(tsock1); - state = TcpReadyToSend; - return 1; + switch (state) + { + case HelloDone: + if ( TCPIsConnected(tsock1) && TCPIsPutReady(tsock1) ) + state = TcpSend; + case TcpSend: + TCPPut( tsock1, 0x01 ); + for (i = 0; i < buflen; i++) + { + TCPPut(tsock1, stregkode[i] ); + } + TCPFlush(tsock1); + state = StregkodeDone; + break; + } + network_worker(); } + return 0; } char network_send_goodbye(void) { - switch (state) + while( state != SockClosed) { - case TcpReadyToSend: - if ( TCPIsConnected(tsock1) && TCPIsPutReady(tsock1) ) - state = TcpSend; + switch (state) + { + case TcpReadyToSend: + if ( TCPIsConnected(tsock1) && TCPIsPutReady(tsock1) ) + state = TcpSend; + break; + + case TcpSend: + TCPPut( tsock1, 0x06 ); + TCPFlush( tsock1 ); + state = SockClosing; + break; - case TcpSend: - TCPPut( tsock1, 0x06 ); - TCPFlush( tsock1 ); - state = SockClosing; - return 0; - - case SockClosing: - TCPDisconnect( tsock1 ); - state = SockClosed; - return 1; + case SockClosing: + TCPDisconnect( tsock1 ); + state = SockClosed; + break; + } + network_worker(); } - return 3; // Didn't close the socket properly; + if( TCPIsConnected(tsock1) ) + return 3; // Didn't close the socket properly; + else + return 0; + +} +void network_wait_for_dhcp() +{ + while (!DHCPIsBound()) + network_worker(); } void main(void) @@ -206,7 +255,8 @@ char sock_state = 0; char is_resolved = 0; char has_arp = 0; - char a; + char a = 1; + TICK tick; TICK lastTick; @@ -279,30 +329,16 @@ * For DHCP information, display how many times we have renewed the IP * configuration since last reset. */ - - a = network_send_hello( 0x01 ); -// a = network_send_scan_frame( stregkode, antal ); - a = network_send_goodbye(); - + + a = network_send_hello( 0x01 ); + a = network_send_scan_frame( stregkode, antal ); + a = network_send_goodbye(); } } -#if defined(MCHP_C18) - #pragma interrupt HighISR save=section(".tmpdata") - void HighISR(void) -#elif defined(HITECH_C18) - #if defined(STACK_USE_SLIP) - extern void MACISR(void); - #endif - void interrupt HighISR(void) -#endif +void interrupt HighISR(void) { TickUpdate(); -/* -#if defined(STACK_USE_SLIP) - MACISR(); -#endif -*/ } #if defined(MCHP_C18)