fix for mbed lib issue 3 (i2c problem) see also https://mbed.org/users/mbed_official/code/mbed/issues/3 affected implementations: LPC812, LPC11U24, LPC1768, LPC2368, LPC4088

Fork of mbed-src by mbed official

Files at this revision

API Documentation at this revision

Comitter:
Shikaneo
Date:
Mon Aug 05 02:27:27 2013 +0000
Parent:
12:5fa2273de5db
Commit message:
equipped timeout

Changed in this revision

hal/i2c_api.h Show annotated file Show diff for this revision Revisions of this file
vendor/Freescale/KL25Z/hal/i2c_api.c Show annotated file Show diff for this revision Revisions of this file
vendor/NXP/LPC11U24/hal/i2c_api.c Show annotated file Show diff for this revision Revisions of this file
vendor/NXP/LPC1768/hal/i2c_api.c Show annotated file Show diff for this revision Revisions of this file
vendor/NXP/LPC2368/hal/i2c_api.c Show annotated file Show diff for this revision Revisions of this file
vendor/NXP/LPC4088/hal/i2c_api.c Show annotated file Show diff for this revision Revisions of this file
vendor/NXP/LPC812/hal/i2c_api.c Show annotated file Show diff for this revision Revisions of this file
diff -r 5fa2273de5db -r bd9ff402dd42 hal/i2c_api.h
--- a/hal/i2c_api.h	Wed Jul 24 11:11:21 2013 +0100
+++ b/hal/i2c_api.h	Mon Aug 05 02:27:27 2013 +0000
@@ -29,7 +29,7 @@
 void i2c_init         (i2c_t *obj, PinName sda, PinName scl);
 void i2c_frequency    (i2c_t *obj, int hz);
 int  i2c_start        (i2c_t *obj);
-void i2c_stop         (i2c_t *obj);
+int  i2c_stop         (i2c_t *obj);
 int  i2c_read         (i2c_t *obj, int address, char *data, int length, int stop);
 int  i2c_write        (i2c_t *obj, int address, const char *data, int length, int stop);
 void i2c_reset        (i2c_t *obj);
diff -r 5fa2273de5db -r bd9ff402dd42 vendor/Freescale/KL25Z/hal/i2c_api.c
--- a/vendor/Freescale/KL25Z/hal/i2c_api.c	Wed Jul 24 11:11:21 2013 +0100
+++ b/vendor/Freescale/KL25Z/hal/i2c_api.c	Mon Aug 05 02:27:27 2013 +0000
@@ -96,7 +96,7 @@
     return 0;
 }
 
-void i2c_stop(i2c_t *obj) {
+int i2c_stop(i2c_t *obj) {
     volatile uint32_t n = 0;
     obj->i2c->C1 &= ~I2C_C1_MST_MASK;
     obj->i2c->C1 &= ~I2C_C1_TX_MASK;
@@ -107,6 +107,7 @@
     // code provided with the freedom board
     for (n = 0; n < 100; n++) __NOP();
     first_read = 1;
+    return 0;
 }
 
 static int timeout_status_poll(i2c_t *obj, uint32_t mask) {
diff -r 5fa2273de5db -r bd9ff402dd42 vendor/NXP/LPC11U24/hal/i2c_api.c
--- a/vendor/NXP/LPC11U24/hal/i2c_api.c	Wed Jul 24 11:11:21 2013 +0100
+++ b/vendor/NXP/LPC11U24/hal/i2c_api.c	Mon Aug 05 02:27:27 2013 +0000
@@ -124,13 +124,18 @@
     return status;
 }
 
-inline void i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj) {
     // write the stop bit
     i2c_conset(obj, 0, 1, 0, 0);
     i2c_clear_SI(obj);
     
     // wait for STO bit to reset
-    while(I2C_CONSET(obj) & (1 << 4));
+    int timeout = 0;
+    while(I2C_CONSET(obj) & (1 << 4)){
+        timeout++;
+        if(timeout > 10000) return -1;
+    }
+    return 0;
 }
 
 
