Project

General

Profile

Download (6.06 KB) Statistics
| Branch: | Tag: | Revision:
1
/* 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
#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
#include <os/pwm.h>
31
#include <os/tc_cdiv.h>
32
#include <os/pio_irq.h>
33
#include <picc/da.h>
34
#include <picc/pll.h>
35
#include <picc/ssc_picc.h>
36
#include <picc/load_modulation.h>
37

    
38
static const uint16_t cdivs[] = { 8192, 2048, 1024, 512, 128, 64, 32, 16 };
39
static uint8_t cdiv_idx = 6;
40

    
41
static uint16_t duty_percent = 22;
42
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
43
static uint32_t pwm_freq[] = { 105937, 211875, 423750, 847500 };
44
static uint8_t pwm_freq_idx = 0;
45

    
46
static uint8_t load_mod = 0;
47

    
48
#define DA_BASELINE 192
49

    
50
void _init_func(void)
51
{
52
	/* low-level hardware initialization */
53
	pio_irq_init();
54
	pll_init();
55
	da_init();
56
	load_mod_init();
57
	tc_cdiv_init();
58
	//tc_fdt_init();
59
	pwm_init();
60
	adc_init();
61
	ssc_rx_init();
62
	ssc_tx_init();
63

    
64
	/* high-level protocol */
65
	decoder_init();
66
	opicc_usbapi_init();
67

    
68
	AT91F_PIO_CfgInput(AT91C_BASE_PIOA, OPENPICC_PIO_BOOTLDR);
69
	da_comp_carr(DA_BASELINE);
70
}
71

    
72
static void help(void)
73
{
74
	DEBUGPCR("q: da decrease       w: da increase\r\n"
75
		 "e: da retransmit     P: PLL inhibit toggle");
76
	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
		 "t: PA23 PWM0           L: display PLL LOCK\r\n"
81
		 "{: decrease cdiv_idx   }: increse cdiv idx\r\n"
82
		 "<: decrease cdiv_phase >: increase cdiv_phase");
83
	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
		 "d: SSC mode select     T: TC_CDIV_HELP enable\r\n");
87
}
88

    
89
int _main_dbgu(char key)
90
{
91
	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

    
96
	DEBUGPCRF("main_dbgu");
97

    
98
	switch (key) {
99
	case 'q':
100
		if (poti > 0)
101
			poti--;
102
		da_comp_carr(poti);
103
		DEBUGPCRF("DA: %u", poti);
104
		break;
105
	case 'w':
106
		if (poti < 255)
107
			poti++;
108
		da_comp_carr(poti);
109
		DEBUGPCRF("DA: %u", poti);
110
		break;
111
	case 'e':
112
		da_comp_carr(poti);
113
		DEBUGPCRF("DA: %u", poti);
114
		break;
115
	case 'P':
116
		pll_inh++;
117
		pll_inh &= 0x01;
118
		pll_inhibit(pll_inh);
119
		DEBUGPCRF("PLL Inhibit: %u", pll_inh);
120
		break;
121
	case 'L':
122
		DEBUGPCRF("PLL Lock: %u", pll_is_locked());
123
		break;
124
	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
	case '>':
179
		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
		break;
203
	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
		ssc_mode++;
226
		if (ssc_mode >= 6)
227
			ssc_mode = 0;
228
		ssc_rx_mode_set(ssc_mode);
229
		DEBUGPCRF("SSC MODE %u", ssc_mode);
230
		break;
231
	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
	}
241

    
242
	tc_cdiv_print();
243
	//tc_fdt_print();
244
	ssc_print();
245

    
246
	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
	/* next we deal with incoming requests from USB EP1 (OUT) */
255
	usb_in_process();
256

    
257
	udp_unthrottle();
258
	ssc_rx_unthrottle();
259
}
(11-11/26)
Add picture from clipboard (Maximum size: 48.8 MB)