This program can detect the type(mbed or LPCXpresso) of platform. The sample recognizes mbed or LPCXpresso.

Dependencies:   mbed

This program detects the LPCXpresso and mbed at run time.

There is a difference in the value of the CoreDebugRegister LPCXpresso and mbed.

The program check those bits and select platform type.

#include "mbed.h"
#include "PlatformInfo.h"
DigitalOut mbedled(LED1);
DigitalOut lpcxled(P0_22);
using namespace MiMic;
int main(){
    switch(PlatformInfo::getPlatformType()){
    case PlatformInfo::PF_MBED:
        while(1) {
            mbedled = 1;
            wait(0.2);
            mbedled = 0;
            wait(0.2);
        }
    case PlatformInfo::PF_LPCXPRESSO:
        while(1) {
            lpcxled = 1;
            wait(0.1);
            lpcxled = 0;
            wait(0.1);
        }
    }    
}

If program run on mbed, LED1(blue) will be blinking. If it run on LPCXpresso, LED2(red) will be blinking.

Files at this revision

API Documentation at this revision

Comitter:
nyatla
Date:
Sun May 05 11:29:12 2013 +0000
Commit message:
Sample of platform detection

Changed in this revision

PlatformInfo.cpp Show annotated file Show diff for this revision Revisions of this file
PlatformInfo.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PlatformInfo.cpp	Sun May 05 11:29:12 2013 +0000
@@ -0,0 +1,47 @@
+#include "PlatformInfo.h"
+#define REG_HCSR 0xe000edf0
+#define REG_DEMCR 0xE000EDFC
+
+#include "mbed.h"
+namespace MiMic
+{
+    int PlatformInfo::_pftype=PF_UNKNOWN;
+    void PlatformInfo::check()
+    {
+    #if PlatformInfo_DETECTION_MODE==PlatformInfo_DETECTION_MODE_MBED
+        _pftype=PF_MBED;
+        return;
+    #elif PlatformInfo_DETECTION_MODE==PlatformInfo_DETECTION_MODE_LPCXPRESSO
+        _pftype=PF_LPCXPRESSO;
+        return;
+    #elif PlatformInfo_DETECTION_MODE==PlatformInfo_DETECTION_MODE_AUTO
+        //LPCXpresso is return S_RESET_ST==1 when standalone.
+        wait_ms(200);
+        unsigned int v;
+        v=*(unsigned int*)REG_HCSR;
+        //check Debug Halting Control and Status::S_RESET_ST sticky bit
+        if((v & 0x02000000)!=0){
+            //may be LPC-Standalone
+            _pftype=PF_LPCXPRESSO;        
+            return;
+        }
+        v=(*(unsigned int*)REG_DEMCR);
+        if((v & 0x01000000)==0x0){
+            //may be mbed
+            _pftype=PF_MBED;
+            return;
+        }
+        _pftype=PF_LPCXPRESSO;
+        return;
+    #else
+        #error "ERROR!"
+    #endif
+    }
+    int PlatformInfo::getPlatformType()
+    {
+        if(_pftype==PF_UNKNOWN){
+            check();
+        }
+        return _pftype;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PlatformInfo.h	Sun May 05 11:29:12 2013 +0000
@@ -0,0 +1,25 @@
+#pragma once
+
+namespace MiMic
+{
+    #define PlatformInfo_DETECTION_MODE_AUTO 1
+    #define PlatformInfo_DETECTION_MODE_MBED 2
+    #define PlatformInfo_DETECTION_MODE_LPCXPRESSO 3
+    #define PlatformInfo_DETECTION_MODE PlatformInfo_DETECTION_MODE_AUTO
+
+    class PlatformInfo
+    {
+    public:
+        const static int PF_UNKNOWN=0;
+        const static int PF_MBED=1;
+        const static int PF_LPCXPRESSO=2;
+        /**
+         * This function returns platform type value.
+         */
+        static int getPlatformType();
+    private:
+        static void check();
+        static int _pftype;
+        PlatformInfo(){};
+    };
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun May 05 11:29:12 2013 +0000
@@ -0,0 +1,26 @@
+#include "mbed.h"
+#include "PlatformInfo.h"
+DigitalOut mbedled(LED1);
+DigitalOut lpcxled(P0_22);
+using namespace MiMic;
+int main(){
+    
+
+    
+    switch(PlatformInfo::getPlatformType()){
+    case PlatformInfo::PF_MBED:
+        while(1) {
+            mbedled = 1;
+            wait(0.2);
+            mbedled = 0;
+            wait(0.2);
+        }
+    case PlatformInfo::PF_LPCXPRESSO:
+        while(1) {
+            lpcxled = 1;
+            wait(0.1);
+            lpcxled = 0;
+            wait(0.1);
+        }
+    }    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun May 05 11:29:12 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7e6c9f46b3bd
\ No newline at end of file