vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / vmod / lib / libvmodttl2dioaio.c
blobf66e8c3d64e39908cb15c874be96105f3502995e
1 #include <stdio.h>
2 #include <gm/moduletypes.h>
3 #include "libvmodttl2dioaio.h"
4 #include <dioaiolib.h>
7 #define VMODTTL_MAX_BOARDS 64 /* max. # of boards supported */
9 static void print_error(int error);
11 int vmodttl_open(int lun)
13 if(lun < 0 || lun >= VMODTTL_MAX_BOARDS){
14 fprintf(stderr, "libvmodttl2dioaio : Invalid lun %d\n", lun);
15 return -1;
17 return 0;
20 int vmodttl_close(int lun)
22 return 0;
25 int vmodttl_io_config(int lun, struct vmodttl_config conf)
27 int ret;
29 ret = DioGlobalReset(IocVMODTTL, lun);
30 if (ret < 0){
31 print_error(ret);
32 return ret;
35 ret = DioChannelSet(IocVMODTTL, lun, 0, 1, conf.dir_a, conf.inverting_logic, conf.inverting_logic);
36 if (ret < 0){
37 print_error(ret);
38 return ret;
41 ret = DioChannelSet(IocVMODTTL, lun, 1, 1, conf.dir_b, conf.inverting_logic, conf.inverting_logic);
42 if (ret < 0){
43 print_error(ret);
44 return ret;
47 return 0;
50 int vmodttl_io_chan_config(int lun, enum vmodttl_channel chan, struct vmodttl_config conf)
52 int ret = 0;
54 switch(chan) {
56 case VMOD_TTL_CHANNEL_A:
57 ret = DioChannelSet(IocVMODTTL, lun, 0, 1, conf.dir_a, conf.inverting_logic, conf.inverting_logic);
58 break;
59 case VMOD_TTL_CHANNEL_B:
60 ret = DioChannelSet(IocVMODTTL, lun, 1, 1, conf.dir_b, conf.inverting_logic, conf.inverting_logic);
61 break;
62 case VMOD_TTL_CHANNELS_AB:
63 ret = vmodttl_io_config(lun, conf);
64 break;
65 default:
66 fprintf(stderr, "libvmodttl2dioaio : Invalid channel (%d) to configure\n", chan);
69 if (ret < 0){
70 print_error(ret);
71 return ret;
73 return 0;
76 int vmodttl_write(int lun, enum vmodttl_channel chan, int val)
78 if (chan != VMOD_TTL_CHANNELS_AB){
79 DioChannelWrite(IocVMODTTL, lun, chan, 1, val);
80 } else {
81 DioChannelWrite(IocVMODTTL, lun, 0, 1, val & 0xff);
82 DioChannelWrite(IocVMODTTL, lun, 1, 1, (val >> 8) & 0xff);
85 return 0;
88 int vmodttl_read(int lun, enum vmodttl_channel chan, int *val)
90 int ret;
92 if (chan != VMOD_TTL_CHANNELS_AB){
93 ret = DioChannelRead(IocVMODTTL, lun, chan, 1, (int *)val);
94 } else {
95 int tmp = 0;
96 int tmp2 = 0;
98 ret = DioChannelRead(IocVMODTTL, lun, 0, 1, (int *)&tmp);
99 ret = DioChannelRead(IocVMODTTL, lun, 1, 1, (int *)&tmp2);
100 *val = tmp + (tmp2 << 8);
103 return ret;
106 int vmodttl_pattern(int lun, enum vmodttl_channel chan, int pos, enum vmodttl_conf_pattern bit_pattern)
108 /* Not implemented */
109 return 0;
112 int vmodttl_read_config(int lun, struct vmodttl_config *conf)
114 /* Not implemented */
115 return 0;
118 int vmodttl_read_device(int lun, unsigned char buffer[2])
120 /* Not implemented */
121 return 0;
125 static void print_error(int error)
127 switch(error){
128 case -dio_system_errno:
129 fprintf(stderr, dio_err1msg);
130 break;
131 case -dio_bad_key:
132 fprintf(stderr, dio_err8msg);
133 break;
134 case -dio_cannot_find_shared_table:
135 fprintf(stderr, dio_err7msg);
136 break;
137 case -dio_cannot_map_shared_table:
138 fprintf(stderr, dio_err6msg);
139 break;
140 case -dio_odd_group_no_and_even_size:
141 fprintf(stderr, dio_err5msg);
142 break;
143 case -dio_bad_size:
144 fprintf(stderr, dio_err4msg);
145 break;
146 case -dio_bad_group:
147 fprintf(stderr, dio_err3msg);
148 break;
149 case -dio_no_direct_access_allowed:
150 fprintf(stderr, dio_err2msg);
151 break;
152 case -dio_lun_out_of_range:
153 fprintf(stderr, dio_err9msg);
154 break;
155 case -dio_no_module_of_this_type:
156 fprintf(stderr, dio_err10msg);
157 break;
158 default:
159 break;