ChibiOS/HAL  6.1.0
SDC Driver

Generic SD Card Driver. More...

Collaboration diagram for SDC Driver:

Detailed Description

Generic SD Card Driver.

This module implements a generic SDC (Secure Digital Card) driver.

Precondition
In order to use the SDC driver the HAL_USE_SDC option must be enabled in halconf.h.

Driver State Machine

This driver implements a state machine internally, see the Abstract I/O Block Device module documentation for details.

Driver Operations

This driver allows to read or write single or multiple 512 bytes blocks on a SD Card.

Macros

#define _sdc_driver_methods   _mmcsd_block_device_methods
 SDCDriver specific methods. More...
 

SD card types

#define SDC_MODE_CARDTYPE_MASK   0xFU
 
#define SDC_MODE_CARDTYPE_SDV11   0U
 
#define SDC_MODE_CARDTYPE_SDV20   1U
 
#define SDC_MODE_CARDTYPE_MMC   2U
 
#define SDC_MODE_HIGH_CAPACITY   0x10U
 

SDC bus error conditions

#define SDC_NO_ERROR   0U
 
#define SDC_CMD_CRC_ERROR   1U
 
#define SDC_DATA_CRC_ERROR   2U
 
#define SDC_DATA_TIMEOUT   4U
 
#define SDC_COMMAND_TIMEOUT   8U
 
#define SDC_TX_UNDERRUN   16U
 
#define SDC_RX_OVERRUN   32U
 
#define SDC_STARTBIT_ERROR   64U
 
#define SDC_OVERFLOW_ERROR   128U
 
#define SDC_UNHANDLED_ERROR   0xFFFFFFFFU
 

SDC configuration options

#define SDC_INIT_RETRY   100
 Number of initialization attempts before rejecting the card. More...
 
#define SDC_MMC_SUPPORT   FALSE
 Include support for MMC cards. More...
 
#define SDC_NICE_WAITING   TRUE
 Delays insertions. More...
 
#define SDC_INIT_OCR_V20   0x50FF8000U
 OCR initialization constant for V20 cards. More...
 
#define SDC_INIT_OCR   0x80100000U
 OCR initialization constant for non-V20 cards. More...
 

Macro Functions

#define sdcIsCardInserted(sdcp)   (sdc_lld_is_card_inserted(sdcp))
 Returns the card insertion status. More...
 
#define sdcIsWriteProtected(sdcp)   (sdc_lld_is_write_protected(sdcp))
 Returns the write protect status. More...
 

PLATFORM configuration options

#define PLATFORM_SDC_USE_SDC1   FALSE
 PWMD1 driver enable switch. More...
 

Typedefs

typedef uint32_t sdcmode_t
 Type of card flags. More...
 
typedef uint32_t sdcflags_t
 SDC Driver condition flags type. More...
 
typedef struct SDCDriver SDCDriver
 Type of a structure representing an SDC driver. More...
 

Data Structures

struct  SDCConfig
 Driver configuration structure. More...
 
struct  SDCDriverVMT
 SDCDriver virtual methods table. More...
 
struct  SDCDriver
 Structure representing an SDC driver. More...
 

Functions

static bool mode_detect (SDCDriver *sdcp)
 Detects card mode. More...
 
static bool mmc_init (SDCDriver *sdcp)
 Init procedure for MMC. More...
 
static bool sdc_init (SDCDriver *sdcp)
 Init procedure for SDC. More...
 
static uint32_t mmc_cmd6_construct (mmc_switch_t access, uint32_t idx, uint32_t value, uint32_t cmd_set)
 Constructs CMD6 argument for MMC. More...
 
static uint32_t sdc_cmd6_construct (sd_switch_t mode, sd_switch_function_t function, uint32_t value)
 Constructs CMD6 argument for SDC. More...
 
static uint16_t sdc_cmd6_extract_info (sd_switch_function_t function, const uint8_t *buf)
 Extracts information from CMD6 answer. More...
 
static bool sdc_cmd6_check_status (sd_switch_function_t function, const uint8_t *buf)
 Checks status after switching using CMD6. More...
 
