Tyler Weaver
/
rtos_sprintf
Demonstration of the use of sprintf() causing a run time problem with RTOS.
main.cpp@0:7fecc17e2765, 2012-02-16 (annotated)
- Committer:
- tylerjw
- Date:
- Thu Feb 16 14:03:52 2012 +0000
- Revision:
- 0:7fecc17e2765
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tylerjw | 0:7fecc17e2765 | 1 | #include "mbed.h" |
tylerjw | 0:7fecc17e2765 | 2 | #include "rtos.h" |
tylerjw | 0:7fecc17e2765 | 3 | |
tylerjw | 0:7fecc17e2765 | 4 | DigitalOut led1(LED1); |
tylerjw | 0:7fecc17e2765 | 5 | DigitalOut led2(LED2); |
tylerjw | 0:7fecc17e2765 | 6 | |
tylerjw | 0:7fecc17e2765 | 7 | char* teststring = ""; |
tylerjw | 0:7fecc17e2765 | 8 | int testint = 65; |
tylerjw | 0:7fecc17e2765 | 9 | |
tylerjw | 0:7fecc17e2765 | 10 | // uncomment only one of the sprintf functions at a time to see it fail at that point |
tylerjw | 0:7fecc17e2765 | 11 | |
tylerjw | 0:7fecc17e2765 | 12 | void led2_thread(void const *argument) { |
tylerjw | 0:7fecc17e2765 | 13 | while (true) { |
tylerjw | 0:7fecc17e2765 | 14 | led2 = !led2; |
tylerjw | 0:7fecc17e2765 | 15 | //sprintf(teststring, "This is a test: %d", testint); |
tylerjw | 0:7fecc17e2765 | 16 | Thread::wait(1000); |
tylerjw | 0:7fecc17e2765 | 17 | } |
tylerjw | 0:7fecc17e2765 | 18 | } |
tylerjw | 0:7fecc17e2765 | 19 | |
tylerjw | 0:7fecc17e2765 | 20 | int main() { |
tylerjw | 0:7fecc17e2765 | 21 | Thread thread(led2_thread); |
tylerjw | 0:7fecc17e2765 | 22 | //sprintf(teststring, "This is a test: %d", testint); |
tylerjw | 0:7fecc17e2765 | 23 | |
tylerjw | 0:7fecc17e2765 | 24 | while (true) { |
tylerjw | 0:7fecc17e2765 | 25 | led1 = !led1; |
tylerjw | 0:7fecc17e2765 | 26 | sprintf(teststring, "This is a test: %d", testint); |
tylerjw | 0:7fecc17e2765 | 27 | Thread::wait(500); |
tylerjw | 0:7fecc17e2765 | 28 | } |
tylerjw | 0:7fecc17e2765 | 29 | } |