Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
05/19/04 11:07
Read: times


 
#70679 - RE: connectors for CF cards
Responding to: ???'s previous message
Benny & Thomas said:
To continue with the post , would there be any way to estimate the time to read the 128 MB CF card when using a 89C51rdxx running at 12 MHz ??


I have made up a simple test platform with a CF (Compact Flash) card. I setup the card interface in the external RAM space of the microcontroller. The card is technically capable of supporting data at a rate of 100 nanoseconds (or less) per byte into or out of the CF cards sector buffer. So it is possible to transfer data as fast as the loop you could care to code up for the 8051. Just know that the loop must stop after 512 bytes of the current sector have been moved so that the command to access the next sector can be given. (In the case of writing to the card there needs to be some "card busy" polling since the write to FLASH takes some time).

The code below demonstrates a reading routine for a CF sector to transfer a card sector to a 512 byte buffer elsewhere in external RAM.
/* 
**
** routine to read one or more sectors from the compact flash card into
** XRAM memory at the specified buffer address.
**
*/

void CF_ReadSector(unsigned char xdata *buf, unsigned long lsn, unsigned char cnt)
{
    union LSN32 lsn_split;
    unsigned int i;

    lsn_split.l = lsn;

    CF_WaitReady();                                     /* wait for card to be ready */
    XBYTE[CF_SEC_CNT_REG] = cnt;
    XBYTE[CF_SEC_NUM_REG] = lsn_split.b[3];             /* (LBA 07-00) */
    XBYTE[CF_CYL_LOW_REG] = lsn_split.b[2];             /* (LBA 15-08) */
    XBYTE[CF_CYL_HIG_REG] = lsn_split.b[1];             /* (LBA 23-16) */
    XBYTE[CF_DR_HEAD_REG] = (lsn_split.b[0] & 0x0F) | 0xE0; /* 1 LBA 1 DRV0 (LBA 27-24) */
    XBYTE[CF_COMMAND_REG] = CF_CMD_READ_SEC;            /* send out the read command */

    while(cnt--)                                        /* loop to handle sectors */
    {
        CF_WaitReady();                                 /* wait for card to be ready */
        i = 512;                                        /* 512 bytes per sector */
        while(i--)
        {
            *buf++ = XBYTE[CF_DATA_REG];
        }
    }
}


There is a way to code the loop in assembly language so that it can be as fast as possible. I show below one method for this loop to read from a fixed XRAM location to another XRAM buffer. If you have a microcontroller with two DPTR registers this loop can be made a bit faster.

     MOV   DPTR, #BUFF  ; setup XRAM buffer pointer
     MOV   R6, DPH      ; save pointer into R6::R7
     MOV   R7, DPL
     MOV   R5, #0       ; clear the loop counter
READ_LOOP1:
     MOV   DPTR, #CF_DATA_REG  ; point to data port on 
                               ; CF card interface
     MOVX  A, @DPTR     ; get byte from CF interface
     MOV   DPH, R6      ; get pointer for buffer
     MOV   DPL, R7
     MOVX  @DPTR, A     ; move byte of data to buff
     INC   DPTR         ; increment buffer pointer
     MOV   R6, DPH      ; save pointer back to R6::R7
     MOV   R7, DPL
     DJNZ  R5, READ_LOOP1  ; process loop for 1st 256
;
READ_LOOP2:
     MOV   DPTR, #CF_DATA_REG  ; point to data port on 
                               ; CF card interface
     MOVX  A, @DPTR     ; get byte from CF interface
     MOV   DPH, R6      ; get pointer for buffer
     MOV   DPL, R7
     MOVX  @DPTR, A     ; move byte of data to buff
     INC   DPTR         ; increment buffer pointer
     MOV   R6, DPH      ; save pointer back to R6::R7
     MOV   R7, DPL
     DJNZ  R5, READ_LOOP2  ; process loop for 2nd 256


The implementation of such a loop on your particular microcontroller will determine the fastest byte rate that is attainable to/from the CF card. This should help you calculate then how fast that the total card can be read. Do note however that the data from the card probably needs to be sent somewhere other than just an XRAM buffer for it to be useful in a real application. Thus you must consider the additional time needed to handle the data for the real application as each sector is read from the card.

In the test platform I built some time back I determined that the above type of loop was too slow to support a "real" CF card application so I built my external memory interface with 64K bytes of SRAM (minus the decode space for the CF card inteface). I put a small CPLD in between the microcontroller and the SRAM. The CPLD allows the microcontroller to access the SRAM in the normal manner including implementing the address latch. It also supports the decoding for the CF ports. There is also special logic in the CPLD with a 16-bit address counter that can supply the address for the SRAM when the microcontroller is accessing the data port of the CF card interface. Using a technique that I call "fly-by DMA" when the microcontroller reads the CF card data register the CPLD simultaneously writes the data "on the fly" to the SRAM. The microcontroller can thus setup the CF card for reading and also set the buffer start address in the CPLD address counter. After everything is all setup then the loops to read the CF card can be as short as:
    MOV    DPTR, #CF_DATA_PORT
    MOV    R6, #0
RD_LP1:
    MOVX   A, @DPTR
    DJNZ   R6, RD_LP1
RD_LP2:
    MOVX   A, @DPTR
    DJNZ   R6, RD_LP2


There is also a completely analogous method to read SRAM and write to the CF card data port.

As you can see this is MUCH faster, particularly on a high speed 1X clocker type microcontroller such as the C8052F020 from Cygnal (Silicon Laboratories).

Michael Karas






List of 18 messages in thread
TopicAuthorDate
connectors for CF cards            01/01/70 00:00      
   RE: connectors for CF cards            01/01/70 00:00      
      RE: connectors for CF cards            01/01/70 00:00      
         RE: connectors for CF cards            01/01/70 00:00      
            RE: connectors for CF cards            01/01/70 00:00      
               RE: connectors for CF cards            01/01/70 00:00      
                  RE: connectors for CF cards            01/01/70 00:00      
      RE: connectors for CF cards            01/01/70 00:00      
         RE: Correction            01/01/70 00:00      
      RE: connectors for CF cards            01/01/70 00:00      
   RE: connectors for CF cards            01/01/70 00:00      
      RE: connectors for CF cards            01/01/70 00:00      
   RE: connectors for CF cards            01/01/70 00:00      
      RE: connectors for CF cards            01/01/70 00:00      
         RE: connectors for CF cards            01/01/70 00:00      
            RE: connectors for CF cards            01/01/70 00:00      
               RE: connectors for CF cards            01/01/70 00:00      
                  RE: connectors for CF cards            01/01/70 00:00      

Back to Subject List