- Timestamp:
- 03/18/14 16:26:33 (11 years ago)
- Location:
- firmware/FSC/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
firmware/FSC/src/w5100_spi_interface.c
r11696 r17631 3 3 #include "w5100_spi_interface.h" 4 4 #include "spi_master.h" 5 #include "usart.h"5 //#include "usart.h" 6 6 volatile BOOL sock0_connection_established = false; 7 7 volatile U08 eth_read_buffer[ETH_READ_BUFFER_SIZE]; … … 173 173 // getters of TX and RX registers 174 174 // S0_TX_FSR 175 U16 get_S0_TX_FSR() 176 {177 U16 freesize;178 freesize=w5100_read(S0_TX_FSR0); // datasheet: user should read upper byte first, and lower byte later179 freesize = freesize << 8; // to get correct value180 freesize += w5100_read(S0_TX_FSR1);181 return freesize;175 // Contains Socket free size in bytes 176 U16 get_S0_TX_FSR() { 177 U16 freesize; 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 180 freesize += w5100_read(S0_TX_FSR1); 181 return freesize; 182 182 } 183 183 … … 280 280 U16 start_address = S0_RX_BASE + offset; 281 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();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 291 292 292 … … 314 314 // inform W5100 about how much data was read out. 315 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();316 //usart_write_str((pU08)"nrp:"); 317 //usart_write_U16_hex(new_read_pointer); 318 //usart_write_crlf(); 319 319 320 320 set_S0_RX_RD(new_read_pointer); … … 343 343 } 344 344 345 // returns number of words, transmitted into TX - buffer.345 // returns number of bytes, transmitted into TX - buffer. 346 346 U16 w5100_set_TX(U08* string, U16 NumBytes) { 347 347 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 366 if (freesize == 0) 367 { 368 return 0; 369 } 370 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 381 U16 offset = last_TX_write_pointer & S0_TX_MASK; 382 U16 start_address = S0_TX_BASE + offset; 383 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(); 406 407 408 U16 upper_size, lower_size; 409 /* 410 if (NumBytes > ETH_WRITE_BUFFER_SIZE) 411 { 412 NumBytes = ETH_WRITE_BUFFER_SIZE; 413 } 414 if (freesize == 0) 415 { 416 return 0; 417 } 418 else */ 419 if ( freesize < NumBytes ) 420 { 421 NumBytes = freesize; 422 } 423 //usart_write_char('|');usart_write_U16_hex( NumBytes ); 424 425 // now calculate the offset address 426 // calculated according to W5100 datasheet page: 44 427 if ((offset + NumBytes) > (S0_RX_MASK + 1) ) // if data is turned over in RX-mem 428 { 429 upper_size = (S0_RX_MASK + 1) - offset; 430 lower_size = NumBytes - upper_size; 431 for (U16 i = 0; i < upper_size; ++i) 432 { 433 w5100_write(start_address + i, string[i]); 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(); 439 440 } 441 for (U16 i = 0; i < lower_size; ++i) 442 { 443 w5100_write(S0_RX_BASE + i, string[upper_size+i]); 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(); 449 450 } 451 } 452 else // if not data turn over in RX-mem 453 { 454 for (U16 i = 0; i < NumBytes; ++i) 455 { 456 w5100_write(start_address + i, string[i]); 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(); 462 463 } 464 } 465 466 // inform W5100 about how much data was written. 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(); 481 482 // tell it to send now the data away 483 w5100_write( S0_CR, CR_SEND); 484 485 486 487 return NumBytes; 348 U08 repetitions; 349 U16 freesize; 350 U16 last_TX_write_pointer; 351 352 freesize = get_S0_TX_FSR(); 353 for (repetitions=0 ; repetitions < 3; ) { // increase is *inside the loop* 354 if ( freesize != get_S0_TX_FSR()) { 355 freesize = get_S0_TX_FSR(); 356 } 357 else { 358 repetitions++; 359 } 360 } 361 if (freesize == 0) { 362 return 0; 363 } 364 365 last_TX_write_pointer = get_S0_TX_WR(); 366 for (repetitions=0 ; repetitions < 3; ) { // increase is *inside the loop* 367 if ( last_TX_write_pointer != get_S0_TX_WR()) { 368 last_TX_write_pointer = get_S0_TX_WR(); 369 } 370 else { 371 repetitions++; 372 } 373 } 374 375 U16 offset = last_TX_write_pointer & S0_TX_MASK; 376 U16 start_address = S0_TX_BASE + offset; 377 U16 upper_size; 378 U16 lower_size; 379 if ( freesize < NumBytes ) { 380 NumBytes = freesize; 381 } 382 383 // now calculate the offset address 384 // calculated according to W5100 datasheet page: 44 385 if ((offset + NumBytes) > (S0_RX_MASK + 1) ) { // if data is turned over in RX-mem 386 upper_size = (S0_RX_MASK + 1) - offset; 387 lower_size = NumBytes - upper_size; 388 for (U16 i = 0; i < upper_size; ++i) { 389 w5100_write(start_address + i, string[i]); 390 } 391 for (U16 i = 0; i < lower_size; ++i) { 392 w5100_write(S0_RX_BASE + i, string[upper_size+i]); 393 } 394 } 395 else { // if not data turn over in RX-mem 396 for (U16 i = 0; i < NumBytes; ++i) { 397 w5100_write(start_address + i, string[i]); 398 } 399 } 400 401 // inform W5100 about how much data was written. 402 U16 new_write_pointer = last_TX_write_pointer + NumBytes; 403 set_S0_TX_WR(new_write_pointer); 404 405 // tell it to send now the data away 406 w5100_write( S0_CR, CR_SEND); 407 return NumBytes; 488 408 } 489 409 -
firmware/FSC/src/w5100_spi_interface.h
r11667 r17631 5 5 #include "typedefs.h" 6 6 #include "application.h" 7 #include "num_conversion.h"7 //#include "num_conversion.h" 8 8 9 9 extern volatile BOOL sock0_connection_established;
Note:
See TracChangeset
for help on using the changeset viewer.