0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/jiffies.h>
0013 #include <linux/sched.h>
0014 #include <linux/timer.h>
0015 #include <linux/kthread.h>
0016 #include <linux/serial_reg.h> /* for UART_MCR* constants */
0017
0018 #include "spk_priv.h"
0019 #include "speakup.h"
0020
0021 #define DRV_VERSION "2.21"
0022 #define SYNTH_CLEAR 0x18
0023 #define PROCSPEECH '\r'
0024
0025 static void do_catch_up(struct spk_synth *synth);
0026
0027 static struct var_t vars[] = {
0028 { CAPS_START, .u.s = {"cap, " } },
0029 { CAPS_STOP, .u.s = {"" } },
0030 { RATE, .u.n = {"@W%d", 6, 1, 9, 0, 0, NULL } },
0031 { PITCH, .u.n = {"@F%x", 10, 0, 15, 0, 0, NULL } },
0032 { VOL, .u.n = {"@A%x", 10, 0, 15, 0, 0, NULL } },
0033 { VOICE, .u.n = {"@V%d", 1, 1, 6, 0, 0, NULL } },
0034 { LANG, .u.n = {"@=%d,", 1, 1, 4, 0, 0, NULL } },
0035 { DIRECT, .u.n = {NULL, 0, 0, 1, 0, 0, NULL } },
0036 V_LAST_VAR
0037 };
0038
0039
0040
0041
0042 static struct kobj_attribute caps_start_attribute =
0043 __ATTR(caps_start, 0644, spk_var_show, spk_var_store);
0044 static struct kobj_attribute caps_stop_attribute =
0045 __ATTR(caps_stop, 0644, spk_var_show, spk_var_store);
0046 static struct kobj_attribute lang_attribute =
0047 __ATTR(lang, 0644, spk_var_show, spk_var_store);
0048 static struct kobj_attribute pitch_attribute =
0049 __ATTR(pitch, 0644, spk_var_show, spk_var_store);
0050 static struct kobj_attribute rate_attribute =
0051 __ATTR(rate, 0644, spk_var_show, spk_var_store);
0052 static struct kobj_attribute voice_attribute =
0053 __ATTR(voice, 0644, spk_var_show, spk_var_store);
0054 static struct kobj_attribute vol_attribute =
0055 __ATTR(vol, 0644, spk_var_show, spk_var_store);
0056
0057 static struct kobj_attribute delay_time_attribute =
0058 __ATTR(delay_time, 0644, spk_var_show, spk_var_store);
0059 static struct kobj_attribute direct_attribute =
0060 __ATTR(direct, 0644, spk_var_show, spk_var_store);
0061 static struct kobj_attribute full_time_attribute =
0062 __ATTR(full_time, 0644, spk_var_show, spk_var_store);
0063 static struct kobj_attribute jiffy_delta_attribute =
0064 __ATTR(jiffy_delta, 0644, spk_var_show, spk_var_store);
0065 static struct kobj_attribute trigger_time_attribute =
0066 __ATTR(trigger_time, 0644, spk_var_show, spk_var_store);
0067
0068
0069
0070
0071
0072 static struct attribute *synth_attrs[] = {
0073 &caps_start_attribute.attr,
0074 &caps_stop_attribute.attr,
0075 &lang_attribute.attr,
0076 &pitch_attribute.attr,
0077 &rate_attribute.attr,
0078 &voice_attribute.attr,
0079 &vol_attribute.attr,
0080 &delay_time_attribute.attr,
0081 &direct_attribute.attr,
0082 &full_time_attribute.attr,
0083 &jiffy_delta_attribute.attr,
0084 &trigger_time_attribute.attr,
0085 NULL,
0086 };
0087
0088 static struct spk_synth synth_apollo = {
0089 .name = "apollo",
0090 .version = DRV_VERSION,
0091 .long_name = "Apollo",
0092 .init = "@R3@D0@K1\r",
0093 .procspeech = PROCSPEECH,
0094 .clear = SYNTH_CLEAR,
0095 .delay = 500,
0096 .trigger = 50,
0097 .jiffies = 50,
0098 .full = 40000,
0099 .dev_name = SYNTH_DEFAULT_DEV,
0100 .startup = SYNTH_START,
0101 .checkval = SYNTH_CHECK,
0102 .vars = vars,
0103 .io_ops = &spk_ttyio_ops,
0104 .probe = spk_ttyio_synth_probe,
0105 .release = spk_ttyio_release,
0106 .synth_immediate = spk_ttyio_synth_immediate,
0107 .catch_up = do_catch_up,
0108 .flush = spk_synth_flush,
0109 .is_alive = spk_synth_is_alive_restart,
0110 .synth_adjust = NULL,
0111 .read_buff_add = NULL,
0112 .get_index = NULL,
0113 .indexing = {
0114 .command = NULL,
0115 .lowindex = 0,
0116 .highindex = 0,
0117 .currindex = 0,
0118 },
0119 .attributes = {
0120 .attrs = synth_attrs,
0121 .name = "apollo",
0122 },
0123 };
0124
0125 static void do_catch_up(struct spk_synth *synth)
0126 {
0127 u_char ch;
0128 unsigned long flags;
0129 unsigned long jiff_max;
0130 struct var_t *jiffy_delta;
0131 struct var_t *delay_time;
0132 struct var_t *full_time;
0133 int full_time_val = 0;
0134 int delay_time_val = 0;
0135 int jiffy_delta_val = 0;
0136
0137 jiffy_delta = spk_get_var(JIFFY);
0138 delay_time = spk_get_var(DELAY);
0139 full_time = spk_get_var(FULL);
0140 spin_lock_irqsave(&speakup_info.spinlock, flags);
0141 jiffy_delta_val = jiffy_delta->u.n.value;
0142 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0143 jiff_max = jiffies + jiffy_delta_val;
0144
0145 while (!kthread_should_stop()) {
0146 spin_lock_irqsave(&speakup_info.spinlock, flags);
0147 jiffy_delta_val = jiffy_delta->u.n.value;
0148 full_time_val = full_time->u.n.value;
0149 delay_time_val = delay_time->u.n.value;
0150 if (speakup_info.flushing) {
0151 speakup_info.flushing = 0;
0152 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0153 synth->flush(synth);
0154 continue;
0155 }
0156 synth_buffer_skip_nonlatin1();
0157 if (synth_buffer_empty()) {
0158 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0159 break;
0160 }
0161 ch = synth_buffer_peek();
0162 set_current_state(TASK_INTERRUPTIBLE);
0163 full_time_val = full_time->u.n.value;
0164 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0165 if (!synth->io_ops->synth_out(synth, ch)) {
0166 synth->io_ops->tiocmset(synth, 0, UART_MCR_RTS);
0167 synth->io_ops->tiocmset(synth, UART_MCR_RTS, 0);
0168 schedule_timeout(msecs_to_jiffies(full_time_val));
0169 continue;
0170 }
0171 if (time_after_eq(jiffies, jiff_max) && (ch == SPACE)) {
0172 spin_lock_irqsave(&speakup_info.spinlock, flags);
0173 jiffy_delta_val = jiffy_delta->u.n.value;
0174 full_time_val = full_time->u.n.value;
0175 delay_time_val = delay_time->u.n.value;
0176 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0177 if (synth->io_ops->synth_out(synth, synth->procspeech))
0178 schedule_timeout(msecs_to_jiffies
0179 (delay_time_val));
0180 else
0181 schedule_timeout(msecs_to_jiffies
0182 (full_time_val));
0183 jiff_max = jiffies + jiffy_delta_val;
0184 }
0185 set_current_state(TASK_RUNNING);
0186 spin_lock_irqsave(&speakup_info.spinlock, flags);
0187 synth_buffer_getc();
0188 spin_unlock_irqrestore(&speakup_info.spinlock, flags);
0189 }
0190 synth->io_ops->synth_out(synth, PROCSPEECH);
0191 }
0192
0193 module_param_named(ser, synth_apollo.ser, int, 0444);
0194 module_param_named(dev, synth_apollo.dev_name, charp, 0444);
0195 module_param_named(start, synth_apollo.startup, short, 0444);
0196
0197 MODULE_PARM_DESC(ser, "Set the serial port for the synthesizer (0-based).");
0198 MODULE_PARM_DESC(dev, "Set the device e.g. ttyUSB0, for the synthesizer.");
0199 MODULE_PARM_DESC(start, "Start the synthesizer once it is loaded.");
0200
0201 module_spk_synth(synth_apollo);
0202
0203 MODULE_AUTHOR("Kirk Reiser <kirk@braille.uwo.ca>");
0204 MODULE_AUTHOR("David Borowski");
0205 MODULE_DESCRIPTION("Speakup support for Apollo II synthesizer");
0206 MODULE_LICENSE("GPL");
0207 MODULE_VERSION(DRV_VERSION);
0208