Changeset 194 for rtos_arduino/trunk


Ignore:
Timestamp:
Mar 30, 2016, 4:57:22 PM (8 years ago)
Author:
ertl-honda
Message:

R2CAでの排他制御のサポート

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtos_arduino/trunk/arduino_lib/libraries/SD/src/utility/Sd2Card.cpp

    r136 r194  
    2121#include <Arduino.h>
    2222#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
    2334//------------------------------------------------------------------------------
    2435#ifndef SOFTWARE_SPI
     
    200211 */
    201212uint8_t Sd2Card::erase(uint32_t firstBlock, uint32_t lastBlock) {
     213  ENTER_CRITICAL;
    202214  if (!eraseSingleBlockEnable()) {
    203215    error(SD_CARD_ERROR_ERASE_SINGLE_BLOCK);
     
    219231  }
    220232  chipSelectHigh();
     233  LEAVE_CRITICAL;
    221234  return true;
    222235
    223236 fail:
    224237  chipSelectHigh();
     238  LEAVE_CRITICAL;   
    225239  return false;
    226240}
     
    253267  uint16_t t0 = (uint16_t)millis();
    254268  uint32_t arg;
    255 
     269   
     270  ENTER_CRITICAL;
    256271  // set pin modes
    257272  pinMode(chipSelectPin_, OUTPUT);
     
    292307#endif
    293308#endif
    294 
    295309  chipSelectLow();
    296310
     
    335349  }
    336350  chipSelectHigh();
    337 
     351  LEAVE_CRITICAL;
    338352#ifndef SOFTWARE_SPI
    339353  return setSckRate(sckRateID);
     
    344358 fail:
    345359  chipSelectHigh();
     360  LEAVE_CRITICAL;
    346361  return false;
    347362}
     
    361376 */
    362377void Sd2Card::partialBlockRead(uint8_t value) {
     378  ENTER_CRITICAL;   
    363379  readEnd();
    364380  partialBlockRead_ = value;
     381  LEAVE_CRITICAL;   
    365382}
    366383//------------------------------------------------------------------------------
     
    392409  uint16_t n;
    393410  if (count == 0) return true;
     411  ENTER_CRITICAL;
    394412  if ((count + offset) > 512) {
    395413    goto fail;
     
    450468    readEnd();
    451469  }
     470  LEAVE_CRITICAL;   
    452471  return true;
    453472
    454473 fail:
     474  LEAVE_CRITICAL;   
    455475  chipSelectHigh();
    456476  return false;
     
    483503uint8_t Sd2Card::readRegister(uint8_t cmd, void* buf) {
    484504  uint8_t* dst = reinterpret_cast<uint8_t*>(buf);
     505  ENTER_CRITICAL;
    485506  if (cardCommand(cmd, 0)) {
    486507    error(SD_CARD_ERROR_READ_REG);
     
    493514  spiRec();  // get second crc byte
    494515  chipSelectHigh();
     516  LEAVE_CRITICAL;
    495517  return true;
    496518
    497519 fail:
    498520  chipSelectHigh();
     521  LEAVE_CRITICAL;   
    499522  return false;
    500523}
     
    582605 */
    583606uint8_t Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {
     607  ENTER_CRITICAL;
    584608#if SD_PROTECT_BLOCK_ZERO
    585609  // don't allow write to first block
     
    609633  }
    610634  chipSelectHigh();
     635  LEAVE_CRITICAL;   
    611636  return true;
    612637
    613638 fail:
    614639  chipSelectHigh();
     640  LEAVE_CRITICAL;   
    615641  return false;
    616642}
     
    618644/** Write one data block in a multiple block write sequence */
    619645uint8_t Sd2Card::writeData(const uint8_t* src) {
     646  uint8_t ret; 
     647  ENTER_CRITICAL;
    620648  // wait for previous write to finish
    621649  if (!waitNotBusy(SD_WRITE_TIMEOUT)) {
    622650    error(SD_CARD_ERROR_WRITE_MULTIPLE);
    623651    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;
    627659}
    628660//------------------------------------------------------------------------------
     
    678710 */
    679711uint8_t Sd2Card::writeStart(uint32_t blockNumber, uint32_t eraseCount) {
     712  ENTER_CRITICAL;
    680713#if SD_PROTECT_BLOCK_ZERO
    681714  // don't allow write to first block
     
    696729    goto fail;
    697730  }
     731  LEAVE_CRITICAL;
    698732  return true;
    699733
    700734 fail:
    701735  chipSelectHigh();
     736  LEAVE_CRITICAL;   
    702737  return false;
    703738}
     
    709744 */
    710745uint8_t Sd2Card::writeStop(void) {
     746  ENTER_CRITICAL;   
    711747  if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto fail;
    712748  spiSend(STOP_TRAN_TOKEN);
    713749  if (!waitNotBusy(SD_WRITE_TIMEOUT)) goto fail;
    714750  chipSelectHigh();
     751  LEAVE_CRITICAL;   
    715752  return true;
    716753
     
    718755  error(SD_CARD_ERROR_STOP_TRAN);
    719756  chipSelectHigh();
    720   return false;
    721 }
     757  LEAVE_CRITICAL;   
     758  return false;
     759}
Note: See TracChangeset for help on using the changeset viewer.