MT2523 API Reference  LinkIt SDK v4
hal_sd.h
1 /* Copyright Statement:
2  *
3  * (C) 2005-2017 MediaTek Inc. All rights reserved.
4  *
5  * This software/firmware and related documentation ("MediaTek Software") are
6  * protected under relevant copyright laws. The information contained herein
7  * is confidential and proprietary to MediaTek Inc. ("MediaTek") and/or its licensors.
8  * Without the prior written permission of MediaTek and/or its licensors,
9  * any reproduction, modification, use or disclosure of MediaTek Software,
10  * and information contained herein, in whole or in part, shall be strictly prohibited.
11  * You may only use, reproduce, modify, or distribute (as applicable) MediaTek Software
12  * if you have agreed to and been bound by the applicable license agreement with
13  * MediaTek ("License Agreement") and been granted explicit permission to do so within
14  * the License Agreement ("Permitted User"). If you are not a Permitted User,
15  * please cease any access or use of MediaTek Software immediately.
16  * BY OPENING THIS FILE, RECEIVER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
17  * THAT MEDIATEK SOFTWARE RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES
18  * ARE PROVIDED TO RECEIVER ON AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL
19  * WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
21  * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
22  * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
23  * SUPPLIED WITH MEDIATEK SOFTWARE, AND RECEIVER AGREES TO LOOK ONLY TO SUCH
24  * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. RECEIVER EXPRESSLY ACKNOWLEDGES
25  * THAT IT IS RECEIVER'S SOLE RESPONSIBILITY TO OBTAIN FROM ANY THIRD PARTY ALL PROPER LICENSES
26  * CONTAINED IN MEDIATEK SOFTWARE. MEDIATEK SHALL ALSO NOT BE RESPONSIBLE FOR ANY MEDIATEK
27  * SOFTWARE RELEASES MADE TO RECEIVER'S SPECIFICATION OR TO CONFORM TO A PARTICULAR
28  * STANDARD OR OPEN FORUM. RECEIVER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND
29  * CUMULATIVE LIABILITY WITH RESPECT TO MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
30  * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE MEDIATEK SOFTWARE AT ISSUE,
31  * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY RECEIVER TO
32  * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
33  */
34 
35 #ifndef __HAL_SD_H__
36 #define __HAL_SD_H__
37 
38 #include "hal_platform.h"
39 
40 #ifdef HAL_SD_MODULE_ENABLED
41 
717 #ifdef HAL_SD_CARD_DETECTION
718 
784 #endif
785 
792 #ifdef __cplusplus
793 extern "C" {
794 #endif
795 
801 typedef enum {
806 
807 
809 typedef enum {
813 
814 
816 typedef enum {
817  HAL_SD_TYPE_SD_CARD = 0,
823  HAL_SD_TYPE_UNKNOWN_CARD = 0xff,
825 
826 #ifdef HAL_SD_CARD_DETECTION
827 
830 typedef enum {
834 #endif
835 
839 typedef enum {
845 
856 typedef struct {
858  uint32_t clock;
860 
865 #ifdef HAL_SD_CARD_DETECTION
866 
877 typedef void (*hal_sd_card_detect_callback_t)(hal_sd_card_event_t event, void *user_data);
881 #endif
882 
894 typedef void (*hal_sd_callback_t)(hal_sd_callback_event_t event, void *user_data);
909 
910 
918 
919 #ifdef HAL_SD_CARD_DETECTION
920 
929 #endif
930 
939 
940 
949 hal_sd_status_t hal_sd_set_clock(hal_sd_port_t sd_port, uint32_t clock);
950 
951 
958 hal_sd_status_t hal_sd_get_clock(hal_sd_port_t sd_port, uint32_t *clock);
959 
960 
967 hal_sd_status_t hal_sd_get_capacity(hal_sd_port_t sd_port, uint64_t *capacity);
968 
969 
977 hal_sd_status_t hal_sd_get_erase_sector_size(hal_sd_port_t sd_port, uint32_t *erase_sector_size);
978 
979 
989 hal_sd_status_t hal_sd_erase_sectors(hal_sd_port_t sd_port, uint32_t start_sector, uint32_t sector_number);
990 
991 
1003 hal_sd_status_t hal_sd_read_blocks(hal_sd_port_t sd_port, uint32_t *read_buffer, uint32_t start_address, uint32_t block_number);
1004 
1005 
1017 hal_sd_status_t hal_sd_write_blocks(hal_sd_port_t sd_port, const uint32_t *write_data, uint32_t start_address, uint32_t block_number);
1018 
1030 hal_sd_status_t hal_sd_read_blocks_dma_blocking(hal_sd_port_t sd_port, uint32_t *read_buffer, uint32_t start_address, uint32_t block_number);
1031 
1032 
1044 hal_sd_status_t hal_sd_write_blocks_dma_blocking(hal_sd_port_t sd_port, const uint32_t *write_data, uint32_t start_address, uint32_t block_number);
1045 
1046 
1054 hal_sd_status_t hal_sd_get_csd(hal_sd_port_t sd_port, uint32_t *csd);
1055 
1056 
1064 hal_sd_status_t hal_sd_get_cid(hal_sd_port_t sd_port, uint32_t *cid);
1065 
1066 
1075 
1076 
1084 hal_sd_status_t hal_sd_get_ocr(hal_sd_port_t sd_port, uint32_t *ocr);
1085 
1086 
1094 hal_sd_status_t hal_sd_get_card_status(hal_sd_port_t sd_port, uint32_t *card_status);
1095 
1104 hal_sd_status_t hal_sd_register_callback(hal_sd_port_t sd_port, hal_sd_callback_t sd_callback,void *user_data);
1105 
1117 hal_sd_status_t hal_sd_read_blocks_dma(hal_sd_port_t sd_port, uint32_t *read_buffer, uint32_t read_address, uint32_t block_number);
1118 
1130 hal_sd_status_t hal_sd_write_blocks_dma(hal_sd_port_t sd_port, const uint32_t *write_buffer, uint32_t write_address, uint32_t block_number);
1131 
1132 #ifdef __cplusplus
1133 }
1134 #endif
1135 
1140 #endif /*HAL_SD_MODULE_ENABLED*/
1141 #endif /* __HAL_SD_H__ */
1142 
1143 
The SD/eMMC bus is busy error occurred.
Definition: hal_sd.h:802
hal_sd_status_t hal_sd_get_clock(hal_sd_port_t sd_port, uint32_t *clock)
This function gets the output clock of the MSDC.
An data timeout occurred during transaction.
Definition: hal_sd.h:843
hal_sd_port_t
This enum defines the SD/eMMC port.
Definition: hal_platform.h:1056
hal_sd_card_event_t
This enum defines the card detection result event.
Definition: hal_sd.h:830
hal_sd_status_t hal_sd_read_blocks_dma(hal_sd_port_t sd_port, uint32_t *read_buffer, uint32_t read_address, uint32_t block_number)
This function reads data from the SD/eMMC card in the DMA interrupt mode.
hal_sd_status_t hal_sd_get_card_status(hal_sd_port_t sd_port, uint32_t *card_status)
This function gets the card status of the SD/eMMC card.
hal_sd_status_t hal_sd_init(hal_sd_port_t sd_port, hal_sd_config_t *sd_config)
This function initializes the MSDC and SD/eMMC card.
void(* hal_sd_card_detect_callback_t)(hal_sd_card_event_t event, void *user_data)
This defines the callback function prototype.
Definition: hal_sd.h:877
hal_sd_status_t hal_sd_write_blocks_dma(hal_sd_port_t sd_port, const uint32_t *write_buffer, uint32_t write_address, uint32_t block_number)
This function writes data to the SD/eMMC card in the DMA interrupt mode.
hal_sd_status_t hal_sd_set_clock(hal_sd_port_t sd_port, uint32_t clock)
This function sets the output clock of the MSDC.
The SD/eMMC read/write data with 4 bit bus width.
Definition: hal_sd.h:811
hal_sd_status_t hal_sd_get_capacity(hal_sd_port_t sd_port, uint64_t *capacity)
This function gets the card capacity of the SD/eMMC card.
hal_sd_status_t hal_sd_write_blocks(hal_sd_port_t sd_port, const uint32_t *write_data, uint32_t start_address, uint32_t block_number)
This function writes data to the SD/eMMC card in the MCU mode.
An CRC error occurred during transaction.
Definition: hal_sd.h:842
The SD/eMMC read/write data with 1 bit bus width.
Definition: hal_sd.h:810
hal_sd_status_t hal_sd_get_csd(hal_sd_port_t sd_port, uint32_t *csd)
This function gets the CSD register value of the SD/eMMC card.
hal_sd_status_t hal_sd_register_card_detection_callback(hal_sd_port_t sd_port, hal_sd_callback_t sd_callback, void *user_data)
This function registers a callback function to detect a card.
hal_sd_bus_width_t bus_width
The SD/eMMC read/write bus width.
Definition: hal_sd.h:857
void(* hal_sd_callback_t)(hal_sd_callback_event_t event, void *user_data)
This defines the callback function prototype.
Definition: hal_sd.h:894
An SD card is removed.
Definition: hal_sd.h:832
hal_sd_status_t hal_sd_write_blocks_dma_blocking(hal_sd_port_t sd_port, const uint32_t *write_data, uint32_t start_address, uint32_t block_number)
This function writes data to the SD/eMMC card in the DMA blocking mode.
The transaction completed without any error.
Definition: hal_sd.h:840
hal_sd_card_type_t
This enum define the SD/eMMC card type.
Definition: hal_sd.h:816
hal_sd_status_t
This enum defines the SD/eMMC API's return type.
Definition: hal_sd.h:801
hal_sd_status_t hal_sd_erase_sectors(hal_sd_port_t sd_port, uint32_t start_sector, uint32_t sector_number)
This function erases the card sectors of the SD/eMMC card.
MMC card.
Definition: hal_sd.h:819
hal_sd_status_t hal_sd_deinit(hal_sd_port_t sd_port)
This function deinitializes the MSDC and the SD/eMMC settings.
uint32_t clock
The MSDC I/O bus clock, the unit is kHz.
Definition: hal_sd.h:858
SD 2.0 card and capacity less than 2GB.
Definition: hal_sd.h:820
hal_sd_status_t hal_sd_register_callback(hal_sd_port_t sd_port, hal_sd_callback_t sd_callback, void *user_data)
This function registers a callback function to transfer data with DMA.
hal_sd_bus_width_t
This enum defines the SD/eMMC bus width types.
Definition: hal_sd.h:809
hal_sd_status_t hal_sd_set_bus_width(hal_sd_port_t sd_port, hal_sd_bus_width_t bus_width)
This function sets a bus width for MSDC and the SD/eMMC card.
No error occurred during the function call.
Definition: hal_sd.h:804
This structure define the SD/eMMC initialize parameter.
Definition: hal_sd.h:856
hal_sd_status_t hal_sd_read_blocks(hal_sd_port_t sd_port, uint32_t *read_buffer, uint32_t start_address, uint32_t block_number)
This function reads data from the SD/eMMC card in the MCU mode.
hal_sd_status_t hal_sd_get_cid(hal_sd_port_t sd_port, uint32_t *cid)
This function gets the CID register value of the SD/eMMC card.
An error occurred and the operation failed.
Definition: hal_sd.h:803
hal_sd_status_t hal_sd_get_ocr(hal_sd_port_t sd_port, uint32_t *ocr)
This function gets the OCR register value of the SD/eMMC card.
hal_sd_callback_event_t
This enum defines the card DMA transfer result event.
Definition: hal_sd.h:839
hal_sd_status_t hal_sd_get_erase_sector_size(hal_sd_port_t sd_port, uint32_t *erase_sector_size)
This function gets the sector size of the SD/eMMC card to erase.
An SD card is inserted.
Definition: hal_sd.h:831
SD 2.0 card and capacity larger than 2GB.
Definition: hal_sd.h:821
hal_sd_status_t hal_sd_read_blocks_dma_blocking(hal_sd_port_t sd_port, uint32_t *read_buffer, uint32_t start_address, uint32_t block_number)
This function reads data from the SD/eMMC card in the DMA blocking mode.
hal_sd_status_t hal_sd_get_card_type(hal_sd_port_t sd_port, hal_sd_card_type_t *card_type)
This function gets the card type of the SD/eMMC card.
An error occurred during transaction.
Definition: hal_sd.h:841
EMMC 4.2 and above card.
Definition: hal_sd.h:822
SD card.
Definition: hal_sd.h:818