Dependencies: DM_FATFileSystem EthernetInterface HTTPClient mbed-rtos mbed-src
Fork of DMSupport by
Memory/InternalEEPROM.h@34:fc366bab393f, 2015-03-09 (annotated)
- Committer:
- embeddedartists
- Date:
- Mon Mar 09 11:15:56 2015 +0100
- Revision:
- 34:fc366bab393f
- Parent:
- 20:9df19da50290
- Added size guards in InternalEEPROM
- Added documentation in missing classes
- Added option to redirect RtosLog to USBSerial (a USB Device Serial port)
- Moved the mbed_mac_address function from the SDK to the BIOS
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
embeddedartists | 0:6b68dac0d986 | 1 | /* |
embeddedartists | 0:6b68dac0d986 | 2 | * Copyright 2014 Embedded Artists AB |
embeddedartists | 0:6b68dac0d986 | 3 | * |
embeddedartists | 0:6b68dac0d986 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
embeddedartists | 0:6b68dac0d986 | 5 | * you may not use this file except in compliance with the License. |
embeddedartists | 0:6b68dac0d986 | 6 | * You may obtain a copy of the License at |
embeddedartists | 0:6b68dac0d986 | 7 | * |
embeddedartists | 0:6b68dac0d986 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
embeddedartists | 0:6b68dac0d986 | 9 | * |
embeddedartists | 0:6b68dac0d986 | 10 | * Unless required by applicable law or agreed to in writing, software |
embeddedartists | 0:6b68dac0d986 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
embeddedartists | 0:6b68dac0d986 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
embeddedartists | 0:6b68dac0d986 | 13 | * See the License for the specific language governing permissions and |
embeddedartists | 0:6b68dac0d986 | 14 | * limitations under the License. |
embeddedartists | 0:6b68dac0d986 | 15 | */ |
embeddedartists | 0:6b68dac0d986 | 16 | |
embeddedartists | 0:6b68dac0d986 | 17 | #ifndef INTERNAL_EEPROM_H |
embeddedartists | 0:6b68dac0d986 | 18 | #define INTERNAL_EEPROM_H |
embeddedartists | 0:6b68dac0d986 | 19 | |
embeddedartists | 0:6b68dac0d986 | 20 | #include "mbed.h" |
embeddedartists | 0:6b68dac0d986 | 21 | |
embeddedartists | 0:6b68dac0d986 | 22 | /** |
embeddedartists | 17:4ea2509445ac | 23 | * Internal EEPROM Driver |
embeddedartists | 0:6b68dac0d986 | 24 | */ |
embeddedartists | 0:6b68dac0d986 | 25 | class InternalEEPROM { |
embeddedartists | 0:6b68dac0d986 | 26 | public: |
embeddedartists | 0:6b68dac0d986 | 27 | |
embeddedartists | 0:6b68dac0d986 | 28 | enum Constants { |
embeddedartists | 0:6b68dac0d986 | 29 | EEPROM_MEMORY_SIZE = 4032, |
embeddedartists | 0:6b68dac0d986 | 30 | EEPROM_PAGE_SIZE = 64, |
embeddedartists | 0:6b68dac0d986 | 31 | EEPROM_NUM_PAGES = EEPROM_MEMORY_SIZE/EEPROM_PAGE_SIZE, |
embeddedartists | 0:6b68dac0d986 | 32 | }; |
embeddedartists | 0:6b68dac0d986 | 33 | |
embeddedartists | 0:6b68dac0d986 | 34 | InternalEEPROM(); |
embeddedartists | 0:6b68dac0d986 | 35 | ~InternalEEPROM(); |
embeddedartists | 0:6b68dac0d986 | 36 | |
embeddedartists | 17:4ea2509445ac | 37 | /** Initializes the EEPROM |
embeddedartists | 0:6b68dac0d986 | 38 | * |
embeddedartists | 0:6b68dac0d986 | 39 | * @returns |
embeddedartists | 0:6b68dac0d986 | 40 | * Ok on success |
embeddedartists | 0:6b68dac0d986 | 41 | * An error code on failure |
embeddedartists | 0:6b68dac0d986 | 42 | */ |
embeddedartists | 0:6b68dac0d986 | 43 | void init(); |
embeddedartists | 0:6b68dac0d986 | 44 | |
embeddedartists | 34:fc366bab393f | 45 | /** Put the internal EEPROM in a low power state |
embeddedartists | 34:fc366bab393f | 46 | */ |
embeddedartists | 0:6b68dac0d986 | 47 | void powerDown(); |
embeddedartists | 0:6b68dac0d986 | 48 | |
embeddedartists | 34:fc366bab393f | 49 | /** Reads size bytes from offset addr |
embeddedartists | 34:fc366bab393f | 50 | * |
embeddedartists | 34:fc366bab393f | 51 | * Note that this function will power up the EEPROM so it is |
embeddedartists | 34:fc366bab393f | 52 | * recommended to call powerDown() when finished reading. |
embeddedartists | 34:fc366bab393f | 53 | * |
embeddedartists | 34:fc366bab393f | 54 | * @param addr the offset to read from |
embeddedartists | 34:fc366bab393f | 55 | * @param data buffer to store the read data in |
embeddedartists | 34:fc366bab393f | 56 | * @param size number of bytes to read |
embeddedartists | 34:fc366bab393f | 57 | * |
embeddedartists | 34:fc366bab393f | 58 | * @returns |
embeddedartists | 34:fc366bab393f | 59 | * The number of bytes read |
embeddedartists | 34:fc366bab393f | 60 | */ |
embeddedartists | 20:9df19da50290 | 61 | int read(uint32_t addr, uint8_t* data, uint32_t size); |
embeddedartists | 34:fc366bab393f | 62 | |
embeddedartists | 34:fc366bab393f | 63 | /** Writes size bytes to offset addr |
embeddedartists | 34:fc366bab393f | 64 | * |
embeddedartists | 34:fc366bab393f | 65 | * Note that this function will power up the EEPROM so it is |
embeddedartists | 34:fc366bab393f | 66 | * recommended to call powerDown() when finished writing. |
embeddedartists | 34:fc366bab393f | 67 | * |
embeddedartists | 34:fc366bab393f | 68 | * @param addr the offset to write to |
embeddedartists | 34:fc366bab393f | 69 | * @param data the data to write |
embeddedartists | 34:fc366bab393f | 70 | * @param size number of bytes to write |
embeddedartists | 34:fc366bab393f | 71 | * |
embeddedartists | 34:fc366bab393f | 72 | * @returns |
embeddedartists | 34:fc366bab393f | 73 | * The number of bytes written |
embeddedartists | 34:fc366bab393f | 74 | */ |
embeddedartists | 20:9df19da50290 | 75 | int write(uint32_t addr, const uint8_t* data, uint32_t size); |
embeddedartists | 0:6b68dac0d986 | 76 | |
embeddedartists | 0:6b68dac0d986 | 77 | /** Returns the size (in bytes) of the internal EEPROM |
embeddedartists | 0:6b68dac0d986 | 78 | * |
embeddedartists | 0:6b68dac0d986 | 79 | * @returns |
embeddedartists | 0:6b68dac0d986 | 80 | * The size in bytes |
embeddedartists | 0:6b68dac0d986 | 81 | */ |
embeddedartists | 0:6b68dac0d986 | 82 | uint32_t memorySize() { return EEPROM_MEMORY_SIZE; } |
embeddedartists | 0:6b68dac0d986 | 83 | |
embeddedartists | 0:6b68dac0d986 | 84 | private: |
embeddedartists | 0:6b68dac0d986 | 85 | |
embeddedartists | 0:6b68dac0d986 | 86 | bool _initialized; |
embeddedartists | 0:6b68dac0d986 | 87 | |
embeddedartists | 0:6b68dac0d986 | 88 | void powerUp(); |
embeddedartists | 0:6b68dac0d986 | 89 | void clearInterrupt(uint32_t mask); |
embeddedartists | 0:6b68dac0d986 | 90 | void waitForInterrupt(uint32_t mask); |
embeddedartists | 0:6b68dac0d986 | 91 | void setAddr(uint32_t pageAddr, uint32_t pageOffset); |
embeddedartists | 0:6b68dac0d986 | 92 | void setCmd(uint32_t cmd); |
embeddedartists | 0:6b68dac0d986 | 93 | void readPage(uint32_t pageAddr, uint32_t pageOffset, uint8_t* buf, uint32_t size); |
embeddedartists | 0:6b68dac0d986 | 94 | void writePage(uint32_t pageAddr, uint32_t pageOffset, const uint8_t* buf, uint32_t size); |
embeddedartists | 0:6b68dac0d986 | 95 | void eraseOrProgramPage(uint32_t pageAddr); |
embeddedartists | 0:6b68dac0d986 | 96 | }; |
embeddedartists | 0:6b68dac0d986 | 97 | |
embeddedartists | 0:6b68dac0d986 | 98 | #endif |