Altera HWLIB  16.0
The Altera HW Manager API Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups
General Control and Status Functions

Description

The declarations and functions in this group provide general purpose control and status functions for the SD/MMC Controller.

Data Structures

struct  ALT_SDMMC_CARD_INFO_s
 
struct  ALT_SDMMC_CMD_CONFIG_s
 
struct  ALT_SDMMC_RESPONSE_s
 

Typedefs

typedef enum ALT_SDMMC_CARD_TYPE_e ALT_SDMMC_CARD_TYPE_t
 
typedef struct
ALT_SDMMC_CARD_INFO_s 
ALT_SDMMC_CARD_INFO_t
 
typedef enum ALT_SDMMC_CMD_TYPE_e ALT_SDMMC_CMD_TYPE_t
 
typedef enum
ALT_SDMMC_TRANSFER_SPEED_e 
ALT_SDMMC_TRANSFER_SPEED_t
 
typedef enum ALT_SDMMC_CMD_INDEX_e ALT_SDMMC_CMD_INDEX_t
 
typedef struct
ALT_SDMMC_CMD_CONFIG_s 
ALT_SDMMC_CMD_CONFIG_t
 
typedef struct ALT_SDMMC_RESPONSE_s ALT_SDMMC_RESPONSE_t
 
typedef enum ALT_SDMMC_INT_STATUS_e ALT_SDMMC_INT_STATUS_t
 

ENUMS

enum  ALT_SDMMC_CARD_TYPE_e {
  ALT_SDMMC_CARD_TYPE_NOTDETECT = 0, ALT_SDMMC_CARD_TYPE_MMC = 1, ALT_SDMMC_CARD_TYPE_SD = 2, ALT_SDMMC_CARD_TYPE_SDIOIO = 3,
  ALT_SDMMC_CARD_TYPE_SDIOCOMBO = 4, ALT_SDMMC_CARD_TYPE_SDHC = 5, ALT_SDMMC_CARD_TYPE_CEATA = 6
}
 
enum  ALT_SDMMC_CMD_TYPE_e { ALT_SDMMC_CMD_TYPE_BASIC, ALT_SDMMC_CMD_TYPE_ACMD }
 
enum  ALT_SDMMC_TRANSFER_SPEED_e { ALT_SDMMC_TRANSFER_SPEED_DEFAULT = 25000000, ALT_SDMMC_TRANSFER_SPEED_HIGH = 50000000 }
 
enum  ALT_SDMMC_CMD_INDEX_e
 
enum  ALT_SDMMC_INT_STATUS_e {
  ALT_SDMMC_INT_STATUS_CD = (1UL << 0), ALT_SDMMC_INT_STATUS_RE = (1UL << 1), ALT_SDMMC_INT_STATUS_CMD = (1UL << 2), ALT_SDMMC_INT_STATUS_DTO = (1UL << 3),
  ALT_SDMMC_INT_STATUS_TXDR = (1UL << 4), ALT_SDMMC_INT_STATUS_RXDR = (1UL << 5), ALT_SDMMC_INT_STATUS_RCRC = (1UL << 6), ALT_SDMMC_INT_STATUS_DCRC = (1UL << 7),
  ALT_SDMMC_INT_STATUS_RTO = (1UL << 8), ALT_SDMMC_INT_STATUS_DRTO = (1UL << 9), ALT_SDMMC_INT_STATUS_HTO = (1UL << 10), ALT_SDMMC_INT_STATUS_FRUN = (1UL << 11),
  ALT_SDMMC_INT_STATUS_HLE = (1UL << 12), ALT_SDMMC_INT_STATUS_SBE = (1UL << 13), ALT_SDMMC_INT_STATUS_ACD = (1UL << 14), ALT_SDMMC_INT_STATUS_EBE = (1UL << 15),
  ALT_SDMMC_INT_STATUS_SDIO_0 = (1UL << 16), ALT_SDMMC_INT_STATUS_ALL = 0x1FFFF
}
 

Functions

ALT_STATUS_CODE alt_sdmmc_init (void)
 
ALT_STATUS_CODE alt_sdmmc_uninit (void)
 
ALT_STATUS_CODE alt_sdmmc_reset (void)
 
ALT_STATUS_CODE alt_sdmmc_command_send (ALT_SDMMC_CMD_TYPE_t command_type, ALT_SDMMC_CMD_INDEX_t command, uint32_t command_arg, uint32_t *response)
 
ALT_STATUS_CODE alt_sdmmc_read_long_response (ALT_SDMMC_RESPONSE_t *response)
 
uint32_t alt_sdmmc_int_status_get (void)
 
uint32_t alt_sdmmc_int_mask_get (void)
 
