Simple counter class, non-volatile between resets and power on/off.
Simple Counter class, used to store count array in non-volatile flash memory between resets and power on/off.
Counter.h
- Committer:
- kpan
- Date:
- 2018-11-12
- Revision:
- 1:e8eeddee2959
- Parent:
- 0:693f2f97c8c1
- Child:
- 2:f02ac448ecd3
File content as of revision 1:e8eeddee2959:
#include "mbed.h" #include "FreescaleIAP.h" #define MAX_LEN 8 //#define COUNTER_DEBUG class Counter { private: int count[MAX_LEN]; int new_count; int address; #ifdef COUNTER_DEBUG /** Simple print function * * Prints all memory addresses in count array with values for debugging purposes. * */ void print_memory(); #endif /** Initialize count array * * Either initializes count array to zeroes or existing count * depending on whether it has been called before or not * */ void init(); public: /** Default Constructor * * Sets read/write memory addresss of Flash memory * Also calls init() * */ Counter(); /** Write to Memory * * Writes current count array to Flash Memory * */ void memwrite(); /** Read from memory * * Loads values of existiing count array from Flash Memory * */ void memread(); /** Increment count * * Simply increments value of index * * @param index Index of count array to be incremented * */ void increment(int index); };