/** Primary entry function ***/ int main( int argc, char* argv[] ) { ReturnCode_t returnCode; // Create the master context Context_t context; // Zero the context memset( &context, 0, sizeof(Context_t) ); // Check the command line arguments for local and remote IP addresses and number of hyperperiods assert( argc == 4 ); /*** Initialize the FRODO subsystems ***/ SysEventInitialize( AllCategories, false, true, false ); PeripheralInitialize(); LogInitialize(); ErrorHandlerInitialize(); SchedInitialize( EarliestDeadlineFirst, ErrSchedulerHandler, 20.0, 1, &context ); UDPInitialize( ErrUDPHandler ); /*** Create message ports ***/ { // Set initial value of port message data_t data = { 1.0 }; CreateSamplingPort( "data", sizeof(data_t), Bidirectional, 0, &(context.msgPort), &returnCode ); WriteSamplingMessage( context.msgPort, &data, sizeof(data_t), &returnCode ); } /*** Create Tasks ***/ { // Create task with instances pfloat_t Task1_times[1] = { 4.0 }; SchedCreatePeriodicTask( "Task1", Task1_exec, &context.task1, 1.00, NoRestriction, 1, Task1_times ); } /*** Create Peripherals ***/ { pfloat_t send_times[1] = { 8.0 }; pfloat_t receive_times[1] = { 14.0 }; SyncExpectation syncExpects[2] = { { ExpectSend, 1, sizeof(data_t), 1, send_times, 2.0, context.msgPort, NULL }, { ExpectReceive, 1, sizeof(data_t), 1, receive_times, 2.0, context.msgPort, NULL } }; context.udpChannel = UDPCreateChannel( argv[1], argv[2], 21212, 2, syncExpects, 0, NULL, true, false, 2 ); } /*** Execute the schedule ***/ // Wait for the platform to wake up ( Platform Dependent ) NanoSleep( SCHEDULER_INITIALIZATION_WAIT ); // Execute the schedule SchedExecute( atoi(argv[3]) ); /*** Shutdown the application ***/ // If this returns we must shut everything down UDPShutdown( ); SchedShutdown( ); SysEventShutdown( NULL ); }
int main(int argc, char **argv) { void (*rcSig)(int); pthread_t hThread; char szName[1024]; int i; int rc; /* * Set up the signal handlers. */ rcSig = bsd_signal(SIGALRM, SigHandler); if (rcSig != SIG_ERR) rcSig = bsd_signal(SIGCHLD, SigHandler); if (rcSig == SIG_ERR) { fprintf(stderr, "bsd_signal failed: %s\n", strerror(errno)); return 1; } if (argc == 2) /* testing... */ { siginterrupt(SIGALRM, 1); siginterrupt(SIGCHLD, 1); } /* * Kick off a thread that will signal us like there was no tomorrow. */ g_hMainThread = pthread_self(); rc = pthread_create(&hThread, NULL, ThreadProc, NULL); if (rc != 0) { fprintf(stderr, "pthread_create failed: %s\n", strerror(rc)); return 1; } /* * Do path related stuff. */ snprintf(szName, sizeof(szName), "%s-test2", argv[0]); for (i = 0; i < 100*1000*1000; i++) { struct stat St; int fd; rc = stat(argv[0], &St); if (rc == 0 || errno != EINTR) rc = stat(szName, &St); if (errno == EINTR && rc != 0) { printf("iteration %d: stat: %u\n", i, errno); break; } fd = open(szName, O_CREAT | O_RDWR, 0666); if (errno == EINTR && fd < 0) { printf("iteration %d: open: %u\n", i, errno); break; } close(fd); rc = unlink(szName); if (errno == EINTR && rc != 0) { printf("iteration %d: unlink: %u\n", i, errno); break; } /* Show progress info */ if ((i % 100000) == 0) { printf("."); if ((i % 1000000) == 0) printf("[%d/%ld/%ld]\n", i, g_cSigs, g_cSigsOther); fflush(stdout); } } g_fShutdown = 1; if (rc) printf("No EINTR in %d iterations - system is working nicely!\n", i); NanoSleep(10000000); return rc ? 1 : 0; }