ALT_STATUS_CODE alt_sdmmc_int_clear (const uint32_t mask)
 
ALT_STATUS_CODE alt_sdmmc_int_disable (const uint32_t mask)
 
ALT_STATUS_CODE alt_sdmmc_int_enable (const uint32_t mask)
 

Data Structure Documentation

struct ALT_SDMMC_CARD_INFO_s

This type defines a structure to hold identification and type information for a card connected to the SD/MMC controller.

Data Fields
ALT_SDMMC_CARD_TYPE_t card_type Type of the card
uint32_t rca Releative Card Address (RCA)
uint32_t xfer_speed The maximum data transfer rate (bit/s)
uint32_t max_r_blkln Max read data block length
uint32_t max_w_blkln Max write data block length
bool partial_r_allowed Partial blocks for read allowed
bool partial_w_allowed Partial blocks for write allowed
bool high_speed 50MHz high speed allowed
uint32_t scr_sd_spec SD_SPEC field in SCR register
uint32_t csd_ccc CCC field in CSD register
uint32_t blk_number_high High 32-bit of total number of blocks
uint32_t blk_number_low Low 32-bit of total number of blocks. Total number of blocks calculated from C_SIZE_MULT and C_SIZE field in CSD register version 1.0: blk_number = (C_SIZE + 1) * (1 << (C_SIZE_MULT + 2)). memory capacity = blk_number_low * max_r_blnln. Total number of blocks calculated from C_SIZE in CSD register version 2.0: blk_number_high = ((C_SIZE+1) * 1024) >> 32. blk_number_low = ((C_SIZE+1) * 1024) & 0xFFFFFFFF. memory capacity = (block_number_high << 32 | block_number_low) * 512 byte
uint32_t scr_bus_widths SD_BUS_WIDTHS field in SCR register
struct ALT_SDMMC_CMD_CONFIG_s

This type defines a structure for command with options.

Data Fields
uint32_t cmd_index: 6 Command index. Bit 5-0
uint32_t response_expect: 1 Response expected from card. Bit 6
uint32_t response_length_long: 1 Long response expected from card. Bit 7
uint32_t check_response_crc: 1 Check response CRC. Bit 8
uint32_t data_expected: 1 Data transfer expected (read/write). Bit 9
uint32_t write_active: 1 0 - Read from card. 1 - Write to card. Bit 10
uint32_t stream_mode_active: 1 Stream data transfer command. Bit 11
uint32_t send_auto_stop: 1 Send stop command at end of data transfer. Bit 12
uint32_t wait_prvdata_complete: 1 Wait for previous data transfer completion before sending command. Bit 13
uint32_t stop_abort_cmd: 1 Stop or abort command intended to stop current data transfer in progress. Bit 14
uint32_t send_initialization: 1 Send initialization sequence before sending this command, Bit 15
uint32_t card_number: 5 Card number in use. Represents physical slot number of card being accessed. Bit 20-16
uint32_t update_clock_registers_only: 1 Do not send commands, just update clock register value into card clock domain. Bit 21
uint32_t read_ceata_device: 1 Host is performing read access (RW_REG or RW_BLK) towards CE-ATA device. Bit 22
uint32_t ccs_expected: 1 Interrupts are enabled in CE-ATA device (nIEN = 0), and RW_BLK command expects command completion signal from CE-ATA device. Bit 23
uint32_t enable_boot: 1 Enable Boot this bit should be set only for mandatory boot mode. Bit 24
uint32_t expect_boot_ack: 1 Expect Boot Acknowledge. When Software sets this bit along with enable_boot, CIU expects a boot acknowledge start pattern of 0-1-0 from the selected card. Bit 25
uint32_t disable_boot: 1 Disable Boot. Bit 26
uint32_t boot_mode: 1 Boot Mode 0 - Mandatory Boot operation 1 - Alternate Boot operation Bit 27
uint32_t volt_switch: 1 Voltage switching enabled; must be set for CMD11 only. Bit 28
uint32_t use_hold_reg: 1 CMD and DATA sent to card through the HOLD Register. Bit 29
uint32_t reserved: 1 Reserved. Bit 30
uint32_t start_bit: 1 Start command. Once command is taken by CIU, bit is cleared. When bit is set, host should not attempt to write to any command registers. If write is attempted, hardware lock error is set in raw interrupt register. Bit 31
struct ALT_SDMMC_RESPONSE_s

This type defines a structure for get long response of last last complete command.

Typedef Documentation

This type enumerates the possible card/device type that may be connected to the SD/MMC controller.

This type defines a structure to hold identification and type information for a card connected to the SD/MMC controller.

This type enumerates the SD/MMC basic commands, application specific commands etc.

