From 2c01189114ed19785af24806c89672e4cf907d54 Mon Sep 17 00:00:00 2001 From: EvalZero Date: Wed, 5 Sep 2018 14:50:43 +0800 Subject: [PATCH] [DeviceDriver][SDIO] Update sdio debug log. --- components/drivers/Kconfig | 4 +++ components/drivers/sdio/block_dev.c | 28 ++++++++++++------ components/drivers/sdio/mmc.c | 26 +++++++++++------ components/drivers/sdio/mmcsd_core.c | 22 ++++++++++---- components/drivers/sdio/sd.c | 26 +++++++++++------ components/drivers/sdio/sdio.c | 43 +++++++++++++++++----------- 6 files changed, 101 insertions(+), 48 deletions(-) diff --git a/components/drivers/Kconfig b/components/drivers/Kconfig index f27c70c481..e2d290032b 100755 --- a/components/drivers/Kconfig +++ b/components/drivers/Kconfig @@ -138,6 +138,10 @@ config RT_USING_SDIO config RT_MMCSD_MAX_PARTITION int "mmcsd max partition" default 16 + + config RT_SDIO_DEBUG + bool "Enable SDIO debug log output" + default n endif config RT_USING_SPI diff --git a/components/drivers/sdio/block_dev.c b/components/drivers/sdio/block_dev.c index 14a01acd90..1651a143f7 100644 --- a/components/drivers/sdio/block_dev.c +++ b/components/drivers/sdio/block_dev.c @@ -27,6 +27,16 @@ #include +#define DBG_ENABLE +#define DBG_SECTION_NAME "[SDIO]" +#ifdef RT_SDIO_DEBUG +#define DBG_LEVEL DBG_LOG +#else +#define DBG_LEVEL DBG_INFO +#endif /* RT_SDIO_DEBUG */ +#define DBG_COLOR +#include + static rt_list_t blk_devices = RT_LIST_OBJECT_INIT(blk_devices); struct mmcsd_blk_device @@ -179,7 +189,7 @@ static rt_err_t rt_mmcsd_req_blk(struct rt_mmcsd_card *card, err = mmcsd_send_cmd(card->host, &cmd, 5); if (err) { - rt_kprintf("error %d requesting status\n", err); + LOG_E("error %d requesting status", err); break; } /* @@ -195,8 +205,8 @@ static rt_err_t rt_mmcsd_req_blk(struct rt_mmcsd_card *card, if (cmd.err || data.err || stop.err) { - rt_kprintf("mmcsd request blocks error\n"); - rt_kprintf("%d,%d,%d, 0x%08x,0x%08x\n", + LOG_E("mmcsd request blocks error"); + LOG_E("%d,%d,%d, 0x%08x,0x%08x", cmd.err, data.err, stop.err, data.flags, sector); return -RT_ERROR; @@ -311,7 +321,7 @@ static rt_int32_t mmcsd_set_blksize(struct rt_mmcsd_card *card) if (err) { - rt_kprintf("MMCSD: unable to set block size to %d: %d\n", cmd.arg, err); + LOG_E("MMCSD: unable to set block size to %d: %d", cmd.arg, err); return -RT_ERROR; } @@ -346,13 +356,13 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) return err; } - rt_kprintf("probe mmcsd block device!\n"); + LOG_I("probe mmcsd block device!"); /* get the first sector to read partition table */ sector = (rt_uint8_t *)rt_malloc(SECTOR_SIZE); if (sector == RT_NULL) { - rt_kprintf("allocate partition sector buffer failed\n"); + LOG_E("allocate partition sector buffer failed!"); return -RT_ENOMEM; } @@ -365,7 +375,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device)); if (!blk_dev) { - rt_kprintf("mmcsd:malloc memory failed!\n"); + LOG_E("mmcsd:malloc memory failed!"); break; } @@ -448,7 +458,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) #ifdef RT_USING_DFS_MNTTABLE if (0) // if (blk_dev) { - rt_kprintf("try to mount file system!\n"); + LOG_I("try to mount file system!"); /* try to mount file system on this block device */ dfs_mount_device(&(blk_dev->dev)); } @@ -457,7 +467,7 @@ rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) } else { - rt_kprintf("read mmcsd first sector failed\n"); + LOG_E("read mmcsd first sector failed"); err = -RT_ERROR; } diff --git a/components/drivers/sdio/mmc.c b/components/drivers/sdio/mmc.c index 138d9565a1..e617c115f4 100644 --- a/components/drivers/sdio/mmc.c +++ b/components/drivers/sdio/mmc.c @@ -25,6 +25,16 @@ #include #include +#define DBG_ENABLE +#define DBG_SECTION_NAME "[SDIO]" +#ifdef RT_SDIO_DEBUG +#define DBG_LEVEL DBG_LOG +#else +#define DBG_LEVEL DBG_INFO +#endif /* RT_SDIO_DEBUG */ +#define DBG_COLOR +#include + static const rt_uint32_t tran_unit[] = { 10000, 100000, 1000000, 10000000, @@ -81,7 +91,7 @@ static rt_int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card) */ csd->csd_structure = GET_BITS(resp, 126, 2); if (csd->csd_structure == 0) { - rt_kprintf("unrecognised CSD structure version %d\n", csd->csd_structure); + LOG_E("unrecognised CSD structure version %d!", csd->csd_structure); return -RT_ERROR; } @@ -137,7 +147,7 @@ static int mmc_get_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t **new_ext_csd) */ ext_csd = rt_malloc(512); if (!ext_csd) { - rt_kprintf("alloc memory failed when get ext csd\n"); + LOG_E("alloc memory failed when get ext csd!"); return -RT_ENOMEM; } @@ -194,7 +204,7 @@ static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) card->card_capacity = *((rt_uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]); card->card_capacity *= card->card_blksize; card->card_capacity >>= 10; /* unit:KB */ - rt_kprintf("emmc card capacity %d KB\n", card->card_capacity); + LOG_I("emmc card capacity %d KB.", card->card_capacity); return 0; } @@ -333,13 +343,13 @@ static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd) } else { switch(ext_csd_bits[idx]){ case 0: - rt_kprintf("switch to bus width 1 bit failed\n"); + LOG_E("switch to bus width 1 bit failed!"); break; case 1: - rt_kprintf("switch to bus width 4 bit failed\n"); + LOG_E("switch to bus width 4 bit failed!"); break; case 2: - rt_kprintf("switch to bus width 8 bit failed\n"); + LOG_E("switch to bus width 8 bit failed!"); break; default: break; @@ -443,7 +453,7 @@ static rt_int32_t mmcsd_mmc_init_card(struct rt_mmcsd_host *host, card = rt_malloc(sizeof(struct rt_mmcsd_card)); if (!card) { - rt_kprintf("malloc card failed\n"); + LOG_E("malloc card failed!"); err = -RT_ENOMEM; goto err; } @@ -580,7 +590,7 @@ remove_card: host->card = RT_NULL; err: - rt_kprintf("init MMC card failed\n"); + LOG_E("init MMC card failed!"); return err; } diff --git a/components/drivers/sdio/mmcsd_core.c b/components/drivers/sdio/mmcsd_core.c index edf4002ac7..45ec1343f2 100644 --- a/components/drivers/sdio/mmcsd_core.c +++ b/components/drivers/sdio/mmcsd_core.c @@ -28,6 +28,16 @@ #include #include +#define DBG_ENABLE +#define DBG_SECTION_NAME "[SDIO]" +#ifdef RT_SDIO_DEBUG +#define DBG_LEVEL DBG_LOG +#else +#define DBG_LEVEL DBG_INFO +#endif /* RT_SDIO_DEBUG */ +#define DBG_COLOR +#include + #ifndef RT_MMCSD_STACK_SIZE #define RT_MMCSD_STACK_SIZE 1024 #endif @@ -206,7 +216,7 @@ rt_int32_t mmcsd_get_cid(struct rt_mmcsd_host *host, rt_uint32_t *cid) buf = (rt_uint32_t *)rt_malloc(16); if (!buf) { - rt_kprintf("allocate memory failed\n"); + LOG_E("allocate memory failed!"); return -RT_ENOMEM; } @@ -282,7 +292,7 @@ rt_int32_t mmcsd_get_csd(struct rt_mmcsd_card *card, rt_uint32_t *csd) buf = (rt_uint32_t*)rt_malloc(16); if (!buf) { - rt_kprintf("allocate memory failed\n"); + LOG_E("allocate memory failed!"); return -RT_ENOMEM; } @@ -418,7 +428,7 @@ void mmcsd_set_clock(struct rt_mmcsd_host *host, rt_uint32_t clk) { if (clk < host->freq_min) { - rt_kprintf("clock too low\n"); + LOG_W("clock too low!"); } host->io_cfg.clock = clk; @@ -539,7 +549,7 @@ rt_uint32_t mmcsd_select_voltage(struct rt_mmcsd_host *host, rt_uint32_t ocr) } else { - rt_kprintf("host doesn't support card's voltages\n"); + LOG_W("host doesn't support card's voltages!"); ocr = 0; } @@ -679,7 +689,7 @@ void mmcsd_detect(void *param) mmcsd_host_lock(host); if (host->card->sdio_function_num != 0) { - rt_kprintf("unsupport sdio card plug out!\n"); + LOG_W("unsupport sdio card plug out!"); } else { @@ -702,7 +712,7 @@ struct rt_mmcsd_host *mmcsd_alloc_host(void) host = rt_malloc(sizeof(struct rt_mmcsd_host)); if (!host) { - rt_kprintf("alloc host failed\n"); + LOG_E("alloc host failed"); return RT_NULL; } diff --git a/components/drivers/sdio/sd.c b/components/drivers/sdio/sd.c index a42aa17531..2a549ed929 100644 --- a/components/drivers/sdio/sd.c +++ b/components/drivers/sdio/sd.c @@ -25,6 +25,16 @@ #include #include +#define DBG_ENABLE +#define DBG_SECTION_NAME "[SDIO]" +#ifdef RT_SDIO_DEBUG +#define DBG_LEVEL DBG_LOG +#else +#define DBG_LEVEL DBG_INFO +#endif /* RT_SDIO_DEBUG */ +#define DBG_COLOR +#include + static const rt_uint32_t tran_unit[] = { 10000, 100000, 1000000, 10000000, @@ -167,11 +177,11 @@ static rt_int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card) #endif break; default: - rt_kprintf("unrecognised CSD structure version %d\n", csd->csd_structure); + LOG_E("unrecognised CSD structure version %d!", csd->csd_structure); return -RT_ERROR; } - rt_kprintf("SD card capacity %d KB\n", card->card_capacity); + LOG_I("SD card capacity %d KB.", card->card_capacity); return 0; } @@ -201,7 +211,7 @@ static rt_int32_t mmcsd_switch(struct rt_mmcsd_card *card) buf = (rt_uint8_t*)rt_malloc(64); if (!buf) { - rt_kprintf("alloc memory failed\n"); + LOG_E("alloc memory failed!"); return -RT_ENOMEM; } @@ -270,7 +280,7 @@ static rt_int32_t mmcsd_switch(struct rt_mmcsd_card *card) if ((buf[16] & 0xF) != 1) { - rt_kprintf("switching card to high speed failed\n"); + LOG_E("switching card to high speed failed!"); goto err; } @@ -588,7 +598,7 @@ static rt_int32_t mmcsd_sd_init_card(struct rt_mmcsd_host *host, card = rt_malloc(sizeof(struct rt_mmcsd_card)); if (!card) { - rt_kprintf("malloc card failed\n"); + LOG_E("malloc card failed!"); err = -RT_ENOMEM; goto err; } @@ -703,9 +713,9 @@ rt_int32_t init_sd(struct rt_mmcsd_host *host, rt_uint32_t ocr) if (ocr & VDD_165_195) { - rt_kprintf(" SD card claims to support the " + LOG_I(" SD card claims to support the " "incompletely defined 'low voltage range'. This " - "will be ignored.\n"); + "will be ignored."); ocr &= ~VDD_165_195; } @@ -743,7 +753,7 @@ remove_card: host->card = RT_NULL; err: - rt_kprintf("init SD card failed\n"); + LOG_D("init SD card failed!"); return err; } diff --git a/components/drivers/sdio/sdio.c b/components/drivers/sdio/sdio.c index b105e65109..67e82156b3 100644 --- a/components/drivers/sdio/sdio.c +++ b/components/drivers/sdio/sdio.c @@ -26,6 +26,16 @@ #include #include +#define DBG_ENABLE +#define DBG_SECTION_NAME "[SDIO]" +#ifdef RT_SDIO_DEBUG +#define DBG_LEVEL DBG_LOG +#else +#define DBG_LEVEL DBG_INFO +#endif /* RT_SDIO_DEBUG */ +#define DBG_COLOR +#include + #ifndef RT_SDIO_STACK_SIZE #define RT_SDIO_STACK_SIZE 512 #endif @@ -432,7 +442,7 @@ static rt_int32_t sdio_read_cccr(struct rt_mmcsd_card *card) if (cccr_version > SDIO_CCCR_REV_3_00) { - rt_kprintf("unrecognised CCCR structure version %d\n", cccr_version); + LOG_E("unrecognised CCCR structure version %d", cccr_version); return -RT_ERROR; } @@ -579,7 +589,7 @@ static rt_int32_t sdio_read_cis(struct rt_sdio_function *func) case CISTPL_MANFID: if (tpl_link < 4) { - rt_kprintf("bad CISTPL_MANFID length\n"); + LOG_D("bad CISTPL_MANFID length"); break; } if (func->num != 0) @@ -605,15 +615,15 @@ static rt_int32_t sdio_read_cis(struct rt_sdio_function *func) if (ret) { - rt_kprintf("bad CISTPL_FUNCE size %u " - "type %u\n", tpl_link, curr->data[0]); + LOG_D("bad CISTPL_FUNCE size %u " + "type %u", tpl_link, curr->data[0]); } break; case CISTPL_VERS_1: if (tpl_link < 2) { - rt_kprintf("CISTPL_VERS_1 too short\n"); + LOG_D("CISTPL_VERS_1 too short"); } break; default: @@ -623,7 +633,7 @@ static rt_int32_t sdio_read_cis(struct rt_sdio_function *func) curr->size = tpl_link; *prev = curr; prev = &curr->next; - rt_kprintf( "function %d, CIS tuple code %#x, length %d\n", + LOG_D( "function %d, CIS tuple code %#x, length %d", func->num, tpl_code, tpl_link); break; } @@ -686,7 +696,6 @@ err: return ret; } - static rt_int32_t sdio_initialize_function(struct rt_mmcsd_card *card, rt_uint32_t func_num) { @@ -698,7 +707,7 @@ static rt_int32_t sdio_initialize_function(struct rt_mmcsd_card *card, func = rt_malloc(sizeof(struct rt_sdio_function)); if (!func) { - rt_kprintf("malloc rt_sdio_function failed\n"); + LOG_E("malloc rt_sdio_function failed"); ret = -RT_ENOMEM; goto err; } @@ -788,7 +797,7 @@ static rt_int32_t sdio_register_card(struct rt_mmcsd_card *card) sc = rt_malloc(sizeof(struct sdio_card)); if (sc == RT_NULL) { - rt_kprintf("malloc sdio card failed\n"); + LOG_E("malloc sdio card failed"); return -RT_ENOMEM; } @@ -836,7 +845,7 @@ static rt_int32_t sdio_init_card(struct rt_mmcsd_host *host, rt_uint32_t ocr) card = rt_malloc(sizeof(struct rt_mmcsd_card)); if (!card) { - rt_kprintf("malloc card failed\n"); + LOG_E("malloc card failed"); err = -RT_ENOMEM; goto err; } @@ -850,7 +859,7 @@ static rt_int32_t sdio_init_card(struct rt_mmcsd_host *host, rt_uint32_t ocr) card->sdio_function[0] = rt_malloc(sizeof(struct rt_sdio_function)); if (!card->sdio_function[0]) { - rt_kprintf("malloc sdio_func0 failed\n"); + LOG_E("malloc sdio_func0 failed"); err = -RT_ENOMEM; goto err1; } @@ -944,7 +953,7 @@ err1: rt_free(host->card); } err: - rt_kprintf("error %d while initialising SDIO card\n", err); + LOG_E("error %d while initialising SDIO card", err); return err; } @@ -958,13 +967,13 @@ rt_int32_t init_sdio(struct rt_mmcsd_host *host, rt_uint32_t ocr) if (ocr & 0x7F) { - rt_kprintf("Card ocr below the defined voltage rang.\n"); + LOG_W("Card ocr below the defined voltage rang."); ocr &= ~0x7F; } if (ocr & VDD_165_195) { - rt_kprintf("Can't support the low voltage SDIO card.\n"); + LOG_W("Can't support the low voltage SDIO card."); ocr &= ~VDD_165_195; } @@ -987,7 +996,7 @@ remove_card: host->card = RT_NULL; err: - rt_kprintf("init SDIO card failed\n"); + LOG_E("init SDIO card failed"); return err; } @@ -1341,7 +1350,7 @@ rt_int32_t sdio_register_driver(struct rt_sdio_driver *driver) sd = rt_malloc(sizeof(struct sdio_driver)); if (sd == RT_NULL) { - rt_kprintf("malloc sdio driver failed\n"); + LOG_E("malloc sdio driver failed"); return -RT_ENOMEM; } @@ -1378,7 +1387,7 @@ rt_int32_t sdio_unregister_driver(struct rt_sdio_driver *driver) if (sd == RT_NULL) { - rt_kprintf("SDIO driver %s not register\n", driver->name); + LOG_E("SDIO driver %s not register", driver->name); return -RT_ERROR; }