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 #include "cc-bitbang.h"
29 dbg = calloc(sizeof (struct ccdbg), 1);
35 tty = getenv("ALTOS_TTY");
39 if (!strcmp(tty, "BITBANG")) {
40 dbg->bb = cc_bitbang_open();
46 dbg->usb = cc_usb_open(tty);
56 ccdbg_close(struct ccdbg *dbg)
59 cc_usb_close(dbg->usb);
61 cc_bitbang_close(dbg->bb);
66 ccdbg_debug_mode(struct ccdbg *dbg)
69 cc_usb_debug_mode(dbg->usb);
71 cc_bitbang_debug_mode(dbg->bb);
75 ccdbg_reset(struct ccdbg *dbg)
78 cc_usb_reset(dbg->usb);
80 cc_bitbang_reset(dbg->bb);
84 ccdbg_send_bytes(struct ccdbg *dbg, uint8_t *bytes, int nbytes)
87 cc_usb_send_bytes(dbg->usb, bytes, nbytes);
89 cc_bitbang_send_bytes(dbg->bb, bytes, nbytes);
93 ccdbg_recv_bytes(struct ccdbg *dbg, uint8_t *bytes, int nbytes)
96 cc_usb_recv_bytes(dbg->usb, bytes, nbytes);
98 cc_bitbang_recv_bytes(dbg->bb, bytes, nbytes);
102 ccdbg_sync(struct ccdbg *dbg)
105 cc_usb_sync(dbg->usb);
107 cc_bitbang_sync(dbg->bb);
111 ccdbg_cmd_write(struct ccdbg *dbg, uint8_t cmd, uint8_t *data, int len)
113 ccdbg_send_bytes(dbg, &cmd, 1);
114 ccdbg_send_bytes(dbg, data, len);
118 ccdbg_cmd_write_read8(struct ccdbg *dbg, uint8_t cmd, uint8_t *data, int len)
121 ccdbg_cmd_write(dbg, cmd, data, len);
122 ccdbg_recv_bytes(dbg, byte, 1);
128 ccdbg_cmd_write_read16(struct ccdbg *dbg, uint8_t cmd, uint8_t *data, int len)
131 ccdbg_cmd_write(dbg, cmd, data, len);
132 ccdbg_recv_bytes(dbg, byte, 2);
134 return (byte[0] << 8) | byte[1];
138 ccdbg_cmd_write_queue8(struct ccdbg *dbg, uint8_t cmd,
139 uint8_t *data, int len,
142 ccdbg_cmd_write(dbg, cmd, data, len);
143 ccdbg_recv_bytes(dbg, reply, 1);