2 * Copyright © 2008 Keith Packard <keithp@keithp.com>
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.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 get_bit(char *line, int i, char on, uint8_t bit)
28 fprintf(stderr, "bad line %s\n", line);
33 is_bit(uint8_t get, char on, uint8_t bit)
42 ccdbg_write_read(struct ccdbg *dbg, uint8_t set)
46 cccp_write(dbg, CC_DATA|CC_CLOCK|CC_RESET_N, set);
47 get = cccp_read_all(dbg);
48 printf("%c %c %c -> %c %c %c\n",
49 is_bit(set, 'C', CC_CLOCK),
50 is_bit(set, 'D', CC_DATA),
51 is_bit(set, 'R', CC_RESET_N),
52 is_bit(get, 'C', CC_CLOCK),
53 is_bit(get, 'D', CC_DATA),
54 is_bit(get, 'R', CC_RESET_N));
55 ccdbg_half_clock(dbg);
60 _ccdbg_debug_mode(struct ccdbg *dbg)
62 ccdbg_write_read(dbg, CC_CLOCK|CC_DATA|CC_RESET_N);
63 ccdbg_write_read(dbg, CC_DATA );
64 ccdbg_write_read(dbg, CC_CLOCK|CC_DATA );
65 ccdbg_write_read(dbg, CC_DATA );
66 ccdbg_write_read(dbg, CC_CLOCK|CC_DATA );
67 ccdbg_write_read(dbg, CC_DATA|CC_RESET_N);
71 _ccdbg_reset(struct ccdbg *dbg)
73 ccdbg_write_read(dbg, CC_CLOCK|CC_DATA|CC_RESET_N);
74 ccdbg_write_read(dbg, CC_CLOCK|CC_DATA );
75 ccdbg_write_read(dbg, CC_CLOCK|CC_DATA );
76 ccdbg_write_read(dbg, CC_CLOCK|CC_DATA|CC_RESET_N);
80 ccdbg_manual(struct ccdbg *dbg, FILE *input)
85 while (fgets(line, sizeof line, input)) {
86 if (line[0] == '#' || line[0] == '\n') {
91 set |= get_bit(line, 0, 'C', CC_CLOCK);
92 set |= get_bit(line, 2, 'D', CC_DATA);
93 set |= get_bit(line, 4, 'R', CC_RESET_N);
94 ccdbg_write_read(dbg, set);
99 main (int argc, char **argv)
105 dbg = ccdbg_open("/dev/ttyUSB0");
108 ccdbg_manual(dbg, stdin);
110 ccdbg_debug_mode(dbg);
111 status = ccdbg_read_status(dbg);
112 printf("Status: 0x%02x\n", status);
113 chip_id = ccdbg_get_chip_id(dbg);
114 printf("Chip id: 0x%04x\n", chip_id);