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.
Diff: Counter.h
- Revision:
- 1:e8eeddee2959
- Parent:
- 0:693f2f97c8c1
- Child:
- 2:f02ac448ecd3
--- a/Counter.h Mon Nov 12 18:43:22 2018 +0000 +++ b/Counter.h Mon Nov 12 19:01:53 2018 +0000 @@ -1,20 +1,61 @@ #include "mbed.h" #include "FreescaleIAP.h" -#define PARTY_LIMIT 8 -#define COUNTER_DEBUG +#define MAX_LEN 8 +//#define COUNTER_DEBUG class Counter { private: - int vc[PARTY_LIMIT]; - int is_written; + 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(); - void write_vc(); - void read_vc(); - void increment(int); + + /** 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); }; \ No newline at end of file