This type enumerates two common SD/MMC bus speeds for demonstration purpose only. It's not a complete list of actual bus speeds supported.

This type enumerates the SDMMC evailable commands. Read specification to the appropriate card type

This type defines a structure for command with options.

This type defines a structure for get long response of last last complete command.

This type definition enumerates the interrupt status conditions that contribute to the ALT_INT_INTERRUPT_SDMMC_IRQ signal state.

NOTE: Both the general purpose interrupt status conditions for the SD/MMC controller (ALT_SDMMC_INT_STATUS_t) and the interrupt status conditions for the internal DMA controller (ALT_SDMMC_DMA_INT_STATUS_t) contribute to the overall ALT_INT_INTERRUPT_SDMMC_IRQ signal state

Enumeration Type Documentation

This type enumerates the possible card/device type that may be connected to the SD/MMC controller.

Enumerator:
ALT_SDMMC_CARD_TYPE_NOTDETECT 

Cart type has not identified yet

ALT_SDMMC_CARD_TYPE_MMC 

MultiMedia Card

ALT_SDMMC_CARD_TYPE_SD 

Secure Digital Memory Card

ALT_SDMMC_CARD_TYPE_SDIOIO 

Secure Digital Input Output

ALT_SDMMC_CARD_TYPE_SDIOCOMBO 

Secure Digital Input Output Combo

ALT_SDMMC_CARD_TYPE_SDHC 

Secure Digital High Capacity

ALT_SDMMC_CARD_TYPE_CEATA 

Serial ATA interface based on the MultiMediaCard standard

This type enumerates the SD/MMC basic commands, application specific commands etc.

Enumerator:
ALT_SDMMC_CMD_TYPE_BASIC 

Standard SD/MMC commands denoted as CMD in the standard.

ALT_SDMMC_CMD_TYPE_ACMD 

Application specific commands or ACMDs that are preceded with APP_CMD (CMD55)

This type enumerates two common SD/MMC bus speeds for demonstration purpose only. It's not a complete list of actual bus speeds supported.

Enumerator:
ALT_SDMMC_TRANSFER_SPEED_DEFAULT 

25MHz

ALT_SDMMC_TRANSFER_SPEED_HIGH 

50MHz

This type enumerates the SDMMC evailable commands. Read specification to the appropriate card type

This type definition enumerates the interrupt status conditions that contribute to the ALT_INT_INTERRUPT_SDMMC_IRQ signal state.

NOTE: Both the general purpose interrupt status conditions for the SD/MMC controller (ALT_SDMMC_INT_STATUS_t) and the interrupt status conditions for the internal DMA controller (ALT_SDMMC_DMA_INT_STATUS_t) contribute to the overall ALT_INT_INTERRUPT_SDMMC_IRQ signal state

Enumerator:
ALT_SDMMC_INT_STATUS_CD 

Card Detect (CD)

ALT_SDMMC_INT_STATUS_RE 

Response Error (RE)

ALT_SDMMC_INT_STATUS_CMD 

Command Done (CMD)

ALT_SDMMC_INT_STATUS_DTO 

Data Transfer Over (DTO)

ALT_SDMMC_INT_STATUS_TXDR 

Transmit FIFO Data Request (TXDR)

ALT_SDMMC_INT_STATUS_RXDR 

Receive FIFO Data Request (RXDR)

ALT_SDMMC_INT_STATUS_RCRC 

Response CRC Error (RCRC)

ALT_SDMMC_INT_STATUS_DCRC 

Data CRC Error (DCRC)

ALT_SDMMC_INT_STATUS_RTO 

Response Timeout Boot Ack Received (RTO)

ALT_SDMMC_INT_STATUS_DRTO 

Data Read Timeout Boot Data Start (DRTO)

ALT_SDMMC_INT_STATUS_HTO 

Data Starvation Host Timeout (HTO) / Volt Switch_int

ALT_SDMMC_INT_STATUS_FRUN 

FIFO Underrun Overrun Error (FRUN)

ALT_SDMMC_INT_STATUS_HLE 

Hardware Locked Write Error (HLE)

ALT_SDMMC_INT_STATUS_SBE 

Start-Bit Error (SBE)

ALT_SDMMC_INT_STATUS_ACD 

Auto Command Done (ACD)

ALT_SDMMC_INT_STATUS_EBE 

End-Bit Error (read) / write no CRC (EBE)

ALT_SDMMC_INT_STATUS_SDIO_0 

SDIO Interrupt Card 0 - only one card supported

ALT_SDMMC_INT_STATUS_ALL 

All previous status types

Function Documentation

ALT_STATUS_CODE alt_sdmmc_init ( void  )

Initialize the SD/MMC controller.

