mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Revision:
22:dbd009839d5e
Parent:
15:4892fe388435
Child:
29:6ac4027eff2b
--- a/targets/hal/TARGET_NXP/TARGET_LPC408X/ethernet_api.c	Wed Sep 11 16:54:00 2013 +0100
+++ b/targets/hal/TARGET_NXP/TARGET_LPC408X/ethernet_api.c	Fri Sep 13 14:22:58 2013 +0100
@@ -962,3 +962,47 @@
             break;
     }
 }
+
+/*
+ * The Embedded Artists LPC4088 QuickStart Board has an eeprom with a unique
+ * 48 bit ID. This ID is used as MAC address.
+ */
+
+#include "i2c_api.h"
+
+static int _macRetrieved = 0;
+static char _macAddr[6] = {0x00,0x02,0xF7,0xF0,0x00,0x00};
+#define EEPROM_24AA02E48_ADDR (0xA0)
+
+void mbed_mac_address(char *mac) {
+
+    if (_macRetrieved == 0) {
+        char tmp[6];
+        i2c_t i2cObj;
+
+        i2c_init(&i2cObj, P0_27, P0_28);
+
+        do {
+            // the unique ID is at offset 0xFA
+            tmp[0] = 0xFA;
+            if (i2c_write(&i2cObj, EEPROM_24AA02E48_ADDR, tmp, 1, 1) != 1) {
+                break; // failed to write
+            }
+
+
+            if (i2c_read(&i2cObj, EEPROM_24AA02E48_ADDR, tmp, 6, 1) != 6) {
+                break; // failed to read
+            }
+
+            memcpy(_macAddr, tmp, 6);
+
+        } while(0);
+
+        // We always consider the MAC address to be retrieved even though
+        // reading from the eeprom failed. If it wasn't possible to read
+        // from eeprom the default address will be used.
+        _macRetrieved = 1;
+    }
+
+    memcpy(mac, _macAddr, 6);
+}