2019-03-11 13:10:36 +08:00
|
|
|
/*
|
2021-03-27 17:51:56 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2019-03-11 13:10:36 +08:00
|
|
|
*
|
2019-03-11 22:55:07 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2019-03-11 13:10:36 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2018-04-02 tanek first implementation
|
2019-04-27 17:35:46 +08:00
|
|
|
* 2019-04-27 misonyo update to cortex-m7 series
|
2019-03-11 13:10:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rthw.h>
|
2019-04-27 17:35:46 +08:00
|
|
|
#include <rtdef.h>
|
|
|
|
#include <board.h>
|
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
/* The L1-caches on all Cortex®-M7s are divided into lines of 32 bytes. */
|
2019-04-27 17:35:46 +08:00
|
|
|
#define L1CACHE_LINESIZE_BYTE (32)
|
2019-03-11 13:10:36 +08:00
|
|
|
|
|
|
|
void rt_hw_cpu_icache_enable(void)
|
|
|
|
{
|
|
|
|
SCB_EnableICache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_cpu_icache_disable(void)
|
|
|
|
{
|
|
|
|
SCB_DisableICache();
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_base_t rt_hw_cpu_icache_status(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_cpu_icache_ops(int ops, void* addr, int size)
|
|
|
|
{
|
2019-04-27 17:35:46 +08:00
|
|
|
rt_uint32_t address = (rt_uint32_t)addr & (rt_uint32_t) ~(L1CACHE_LINESIZE_BYTE - 1);
|
|
|
|
rt_int32_t size_byte = size + address - (rt_uint32_t)addr;
|
|
|
|
rt_uint32_t linesize = 32U;
|
2019-03-11 13:10:36 +08:00
|
|
|
if (ops & RT_HW_CACHE_INVALIDATE)
|
|
|
|
{
|
2019-04-27 17:35:46 +08:00
|
|
|
__DSB();
|
|
|
|
while (size_byte > 0)
|
|
|
|
{
|
|
|
|
SCB->ICIMVAU = address;
|
|
|
|
address += linesize;
|
|
|
|
size_byte -= linesize;
|
|
|
|
}
|
|
|
|
__DSB();
|
|
|
|
__ISB();
|
2019-03-11 13:10:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_cpu_dcache_enable(void)
|
|
|
|
{
|
|
|
|
SCB_EnableDCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_cpu_dcache_disable(void)
|
|
|
|
{
|
|
|
|
SCB_DisableDCache();
|
|
|
|
}
|
|
|
|
|
|
|
|
rt_base_t rt_hw_cpu_dcache_status(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_cpu_dcache_ops(int ops, void* addr, int size)
|
|
|
|
{
|
2019-04-27 17:35:46 +08:00
|
|
|
rt_uint32_t startAddr = (rt_uint32_t)addr & (rt_uint32_t)~(L1CACHE_LINESIZE_BYTE - 1);
|
|
|
|
rt_uint32_t size_byte = size + (rt_uint32_t)addr - startAddr;
|
|
|
|
|
2019-03-11 13:10:36 +08:00
|
|
|
if (ops & (RT_HW_CACHE_FLUSH | RT_HW_CACHE_INVALIDATE))
|
|
|
|
{
|
2019-10-23 15:04:30 +08:00
|
|
|
SCB_CleanInvalidateDCache_by_Addr((uint32_t *)startAddr, size_byte);
|
2019-03-11 13:10:36 +08:00
|
|
|
}
|
|
|
|
else if (ops & RT_HW_CACHE_FLUSH)
|
|
|
|
{
|
2019-10-23 15:04:30 +08:00
|
|
|
SCB_CleanDCache_by_Addr((uint32_t *)startAddr, size_byte);
|
2019-03-11 13:10:36 +08:00
|
|
|
}
|
|
|
|
else if (ops & RT_HW_CACHE_INVALIDATE)
|
|
|
|
{
|
2019-10-23 15:04:30 +08:00
|
|
|
SCB_InvalidateDCache_by_Addr((uint32_t *)startAddr, size_byte);
|
2019-03-11 13:10:36 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RT_ASSERT(0);
|
|
|
|
}
|
|
|
|
}
|