500KB USB mass storage
Dependencies: mbed EEPROM USBDevice
bbt_eeprom.h@1:49963e1662d6, 2021-02-09 (annotated)
- Committer:
- muraguchi
- Date:
- Tue Feb 09 12:02:52 2021 +0000
- Revision:
- 1:49963e1662d6
- Parent:
- 0:1472308ded03
Initial release
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
muraguchi | 0:1472308ded03 | 1 | #include "mbed.h" |
muraguchi | 0:1472308ded03 | 2 | #include "EEPROM.h" |
muraguchi | 0:1472308ded03 | 3 | |
muraguchi | 0:1472308ded03 | 4 | #ifndef BBT_EEPROM_H |
muraguchi | 0:1472308ded03 | 5 | #define BBT_EEPROM_H |
muraguchi | 0:1472308ded03 | 6 | |
muraguchi | 0:1472308ded03 | 7 | #define BBT_EEPROM_SLOT_LENGTH 20 |
muraguchi | 0:1472308ded03 | 8 | #define BBT_EEPROM_SLOT_SIZE 2 |
muraguchi | 0:1472308ded03 | 9 | #define BBT_EEPROM_STATUS_ADDR 0 |
muraguchi | 0:1472308ded03 | 10 | #define BBT_EEPROM_TEMPSLOT_ADDR 1 |
muraguchi | 0:1472308ded03 | 11 | #define BBT_EEPROM_SLOT_BASE_ADDR 2 |
muraguchi | 0:1472308ded03 | 12 | |
muraguchi | 0:1472308ded03 | 13 | |
muraguchi | 0:1472308ded03 | 14 | class bbt_eeprom { |
muraguchi | 0:1472308ded03 | 15 | public: |
muraguchi | 0:1472308ded03 | 16 | bbt_eeprom(uint16_t offsetReservedBlockAddress); |
muraguchi | 0:1472308ded03 | 17 | uint8_t getStatus_EEP(); |
muraguchi | 0:1472308ded03 | 18 | void setStatus_EEP(uint8_t status); |
muraguchi | 0:1472308ded03 | 19 | void clearAllSlot_EEP(); |
muraguchi | 0:1472308ded03 | 20 | void setSlot_EEP(uint8_t slot, uint8_t broken, uint8_t used,uint16_t blockAddress); |
muraguchi | 0:1472308ded03 | 21 | void getSlot_EEP(uint8_t slot, uint8_t * broken, uint8_t * used, uint16_t * blockAddress); |
muraguchi | 0:1472308ded03 | 22 | |
muraguchi | 0:1472308ded03 | 23 | // Reserved Block Address <-> Slot translation |
muraguchi | 0:1472308ded03 | 24 | uint16_t slotToReservedBlockAddress(uint8_t slot); |
muraguchi | 0:1472308ded03 | 25 | uint8_t reservedBlockAddressToSlot(uint16_t reservedBlockAddress); |
muraguchi | 0:1472308ded03 | 26 | |
muraguchi | 0:1472308ded03 | 27 | // get not broken not used slot |
muraguchi | 0:1472308ded03 | 28 | uint8_t getFreeSlot_EEP(); |
muraguchi | 0:1472308ded03 | 29 | |
muraguchi | 0:1472308ded03 | 30 | // build ram bbt table |
muraguchi | 0:1472308ded03 | 31 | void updateTranslateTable(); |
muraguchi | 0:1472308ded03 | 32 | |
muraguchi | 0:1472308ded03 | 33 | |
muraguchi | 0:1472308ded03 | 34 | // get translated block address |
muraguchi | 0:1472308ded03 | 35 | uint16_t getTranslatedBlockAddress(uint16_t blockAddress); |
muraguchi | 0:1472308ded03 | 36 | |
muraguchi | 0:1472308ded03 | 37 | void setTempSlot_EEP(uint8_t tempSlot); |
muraguchi | 0:1472308ded03 | 38 | uint8_t getTempSlot_EEP(); |
muraguchi | 0:1472308ded03 | 39 | void incrTempSlot_EEP(); |
muraguchi | 0:1472308ded03 | 40 | |
muraguchi | 0:1472308ded03 | 41 | // build ram temp value |
muraguchi | 0:1472308ded03 | 42 | void updateTempSlot(); |
muraguchi | 0:1472308ded03 | 43 | |
muraguchi | 0:1472308ded03 | 44 | void setTempSlot(uint8_t tempSlot); |
muraguchi | 0:1472308ded03 | 45 | uint8_t getTempSlot(); |
muraguchi | 0:1472308ded03 | 46 | |
muraguchi | 0:1472308ded03 | 47 | bool isReservedBlockAddress(uint16_t blockAddress); |
muraguchi | 0:1472308ded03 | 48 | |
muraguchi | 0:1472308ded03 | 49 | uint8_t get(uint16_t address); |
muraguchi | 0:1472308ded03 | 50 | void put(uint16_t address,uint8_t data); |
muraguchi | 0:1472308ded03 | 51 | |
muraguchi | 0:1472308ded03 | 52 | protected: |
muraguchi | 0:1472308ded03 | 53 | EEPROM m_eeprom; |
muraguchi | 0:1472308ded03 | 54 | uint16_t m_offsetReservedBlockAddress; |
muraguchi | 0:1472308ded03 | 55 | uint16_t m_translateTableFrom[BBT_EEPROM_SLOT_LENGTH]; |
muraguchi | 0:1472308ded03 | 56 | uint16_t m_translateTableTo[BBT_EEPROM_SLOT_LENGTH]; |
muraguchi | 0:1472308ded03 | 57 | int m_translateTableMaxIndex; |
muraguchi | 0:1472308ded03 | 58 | uint8_t m_tempSlot; |
muraguchi | 0:1472308ded03 | 59 | }; |
muraguchi | 0:1472308ded03 | 60 | |
muraguchi | 0:1472308ded03 | 61 | |
muraguchi | 0:1472308ded03 | 62 | #endif |