1 /** 2 * @file sd.h 3 * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited 4 */ 5 6 #ifndef HAL_SD_H 7 #define HAL_SD_H 8 9 #ifdef __cplusplus 10 extern "C" { 11 #endif 12 13 /** @addtogroup hal_sd SD 14 * sd hal API. 15 * 16 * @{ 17 */ 18 19 #include <stdint.h> 20 21 /* This enum lists all SD states */ 22 typedef enum { 23 SD_STAT_RESET, 24 SD_STAT_READY, 25 SD_STAT_TIMEOUT, 26 SD_STAT_BUSY, 27 SD_STAT_PROGRAMMING, 28 SD_STAT_RECEIVING, 29 SD_STAT_TRANSFER, 30 SD_STAT_ERR 31 } hal_sd_stat; 32 33 /* Define sd blk info */ 34 typedef struct { 35 uint32_t blk_nums; /**< sd total block nums */ 36 uint32_t blk_size; /**< sd block size */ 37 } hal_sd_info_t; 38 39 /* 40 * UART configuration 41 */ 42 typedef struct { 43 uint32_t bus_wide; /**< sd bus wide */ 44 uint32_t freq; /**< sd freq */ 45 } sd_config_t; 46 47 /* Define sd dev handle */ 48 typedef struct { 49 uint8_t port; /**< sd port */ 50 sd_config_t config; /**< sd config */ 51 void *priv; /**< priv data */ 52 } sd_dev_t; 53 54 /** 55 * Initialises a sd interface 56 * 57 * @param[in] sd the interface which should be initialised 58 * 59 * @return 0 : on success, otherwise is error 60 */ 61 int32_t hal_sd_init(sd_dev_t *sd); 62 63 /** 64 * Read sd blocks 65 * 66 * @param[in] sd the interface which should be read 67 * @param[out] data pointer to the buffer which will store incoming data 68 * @param[in] blk_addr sd blk addr 69 * @param[in] blks sd blks 70 * @param[in] timeout timeout in milisecond 71 * 72 * @return 0 : on success, otherwise is error 73 */ 74 int32_t hal_sd_blks_read(sd_dev_t *sd, uint8_t *data, uint32_t blk_addr, 75 uint32_t blks, uint32_t timeout); 76 77 /** 78 * Write sd blocks 79 * 80 * @param[in] sd the interface which should be wrote 81 * @param[in] data pointer to the buffer which will store incoming data 82 * @param[in] blk_addr sd blk addr 83 * @param[in] blks sd blks 84 * @param[in] timeout timeout in milisecond 85 * 86 * @return 0 : on success, otherwise is error 87 */ 88 int32_t hal_sd_blks_write(sd_dev_t *sd, uint8_t *data, uint32_t blk_addr, 89 uint32_t blks, uint32_t timeout); 90 91 /** 92 * Erase sd blocks 93 * 94 * @param[in] sd the interface which should be erased 95 * @param[in] blk_start_addr sd blocks start addr 96 * @param[in] blk_end_addr sd blocks end addr 97 * 98 * @return 0 : on success, otherwise is error 99 */ 100 int32_t hal_sd_erase(sd_dev_t *sd, uint32_t blk_start_addr, uint32_t blk_end_addr); 101 102 /** 103 * Get sd state 104 * 105 * @param[in] sd the interface which should be got state 106 * @param[out] stat pointer to the buffer which will store incoming state data 107 * 108 * @return 0 : on success, otherwise is error 109 */ 110 int32_t hal_sd_stat_get(sd_dev_t *sd, hal_sd_stat *stat); 111 112 /** 113 * Get sd info 114 * 115 * @param[in] sd the interface which should be got info 116 * @param[out] stat pointer to the buffer which will store incoming info data 117 * 118 * @return 0 : on success, otherwise is error 119 */ 120 int32_t hal_sd_info_get(sd_dev_t *sd, hal_sd_info_t *info); 121 122 /** 123 * Deinitialises a sd interface 124 * 125 * @param[in] sd the interface which should be Deinitialised 126 * 127 * @return 0 : on success, otherwise is error 128 */ 129 int32_t hal_sd_finalize(sd_dev_t *sd); 130 131 /** @} */ 132 133 #ifdef __cplusplus 134 } 135 #endif 136 137 #endif /* HAL_SD_H */ 138 139