From 70e659b1b29904d27eba408d847368e28c49b887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?An=C4=B1l=20Kara?= Date: Tue, 26 Sep 2023 03:08:59 +0300 Subject: [PATCH] fix(SDHC): Fix SDHC Get Capacity and Implement Get Sectors functionality (#727) Co-authored-by: Jake Carter --- Libraries/SDHC/Include/sdhc_lib.h | 2 +- Libraries/SDHC/Source/sdhc_lib.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Libraries/SDHC/Include/sdhc_lib.h b/Libraries/SDHC/Include/sdhc_lib.h index 4b94234116..492bbd97fa 100644 --- a/Libraries/SDHC/Include/sdhc_lib.h +++ b/Libraries/SDHC/Include/sdhc_lib.h @@ -102,7 +102,7 @@ int MXC_SDHC_Lib_SetRCA(void); int MXC_SDHC_Lib_GetCSD(mxc_sdhc_csd_regs_t *csd); /* ************************************************************************** */ -unsigned int MXC_SDHC_Lib_GetCapacity(mxc_sdhc_csd_regs_t* csd); +unsigned long long MXC_SDHC_Lib_GetCapacity(mxc_sdhc_csd_regs_t* csd); /* ************************************************************************** */ unsigned int MXC_SDHC_Lib_GetSectors(mxc_sdhc_csd_regs_t* csd); diff --git a/Libraries/SDHC/Source/sdhc_lib.c b/Libraries/SDHC/Source/sdhc_lib.c index 1e3a8823ae..d1791de2db 100644 --- a/Libraries/SDHC/Source/sdhc_lib.c +++ b/Libraries/SDHC/Source/sdhc_lib.c @@ -176,11 +176,17 @@ int MXC_SDHC_Lib_GetCSD(mxc_sdhc_csd_regs_t *csd) } /* ************************************************************************** */ -unsigned int MXC_SDHC_Lib_GetCapacity(mxc_sdhc_csd_regs_t* csd) +unsigned long long MXC_SDHC_Lib_GetCapacity(mxc_sdhc_csd_regs_t* csd) { unsigned int size = csd->csd.c_size; - return (size*(512*1024)); + return ((unsigned long long)(size+1))*((unsigned long long)512*1024); +} + +/* ************************************************************************** */ +unsigned int MXC_SDHC_Lib_GetSectors(mxc_sdhc_csd_regs_t* csd) +{ + return csd->csd.c_size; } /* ************************************************************************** */