Dependencies:   DM_FATFileSystem EthernetInterface HTTPClient mbed-rtos mbed-src

Fork of DMSupport by Embedded Artists

Committer:
embeddedartists
Date:
Fri Nov 21 11:42:51 2014 +0000
Revision:
0:6b68dac0d986
Child:
17:4ea2509445ac
First version

Who changed what in which revision?

UserRevisionLine numberNew 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 0:6b68dac0d986 23 * Internal EEPROM Example
embeddedartists 0:6b68dac0d986 24 *
embeddedartists 0:6b68dac0d986 25 * @code
embeddedartists 0:6b68dac0d986 26 * #include "mbed.h"
embeddedartists 0:6b68dac0d986 27 * #include "InternalEEPROM.h"
embeddedartists 0:6b68dac0d986 28 *
embeddedartists 0:6b68dac0d986 29 * int main(void) {
embeddedartists 0:6b68dac0d986 30 * InternalEEPROM mem;
embeddedartists 0:6b68dac0d986 31 *
embeddedartists 0:6b68dac0d986 32 * err = SPIFI::instance().init();
embeddedartists 0:6b68dac0d986 33 * if (err != SPIFI::Ok) {
embeddedartists 0:6b68dac0d986 34 * printf("Failed to initialize SPIFI, error %d\n", err);
embeddedartists 0:6b68dac0d986 35 * }
embeddedartists 0:6b68dac0d986 36 *
embeddedartists 0:6b68dac0d986 37 * // Write "Hello World!" into the first bytes of the SPIFI
embeddedartists 0:6b68dac0d986 38 * char buff[20] = "Hello World!";
embeddedartists 0:6b68dac0d986 39 * err = SPIFI::instance().program(0, strlen(buff)+1, buff, SPIFI::EraseAsRequired);
embeddedartists 0:6b68dac0d986 40 * if (err != SPIFI::Ok) {
embeddedartists 0:6b68dac0d986 41 * printf("Failed to write to SPIFI, error %d\n", err);
embeddedartists 0:6b68dac0d986 42 * }
embeddedartists 0:6b68dac0d986 43 *
embeddedartists 0:6b68dac0d986 44 * // Now verify that it can be read
embeddedartists 0:6b68dac0d986 45 * if (memcmp((char*)SPIFI::SpifiMemBase, buff, strlen(buff)+1) == 0) {
embeddedartists 0:6b68dac0d986 46 * printf("Readback from memory OK: '%s'\n", SPIFI::SpifiMemBase);
embeddedartists 0:6b68dac0d986 47 * } else {
embeddedartists 0:6b68dac0d986 48 * printf("Spifi does not contain the correct data!\n");
embeddedartists 0:6b68dac0d986 49 * }
embeddedartists 0:6b68dac0d986 50 * }
embeddedartists 0:6b68dac0d986 51 * @endcode
embeddedartists 0:6b68dac0d986 52 */
embeddedartists 0:6b68dac0d986 53 class InternalEEPROM {
embeddedartists 0:6b68dac0d986 54 public:
embeddedartists 0:6b68dac0d986 55
embeddedartists 0:6b68dac0d986 56 enum Constants {
embeddedartists 0:6b68dac0d986 57 EEPROM_MEMORY_SIZE = 4032,
embeddedartists 0:6b68dac0d986 58 EEPROM_PAGE_SIZE = 64,
embeddedartists 0:6b68dac0d986 59 EEPROM_NUM_PAGES = EEPROM_MEMORY_SIZE/EEPROM_PAGE_SIZE,
embeddedartists 0:6b68dac0d986 60 };
embeddedartists 0:6b68dac0d986 61
embeddedartists 0:6b68dac0d986 62 InternalEEPROM();
embeddedartists 0:6b68dac0d986 63 ~InternalEEPROM();
embeddedartists 0:6b68dac0d986 64
embeddedartists 0:6b68dac0d986 65 /** Initializes the SPIFI ROM driver making the content of the external serial flash available
embeddedartists 0:6b68dac0d986 66 *
embeddedartists 0:6b68dac0d986 67 * @returns
embeddedartists 0:6b68dac0d986 68 * Ok on success
embeddedartists 0:6b68dac0d986 69 * An error code on failure
embeddedartists 0:6b68dac0d986 70 */
embeddedartists 0:6b68dac0d986 71 void init();
embeddedartists 0:6b68dac0d986 72
embeddedartists 0:6b68dac0d986 73 void powerDown();
embeddedartists 0:6b68dac0d986 74
embeddedartists 0:6b68dac0d986 75 int read(uint32_t pageAddr, uint32_t pageOffset, uint8_t* data, uint32_t size);
embeddedartists 0:6b68dac0d986 76 int write(uint32_t pageAddr, uint32_t pageOffset, const uint8_t* data, uint32_t size);
embeddedartists 0:6b68dac0d986 77 void erasePage(uint32_t pageAddr);
embeddedartists 0:6b68dac0d986 78
embeddedartists 0:6b68dac0d986 79 /** Returns the size (in bytes) of the internal EEPROM
embeddedartists 0:6b68dac0d986 80 *
embeddedartists 0:6b68dac0d986 81 * @returns
embeddedartists 0:6b68dac0d986 82 * The size in bytes
embeddedartists 0:6b68dac0d986 83 */
embeddedartists 0:6b68dac0d986 84 uint32_t memorySize() { return EEPROM_MEMORY_SIZE; }
embeddedartists 0:6b68dac0d986 85
embeddedartists 0:6b68dac0d986 86 /** Returns the size of a page (in bytes) of the internal EEPROM
embeddedartists 0:6b68dac0d986 87 *
embeddedartists 0:6b68dac0d986 88 * @returns
embeddedartists 0:6b68dac0d986 89 * The page size in bytes
embeddedartists 0:6b68dac0d986 90 */
embeddedartists 0:6b68dac0d986 91 uint32_t pageSize() { return EEPROM_PAGE_SIZE; }
embeddedartists 0:6b68dac0d986 92
embeddedartists 0:6b68dac0d986 93 /** Returns the number of pages in the internal EEPROM
embeddedartists 0:6b68dac0d986 94 *
embeddedartists 0:6b68dac0d986 95 * @returns
embeddedartists 0:6b68dac0d986 96 * The number of pages
embeddedartists 0:6b68dac0d986 97 */
embeddedartists 0:6b68dac0d986 98 uint32_t numPages() { return EEPROM_NUM_PAGES; }
embeddedartists 0:6b68dac0d986 99
embeddedartists 0:6b68dac0d986 100 private:
embeddedartists 0:6b68dac0d986 101
embeddedartists 0:6b68dac0d986 102 bool _initialized;
embeddedartists 0:6b68dac0d986 103
embeddedartists 0:6b68dac0d986 104 void powerUp();
embeddedartists 0:6b68dac0d986 105 void clearInterrupt(uint32_t mask);
embeddedartists 0:6b68dac0d986 106 void waitForInterrupt(uint32_t mask);
embeddedartists 0:6b68dac0d986 107 void setAddr(uint32_t pageAddr, uint32_t pageOffset);
embeddedartists 0:6b68dac0d986 108 void setCmd(uint32_t cmd);
embeddedartists 0:6b68dac0d986 109 void readPage(uint32_t pageAddr, uint32_t pageOffset, uint8_t* buf, uint32_t size);
embeddedartists 0:6b68dac0d986 110 void writePage(uint32_t pageAddr, uint32_t pageOffset, const uint8_t* buf, uint32_t size);
embeddedartists 0:6b68dac0d986 111 void eraseOrProgramPage(uint32_t pageAddr);
embeddedartists 0:6b68dac0d986 112 };
embeddedartists 0:6b68dac0d986 113
embeddedartists 0:6b68dac0d986 114 #endif