initial test app that shows potential memory usage by mbed-rtos
Dependencies: mbed-rtosMemoryTest mbed
Revision 0:9a0840718117, committed 2014-12-09
- Comitter:
- dmatsumoto
- Date:
- Tue Dec 09 18:42:05 2014 +0000
- Commit message:
- initial test app that shows potential memory usage by mbed-rtos
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/heapsize.hpp Tue Dec 09 18:42:05 2014 +0000 @@ -0,0 +1,15 @@ +#ifndef __HEAPSIZE_HPP__ +#define __HEAPSIZE_HPP__ + +unsigned long heapSize() +{ + char stackVariable; + void *heap; + unsigned long result; + heap = malloc(4); + result = (uint8_t*)&stackVariable - (uint8_t*)heap; + free(heap); + return result; +} + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Dec 09 18:42:05 2014 +0000 @@ -0,0 +1,109 @@ +#include "mbed.h" +#include "heapsize.hpp" + +DigitalOut GreenLed(LED_GREEN); +DigitalOut RedLed(LED_RED); +DigitalOut BlueLed(LED_BLUE); + +void BlinkErrorCodeNoRtos( int blinks) +{ + GreenLed = 1; + BlueLed = 1; + for( int i=0; i<blinks; i++) { + RedLed = 0; + wait( 0.15); + RedLed = 1; + wait( 0.15); + } + wait(0.5); +} + +extern "C" void HardFault_Handler() +{ + while( 1) + BlinkErrorCodeNoRtos(1); +} + +extern "C" void UsageFault_Handler() +{ + while( 1) + BlinkErrorCodeNoRtos( 2); +} + +extern "C" void BusFault_Handler() +{ + while( 1) + BlinkErrorCodeNoRtos( 3); +} + +extern "C" void MemManage_Handler() +{ + while( 1) + BlinkErrorCodeNoRtos( 4); +} + +/* +extern "C" void SVC_Handler(int R0) +{ + //wait(0.1); +} + +extern "C" void NMI_Handler() +{ +} + +extern "C" void DebugMon_Handler() +{ + GreenLed = 1; + + BlueLed = 0; + RedLed = 0; + wait( 0.1); + BlueLed = 1; + RedLed = 1; +} + +extern "C" void PendSV_Handler() +{ + BlueLed = 1; + + GreenLed = 0; + RedLed = 0; + wait( 0.1); + GreenLed = 1; + RedLed = 1; +} + +extern "C" void SysTick_Handler() +{ + +} + +extern "C" void IntDefaultHandler() +{ +} +*/ + +int main() +{ +#ifdef __CC_ARM + printf( "CC ARM \r\n"); +#elif defined(__GNUC__) + printf( "GNUC \r\n"); +#elif defined(__ICCARM__) + printf( "ICC ARM \r\n"); +#endif + + printf( "in main, heap free is: %ld\r\n", heapSize()); + + while (true) { + GreenLed = 0; + BlueLed = 0; + RedLed = 0; + wait( 0.15); + GreenLed = 1; + BlueLed = 1; + RedLed = 1; + wait( 0.15); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Tue Dec 09 18:42:05 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/dmatsumoto/code/mbed-rtosMemoryTest/#12e4664cbe28
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.lib Tue Dec 09 18:42:05 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/#4fc01daae5a5