This program can detect the type(mbed or LPCXpresso) of platform. The sample recognizes mbed or LPCXpresso.
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.
PlatformInfo.h@0:ef577a5fd78f, 2013-05-05 (annotated)
- Committer:
- nyatla
- Date:
- Sun May 05 11:29:12 2013 +0000
- Revision:
- 0:ef577a5fd78f
Sample of platform detection
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nyatla | 0:ef577a5fd78f | 1 | #pragma once |
nyatla | 0:ef577a5fd78f | 2 | |
nyatla | 0:ef577a5fd78f | 3 | namespace MiMic |
nyatla | 0:ef577a5fd78f | 4 | { |
nyatla | 0:ef577a5fd78f | 5 | #define PlatformInfo_DETECTION_MODE_AUTO 1 |
nyatla | 0:ef577a5fd78f | 6 | #define PlatformInfo_DETECTION_MODE_MBED 2 |
nyatla | 0:ef577a5fd78f | 7 | #define PlatformInfo_DETECTION_MODE_LPCXPRESSO 3 |
nyatla | 0:ef577a5fd78f | 8 | #define PlatformInfo_DETECTION_MODE PlatformInfo_DETECTION_MODE_AUTO |
nyatla | 0:ef577a5fd78f | 9 | |
nyatla | 0:ef577a5fd78f | 10 | class PlatformInfo |
nyatla | 0:ef577a5fd78f | 11 | { |
nyatla | 0:ef577a5fd78f | 12 | public: |
nyatla | 0:ef577a5fd78f | 13 | const static int PF_UNKNOWN=0; |
nyatla | 0:ef577a5fd78f | 14 | const static int PF_MBED=1; |
nyatla | 0:ef577a5fd78f | 15 | const static int PF_LPCXPRESSO=2; |
nyatla | 0:ef577a5fd78f | 16 | /** |
nyatla | 0:ef577a5fd78f | 17 | * This function returns platform type value. |
nyatla | 0:ef577a5fd78f | 18 | */ |
nyatla | 0:ef577a5fd78f | 19 | static int getPlatformType(); |
nyatla | 0:ef577a5fd78f | 20 | private: |
nyatla | 0:ef577a5fd78f | 21 | static void check(); |
nyatla | 0:ef577a5fd78f | 22 | static int _pftype; |
nyatla | 0:ef577a5fd78f | 23 | PlatformInfo(){}; |
nyatla | 0:ef577a5fd78f | 24 | }; |
nyatla | 0:ef577a5fd78f | 25 | } |