Changeset 194 for rtos_arduino/trunk/arduino_lib/libraries/SD/src/utility
- Timestamp:
- Mar 30, 2016, 4:57:22 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rtos_arduino/trunk/arduino_lib/libraries/SD/src/utility/Sd2Card.cpp
r136 r194 21 21 #include <Arduino.h> 22 22 #include "Sd2Card.h" 23 24 #ifdef TOPPERS_WITH_ARDUINO 25 #include "rca.h" 26 #define ENTER_CRITICAL wai_sem(SPI_SEM); 27 #define LEAVE_CRITICAL sig_sem(SPI_SEM); 28 #else /* !TOPPERS_WITH_ARDUINO */ 29 #define WAIT_TIMEOUT 30 #define ENTER_CRITICAL 31 #define LEAVE_CRITICAL 32 #endif /* TOPPERS_WITH_ARDUINO */ 33 23 34 //------------------------------------------------------------------------------ 24 35 #ifndef SOFTWARE_SPI … … 200 211 */ 201 212 uint8_t Sd2Card::erase(uint32_t firstBlock, uint32_t lastBlock) { 213 ENTER_CRITICAL; 202 214 if (!eraseSingleBlockEnable()) { 203 215 error(SD_CARD_ERROR_ERASE_SINGLE_BLOCK); … … 219 231 } 220 232 chipSelectHigh(); 233 LEAVE_CRITICAL; 221 234 return true; 222 235 223 236 fail: 224 237 chipSelectHigh(); 238 LEAVE_CRITICAL; 225 239 return false; 226 240 } … … 253 267 uint16_t t0 = (uint16_t)millis(); 254 268 uint32_t arg; 255 269 270 ENTER_CRITICAL; 256 271 // set pin modes 257 272 pinMode(chipSelectPin_, OUTPUT); … … 292 307 #endif 293 308 #endif 294 295 309 chipSelectLow(); 296 310 … … 335 349 } 336 350 chipSelectHigh(); 337 351 LEAVE_CRITICAL; 338 352 #ifndef SOFTWARE_SPI 339 353 return setSckRate(sckRateID); … … 344 358 fail: 345 359 chipSelectHigh(); 360 LEAVE_CRITICAL; 346 361 return false; 347 362 } … … 361 376 */ 362 377 void Sd2Card::partialBlockRead(uint8_t value) { 378 ENTER_CRITICAL; 363 379 readEnd(); 364 380 partialBlockRead_ = value; 381 LEAVE_CRITICAL; 365 382 } 366 383 //------------------------------------------------------------------------------ … … 392 409 uint16_t n; 393 410 if (count == 0) return true; 411 ENTER_CRITICAL; 394 412 if ((count + offset) > 512) { 395 413 goto fail; … … 450 468 readEnd(); 451 469 } 470 LEAVE_CRITICAL; 452 471 return true; 453 472 454 473 fail: 474 LEAVE_CRITICAL; 455 475 chipSelectHigh(); 456 476 return false; … … 483 503 uint8_t Sd2Card::readRegister(uint8_t cmd, void* buf) { 484 504 uint8_t* dst = reinterpret_cast<uint8_t*>(buf); 505 ENTER_CRITICAL; 485 506 if (cardCommand(cmd, 0)) { 486 507 error(SD_CARD_ERROR_READ_REG); … … 493 514 spiRec(); // get second crc byte 494 515 chipSelectHigh(); 516 LEAVE_CRITICAL; 495 517 return true; 496 518 497 519 fail: 498 520 chipSelectHigh(); 521 LEAVE_CRITICAL; 499 522 return false; 500 523 } … … 582 605 */ 583 606 uint8_t Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) { 607 ENTER_CRITICAL; 584 608 #if SD_PROTECT_BLOCK_ZERO 585 609 // don't allow write to first block … … 609 633 } 610 634 chipSelectHigh(); 635 LEAVE_CRITICAL; 611 636 return true; 612 637 613 638 fail: 614 639 chipSelectHigh(); 640 LEAVE_CRITICAL; 615 641 return false; 616 642 } … … 618 644 /** Write one data block in a multiple block write sequence */ 619 645 uint8_t Sd2Card::writeData(const uint8_t* src) { 646 uint8_t ret; 647 ENTER_CRITICAL; 620 648 // wait for previous write to finish 621 649 if (!waitNotBusy(SD_WRITE_TIMEOUT)) { 622 650 error(SD_CARD_ERROR_WRITE_MULTIPLE); 623 651 chipSelectHigh(); 624 return false; 625 } 626 return writeData(WRITE_MULTIPLE_TOKEN, src); 652 ret = false; 653 } 654 else { 655 ret = writeData(WRITE_MULTIPLE_TOKEN, src); 656 } 657 LEAVE_CRITICAL; 658 return ret; 627 659 } 628 660 //------------------------------------------------------------------------------ … … 678 710 */ 679 711 uint8_t Sd2Card::writeStart(uint32_t blockNumber, uint32_t eraseCount) { 712 ENTER_CRITICAL; 680 713 #if SD_PROTECT_BLOCK_ZERO 681 714 // don't allow write to first block … … 696 729 goto fail; 697 730 } 731 LEAVE_CRITICAL; 698 732 return true; 699 733 700 734 fail: 701 735 chipSelectHigh(); 736 LEAVE_CRITICAL; 702 737 return false; 703 738 } … … 709 744 */ 710 745 uint8_t Sd2Card::writeStop(void) { 746 ENTER_CRITICAL; 711 747 if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto fail; 712 748 spiSend(STOP_TRAN_TOKEN); 713 749 if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto fail; 714 750 chipSelectHigh(); 751 LEAVE_CRITICAL; 715 752 return true; 716 753 … … 718 755 error(SD_CARD_ERROR_STOP_TRAN); 719 756 chipSelectHigh(); 720 return false; 721 } 757 LEAVE_CRITICAL; 758 return false; 759 }
Note:
See TracChangeset
for help on using the changeset viewer.