#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 char msg[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; /* send message to main task */ if( NULL != mainTask ) { rt_sendx( mainTask, msg, sizeof(msg) ); } } /* Wait for main task to process sent message */ /* If this task is deleted before main task process the message, */ /* send message will be broken */ sleep(1); /* 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 char msg[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; long actualLength = 0; /* receive message */ rt_receivex( sender, msg, sizeof(msg), &actualLength ); { int i = 0; printf("Received message (%d): ", actualLength ); for( i = 0 ; i < sizeof(msg) / sizeof(unsigned char) ; ++i ) { printf("%02X ", msg[ i ] ); } printf("\n"); } } pthread_join( th1, NULL ); /* Delete MAINTH */ rt_task_delete( mainTask ); }