Statistics
| Branch: | Tag: | Revision:

amiro-os / components / bus / i2c / I2CMultiplexer.cpp @ 552936c8

History | View | Annotate | Download (1.015 KB)

1
#include <amiro/bus/i2c/I2CMultiplexer.hpp>
2

    
3
namespace amiro {
4

    
5
I2CMultiplexer::
6
I2CMultiplexer(I2CDriver *driver) :
7
  driver(driver) {
8

    
9
#if CH_USE_MUTEXES
10
  chMtxInit(&this->mutex);
11
#else
12
  chSemInit(&this->semaphore, 1);
13
#endif /* CH_USE_MUTEXES */
14

    
15
};
16

    
17
I2CMultiplexer::
18
~I2CMultiplexer() {
19

    
20
}
21

    
22
i2cflags_t
23
I2CMultiplexer::
24
getErrors() {
25

    
26
  return this->driver->getErrors();
27

    
28
}
29

    
30
msg_t
31
I2CMultiplexer::
32
masterTransmit(const I2CTxParams *params, systime_t timeout) {
33

    
34
  return this->driver->masterTransmit(params, timeout);
35

    
36
}
37

    
38
msg_t
39
I2CMultiplexer::
40
masterReceive(const I2CRxParams *params, systime_t timeout) {
41

    
42
  return this->driver->masterReceive(params, timeout);
43

    
44
}
45

    
46
void
47
I2CMultiplexer::
48
acquireBus() {
49

    
50
#if CH_USE_MUTEXES
51
  chMtxLock(&this->mutex);
52
#elif CH_USE_SEMAPHORES
53
  chSemWait(&this->semaphore);
54
#endif
55

    
56
  this->driver->acquireBus();
57
}
58

    
59
void
60
I2CMultiplexer::
61
releaseBus() {
62

    
63
  this->driver->releaseBus();
64

    
65
#if CH_USE_MUTEXES
66
  chMtxUnlock();
67
#elif CH_USE_SEMAPHORES
68
  chSemSignal(&this->semaphore);
69
#endif
70

    
71
}
72

    
73
} /* amiro */