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#include <linux/unistd.h>
26#include <linux/proc_fs.h>
27#include <linux/jiffies.h>
28#include <linux/spinlock.h>
29#include <linux/sched.h>
30#include <linux/timer.h>
31#include <linux/kthread.h>
32#include "speakup.h"
33#include "spk_priv.h"
34#include "serialio.h"
35
36#define DRV_VERSION "2.20"
37#define SYNTH_CLEAR 0x03
38#define PROCSPEECH 0x0b
39static int xoff;
40
41static inline int synth_full(void)
42{
43 return xoff;
44}
45
46static void do_catch_up(struct spk_synth *synth);
47static void synth_flush(struct spk_synth *synth);
48static void read_buff_add(u_char c);
49static unsigned char get_index(void);
50
51static int in_escape;
52static int is_flushing;
53
54static spinlock_t flush_lock;
55static DECLARE_WAIT_QUEUE_HEAD(flush);
56
57static struct var_t vars[] = {
58 { CAPS_START, .u.s = {"[:dv ap 160] " } },
59 { CAPS_STOP, .u.s = {"[:dv ap 100 ] " } },
60 { RATE, .u.n = {"[:ra %d] ", 180, 75, 650, 0, 0, NULL } },
61 { PITCH, .u.n = {"[:dv ap %d] ", 122, 50, 350, 0, 0, NULL } },
62 { VOL, .u.n = {"[:dv g5 %d] ", 86, 60, 86, 0, 0, NULL } },
63 { PUNCT, .u.n = {"[:pu %c] ", 0, 0, 2, 0, 0, "nsa" } },
64 { VOICE, .u.n = {"[:n%c] ", 0, 0, 9, 0, 0, "phfdburwkv" } },
65 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
66 V_LAST_VAR
67};
68
69
70
71
72static struct kobj_attribute caps_start_attribute =
73 __ATTR(caps_start, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
74static struct kobj_attribute caps_stop_attribute =
75 __ATTR(caps_stop, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
76static struct kobj_attribute pitch_attribute =
77 __ATTR(pitch, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
78static struct kobj_attribute punct_attribute =
79 __ATTR(punct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
80static struct kobj_attribute rate_attribute =
81 __ATTR(rate, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
82static struct kobj_attribute voice_attribute =
83 __ATTR(voice, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
84static struct kobj_attribute vol_attribute =
85 __ATTR(vol, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
86
87static struct kobj_attribute delay_time_attribute =
88 __ATTR(delay_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
89static struct kobj_attribute direct_attribute =
90 __ATTR(direct, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
91static struct kobj_attribute full_time_attribute =
92 __ATTR(full_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
93static struct kobj_attribute jiffy_delta_attribute =
94 __ATTR(jiffy_delta, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
95static struct kobj_attribute trigger_time_attribute =
96 __ATTR(trigger_time, S_IWUSR|S_IRUGO, spk_var_show, spk_var_store);
97
98
99
100
101
102static struct attribute *synth_attrs[] = {
103 &caps_start_attribute.attr,
104 &caps_stop_attribute.attr,
105 &pitch_attribute.attr,
106 &punct_attribute.attr,
107 &rate_attribute.attr,
108 &voice_attribute.attr,
109 &vol_attribute.attr,
110 &delay_time_attribute.attr,
111 &direct_attribute.attr,
112 &full_time_attribute.attr,
113 &jiffy_delta_attribute.attr,
114 &trigger_time_attribute.attr,
115 NULL,
116};
117
118static int ap_defaults[] = {122, 89, 155, 110, 208, 240, 200, 106, 306};
119static int g5_defaults[] = {86, 81, 86, 84, 81, 80, 83, 83, 73};
120
121static struct spk_synth synth_dectlk = {
122 .name = "dectlk",
123 .version = DRV_VERSION,
124 .long_name = "Dectalk Express",
125 .init = "[:error sp :name paul :rate 180 :tsr off] ",
126 .procspeech = PROCSPEECH,
127 .clear = SYNTH_CLEAR,
128 .delay = 500,
129 .trigger = 50,
130 .jiffies = 50,
131 .full = 40000,
132 .startup = SYNTH_START,
133 .checkval = SYNTH_CHECK,
134 .vars = vars,
135 .default_pitch = ap_defaults,
136 .default_vol = g5_defaults,
137 .probe = spk_serial_synth_probe,
138 .release = spk_serial_release,
139 .synth_immediate = spk_synth_immediate,
140 .catch_up = do_catch_up,
141 .flush = synth_flush,
142 .is_alive = spk_synth_is_alive_restart,
143 .synth_adjust = NULL,
144 .read_buff_add = read_buff_add,
145 .get_index = get_index,
146 .indexing = {
147 .command = "[:in re %d ] ",
148 .lowindex = 1,
149 .highindex = 8,
150 .currindex = 1,
151 },
152 .attributes = {
153 .attrs = synth_attrs,
154 .name = "dectlk",
155 },
156};
157
158static int is_indnum(u_char *ch)
159{
160 if ((*ch >= '0') && (*ch <= '9')) {
161 *ch = *ch - '0';
162 return 1;
163 }
164 return 0;
165}
166
167static u_char lastind;
168
169static unsigned char get_index(void)
170{
171 u_char rv;
172 rv = lastind;
173 lastind = 0;
174 return rv;
175}
176
177static void read_buff_add(u_char c)
178{
179 static int ind = -1;
180
181 if (c == 0x01) {
182 unsigned long flags;
183 spin_lock_irqsave(&flush_lock, flags);
184 is_flushing = 0;
185 wake_up_interruptible(&flush);
186 spin_unlock_irqrestore(&flush_lock, flags);
187 } else if (c == 0x13) {
188 xoff = 1;
189 } else if (c == 0x11) {
190 xoff = 0;
191 } else if (is_indnum(&c)) {
192 if (ind == -1)
193 ind = c;
194 else
195 ind = ind * 10 + c;
196 } else if ((c > 31) && (c < 127)) {
197 if (ind != -1)
198 lastind = (u_char)ind;
199 ind = -1;
200 }
201}
202
203static void do_catch_up(struct spk_synth *synth)
204{
205 int synth_full_val = 0;
206 static u_char ch;
207 static u_char last = '\0';
208 unsigned long flags;
209 unsigned long jiff_max;
210 unsigned long timeout = msecs_to_jiffies(4000);
211 DEFINE_WAIT(wait);
212 struct var_t *jiffy_delta;
213 struct var_t *delay_time;
214 int jiffy_delta_val;
215 int delay_time_val;
216
217 jiffy_delta = spk_get_var(JIFFY);
218 delay_time = spk_get_var(DELAY);
219 spin_lock_irqsave(&speakup_info.spinlock, flags);
220 jiffy_delta_val = jiffy_delta->u.n.value;
221 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
222 jiff_max = jiffies + jiffy_delta_val;
223
224 while (!kthread_should_stop()) {
225
226 spin_lock_irqsave(&flush_lock, flags);
227 while (is_flushing && timeout) {
228 prepare_to_wait(&flush, &wait, TASK_INTERRUPTIBLE);
229 spin_unlock_irqrestore(&flush_lock, flags);
230 timeout = schedule_timeout(timeout);
231 spin_lock_irqsave(&flush_lock, flags);
232 }
233 finish_wait(&flush, &wait);
234 is_flushing = 0;
235 spin_unlock_irqrestore(&flush_lock, flags);
236
237 spin_lock_irqsave(&speakup_info.spinlock, flags);
238 if (speakup_info.flushing) {
239 speakup_info.flushing = 0;
240 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
241 synth->flush(synth);
242 continue;
243 }
244 if (synth_buffer_empty()) {
245 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
246 break;
247 }
248 ch = synth_buffer_peek();
249 set_current_state(TASK_INTERRUPTIBLE);
250 delay_time_val = delay_time->u.n.value;
251 synth_full_val = synth_full();
252 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
253 if (ch == '\n')
254 ch = 0x0D;
255 if (synth_full_val || !spk_serial_out(ch)) {
256 schedule_timeout(msecs_to_jiffies(delay_time_val));
257 continue;
258 }
259 set_current_state(TASK_RUNNING);
260 spin_lock_irqsave(&speakup_info.spinlock, flags);
261 synth_buffer_getc();
262 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
263 if (ch == '[')
264 in_escape = 1;
265 else if (ch == ']')
266 in_escape = 0;
267 else if (ch <= SPACE) {
268 if (!in_escape && strchr(",.!?;:", last))
269 spk_serial_out(PROCSPEECH);
270 if (jiffies >= jiff_max) {
271 if (!in_escape)
272 spk_serial_out(PROCSPEECH);
273 spin_lock_irqsave(&speakup_info.spinlock,
274 flags);
275 jiffy_delta_val = jiffy_delta->u.n.value;
276 delay_time_val = delay_time->u.n.value;
277 spin_unlock_irqrestore(&speakup_info.spinlock,
278 flags);
279 schedule_timeout(msecs_to_jiffies
280 (delay_time_val));
281 jiff_max = jiffies + jiffy_delta_val;
282 }
283 }
284 last = ch;
285 }
286 if (!in_escape)
287 spk_serial_out(PROCSPEECH);
288}
289
290static void synth_flush(struct spk_synth *synth)
291{
292 if (in_escape) {
293
294 spk_serial_out(']');
295 }
296 in_escape = 0;
297 is_flushing = 1;
298 spk_serial_out(SYNTH_CLEAR);
299}
300
301module_param_named(ser, synth_dectlk.ser, int, S_IRUGO);
302module_param_named(start, synth_dectlk.startup, short, S_IRUGO);
303
304MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
305MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
306
307static int __init dectlk_init(void)
308{
309 return synth_add(&synth_dectlk);
310}
311
312static void __exit dectlk_exit(void)
313{
314 synth_remove(&synth_dectlk);
315}
316
317module_init(dectlk_init);
318module_exit(dectlk_exit);
319MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
320MODULE_AUTHOR("David Borowski");
321MODULE_DESCRIPTION("Speakup support for DECtalk Express synthesizers");
322MODULE_LICENSE("GPL");
323MODULE_VERSION(DRV_VERSION);
324
325