Statistics
| Branch: | Tag: | Revision:

amiro-os / include / amiro / FileSystemInputOutput / FileSystemInputOutputBase.hpp @ 309980f0

History | View | Annotate | Download (3.714 KB)

1 58fe0e0b Thomas Schöpping
#ifndef AMIRO_FILESYSTEMIO_H_
2
#define AMIRO_FILESYSTEMIO_H_
3
4
/*! \brief memory layouts for the eeproms
5
 *
6
 * This header defines the memory layout.
7
 * Every memory layout starts with a preamble
8
 * of 3 byte. The first one is a magic byte
9
 * for checking purpose. The second one declares
10
 * the byte structure major version (BSMV) and the third
11
 * the byte structure minor version (bsmv) of the subsequently
12
 * bytes in the memory. With different major versions, the
13
 * layout of the memory may totaly change, so one should
14
 * not read from such a different layout if the version
15
 * differs from the expected one. With greater minor
16
 * versions the old memory layout may not change, but
17
 * new elements emerge.
18
 */
19
20
#include <amiro/eeprom/at24.hpp>
21
22
namespace amiro {
23
namespace fileSystemIo {
24
25
class FileSystemIoBase {
26
27
  public:
28
    AT24 &at24c01;
29
    const uint8_t BSMV;
30
    const uint8_t bsmv;
31
    const uint8_t HMV;
32
    const uint8_t hmv;
33
    static constexpr uint8_t magicByteValue() { return 0xAAu;}
34
35
    // TODO implement CRC check at 0x7D to 0x80
36
    /** \brief Global memory structure */
37
    struct preamble_1_1 {
38
      uint8_t magicByte;
39
      uint8_t byteStructureMajorVersion;
40
      uint8_t byteStructureMinorVersion;
41
      uint8_t hardwareMajorVersion;
42
      uint8_t hardwareMinorVersion;
43
      uint8_t reserved_0x05_0x14[15];
44
    };
45
46
    struct preamble_1_2 {
47
      uint8_t reserved_0x00_0x04[5];
48
      uint8_t boardId;
49
      uint8_t reserved_0x06_0x14[14];
50
    };
51
52
    /** \brief FSIO return types */
53
    enum{
54
      OK                    = 0x00u,
55
      NOT_IMPLEMENTED       = 0x01u,
56
      WRONG_BSMV            = 0x02u,
57
      WRONG_bsmv            = 0x04u,
58
      IO_ERROR              = 0x08u,
59
      WRONG_MAGICBYTE_VALUE = 0x10u,
60
      WRONG_INDEX           = 0x20u,
61
      WRONG_HMV             = 0x40u,
62
      WRONG_hmv             = 0x80u,
63
    };
64
65
  public:
66
67
    FileSystemIoBase(AT24 &at24c01, uint8_t BSMV, uint8_t bsmv, uint8_t HMV, uint8_t hmv)
68
      : at24c01(at24c01),
69
        BSMV(BSMV),
70
        bsmv(bsmv),
71
        HMV(HMV),
72
        hmv(hmv) {
73
     }
74
75
    /**
76
     * \brief Checks the values stored in the memory and compares the set version numbers and the version numbers found.
77
     *        If the magic byte is incorrect WRONG_MAGICBYTE_VALUE is returned.
78
     *        If the BMSVs are not equal WRONG_BSMV is returned.
79
     *        If the bmsv found in the memory is smaller, the missing elements are initialized with default values and WRONG_bsmv is returned.
80
     *        If the bmsv found in the memory is equal or greater OK is returned.
81
     *        If the HMVs are not equal WRONG_HMV is returned.
82
     *        If the mmvs are not equal WRONG_hmv is returned.
83
     * @return FSIO return types
84
     */
85
    msg_t init();
86
87
    /**
88
     * \brief Check the memory structure
89
     * @return FSIO return types
90
     */
91
    msg_t getCheck();
92
93
    /**
94
     * @brief Initializes the memory of the given preamble with default values.
95
     * @param[in] BSMV The Byte Structure Major Version to initialize.
96
     * @param[in] bsvm The Byte Structure Minor Version to initialize.
97
     * @param[in] strict Specifies whether all (true) or only new (false) values are written to the memory.
98
     * @return FSIO return types
99
     */
100
    msg_t initPreamble(const uint8_t BSMV, const uint8_t bsmv, const bool strict = true);
101
102
    /**
103
     * \brief Initializes the memory with the given structure
104
     * @return FSIO return types
105
     */
106
    msg_t resetMemory();
107
108
    /**
109
     * \brief Writes the board id to the eeprom
110
     * @return FSIO return types
111
     */
112
    msg_t setBoardId (uint8_t buffer);
113
114
    /**
115
     * \brief Reads the board id from the eeprom
116
     * @return FSIO return types
117
     */
118
    msg_t getBoardId (uint8_t *buffer);
119
120
};
121
122
}
123
}
124
125
#endif /* AMIRO_FILESYSTEMIO_H_ */