I2CRTOS Driver by Helmut Schmücker. Removed included mbed-rtos library to prevent multiple definition. Make sure to include mbed-rtos library in your program!
Fork of I2cRtosDriver by
Diff: I2CDriver.h
- Revision:
- 1:90455d5bdd8c
- Parent:
- 0:13c962fecb13
- Child:
- 2:514105beb343
diff -r 13c962fecb13 -r 90455d5bdd8c I2CDriver.h --- a/I2CDriver.h Sat Apr 13 13:37:29 2013 +0000 +++ b/I2CDriver.h Sun Apr 14 06:39:04 2013 +0000 @@ -26,12 +26,6 @@ */ I2CDriver(PinName sda, PinName scl); - /** Set the frequency of the I2C interface - * - * @param hz The bus frequency in hertz - */ - void frequency(int hz); - /** Read from an I2C slave * * Performs a complete read transaction. The bottom bit of @@ -48,6 +42,8 @@ */ int read(int address, char *data, int length, bool repeated = false); + int read(int address, uint8_t regist, char *data, int length, bool repeated = false); + /** Read a single byte from the I2C bus * * @param ack indicates if the byte is to be acknowledged (1 = acknowledge) @@ -90,15 +86,15 @@ void stop(void); /// Wait until the i2c driver becomes available. - void lock() { + void lock() { // if one and the same thread can lock twice, but then it needs also to unlock twice. // exactly what we need here - m_channel.mutex.lock(osWaitForever); + m_channel->mutex.lock(osWaitForever); } /// Unlock the driver that has previously been locked by the same thread - void osStatus unlock() { - m_channel.mutex.unlock(osWaitForever); + void unlock() { + m_channel->mutex.unlock(); } @@ -112,41 +108,43 @@ READ_BYTE, READ, READ_FROM_REGISTER - } + }; struct Transfer { + osThreadId caller; Command cmd; int freq; int adr; - int reg; + uint8_t reg; char* dta; + const char* wdta; int len; + int ack; bool rep; - int res; - } + int ret; + }; struct Channel { - osThreadId caller; - osThreadId driver; - Mutex mutex; - Transfer transfer; - int freq; - } + volatile osThreadId driver; + rtos::Mutex mutex; + volatile Transfer transfer; + volatile int freq; + }; - static const PinName c_sda[]= {p9,p28}; - static const PinName c_scl[]= {p10,p27}; + static const PinName c_sdas[2]; + static const PinName c_scls[2]; - static Channel* s_channels[2]; + static Channel* s_channels[2]; - Channel& m_channel; + Channel* m_channel; static void channel_0_ISR(); static void channel_1_ISR(); - static void threadFun(void* const args); + static void threadFun(void const *args); void sendNwait(); -} +}; } #endif