examples/dc_user/main.c
branchstable-1.5
changeset 2698 9e65f782e8a1
parent 2421 bc2d4bf9cbe5
equal deleted inserted replaced
2697:4f5ae7e0fbaa 2698:9e65f782e8a1
    36 #include <sys/types.h>
    36 #include <sys/types.h>
    37 #include <unistd.h>
    37 #include <unistd.h>
    38 #include <time.h>
    38 #include <time.h>
    39 #include <sys/mman.h>
    39 #include <sys/mman.h>
    40 #include <malloc.h>
    40 #include <malloc.h>
       
    41 #include <sched.h> /* sched_setscheduler() */
    41 
    42 
    42 /****************************************************************************/
    43 /****************************************************************************/
    43 
    44 
    44 #include "ecrt.h"
    45 #include "ecrt.h"
    45 
    46 
    46 /****************************************************************************/
    47 /****************************************************************************/
    47 
    48 
    48 // Application parameters
    49 // Application parameters
    49 #define FREQUENCY 1000
    50 #define FREQUENCY 1000
    50 #define CLOCK_TO_USE CLOCK_REALTIME
    51 #define CLOCK_TO_USE CLOCK_MONOTONIC
    51 #define MEASURE_TIMING
    52 #define MEASURE_TIMING
    52 
    53 
    53 /****************************************************************************/
    54 /****************************************************************************/
    54 
    55 
    55 #define NSEC_PER_SEC (1000000000L)
    56 #define NSEC_PER_SEC (1000000000L)
   311 
   312 
   312     if (!(domain1_pd = ecrt_domain_data(domain1))) {
   313     if (!(domain1_pd = ecrt_domain_data(domain1))) {
   313         return -1;
   314         return -1;
   314     }
   315     }
   315 
   316 
   316     pid_t pid = getpid();
   317     /* Set priority */
   317     if (setpriority(PRIO_PROCESS, pid, -19))
   318 
   318         fprintf(stderr, "Warning: Failed to set priority: %s\n",
   319     struct sched_param param = {};
   319                 strerror(errno));
   320     param.sched_priority = sched_get_priority_max(SCHED_FIFO);
       
   321 
       
   322     printf("Using priority %i.", param.sched_priority);
       
   323     if (sched_setscheduler(0, SCHED_FIFO, &param) == -1) {
       
   324         perror("sched_setscheduler failed");
       
   325     }
   320 
   326 
   321 	printf("Starting cyclic function.\n");
   327 	printf("Starting cyclic function.\n");
   322     cyclic_task();
   328     cyclic_task();
   323 
   329 
   324     return 0;
   330     return 0;