Initializes the SD/MMC controller by gracefully bringing the controller out of reset. This function also initializes the registers, FIFO buffer pointers, DMA interface controls, and state machines in the controller. All interrupts are cleared and disabled (masked) and timeout parameters set to default values.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_STATUS_CODE alt_sdmmc_uninit ( void  )

Uninitializes the SD/MMC controller by stopping any data transfers in progress and putting the controller into reset.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_STATUS_CODE alt_sdmmc_reset ( void  )

Reset the SD/MMC controller by stopping any data transfers in progress and putting the controller into reset and reinit it after reset complete.

Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_STATUS_CODE alt_sdmmc_command_send ( ALT_SDMMC_CMD_TYPE_t  command_type,
ALT_SDMMC_CMD_INDEX_t  command,
uint32_t  command_arg,
uint32_t *  response 
)

Send the a command and command argument to the card and optionally return the command response.

Parameters
command_typeThe type of card command.
commandThe card command.
command_argThe card command argument.
response[out] A pointer to a 4 (32-bit) word to return the card command response. If NULL is passed then any card command response is ignored.
Return values
ALT_E_SUCCESSThe operation was successful.
ALT_E_ERRORThe operation failed.
ALT_STATUS_CODE alt_sdmmc_read_long_response ( ALT_SDMMC_RESPONSE_t response)

Get the long response of the last compleated command.

Parameters
response[out] Pointer to a ALT_SDMMC_RESPONSE_t structure to hold the long response.
Return values
ALT_E_SUCCESSSuccessful status.
ALT_E_ERRORDetails about error status code
uint32_t alt_sdmmc_int_status_get ( void  )

Returns the SD/MMC controller interrupt status register value which reflects interrupt controller interrupt status conditions before masking.

Returns
The raw value of the SD/MMC controller interrupt status register which reflects the current SD/MMC controller interrupt status conditions before masking.
uint32_t alt_sdmmc_int_mask_get ( void  )

Returns the SD/MMC controller interrupt mask register value which reflects the enabled (i.e. unmasked) interrupt status conditions.

Returns
The aggregate value of the enabled SD/MMC controller interrupt status conditions. A set (1) bit in the corresponding ALT_SDMMC_INT_STATUS_t position indicates an interrupt that is enabled. A clear (0) bit the corresponding ALT_SDMMC_INT_STATUS_t position indicates an interrupt that is masked.
ALT_STATUS_CODE alt_sdmmc_int_clear ( const uint32_t  mask)

Clears the specified SD/MMC controller interrupt status conditions identified in the mask.

This function clears one or more of the status conditions as contributors to the ALT_INT_INTERRUPT_SDMMC_IRQ interrupt signal state.

Parameters
maskSpecifies the SD/MMC controller status conditions to clear. mask is a mask of logically OR'ed ALT_SDMMC_INT_STATUS_t values that designate the status conditions to clear.
Return values
ALT_E_SUCCESSIndicates successful completion.
ALT_E_ERRORIndicates an error occurred.
ALT_STATUS_CODE alt_sdmmc_int_disable ( const uint32_t  mask)

Disable the specified SD/MMC controller interrupt status conditions identified in the mask.

This function disables one or more of the status conditions as contributors to the ALT_INT_INTERRUPT_SDMMC_IRQ interrupt signal state.

NOTE: A cleared bit for any status condition in the mask value does not have the effect of enabling it as a contributor to the ALT_INT_INTERRUPT_SDMMC_IRQ interrupt signal state. The function alt_sdmmc_int_enable() is used to enable status source conditions.

Parameters
maskSpecifies the status conditions to disable as interrupt source contributors. mask is a mask of logically OR'ed ALT_SDMMC_INT_STATUS_t values that designate the status conditions to disable.
Return values
ALT_E_SUCCESSIndicates successful completion.
ALT_E_ERRORIndicates an error occurred.
ALT_STATUS_CODE alt_sdmmc_int_enable ( const uint32_t  mask)

Enable the specified SD/MMC controller interrupt status conditions identified in the mask.

This function enables one or more of the status conditions as contributors to the ALT_INT_INTERRUPT_SDMMC_IRQ interrupt signal state.

NOTE: A cleared bit for any status condition in the mask value does not have the effect of disabling it as a contributor to the ALT_INT_INTERRUPT_SDMMC_IRQ interrupt signal state. The function alt_sdmmc_int_disable() is used to disable status source conditions.

Parameters
maskSpecifies the status conditions to enable as interrupt source contributors. mask is a mask of logically OR'ed ALT_SDMMC_INT_STATUS_t values that designate the status conditions to enable.
Return values
ALT_E_SUCCESSIndicates successful completion.
ALT_E_ERRORIndicates an error occurred.