|
| 1 | +/* |
| 2 | + * Copyright (c) 2006-2018, RT-Thread Development Team |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + * |
| 6 | + * Change Logs: |
| 7 | + * Date Author Notes |
| 8 | + * 2018-04-02 tanek first implementation |
| 9 | + * 2019-04-27 misonyo update to cortex-m7 series |
| 10 | + */ |
| 11 | + |
| 12 | +#include <rthw.h> |
| 13 | +#include <rtdef.h> |
| 14 | +#include <board.h> |
| 15 | + |
| 16 | +/* The L1-caches on all Cortex®-M7s are divided into lines of 32 bytes. */ |
| 17 | +#define L1CACHE_LINESIZE_BYTE (32) |
| 18 | + |
| 19 | +void rt_hw_cpu_icache_enable(void) |
| 20 | +{ |
| 21 | + SCB_EnableICache(); |
| 22 | +} |
| 23 | + |
| 24 | +void rt_hw_cpu_icache_disable(void) |
| 25 | +{ |
| 26 | + SCB_DisableICache(); |
| 27 | +} |
| 28 | + |
| 29 | +rt_base_t rt_hw_cpu_icache_status(void) |
| 30 | +{ |
| 31 | + return 0; |
| 32 | +} |
| 33 | + |
| 34 | +void rt_hw_cpu_icache_ops(int ops, void* addr, int size) |
| 35 | +{ |
| 36 | + rt_uint32_t address = (rt_uint32_t)addr & (rt_uint32_t) ~(L1CACHE_LINESIZE_BYTE - 1); |
| 37 | + rt_int32_t size_byte = size + address - (rt_uint32_t)addr; |
| 38 | + rt_uint32_t linesize = 32U; |
| 39 | + if (ops & RT_HW_CACHE_INVALIDATE) |
| 40 | + { |
| 41 | + __DSB(); |
| 42 | + while (size_byte > 0) |
| 43 | + { |
| 44 | + SCB->ICIMVAU = address; |
| 45 | + address += linesize; |
| 46 | + size_byte -= linesize; |
| 47 | + } |
| 48 | + __DSB(); |
| 49 | + __ISB(); |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +void rt_hw_cpu_dcache_enable(void) |
| 54 | +{ |
| 55 | + SCB_EnableDCache(); |
| 56 | +} |
| 57 | + |
| 58 | +void rt_hw_cpu_dcache_disable(void) |
| 59 | +{ |
| 60 | + SCB_DisableDCache(); |
| 61 | +} |
| 62 | + |
| 63 | +rt_base_t rt_hw_cpu_dcache_status(void) |
| 64 | +{ |
| 65 | + return 0; |
| 66 | +} |
| 67 | + |
| 68 | +void rt_hw_cpu_dcache_ops(int ops, void* addr, int size) |
| 69 | +{ |
| 70 | + rt_uint32_t startAddr = (rt_uint32_t)addr & (rt_uint32_t)~(L1CACHE_LINESIZE_BYTE - 1); |
| 71 | + rt_uint32_t size_byte = size + (rt_uint32_t)addr - startAddr; |
| 72 | + |
| 73 | + if (ops & (RT_HW_CACHE_FLUSH | RT_HW_CACHE_INVALIDATE)) |
| 74 | + { |
| 75 | + SCB_CleanInvalidateDCache_by_Addr((rt_uint32_t *)startAddr, size_byte); |
| 76 | + } |
| 77 | + else if (ops & RT_HW_CACHE_FLUSH) |
| 78 | + { |
| 79 | + SCB_CleanDCache_by_Addr((rt_uint32_t *)startAddr, size_byte); |
| 80 | + } |
| 81 | + else if (ops & RT_HW_CACHE_INVALIDATE) |
| 82 | + { |
| 83 | + SCB_InvalidateDCache_by_Addr((rt_uint32_t *)startAddr, size_byte); |
| 84 | + } |
| 85 | + else |
| 86 | + { |
| 87 | + RT_ASSERT(0); |
| 88 | + } |
| 89 | +} |
0 commit comments