📄 mmc.h
字号:
// all returned function ints are < 0 if an error occurs, otherwise the returned code is >= 0
#ifndef mmcH
#define mmcH
#include "common.h"
// ******************
// compile options
//#define mmc_use_switch // uncomment this to use the MMC/SD slot switch (detects if card is inserted or not)
#define mmc_use_crc // uncomment this to enable full crc checking options in MMC/SD transfers (command, data, sector transfers)
#ifdef mmc_use_crc
#define mmc_crc_tab // uncomment this to use the faster crc look-up table method (though uses more rom space)
#endif
#define mmc_debug // uncomment this to get debug info sent down the UART port
#ifdef mmc_debug
#define mmc_debug1 // uncomment this to get full debug info sent down the UART port
#endif
// ******************
// public return codes
#define mmc_ok 0
#define mmc_err_not_inserted -1
#define mmc_err_timeout -2
#define mmc_err_busy -3
#define mmc_err_invalid_address -4
#define mmc_err_invalid_data_size -5
#define mmc_err_write -6
#define mmc_err_read -7
#define mmc_err_invalid_state -8
#define mmc_err_crc -9
#define mmc_err_invalid_sector_count -10
#define mmc_err_data -11
#define mmc_err_fail -12
// ******************
// public types
typedef struct TMMC_Info
{
// the ocr register in the MMC/SD
_u32 ocr;
// the cid register in the MMC/SD
_u8 mid;
_u8 oid;
char pnm[8];
_u8 prv_ms;
_u8 prv_ls;
_u32 psn;
_u8 mdt_month;
_u8 mdt_year;
// the csd register in the MMC/SD
_u8 csd_structure;
_u8 prot;
_u8 taac;
_u8 nsac;
_u8 tran_speed;
_u16 ccc;
_u8 read_bl_len;
_u8 read_bl_partial;
_u8 write_blk_misalign;
_u8 read_blk_misalign;
_u8 dsr_imp;
_u16 c_size;
_u8 vdd_r_curr_min;
_u8 vdd_r_curr_max;
_u8 vdd_w_curr_min;
_u8 vdd_w_curr_max;
_u8 c_size_mult;
_u8 erase_sector_size;
_u8 erase_grp_size;
_u8 wp_grp_size;
_u8 wp_grp_enable;
_u8 default_ecc;
_u8 r2w_factor;
_u8 write_bl_len;
_u8 write_bl_partial;
_u8 copy;
_u8 perm_write_protect;
_u8 tmp_write_protect;
_u8 eec;
// own data
_u32 size_bytes; // MMC size (in bytes)
_u16 size_sector; // MMC sector size (in bytes)
_u32 size_sectors; // number of MMC sectors
_u32 max_transfer_speed; // max transfer speed of the MMC - bits per second (max spi/ssp sclk speed)
_u32 spi_sclk_speed; // the actual speed of sclk we use .. YOU MUST SET THIS AT START OF mmc_init() !!!!!!!!
_u32 max_read_timeout_us; // max read timeout .. in micro-seconds
_u32 max_write_timeout_us; // max write timeout .. in micro-seconds
_u32 max_read_timeout_count; // max read time-out (in spi bytes)
_u32 max_write_timeout_count; // max read time-out (in spi bytes)
_u32 last_block_len; // our last block length setting
} T_MMC_Info;
// ******************
// public data
extern T_MMC_Info MMC_Info;
// ******************
// public procs/funcs
bool mmc_inserted(void); // returns true if the MMC/SD card is inserted (if option is enabled above)
void mmc_deselect(void); // call this when your done using the MMC/SD card (after using the following 4 functions)
int mmc_init(void); // call this before using the next 3 functions
int mmc_write_sector(void *buffer, _u32 sector, int num_of_bytes); // call mmc_init() before using this .. use mmc_deselect() when finished
int mmc_read_sector(void *buffer, _u32 sector, int num_of_bytes); // call mmc_init() before using this .. use mmc_deselect() when finished
int mmc_erase_sectors(_u32 start_sector, int num_of_sectors); // call mmc_init() before using this .. use mmc_deselect() when finished
int mmc_write_sectors(void *buffer, _u32 start_sector, int num_of_sectors); // stand-alone function - just call it on it's own
int mmc_read_sectors(void *buffer, _u32 start_sector, int num_of_sectors); // stand-alone function - just call it on it's own
int mmc_test_sector(_u32 sector); // stand-alone function - just call it on it's own
// ******************
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -