lib/master.c
changeset 1258 900f1124e8f8
parent 1255 38b7e05b20c1
child 1259 5f9d1abbee71
equal deleted inserted replaced
1257:9844ac126275 1258:900f1124e8f8
    34 #include <stdlib.h>
    34 #include <stdlib.h>
    35 #include <sys/ioctl.h>
    35 #include <sys/ioctl.h>
    36 #include <stdio.h>
    36 #include <stdio.h>
    37 #include <errno.h>
    37 #include <errno.h>
    38 #include <string.h>
    38 #include <string.h>
       
    39 #include <sys/mman.h>
    39 
    40 
    40 #include "master.h"
    41 #include "master.h"
    41 #include "domain.h"
    42 #include "domain.h"
    42 #include "slave_config.h"
    43 #include "slave_config.h"
    43 #include "master/ioctl.h"
    44 #include "master/ioctl.h"
    62         return 0; 
    63         return 0; 
    63     }
    64     }
    64 
    65 
    65     domain->index = (unsigned int) index;
    66     domain->index = (unsigned int) index;
    66     domain->master = master;
    67     domain->master = master;
       
    68     domain->process_data = NULL;
    67     return domain;
    69     return domain;
    68 }
    70 }
    69 
    71 
    70 /*****************************************************************************/
    72 /*****************************************************************************/
    71 
    73 
   104 
   106 
   105 /*****************************************************************************/
   107 /*****************************************************************************/
   106 
   108 
   107 int ecrt_master_activate(ec_master_t *master)
   109 int ecrt_master_activate(ec_master_t *master)
   108 {
   110 {
   109     if (ioctl(master->fd, EC_IOCTL_ACTIVATE, NULL) == -1) {
   111     if (ioctl(master->fd, EC_IOCTL_ACTIVATE,
       
   112                 &master->process_data_size) == -1) {
   110         fprintf(stderr, "Failed to activate master: %s\n",
   113         fprintf(stderr, "Failed to activate master: %s\n",
   111                 strerror(errno));
   114                 strerror(errno));
   112         return -1; 
   115         return -1; 
       
   116     }
       
   117 
       
   118     if (master->process_data_size) {
       
   119         master->process_data = mmap(0, master->process_data_size,
       
   120                 PROT_READ | PROT_WRITE, MAP_PRIVATE, master->fd, 0);
       
   121         if (master->process_data == MAP_FAILED) {
       
   122             fprintf(stderr, "Failed to map process data: %s", strerror(errno));
       
   123             master->process_data = NULL;
       
   124             master->process_data_size = 0;
       
   125             return -1;
       
   126         }
       
   127 
       
   128         // Access the mapped region to cause the initial page fault
       
   129         printf("pd: %x\n", master->process_data[0]);
   113     }
   130     }
   114 
   131 
   115     return 0;
   132     return 0;
   116 }
   133 }
   117 
   134