Subdirectory provided by Embedded Artists

Dependencies:   DM_FATFileSystem DM_HttpServer DM_USBHost EthernetInterface USBDevice mbed-rpc mbed-rtos mbed-src

Dependents:   lpc4088_displaymodule_hello_world_Sept_2018

Fork of DMSupport by Embedded Artists

Revision:
28:8ae20cb0b943
Parent:
27:0499c29688cc
Child:
29:b1ec19000e15
--- a/Bios/BiosLoader.cpp	Fri Jan 23 13:48:44 2015 +0100
+++ b/Bios/BiosLoader.cpp	Fri Jan 23 17:31:56 2015 +0100
@@ -20,6 +20,7 @@
 #include "BiosEEPROM.h"
 #include "crc.h"
 #include "bios.h"
+#include "meas.h"
 
 #if defined(DM_BOARD_BIOS_DEVELOPMENT)
   #ifdef __cplusplus
@@ -55,15 +56,47 @@
 #define SUPPORTED_BIOS_VER   0x000000
 #define SUPPORTED_BIOS_MASK  0xff0000  // only look at the Major component
 #define SUPPORTED_VERSION(__ver) (((__ver)&SUPPORTED_BIOS_MASK) == SUPPORTED_BIOS_VER)
-    
+
+#define MAC_IN_SDK
+
 /******************************************************************************
  * Local variables
  *****************************************************************************/
 
 /******************************************************************************
+ * Global functions
+ *****************************************************************************/
+
+#if !defined(MAC_IN_SDK)
+/* The LPC4088QSB platform in the MBED SDK have defined the WEAK function
+ * mbed_mac_address (ethernet_api.c) to read a unique MAC address from the
+ * onboard EEPROM.
+ * The LPC4088DM platform in the MBED SDK does not have the WEAK function
+ * so it is implemented here instead. This version of the function will ask
+ * the bios for a MAC address.
+ */
+void mbed_mac_address(char *mac) {
+  static char cache[6];
+  static bool haveIt = false;
+  if (!haveIt) {
+    BiosLoader::instance().getMacAddress(cache);
+    haveIt = true;
+  }
+  memcpy(mac, cache, 6);
+}
+#endif
+
+/******************************************************************************
  * Private Functions
  *****************************************************************************/
 
+// Called by the NVIC
+static void loader_i2c0_irq_handler()
+{
+  BiosLoader::instance().handleI2CInterrupt();
+}
+
+
 // Function called from the BIOS
 static uint32_t readTimeMs()
 {
@@ -196,6 +229,7 @@
         break;
       }
       
+#if defined(MAC_IN_SDK)
       // The BIOS has been read so we know that the I2C bus is working. After the
       // BIOS is "started" it will take ownership of the bus and it can cause
       // problems for other peripherals on it. The only other peripheral today
@@ -204,6 +238,7 @@
       // we prevent future access to the I2C bus.
       char mac[6] = {0};
       mbed_mac_address(mac);
+#endif
       
       // Extract the function pointers so that they can be modified to match the
       // actual location of the code
@@ -248,6 +283,11 @@
         err = DMBoard::BiosInvalidError;
         break;
       }
+
+      // Setup the mandatory I2C0 interrupt handler after initParams but before all other calls
+      NVIC_DisableIRQ(I2C0_IRQn);
+      NVIC_SetVector(I2C0_IRQn, (uint32_t)loader_i2c0_irq_handler);      
+      NVIC_EnableIRQ(I2C0_IRQn);
       
       _initialized = true;
     } while(0);
@@ -287,3 +327,34 @@
   }
   return false;
 }
+
+void BiosLoader::getMacAddress(char mac[6])
+{
+  if (!_initialized) {
+    init();
+  }
+  if (_initialized) {
+    BiosError_t err = _bios.ethernetMac(_biosData, mac);
+    if (err == BiosError_Ok) {
+      return;
+    }
+  }
+  
+  // We always consider the MAC address to be retrieved even though
+  // reading is failed. If it wasn't possible to read then the default
+  // address will be used.
+  mac[0] = 0x00;
+  mac[1] = 0x02;
+  mac[2] = 0xF7;
+  mac[3] = 0xF0;
+  mac[4] = 0x00;
+  mac[5] = 0x01;
+}
+
+void BiosLoader::handleI2CInterrupt()
+{
+  SET_MEAS_PIN_2();
+  _bios.i2cIRQHandler(_biosData);
+  CLR_MEAS_PIN_2();
+}
+