Statistics
| Branch: | Tag: | Revision:

amiro-os / include / amiro / eeprom / eeprom.hpp @ 2af9778e

History | View | Annotate | Download (1.623 KB)

1
#ifndef EEPROM_HPP_
2
#define EEPROM_HPP_
3

    
4
#include <ch.hpp>
5
#include <hal.h>
6

    
7
#include <amiro/bus/i2c/I2CParams.hpp>
8

    
9
namespace amiro {
10

    
11
class I2CDriver;
12
class HWSPIDriver;
13

    
14
class EEPROM {
15

    
16
  public:
17
    /**
18
     * Base File Stream
19
     * eepromInit initializes this member.
20
     */
21
    BaseFileStream bfs;
22

    
23
    msg_t error;
24
    fileoffset_t position;
25

    
26
    size_t size;
27
    uint8_t page_size;
28

    
29
    /**
30
     * Maximum Write Cycle time
31
     * Expressed in multiples of 10 µs.
32
     */
33
    uint16_t max_t_wr;
34

    
35
    union {
36

    
37
#if HAL_USE_I2C
38
      struct {
39
        I2CDriver* i2c_driver;
40
        I2CTxParams i2c_txparams;
41
      };
42
#endif /* HAL_USE_I2C */
43

    
44
#if HAL_USE_SPI
45
      struct {
46
        HWSPIDriver* spi_driver;
47
      };
48
#endif /* HAL_USE_SPI */
49

    
50
    }; /* union */
51

    
52
#if CH_USE_MUTEXES
53
    /**
54
     * Mutex Lock
55
     */
56
    Mutex mutex;
57
#elif CH_USE_SEMAPHORES
58
    /**
59
     * Semaphore
60
     */
61
    Semaphore semaphore;
62
#endif
63

    
64
    enum {
65
      EEPROM_ERROR_NONE = 0x00u,
66
    };
67

    
68
  protected:
69

    
70
#if HAL_USE_I2C
71
    EEPROM(const struct BaseFileStreamVMT* vmt, size_t size, uint8_t page_size, uint16_t max_t_wr, uint8_t sla, I2CDriver* i2c_driver);
72
#endif /* HAL_USE_I2C */
73
#if HAL_USE_SPI
74
    EEPROM(const struct BaseFileStreamVMT* vmt, size_t size, uint8_t page_size, uint16_t max_t_wr, HWSPIDriver* spi_driver);
75
#endif /* HAL_USE_SPI */
76
    ~EEPROM();
77

    
78
  public:
79

    
80
    void acquire();
81
    void release();
82

    
83
    static int geterror(void* instance);
84
    static fileoffset_t getsize(void* instance);
85
    static fileoffset_t getposition(void* instance);
86
    static fileoffset_t lseek(void *instance, fileoffset_t offset);
87

    
88
};
89

    
90
} /* amiro */
91

    
92
#endif /* EEPROM_HPP_ */