Simple RTOS example with a thread writing to an SD card, requiring custom stack size
Dependencies: fat mbed SDFileSystem
main.cpp@0:754abc1f45da, 2012-03-07 (annotated)
- Committer:
- emilmont
- Date:
- Wed Mar 07 10:08:58 2012 +0000
- Revision:
- 0:754abc1f45da
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 0:754abc1f45da | 1 | #include "mbed.h" |
emilmont | 0:754abc1f45da | 2 | #include "rtos.h" |
emilmont | 0:754abc1f45da | 3 | #include "SDFileSystem.h" |
emilmont | 0:754abc1f45da | 4 | |
emilmont | 0:754abc1f45da | 5 | DigitalOut led1(LED1); |
emilmont | 0:754abc1f45da | 6 | DigitalOut led2(LED2); |
emilmont | 0:754abc1f45da | 7 | |
emilmont | 0:754abc1f45da | 8 | void sd_thread(void const *argument) { |
emilmont | 0:754abc1f45da | 9 | SDFileSystem sd(p5, p6, p7, p8, "sd"); |
emilmont | 0:754abc1f45da | 10 | FILE *f = fopen("/sd/out.txt", "w"); |
emilmont | 0:754abc1f45da | 11 | for (int i=0; i<30; i++) { |
emilmont | 0:754abc1f45da | 12 | fprintf(f, "%d\n", i); |
emilmont | 0:754abc1f45da | 13 | printf("%d\n\r", i); |
emilmont | 0:754abc1f45da | 14 | } |
emilmont | 0:754abc1f45da | 15 | printf("closing\n"); |
emilmont | 0:754abc1f45da | 16 | fclose(f); |
emilmont | 0:754abc1f45da | 17 | |
emilmont | 0:754abc1f45da | 18 | while (true) { |
emilmont | 0:754abc1f45da | 19 | led2 = !led2; |
emilmont | 0:754abc1f45da | 20 | Thread::wait(1000); |
emilmont | 0:754abc1f45da | 21 | } |
emilmont | 0:754abc1f45da | 22 | } |
emilmont | 0:754abc1f45da | 23 | |
emilmont | 0:754abc1f45da | 24 | int main() { |
emilmont | 0:754abc1f45da | 25 | Thread t(sd_thread, NULL, osPriorityNormal, (DEFAULT_STACK_SIZE * 2.25)); |
emilmont | 0:754abc1f45da | 26 | |
emilmont | 0:754abc1f45da | 27 | while (true) { |
emilmont | 0:754abc1f45da | 28 | led1 = !led1; |
emilmont | 0:754abc1f45da | 29 | Thread::wait(1000); |
emilmont | 0:754abc1f45da | 30 | } |
emilmont | 0:754abc1f45da | 31 | } |