1 |
32985a29
|
laforge
|
/* OpenPICC Main Program
|
2 |
|
|
* (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
|
3 |
|
|
*
|
4 |
|
|
* This program is free software; you can redistribute it and/or modify
|
5 |
|
|
* it under the terms of the GNU General Public License as published by
|
6 |
|
|
* the Free Software Foundation; either version 2 of the License, or
|
7 |
|
|
* (at your option) any later version.
|
8 |
|
|
*
|
9 |
|
|
* This program is distributed in the hope that it will be useful,
|
10 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12 |
|
|
* GNU General Public License for more details.
|
13 |
|
|
*
|
14 |
|
|
* You should have received a copy of the GNU General Public License
|
15 |
|
|
* along with this program; if not, write to the Free Software
|
16 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17 |
|
|
*
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
|
21 |
5bf2bacd
|
(no author)
|
#include <errno.h>
|
22 |
|
|
#include <include/lib_AT91SAM7.h>
|
23 |
|
|
#include <include/openpcd.h>
|
24 |
|
|
#include <os/dbgu.h>
|
25 |
|
|
#include <os/led.h>
|
26 |
|
|
#include <os/pcd_enumerate.h>
|
27 |
|
|
#include <os/usb_handler.h>
|
28 |
|
|
#include "../openpcd.h"
|
29 |
|
|
#include <os/main.h>
|
30 |
3b42a77d
|
(no author)
|
#include <os/pwm.h>
|
31 |
|
|
#include <os/tc_cdiv.h>
|
32 |
d31e4fa6
|
(no author)
|
#include <os/pio_irq.h>
|
33 |
6c6b1878
|
laforge
|
#include <picc/da.h>
|
34 |
82a994e1
|
(no author)
|
#include <picc/pll.h>
|
35 |
d31e4fa6
|
(no author)
|
#include <picc/ssc_picc.h>
|
36 |
3b42a77d
|
(no author)
|
#include <picc/load_modulation.h>
|
37 |
|
|
|
38 |
373c172a
|
Harald Welte
|
static const uint16_t cdivs[] = { 8192, 2048, 1024, 512, 128, 64, 32, 16 };
|
39 |
|
|
static uint8_t cdiv_idx = 6;
|
40 |
3b42a77d
|
(no author)
|
|
41 |
373c172a
|
Harald Welte
|
static uint16_t duty_percent = 22;
|
42 |
3b42a77d
|
(no author)
|
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
|
43 |
373c172a
|
Harald Welte
|
static uint32_t pwm_freq[] = { 105937, 211875, 423750, 847500 };
|
44 |
|
|
static uint8_t pwm_freq_idx = 0;
|
45 |
3b42a77d
|
(no author)
|
|
46 |
373c172a
|
Harald Welte
|
static uint8_t load_mod = 0;
|
47 |
5bf2bacd
|
(no author)
|
|
48 |
10171996
|
laforge
|
#define DA_BASELINE 192
|
49 |
|
|
|
50 |
5bf2bacd
|
(no author)
|
void _init_func(void)
|
51 |
|
|
{
|
52 |
514b0f72
|
laforge
|
/* low-level hardware initialization */
|
53 |
d31e4fa6
|
(no author)
|
pio_irq_init();
|
54 |
82a994e1
|
(no author)
|
pll_init();
|
55 |
6c6b1878
|
laforge
|
da_init();
|
56 |
3b42a77d
|
(no author)
|
load_mod_init();
|
57 |
82a994e1
|
(no author)
|
tc_cdiv_init();
|
58 |
b7e11109
|
laforge
|
//tc_fdt_init();
|
59 |
3b42a77d
|
(no author)
|
pwm_init();
|
60 |
d31e4fa6
|
(no author)
|
adc_init();
|
61 |
|
|
ssc_rx_init();
|
62 |
28eb4a57
|
laforge
|
ssc_tx_init();
|
63 |
|
|
|
64 |
514b0f72
|
laforge
|
/* high-level protocol */
|
65 |
|
|
decoder_init();
|
66 |
|
|
opicc_usbapi_init();
|
67 |
d31e4fa6
|
(no author)
|
|
68 |
|
|
AT91F_PIO_CfgInput(AT91C_BASE_PIOA, OPENPICC_PIO_BOOTLDR);
|
69 |
10171996
|
laforge
|
da_comp_carr(DA_BASELINE);
|
70 |
5bf2bacd
|
(no author)
|
}
|
71 |
|
|
|
72 |
3b42a77d
|
(no author)
|
static void help(void)
|
73 |
|
|
{
|
74 |
6c6b1878
|
laforge
|
DEBUGPCR("q: da decrease w: da increase\r\n"
|
75 |
|
|
"e: da retransmit P: PLL inhibit toggle");
|
76 |
3b42a77d
|
(no author)
|
DEBUGPCR("o: decrease duty p: increase duty\r\n"
|
77 |
|
|
"k: stop pwm l: start pwn\r\n"
|
78 |
|
|
"n: decrease freq m: incresae freq");
|
79 |
|
|
DEBUGPCR("u: PA23 const 1 y: PA23 const 0\r\n"
|
80 |
d31e4fa6
|
(no author)
|
"t: PA23 PWM0 L: display PLL LOCK\r\n"
|
81 |
3b42a77d
|
(no author)
|
"{: decrease cdiv_idx }: increse cdiv idx\r\n"
|
82 |
|
|
"<: decrease cdiv_phase >: increase cdiv_phase");
|
83 |
d31e4fa6
|
(no author)
|
DEBUGPCR("v: decrease load_mod b: increase load_mod\r\n"
|
84 |
|
|
"B: read button S: toggle nSLAVE_RESET\r\n"
|
85 |
|
|
"a: SSC stop s: SSC start\r\n"
|
86 |
28eb4a57
|
laforge
|
"d: SSC mode select T: TC_CDIV_HELP enable\r\n");
|
87 |
3b42a77d
|
(no author)
|
}
|
88 |
|
|
|
89 |
5bf2bacd
|
(no author)
|
int _main_dbgu(char key)
|
90 |
|
|
{
|
91 |
373c172a
|
Harald Welte
|
static uint8_t poti = DA_BASELINE;
|
92 |
|
|
static uint8_t pll_inh = 1;
|
93 |
|
|
static uint8_t ssc_mode = 1;
|
94 |
|
|
static uint8_t sync_enabled = 0;
|
95 |
71de0ff0
|
(no author)
|
|
96 |
|
|
DEBUGPCRF("main_dbgu");
|
97 |
5bf2bacd
|
(no author)
|
|
98 |
|
|
switch (key) {
|
99 |
71de0ff0
|
(no author)
|
case 'q':
|
100 |
|
|
if (poti > 0)
|
101 |
|
|
poti--;
|
102 |
6c6b1878
|
laforge
|
da_comp_carr(poti);
|
103 |
|
|
DEBUGPCRF("DA: %u", poti);
|
104 |
71de0ff0
|
(no author)
|
break;
|
105 |
|
|
case 'w':
|
106 |
6c6b1878
|
laforge
|
if (poti < 255)
|
107 |
71de0ff0
|
(no author)
|
poti++;
|
108 |
6c6b1878
|
laforge
|
da_comp_carr(poti);
|
109 |
|
|
DEBUGPCRF("DA: %u", poti);
|
110 |
71de0ff0
|
(no author)
|
break;
|
111 |
|
|
case 'e':
|
112 |
6c6b1878
|
laforge
|
da_comp_carr(poti);
|
113 |
|
|
DEBUGPCRF("DA: %u", poti);
|
114 |
5bf2bacd
|
(no author)
|
break;
|
115 |
3b42a77d
|
(no author)
|
case 'P':
|
116 |
82a994e1
|
(no author)
|
pll_inh++;
|
117 |
|
|
pll_inh &= 0x01;
|
118 |
|
|
pll_inhibit(pll_inh);
|
119 |
d31e4fa6
|
(no author)
|
DEBUGPCRF("PLL Inhibit: %u", pll_inh);
|
120 |
|
|
break;
|
121 |
|
|
case 'L':
|
122 |
|
|
DEBUGPCRF("PLL Lock: %u", pll_is_locked());
|
123 |
82a994e1
|
(no author)
|
break;
|
124 |
3b42a77d
|
(no author)
|
case 'o':
|
125 |
|
|
if (duty_percent >= 1)
|
126 |
|
|
duty_percent--;
|
127 |
|
|
pwm_duty_set_percent(0, duty_percent);
|
128 |
|
|
break;
|
129 |
|
|
case 'p':
|
130 |
|
|
if (duty_percent <= 99)
|
131 |
|
|
duty_percent++;
|
132 |
|
|
pwm_duty_set_percent(0, duty_percent);
|
133 |
|
|
break;
|
134 |
|
|
case 'k':
|
135 |
|
|
pwm_stop(0);
|
136 |
|
|
break;
|
137 |
|
|
case 'l':
|
138 |
|
|
pwm_start(0);
|
139 |
|
|
break;
|
140 |
|
|
case 'n':
|
141 |
|
|
if (pwm_freq_idx > 0) {
|
142 |
|
|
pwm_freq_idx--;
|
143 |
|
|
pwm_stop(0);
|
144 |
|
|
pwm_freq_set(0, pwm_freq[pwm_freq_idx]);
|
145 |
|
|
pwm_start(0);
|
146 |
|
|
pwm_duty_set_percent(0, 22); /* 22% of 9.43uS = 2.07uS */
|
147 |
|
|
}
|
148 |
|
|
break;
|
149 |
|
|
case 'm':
|
150 |
|
|
if (pwm_freq_idx < ARRAY_SIZE(pwm_freq)-1) {
|
151 |
|
|
pwm_freq_idx++;
|
152 |
|
|
pwm_stop(0);
|
153 |
|
|
pwm_freq_set(0, pwm_freq[pwm_freq_idx]);
|
154 |
|
|
pwm_start(0);
|
155 |
|
|
pwm_duty_set_percent(0, 22); /* 22% of 9.43uS = 2.07uS */
|
156 |
|
|
}
|
157 |
|
|
break;
|
158 |
|
|
case 'u':
|
159 |
|
|
DEBUGPCRF("PA23 output high");
|
160 |
|
|
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, AT91C_PIO_PA23);
|
161 |
|
|
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, AT91C_PIO_PA23);
|
162 |
|
|
break;
|
163 |
|
|
case 'y':
|
164 |
|
|
DEBUGPCRF("PA23 output low");
|
165 |
|
|
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, AT91C_PIO_PA23);
|
166 |
|
|
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, AT91C_PIO_PA23);
|
167 |
|
|
break;
|
168 |
|
|
case 't':
|
169 |
|
|
DEBUGPCRF("PA23 PeriphA (PWM)");
|
170 |
|
|
AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, 0, AT91C_PA23_PWM0);
|
171 |
|
|
break;
|
172 |
|
|
case '?':
|
173 |
|
|
help();
|
174 |
|
|
break;
|
175 |
|
|
case '<':
|
176 |
|
|
tc_cdiv_phase_inc();
|
177 |
|
|
break;
|
178 |
82a994e1
|
(no author)
|
case '>':
|
179 |
3b42a77d
|
(no author)
|
tc_cdiv_phase_dec();
|
180 |
|
|
break;
|
181 |
|
|
case '{':
|
182 |
|
|
if (cdiv_idx > 0)
|
183 |
|
|
cdiv_idx--;
|
184 |
|
|
tc_cdiv_set_divider(cdivs[cdiv_idx]);
|
185 |
|
|
break;
|
186 |
|
|
case '}':
|
187 |
|
|
if (cdiv_idx < ARRAY_SIZE(cdivs)-1)
|
188 |
|
|
cdiv_idx++;
|
189 |
|
|
tc_cdiv_set_divider(cdivs[cdiv_idx]);
|
190 |
|
|
break;
|
191 |
|
|
case 'v':
|
192 |
|
|
if (load_mod > 0)
|
193 |
|
|
load_mod--;
|
194 |
|
|
load_mod_level(load_mod);
|
195 |
|
|
DEBUGPCR("load_mod: %u\n", load_mod);
|
196 |
|
|
break;
|
197 |
|
|
case 'b':
|
198 |
|
|
if (load_mod < 3)
|
199 |
|
|
load_mod++;
|
200 |
|
|
load_mod_level(load_mod);
|
201 |
|
|
DEBUGPCR("load_mod: %u\n", load_mod);
|
202 |
5bf2bacd
|
(no author)
|
break;
|
203 |
d31e4fa6
|
(no author)
|
case 'B':
|
204 |
|
|
DEBUGPCRF("Button status: %u\n",
|
205 |
|
|
AT91F_PIO_IsInputSet(AT91C_BASE_PIOA, AT91F_PIO_IsInputSet));
|
206 |
|
|
break;
|
207 |
|
|
case 'S':
|
208 |
|
|
if (AT91F_PIO_IsOutputSet(AT91C_BASE_PIOA, OPENPICC_PIO_nSLAVE_RESET)) {
|
209 |
|
|
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_nSLAVE_RESET);
|
210 |
|
|
DEBUGPCRF("nSLAVE_RESET == LOW");
|
211 |
|
|
} else {
|
212 |
|
|
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_nSLAVE_RESET);
|
213 |
|
|
DEBUGPCRF("nSLAVE_RESET == HIGH");
|
214 |
|
|
}
|
215 |
|
|
break;
|
216 |
|
|
case 'a':
|
217 |
|
|
DEBUGPCRF("SSC RX STOP");
|
218 |
|
|
ssc_rx_stop();
|
219 |
|
|
break;
|
220 |
|
|
case 's':
|
221 |
|
|
DEBUGPCRF("SSC RX START");
|
222 |
|
|
ssc_rx_start();
|
223 |
|
|
break;
|
224 |
|
|
case 'd':
|
225 |
28eb4a57
|
laforge
|
ssc_mode++;
|
226 |
|
|
if (ssc_mode >= 6)
|
227 |
|
|
ssc_mode = 0;
|
228 |
|
|
ssc_rx_mode_set(ssc_mode);
|
229 |
d31e4fa6
|
(no author)
|
DEBUGPCRF("SSC MODE %u", ssc_mode);
|
230 |
|
|
break;
|
231 |
28eb4a57
|
laforge
|
case 'T':
|
232 |
|
|
if (sync_enabled) {
|
233 |
|
|
tc_cdiv_sync_disable();
|
234 |
|
|
sync_enabled = 0;
|
235 |
|
|
} else {
|
236 |
|
|
tc_cdiv_sync_enable();
|
237 |
|
|
sync_enabled = 1;
|
238 |
|
|
}
|
239 |
|
|
break;
|
240 |
5bf2bacd
|
(no author)
|
}
|
241 |
|
|
|
242 |
d31e4fa6
|
(no author)
|
tc_cdiv_print();
|
243 |
28eb4a57
|
laforge
|
//tc_fdt_print();
|
244 |
6c6b1878
|
laforge
|
ssc_print();
|
245 |
d31e4fa6
|
(no author)
|
|
246 |
5bf2bacd
|
(no author)
|
return -EINVAL;
|
247 |
|
|
}
|
248 |
|
|
|
249 |
|
|
void _main_func(void)
|
250 |
|
|
{
|
251 |
|
|
/* first we try to get rid of pending to-be-sent stuff */
|
252 |
|
|
usb_out_process();
|
253 |
|
|
|
254 |
8ac31009
|
Holger Hans Peter Freyther
|
/* next we deal with incoming requests from USB EP1 (OUT) */
|
255 |
5bf2bacd
|
(no author)
|
usb_in_process();
|
256 |
|
|
|
257 |
28eb4a57
|
laforge
|
udp_unthrottle();
|
258 |
d31e4fa6
|
(no author)
|
ssc_rx_unthrottle();
|
259 |
5bf2bacd
|
(no author)
|
}
|