static bool sdc_detect_bus_clk (SDCDriver *sdcp, sdcbusclk_t *clk)
 Reads supported bus clock and switch SDC to appropriate mode. More...
 
static bool mmc_detect_bus_clk (SDCDriver *sdcp, sdcbusclk_t *clk)
 Reads supported bus clock and switch MMC to appropriate mode. More...
 
static bool detect_bus_clk (SDCDriver *sdcp, sdcbusclk_t *clk)
 Reads supported bus clock and switch card to appropriate mode. More...
 
static bool sdc_set_bus_width (SDCDriver *sdcp)
 Sets bus width for SDC. More...
 
static bool mmc_set_bus_width (SDCDriver *sdcp)
 Sets bus width for MMC. More...
 
bool _sdc_wait_for_transfer_state (SDCDriver *sdcp)
 Wait for the card to complete pending operations. More...
 
void sdcInit (void)
 SDC Driver initialization. More...
 
void sdcObjectInit (SDCDriver *sdcp)
 Initializes the standard part of a SDCDriver structure. More...
 
void sdcStart (SDCDriver *sdcp, const SDCConfig *config)
 Configures and activates the SDC peripheral. More...
 
void sdcStop (SDCDriver *sdcp)
 Deactivates the SDC peripheral. More...
 
bool sdcConnect (SDCDriver *sdcp)
 Performs the initialization procedure on the inserted card. More...
 
bool sdcDisconnect (SDCDriver *sdcp)
 Brings the driver in a state safe for card removal. More...
 
bool sdcRead (SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t n)
 Reads one or more blocks. More...
 
bool sdcWrite (SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t n)
 Writes one or more blocks. More...
 
sdcflags_t sdcGetAndClearErrors (SDCDriver *sdcp)
 Returns the errors mask associated to the previous operation. More...
 
bool sdcSync (SDCDriver *sdcp)
 Waits for card idle condition. More...
 
bool sdcGetInfo (SDCDriver *sdcp, BlockDeviceInfo *bdip)
 Returns the media info. More...
 
bool sdcErase (SDCDriver *sdcp, uint32_t startblk, uint32_t endblk)
 Erases the supplied blocks. More...
 
void sdc_lld_init (void)
 Low level SDC driver initialization. More...
 
void sdc_lld_start (SDCDriver *sdcp)
 Configures and activates the SDC peripheral. More...
 
void sdc_lld_stop (SDCDriver *sdcp)
 Deactivates the SDC peripheral. More...
 
void sdc_lld_start_clk (SDCDriver *sdcp)
 Starts the SDIO clock and sets it to init mode (400kHz or less). More...
 
void sdc_lld_set_data_clk (SDCDriver *sdcp, sdcbusclk_t clk)
 Sets the SDIO clock to data mode (25MHz or less). More...
 
void sdc_lld_stop_clk (SDCDriver *sdcp)
 Stops the SDIO clock. More...
 
void sdc_lld_set_bus_mode (SDCDriver *sdcp, sdcbusmode_t mode)
 Switches the bus to 4 bits mode. More...
 
void sdc_lld_send_cmd_none (SDCDriver *sdcp, uint8_t cmd, uint32_t arg)
 Sends an SDIO command with no response expected. More...
 
bool sdc_lld_send_cmd_short (SDCDriver *sdcp, uint8_t cmd, uint32_t arg, uint32_t *resp)
 Sends an SDIO command with a short response expected. More...
 
bool sdc_lld_send_cmd_short_crc (SDCDriver *sdcp, uint8_t cmd, uint32_t arg, uint32_t *resp)
 Sends an SDIO command with a short response expected and CRC. More...
 
bool sdc_lld_send_cmd_long_crc (SDCDriver *sdcp, uint8_t cmd, uint32_t arg, uint32_t *resp)
 Sends an SDIO command with a long response expected and CRC. More...
 
bool sdc_lld_read (SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t n)
 Reads one or more blocks. More...
 
