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
Revision 2:514105beb343, committed 2013-04-14
- Comitter:
- humlet
- Date:
- Sun Apr 14 21:42:22 2013 +0000
- Parent:
- 1:90455d5bdd8c
- Child:
- 3:967dde37e712
- Commit message:
- seems to work
Changed in this revision
--- a/I2CDriver.cpp Sun Apr 14 06:39:04 2013 +0000 +++ b/I2CDriver.cpp Sun Apr 14 21:42:22 2013 +0000 @@ -4,7 +4,7 @@ using namespace mbed; using namespace rtos; -#define ISR2DRV_SIG (1<<7) +#define I2C_ISR_DRV_SIG (1<<7) #define DRV_USR_SIG (1<<6) const PinName I2CDriver::c_sdas[] = {p9,p28}; @@ -15,14 +15,14 @@ void I2CDriver::channel_0_ISR() { - osSignalSet( s_channels[0]->driver, ISR2DRV_SIG); + osSignalSet( s_channels[0]->driver, I2C_ISR_DRV_SIG); NVIC_DisableIRQ(I2C1_IRQn); } void I2CDriver::channel_1_ISR() { - osSignalSet( s_channels[1]->driver, ISR2DRV_SIG); + osSignalSet( s_channels[1]->driver, I2C_ISR_DRV_SIG); #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) NVIC_DisableIRQ(I2C2_IRQn); #elif defined(TARGET_LPC11U24) @@ -36,15 +36,17 @@ int channelIdx = (int)args; Channel channel; s_channels[channelIdx] = &channel; + channel.driver = Thread::gettid(); - channel.driver = Thread::gettid(); #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) if(channelIdx==0)NVIC_SetVector(I2C1_IRQn, (uint32_t)I2CDriver::channel_0_ISR); if(channelIdx==1)NVIC_SetVector(I2C2_IRQn, (uint32_t)I2CDriver::channel_1_ISR); #elif defined(TARGET_LPC11U24) NVIC_SetVector(I2C_IRQn, (uint32_t)I2CDriver::channel_1_ISR); #endif + I2C i2c(c_sdas[channelIdx], c_scls[channelIdx]); + volatile Transfer& tr = channel.transfer; while(1) { // wait for requests @@ -98,6 +100,7 @@ #endif if (sda==c_sdas[1] && scl==c_scls[1]) channel=1; //I2C_2 or I2C else error("I2CDriver: Invalid I2C pinns selected"); + if(s_channels[channel]==0) new Thread(threadFun,(void *)channel,osPriorityRealtime); m_channel = s_channels[channel];
--- a/I2CDriver.h Sun Apr 14 06:39:04 2013 +0000 +++ b/I2CDriver.h Sun Apr 14 21:42:22 2013 +0000 @@ -86,14 +86,14 @@ 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); } /// Unlock the driver that has previously been locked by the same thread - void unlock() { + void unlock() { m_channel->mutex.unlock(); } @@ -134,9 +134,9 @@ 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();
--- a/mbed-NXP.lib Sun Apr 14 06:39:04 2013 +0000 +++ b/mbed-NXP.lib Sun Apr 14 21:42:22 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-NXP/#102159096554 +http://mbed.org/users/mbed_official/code/mbed-NXP/#09117a22982e