examples/dc_user/main.c
branchstable-1.5
changeset 2421 bc2d4bf9cbe5
parent 1971 ba8a75cb1c98
child 2698 9e65f782e8a1
equal deleted inserted replaced
2420:69056c46aa4d 2421:bc2d4bf9cbe5
    57 
    57 
    58 #define DIFF_NS(A, B) (((B).tv_sec - (A).tv_sec) * NSEC_PER_SEC + \
    58 #define DIFF_NS(A, B) (((B).tv_sec - (A).tv_sec) * NSEC_PER_SEC + \
    59 	(B).tv_nsec - (A).tv_nsec)
    59 	(B).tv_nsec - (A).tv_nsec)
    60 
    60 
    61 #define TIMESPEC2NS(T) ((uint64_t) (T).tv_sec * NSEC_PER_SEC + (T).tv_nsec)
    61 #define TIMESPEC2NS(T) ((uint64_t) (T).tv_sec * NSEC_PER_SEC + (T).tv_nsec)
    62   
    62 
    63 /****************************************************************************/
    63 /****************************************************************************/
    64 
    64 
    65 // EtherCAT
    65 // EtherCAT
    66 static ec_master_t *master = NULL;
    66 static ec_master_t *master = NULL;
    67 static ec_master_state_t master_state = {};
    67 static ec_master_state_t master_state = {};
   206 			check_master_state();
   206 			check_master_state();
   207 
   207 
   208 #ifdef MEASURE_TIMING
   208 #ifdef MEASURE_TIMING
   209             // output timing stats
   209             // output timing stats
   210             printf("period     %10u ... %10u\n",
   210             printf("period     %10u ... %10u\n",
   211                     period_min_ns, period_max_ns); 
   211                     period_min_ns, period_max_ns);
   212             printf("exec       %10u ... %10u\n",
   212             printf("exec       %10u ... %10u\n",
   213                     exec_min_ns, exec_max_ns); 
   213                     exec_min_ns, exec_max_ns);
   214             printf("latency    %10u ... %10u\n",
   214             printf("latency    %10u ... %10u\n",
   215                     latency_min_ns, latency_max_ns); 
   215                     latency_min_ns, latency_max_ns);
   216             period_max_ns = 0;
   216             period_max_ns = 0;
   217             period_min_ns = 0xffffffff;
   217             period_min_ns = 0xffffffff;
   218             exec_max_ns = 0;
   218             exec_max_ns = 0;
   219             exec_min_ns = 0xffffffff;
   219             exec_min_ns = 0xffffffff;
   220             latency_max_ns = 0;
   220             latency_max_ns = 0;
   259 
   259 
   260 	if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
   260 	if (mlockall(MCL_CURRENT | MCL_FUTURE) == -1) {
   261 		perror("mlockall failed");
   261 		perror("mlockall failed");
   262 		return -1;
   262 		return -1;
   263 	}
   263 	}
   264     
   264 
   265     master = ecrt_request_master(0);
   265     master = ecrt_request_master(0);
   266     if (!master)
   266     if (!master)
   267         return -1;
   267         return -1;
   268 
   268 
   269     domain1 = ecrt_master_create_domain(master);
   269     domain1 = ecrt_master_create_domain(master);
   318         fprintf(stderr, "Warning: Failed to set priority: %s\n",
   318         fprintf(stderr, "Warning: Failed to set priority: %s\n",
   319                 strerror(errno));
   319                 strerror(errno));
   320 
   320 
   321 	printf("Starting cyclic function.\n");
   321 	printf("Starting cyclic function.\n");
   322     cyclic_task();
   322     cyclic_task();
   323     
   323 
   324     return 0;
   324     return 0;
   325 }
   325 }
   326 
   326 
   327 /****************************************************************************/
   327 /****************************************************************************/