bool sdc_lld_write (SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t n)
 Writes one or more blocks. More...
 
bool sdc_lld_sync (SDCDriver *sdcp)
 Waits for card idle condition. More...
 

Enumerations

Variables

static const struct SDCDriverVMT sdc_vmt
 Virtual methods table. More...
 
SDCDriver SDCD1
 SDCD1 driver identifier. More...
 

Macro Definition Documentation

#define SDC_INIT_RETRY   100

Number of initialization attempts before rejecting the card.

Note
Attempts are performed at 10mS intervals.

Definition at line 74 of file hal_sdc.h.

Referenced by mmc_init(), and sdc_init().

#define SDC_MMC_SUPPORT   FALSE

Include support for MMC cards.

Note
MMC support is not yet implemented so this option must be kept at FALSE.

Definition at line 83 of file hal_sdc.h.

#define SDC_NICE_WAITING   TRUE

Delays insertions.

If enabled this options inserts delays into the MMC waiting routines releasing some extra CPU time for the threads with lower priority, this may slow down the driver a bit however.

Definition at line 93 of file hal_sdc.h.

#define SDC_INIT_OCR_V20   0x50FF8000U

OCR initialization constant for V20 cards.

Definition at line 100 of file hal_sdc.h.

Referenced by sdc_init().

#define SDC_INIT_OCR   0x80100000U

OCR initialization constant for non-V20 cards.

Definition at line 107 of file hal_sdc.h.

Referenced by sdc_init().

#define sdcIsCardInserted (   sdcp)    (sdc_lld_is_card_inserted(sdcp))

Returns the card insertion status.

Note
This macro wraps a low level function named sdc_lld_is_card_inserted(), this function must be provided by the application because it is not part of the SDC driver.
Parameters
[in]sdcppointer to the SDCDriver object
Returns
The card state.
Return values
falsecard not inserted.
truecard inserted.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 160 of file hal_sdc.h.

#define sdcIsWriteProtected (   sdcp)    (sdc_lld_is_write_protected(sdcp))

Returns the write protect status.

Note
This macro wraps a low level function named sdc_lld_is_write_protected(), this function must be provided by the application because it is not part of the SDC driver.
Parameters
[in]sdcppointer to the SDCDriver object
Returns
The card state.
Return values
falsenot write protected.
truewrite protected.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 176 of file hal_sdc.h.

#define PLATFORM_SDC_USE_SDC1   FALSE

PWMD1 driver enable switch.

If set to TRUE the support for PWM1 is included.

Note
The default is FALSE.

Definition at line 48 of file hal_sdc_lld.h.

#define _sdc_driver_methods   _mmcsd_block_device_methods

SDCDriver specific methods.

Definition at line 98 of file hal_sdc_lld.h.

Typedef Documentation

typedef uint32_t sdcmode_t

Type of card flags.

Definition at line 63 of file hal_sdc_lld.h.

typedef uint32_t sdcflags_t

SDC Driver condition flags type.

Definition at line 68 of file hal_sdc_lld.h.

typedef struct SDCDriver SDCDriver

Type of a structure representing an SDC driver.

Definition at line 73 of file hal_sdc_lld.h.

Enumeration Type Documentation

MMC switch mode.

Definition at line 38 of file hal_sdc.c.

SDC switch mode.

Definition at line 48 of file hal_sdc.c.

SDC switch function.

Definition at line 56 of file hal_sdc.c.

Type of SDIO bus mode.

Definition at line 122 of file hal_sdc.h.

Max supported clock.

Definition at line 131 of file hal_sdc.h.

Function Documentation

static bool mode_detect ( SDCDriver sdcp)
static

Detects card mode.

Parameters
[in]sdcppointer to the SDCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 100 of file hal_sdc.c.

References SDCDriver::cardmode, MMCSD_CMD8_PATTERN, MMCSD_R1_ERROR, sdc_lld_send_cmd_none(), and sdc_lld_send_cmd_short_crc().

Referenced by sdcConnect().

Here is the call graph for this function:

static bool mmc_init ( SDCDriver sdcp)
static