diff -r 5fa2273de5db -r bd9ff402dd42 vendor/NXP/LPC1768/hal/i2c_api.c
--- a/vendor/NXP/LPC1768/hal/i2c_api.c	Wed Jul 24 11:11:21 2013 +0100
+++ b/vendor/NXP/LPC1768/hal/i2c_api.c	Mon Aug 05 02:27:27 2013 +0000
@@ -133,13 +133,18 @@
     return status;
 }
 
-inline void i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj) {
     // write the stop bit
     i2c_conset(obj, 0, 1, 0, 0);
     i2c_clear_SI(obj);
     
     // wait for STO bit to reset
-    while(I2C_CONSET(obj) & (1 << 4));
+    int timeout = 0;
+    while(I2C_CONSET(obj) & (1 << 4)){
+        timeout++;
+        if(timeout > 10000) return -1;
+    }
+    return 0;
 }
 
 static inline int i2c_do_write(i2c_t *obj, int value, uint8_t addr) {
diff -r 5fa2273de5db -r bd9ff402dd42 vendor/NXP/LPC2368/hal/i2c_api.c
--- a/vendor/NXP/LPC2368/hal/i2c_api.c	Wed Jul 24 11:11:21 2013 +0100
+++ b/vendor/NXP/LPC2368/hal/i2c_api.c	Mon Aug 05 02:27:27 2013 +0000
@@ -133,13 +133,18 @@
     return status;
 }
 
-inline void i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj) {
     // write the stop bit
     i2c_conset(obj, 0, 1, 0, 0);
     i2c_clear_SI(obj);
     
     // wait for STO bit to reset
-    while (I2C_CONSET(obj) & (1 << 4));
+    int timeout = 0;
+    while (I2C_CONSET(obj) & (1 << 4)){
+        timeout++;
+        if(timeout > 10000) return -1;
+    }
+    return 0;
 }
 
 static inline int i2c_do_write(i2c_t *obj, int value, uint8_t addr) {
diff -r 5fa2273de5db -r bd9ff402dd42 vendor/NXP/LPC4088/hal/i2c_api.c
--- a/vendor/NXP/LPC4088/hal/i2c_api.c	Wed Jul 24 11:11:21 2013 +0100
+++ b/vendor/NXP/LPC4088/hal/i2c_api.c	Mon Aug 05 02:27:27 2013 +0000
@@ -144,13 +144,18 @@
     return status;
 }
 
-inline void i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj) {
     // write the stop bit
     i2c_conset(obj, 0, 1, 0, 0);
     i2c_clear_SI(obj);
     
     // wait for STO bit to reset
-    while(I2C_CONSET(obj) & (1 << 4));
+    int timeout = 0;
+    while(I2C_CONSET(obj) & (1 << 4)){
+        timeout++;
+        if(timeout > 10000) return -1;
+    }
+    return 0;
 }
 
 
diff -r 5fa2273de5db -r bd9ff402dd42 vendor/NXP/LPC812/hal/i2c_api.c
--- a/vendor/NXP/LPC812/hal/i2c_api.c	Wed Jul 24 11:11:21 2013 +0100
+++ b/vendor/NXP/LPC812/hal/i2c_api.c	Mon Aug 05 02:27:27 2013 +0000
@@ -87,9 +87,13 @@
     return status;
 }
 
-inline void i2c_stop(i2c_t *obj) {
+inline int i2c_stop(i2c_t *obj) {
     obj->i2c->MSTCTL = (1 << 2) | (1 << 0);
-    while ((obj->i2c->STAT & ((1 << 0) | (7 << 1))) != ((1 << 0) | (0 << 1)));
+    while ((obj->i2c->STAT & ((1 << 0) | (7 << 1))) != ((1 << 0) | (0 << 1))){
+        timeout++;
+        if(timeout > 10000) return -1;
+    }
+    return 0;
 }