MHVLib
20111011
An efficiency oriented runtime library for AVR microcontrollers
|
00001 /* Copyright (c) 2011, Make, Hack, Void Inc 00002 * All rights reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions are met: 00006 * * Redistributions of source code must retain the above copyright 00007 * notice, this list of conditions and the following disclaimer. 00008 * * Redistributions in binary form must reproduce the above copyright 00009 * notice, this list of conditions and the following disclaimer in the 00010 * documentation and/or other materials provided with the distribution. 00011 * * Neither the name of the Make, Hack, Void nor the 00012 * names of its contributors may be used to endorse or promote products 00013 * derived from this software without specific prior written permission. 00014 * 00015 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00016 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00017 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00018 * DISCLAIMED. IN NO EVENT SHALL MAKE, HACK, VOID BE LIABLE FOR ANY 00019 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00020 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00021 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00022 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00023 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00024 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00025 */ 00026 00027 00028 #ifndef MHV_EEPROM_H_ 00029 #define MHV_EEPROM_H_ 00030 00031 #include <MHV_io.h> 00032 #include <MHV_Lock.h> 00033 #include <inttypes.h> 00034 00035 #define MHV_EEPROM_ASSIGN_INTERRUPTS(_mhvEeprom) \ 00036 ISR(MHV_EEPROM_VECT) { \ 00037 _mhvEeprom.writeInterrupt(); \ 00038 } 00039 00040 #define MHV_EEPROM_CREATE(_mhvObjectName) \ 00041 MHV_EEPROM _mhvObjectName; \ 00042 MHV_EEPROM_ASSIGN_INTERRUPTS(_mhvObjectName); 00043 00044 #define MHV_EEPROM_BUSY -1 00045 00046 class MHV_EEPROM { 00047 private: 00048 MHV_Lock _lock; 00049 uint16_t _writeAddress; 00050 uint8_t *_writeBuffer; 00051 uint16_t _bytesWritten; 00052 uint16_t _bytesToWrite; 00053 void (*_doneCallback)(void *buffer, void *data); 00054 void *_doneCallbackData; 00055 00056 public: 00057 MHV_EEPROM(); 00058 int16_t read(uint16_t address); 00059 uint8_t busyRead(uint16_t address); 00060 int8_t read(void *buffer, uint16_t address, uint16_t length); 00061 void busyRead(void *buffer, uint16_t address, uint16_t length); 00062 int8_t write(uint16_t address, uint8_t data); 00063 int8_t busyWrite(void *buffer, uint16_t address, uint16_t length); 00064 int8_t write(void *buffer, uint16_t address, uint16_t length, 00065 void (*doneCallback)(void *buffer, void *data), 00066 void *doneCallbackData); 00067 void writeInterrupt(); 00068 bool isBusy(); 00069 }; 00070 00071 #endif /* MHV_EEPROM_H_ */