Skip to content

Commit

Permalink
Simplified cache control algorithm.
Browse files Browse the repository at this point in the history
The SCB Cache controll functions has follwoing two functionality :
1. Round the start address to 32byte align ( by hardware register ).
2. Repeat untill all required area were processed.
Thus, we don't need to do it in Murasaki.

Followings are affected.

CleanDataCacheByAddress()
CleanAndInvalidateDataCacheByAddress()
  • Loading branch information
suikan4github committed Jul 2, 2023
1 parent 408e19c commit 8eb2235
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions core/murasaki_defs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,24 +341,12 @@ static inline bool IsInsideInterrupt()
*/
static inline void CleanAndInvalidateDataCacheByAddress(void *address, size_t size)
{
#ifdef __CORE_CM7_H_GENERIC
#if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
// Is data cache enabled? then, invalidate it
if (( SCB->CCR & SCB_CCR_DC_Msk ) != 0 )
{
unsigned int aligned_address = reinterpret_cast<unsigned int>(address);

// extract modulo 32. The address have to be aligned to 32byte.
unsigned int adjustment = aligned_address & 0x1F;
// Adjust the address and size.
aligned_address -= adjustment; // aligne to 32byte boarder
size += adjustment; // Because the start address is lower, the size is bigger.

::SCB_CleanInvalidateDCache_by_Addr(reinterpret_cast<long unsigned int *>(aligned_address), size);
::SCB_CleanInvalidateDCache_by_Addr(reinterpret_cast<long unsigned int *>(address), size);
}
#elif defined ( __CORE_CM0_H_GENERIC ) ||defined ( __CORE_CM0PLUS_H_GENERIC ) ||defined ( __CORE_CM3_H_GENERIC ) ||defined ( __CORE_CM4_H_GENERIC ) ||defined ( __CORE_CM1_H_GENERIC ) ||defined ( __CORE_CM33_H_GENERIC )
// Do nothing. These core doesn't have d-cache.
#else
#error "Unknown core"
#endif
}

Expand All @@ -376,24 +364,12 @@ static inline void CleanAndInvalidateDataCacheByAddress(void *address, size_t si
*/
static inline void CleanDataCacheByAddress(void *address, size_t size)
{
#ifdef __CORE_CM7_H_GENERIC
#if defined (__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U)
// Is data cache enabled? then, clean the data cache
if (( SCB->CCR & SCB_CCR_DC_Msk ) != 0 )
{
unsigned int aligned_address = reinterpret_cast<unsigned int>(address);

// extract modulo 32. The address have to be aligned to 32byte.
unsigned int adjustment = aligned_address & 0x1F;
// Adjust the address and size.
aligned_address -= adjustment; // aligne to 32byte boarder
size += adjustment; // Because the start address is lower, the size is bigger.

::SCB_CleanDCache_by_Addr(reinterpret_cast<long unsigned int *>(aligned_address), size);
::SCB_CleanDCache_by_Addr(reinterpret_cast<long unsigned int *>(address), size);
}
#elif defined ( __CORE_CM0_H_GENERIC ) ||defined ( __CORE_CM0PLUS_H_GENERIC ) ||defined ( __CORE_CM3_H_GENERIC ) ||defined ( __CORE_CM4_H_GENERIC ) ||defined ( __CORE_CM1_H_GENERIC ) ||defined ( __CORE_CM33_H_GENERIC )
// Do nothing. These core doesn't have d-cache.
#else
#error "Unknown core"
#endif
}

Expand Down

0 comments on commit 8eb2235

Please sign in to comment.