1 | // %flair:license{
|
---|
2 | // This file is part of the Flair framework distributed under the
|
---|
3 | // CECILL-C License, Version 1.0.
|
---|
4 | // %flair:license}
|
---|
5 | /*!
|
---|
6 | * \file I2cPort.h
|
---|
7 | * \brief Base class for i2c port
|
---|
8 | * \author Guillaume Sanahuja, Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
9 | * \date 2014/04/24
|
---|
10 | * \version 4.0
|
---|
11 | */
|
---|
12 |
|
---|
13 | #ifndef I2CPORT_H
|
---|
14 | #define I2CPORT_H
|
---|
15 |
|
---|
16 | #include <Mutex.h>
|
---|
17 | #include <stdint.h>
|
---|
18 |
|
---|
19 | namespace flair
|
---|
20 | {
|
---|
21 | namespace core
|
---|
22 | {
|
---|
23 | /*! \class I2cPort
|
---|
24 | *
|
---|
25 | * \brief Base class for i2c port
|
---|
26 | *
|
---|
27 | * This class has a Mutex which must be used to protect access to the port in case
|
---|
28 | * that more than one Thread is using it. Lock the Mutex before any communication (including SetSlave)
|
---|
29 | * and release it after communication.
|
---|
30 | */
|
---|
31 | class I2cPort: public Mutex
|
---|
32 | {
|
---|
33 | public:
|
---|
34 | /*!
|
---|
35 | * \brief Constructor
|
---|
36 | *
|
---|
37 | * Construct an i2c port.
|
---|
38 | *
|
---|
39 | * \param parent parent
|
---|
40 | * \param name name
|
---|
41 | */
|
---|
42 | I2cPort(const Object* parent,std::string name): Mutex(parent,name)
|
---|
43 | {}
|
---|
44 |
|
---|
45 | /*!
|
---|
46 | * \brief Destructor
|
---|
47 | *
|
---|
48 | */
|
---|
49 | ~I2cPort(){};
|
---|
50 |
|
---|
51 | /*!
|
---|
52 | * \brief Set slave's address
|
---|
53 | *
|
---|
54 | * This function need to be called before any communication.
|
---|
55 | *
|
---|
56 | * \param address slave's address
|
---|
57 | */
|
---|
58 | virtual int SetSlave(uint16_t address)=0;
|
---|
59 |
|
---|
60 | /*!
|
---|
61 | * \brief Write datas
|
---|
62 | *
|
---|
63 | * \param buf pointer to datas
|
---|
64 | * \param nbyte length of datas
|
---|
65 | *
|
---|
66 | * \return amount of written datas
|
---|
67 | */
|
---|
68 | virtual ssize_t Write(const void *buf,size_t nbyte)=0;
|
---|
69 |
|
---|
70 | /*!
|
---|
71 | * \brief Read datas
|
---|
72 | *
|
---|
73 | * \param buf pointer to datas
|
---|
74 | * \param nbyte length of datas
|
---|
75 | *
|
---|
76 | * \return amount of read datas
|
---|
77 | */
|
---|
78 | virtual ssize_t Read(void *buf,size_t nbyte)=0;
|
---|
79 |
|
---|
80 | /*!
|
---|
81 | * \brief Set RX timeout
|
---|
82 | *
|
---|
83 | * Timeout for waiting an ACK from the slave.
|
---|
84 | *
|
---|
85 | * \param timeout_ns timeout in nano second
|
---|
86 | */
|
---|
87 | virtual void SetRxTimeout(Time timeout_ns)=0;
|
---|
88 |
|
---|
89 | /*!
|
---|
90 | * \brief Set TX timeout
|
---|
91 | *
|
---|
92 | * Timeout for waiting an ACK from the slave.
|
---|
93 | *
|
---|
94 | * \param timeout_ns timeout in nano second
|
---|
95 | */
|
---|
96 | virtual void SetTxTimeout(Time timeout_ns)=0;
|
---|
97 |
|
---|
98 | };
|
---|
99 | } // end namespace core
|
---|
100 | } // end namespace framework
|
---|
101 |
|
---|
102 | #endif // I2CPORT_H
|
---|