Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

This section describes the programming interface of the SDCH Peripheral driver. The SDHC driver configures the secure digital host controller and provides an easy way to operate the SDHC module.

SDHC Initialization

To initialize the SDHC module, call the SDHC_DRV_Init() function and pass in the configuration data structure.
This is an example code to initialize and configure the driver:

// Define device configuration.
sdhc_user_config_t config = {0};
config.clock = 0;
// Initialize
if (SDHC_DRV_Init(instance, &host, &config) != kStatus_SDHC_NoError)
{
// error occurs //
}
else
{
// SDHC has been successfully initialized //
}

SDHC Issuing a request to the card

The SDHC driver provides a simple way to send commands to and retrieve response/data from the card.

This is a example to send the SD_SWITCH command to the card.

sdhc_request_t req = {0};
sdhc_data_t data = {0};
req.cmdIndex = kSdSwitch; // Set command index //
req.argument = mode << 31 | 0x00FFFFFF; // Set argument //
req.argument &= ~((0xF) << (group * 4));
req.argument |= value << (group * 4);
req.flags = FSL_SDHC_REQ_FLAGS_DATA_READ; // Set command flags //
req.respType = kSdhcRespTypeR1; // Set response type //
data.blockSize = 64; // Set data block size //
data.blockCount = 1; // Set data block count //
data.buffer = response; // Set data buffer //
// link data, command with request //
data.req = &req
req.data = &data;
&req,
FSL_SDCARD_REQUEST_TIMEOUT);) // issue request //
{
// error occurs //
}
else
{
// request has been issued successfully //
}

This section describes the programming interface of the SDCH Peripheral Driver.

SDHC PD FUNCTION

sdhc_status_t SDHC_DRV_Init (uint32_t instance, sdhc_host_t *host, const sdhc_user_config_t *config)
 Initializes the Host controller with a specific instance index. More...
 
sdhc_status_t SDHC_DRV_Shutdown (uint32_t instance)
 Destroys the host controller. More...
 
sdhc_status_t SDHC_DRV_DetectCard (uint32_t instance)
 Checks whether the card is present on a specified host controller. More...
 
sdhc_status_t SDHC_DRV_ConfigClock (uint32_t instance, uint32_t clock)
 Sets the clock frequency of the host controller. More...
 
sdhc_status_t SDHC_DRV_SetBusWidth (uint32_t instance, sdhc_buswidth_t busWidth)
 Sets the bus width of the host controller. More...
 
sdhc_status_t SDHC_DRV_IssueRequestBlocking (uint32_t instance, sdhc_request_t *req, uint32_t timeoutInMs)
 Issues the request on a specific host controller and returns on completion. More...
 
void SDHC_DRV_DoIrq (uint32_t instance)
 IRQ handler for SDHC. More...
 

Function Documentation

sdhc_status_t SDHC_DRV_Init ( uint32_t  instance,
sdhc_host_t host,
const sdhc_user_config_t config 
)

This function initializes the SDHC module according to the given initialization configuration structure including the clock frequency, bus width, and card detect callback.

Parameters
instancethe specific instance index
hostpointer to a place storing the sdhc_host_t structure
configinitialization configuration data
Returns
kStatus_SDHC_NoError if success
sdhc_status_t SDHC_DRV_Shutdown ( uint32_t  instance)
Parameters
instancethe instance index of host controller
Returns
kStatus_SDHC_NoError if success
sdhc_status_t SDHC_DRV_DetectCard ( uint32_t  instance)

This function checks if there's a card inserted in the SDHC.

Parameters
instancethe instance index of host controller
Returns
kStatus_SDHC_NoError on success
sdhc_status_t SDHC_DRV_ConfigClock ( uint32_t  instance,
uint32_t  clock 
)
Parameters
instancethe instance index of host controller
clockthe desired frequency to be set to controller
Returns
kStatus_SDHC_NoError on success
sdhc_status_t SDHC_DRV_SetBusWidth ( uint32_t  instance,
sdhc_buswidth_t  busWidth 
)
Parameters
instancethe instance index of host controller
busWidththe desired bus width to be set to controller
Returns
kStatus_SDHC_NoError on success
sdhc_status_t SDHC_DRV_IssueRequestBlocking ( uint32_t  instance,
sdhc_request_t req,
uint32_t  timeoutInMs 
)

This function issues the request to the card on a specific SDHC. The command is sent and is blocked as long as the response/data is sending back from the card.

Parameters
instancethe instance index of host controller
reqthe pointer to the request
timeoutInMstimeout value in microseconds
Returns
kStatus_SDHC_NoError on success
void SDHC_DRV_DoIrq ( uint32_t  instance)

This function deals with IRQs on the given host controller.

Parameters
instancethe instance index of host controller