equal
deleted
inserted
replaced
36 #include <fcntl.h> |
36 #include <fcntl.h> |
37 #include <stdio.h> |
37 #include <stdio.h> |
38 #include <stdlib.h> |
38 #include <stdlib.h> |
39 #include <errno.h> |
39 #include <errno.h> |
40 #include <string.h> |
40 #include <string.h> |
|
41 #include <sys/ioctl.h> |
41 |
42 |
42 #include "include/ecrt.h" |
43 #include "master.h" |
43 #include "master/ioctl.h" |
44 #include "master/ioctl.h" |
44 |
45 |
45 struct ec_master { |
46 /*****************************************************************************/ |
46 int fd; |
47 |
47 void *handle; |
48 unsigned int ecrt_version_magic(void) |
48 }; |
49 { |
|
50 return ECRT_VERSION_MAGIC; |
|
51 } |
49 |
52 |
50 /*****************************************************************************/ |
53 /*****************************************************************************/ |
51 |
54 |
52 #define MAX_PATH_LEN 64 |
55 #define MAX_PATH_LEN 64 |
53 |
56 |
54 ec_master_t *ecrt_request_master(unsigned int master_index) |
57 ec_master_t *ecrt_request_master(unsigned int master_index) |
55 { |
58 { |
56 char path[MAX_PATH_LEN]; |
59 char path[MAX_PATH_LEN]; |
57 ec_master_t *master; |
60 ec_master_t *master; |
58 ec_ioctl_request_t data; |
|
59 |
61 |
60 master = malloc(sizeof(ec_master_t)); |
62 master = malloc(sizeof(ec_master_t)); |
61 if (!master) { |
63 if (!master) { |
62 fprintf(stderr, "Failed to allocate memory.\n"); |
64 fprintf(stderr, "Failed to allocate memory.\n"); |
63 return 0; |
65 return 0; |
70 fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno)); |
72 fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno)); |
71 free(master); |
73 free(master); |
72 return 0; |
74 return 0; |
73 } |
75 } |
74 |
76 |
75 if (ioctl(master->fd, EC_IOCTL_REQUEST, &data) == -1) { |
77 if (ioctl(master->fd, EC_IOCTL_REQUEST, NULL) == -1) { |
76 fprintf(stderr, "Failed to request master %u: %s\n", |
78 fprintf(stderr, "Failed to request master %u: %s\n", |
77 master_index, strerror(errno)); |
79 master_index, strerror(errno)); |
78 close(master->fd); |
80 close(master->fd); |
79 free(master); |
81 free(master); |
80 return 0; |
82 return 0; |
81 } |
83 } |
82 |
84 |
83 master->handle = data.handle; |
|
84 return master; |
85 return master; |
85 } |
86 } |
86 |
87 |
87 /*****************************************************************************/ |
88 /*****************************************************************************/ |
88 |
89 |
91 close(master->fd); |
92 close(master->fd); |
92 free(master); |
93 free(master); |
93 } |
94 } |
94 |
95 |
95 /*****************************************************************************/ |
96 /*****************************************************************************/ |
96 |
|
97 unsigned int ecrt_version_magic(void) |
|
98 { |
|
99 return ECRT_VERSION_MAGIC; |
|
100 } |
|
101 |
|
102 /*****************************************************************************/ |
|