From 2d4c475d1d9a67d03193366a6a402d00de7f414a Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 14 Jun 2016 09:26:16 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9625 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/lib/peripherals/flash/hal_flash.c | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'os/hal/lib/peripherals/flash/hal_flash.c') diff --git a/os/hal/lib/peripherals/flash/hal_flash.c b/os/hal/lib/peripherals/flash/hal_flash.c index b65ca3768..439a9c6aa 100644 --- a/os/hal/lib/peripherals/flash/hal_flash.c +++ b/os/hal/lib/peripherals/flash/hal_flash.c @@ -72,4 +72,44 @@ flash_error_t flashWaitErase(BaseFlash *devp) { } } +/** + * @brief Returns the offset of a sector. + */ +flash_offset_t flashGetSectorOffset(BaseFlash *devp, + flash_sector_t sector) { + flash_offset_t offset; + const flash_descriptor_t *descriptor = flashGetDescriptor(devp); + + osalDbgAssert(sector < descriptor->sectors_count, "invalid sector"); + + if (descriptor->sectors != NULL) { + offset = descriptor->sectors[sector].offset; + } + else { + offset = (flash_offset_t)sector * (flash_offset_t)descriptor->sectors_size; + } + + return offset; +} + +/** + * @brief Returns the size of a sector. + */ +uint32_t flashGetSectorSize(BaseFlash *devp, + flash_sector_t sector) { + uint32_t size; + const flash_descriptor_t *descriptor = flashGetDescriptor(devp); + + osalDbgAssert(sector < descriptor->sectors_count, "invalid sector"); + + if (descriptor->sectors != NULL) { + size = descriptor->sectors[sector].size; + } + else { + size = descriptor->sectors_size; + } + + return size; +} + /** @} */ -- cgit v1.2.3