|
| 1 | + |
| 2 | +/* |
| 3 | + core_esp8266_features.cpp |
| 4 | +
|
| 5 | + Copyright (c) 2019 Mike Nix. All rights reserved. |
| 6 | + This file is part of the esp8266 core for Arduino environment. |
| 7 | +
|
| 8 | + This library is free software; you can redistribute it and/or |
| 9 | + modify it under the terms of the GNU Lesser General Public |
| 10 | + License as published by the Free Software Foundation; either |
| 11 | + version 2.1 of the License, or (at your option) any later version. |
| 12 | +
|
| 13 | + This library is distributed in the hope that it will be useful, |
| 14 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | + Lesser General Public License for more details. |
| 17 | +
|
| 18 | + You should have received a copy of the GNU Lesser General Public |
| 19 | + License along with this library; if not, write to the Free Software |
| 20 | + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | +*/ |
| 22 | + |
| 23 | +#include <stdint.h> |
| 24 | + |
| 25 | +/* precache() |
| 26 | + * pre-loads flash data into the flash cache |
| 27 | + * if f==0, preloads instructions starting at the address we were called from. |
| 28 | + * otherwise preloads flash at the given address. |
| 29 | + * All preloads are word aligned. |
| 30 | + */ |
| 31 | +#ifdef __cplusplus |
| 32 | +extern "C" { |
| 33 | +#endif |
| 34 | + |
| 35 | +void precache(void *f, uint32_t bytes) { |
| 36 | + // Size of a cache page in bytes. We only need to read one word per |
| 37 | + // page (ie 1 word in 8) for this to work. |
| 38 | + #define CACHE_PAGE_SIZE 32 |
| 39 | + |
| 40 | + register uint32_t a0 asm("a0"); |
| 41 | + register uint32_t lines = (bytes/CACHE_PAGE_SIZE)+2; |
| 42 | + volatile uint32_t *p = (uint32_t*)((f ? (uint32_t)f : a0) & ~0x03); |
| 43 | + uint32_t x; |
| 44 | + for (uint32_t i=0; i<lines; i++, p+=CACHE_PAGE_SIZE/sizeof(uint32_t)) x=*p; |
| 45 | + (void)x; |
| 46 | +} |
| 47 | + |
| 48 | +#ifdef __cplusplus |
| 49 | +} |
| 50 | +#endif |
0 commit comments