MySensors Library & Examples  2.3.2-62-ge298769
NVRAM.h
Go to the documentation of this file.
1 /*
2  * NVRAM.h - Byte-wise storage for Virtual Pages.
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 */
28 #pragma once
29 
30 #include "Flash.h"
31 #include "VirtualPage.h"
32 #include <Arduino.h>
33 
39 {
40 public:
41  //----------------------------------------------------------------------------
43  NVRAMClass() {};
44  //----------------------------------------------------------------------------
46  void begin() {};
47  //----------------------------------------------------------------------------
49  void end() {};
50  //----------------------------------------------------------------------------
54  uint16_t length() const;
55  //----------------------------------------------------------------------------
61  void read_block(uint8_t *dst, uint16_t idx, uint16_t n);
62  //----------------------------------------------------------------------------
67  uint8_t read(const uint16_t idx);
68  //----------------------------------------------------------------------------
75  bool write_block(uint8_t *src, uint16_t idx, uint16_t n);
76  //----------------------------------------------------------------------------
82  bool write(const uint16_t idx, uint8_t value);
83  //----------------------------------------------------------------------------
89  int write_prepare(uint16_t number);
90  //----------------------------------------------------------------------------
95  void clean_up(uint16_t write_preserve);
96 
97 private:
98  // Return a virtual page
99  uint32_t *get_page();
100  // Get actual log position
101  uint16_t get_log_position(uint32_t *vpage);
102  // Read a byte from page
103  uint8_t get_byte_from_page(uint32_t *vpage, uint16_t log_start,
104  uint16_t log_end, uint16_t idx);
105  // switch a page
106  uint32_t *switch_page(uint32_t *old_vpage, uint16_t *log_start,
107  uint16_t *log_end);
108 };
109 
111 extern NVRAMClass NVRAM;
112 
NVRAMClass::clean_up
void clean_up(uint16_t write_preserve)
NVRAMClass::end
void end()
Definition: NVRAM.h:49
NVRAMClass::write
bool write(const uint16_t idx, uint8_t value)
NVRAMClass::read_block
void read_block(uint8_t *dst, uint16_t idx, uint16_t n)
VirtualPage.h
Virtual page management on top of Flash The managed pages are organized into VirtualPage....
NVRAMClass::begin
void begin()
Definition: NVRAM.h:46
NVRAM
NVRAMClass NVRAM
NVRAMClass
Nonvolatile Memory.
Definition: NVRAM.h:38
NVRAMClass::write_prepare
int write_prepare(uint16_t number)
NVRAMClass::length
uint16_t length() const
NVRAMClass::NVRAMClass
NVRAMClass()
Definition: NVRAM.h:43
NVRAMClass::write_block
bool write_block(uint8_t *src, uint16_t idx, uint16_t n)
NVRAMClass::read
uint8_t read(const uint16_t idx)
Flash.h
Flash abstraction layer.