Init procedure for MMC.

Parameters
[in]sdcppointer to the SDCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 144 of file hal_sdc.c.

References SDCDriver::cardmode, osalThreadSleepMilliseconds, SDC_INIT_RETRY, and sdc_lld_send_cmd_short().

Referenced by sdcConnect().

Here is the call graph for this function:

static bool sdc_init ( SDCDriver sdcp)
static

Init procedure for SDC.

Parameters
[in]sdcppointer to the SDCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 181 of file hal_sdc.c.

References SDCDriver::cardmode, MMCSD_R1_ERROR, osalThreadSleepMilliseconds, SDC_INIT_OCR, SDC_INIT_OCR_V20, SDC_INIT_RETRY, sdc_lld_send_cmd_short(), and sdc_lld_send_cmd_short_crc().

Referenced by sdcConnect().

Here is the call graph for this function:

static uint32_t mmc_cmd6_construct ( mmc_switch_t  access,
uint32_t  idx,
uint32_t  value,
uint32_t  cmd_set 
)
static

Constructs CMD6 argument for MMC.

Parameters
[in]accessEXT_CSD access mode
[in]idxEXT_CSD byte number
[in]valuevalue to be written in target field
[in]cmd_setswitch current command set
Returns
CMD6 argument.
Function Class:Not an API, this function is for internal use only.

Definition at line 229 of file hal_sdc.c.

References osalDbgAssert.

Referenced by mmc_detect_bus_clk(), and mmc_set_bus_width().

static uint32_t sdc_cmd6_construct ( sd_switch_t  mode,
sd_switch_function_t  function,
uint32_t  value 
)
static

Constructs CMD6 argument for SDC.

Parameters
[in]modeswitch/test mode
[in]functionfunction number to be switched
[in]valuevalue to be written in target function
Returns
CMD6 argument.
Function Class:Not an API, this function is for internal use only.

Definition at line 249 of file hal_sdc.c.

References osalDbgAssert.

Referenced by sdc_detect_bus_clk().

static uint16_t sdc_cmd6_extract_info ( sd_switch_function_t  function,
const uint8_t *  buf 
)
static

Extracts information from CMD6 answer.

Parameters
[in]functionfunction number to be switched
[in]bufbuffer with answer
Returns
extracted answer.
Function Class:Not an API, this function is for internal use only.

Definition at line 271 of file hal_sdc.c.

Referenced by sdc_detect_bus_clk().

static bool sdc_cmd6_check_status ( sd_switch_function_t  function,
const uint8_t *  buf 
)
static

Checks status after switching using CMD6.

Parameters
[in]functionfunction number to be switched
[in]bufbuffer with answer
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 291 of file hal_sdc.c.

Referenced by sdc_detect_bus_clk().

static bool sdc_detect_bus_clk ( SDCDriver sdcp,
sdcbusclk_t clk 
)
static

Reads supported bus clock and switch SDC to appropriate mode.

Parameters
[in]sdcppointer to the SDCDriver object
[out]clkpointer to clock enum
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 319 of file hal_sdc.c.

References _mmcsd_get_slice(), sdc_cmd6_check_status(), sdc_cmd6_construct(), and sdc_cmd6_extract_info().

Referenced by detect_bus_clk().

Here is the call graph for this function:

static bool mmc_detect_bus_clk ( SDCDriver sdcp,
sdcbusclk_t clk 
)
static

Reads supported bus clock and switch MMC to appropriate mode.

Parameters
[in]sdcppointer to the SDCDriver object
[out]clkpointer to clock enum
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 373 of file hal_sdc.c.

References SDCDriver::config, mmc_cmd6_construct(), MMCSD_R1_ERROR, SDCConfig::scratchpad, and sdc_lld_send_cmd_short_crc().

Referenced by detect_bus_clk().

Here is the call graph for this function:

static bool detect_bus_clk ( SDCDriver sdcp,
sdcbusclk_t clk 
)
static

Reads supported bus clock and switch card to appropriate mode.

