Data Fields | |
uint8_t | bufferState |
The buffer state. | |
uint8_t | cardType |
The recognised small memory card (SMC) | |
uint8_t | csd [16] |
The cards CSD. | |
uint8_t | flag |
The action flag. | |
uint8_t | lastCmdResp [5] |
Last command response. | |
uint8_t | lastDatResp |
Last data response. | |
uint8_t | ocr [4] |
The cards OCR. | |
pt_t | pt |
The (raw) protothread data structure for the SMC handling thread. | |
uint8_t | retC |
The return code of the last schedule. | |
uint32_t | rwSector |
Buffer address. | |
uint8_t | sectorBuff [SMC_SEC_BUF_SZ] |
The sector buffer. | |
p2ptFunV | theSMCfun |
The SMC thread function (pointer to) |
The organisational data for a small memory card (SMC) handling thread.
A structure of this type hold the state of one small memory card (SMC) as well as of a handling thread.
uint8_t flag |
The action flag.
0 means nothing to do.
Bit 4 : power up (80 dummy clocks), CT_POWERD_UP
Bit 5 : set idle CT_INSERTED
Bit 6 : determine card type FL_CAT
Bit 7 : if no card inserted and powered up, check for it.
Bit 1 : read sector FL_RDS
Bit 2 : write sector FL_WRS
Bits 0..6 will be cleared by the respective action performed.
Bit 7 will not be cleared by the "check for card" action. If a card is (newly) detected bits 4 to 6 will be set
uint8_t retC |
The return code of the last schedule.
This is intended to hold the return code, i.e. the SMC thread function's last return value.
The SMC thread function (pointer to)
The function pointer will be initialised pointing to smcThreadF, the system provided SMC handling thread. It is provided for future use to put an application specific handler in.
uint8_t bufferState |
The buffer state.
Bit 1 : sector in sync with SMC by just so read or written FL_RDS
Bit 2 : sector to be written after being modified FL_WRS
If neither bit 1 nor bit 2 is set the buffer .sectorBuff has no relation to the SMC's sector
rwSector
. If either is set .sectorBuff is the actual or intended content implying a read operation on
rwSector
redundant.
uint8_t lastDatResp |
Last data response.
This byte is set by some (block) write / read functions as received from the device. The bit pattern is xxx0rrr1.
rrr = 010 : data accepted
rrr = 101 : data rejected due to a CRC error
rrr = 110 : data rejected due to a write error
uint8_t lastCmdResp[5] |
Last command response.
In this field the functions sendCmd(), sendCmd0arg() and alike store their last return value for later reference. A R1 response would be in the first byte (SMC_LAST_R1 or lastCmdResp[0]).
uint8_t ocr[4] |
The cards OCR.
This is the informational part of the R3 response. It is valid if (one bit of) CT_TYPE_MASK bit is set in .cardType
uint8_t csd[16] |
The cards CSD.
This is the informational part of the R3 response. It is valid if (one bit of) CT_TYPE_MASK bit is set in .cardType
uint8_t cardType |
The recognised small memory card (SMC)
The value 0 means no usable card recognised. The lower 4 bits contain the card type information; the upper 4 bits show recognised operational conditions
Bit 0 (CT_V_3) : MMC version 3
Bit 1 (CT_V_1) : SD version 1
Bit 2 (CT_V_2) : SD version 2
Bit 3 (CT_HC ) : high capacity (V.2) respectively block addressing mode
Bit 4 (CT_POWERD_UP) : card has been successfully powered up (to idle state)
Bit 5 (CT_INSERTED) : a card is (seems to be) inserted
Bit 4 (CT_POWERD_UP) is set by getting a card successfully to idle state. Bit 5 (CT_INSERTED) is set by any valid command response (or card switch). It is reset by no valid card response (i.e. MoSi always tri-stated).
Hint1: Bits 0..4 are compatible to petit FATFS for the purpose of using its file system implementation.
Hint2: For high capacity a 32-bit argument of memory access commands means the block address and the block length is fixed to 512 bytes. (For standard capacity cards this would be a byte address and the block length is determined by CMD16,
uint32_t rwSector |
Buffer address.
This is the address in the form of a 512 byte sector number (independent of card type) of the buffer .sectorBuff.
uint8_t sectorBuff[SMC_SEC_BUF_SZ] |
The sector buffer.
This is a buffer for a 512 byte sector. The buffer's size is larger (SMC_SEC_BUF_SZ bytes) to handle some extra bytes like CRC. If the SMC is not used the space can serve other purposes.
If the bit FL_RDS is set in bufferState
the content is the (cached) SMC's content at readSector
. If the bit FL_WRS is set in bufferState
the content is the (cached) SMC's content at writeSector
.
Any software that changes writeSector
, readSector
or the first 512 bytes of sectorBuff
must clear the respective flag bits in bufferState
.