/[H8]/trunk/PIC/Demo trimmet/TFTPcDemo.c
ViewVC logotype

Diff of /trunk/PIC/Demo trimmet/TFTPcDemo.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 92 by hedin, Wed May 16 09:24:33 2007 UTC revision 93 by hedin, Wed May 16 15:46:08 2007 UTC
# Line 1  Line 1 
 /*********************************************************************  
  *  
  *                  TFTP Client Demo App for Microchip TCP/IP Stack  
  *  
  *********************************************************************  
  * FileName:        TFTPcDemo.c  
  * Dependencies:    tftpc.h  
  *                  stacktsk.h  
  *                  xlcd.h  
  *                  tick.h  
  * Processor:       PIC18  
  * Complier:        MCC18 v1.00.50 or higher  
  *                  HITECH PICC-18 V8.10PL1 or higher  
  * Company:         Microchip Technology, Inc.  
  *  
  * Software License Agreement  
  *  
  * The software supplied herewith by Microchip Technology Incorporated  
  * (the “Company”) for its PICmicro® Microcontroller is intended and  
  * supplied to you, the Company’s customer, for use solely and  
  * exclusively on Microchip PICmicro Microcontroller products. The  
  * software is owned by the Company and/or its supplier, and is  
  * protected under applicable copyright laws. All rights are reserved.  
  * Any use in violation of the foregoing restrictions may subject the  
  * user to criminal sanctions under applicable laws, as well as to  
  * civil liability for the breach of the terms and conditions of this  
  * license.  
  *  
  * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,  
  * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED  
  * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A  
  * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,  
  * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR  
  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.  
  *  
  * Author               Date    Comment  
  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
  * Nilesh Rajbharti     8/7/03  Original        (Rev 1.0)  
  *  
  *  
  * This demo application demonstartes Microchip TFTP client module usage  
  * See TFTPDemo(), TFTPWrite() and TFTPRead() for actual implementation.  
  *  
  * This application monitors RB5 switch. On first push it  
  * writes 'tftpwr.bin' file to server.  tftpwr.bin file is made up of  
  * first 16KB of program memory.  
  * On second push, it reads 'tftprd.txt' file from server.  
  *  
  * Server IP address is set in "Board Setup" mode using Hyperterminal.  
  *  
  * It displays rotating '-' to indicate command in progress.  
  * 'Y' to indicate success  
  * 'N' for failure  
  * 'T' for timeout  
  * 'E' for error.  
  *  
  *  
  * If running this applicaton on PICDEM.net use  
  * HS Oscillator  
  * Debug disabled  
  * Low Voltage Disabled  
  * Watchdog timer disabled  
  ********************************************************************/  
 /*  
  * Following define uniquely deines this file as main  
  * entry/application In whole project, there should only be one such  
  * definition and application file must define AppConfig variable as  
  * described below.  
  */  