Parameters
[in]sdcppointer to the SDCDriver object
[out]clkpointer to clock enum
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 407 of file hal_sdc.c.

References SDCDriver::cardmode, mmc_detect_bus_clk(), and sdc_detect_bus_clk().

Referenced by sdcConnect().

Here is the call graph for this function:

static bool sdc_set_bus_width ( SDCDriver sdcp)
static

Sets bus width for SDC.

Parameters
[in]sdcppointer to the SDCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 426 of file hal_sdc.c.

References SDCConfig::bus_width, SDCDriver::config, MMCSD_R1_ERROR, SDCDriver::rca, sdc_lld_send_cmd_short_crc(), and sdc_lld_set_bus_mode().

Referenced by sdcConnect().

Here is the call graph for this function:

static bool mmc_set_bus_width ( SDCDriver sdcp)
static

Sets bus width for MMC.

Parameters
[in]sdcppointer to the SDCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 464 of file hal_sdc.c.

References SDCConfig::bus_width, SDCDriver::config, mmc_cmd6_construct(), MMCSD_R1_ERROR, osalDbgAssert, sdc_lld_send_cmd_short_crc(), and sdc_lld_set_bus_mode().

Referenced by sdcConnect().

Here is the call graph for this function:

bool _sdc_wait_for_transfer_state ( SDCDriver sdcp)

Wait for the card to complete pending operations.

Parameters
[in]sdcppointer to the SDCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 503 of file hal_sdc.c.

References MMCSD_R1_ERROR, MMCSD_R1_STS, osalThreadSleepMilliseconds, SDCDriver::rca, and sdc_lld_send_cmd_short_crc().

Referenced by sdcDisconnect(), and sdcErase().

Here is the call graph for this function:

void sdcInit ( void  )

SDC Driver initialization.

Note
This function is implicitly invoked by halInit(), there is no need to explicitly initialize the driver.
Function Class:Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 542 of file hal_sdc.c.

References sdc_lld_init().

Referenced by halInit().

Here is the call graph for this function:

void sdcObjectInit ( SDCDriver sdcp)

Initializes the standard part of a SDCDriver structure.

Parameters
[out]sdcppointer to the SDCDriver object
Function Class:Initializer, this function just initializes an object and can be invoked before the kernel is initialized.

Definition at line 554 of file hal_sdc.c.

References BLK_STOP, SDCDriver::config, SDCDriver::errors, sdc_vmt, and SDCDriver::vmt.

Referenced by sdc_lld_init().

void sdcStart ( SDCDriver sdcp,
const SDCConfig config 
)

Configures and activates the SDC peripheral.

Parameters
[in]sdcppointer to the SDCDriver object
[in]configpointer to the SDCConfig object, can be NULL if the driver supports a default configuration or requires no configuration
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 573 of file hal_sdc.c.

References BLK_ACTIVE, BLK_STOP, SDCDriver::config, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and sdc_lld_start().

Here is the call graph for this function:

void sdcStop ( SDCDriver sdcp)

Deactivates the SDC peripheral.

Parameters
[in]sdcppointer to the SDCDriver object
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 593 of file hal_sdc.c.

References BLK_ACTIVE, BLK_STOP, SDCDriver::config, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and sdc_lld_stop().

Here is the call graph for this function:

bool sdcConnect ( SDCDriver sdcp)

Performs the initialization procedure on the inserted card.

This function should be invoked when a card is inserted and brings the driver in the BLK_READY state where it is possible to perform read and write operations.

Parameters
[in]sdcppointer to the SDCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 623 of file hal_sdc.c.

References _mmcsd_get_capacity(), _mmcsd_get_capacity_ext(), _mmcsd_get_slice(), BLK_ACTIVE, BLK_CONNECTING, BLK_READY, SDCDriver::cardmode, SDCDriver::config, detect_bus_clk(), mmc_init(), mmc_set_bus_width(), MMCSD_BLOCK_SIZE, MMCSD_CSD_MMC_CSD_STRUCTURE_SLICE, MMCSD_R1_ERROR, mode_detect(), osalDbgAssert, osalDbgCheck, SDCDriver::rca, SDCConfig::scratchpad, sdc_init(), sdc_lld_send_cmd_long_crc(), sdc_lld_send_cmd_none(), sdc_lld_send_cmd_short_crc(), sdc_lld_set_data_clk(), sdc_lld_start_clk(), sdc_lld_stop_clk(), and sdc_set_bus_width().

