simple program for rtos thread test.

Dependencies:   mbed-rtos mbed

threadの解説は、

http://mbed.org/users/takashikojo/notebook/r/

が詳しいです。

Committer:
hayashiisme
Date:
Thu Jan 17 02:22:58 2013 +0000
Revision:
0:9c5cee1cb2ba
theread test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hayashiisme 0:9c5cee1cb2ba 1 #include "mbed.h"
hayashiisme 0:9c5cee1cb2ba 2 #include "rtos.h"
hayashiisme 0:9c5cee1cb2ba 3 #include<vector>
hayashiisme 0:9c5cee1cb2ba 4
hayashiisme 0:9c5cee1cb2ba 5 LocalFileSystem local("local");
hayashiisme 0:9c5cee1cb2ba 6 Serial pc(USBTX, USBRX);
hayashiisme 0:9c5cee1cb2ba 7 DigitalOut myled(LED4);
hayashiisme 0:9c5cee1cb2ba 8 Queue<uint32_t, 5> queue;
hayashiisme 0:9c5cee1cb2ba 9
hayashiisme 0:9c5cee1cb2ba 10
hayashiisme 0:9c5cee1cb2ba 11 void indicater(void const *args)
hayashiisme 0:9c5cee1cb2ba 12 {
hayashiisme 0:9c5cee1cb2ba 13 printf(">led thread start\r\n");
hayashiisme 0:9c5cee1cb2ba 14 // int n;
hayashiisme 0:9c5cee1cb2ba 15 FILE *fp = fopen("/local/test02.txt", "w");
hayashiisme 0:9c5cee1cb2ba 16 fprintf(fp, "Hello file system from thread!\n");
hayashiisme 0:9c5cee1cb2ba 17 fclose(fp);
hayashiisme 0:9c5cee1cb2ba 18 while(1){
hayashiisme 0:9c5cee1cb2ba 19 // for(n=0; n < 100; n++){
hayashiisme 0:9c5cee1cb2ba 20 myled = 1;
hayashiisme 0:9c5cee1cb2ba 21 Thread::wait(500);
hayashiisme 0:9c5cee1cb2ba 22 myled = 0;
hayashiisme 0:9c5cee1cb2ba 23 Thread::wait(500);
hayashiisme 0:9c5cee1cb2ba 24 }
hayashiisme 0:9c5cee1cb2ba 25 while(1){Thread::wait(500);}
hayashiisme 0:9c5cee1cb2ba 26 }
hayashiisme 0:9c5cee1cb2ba 27
hayashiisme 0:9c5cee1cb2ba 28 int main(void)
hayashiisme 0:9c5cee1cb2ba 29 {
hayashiisme 0:9c5cee1cb2ba 30 pc.baud(921600);
hayashiisme 0:9c5cee1cb2ba 31 printf("\r\n==== mbed program start ====\r\n");
hayashiisme 0:9c5cee1cb2ba 32 printf("%s\r\n", __FILE__);
hayashiisme 0:9c5cee1cb2ba 33 Thread th_console_out(indicater);
hayashiisme 0:9c5cee1cb2ba 34 FILE *fp = fopen("/local/test01.txt", "w");
hayashiisme 0:9c5cee1cb2ba 35 fprintf(fp, "Hello file system from main()!\n");
hayashiisme 0:9c5cee1cb2ba 36 fclose(fp);
hayashiisme 0:9c5cee1cb2ba 37 wait(3);
hayashiisme 0:9c5cee1cb2ba 38 th_console_out.terminate();
hayashiisme 0:9c5cee1cb2ba 39 wait(1);
hayashiisme 0:9c5cee1cb2ba 40 printf("=== mbed program end ====\r\n");
hayashiisme 0:9c5cee1cb2ba 41 exit(1);
hayashiisme 0:9c5cee1cb2ba 42 }