Skip to content

Commit

Permalink
[bsp][hpmicro] fix the alignement check logic and the cache-maintenan…
Browse files Browse the repository at this point in the history
…ce logic

- corrected the alignement check logic
- optimized the cache maintenance logic

Signed-off-by: Fan YANG <[email protected]>
  • Loading branch information
helloeagleyang committed Jan 6, 2025
1 parent 2946e4a commit 04fe968
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions bsp/hpmicro/libraries/drivers/drv_sdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@
* Keep this option disabled by default, please enable it if the default setting cannot meet
* real requirement of application.
*/
#ifndef HPM_SDXC_ALLOC_CACHELINE_ALIGNED_BUF
#define HPM_SDXC_ALLOC_CACHELINE_ALIGNED_BUF 0
#endif

struct hpm_mmcsd
{
Expand Down Expand Up @@ -395,7 +397,7 @@ static void hpm_sdmmc_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *r
struct rt_mmcsd_cmd *cmd = req->cmd;
struct rt_mmcsd_data *data = cmd->data;

/* configure command */
/* configure command */
sdxc_cmd.cmd_index = cmd->cmd_code;
sdxc_cmd.cmd_argument = cmd->arg;
sdxc_cmd.cmd_type = (cmd->cmd_code == STOP_TRANSMISSION) ? sdxc_cmd_type_abort_cmd : sdxc_cmd_type_normal_cmd;
Expand Down Expand Up @@ -461,7 +463,7 @@ static void hpm_sdmmc_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *r
#if defined(HPM_SDXC_ALLOC_CACHELINE_ALIGNED_BUF) && (HPM_SDXC_ALLOC_CACHELINE_ALIGNED_BUF == 1)
if (!SDXC_IS_CACHELINE_ALIGNED(xfer_buf_addr) || !SDXC_IS_CACHELINE_ALIGNED(write_size))
#else
if ((xfer_buf_addr % 4 != 0) && (write_size % 4 != 0))
if ((xfer_buf_addr % 4 != 0) || (write_size % 4 != 0))
#endif
{
write_size = SDXC_CACHELINE_ALIGN_UP(xfer_len);
Expand All @@ -484,9 +486,7 @@ static void hpm_sdmmc_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *r
size_t aligned_end = SDXC_CACHELINE_ALIGN_UP((uint32_t)sdxc_data.tx_data + write_size);
aligned_size = aligned_end - aligned_start;
}
rt_base_t level = rt_hw_interrupt_disable();
l1c_dc_flush(aligned_start, aligned_size);
rt_hw_interrupt_enable(level);
sdxc_data.rx_data = NULL;
}
else
Expand All @@ -507,12 +507,17 @@ static void hpm_sdmmc_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *r
else
{
sdxc_data.rx_data = (uint32_t*) core_local_mem_to_sys_address(BOARD_RUNNING_CORE, xfer_buf_addr);
size_t aligned_start = SDXC_CACHELINE_ALIGN_DOWN(sdxc_data.rx_data);
size_t aligned_end = SDXC_CACHELINE_ALIGN_UP((uint32_t)sdxc_data.rx_data + read_size);
uint32_t aligned_size = aligned_end - aligned_start;
rt_base_t level = rt_hw_interrupt_disable();
l1c_dc_flush(aligned_start, aligned_size);
rt_hw_interrupt_enable(level);
size_t buf_start = (uint32_t) sdxc_data.rx_data;
size_t aligned_start = HPM_L1C_CACHELINE_ALIGN_DOWN(buf_start);
size_t end_addr = buf_start + xfer_len;
/* FLUSH un-cacheline aligned memory region */
if ((buf_start % HPM_L1C_CACHELINE_SIZE) != 0) {
l1c_dc_writeback(aligned_start, HPM_L1C_CACHELINE_SIZE);
}
if ((end_addr % HPM_L1C_CACHELINE_SIZE) != 0) {
uint32_t aligned_tail = HPM_L1C_CACHELINE_ALIGN_DOWN(end_addr);
l1c_dc_writeback(aligned_tail, HPM_L1C_CACHELINE_SIZE);
}
}
sdxc_data.tx_data = RT_NULL;
}
Expand Down

0 comments on commit 04fe968

Please sign in to comment.