Here is the call graph for this function:

bool sdcDisconnect ( SDCDriver sdcp)

Brings the driver in a state safe for card removal.

Parameters
[in]sdcppointer to the SDCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 762 of file hal_sdc.c.

References _sdc_wait_for_transfer_state(), BLK_ACTIVE, BLK_DISCONNECTING, BLK_READY, osalDbgAssert, osalDbgCheck, osalSysLock(), osalSysUnlock(), and sdc_lld_stop_clk().

Here is the call graph for this function:

bool sdcRead ( SDCDriver sdcp,
uint32_t  startblk,
uint8_t *  buf,
uint32_t  n 
)

Reads one or more blocks.

Precondition
The driver must be in the BLK_READY state after a successful sdcConnect() invocation.
Parameters
[in]sdcppointer to the SDCDriver object
[in]startblkfirst block to read
[out]bufpointer to the read buffer
[in]nnumber of blocks to read
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 805 of file hal_sdc.c.

References BLK_READING, BLK_READY, SDCDriver::errors, osalDbgAssert, osalDbgCheck, and sdc_lld_read().

Here is the call graph for this function:

bool sdcWrite ( SDCDriver sdcp,
uint32_t  startblk,
const uint8_t *  buf,
uint32_t  n 
)

Writes one or more blocks.

Precondition
The driver must be in the BLK_READY state after a successful sdcConnect() invocation.
Parameters
[in]sdcppointer to the SDCDriver object
[in]startblkfirst block to write
[out]bufpointer to the write buffer
[in]nnumber of blocks to write
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 842 of file hal_sdc.c.

References BLK_READY, BLK_WRITING, SDCDriver::errors, osalDbgAssert, osalDbgCheck, and sdc_lld_write().

Here is the call graph for this function:

sdcflags_t sdcGetAndClearErrors ( SDCDriver sdcp)

Returns the errors mask associated to the previous operation.

Parameters
[in]sdcppointer to the SDCDriver object
Returns
The errors mask.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 872 of file hal_sdc.c.

References BLK_READY, SDCDriver::errors, osalDbgAssert, osalDbgCheck, osalSysLock(), and osalSysUnlock().

Here is the call graph for this function:

bool sdcSync ( SDCDriver sdcp)

Waits for card idle condition.

Parameters
[in]sdcppointer to the SDCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSthe operation succeeded.
HAL_FAILEDthe operation failed.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 896 of file hal_sdc.c.

References BLK_READY, BLK_SYNCING, osalDbgCheck, and sdc_lld_sync().

Here is the call graph for this function:

bool sdcGetInfo ( SDCDriver sdcp,
BlockDeviceInfo bdip 
)

Returns the media info.

Parameters
[in]sdcppointer to the SDCDriver object
[out]bdippointer to a BlockDeviceInfo structure
Returns
The operation status.
Return values
HAL_SUCCESSthe operation succeeded.
HAL_FAILEDthe operation failed.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 927 of file hal_sdc.c.

References BlockDeviceInfo::blk_num, BLK_READY, BlockDeviceInfo::blk_size, MMCSD_BLOCK_SIZE, and osalDbgCheck.

bool sdcErase ( SDCDriver sdcp,
uint32_t  startblk,
uint32_t  endblk 
)

Erases the supplied blocks.

Parameters
[in]sdcppointer to the SDCDriver object
[in]startblkstarting block number
[in]endblkending block number
Returns
The operation status.
Return values
HAL_SUCCESSthe operation succeeded.
HAL_FAILEDthe operation failed.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 954 of file hal_sdc.c.

