-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathselect_BR.c
205 lines (180 loc) · 5.71 KB
/
select_BR.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* INCLUDE FILE DECLARATIONS */
#include <string.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <linux/sockios.h>
#include <pthread.h>
#include "ioctl.h"
/* LOCAL VARIABLES DECLARATIONS */
int main(int argc, char* argv[])
{
char dev[16];
int select;
int custom_baud;
int product;
int parameter;
int sampling_clock;
int devfd;
while ( 1 ) {
printf( "Please input the port of AX99100. (ex. /dev/ttyF0):" );
scanf( "%s", dev );
if ( memcmp(dev, "/dev/ttyF", 4) != 0 )
printf( "Wrong input!!\n" );
else
{
printf( "Correct input!!\n" );
break;
}
}
//memcpy(dev, "/dev/ttyF0", 10);
devfd = open(dev, O_RDWR);
if ( devfd == -1 ) {
printf( "Can't open %s\n", dev );
return 0;
}
if ( ioctl( devfd, IOCTL_GET_PRODUCT, &product ) < 0 ) {
printf( "IOCTL_GET_PRODUCT failed!!!\n" );
return 0;
}
if ( (product == 1) || (product == 0) ) {
printf("\nPort %s is AX99100 serial port.\n", dev);
} else {
printf("\nPort %s dose not support.\n", dev);
return 0;
}
if ( ioctl(devfd, IOCTL_GET_CUSTOM, &custom_baud ) < 0) {
printf("IOCTL_GET_CUSTOM failed!!!\n");
return 0;
}
if ( custom_baud == 0 )
printf("\nPort %s support standard baud rate\n", dev);
else
printf("\nPort %s support custom baud rate:%d\n", dev, custom_baud);
if ( product == 1 || product == 0 ) { // AX99100
while (1) {
printf("\nPlease specify the baud rate of %s.\n", dev);
printf("0 : Standard baud rate\n");
printf("1 : 1.1520 M\n");
printf("2 : 1.8382 M\n");
printf("3 : 3.6864 M\n");
printf("4 : 5.0000 M\n");
printf("5 : 7.8125 M\n");
printf("6 : 10.417 M\n");
printf("7 : 12.500 M\n");
printf("8 : 15.625 M\n");
printf("9 : 25.000 M\n");
printf("10 : 25.000 M\n");
printf("99 : Exit\n");
printf(":");
scanf("%d", &select);
//bit[27:20] = baud base clock
//bit[19:12] = DLM
//bit[11:4] = DLL
//bit[3:0] = sampling rate
parameter = 0;
if (select == 1) {
custom_baud = 1152000;
parameter |= CLK_125M << 20; //bit[27:20] = baud base clock
parameter |= 0 << 12; //bit[19:12] = DLM
parameter |= 4 << 4; //bit[11:4] = DLL
sampling_clock = 27; //bit[3:0] = sampling rate
break;
} else if (select == 2) {
custom_baud = 1843200;
parameter |= CLK_125M << 20; //bit[27:20] = baud base clock
parameter |= 0 << 12; //bit[19:12] = DLM
parameter |= 1 << 4; //bit[11:4] = DLL
sampling_clock = 68; //bit[3:0] = sampling rate
break;
} else if (select == 3) {
custom_baud = 3686400;
parameter |= CLK_125M << 20; //bit[27:20] = baud base clock
parameter |= 0 << 12; //bit[19:12] = DLM
parameter |= 1 << 4; //bit[11:4] = DLL
sampling_clock = 34; //bit[3:0] = sampling rate
break;
} else if (select == 4) {
custom_baud = 5000000;
parameter |= CLK_125M << 20; //bit[27:20] = baud base clock
parameter |= 0 << 12; //bit[19:12] = DLM
parameter |= 5 << 4; //bit[11:4] = DLL
sampling_clock = 5 ; //bit[3:0] = sampling rate
break;
} else if (select == 5) {
custom_baud = 7812500;
parameter |= CLK_125M << 20; //bit[27:20] = baud base clock
parameter |= 0 << 12; //bit[19:12] = DLM
parameter |= 1 << 4; //bit[11:4] = DLL
sampling_clock = 16 ; //bit[3:0] = sampling rate
break;
} else if (select == 6) {
custom_baud = 10416666;
parameter |= CLK_125M << 20; //bit[27:20] = baud base clock
parameter |= 0 << 12; //bit[19:12] = DLM
parameter |= 1 << 4; //bit[11:4] = DLL
sampling_clock = 12; //bit[3:0] = sampling rate
break;
} else if (select == 7) {
custom_baud = 12500000;
parameter |= CLK_125M << 20; //bit[27:20] = baud base clock
parameter |= 0 << 12; //bit[19:12] = DLM
parameter |= 10 << 4; //bit[11:4] = DLL
sampling_clock = 10; //bit[3:0] = sampling rate
break;
} else if (select == 8) {
custom_baud = 15625000;
parameter |= CLK_125M << 20; //bit[27:20] = baud base clock
parameter |= 0 << 12; //bit[19:12] = DLM
parameter |= 1 << 4; //bit[11:4] = DLL
sampling_clock = 8; //bit[3:0] = sampling rate
break;
} else if (select == 9) {
custom_baud = 25000000;
parameter |= CLK_125M << 20; //bit[27:20] = baud base clock
parameter |= 0 << 12; //bit[19:12] = DLM
parameter |= 1 << 4; //bit[11:4] = DLL
sampling_clock = 5; //bit[3:0] = sampling rate
break;
} else if (select == 10) {
custom_baud = 25000000;
parameter |= CLK_125M << 20; //bit[27:20] = baud base clock
parameter |= 0 << 12; //bit[19:12] = DLM
parameter |= 1 << 4; //bit[11:4] = DLL
sampling_clock = 5; //bit[3:0] = sampling rate
break;
} else if (select == 0) {
custom_baud = 0;
parameter |= CLK_1_8382M << 20; //bit[27:20] = baud base clock
// parameter |= 0 << 12; //bit[19:12] = DLM
parameter |= 1 << 4; //bit[11:4] = DLL
sampling_clock = 0; //bit[3:0] = sampling rate
break;
} else if (select == 99) {
return 0;
}
}
}
if (ioctl(devfd, IOCTL_SET_CUSTOM, custom_baud) < 0) {
printf("IOCTL_SET_CUSTOM failed!!!\n");
return 0;
}
if (ioctl(devfd, IOCTL_SET_PARAMETER, parameter) < 0) {
printf("IOCTL_SET_PARAMETER failed!!!\n");
return 0;
}
if (ioctl(devfd, IOCTL_SET_SAMPLING, sampling_clock) < 0) {
printf("IOCTL_SET_SAMPLING failed!!!\n");
return 0;
}
printf("The %s will operating in custom baud rate after open(re-open) it.\n", dev);
exit:
printf("\n");
return 0;
}