Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed-rtos mbed-src
Diff: I2CDriver.cpp
- Revision:
- 8:5be85bd4c5ba
- Parent:
- 7:04824382eafb
--- a/I2CDriver.cpp Sun Apr 28 15:08:04 2013 +0000
+++ b/I2CDriver.cpp Tue Apr 30 19:12:57 2013 +0000
@@ -2,12 +2,15 @@
#include "i2c_api.h"
#include "error.h"
-#include "DigitalOut.h"
-
using namespace mbed;
using namespace rtos;
-DigitalOut osci(p12);
+extern "C"{
+osSemaphoreId i2cIsrDrvSem_1;
+osSemaphoreDef(i2cIsrDrvSem_1);
+osSemaphoreId i2cIsrDrvSem_2;
+osSemaphoreDef(i2cIsrDrvSem_2);
+}
#define DRV_USR_SIG (1<<6)
@@ -19,23 +22,19 @@
#if defined(TARGET_LPC1768)
void I2CDriver::channel_0_ISR()
{
- osci.write(1);
- osSignalSet( s_channels[0]->driver, I2C_ISR_DRV_SIG);
+ osSemaphoreRelease(i2cIsrDrvSem_1);
NVIC_DisableIRQ(I2C1_IRQn);
- osci.write(0);
}
#endif
void I2CDriver::channel_1_ISR()
{
- osci.write(1);
- osSignalSet( s_channels[1]->driver, I2C_ISR_DRV_SIG);
+ osSemaphoreRelease(i2cIsrDrvSem_2);
#if defined(TARGET_LPC1768) || defined(TARGET_LPC2368)
NVIC_DisableIRQ(I2C2_IRQn);
#elif defined(TARGET_LPC11U24)
NVIC_DisableIRQ(I2C_IRQn);
#endif
- osci.write(0);
}
@@ -50,8 +49,16 @@
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)
+ if(s_channels[channel]==0){
new Thread(threadFun,(void *)channel,osPriorityRealtime,256);
+ if(channel==0){
+ i2cIsrDrvSem_1 = osSemaphoreCreate(osSemaphore(i2cIsrDrvSem_1), 1);
+ osSemaphoreWait(i2cIsrDrvSem_1,osWaitForever);
+ }else{
+ i2cIsrDrvSem_2 = osSemaphoreCreate(osSemaphore(i2cIsrDrvSem_2), 1);
+ osSemaphoreWait(i2cIsrDrvSem_2,osWaitForever);
+ }
+ }
m_channel = s_channels[channel];
}