References _sdc_wait_for_transfer_state(), BLK_READY, BLK_WRITING, SDCDriver::cardmode, MMCSD_BLOCK_SIZE, MMCSD_R1_ERROR, osalDbgAssert, osalDbgCheck, and sdc_lld_send_cmd_short_crc().

Here is the call graph for this function:

void sdc_lld_init ( void  )

Low level SDC driver initialization.

Function Class:Not an API, this function is for internal use only.

Definition at line 65 of file hal_sdc_lld.c.

References sdcObjectInit().

Referenced by sdcInit().

Here is the call graph for this function:

void sdc_lld_start ( SDCDriver sdcp)

Configures and activates the SDC peripheral.

Parameters
[in]sdcppointer to the SDCDriver object
Function Class:Not an API, this function is for internal use only.

Definition at line 79 of file hal_sdc_lld.c.

References BLK_STOP.

Referenced by sdcStart().

void sdc_lld_stop ( SDCDriver sdcp)

Deactivates the SDC peripheral.

Parameters
[in]sdcppointer to the SDCDriver object
Function Class:Not an API, this function is for internal use only.

Definition at line 93 of file hal_sdc_lld.c.

References BLK_STOP.

Referenced by sdcStop().

void sdc_lld_start_clk ( SDCDriver sdcp)

Starts the SDIO clock and sets it to init mode (400kHz or less).

Parameters
[in]sdcppointer to the SDCDriver object
Function Class:Not an API, this function is for internal use only.

Definition at line 107 of file hal_sdc_lld.c.

Referenced by sdcConnect().

void sdc_lld_set_data_clk ( SDCDriver sdcp,
sdcbusclk_t  clk 
)

Sets the SDIO clock to data mode (25MHz or less).

Parameters
[in]sdcppointer to the SDCDriver object
[in]clkthe clock mode
Function Class:Not an API, this function is for internal use only.

Definition at line 120 of file hal_sdc_lld.c.

Referenced by sdcConnect().

void sdc_lld_stop_clk ( SDCDriver sdcp)

Stops the SDIO clock.

Parameters
[in]sdcppointer to the SDCDriver object
Function Class:Not an API, this function is for internal use only.

Definition at line 133 of file hal_sdc_lld.c.

Referenced by sdcConnect(), and sdcDisconnect().

void sdc_lld_set_bus_mode ( SDCDriver sdcp,
sdcbusmode_t  mode 
)

Switches the bus to 4 bits mode.

Parameters
[in]sdcppointer to the SDCDriver object
[in]modebus mode
Function Class:Not an API, this function is for internal use only.

Definition at line 146 of file hal_sdc_lld.c.

References osalDbgAssert.

Referenced by mmc_set_bus_width(), and sdc_set_bus_width().

void sdc_lld_send_cmd_none ( SDCDriver sdcp,
uint8_t  cmd,
uint32_t  arg 
)

Sends an SDIO command with no response expected.

Parameters
[in]sdcppointer to the SDCDriver object
[in]cmdcard command
[in]argcommand argument
Function Class:Not an API, this function is for internal use only.

Definition at line 175 of file hal_sdc_lld.c.

Referenced by mode_detect(), and sdcConnect().

bool sdc_lld_send_cmd_short ( SDCDriver sdcp,
uint8_t  cmd,
uint32_t  arg,
uint32_t *  resp 
)

Sends an SDIO command with a short response expected.

Note
The CRC is not verified.
Parameters
[in]sdcppointer to the SDCDriver object
[in]cmdcard command
[in]argcommand argument
[out]resppointer to the response buffer (one word)
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 197 of file hal_sdc_lld.c.

Referenced by mmc_init(), and sdc_init().

bool sdc_lld_send_cmd_short_crc ( SDCDriver sdcp,
uint8_t  cmd,
uint32_t  arg,
uint32_t *  resp 
)

Sends an SDIO command with a short response expected and CRC.

Parameters
[in]sdcppointer to the SDCDriver object
[in]cmdcard command
[in]argcommand argument
[out]resppointer to the response buffer (one word)
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 222 of file hal_sdc_lld.c.

