Skip to content

Commit

Permalink
hal_flash: Add hal_flash_sector_info
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
kasjer committed Jun 28, 2024
1 parent 0b2a79c commit 999c8f2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions hw/hal/include/hal/hal_flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
15 changes: 15 additions & 0 deletions hw/hal/src/hal_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 999c8f2

Please sign in to comment.