BOOTLOADER
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
tftp.c
Go to the documentation of this file.
1 /******************************************************
2 * Function: Do tftp download function
3 *
4 * File: Tftp.c
5 * Author: Book Chen
6 * Date: 2008.07.18
7 *******************************************************
8 */
9 #include "includes.h"
10 
11 #define TftpIdleState 0
12 #define TftpCs8900InitialState0 1
13 #define TftpCs8900InitialState1 2
14 #define TftpCs8900DownloadState0 3
15 #define TftpCs8900FinishState 4
16 #define TftpDm9000InitialState0 5
17 #define TftpDm9000InitialState1 6
18 #define TftpDm9000DownloadState0 7
19 #define TftpDm9000FinishState 8
20 
21 #define Tftp_DOWNLOAD_ADDRESS IMAGE_ADDRESS
22 INT8U EthernetMacAddress[ETHERNET_MAC_LENGTH]={0x00,0x80,0x48,0x12,0x34,0x56};
25 
26 void F_TftpInit(void);
27 void F_TftpSvc(void);
28 void F_TftpPlay(void);
30 
31 void F_TftpInit(void){
32  TftpCtrl.i=0;
33  TftpCtrl.IpAddress[0]=EthernetIpAddress[0];
34  TftpCtrl.IpAddress[1]=EthernetIpAddress[1];
35  TftpCtrl.IpAddress[2]=EthernetIpAddress[2];
36  TftpCtrl.IpAddress[3]=EthernetIpAddress[3];
37  TftpCtrl.MacAddress[0]=EthernetMacAddress[0];
38  TftpCtrl.MacAddress[1]=EthernetMacAddress[1];
39  TftpCtrl.MacAddress[2]=EthernetMacAddress[2];
40  TftpCtrl.MacAddress[3]=EthernetMacAddress[3];
41  TftpCtrl.MacAddress[4]=EthernetMacAddress[4];
42  TftpCtrl.MacAddress[5]=EthernetMacAddress[5];
44  TftpCtrl.DownloadLength=0;
45  TftpCtrl.InUse=FALSE;
46  TftpCtrl.Id=ID_TFTP_MW;
47  TftpCtrl.State=TftpIdleState;
48 }
49 void F_TftpSvc(void){
50  //INT32U i;
51  //INT16U i,j,k,l,m,n,o,p;
52 
53  switch(TftpCtrl.State){
54  case TftpIdleState:
55  break;
57  if(F_Cs8900InUseCheck()==TRUE) return;
58  printf("\n mini tftp server 1.0");
59  printf("\n cs8900 initial");
60  F_Cs8900Allocate(TftpCtrl.Id);
63  F_Cs8900InitialStart(TftpCtrl.Id);
64  F_Cs8900Release(TftpCtrl.Id);
66  break;
68  if(F_Cs8900ReadyCheck()==FALSE) return;
70  printf("\n cs8900 initial fail");
71  TftpCtrl.State=TftpIdleState;
72  return;
73  }
74  //******
75  // ETHERNET initial
76  //******
77  printf("\n ETHERNET initial");
78 
79  printf("\n ETHERNET MAC %2x %2x %2x %2x %2x %2x ",TftpCtrl.MacAddress[0],
80  TftpCtrl.MacAddress[1],
81  TftpCtrl.MacAddress[2],
82  TftpCtrl.MacAddress[3],
83  TftpCtrl.MacAddress[4],
84  TftpCtrl.MacAddress[5]);
85  printf("\n ETHERNET IP %2x %2x %2x %2x ",TftpCtrl.IpAddress[0],
86  TftpCtrl.IpAddress[1],
87  TftpCtrl.IpAddress[2],
88  TftpCtrl.IpAddress[3]);
89  F_EthernetInit();
90  F_EthernetAllocate(TftpCtrl.Id);
93  F_EthernetRelease(TftpCtrl.Id);
94  //******
95  // Arp initial
96  //******
97  printf("\n ARP initial");
99  F_EthernetArpAllocate(TftpCtrl.Id);
101  F_EthernetArpRelease(TftpCtrl.Id);
102  //******
103  // Ip initial
104  //******
105  printf("\n IP initial");
106  F_EthernetIpInit();
107  F_EthernetIpAllocate(TftpCtrl.Id);
109  F_EthernetIpRelease(TftpCtrl.Id);
110  //******
111  // ICMP initial
112  //******
113  printf("\n ICMP initial");
115  //******
116  // Udp initial
117  //******
118  printf("\n UDP initial");
119  F_EthernetUdpInit(); // do nothing;
120  //******
121  // TFTP initial
122  //******
123  printf("\n TFTP initial");
125  F_EthernetTftpAllocate(TftpCtrl.Id);
126  F_EthernetTftpAddressSet(TftpCtrl.Id,TftpCtrl.DownloadAddress);
127  printf("\n Download start");
128  //TftpCtrl.State=TftpIdleState;
130  break;
133  /*TftpCtrl.i++;
134  if(TftpCtrl.i>=50000){
135  TftpCtrl.i=0;
136  i=F_Cs8900IoRegisterRead(IO_INT_STATSU_QUEUE);
137  i=F_Cs8900RegisterRead(PKTPG_IO_BASE_ADDR);
138  j=F_Cs8900RegisterRead(PKTPG_RX_STATUS);
139  k=F_Cs8900RegisterRead(PKTPG_RX_LENGTH);
140  l=F_Cs8900RegisterRead(PKTPG_RX_FRAME);
141  m=F_Cs8900RegisterRead(PKTPG_RX_CFG);
142  n=F_Cs8900RegisterRead(PKTPG_RX_CTL);
143  o=F_Cs8900RegisterRead(PKTPG_TX_CFG);
144  p=F_Cs8900RegisterRead(PKTPG_TX_CMD_ST);
145 
146  printf("\n Io %4x RxStatus %4x RxLength %4x RxLocation %4x",i,j,k,l);
147  printf(" RX_CFG %4x RX_CTL %4x TX_CFG %4x TX_CMD_ST %4x",m,n,o,p);
148 
149  }*/
150  if(F_EthernetTftpDownloadCheck()==TRUE){ //check if download ok
151  TftpCtrl.State=TftpCs8900FinishState;
152  }
153  break;
154  case TftpCs8900FinishState:
155  if(EthTftpCtrl.Length==0) printf("\n tftp download 0 bytes");
156  else printf("\n receive %x bytes success",EthTftpCtrl.Length);
157  F_EthernetTftpReset(TftpCtrl.Id);
158  F_EthernetTftpRelease(TftpCtrl.Id);
159  printf("\n done \n ARM:>");
160  TftpCtrl.State=TftpIdleState;
161  break;
163  if(F_Dm9000InUseCheck()==TRUE) return;
164  printf("\n mini tftp server 1.0");
165  printf("\n dm9000a initial");
166  F_Dm9000Allocate(TftpCtrl.Id);
169  F_Dm9000InitialStart(TftpCtrl.Id);
170  F_Dm9000Release(TftpCtrl.Id);
172  //TftpCtrl.State=TftpIdleState;
173  break;
175  if(F_Dm9000ReadyCheck()==FALSE) return;
177  printf("\n dm9000a initial fail");
178  TftpCtrl.State=TftpIdleState;
179  return;
180  }
181  //TftpCtrl.State=TftpIdleState;
182  //return;
183 
184  //******
185  // ETHERNET initial
186  //******
187  printf("\n ETHERNET initial");
188 
189  printf("\n ETHERNET MAC %2x %2x %2x %2x %2x %2x ",TftpCtrl.MacAddress[0],
190  TftpCtrl.MacAddress[1],
191  TftpCtrl.MacAddress[2],
192  TftpCtrl.MacAddress[3],
193  TftpCtrl.MacAddress[4],
194  TftpCtrl.MacAddress[5]);
195  printf("\n ETHERNET IP %2x %2x %2x %2x ",TftpCtrl.IpAddress[0],
196  TftpCtrl.IpAddress[1],
197  TftpCtrl.IpAddress[2],
198  TftpCtrl.IpAddress[3]);
199  F_EthernetInit();
200  F_EthernetAllocate(TftpCtrl.Id);
203  F_EthernetRelease(TftpCtrl.Id);
204 
205  //******
206  // Arp initial
207  //******
208  printf("\n ARP initial");
210  F_EthernetArpAllocate(TftpCtrl.Id);
212  F_EthernetArpRelease(TftpCtrl.Id);
213  //******
214  // Ip initial
215  //******
216  printf("\n IP initial");
217  F_EthernetIpInit();
218  F_EthernetIpAllocate(TftpCtrl.Id);
220  F_EthernetIpRelease(TftpCtrl.Id);
221  //******
222  // ICMP initial
223  //******
224  printf("\n ICMP initial");
226  //******
227  // Udp initial
228  //******
229  printf("\n UDP initial");
230  F_EthernetUdpInit(); // do nothing;
231  //******
232  // TFTP initial
233  //******
234  printf("\n TFTP initial");
236  F_EthernetTftpAllocate(TftpCtrl.Id);
237  F_EthernetTftpAddressSet(TftpCtrl.Id,TftpCtrl.DownloadAddress);
238  printf("\n Download start");
239  //TftpCtrl.State=TftpIdleState;
241  break;
244  /*TftpCtrl.i++;
245  if(TftpCtrl.i>=50000){
246  TftpCtrl.i=0;
247  i=F_Cs8900IoRegisterRead(IO_INT_STATSU_QUEUE);
248  i=F_Cs8900RegisterRead(PKTPG_IO_BASE_ADDR);
249  j=F_Cs8900RegisterRead(PKTPG_RX_STATUS);
250  k=F_Cs8900RegisterRead(PKTPG_RX_LENGTH);
251  l=F_Cs8900RegisterRead(PKTPG_RX_FRAME);
252  m=F_Cs8900RegisterRead(PKTPG_RX_CFG);
253  n=F_Cs8900RegisterRead(PKTPG_RX_CTL);
254  o=F_Cs8900RegisterRead(PKTPG_TX_CFG);
255  p=F_Cs8900RegisterRead(PKTPG_TX_CMD_ST);
256 
257  printf("\n Io %4x RxStatus %4x RxLength %4x RxLocation %4x",i,j,k,l);
258  printf(" RX_CFG %4x RX_CTL %4x TX_CFG %4x TX_CMD_ST %4x",m,n,o,p);
259 
260  }*/
261  if(F_EthernetTftpDownloadCheck()==TRUE){ //check if download ok
262  TftpCtrl.State=TftpDm9000FinishState;
263  }
264  break;
266  if(EthTftpCtrl.Length==0) printf("\n tftp download 0 bytes");
267  else printf("\n receive %x bytes success",EthTftpCtrl.Length);
268  F_EthernetTftpReset(TftpCtrl.Id);
269  F_EthernetTftpRelease(TftpCtrl.Id);
270  printf("\n done \n ARM:>");
271  TftpCtrl.State=TftpIdleState;
272  break;
273  }
274 }
275 void F_TftpPlay(void){
276  //TftpCtrl.State=TftpCs8900InitialState0;
277  TftpCtrl.State=TftpDm9000InitialState0;
278 }
280  if(TftpCtrl.State==TftpIdleState) return TRUE;
281  else return FALSE;
282 }