Referenced by _sdc_wait_for_transfer_state(), mmc_detect_bus_clk(), mmc_set_bus_width(), mode_detect(), sdc_init(), sdc_set_bus_width(), sdcConnect(), and sdcErase().

bool sdc_lld_send_cmd_long_crc ( SDCDriver sdcp,
uint8_t  cmd,
uint32_t  arg,
uint32_t *  resp 
)

Sends an SDIO command with a long response expected and CRC.

Parameters
[in]sdcppointer to the SDCDriver object
[in]cmdcard command
[in]argcommand argument
[out]resppointer to the response buffer (four words)
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 247 of file hal_sdc_lld.c.

Referenced by sdcConnect().

bool sdc_lld_read ( SDCDriver sdcp,
uint32_t  startblk,
uint8_t *  buf,
uint32_t  n 
)

Reads one or more blocks.

Parameters
[in]sdcppointer to the SDCDriver object
[in]startblkfirst block to read
[out]bufpointer to the read buffer
[in]nnumber of blocks to read
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 272 of file hal_sdc_lld.c.

Referenced by sdcRead().

bool sdc_lld_write ( SDCDriver sdcp,
uint32_t  startblk,
const uint8_t *  buf,
uint32_t  n 
)

Writes one or more blocks.

Parameters
[in]sdcppointer to the SDCDriver object
[in]startblkfirst block to write
[out]bufpointer to the write buffer
[in]nnumber of blocks to write
Returns
The operation status.
Return values
HAL_SUCCESSoperation succeeded.
HAL_FAILEDoperation failed.
Function Class:Not an API, this function is for internal use only.

Definition at line 297 of file hal_sdc_lld.c.

Referenced by sdcWrite().

bool sdc_lld_sync ( SDCDriver sdcp)

Waits for card idle condition.

Parameters
[in]sdcppointer to the SDCDriver object
Returns
The operation status.
Return values
HAL_SUCCESSthe operation succeeded.
HAL_FAILEDthe operation failed.
Function Class:Normal API, this function can be invoked by regular system threads but not from within a lock zone.

Definition at line 319 of file hal_sdc_lld.c.

Referenced by sdcSync().

Variable Documentation

const struct SDCDriverVMT sdc_vmt
static
Initial value:
= {
(size_t)0,
(bool (*)(void *))sdc_lld_is_card_inserted,
(bool (*)(void *))sdc_lld_is_write_protected,
(bool (*)(void *))sdcConnect,
(bool (*)(void *))sdcDisconnect,
(bool (*)(void *, uint32_t, uint8_t *, uint32_t))sdcRead,
(bool (*)(void *, uint32_t, const uint8_t *, uint32_t))sdcWrite,
(bool (*)(void *))sdcSync,
(bool (*)(void *, BlockDeviceInfo *))sdcGetInfo
}
bool sdcConnect(SDCDriver *sdcp)
Performs the initialization procedure on the inserted card.
Definition: hal_sdc.c:623
bool sdcDisconnect(SDCDriver *sdcp)
Brings the driver in a state safe for card removal.
Definition: hal_sdc.c:762
bool sdcRead(SDCDriver *sdcp, uint32_t startblk, uint8_t *buf, uint32_t n)
Reads one or more blocks.
Definition: hal_sdc.c:805
Block device info.
Definition: hal_ioblock.h:55
bool sdcSync(SDCDriver *sdcp)
Waits for card idle condition.
Definition: hal_sdc.c:896
bool sdcGetInfo(SDCDriver *sdcp, BlockDeviceInfo *bdip)
Returns the media info.
Definition: hal_sdc.c:927
bool sdcWrite(SDCDriver *sdcp, uint32_t startblk, const uint8_t *buf, uint32_t n)
Writes one or more blocks.
Definition: hal_sdc.c:842

Virtual methods table.

Definition at line 74 of file hal_sdc.c.

Referenced by sdcObjectInit().

SDCDriver SDCD1

SDCD1 driver identifier.

Definition at line 41 of file hal_sdc_lld.c.