#ifndef _CACHE_H_DEF #define _CACHE_H_DEF #include "norflash.h" template class Cache { T data [N]; unsigned begin_address; unsigned ofset_current; NorFlash nor; public: explicit Cache () noexcept : begin_address(0u), ofset_current(0u), nor() {} Cache & operator= (const unsigned addr) { begin_address = addr; ofset_current = 0u; reload (); return * this; } operator bool () { if (begin_address == 0u) return false; return true; } T * operator++ (int) { check_validity (); T * tmp = data + ofset_current; ofset_current += 1; return tmp; } protected: void check_validity () { if (ofset_current >= N) { begin_address += N * sizeof(T); reload (); ofset_current = 0u; } } void reload () { unsigned char * ptr = reinterpret_cast(data); nor.ReadBlock (begin_address, ptr, N * sizeof(T)); } }; #endif // _CACHE_H_DEF