<< Previous | Next >>

sdspi_process_command

int sdspi_process_command( sd_device *sd, SD_CMD_REPLY * cmd_reply, int mode );

Description

This function sends the command placed in the cmd_reply structure and retrieves a reply and data (optional) as defined in the cmd_reply structure. Pointers to TX and RX buffers are retrieved from the cmd_reply structure and used for command transmission and reply/data reception. Reply is parsed and placed in cmd_reply.reply. Errors encountered will give a negative return value.

The SPI semaphore is obtained before the command is sent. The mode parameter controls whether the semaphore will be released after command execution and reply/data reception. If mode is zero, both semaphore and chip select are active on a successful return. An end command sequence and release of the semaphore must be handled by caller.

If mode is not 0, the semaphore will be released before returning. In addition, if mode is 2 then an SD card reset is in progress. This enables the distinguishing of certain I/O error conditions that would normally be grouped with the -EIO error code and instead return the -EAGAIN error code, indicating reset retries should continue.

Parameter

sd
Pointer to sd_device structure of the SD card.

cmd_reply
Pointer to cmd_reply structure, which contains:

cmd - command to be executed
argument - arguments for the command
reply - storage for command reply
reply_size - size in bytes of expected reply
data_size - size in bytes of expected data
tx_buffer - pointer to TX buffer to use
rx_buffer - pointer to RX buffer to use
mode
One of the following:

0 = SPI port semaphore should be retained.
1 = If SPI port to be released before return.
2 = Attempting SD card reset, otherwise same as mode "1". (Enables -EAGAIN return value.)

Return Value

0: Success
-EIO: I/O error
-EAGAIN: Allowable I/O error during card reset
-EINVAL: Invalid parameter given
-ENOMEDIUM: No SD card in socket
-ESHAREDBUSY: Shared SPI port busy

Library

SDFLASH.LIB


Dynamic C Functions << Previous | Next >> rabbit.com