This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git

commit ff86f8f8f15a6b8679c516b6a627b9bb9d436c93
Author: Jerzy Kasenberg <[email protected]>
AuthorDate: Fri Jun 28 13:48:08 2024 +0200

    hal_flash: Add hal_flash_sector_info
    
    In several places code was accessing hal_flash structure
    and then pointer to hff_sector_info to get sector information.
    
    Now function is exposed to make it things simpler.
    
    Signed-off-by: Jerzy Kasenberg <[email protected]>
---
 hw/hal/include/hal/hal_flash.h | 15 +++++++++++++++
 hw/hal/src/hal_flash.c         | 15 +++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/hw/hal/include/hal/hal_flash.h b/hw/hal/include/hal/hal_flash.h
index 9aa8679ac..95807ddef 100644
--- a/hw/hal/include/hal/hal_flash.h
+++ b/hw/hal/include/hal/hal_flash.h
@@ -35,6 +35,21 @@ extern "C" {
 
 int hal_flash_ioctl(uint8_t flash_id, uint32_t cmd, void *args);
 
+/**
+ * @brief Return information about flash sector
+ *
+ * @param flash_id              The ID of the flash device to read from.
+ * @param sector_index          The sector number to get information about.
+ * @param start_address         A buffer to fill with start address of the 
sector.
+ * @param size                  A buffer for sector size.
+ *
+ * @return                      0 on success;
+ *                              SYS_EINVAL on bad argument error;
+ *                              SYS_EIO on flash driver error.
+ */
+int hal_flash_sector_info(uint8_t flash_id, int sector_index,
+                          uint32_t *start_address, uint32_t *size);
+
 /**
  * @brief Reads a block of data from flash.
  *
diff --git a/hw/hal/src/hal_flash.c b/hw/hal/src/hal_flash.c
index b54f65b82..29cf72d49 100644
--- a/hw/hal/src/hal_flash.c
+++ b/hw/hal/src/hal_flash.c
@@ -77,6 +77,21 @@ hal_flash_erased_val(uint8_t flash_id)
     return hf->hf_erased_val;
 }
 
+int
+hal_flash_sector_info(uint8_t flash_id, int sector_index,
+                      uint32_t *start_address, uint32_t *size)
+{
+    const struct hal_flash *hf;
+
+    hf = hal_bsp_flash_dev(flash_id);
+    if (!hf) {
+        return SYS_EINVAL;
+    }
+
+    return hf->hf_itf->hff_sector_info(hf, sector_index, start_address, size);
+}
+
+
 uint32_t
 hal_flash_sector_size(const struct hal_flash *hf, int sec_idx)
 {

Reply via email to