#include #include #include #include #include #include #include #include void *thread1( void* arg ) { void* result = NULL; RT_TASK *task1 = NULL; /* Create new realtime task */ task1 = rt_task_init_schmod( nam2num("MYTHD1"), /* ID */ 0, /* Priority: 0 is highest. 0x3fffffff is lowest */ 1024, /* Stack size */ 1024, /* Max message size */ SCHED_FIFO, /* Task scheduling policy */ 1 /* Processor affinity */ ); if( NULL == task1 ) { printf("Failed to create task1\n"); return( result ); } /* Make this task realtime */ rt_make_hard_real_time(); /* do realtime job */ { /* get address of main task */ RT_TASK *mainTask = (RT_TASK*)rt_get_adr( nam2num("MAINTH") ); unsigned int msg = 0x1234; /* send message to main task */ if( NULL != mainTask ) { rt_send( mainTask, msg ); } } /* Delete realtime task */ rt_task_delete( task1 ); /* Exit thread */ return( result ); } main() { pthread_t th1; RT_TASK *mainTask = NULL; /* Enable non-root hrt */ rt_allow_nonroot_hrt(); /* Create realtime task */ mainTask = rt_task_init_schmod( nam2num("MAINTH"), /* ID */ 10, /* Priority: 0 is highest. 0x3fffffff is lowest */ 1024, /* Stack size */ 1024, /* Max message size */ SCHED_FIFO, /* Task scheduling policy */ 1 /* Processor affinity */ ); if( NULL == mainTask ) { printf("Failed to create main task.\n"); return( 0 ); } /* Create user thread */ pthread_create( &th1, NULL, thread1, NULL ); { RT_TASK *sender = NULL; unsigned int msg = 0; /* receive message */ rt_receive( sender, &msg ); printf("Received message %X\n", msg ); } pthread_join( th1, NULL ); /* Delete MAINTH */ rt_task_delete( mainTask ); }