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.cpp@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 | #include "PlatformInfo.h" |
nyatla | 0:ef577a5fd78f | 2 | #define REG_HCSR 0xe000edf0 |
nyatla | 0:ef577a5fd78f | 3 | #define REG_DEMCR 0xE000EDFC |
nyatla | 0:ef577a5fd78f | 4 | |
nyatla | 0:ef577a5fd78f | 5 | #include "mbed.h" |
nyatla | 0:ef577a5fd78f | 6 | namespace MiMic |
nyatla | 0:ef577a5fd78f | 7 | { |
nyatla | 0:ef577a5fd78f | 8 | int PlatformInfo::_pftype=PF_UNKNOWN; |
nyatla | 0:ef577a5fd78f | 9 | void PlatformInfo::check() |
nyatla | 0:ef577a5fd78f | 10 | { |
nyatla | 0:ef577a5fd78f | 11 | #if PlatformInfo_DETECTION_MODE==PlatformInfo_DETECTION_MODE_MBED |
nyatla | 0:ef577a5fd78f | 12 | _pftype=PF_MBED; |
nyatla | 0:ef577a5fd78f | 13 | return; |
nyatla | 0:ef577a5fd78f | 14 | #elif PlatformInfo_DETECTION_MODE==PlatformInfo_DETECTION_MODE_LPCXPRESSO |
nyatla | 0:ef577a5fd78f | 15 | _pftype=PF_LPCXPRESSO; |
nyatla | 0:ef577a5fd78f | 16 | return; |
nyatla | 0:ef577a5fd78f | 17 | #elif PlatformInfo_DETECTION_MODE==PlatformInfo_DETECTION_MODE_AUTO |
nyatla | 0:ef577a5fd78f | 18 | //LPCXpresso is return S_RESET_ST==1 when standalone. |
nyatla | 0:ef577a5fd78f | 19 | wait_ms(200); |
nyatla | 0:ef577a5fd78f | 20 | unsigned int v; |
nyatla | 0:ef577a5fd78f | 21 | v=*(unsigned int*)REG_HCSR; |
nyatla | 0:ef577a5fd78f | 22 | //check Debug Halting Control and Status::S_RESET_ST sticky bit |
nyatla | 0:ef577a5fd78f | 23 | if((v & 0x02000000)!=0){ |
nyatla | 0:ef577a5fd78f | 24 | //may be LPC-Standalone |
nyatla | 0:ef577a5fd78f | 25 | _pftype=PF_LPCXPRESSO; |
nyatla | 0:ef577a5fd78f | 26 | return; |
nyatla | 0:ef577a5fd78f | 27 | } |
nyatla | 0:ef577a5fd78f | 28 | v=(*(unsigned int*)REG_DEMCR); |
nyatla | 0:ef577a5fd78f | 29 | if((v & 0x01000000)==0x0){ |
nyatla | 0:ef577a5fd78f | 30 | //may be mbed |
nyatla | 0:ef577a5fd78f | 31 | _pftype=PF_MBED; |
nyatla | 0:ef577a5fd78f | 32 | return; |
nyatla | 0:ef577a5fd78f | 33 | } |
nyatla | 0:ef577a5fd78f | 34 | _pftype=PF_LPCXPRESSO; |
nyatla | 0:ef577a5fd78f | 35 | return; |
nyatla | 0:ef577a5fd78f | 36 | #else |
nyatla | 0:ef577a5fd78f | 37 | #error "ERROR!" |
nyatla | 0:ef577a5fd78f | 38 | #endif |
nyatla | 0:ef577a5fd78f | 39 | } |
nyatla | 0:ef577a5fd78f | 40 | int PlatformInfo::getPlatformType() |
nyatla | 0:ef577a5fd78f | 41 | { |
nyatla | 0:ef577a5fd78f | 42 | if(_pftype==PF_UNKNOWN){ |
nyatla | 0:ef577a5fd78f | 43 | check(); |
nyatla | 0:ef577a5fd78f | 44 | } |
nyatla | 0:ef577a5fd78f | 45 | return _pftype; |
nyatla | 0:ef577a5fd78f | 46 | } |
nyatla | 0:ef577a5fd78f | 47 | } |