Changeset 11667 for firmware/FSC/src/w5100_spi_interface.c
- Timestamp:
- 07/27/11 18:57:59 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FSC/src/w5100_spi_interface.c
r10911 r11667 12 12 // INTERFACE CONTROL VARS 13 13 14 bool w5100_needs_reset = true;15 14 bool w5100_needs_init = true; 16 15 bool w5100_ready = false; 17 16 17 U16 last_samurai = 0x0000; 18 18 19 U08 w5100_caretaker() { 19 20 U08 socket_status; 20 if (w5100_needs_reset) 21 w5100_reset(); 22 21 23 22 socket_status = w5100_sock_status(); 23 //usart_write_str((pU08)"ss:"); 24 //usart_write_U08_hex(socket_status); 25 //usart_write_char(' '); 24 26 25 27 if (socket_status == SR_SOCK_ESTABLISHED) { 26 28 w5100_ready = true; 27 28 29 // everything is fine... 29 return 0; 30 } 31 else if(socket_status < SR_SOCK_ESTABLISHED) { 32 // it might be LISTENING ... or not even OPEN 33 if (socket_status == SR_SOCK_CLOSED) { 30 } 31 else if (socket_status == SR_SOCK_LISTEN) { 32 w5100_ready = false; 33 // wait for connection 34 } 35 else { 36 socket_status = w5100_sock_status(); 37 //usart_write_str((pU08)"ss2:"); 38 //usart_write_U08_hex(socket_status); 39 //usart_write_char(' '); 40 41 if (socket_status == SR_SOCK_ESTABLISHED) { 42 w5100_ready = true; 43 // everything is fine... 44 } 45 else if (socket_status == SR_SOCK_LISTEN) { 46 w5100_ready = false; 47 // wait for connection 48 } 49 else 50 { 51 // this should never happen 52 w5100_ready = false; 53 w5100_reset(); 34 54 w5100_init(); 35 55 } 36 if (socket_status == SR_SOCK_INIT) { 37 w5100_init(); 38 } 39 if (socket_status == SR_SOCK_LISTEN) { 40 41 } 42 } 43 else { // all other socket states need a reset 44 w5100_needs_reset = true; 45 } 46 w5100_ready = false; 47 return 1; 56 } 57 58 //usart_write_crlf(); 59 return socket_status; 48 60 } 49 61 … … 54 66 PORTB |= 1<<PB2; //#reset = HIGH --> W5100 is active 55 67 _delay_ms(5); // give it 5ms to accomodate. 56 w5100_needs_reset = false;57 68 } 58 69 … … 165 176 { 166 177 U16 freesize; 167 freesize=w5100_read(S0_TX_FSR0); 168 freesize = freesize << 8; 178 freesize=w5100_read(S0_TX_FSR0); // datasheet: user should read upper byte first, and lower byte later 179 freesize = freesize << 8; // to get correct value 169 180 freesize += w5100_read(S0_TX_FSR1); 170 181 return freesize; … … 195 206 { 196 207 U16 received_size; 197 received_size=w5100_read(S0_RX_RSR0); 198 received_size = received_size << 8; 199 received_size += w5100_read(S0_RX_RSR1); // S0_RX_RSR1 is the least significant byte ... 200 return received_size; 208 U08 highbyte, lowbyte; 209 highbyte = w5100_read(S0_RX_RSR0); 210 lowbyte = w5100_read(S0_RX_RSR1); 211 received_size = (highbyte<<8) | lowbyte; 212 213 // usart_write_str((pU08)"hi:"); 214 // usart_write_U08_hex(highbyte); 215 // usart_write_crlf(); 216 // 217 // usart_write_str((pU08)"lo:"); 218 // usart_write_U08_hex(lowbyte); 219 // usart_write_crlf(); 220 // 221 // usart_write_str((pU08)"total:"); 222 // usart_write_U16_hex(received_size); 223 // usart_write_crlf(); 224 225 // _delay_ms(200); 226 227 return received_size; 201 228 } 202 229 … … 205 232 { 206 233 U16 readpointer; 207 readpointer=w5100_read(S0_RX_RD0); 234 readpointer=w5100_read(S0_RX_RD0); 208 235 readpointer = readpointer << 8; 209 236 readpointer += w5100_read(S0_RX_RD1); … … 217 244 U08 high_byte = (value>>8); 218 245 U08 low_byte = value&0x00FF; 246 w5100_write(S0_TX_WR0, high_byte); 219 247 w5100_write(S0_TX_WR1, low_byte); 220 w5100_write(S0_TX_WR0, high_byte);221 222 248 } 223 249 … … 227 253 U08 high_byte = (value>>8); 228 254 U08 low_byte = value&0x00FF; 229 230 255 w5100_write(S0_RX_RD0, high_byte); 231 256 w5100_write(S0_RX_RD1, low_byte); … … 255 280 U16 start_address = S0_RX_BASE + offset; 256 281 282 usart_write_str((pU08)"lrp:"); 283 usart_write_U16_hex(last_RX_read_pointer); 284 usart_write_crlf(); 285 usart_write_str((pU08)"off:"); 286 usart_write_U16_hex(offset); 287 usart_write_crlf(); 288 usart_write_str((pU08)"sad:"); 289 usart_write_U16_hex(start_address); 290 usart_write_crlf(); 291 292 257 293 if ((offset + NumBytes) > (S0_RX_MASK + 1) ) // if data is turned over in RX-mem 258 294 { … … 277 313 278 314 // inform W5100 about how much data was read out. 279 set_S0_RX_RD(last_RX_read_pointer + NumBytes); 315 U16 new_read_pointer = last_RX_read_pointer + NumBytes; 316 usart_write_str((pU08)"nrp:"); 317 usart_write_U16_hex(new_read_pointer); 318 usart_write_crlf(); 319 320 set_S0_RX_RD(new_read_pointer); 280 321 w5100_write ( S0_CR, CR_RECV ); 281 322 … … 305 346 U16 w5100_set_TX(U08* string, U16 NumBytes) { 306 347 307 U16 freesize = get_S0_TX_FSR(); 348 U08 repetitions; 349 U16 freesize; 350 U16 last_TX_write_pointer; 351 352 //usart_write_str((pU08)"S0_IR:"); 353 //usart_write_U08_hex( w5100_read(S0_IR) ); 354 //usart_write_crlf(); 355 356 freesize = get_S0_TX_FSR(); 357 for (repetitions=0 ; repetitions < 3; ) // increase is *inside the loop* 358 { 359 if ( freesize != get_S0_TX_FSR()) { 360 freesize = get_S0_TX_FSR(); 361 } else { 362 repetitions++; 363 } 364 } 365 308 366 if (freesize == 0) 309 367 { … … 311 369 } 312 370 313 U16 last_TX_write_pointer = get_S0_TX_WR(); 371 last_TX_write_pointer = get_S0_TX_WR(); 372 for (repetitions=0 ; repetitions < 3; ) // increase is *inside the loop* 373 { 374 if ( last_TX_write_pointer != get_S0_TX_WR()) { 375 last_TX_write_pointer = get_S0_TX_WR(); 376 } else { 377 repetitions++; 378 } 379 } 380 314 381 U16 offset = last_TX_write_pointer & S0_TX_MASK; 315 382 U16 start_address = S0_TX_BASE + offset; 316 383 317 usart_write_crlf(); 318 usart_write_crlf(); 319 usart_write_str((pU08)"lwp :"); 320 usart_write_U16_hex(last_TX_write_pointer); 321 usart_write_crlf(); 322 323 usart_write_str((pU08)"off :"); 324 usart_write_U16_hex(offset); 325 usart_write_crlf(); 326 327 usart_write_str((pU08)"stad:"); 328 usart_write_U16_hex(start_address); 329 usart_write_crlf(); 384 if (last_samurai != last_TX_write_pointer) 385 usart_write_str((pU08)"Hilfeeeeeeeeeeeeeee\n"); 386 387 //usart_write_crlf(); 388 //usart_write_char('|');usart_write_U16_hex( last_TX_write_pointer ); 389 //usart_write_char('|');usart_write_U16_hex( offset ); 390 //usart_write_char('|');usart_write_U16_hex( start_address ); 391 392 393 //usart_write_crlf(); 394 //usart_write_crlf(); 395 //usart_write_str((pU08)"lwp :"); 396 //usart_write_U16_hex(last_TX_write_pointer); 397 //usart_write_crlf(); 398 // 399 //usart_write_str((pU08)"off :"); 400 //usart_write_U16_hex(offset); 401 //usart_write_crlf(); 402 // 403 //usart_write_str((pU08)"stad:"); 404 //usart_write_U16_hex(start_address); 405 //usart_write_crlf(); 330 406 331 407 … … 345 421 NumBytes = freesize; 346 422 } 347 423 //usart_write_char('|');usart_write_U16_hex( NumBytes ); 424 348 425 // now calculate the offset address 349 426 // calculated according to W5100 datasheet page: 44 350 351 427 if ((offset + NumBytes) > (S0_RX_MASK + 1) ) // if data is turned over in RX-mem 352 428 { … … 356 432 { 357 433 w5100_write(start_address + i, string[i]); 358 usart_write_str((pU08)"wr:");359 usart_write_U16_hex(start_address + i);360 usart_write_char(' ');361 usart_write_char(string[i]);362 usart_write_crlf();434 //usart_write_str((pU08)"wr:"); 435 //usart_write_U16_hex(start_address + i); 436 //usart_write_char(' '); 437 //usart_write_char(string[i]); 438 //usart_write_crlf(); 363 439 364 440 } … … 366 442 { 367 443 w5100_write(S0_RX_BASE + i, string[upper_size+i]); 368 usart_write_str((pU08)"wr:");369 usart_write_U16_hex(S0_RX_BASE + i);370 usart_write_char(' ');371 usart_write_char(string[upper_size+i]);372 usart_write_crlf();444 //usart_write_str((pU08)"wr:"); 445 //usart_write_U16_hex(S0_RX_BASE + i); 446 //usart_write_char(' '); 447 //usart_write_char(string[upper_size+i]); 448 //usart_write_crlf(); 373 449 374 450 } … … 379 455 { 380 456 w5100_write(start_address + i, string[i]); 381 usart_write_str((pU08)"wr:");382 usart_write_U16_hex(start_address + i);383 usart_write_char(' ');384 usart_write_char(string[i]);385 usart_write_crlf();457 //usart_write_str((pU08)"wr:"); 458 //usart_write_U16_hex(start_address + i); 459 //usart_write_char(' '); 460 //usart_write_char(string[i]); 461 //usart_write_crlf(); 386 462 387 463 } … … 389 465 390 466 // inform W5100 about how much data was written. 391 set_S0_TX_WR(last_TX_write_pointer + NumBytes); 392 usart_write_str((pU08)"wrpt:"); 393 usart_write_U16_hex(last_TX_write_pointer + NumBytes); 394 usart_write_crlf(); 467 U16 new_write_pointer = last_TX_write_pointer + NumBytes; 468 last_samurai = new_write_pointer; 469 470 471 set_S0_TX_WR(new_write_pointer); 472 //usart_write_char('|');usart_write_U16_hex( new_write_pointer ); 473 474 //usart_write_char('|'); 475 //usart_write_crlf(); 476 477 478 //usart_write_str((pU08)"wrpt:"); 479 //usart_write_U16_hex(last_TX_write_pointer + NumBytes); 480 //usart_write_crlf(); 395 481 396 482 // tell it to send now the data away 397 483 w5100_write( S0_CR, CR_SEND); 484 485 398 486 399 487 return NumBytes; … … 427 515 } 428 516 517 void eth_write_lf(void) { 518 if (eth_write_index < ETH_WRITE_BUFFER_SIZE) { 519 eth_write_buffer[eth_write_index++] = '\n'; 520 } 521 w5100_set_TX(eth_write_buffer, eth_write_index); 522 eth_write_index = 0; 523 }
Note:
See TracChangeset
for help on using the changeset viewer.