floobydust wrote:
Some questions regarding your hardware setup:
1- Are you running the CF Card in memory mode or True IDE mode?
2- Are you using a 16-bit data transfer or an 8-bit data transfer?
3- Are you using DMA or PIO transfers?
4- Are you using interrupts on the hardware?
I am using 8bit data transfer. No interrupts nor DMA.
Configuration is the sam as in 6800 example I've mentioned above:
Code:
********************************
* INITIALIZE CF
********************************
CFINIT LDAA #$04 RESET COMMAND
STAA CFREG7
JSR CFWAIT
LDAA #$E0 LBA3=0, MASTER, MODE=LBA
STAA CFREG6
LDAA #$01 8-BIT TRANSFERS
STAA CFREG1
LDAA #$EF SET FEATURE COMMAND
STAA CFREG7
JSR CFWAIT
JSR CFCHERR
RTS
Which in my case is:
Code:
uint8_t cfInit(void) {
CFREG7 = CMD_RST;
cfWait();
CFREG6 = 0xE0; // LBA3=0, MASTER, MODE=LBA
CFREG1 = 0x01; // 8-BIT TRANSFERS
CFREG7 = 0xEF; // SET FEATURE COMMAND
cfWait();
// check for error now and return
if (CFREG7 & MASK_ERROR) return 1;
return 0;
}
Quote:
Words 60-61 (4 bytes) contains the LBA count of the device.
So, in case (8bit transfer mode) this information will be stored in bytes 120-123.
I do not store entre data sequence in 512 bytes long buffer. I simply count incoming bytes and operate or those, which I am interested in.
So, is my current version of the code valid?
Code:
uint8_t cfGetSizeInfo(uint32_t *availableBlocks, uint16_t *sizeOfBlock) {
uint16_t i=0;
uint8_t tmp;
*availableBlocks = 0x00000000;
cfWait();
CFREG7 = CMD_INFO_COMMAND;
cfWait();
while (CFREG7 & MASK_DRQ) {
tmp = CFREG0;
if (i == 120) { *availableBlocks |= (uint32_t)tmp; }
else if (i == 121) {*availableBlocks |= ((uint32_t)tmp << 8); }
else if (i == 122) {*availableBlocks |= ((uint32_t)tmp << 16); }
else if (i == 123) {*availableBlocks |= ((uint32_t)tmp << 24); }
i++;
cfWait();
}
*sizeOfBlock = 512;
return 1;
}