First SPI/SDcard & UART tests

Dependencies:   SDFileSystem mbed-rtos mbed cmsis_rtos_demo_thread

Fork of cmsis_rtos_demo_thread by Ye Cheng

Committer:
cnhzcy14
Date:
Sun Jan 06 12:39:37 2013 +0000
Revision:
0:618ffeb1dfc5
Child:
1:cbda4d713dc8
first

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cnhzcy14 0:618ffeb1dfc5 1 #include "mbed.h"
cnhzcy14 0:618ffeb1dfc5 2 #include "cmsis_os.h"
cnhzcy14 0:618ffeb1dfc5 3
cnhzcy14 0:618ffeb1dfc5 4 #define NUM_THREADS 8
cnhzcy14 0:618ffeb1dfc5 5 char *messages[NUM_THREADS];
cnhzcy14 0:618ffeb1dfc5 6
cnhzcy14 0:618ffeb1dfc5 7 struct thread_data
cnhzcy14 0:618ffeb1dfc5 8 {
cnhzcy14 0:618ffeb1dfc5 9 int thread_id;
cnhzcy14 0:618ffeb1dfc5 10 int sum;
cnhzcy14 0:618ffeb1dfc5 11 char *message;
cnhzcy14 0:618ffeb1dfc5 12 };
cnhzcy14 0:618ffeb1dfc5 13
cnhzcy14 0:618ffeb1dfc5 14 struct thread_data thread_data_array[NUM_THREADS];
cnhzcy14 0:618ffeb1dfc5 15 Serial debug(USBTX, USBRX);
cnhzcy14 0:618ffeb1dfc5 16
cnhzcy14 0:618ffeb1dfc5 17 void PrintHello(void const *threadarg)
cnhzcy14 0:618ffeb1dfc5 18 {
cnhzcy14 0:618ffeb1dfc5 19 int taskid, sum;
cnhzcy14 0:618ffeb1dfc5 20 char *hello_msg;
cnhzcy14 0:618ffeb1dfc5 21 struct thread_data *my_data;
cnhzcy14 0:618ffeb1dfc5 22 osThreadId id;
cnhzcy14 0:618ffeb1dfc5 23
cnhzcy14 0:618ffeb1dfc5 24 osDelay(1000);
cnhzcy14 0:618ffeb1dfc5 25 my_data = (struct thread_data *) threadarg;
cnhzcy14 0:618ffeb1dfc5 26 taskid = my_data->thread_id;
cnhzcy14 0:618ffeb1dfc5 27 sum = my_data->sum;
cnhzcy14 0:618ffeb1dfc5 28 hello_msg = my_data->message;
cnhzcy14 0:618ffeb1dfc5 29 printf("Thread %d: %s Sum=%d\n", taskid, hello_msg, sum);
cnhzcy14 0:618ffeb1dfc5 30 id = osThreadGetId();
cnhzcy14 0:618ffeb1dfc5 31 osThreadTerminate(id);
cnhzcy14 0:618ffeb1dfc5 32 }
cnhzcy14 0:618ffeb1dfc5 33
cnhzcy14 0:618ffeb1dfc5 34
cnhzcy14 0:618ffeb1dfc5 35 void t0(void const *argument) {PrintHello(argument);}
cnhzcy14 0:618ffeb1dfc5 36 osThreadDef(t0, osPriorityNormal, DEFAULT_STACK_SIZE);
cnhzcy14 0:618ffeb1dfc5 37
cnhzcy14 0:618ffeb1dfc5 38 void t1(void const *argument) {PrintHello(argument);}
cnhzcy14 0:618ffeb1dfc5 39 osThreadDef(t1, osPriorityNormal, DEFAULT_STACK_SIZE);
cnhzcy14 0:618ffeb1dfc5 40
cnhzcy14 0:618ffeb1dfc5 41 void t2(void const *argument) {PrintHello(argument);}
cnhzcy14 0:618ffeb1dfc5 42 osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE);
cnhzcy14 0:618ffeb1dfc5 43
cnhzcy14 0:618ffeb1dfc5 44 void t3(void const *argument) {PrintHello(argument);}
cnhzcy14 0:618ffeb1dfc5 45 osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE);
cnhzcy14 0:618ffeb1dfc5 46
cnhzcy14 0:618ffeb1dfc5 47 void t4(void const *argument) {PrintHello(argument);}
cnhzcy14 0:618ffeb1dfc5 48 osThreadDef(t4, osPriorityNormal, DEFAULT_STACK_SIZE);
cnhzcy14 0:618ffeb1dfc5 49
cnhzcy14 0:618ffeb1dfc5 50 void t5(void const *argument) {PrintHello(argument);}
cnhzcy14 0:618ffeb1dfc5 51 osThreadDef(t5, osPriorityNormal, DEFAULT_STACK_SIZE);
cnhzcy14 0:618ffeb1dfc5 52
cnhzcy14 0:618ffeb1dfc5 53 void t6(void const *argument) {PrintHello(argument);}
cnhzcy14 0:618ffeb1dfc5 54 osThreadDef(t6, osPriorityNormal, DEFAULT_STACK_SIZE);
cnhzcy14 0:618ffeb1dfc5 55
cnhzcy14 0:618ffeb1dfc5 56 void t7(void const *argument) {PrintHello(argument);}
cnhzcy14 0:618ffeb1dfc5 57 osThreadDef(t7, osPriorityNormal, DEFAULT_STACK_SIZE);
cnhzcy14 0:618ffeb1dfc5 58
cnhzcy14 0:618ffeb1dfc5 59 int main() {
cnhzcy14 0:618ffeb1dfc5 60 debug.baud(57600);
cnhzcy14 0:618ffeb1dfc5 61 int t, sum;
cnhzcy14 0:618ffeb1dfc5 62
cnhzcy14 0:618ffeb1dfc5 63 sum=0;
cnhzcy14 0:618ffeb1dfc5 64 messages[0] = "English: Hello World!";
cnhzcy14 0:618ffeb1dfc5 65 messages[1] = "French: Bonjour, le monde!";
cnhzcy14 0:618ffeb1dfc5 66 messages[2] = "Spanish: Hola al mundo";
cnhzcy14 0:618ffeb1dfc5 67 messages[3] = "Klingon: Nuq neH!";
cnhzcy14 0:618ffeb1dfc5 68 messages[4] = "German: Guten Tag, Welt!";
cnhzcy14 0:618ffeb1dfc5 69 messages[5] = "Russian: Zdravstvytye, mir!";
cnhzcy14 0:618ffeb1dfc5 70 messages[6] = "Japan: Sekai e konnichiwa!";
cnhzcy14 0:618ffeb1dfc5 71 messages[7] = "Latin: Orbis, te saluto!";
cnhzcy14 0:618ffeb1dfc5 72
cnhzcy14 0:618ffeb1dfc5 73 for(t=0;t<NUM_THREADS;t++) {
cnhzcy14 0:618ffeb1dfc5 74 sum = sum + t;
cnhzcy14 0:618ffeb1dfc5 75 thread_data_array[t].thread_id = t;
cnhzcy14 0:618ffeb1dfc5 76 thread_data_array[t].sum = sum;
cnhzcy14 0:618ffeb1dfc5 77 thread_data_array[t].message = messages[t];
cnhzcy14 0:618ffeb1dfc5 78 printf("Creating thread %d\n", t);
cnhzcy14 0:618ffeb1dfc5 79 if(t==0) osThreadCreate(osThread(t0), (void *)&thread_data_array[t]);
cnhzcy14 0:618ffeb1dfc5 80 if(t==1) osThreadCreate(osThread(t1), (void *)&thread_data_array[t]);
cnhzcy14 0:618ffeb1dfc5 81 if(t==2) osThreadCreate(osThread(t2), (void *)&thread_data_array[t]);
cnhzcy14 0:618ffeb1dfc5 82 if(t==3) osThreadCreate(osThread(t3), (void *)&thread_data_array[t]);
cnhzcy14 0:618ffeb1dfc5 83 if(t==4) osThreadCreate(osThread(t4), (void *)&thread_data_array[t]);
cnhzcy14 0:618ffeb1dfc5 84 if(t==5) osThreadCreate(osThread(t5), (void *)&thread_data_array[t]);
cnhzcy14 0:618ffeb1dfc5 85 if(t==6) osThreadCreate(osThread(t6), (void *)&thread_data_array[t]);
cnhzcy14 0:618ffeb1dfc5 86 if(t==7) osThreadCreate(osThread(t7), (void *)&thread_data_array[t]);
cnhzcy14 0:618ffeb1dfc5 87 }
cnhzcy14 0:618ffeb1dfc5 88 }