1  #define THIS_IS_STACK_APPLICATION  #define THIS_IS_STACK_APPLICATION
2    
3  #include "stacktsk.h"  #include "stacktsk.h"
# Line 77  Line 8 
8  #include "udp.h"  #include "udp.h"
9  #include "arp.h"  #include "arp.h"
10  #include "arptsk.h"  #include "arptsk.h"
11    #include "tcp.h"
12    
13    
14  // All TFTP command statuts display will be done on first line of LCD.  // All TFTP command statuts display will be done on first line of LCD.
# Line 137  static void InitializeBoard(void); Line 69  static void InitializeBoard(void);
69  static void DisplayIPValue(IP_ADDR *IPVal, BOOL bToLCD);  static void DisplayIPValue(IP_ADDR *IPVal, BOOL bToLCD);
70  static void SetConfig(void);  static void SetConfig(void);
71    
72    /*void network_send_hello( unsigned char termid )
73    {
74               if (DHCPIsBound())
75            {
76                    RA3 =0;
77                    if (sock_open == 0)
78                    {
79                            if (ARPIsTxReady())
80                            {
81                                    if (is_resolved == 0)
82                                    {
83                                            ARPResolve( &rnode.IPAddr);
84                                            is_resolved = 1;
85                                    }
86                                    else
87                                    {
88                                            if (ARPIsResolved( &rnode.IPAddr, &rnode.MACAddr))
89                                            //if (MyArp( &rnode))
90                                            {
91                                                    usock1=UDPOpen(2000,&rnode,3000); // socket to send UDP
92                                                    sock_open=1;
93                                            }
94                                    }      
95                            }
96                    }
97                    
98                    if (UDPIsPutReady(usock1) && datagrams_to_send>0)
99                    {
100                            UDPPut( rnode.MACAddr.v[0] );
101                            UDPPut( rnode.MACAddr.v[1] );
102                            UDPPut( rnode.MACAddr.v[2] );
103                            UDPPut( rnode.MACAddr.v[3] );
104                            UDPPut( rnode.MACAddr.v[4] );
105                            UDPPut( rnode.MACAddr.v[5] );
106                            UDPPut('D');
107                            UDPPut('a');
108                            UDPPut('w');
109                            UDPPut(0);
110                            UDPFlush();
111                            datagrams_to_send--;
112                    }
113                    }
114    }
115    */
116    
117    void WriteTcpStatus(char status)
118    {
119            XLCDGoto(0,0);
120            status += 'a';
121            XLCDPut(status);
122            
123    }
124    
125  void main(void)  void main(void)
126  {  {
127      // Tick to blink SYSTEM led.      // Tick to blink SYSTEM led.
128      static TICK t = 0;      static TICK t = 0;
129      UDP_SOCKET usock1;      TCP_SOCKET usock1;
130      NODE_INFO rnode;      NODE_INFO rnode;
131      char datagrams_to_send = 10;      char sock_state = 0;
     char sock_open = 0;  
132      char is_resolved = 0;      char is_resolved = 0;
133        char has_arp = 0;
134                    
135        TICK tick;
136        TICK lastTick;
137            TICK diffTicks;
138    
139      /*      /*
140       * Initialize any application specific hardware.       * Initialize any application specific hardware.
# Line 253  void main(void) Line 241  void main(void)
241              }              }
242          }          }
243                    
244            WriteTcpStatus( TCB[usock1].smState );
245            
246          if (DHCPIsBound())          if (DHCPIsBound())
247          {          {
248                  RA3 =0;                  RA3 =0;
249                  if (sock_open == 0)                  if (has_arp == 0)
250                  {                  {
251                          if (ARPIsTxReady())                          if (ARPIsTxReady())
252                          {                          {
# Line 268  void main(void) Line 258  void main(void)
258                                  else                                  else
259                                  {                                  {
260                                          if (ARPIsResolved( &rnode.IPAddr, &rnode.MACAddr))                                          if (ARPIsResolved( &rnode.IPAddr, &rnode.MACAddr))
                                         //if (MyArp( &rnode))  
261                                          {                                          {
262                                                  usock1=UDPOpen(2000,&rnode,3000); // socket to send UDP                                                          has_arp = 1;
                                                 sock_open=1;  
263                                          }                                          }
264                                  }                                  }
265            
   
                                           
266                          }                          }
267                  }                  }
268                                    
269                  if (UDPIsPutReady(usock1) && datagrams_to_send>0)                  if (has_arp == 1)
270                  {                  {
271                          UDPPut( rnode.MACAddr.v[0] );                          if (sock_state == 0)
272                          UDPPut( rnode.MACAddr.v[1] );                          {
273                          UDPPut( rnode.MACAddr.v[2] );                          usock1=TCPConnect(&rnode,3000);
274                          UDPPut( rnode.MACAddr.v[3] );                                  sock_state = 1;
275                          UDPPut( rnode.MACAddr.v[4] );                          }
276                          UDPPut( rnode.MACAddr.v[5] );                          if (sock_state ==1 && TCPIsConnected(usock1) && TCPIsPutReady(usock1))
277                          UDPPut('D');                          {
278                          UDPPut('a');                                  TCPPut(usock1,'D');
279                          UDPPut('w');                                  TCPPut(usock1,'a');
280                          UDPPut(0);                                  TCPPut(usock1,'w');
281                          UDPFlush();                                  TCPPut(usock1,0);
282                          datagrams_to_send--;                          TCPFlush(usock1);
283                  }                                  sock_state = 2;
284                            }
285                    
286                            if (sock_state == 2 && TCPIsPutReady(usock1))
287                        {
288                                    TCPDisconnect(usock1);
289                                    lastTick = TickGet();
290                                    sock_state =3;
291                            }
292                            tick = TickGet();
293                            diffTicks = TickGetDiff(tick, lastTick);
294                            
295                            if ( sock_state == 3 && diffTicks > ((TICK)TICK_SECOND * (TICK)2) )
296                                    sock_state = 0;
297                                    
298                        }
299          }          }
300      }      }
301  }  }

Legend:
Removed from v.92  
changed lines
  Added in v.93

  ViewVC Help
Powered by ViewVC 1.1.20