Fix hexadecimal number formatting
This commit is contained in:
parent
0938c62b48
commit
75e6f72c89
@ -55,7 +55,7 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/** SPI receive a byte */
|
/** SPI receive a byte */
|
||||||
static uint8_t spiRec() {
|
static uint8_t spiRec() {
|
||||||
SPDR = 0XFF;
|
SPDR = 0xFF;
|
||||||
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
||||||
return SPDR;
|
return SPDR;
|
||||||
}
|
}
|
||||||
@ -64,11 +64,11 @@
|
|||||||
static inline __attribute__((always_inline))
|
static inline __attribute__((always_inline))
|
||||||
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
void spiRead(uint8_t* buf, uint16_t nbyte) {
|
||||||
if (nbyte-- == 0) return;
|
if (nbyte-- == 0) return;
|
||||||
SPDR = 0XFF;
|
SPDR = 0xFF;
|
||||||
for (uint16_t i = 0; i < nbyte; i++) {
|
for (uint16_t i = 0; i < nbyte; i++) {
|
||||||
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
||||||
buf[i] = SPDR;
|
buf[i] = SPDR;
|
||||||
SPDR = 0XFF;
|
SPDR = 0xFF;
|
||||||
}
|
}
|
||||||
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
while (!TEST(SPSR, SPIF)) { /* Intentionally left empty */ }
|
||||||
buf[nbyte] = SPDR;
|
buf[nbyte] = SPDR;
|
||||||
@ -103,7 +103,7 @@
|
|||||||
uint8_t data = 0;
|
uint8_t data = 0;
|
||||||
// no interrupts during byte receive - about 8 us
|
// no interrupts during byte receive - about 8 us
|
||||||
cli();
|
cli();
|
||||||
// output pin high - like sending 0XFF
|
// output pin high - like sending 0xFF
|
||||||
WRITE(SPI_MOSI_PIN, HIGH);
|
WRITE(SPI_MOSI_PIN, HIGH);
|
||||||
|
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
@ -137,7 +137,7 @@
|
|||||||
for (uint8_t i = 0; i < 8; i++) {
|
for (uint8_t i = 0; i < 8; i++) {
|
||||||
WRITE(SPI_SCK_PIN, LOW);
|
WRITE(SPI_SCK_PIN, LOW);
|
||||||
|
|
||||||
WRITE(SPI_MOSI_PIN, data & 0X80);
|
WRITE(SPI_MOSI_PIN, data & 0x80);
|
||||||
|
|
||||||
data <<= 1;
|
data <<= 1;
|
||||||
|
|
||||||
@ -177,16 +177,16 @@ uint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) {
|
|||||||
for (int8_t s = 24; s >= 0; s -= 8) spiSend(arg >> s);
|
for (int8_t s = 24; s >= 0; s -= 8) spiSend(arg >> s);
|
||||||
|
|
||||||
// send CRC
|
// send CRC
|
||||||
uint8_t crc = 0XFF;
|
uint8_t crc = 0xFF;
|
||||||
if (cmd == CMD0) crc = 0X95; // correct crc for CMD0 with arg 0
|
if (cmd == CMD0) crc = 0x95; // correct crc for CMD0 with arg 0
|
||||||
if (cmd == CMD8) crc = 0X87; // correct crc for CMD8 with arg 0X1AA
|
if (cmd == CMD8) crc = 0x87; // correct crc for CMD8 with arg 0x1AA
|
||||||
spiSend(crc);
|
spiSend(crc);
|
||||||
|
|
||||||
// skip stuff byte for stop read
|
// skip stuff byte for stop read
|
||||||
if (cmd == CMD12) spiRec();
|
if (cmd == CMD12) spiRec();
|
||||||
|
|
||||||
// wait for response
|
// wait for response
|
||||||
for (uint8_t i = 0; ((status_ = spiRec()) & 0X80) && i != 0XFF; i++) { /* Intentionally left empty */ }
|
for (uint8_t i = 0; ((status_ = spiRec()) & 0x80) && i != 0xFF; i++) { /* Intentionally left empty */ }
|
||||||
return status_;
|
return status_;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@ -329,7 +329,7 @@ bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
|
|||||||
#endif // SOFTWARE_SPI
|
#endif // SOFTWARE_SPI
|
||||||
|
|
||||||
// must supply min of 74 clock cycles with CS high.
|
// must supply min of 74 clock cycles with CS high.
|
||||||
for (uint8_t i = 0; i < 10; i++) spiSend(0XFF);
|
for (uint8_t i = 0; i < 10; i++) spiSend(0xFF);
|
||||||
|
|
||||||
// command to go idle in SPI mode
|
// command to go idle in SPI mode
|
||||||
while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
|
while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {
|
||||||
@ -345,14 +345,14 @@ bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
|
|||||||
else {
|
else {
|
||||||
// only need last byte of r7 response
|
// only need last byte of r7 response
|
||||||
for (uint8_t i = 0; i < 4; i++) status_ = spiRec();
|
for (uint8_t i = 0; i < 4; i++) status_ = spiRec();
|
||||||
if (status_ != 0XAA) {
|
if (status_ != 0xAA) {
|
||||||
error(SD_CARD_ERROR_CMD8);
|
error(SD_CARD_ERROR_CMD8);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
type(SD_CARD_TYPE_SD2);
|
type(SD_CARD_TYPE_SD2);
|
||||||
}
|
}
|
||||||
// initialize card and send host supports SDHC if SD2
|
// initialize card and send host supports SDHC if SD2
|
||||||
arg = type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0;
|
arg = type() == SD_CARD_TYPE_SD2 ? 0x40000000 : 0;
|
||||||
|
|
||||||
while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {
|
while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {
|
||||||
// check for timeout
|
// check for timeout
|
||||||
@ -367,7 +367,7 @@ bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {
|
|||||||
error(SD_CARD_ERROR_CMD58);
|
error(SD_CARD_ERROR_CMD58);
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
if ((spiRec() & 0XC0) == 0XC0) type(SD_CARD_TYPE_SDHC);
|
if ((spiRec() & 0xC0) == 0xC0) type(SD_CARD_TYPE_SDHC);
|
||||||
// discard rest of ocr - contains allowed voltage range
|
// discard rest of ocr - contains allowed voltage range
|
||||||
for (uint8_t i = 0; i < 3; i++) spiRec();
|
for (uint8_t i = 0; i < 3; i++) spiRec();
|
||||||
}
|
}
|
||||||
@ -473,7 +473,7 @@ static const uint16_t crctab[] PROGMEM = {
|
|||||||
static uint16_t CRC_CCITT(const uint8_t* data, size_t n) {
|
static uint16_t CRC_CCITT(const uint8_t* data, size_t n) {
|
||||||
uint16_t crc = 0;
|
uint16_t crc = 0;
|
||||||
for (size_t i = 0; i < n; i++) {
|
for (size_t i = 0; i < n; i++) {
|
||||||
crc = pgm_read_word(&crctab[(crc >> 8 ^ data[i]) & 0XFF]) ^ (crc << 8);
|
crc = pgm_read_word(&crctab[(crc >> 8 ^ data[i]) & 0xFF]) ^ (crc << 8);
|
||||||
}
|
}
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
@ -92,27 +92,27 @@ uint8_t const SD_CARD_ERROR_ERASE_TIMEOUT = 0XE;
|
|||||||
/** card returned an error token instead of read data */
|
/** card returned an error token instead of read data */
|
||||||
uint8_t const SD_CARD_ERROR_READ = 0XF;
|
uint8_t const SD_CARD_ERROR_READ = 0XF;
|
||||||
/** read CID or CSD failed */
|
/** read CID or CSD failed */
|
||||||
uint8_t const SD_CARD_ERROR_READ_REG = 0X10;
|
uint8_t const SD_CARD_ERROR_READ_REG = 0x10;
|
||||||
/** timeout while waiting for start of read data */
|
/** timeout while waiting for start of read data */
|
||||||
uint8_t const SD_CARD_ERROR_READ_TIMEOUT = 0X11;
|
uint8_t const SD_CARD_ERROR_READ_TIMEOUT = 0x11;
|
||||||
/** card did not accept STOP_TRAN_TOKEN */
|
/** card did not accept STOP_TRAN_TOKEN */
|
||||||
uint8_t const SD_CARD_ERROR_STOP_TRAN = 0X12;
|
uint8_t const SD_CARD_ERROR_STOP_TRAN = 0x12;
|
||||||
/** card returned an error token as a response to a write operation */
|
/** card returned an error token as a response to a write operation */
|
||||||
uint8_t const SD_CARD_ERROR_WRITE = 0X13;
|
uint8_t const SD_CARD_ERROR_WRITE = 0x13;
|
||||||
/** attempt to write protected block zero */
|
/** attempt to write protected block zero */
|
||||||
uint8_t const SD_CARD_ERROR_WRITE_BLOCK_ZERO = 0X14; // REMOVE - not used
|
uint8_t const SD_CARD_ERROR_WRITE_BLOCK_ZERO = 0x14; // REMOVE - not used
|
||||||
/** card did not go ready for a multiple block write */
|
/** card did not go ready for a multiple block write */
|
||||||
uint8_t const SD_CARD_ERROR_WRITE_MULTIPLE = 0X15;
|
uint8_t const SD_CARD_ERROR_WRITE_MULTIPLE = 0x15;
|
||||||
/** card returned an error to a CMD13 status check after a write */
|
/** card returned an error to a CMD13 status check after a write */
|
||||||
uint8_t const SD_CARD_ERROR_WRITE_PROGRAMMING = 0X16;
|
uint8_t const SD_CARD_ERROR_WRITE_PROGRAMMING = 0x16;
|
||||||
/** timeout occurred during write programming */
|
/** timeout occurred during write programming */
|
||||||
uint8_t const SD_CARD_ERROR_WRITE_TIMEOUT = 0X17;
|
uint8_t const SD_CARD_ERROR_WRITE_TIMEOUT = 0x17;
|
||||||
/** incorrect rate selected */
|
/** incorrect rate selected */
|
||||||
uint8_t const SD_CARD_ERROR_SCK_RATE = 0X18;
|
uint8_t const SD_CARD_ERROR_SCK_RATE = 0x18;
|
||||||
/** init() not called */
|
/** init() not called */
|
||||||
uint8_t const SD_CARD_ERROR_INIT_NOT_CALLED = 0X19;
|
uint8_t const SD_CARD_ERROR_INIT_NOT_CALLED = 0x19;
|
||||||
/** crc check error */
|
/** crc check error */
|
||||||
uint8_t const SD_CARD_ERROR_CRC = 0X20;
|
uint8_t const SD_CARD_ERROR_CRC = 0x20;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// card types
|
// card types
|
||||||
/** Standard capacity V1 SD card */
|
/** Standard capacity V1 SD card */
|
||||||
|
@ -57,7 +57,7 @@ bool SdBaseFile::addCluster() {
|
|||||||
bool SdBaseFile::addDirCluster() {
|
bool SdBaseFile::addDirCluster() {
|
||||||
uint32_t block;
|
uint32_t block;
|
||||||
// max folder size
|
// max folder size
|
||||||
if (fileSize_ / sizeof(dir_t) >= 0XFFFF) goto fail;
|
if (fileSize_ / sizeof(dir_t) >= 0xFFFF) goto fail;
|
||||||
|
|
||||||
if (!addCluster()) goto fail;
|
if (!addCluster()) goto fail;
|
||||||
if (!vol_->cacheFlush()) goto fail;
|
if (!vol_->cacheFlush()) goto fail;
|
||||||
@ -510,7 +510,7 @@ bool SdBaseFile::mkdir(SdBaseFile* parent, const uint8_t dname[11]) {
|
|||||||
d.firstClusterHigh = 0;
|
d.firstClusterHigh = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
d.firstClusterLow = parent->firstCluster_ & 0XFFFF;
|
d.firstClusterLow = parent->firstCluster_ & 0xFFFF;
|
||||||
d.firstClusterHigh = parent->firstCluster_ >> 16;
|
d.firstClusterHigh = parent->firstCluster_ >> 16;
|
||||||
}
|
}
|
||||||
// copy '..' to block
|
// copy '..' to block
|
||||||
@ -1063,7 +1063,7 @@ int16_t SdBaseFile::read(void* buf, uint16_t nbyte) {
|
|||||||
// amount left to read
|
// amount left to read
|
||||||
toRead = nbyte;
|
toRead = nbyte;
|
||||||
while (toRead > 0) {
|
while (toRead > 0) {
|
||||||
offset = curPosition_ & 0X1FF; // offset in block
|
offset = curPosition_ & 0x1FF; // offset in block
|
||||||
if (type_ == FAT_FILE_TYPE_ROOT_FIXED) {
|
if (type_ == FAT_FILE_TYPE_ROOT_FIXED) {
|
||||||
block = vol_->rootDirStart() + (curPosition_ >> 9);
|
block = vol_->rootDirStart() + (curPosition_ >> 9);
|
||||||
}
|
}
|
||||||
@ -1120,7 +1120,7 @@ fail:
|
|||||||
int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
|
int8_t SdBaseFile::readDir(dir_t* dir, char* longFilename) {
|
||||||
int16_t n;
|
int16_t n;
|
||||||
// if not a directory file or miss-positioned return an error
|
// if not a directory file or miss-positioned return an error
|
||||||
if (!isDir() || (0X1F & curPosition_)) return -1;
|
if (!isDir() || (0x1F & curPosition_)) return -1;
|
||||||
|
|
||||||
//If we have a longFilename buffer, mark it as invalid. If we find a long filename it will be filled automaticly.
|
//If we have a longFilename buffer, mark it as invalid. If we find a long filename it will be filled automaticly.
|
||||||
if (longFilename != NULL) longFilename[0] = '\0';
|
if (longFilename != NULL) longFilename[0] = '\0';
|
||||||
@ -1513,7 +1513,7 @@ bool SdBaseFile::sync() {
|
|||||||
if (!isDir()) d->fileSize = fileSize_;
|
if (!isDir()) d->fileSize = fileSize_;
|
||||||
|
|
||||||
// update first cluster fields
|
// update first cluster fields
|
||||||
d->firstClusterLow = firstCluster_ & 0XFFFF;
|
d->firstClusterLow = firstCluster_ & 0xFFFF;
|
||||||
d->firstClusterHigh = firstCluster_ >> 16;
|
d->firstClusterHigh = firstCluster_ >> 16;
|
||||||
|
|
||||||
// set modify time if user supplied a callback date/time function
|
// set modify time if user supplied a callback date/time function
|
||||||
@ -1738,7 +1738,7 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
|||||||
|
|
||||||
while (nToWrite > 0) {
|
while (nToWrite > 0) {
|
||||||
uint8_t blockOfCluster = vol_->blockOfCluster(curPosition_);
|
uint8_t blockOfCluster = vol_->blockOfCluster(curPosition_);
|
||||||
uint16_t blockOffset = curPosition_ & 0X1FF;
|
uint16_t blockOffset = curPosition_ & 0x1FF;
|
||||||
if (blockOfCluster == 0 && blockOffset == 0) {
|
if (blockOfCluster == 0 && blockOffset == 0) {
|
||||||
// start of new cluster
|
// start of new cluster
|
||||||
if (curCluster_ == 0) {
|
if (curCluster_ == 0) {
|
||||||
@ -1774,7 +1774,7 @@ int16_t SdBaseFile::write(const void* buf, uint16_t nbyte) {
|
|||||||
// full block - don't need to use cache
|
// full block - don't need to use cache
|
||||||
if (vol_->cacheBlockNumber() == block) {
|
if (vol_->cacheBlockNumber() == block) {
|
||||||
// invalidate cache if block is in cache
|
// invalidate cache if block is in cache
|
||||||
vol_->cacheSetBlockNumber(0XFFFFFFFF, false);
|
vol_->cacheSetBlockNumber(0xFFFFFFFF, false);
|
||||||
}
|
}
|
||||||
if (!vol_->writeBlock(block, src)) goto fail;
|
if (!vol_->writeBlock(block, src)) goto fail;
|
||||||
}
|
}
|
||||||
|
@ -54,11 +54,11 @@ struct filepos_t {
|
|||||||
|
|
||||||
// use the gnu style oflag in open()
|
// use the gnu style oflag in open()
|
||||||
/** open() oflag for reading */
|
/** open() oflag for reading */
|
||||||
uint8_t const O_READ = 0X01;
|
uint8_t const O_READ = 0x01;
|
||||||
/** open() oflag - same as O_IN */
|
/** open() oflag - same as O_IN */
|
||||||
uint8_t const O_RDONLY = O_READ;
|
uint8_t const O_RDONLY = O_READ;
|
||||||
/** open() oflag for write */
|
/** open() oflag for write */
|
||||||
uint8_t const O_WRITE = 0X02;
|
uint8_t const O_WRITE = 0x02;
|
||||||
/** open() oflag - same as O_WRITE */
|
/** open() oflag - same as O_WRITE */
|
||||||
uint8_t const O_WRONLY = O_WRITE;
|
uint8_t const O_WRONLY = O_WRITE;
|
||||||
/** open() oflag for reading and writing */
|
/** open() oflag for reading and writing */
|
||||||
@ -66,17 +66,17 @@ uint8_t const O_RDWR = (O_READ | O_WRITE);
|
|||||||
/** open() oflag mask for access modes */
|
/** open() oflag mask for access modes */
|
||||||
uint8_t const O_ACCMODE = (O_READ | O_WRITE);
|
uint8_t const O_ACCMODE = (O_READ | O_WRITE);
|
||||||
/** The file offset shall be set to the end of the file prior to each write. */
|
/** The file offset shall be set to the end of the file prior to each write. */
|
||||||
uint8_t const O_APPEND = 0X04;
|
uint8_t const O_APPEND = 0x04;
|
||||||
/** synchronous writes - call sync() after each write */
|
/** synchronous writes - call sync() after each write */
|
||||||
uint8_t const O_SYNC = 0X08;
|
uint8_t const O_SYNC = 0x08;
|
||||||
/** truncate the file to zero length */
|
/** truncate the file to zero length */
|
||||||
uint8_t const O_TRUNC = 0X10;
|
uint8_t const O_TRUNC = 0x10;
|
||||||
/** set the initial position at the end of the file */
|
/** set the initial position at the end of the file */
|
||||||
uint8_t const O_AT_END = 0X20;
|
uint8_t const O_AT_END = 0x20;
|
||||||
/** create the file if nonexistent */
|
/** create the file if nonexistent */
|
||||||
uint8_t const O_CREAT = 0X40;
|
uint8_t const O_CREAT = 0x40;
|
||||||
/** If O_CREAT and O_EXCL are set, open() shall fail if the file exists */
|
/** If O_CREAT and O_EXCL are set, open() shall fail if the file exists */
|
||||||
uint8_t const O_EXCL = 0X80;
|
uint8_t const O_EXCL = 0x80;
|
||||||
|
|
||||||
// SdBaseFile class static and const definitions
|
// SdBaseFile class static and const definitions
|
||||||
// flags for ls()
|
// flags for ls()
|
||||||
@ -141,7 +141,7 @@ static inline uint8_t FAT_MONTH(uint16_t fatDate) {
|
|||||||
* \return Extracted day [1,31]
|
* \return Extracted day [1,31]
|
||||||
*/
|
*/
|
||||||
static inline uint8_t FAT_DAY(uint16_t fatDate) {
|
static inline uint8_t FAT_DAY(uint16_t fatDate) {
|
||||||
return fatDate & 0X1F;
|
return fatDate & 0x1F;
|
||||||
}
|
}
|
||||||
/** time field for FAT directory entry
|
/** time field for FAT directory entry
|
||||||
* \param[in] hour [0,23]
|
* \param[in] hour [0,23]
|
||||||
@ -167,7 +167,7 @@ static inline uint8_t FAT_HOUR(uint16_t fatTime) {
|
|||||||
* \return Extracted minute [0,59]
|
* \return Extracted minute [0,59]
|
||||||
*/
|
*/
|
||||||
static inline uint8_t FAT_MINUTE(uint16_t fatTime) {
|
static inline uint8_t FAT_MINUTE(uint16_t fatTime) {
|
||||||
return (fatTime >> 5) & 0X3F;
|
return (fatTime >> 5) & 0x3F;
|
||||||
}
|
}
|
||||||
/** second part of FAT directory time field
|
/** second part of FAT directory time field
|
||||||
* Note second/2 is stored in packed time.
|
* Note second/2 is stored in packed time.
|
||||||
@ -177,7 +177,7 @@ static inline uint8_t FAT_MINUTE(uint16_t fatTime) {
|
|||||||
* \return Extracted second [0,58]
|
* \return Extracted second [0,58]
|
||||||
*/
|
*/
|
||||||
static inline uint8_t FAT_SECOND(uint16_t fatTime) {
|
static inline uint8_t FAT_SECOND(uint16_t fatTime) {
|
||||||
return 2 * (fatTime & 0X1F);
|
return 2 * (fatTime & 0x1F);
|
||||||
}
|
}
|
||||||
/** Default date for file timestamps is 1 Jan 2000 */
|
/** Default date for file timestamps is 1 Jan 2000 */
|
||||||
uint16_t const FAT_DEFAULT_DATE = ((2000 - 1980) << 9) | (1 << 5) | 1;
|
uint16_t const FAT_DEFAULT_DATE = ((2000 - 1980) << 9) | (1 << 5) | 1;
|
||||||
@ -338,10 +338,10 @@ class SdBaseFile {
|
|||||||
// data time callback function
|
// data time callback function
|
||||||
static void (*dateTime_)(uint16_t* date, uint16_t* time);
|
static void (*dateTime_)(uint16_t* date, uint16_t* time);
|
||||||
// bits defined in flags_
|
// bits defined in flags_
|
||||||
// should be 0X0F
|
// should be 0x0F
|
||||||
static uint8_t const F_OFLAG = (O_ACCMODE | O_APPEND | O_SYNC);
|
static uint8_t const F_OFLAG = (O_ACCMODE | O_APPEND | O_SYNC);
|
||||||
// sync of directory entry required
|
// sync of directory entry required
|
||||||
static uint8_t const F_FILE_DIR_DIRTY = 0X80;
|
static uint8_t const F_FILE_DIR_DIRTY = 0x80;
|
||||||
|
|
||||||
// private data
|
// private data
|
||||||
uint8_t flags_; // See above for definition of flags_ bits
|
uint8_t flags_; // See above for definition of flags_ bits
|
||||||
|
@ -43,11 +43,11 @@
|
|||||||
*/
|
*/
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/** Value for byte 510 of boot block or MBR */
|
/** Value for byte 510 of boot block or MBR */
|
||||||
uint8_t const BOOTSIG0 = 0X55;
|
uint8_t const BOOTSIG0 = 0x55;
|
||||||
/** Value for byte 511 of boot block or MBR */
|
/** Value for byte 511 of boot block or MBR */
|
||||||
uint8_t const BOOTSIG1 = 0XAA;
|
uint8_t const BOOTSIG1 = 0xAA;
|
||||||
/** Value for bootSignature field int FAT/FAT32 boot sector */
|
/** Value for bootSignature field int FAT/FAT32 boot sector */
|
||||||
uint8_t const EXTENDED_BOOT_SIG = 0X29;
|
uint8_t const EXTENDED_BOOT_SIG = 0x29;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* \struct partitionTable
|
* \struct partitionTable
|
||||||
@ -59,8 +59,8 @@ uint8_t const EXTENDED_BOOT_SIG = 0X29;
|
|||||||
struct partitionTable {
|
struct partitionTable {
|
||||||
/**
|
/**
|
||||||
* Boot Indicator . Indicates whether the volume is the active
|
* Boot Indicator . Indicates whether the volume is the active
|
||||||
* partition. Legal values include: 0X00. Do not use for booting.
|
* partition. Legal values include: 0x00. Do not use for booting.
|
||||||
* 0X80 Active partition.
|
* 0x80 Active partition.
|
||||||
*/
|
*/
|
||||||
uint8_t boot;
|
uint8_t boot;
|
||||||
/**
|
/**
|
||||||
@ -126,9 +126,9 @@ struct masterBootRecord {
|
|||||||
uint16_t usuallyZero;
|
uint16_t usuallyZero;
|
||||||
/** Partition tables. */
|
/** Partition tables. */
|
||||||
part_t part[4];
|
part_t part[4];
|
||||||
/** First MBR signature byte. Must be 0X55 */
|
/** First MBR signature byte. Must be 0x55 */
|
||||||
uint8_t mbrSig0;
|
uint8_t mbrSig0;
|
||||||
/** Second MBR signature byte. Must be 0XAA */
|
/** Second MBR signature byte. Must be 0xAA */
|
||||||
uint8_t mbrSig1;
|
uint8_t mbrSig1;
|
||||||
} PACKED;
|
} PACKED;
|
||||||
/** Type name for masterBootRecord */
|
/** Type name for masterBootRecord */
|
||||||
@ -234,7 +234,7 @@ struct fat_boot {
|
|||||||
uint8_t driveNumber;
|
uint8_t driveNumber;
|
||||||
/** used by Windows NT - should be zero for FAT */
|
/** used by Windows NT - should be zero for FAT */
|
||||||
uint8_t reserved1;
|
uint8_t reserved1;
|
||||||
/** 0X29 if next three fields are valid */
|
/** 0x29 if next three fields are valid */
|
||||||
uint8_t bootSignature;
|
uint8_t bootSignature;
|
||||||
/**
|
/**
|
||||||
* A random serial number created when formatting a disk,
|
* A random serial number created when formatting a disk,
|
||||||
@ -254,9 +254,9 @@ struct fat_boot {
|
|||||||
char fileSystemType[8];
|
char fileSystemType[8];
|
||||||
/** X86 boot code */
|
/** X86 boot code */
|
||||||
uint8_t bootCode[448];
|
uint8_t bootCode[448];
|
||||||
/** must be 0X55 */
|
/** must be 0x55 */
|
||||||
uint8_t bootSectorSig0;
|
uint8_t bootSectorSig0;
|
||||||
/** must be 0XAA */
|
/** must be 0xAA */
|
||||||
uint8_t bootSectorSig1;
|
uint8_t bootSectorSig1;
|
||||||
} PACKED;
|
} PACKED;
|
||||||
/** Type name for FAT Boot Sector */
|
/** Type name for FAT Boot Sector */
|
||||||
@ -389,7 +389,7 @@ struct fat32_boot {
|
|||||||
uint8_t driveNumber;
|
uint8_t driveNumber;
|
||||||
/** used by Windows NT - should be zero for FAT */
|
/** used by Windows NT - should be zero for FAT */
|
||||||
uint8_t reserved1;
|
uint8_t reserved1;
|
||||||
/** 0X29 if next three fields are valid */
|
/** 0x29 if next three fields are valid */
|
||||||
uint8_t bootSignature;
|
uint8_t bootSignature;
|
||||||
/**
|
/**
|
||||||
* A random serial number created when formatting a disk,
|
* A random serial number created when formatting a disk,
|
||||||
@ -408,9 +408,9 @@ struct fat32_boot {
|
|||||||
char fileSystemType[8];
|
char fileSystemType[8];
|
||||||
/** X86 boot code */
|
/** X86 boot code */
|
||||||
uint8_t bootCode[420];
|
uint8_t bootCode[420];
|
||||||
/** must be 0X55 */
|
/** must be 0x55 */
|
||||||
uint8_t bootSectorSig0;
|
uint8_t bootSectorSig0;
|
||||||
/** must be 0XAA */
|
/** must be 0xAA */
|
||||||
uint8_t bootSectorSig1;
|
uint8_t bootSectorSig1;
|
||||||
} PACKED;
|
} PACKED;
|
||||||
/** Type name for FAT32 Boot Sector */
|
/** Type name for FAT32 Boot Sector */
|
||||||
@ -427,11 +427,11 @@ uint32_t const FSINFO_STRUCT_SIG = 0x61417272;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
struct fat32_fsinfo {
|
struct fat32_fsinfo {
|
||||||
/** must be 0X52, 0X52, 0X61, 0X41 */
|
/** must be 0x52, 0x52, 0x61, 0x41 */
|
||||||
uint32_t leadSignature;
|
uint32_t leadSignature;
|
||||||
/** must be zero */
|
/** must be zero */
|
||||||
uint8_t reserved1[480];
|
uint8_t reserved1[480];
|
||||||
/** must be 0X72, 0X72, 0X41, 0X61 */
|
/** must be 0x72, 0x72, 0x41, 0x61 */
|
||||||
uint32_t structSignature;
|
uint32_t structSignature;
|
||||||
/**
|
/**
|
||||||
* Contains the last known free cluster count on the volume.
|
* Contains the last known free cluster count on the volume.
|
||||||
@ -450,7 +450,7 @@ struct fat32_fsinfo {
|
|||||||
uint32_t nextFree;
|
uint32_t nextFree;
|
||||||
/** must be zero */
|
/** must be zero */
|
||||||
uint8_t reserved2[12];
|
uint8_t reserved2[12];
|
||||||
/** must be 0X00, 0X00, 0X55, 0XAA */
|
/** must be 0x00, 0x00, 0x55, 0xAA */
|
||||||
uint8_t tailSignature[4];
|
uint8_t tailSignature[4];
|
||||||
} PACKED;
|
} PACKED;
|
||||||
/** Type name for FAT32 FSINFO Sector */
|
/** Type name for FAT32 FSINFO Sector */
|
||||||
@ -458,19 +458,19 @@ typedef struct fat32_fsinfo fat32_fsinfo_t;
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// End Of Chain values for FAT entries
|
// End Of Chain values for FAT entries
|
||||||
/** FAT12 end of chain value used by Microsoft. */
|
/** FAT12 end of chain value used by Microsoft. */
|
||||||
uint16_t const FAT12EOC = 0XFFF;
|
uint16_t const FAT12EOC = 0xFFF;
|
||||||
/** Minimum value for FAT12 EOC. Use to test for EOC. */
|
/** Minimum value for FAT12 EOC. Use to test for EOC. */
|
||||||
uint16_t const FAT12EOC_MIN = 0XFF8;
|
uint16_t const FAT12EOC_MIN = 0xFF8;
|
||||||
/** FAT16 end of chain value used by Microsoft. */
|
/** FAT16 end of chain value used by Microsoft. */
|
||||||
uint16_t const FAT16EOC = 0XFFFF;
|
uint16_t const FAT16EOC = 0xFFFF;
|
||||||
/** Minimum value for FAT16 EOC. Use to test for EOC. */
|
/** Minimum value for FAT16 EOC. Use to test for EOC. */
|
||||||
uint16_t const FAT16EOC_MIN = 0XFFF8;
|
uint16_t const FAT16EOC_MIN = 0xFFF8;
|
||||||
/** FAT32 end of chain value used by Microsoft. */
|
/** FAT32 end of chain value used by Microsoft. */
|
||||||
uint32_t const FAT32EOC = 0X0FFFFFFF;
|
uint32_t const FAT32EOC = 0x0FFFFFFF;
|
||||||
/** Minimum value for FAT32 EOC. Use to test for EOC. */
|
/** Minimum value for FAT32 EOC. Use to test for EOC. */
|
||||||
uint32_t const FAT32EOC_MIN = 0X0FFFFFF8;
|
uint32_t const FAT32EOC_MIN = 0x0FFFFFF8;
|
||||||
/** Mask a for FAT32 entry. Entries are 28 bits. */
|
/** Mask a for FAT32 entry. Entries are 28 bits. */
|
||||||
uint32_t const FAT32MASK = 0X0FFFFFFF;
|
uint32_t const FAT32MASK = 0x0FFFFFFF;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* \struct directoryEntry
|
* \struct directoryEntry
|
||||||
@ -590,31 +590,31 @@ struct directoryVFATEntry {
|
|||||||
typedef struct directoryEntry dir_t;
|
typedef struct directoryEntry dir_t;
|
||||||
/** Type name for directoryVFATEntry */
|
/** Type name for directoryVFATEntry */
|
||||||
typedef struct directoryVFATEntry vfat_t;
|
typedef struct directoryVFATEntry vfat_t;
|
||||||
/** escape for name[0] = 0XE5 */
|
/** escape for name[0] = 0xE5 */
|
||||||
uint8_t const DIR_NAME_0XE5 = 0X05;
|
uint8_t const DIR_NAME_0xE5 = 0x05;
|
||||||
/** name[0] value for entry that is free after being "deleted" */
|
/** name[0] value for entry that is free after being "deleted" */
|
||||||
uint8_t const DIR_NAME_DELETED = 0XE5;
|
uint8_t const DIR_NAME_DELETED = 0xE5;
|
||||||
/** name[0] value for entry that is free and no allocated entries follow */
|
/** name[0] value for entry that is free and no allocated entries follow */
|
||||||
uint8_t const DIR_NAME_FREE = 0X00;
|
uint8_t const DIR_NAME_FREE = 0x00;
|
||||||
/** file is read-only */
|
/** file is read-only */
|
||||||
uint8_t const DIR_ATT_READ_ONLY = 0X01;
|
uint8_t const DIR_ATT_READ_ONLY = 0x01;
|
||||||
/** File should hidden in directory listings */
|
/** File should hidden in directory listings */
|
||||||
uint8_t const DIR_ATT_HIDDEN = 0X02;
|
uint8_t const DIR_ATT_HIDDEN = 0x02;
|
||||||
/** Entry is for a system file */
|
/** Entry is for a system file */
|
||||||
uint8_t const DIR_ATT_SYSTEM = 0X04;
|
uint8_t const DIR_ATT_SYSTEM = 0x04;
|
||||||
/** Directory entry contains the volume label */
|
/** Directory entry contains the volume label */
|
||||||
uint8_t const DIR_ATT_VOLUME_ID = 0X08;
|
uint8_t const DIR_ATT_VOLUME_ID = 0x08;
|
||||||
/** Entry is for a directory */
|
/** Entry is for a directory */
|
||||||
uint8_t const DIR_ATT_DIRECTORY = 0X10;
|
uint8_t const DIR_ATT_DIRECTORY = 0x10;
|
||||||
/** Old DOS archive bit for backup support */
|
/** Old DOS archive bit for backup support */
|
||||||
uint8_t const DIR_ATT_ARCHIVE = 0X20;
|
uint8_t const DIR_ATT_ARCHIVE = 0x20;
|
||||||
/** Test value for long name entry. Test is
|
/** Test value for long name entry. Test is
|
||||||
(d->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME. */
|
(d->attributes & DIR_ATT_LONG_NAME_MASK) == DIR_ATT_LONG_NAME. */
|
||||||
uint8_t const DIR_ATT_LONG_NAME = 0X0F;
|
uint8_t const DIR_ATT_LONG_NAME = 0x0F;
|
||||||
/** Test mask for long name entry */
|
/** Test mask for long name entry */
|
||||||
uint8_t const DIR_ATT_LONG_NAME_MASK = 0X3F;
|
uint8_t const DIR_ATT_LONG_NAME_MASK = 0x3F;
|
||||||
/** defined attribute bits */
|
/** defined attribute bits */
|
||||||
uint8_t const DIR_ATT_DEFINED_BITS = 0X3F;
|
uint8_t const DIR_ATT_DEFINED_BITS = 0x3F;
|
||||||
/** Directory entry is part of a long name
|
/** Directory entry is part of a long name
|
||||||
* \param[in] dir Pointer to a directory entry.
|
* \param[in] dir Pointer to a directory entry.
|
||||||
*
|
*
|
||||||
|
@ -45,59 +45,59 @@
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// SD card commands
|
// SD card commands
|
||||||
/** GO_IDLE_STATE - init card in spi mode if CS low */
|
/** GO_IDLE_STATE - init card in spi mode if CS low */
|
||||||
uint8_t const CMD0 = 0X00;
|
uint8_t const CMD0 = 0x00;
|
||||||
/** SEND_IF_COND - verify SD Memory Card interface operating condition.*/
|
/** SEND_IF_COND - verify SD Memory Card interface operating condition.*/
|
||||||
uint8_t const CMD8 = 0X08;
|
uint8_t const CMD8 = 0x08;
|
||||||
/** SEND_CSD - read the Card Specific Data (CSD register) */
|
/** SEND_CSD - read the Card Specific Data (CSD register) */
|
||||||
uint8_t const CMD9 = 0X09;
|
uint8_t const CMD9 = 0x09;
|
||||||
/** SEND_CID - read the card identification information (CID register) */
|
/** SEND_CID - read the card identification information (CID register) */
|
||||||
uint8_t const CMD10 = 0X0A;
|
uint8_t const CMD10 = 0x0A;
|
||||||
/** STOP_TRANSMISSION - end multiple block read sequence */
|
/** STOP_TRANSMISSION - end multiple block read sequence */
|
||||||
uint8_t const CMD12 = 0X0C;
|
uint8_t const CMD12 = 0x0C;
|
||||||
/** SEND_STATUS - read the card status register */
|
/** SEND_STATUS - read the card status register */
|
||||||
uint8_t const CMD13 = 0X0D;
|
uint8_t const CMD13 = 0x0D;
|
||||||
/** READ_SINGLE_BLOCK - read a single data block from the card */
|
/** READ_SINGLE_BLOCK - read a single data block from the card */
|
||||||
uint8_t const CMD17 = 0X11;
|
uint8_t const CMD17 = 0x11;
|
||||||
/** READ_MULTIPLE_BLOCK - read a multiple data blocks from the card */
|
/** READ_MULTIPLE_BLOCK - read a multiple data blocks from the card */
|
||||||
uint8_t const CMD18 = 0X12;
|
uint8_t const CMD18 = 0x12;
|
||||||
/** WRITE_BLOCK - write a single data block to the card */
|
/** WRITE_BLOCK - write a single data block to the card */
|
||||||
uint8_t const CMD24 = 0X18;
|
uint8_t const CMD24 = 0x18;
|
||||||
/** WRITE_MULTIPLE_BLOCK - write blocks of data until a STOP_TRANSMISSION */
|
/** WRITE_MULTIPLE_BLOCK - write blocks of data until a STOP_TRANSMISSION */
|
||||||
uint8_t const CMD25 = 0X19;
|
uint8_t const CMD25 = 0x19;
|
||||||
/** ERASE_WR_BLK_START - sets the address of the first block to be erased */
|
/** ERASE_WR_BLK_START - sets the address of the first block to be erased */
|
||||||
uint8_t const CMD32 = 0X20;
|
uint8_t const CMD32 = 0x20;
|
||||||
/** ERASE_WR_BLK_END - sets the address of the last block of the continuous
|
/** ERASE_WR_BLK_END - sets the address of the last block of the continuous
|
||||||
range to be erased*/
|
range to be erased*/
|
||||||
uint8_t const CMD33 = 0X21;
|
uint8_t const CMD33 = 0x21;
|
||||||
/** ERASE - erase all previously selected blocks */
|
/** ERASE - erase all previously selected blocks */
|
||||||
uint8_t const CMD38 = 0X26;
|
uint8_t const CMD38 = 0x26;
|
||||||
/** APP_CMD - escape for application specific command */
|
/** APP_CMD - escape for application specific command */
|
||||||
uint8_t const CMD55 = 0X37;
|
uint8_t const CMD55 = 0x37;
|
||||||
/** READ_OCR - read the OCR register of a card */
|
/** READ_OCR - read the OCR register of a card */
|
||||||
uint8_t const CMD58 = 0X3A;
|
uint8_t const CMD58 = 0x3A;
|
||||||
/** SET_WR_BLK_ERASE_COUNT - Set the number of write blocks to be
|
/** SET_WR_BLK_ERASE_COUNT - Set the number of write blocks to be
|
||||||
pre-erased before writing */
|
pre-erased before writing */
|
||||||
uint8_t const ACMD23 = 0X17;
|
uint8_t const ACMD23 = 0x17;
|
||||||
/** SD_SEND_OP_COMD - Sends host capacity support information and
|
/** SD_SEND_OP_COMD - Sends host capacity support information and
|
||||||
activates the card's initialization process */
|
activates the card's initialization process */
|
||||||
uint8_t const ACMD41 = 0X29;
|
uint8_t const ACMD41 = 0x29;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/** status for card in the ready state */
|
/** status for card in the ready state */
|
||||||
uint8_t const R1_READY_STATE = 0X00;
|
uint8_t const R1_READY_STATE = 0x00;
|
||||||
/** status for card in the idle state */
|
/** status for card in the idle state */
|
||||||
uint8_t const R1_IDLE_STATE = 0X01;
|
uint8_t const R1_IDLE_STATE = 0x01;
|
||||||
/** status bit for illegal command */
|
/** status bit for illegal command */
|
||||||
uint8_t const R1_ILLEGAL_COMMAND = 0X04;
|
uint8_t const R1_ILLEGAL_COMMAND = 0x04;
|
||||||
/** start data token for read or write single block*/
|
/** start data token for read or write single block*/
|
||||||
uint8_t const DATA_START_BLOCK = 0XFE;
|
uint8_t const DATA_START_BLOCK = 0xFE;
|
||||||
/** stop token for write multiple blocks*/
|
/** stop token for write multiple blocks*/
|
||||||
uint8_t const STOP_TRAN_TOKEN = 0XFD;
|
uint8_t const STOP_TRAN_TOKEN = 0xFD;
|
||||||
/** start data token for write multiple blocks*/
|
/** start data token for write multiple blocks*/
|
||||||
uint8_t const WRITE_MULTIPLE_TOKEN = 0XFC;
|
uint8_t const WRITE_MULTIPLE_TOKEN = 0xFC;
|
||||||
/** mask for data response tokens after a write block operation */
|
/** mask for data response tokens after a write block operation */
|
||||||
uint8_t const DATA_RES_MASK = 0X1F;
|
uint8_t const DATA_RES_MASK = 0x1F;
|
||||||
/** write data accepted token */
|
/** write data accepted token */
|
||||||
uint8_t const DATA_RES_ACCEPTED = 0X05;
|
uint8_t const DATA_RES_ACCEPTED = 0x05;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
/** Card IDentification (CID) register */
|
/** Card IDentification (CID) register */
|
||||||
typedef struct CID {
|
typedef struct CID {
|
||||||
@ -203,7 +203,7 @@ typedef struct CSDV2 {
|
|||||||
unsigned char reserved1 : 6;
|
unsigned char reserved1 : 6;
|
||||||
unsigned char csd_ver : 2;
|
unsigned char csd_ver : 2;
|
||||||
// byte 1
|
// byte 1
|
||||||
/** fixed to 0X0E */
|
/** fixed to 0x0E */
|
||||||
unsigned char taac;
|
unsigned char taac;
|
||||||
// byte 2
|
// byte 2
|
||||||
/** fixed to 0 */
|
/** fixed to 0 */
|
||||||
|
@ -167,7 +167,7 @@ bool SdVolume::fatGet(uint32_t cluster, uint32_t* value) {
|
|||||||
index += index >> 1;
|
index += index >> 1;
|
||||||
lba = fatStartBlock_ + (index >> 9);
|
lba = fatStartBlock_ + (index >> 9);
|
||||||
if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto fail;
|
if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto fail;
|
||||||
index &= 0X1FF;
|
index &= 0x1FF;
|
||||||
uint16_t tmp = cacheBuffer_.data[index];
|
uint16_t tmp = cacheBuffer_.data[index];
|
||||||
index++;
|
index++;
|
||||||
if (index == 512) {
|
if (index == 512) {
|
||||||
@ -175,7 +175,7 @@ bool SdVolume::fatGet(uint32_t cluster, uint32_t* value) {
|
|||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
tmp |= cacheBuffer_.data[index] << 8;
|
tmp |= cacheBuffer_.data[index] << 8;
|
||||||
*value = cluster & 1 ? tmp >> 4 : tmp & 0XFFF;
|
*value = cluster & 1 ? tmp >> 4 : tmp & 0xFFF;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (fatType_ == 16) {
|
if (fatType_ == 16) {
|
||||||
@ -191,10 +191,10 @@ bool SdVolume::fatGet(uint32_t cluster, uint32_t* value) {
|
|||||||
if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto fail;
|
if (!cacheRawBlock(lba, CACHE_FOR_READ)) goto fail;
|
||||||
}
|
}
|
||||||
if (fatType_ == 16) {
|
if (fatType_ == 16) {
|
||||||
*value = cacheBuffer_.fat16[cluster & 0XFF];
|
*value = cacheBuffer_.fat16[cluster & 0xFF];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*value = cacheBuffer_.fat32[cluster & 0X7F] & FAT32MASK;
|
*value = cacheBuffer_.fat32[cluster & 0x7F] & FAT32MASK;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
fail:
|
fail:
|
||||||
@ -217,7 +217,7 @@ bool SdVolume::fatPut(uint32_t cluster, uint32_t value) {
|
|||||||
if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail;
|
if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail;
|
||||||
// mirror second FAT
|
// mirror second FAT
|
||||||
if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
|
if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
|
||||||
index &= 0X1FF;
|
index &= 0x1FF;
|
||||||
uint8_t tmp = value;
|
uint8_t tmp = value;
|
||||||
if (cluster & 1) {
|
if (cluster & 1) {
|
||||||
tmp = (cacheBuffer_.data[index] & 0XF) | tmp << 4;
|
tmp = (cacheBuffer_.data[index] & 0XF) | tmp << 4;
|
||||||
@ -233,7 +233,7 @@ bool SdVolume::fatPut(uint32_t cluster, uint32_t value) {
|
|||||||
}
|
}
|
||||||
tmp = value >> 4;
|
tmp = value >> 4;
|
||||||
if (!(cluster & 1)) {
|
if (!(cluster & 1)) {
|
||||||
tmp = ((cacheBuffer_.data[index] & 0XF0)) | tmp >> 4;
|
tmp = ((cacheBuffer_.data[index] & 0xF0)) | tmp >> 4;
|
||||||
}
|
}
|
||||||
cacheBuffer_.data[index] = tmp;
|
cacheBuffer_.data[index] = tmp;
|
||||||
return true;
|
return true;
|
||||||
@ -250,10 +250,10 @@ bool SdVolume::fatPut(uint32_t cluster, uint32_t value) {
|
|||||||
if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail;
|
if (!cacheRawBlock(lba, CACHE_FOR_WRITE)) goto fail;
|
||||||
// store entry
|
// store entry
|
||||||
if (fatType_ == 16) {
|
if (fatType_ == 16) {
|
||||||
cacheBuffer_.fat16[cluster & 0XFF] = value;
|
cacheBuffer_.fat16[cluster & 0xFF] = value;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cacheBuffer_.fat32[cluster & 0X7F] = value;
|
cacheBuffer_.fat32[cluster & 0x7F] = value;
|
||||||
}
|
}
|
||||||
// mirror second FAT
|
// mirror second FAT
|
||||||
if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
|
if (fatCount_ > 1) cacheMirrorBlock_ = lba + blocksPerFat_;
|
||||||
@ -344,7 +344,7 @@ bool SdVolume::init(Sd2Card* dev, uint8_t part) {
|
|||||||
allocSearchStart_ = 2;
|
allocSearchStart_ = 2;
|
||||||
cacheDirty_ = 0; // cacheFlush() will write block if true
|
cacheDirty_ = 0; // cacheFlush() will write block if true
|
||||||
cacheMirrorBlock_ = 0;
|
cacheMirrorBlock_ = 0;
|
||||||
cacheBlockNumber_ = 0XFFFFFFFF;
|
cacheBlockNumber_ = 0xFFFFFFFF;
|
||||||
|
|
||||||
// if part == 0 assume super floppy with FAT boot sector in block zero
|
// if part == 0 assume super floppy with FAT boot sector in block zero
|
||||||
// if part > 0 assume mbr volume with partition table
|
// if part > 0 assume mbr volume with partition table
|
||||||
@ -352,7 +352,7 @@ bool SdVolume::init(Sd2Card* dev, uint8_t part) {
|
|||||||
if (part > 4)goto fail;
|
if (part > 4)goto fail;
|
||||||
if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) goto fail;
|
if (!cacheRawBlock(volumeStartBlock, CACHE_FOR_READ)) goto fail;
|
||||||
part_t* p = &cacheBuffer_.mbr.part[part - 1];
|
part_t* p = &cacheBuffer_.mbr.part[part - 1];
|
||||||
if ((p->boot & 0X7F) != 0 ||
|
if ((p->boot & 0x7F) != 0 ||
|
||||||
p->totalSectors < 100 ||
|
p->totalSectors < 100 ||
|
||||||
p->firstSector == 0) {
|
p->firstSector == 0) {
|
||||||
// not a valid partition
|
// not a valid partition
|
||||||
|
@ -76,7 +76,7 @@ class SdVolume {
|
|||||||
*/
|
*/
|
||||||
cache_t* cacheClear() {
|
cache_t* cacheClear() {
|
||||||
if (!cacheFlush()) return 0;
|
if (!cacheFlush()) return 0;
|
||||||
cacheBlockNumber_ = 0XFFFFFFFF;
|
cacheBlockNumber_ = 0xFFFFFFFF;
|
||||||
return &cacheBuffer_;
|
return &cacheBuffer_;
|
||||||
}
|
}
|
||||||
/** Initialize a FAT volume. Try partition one first then try super
|
/** Initialize a FAT volume. Try partition one first then try super
|
||||||
|
@ -45,7 +45,7 @@
|
|||||||
#define PCA9632_PWM3 0x05
|
#define PCA9632_PWM3 0x05
|
||||||
#define PCA9632_GRPPWM 0x06
|
#define PCA9632_GRPPWM 0x06
|
||||||
#define PCA9632_GRPFREQ 0x07
|
#define PCA9632_GRPFREQ 0x07
|
||||||
#define PCA9632_LEDOUT 0X08
|
#define PCA9632_LEDOUT 0x08
|
||||||
#define PCA9632_SUBADR1 0x09
|
#define PCA9632_SUBADR1 0x09
|
||||||
#define PCA9632_SUBADR2 0x0A
|
#define PCA9632_SUBADR2 0x0A
|
||||||
#define PCA9632_SUBADR3 0x0B
|
#define PCA9632_SUBADR3 0x0B
|
||||||
|
@ -455,7 +455,7 @@ void badPinCheck(uint8_t pin) {
|
|||||||
static inline __attribute__((always_inline))
|
static inline __attribute__((always_inline))
|
||||||
void fastBitWriteSafe(volatile uint8_t* address, uint8_t bit, bool level) {
|
void fastBitWriteSafe(volatile uint8_t* address, uint8_t bit, bool level) {
|
||||||
uint8_t oldSREG;
|
uint8_t oldSREG;
|
||||||
if (address > (uint8_t*)0X5F) {
|
if (address > (uint8_t*)0x5F) {
|
||||||
oldSREG = SREG;
|
oldSREG = SREG;
|
||||||
cli();
|
cli();
|
||||||
}
|
}
|
||||||
@ -464,7 +464,7 @@ void fastBitWriteSafe(volatile uint8_t* address, uint8_t bit, bool level) {
|
|||||||
} else {
|
} else {
|
||||||
*address &= ~(1 << bit);
|
*address &= ~(1 << bit);
|
||||||
}
|
}
|
||||||
if (address > (uint8_t*)0X5F) {
|
if (address > (uint8_t*)0x5F) {
|
||||||
SREG = oldSREG;
|
SREG = oldSREG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -488,7 +488,7 @@ bool fastDigitalRead(uint8_t pin) {
|
|||||||
static inline __attribute__((always_inline))
|
static inline __attribute__((always_inline))
|
||||||
void fastDigitalToggle(uint8_t pin) {
|
void fastDigitalToggle(uint8_t pin) {
|
||||||
badPinCheck(pin);
|
badPinCheck(pin);
|
||||||
if (pinMap[pin].pin > (uint8_t*)0X5F) {
|
if (pinMap[pin].pin > (uint8_t*)0x5F) {
|
||||||
// must write bit to high address port
|
// must write bit to high address port
|
||||||
*pinMap[pin].pin = 1 << pinMap[pin].bit;
|
*pinMap[pin].pin = 1 << pinMap[pin].bit;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user