Keyur Panchal / Counter
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Counter.h Source File

Counter.h

00001 #ifndef COUNTER_H
00002 #define COUNTER_H
00003 
00004 #include "mbed.h"
00005 #include "FreescaleIAP.h"
00006 
00007 #ifndef MAX_LEN
00008 #define MAX_LEN 8
00009 #endif
00010 
00011 /**
00012 * Counter example
00013 *
00014 * @code
00015 * #include "mbed.h"
00016 * #include "Counter.h"
00017 * 
00018 * int main(void) {
00019 *     
00020 *     Counter ct;
00021 *     while (true) {
00022 *         ct.increment(rand()%MAX_LEN);
00023 *         wait(0.5);
00024 *     }
00025 * }
00026 * @endcode
00027 */
00028 
00029 class Counter
00030 {
00031 private:
00032     int count[MAX_LEN];
00033     int is_new_count;
00034     int address;
00035     #ifdef COUNTER_DEBUG
00036     /** Simple print function
00037     *
00038     *   Prints all memory addresses in count array with values for debugging purposes.
00039     *
00040     */
00041     void print_memory(void);
00042     #endif
00043     /** Initialize count array
00044     *
00045     *   Either initializes count array to zeroes or existing count
00046     *   depending on whether it has been called before or not
00047     *
00048     */
00049     void init(void);
00050     /** Decrement count
00051     *
00052     *   Simply decrement value of index
00053     *   Private to disallow access for this specific purpose;
00054     *   @param index Index of count array to be decremented
00055     *
00056     */
00057     void decrement(int index);
00058     
00059 public:
00060 
00061     /** Default Constructor
00062     *
00063     *   Sets read/write memory addresss of Flash memory
00064     *   Also calls init()
00065     *
00066     */
00067     Counter();
00068     
00069     /** Write to Memory
00070     *
00071     *   Writes current count array to Flash Memory
00072     *
00073     */
00074     void memwrite(void);
00075     
00076     /** Read from memory
00077     *
00078     *   Loads values of existiing count array from Flash Memory
00079     *
00080     */
00081     void memread(void);
00082     
00083     /** Increment count
00084     *
00085     *   Simply increments value of index
00086     *
00087     *   @param index Index of count array to be incremented
00088     *
00089     */
00090     void increment(int index);
00091     /** Clears Count
00092     *
00093     * RESETS count array
00094     *
00095     */
00096     void clear();
00097 };
00098 
00099 #endif