MySensors Library & Examples  2.3.2-62-ge298769
VirtualPage.h
Go to the documentation of this file.
1 /*
2  VirtualPage.h - Flash page management
3  Original Copyright (c) 2017 Frank Holtz. All right reserved.
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
29 #pragma once
30 
31 #include "Flash.h"
32 #include <Arduino.h>
33 
39 {
40 public:
41  //----------------------------------------------------------------------------
44  //----------------------------------------------------------------------------
46  void begin() {};
47  //----------------------------------------------------------------------------
49  void end() {};
50  //----------------------------------------------------------------------------
54  uint16_t size() const;
55  //----------------------------------------------------------------------------
59  uint16_t length() const;
60  //----------------------------------------------------------------------------
64  uint16_t page_count() const;
65  //----------------------------------------------------------------------------
71  uint32_t wear_level();
72  //----------------------------------------------------------------------------
79  uint32_t *get(uint32_t magic);
80  //----------------------------------------------------------------------------
87  uint32_t *allocate(uint32_t magic);
88  //----------------------------------------------------------------------------
97  uint32_t *allocate(uint32_t magic, uint32_t max_writes);
98  //----------------------------------------------------------------------------
103  void release_prepare(uint32_t *address);
104  //----------------------------------------------------------------------------
108  void release(uint32_t *address);
109  //----------------------------------------------------------------------------
114  bool release_started(uint32_t *address);
115  //----------------------------------------------------------------------------
118  void fail(uint32_t *address);
119  //----------------------------------------------------------------------------
122  void clean_up();
123  //----------------------------------------------------------------------------
126  void format();
127 
128 private:
129  // convert page number 1..max_pages into an address
130  uint32_t *get_page_address(uint16_t page);
131  // build a page
132  void build_page(uint32_t *address, uint32_t magic);
133  // return number of erase cycles
134  uint32_t get_page_erase_cycles(uint32_t *address);
135 };
136 
138 
VirtualPageClass::wear_level
uint32_t wear_level()
VirtualPageClass::begin
void begin()
Definition: VirtualPage.h:46
VirtualPageClass::release
void release(uint32_t *address)
VirtualPageClass::release_started
bool release_started(uint32_t *address)
VirtualPageClass::size
uint16_t size() const
VirtualPageClass::length
uint16_t length() const
VirtualPage
VirtualPageClass VirtualPage
extern VirtualPageClass
VirtualPageClass::get
uint32_t * get(uint32_t magic)
VirtualPageClass::clean_up
void clean_up()
VirtualPageClass
Virtual page management on top of Flash.
Definition: VirtualPage.h:38
VirtualPageClass::fail
void fail(uint32_t *address)
VirtualPageClass::format
void format()
VirtualPageClass::VirtualPageClass
VirtualPageClass()
Definition: VirtualPage.h:43
VirtualPageClass::release_prepare
void release_prepare(uint32_t *address)
VirtualPageClass::end
void end()
Definition: VirtualPage.h:49
VirtualPageClass::page_count
uint16_t page_count() const
VirtualPageClass::allocate
uint32_t * allocate(uint32_t magic)
Flash.h
Flash abstraction layer.