Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /****************************************************************************** 00002 * DESCRIPTION: 00003 * A "hello world" CMSIS RTOS program which demonstrates another safe way 00004 * to pass arguments to threads during thread creation. In this case, 00005 * a structure is used to pass multiple arguments. 00006 * AUTHOR: Blaise Barney 00007 * MODIFICATOR: (Simon) CHENG Ye 00008 * LAST REVISED: 06/JAN/2013 00009 ******************************************************************************/ 00010 00011 #include "mbed.h" 00012 #include "cmsis_os.h" 00013 00014 #define NUM_THREADS 8 00015 00016 Serial debug(USBTX, USBRX); // For mbed debug by serial port. 00017 char *messages[NUM_THREADS]; 00018 00019 struct thread_data 00020 { 00021 int thread_id; 00022 int sum; 00023 char *message; 00024 }; 00025 struct thread_data thread_data_array[NUM_THREADS]; 00026 00027 void PrintHello(void const *threadarg) 00028 { 00029 int taskid, sum; 00030 char *hello_msg; 00031 struct thread_data *my_data; 00032 osThreadId id; 00033 00034 osDelay(1000); 00035 my_data = (struct thread_data *) threadarg; 00036 taskid = my_data->thread_id; 00037 sum = my_data->sum; 00038 hello_msg = my_data->message; 00039 printf("Thread %d: %s Sum=%d\n", taskid, hello_msg, sum); 00040 id = osThreadGetId(); 00041 osThreadTerminate(id); 00042 } 00043 00044 void t0(void const *argument) {PrintHello(argument);} 00045 osThreadDef(t0, osPriorityNormal, DEFAULT_STACK_SIZE); 00046 00047 void t1(void const *argument) {PrintHello(argument);} 00048 osThreadDef(t1, osPriorityNormal, DEFAULT_STACK_SIZE); 00049 00050 void t2(void const *argument) {PrintHello(argument);} 00051 osThreadDef(t2, osPriorityNormal, DEFAULT_STACK_SIZE); 00052 00053 void t3(void const *argument) {PrintHello(argument);} 00054 osThreadDef(t3, osPriorityNormal, DEFAULT_STACK_SIZE); 00055 00056 void t4(void const *argument) {PrintHello(argument);} 00057 osThreadDef(t4, osPriorityNormal, DEFAULT_STACK_SIZE); 00058 00059 void t5(void const *argument) {PrintHello(argument);} 00060 osThreadDef(t5, osPriorityNormal, DEFAULT_STACK_SIZE); 00061 00062 void t6(void const *argument) {PrintHello(argument);} 00063 osThreadDef(t6, osPriorityNormal, DEFAULT_STACK_SIZE); 00064 00065 void t7(void const *argument) {PrintHello(argument);} 00066 osThreadDef(t7, osPriorityNormal, DEFAULT_STACK_SIZE); 00067 00068 int main() 00069 { 00070 debug.baud(57600); 00071 int t, sum; 00072 00073 sum=0; 00074 messages[0] = "English: Hello World!"; 00075 messages[1] = "French: Bonjour, le monde!"; 00076 messages[2] = "Spanish: Hola al mundo"; 00077 messages[3] = "Klingon: Nuq neH!"; 00078 messages[4] = "German: Guten Tag, Welt!"; 00079 messages[5] = "Russian: Zdravstvytye, mir!"; 00080 messages[6] = "Japan: Sekai e konnichiwa!"; 00081 messages[7] = "Latin: Orbis, te saluto!"; 00082 00083 for(t=0;t<NUM_THREADS;t++) 00084 { 00085 sum = sum + t; 00086 thread_data_array[t].thread_id = t; 00087 thread_data_array[t].sum = sum; 00088 thread_data_array[t].message = messages[t]; 00089 printf("Creating thread %d\n", t); 00090 if(t==0) osThreadCreate(osThread(t0), (void *)&thread_data_array[t]); 00091 if(t==1) osThreadCreate(osThread(t1), (void *)&thread_data_array[t]); 00092 if(t==2) osThreadCreate(osThread(t2), (void *)&thread_data_array[t]); 00093 if(t==3) osThreadCreate(osThread(t3), (void *)&thread_data_array[t]); 00094 if(t==4) osThreadCreate(osThread(t4), (void *)&thread_data_array[t]); 00095 if(t==5) osThreadCreate(osThread(t5), (void *)&thread_data_array[t]); 00096 if(t==6) osThreadCreate(osThread(t6), (void *)&thread_data_array[t]); 00097 if(t==7) osThreadCreate(osThread(t7), (void *)&thread_data_array[t]); 00098 } 00099 }
Generated on Sun Jul 17 2022 00:49:17 by
1.7.2