diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | cccp.c | 2 | ||||
-rw-r--r-- | cccp.h | 3 | ||||
-rw-r--r-- | ccdbg-io.c | 8 | ||||
-rw-r--r-- | ccdbg.c | 35 | ||||
-rw-r--r-- | ccdbg.h | 51 |
7 files changed, 104 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..fe255c6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +ccdbg +*.o @@ -1,9 +1,11 @@ KERNEL=/local/src/linux-2.6-aiko-64 KINC=$(KERNEL)/drivers/usb/serial -CFLAGS=-g -I$(KINC) +WARN=-Wall -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes\ + -Wmissing-declarations -Wnested-externs -fno-strict-aliasing +CFLAGS=-g -I$(KINC) $(WARN) -OBJS=ccdbg-command.o ccdbg-io.o cccp.o +OBJS=ccdbg.o ccdbg-command.o ccdbg-io.o cccp.o INCS=ccdbg.h cccp.h PROG=ccdbg @@ -26,6 +26,7 @@ cccp_write(struct ccdbg *dbg, uint8_t mask, uint8_t value) set = (mask) | (value << 8); dbg->debug_data = (dbg->debug_data & ~mask) | (value & mask); + printf (" -> %02x\n", dbg->debug_data); ret = ioctl(dbg->fd, CP2101_IOCTL_GPIOSET, &set); if (ret < 0) perror("CP2101_IOCTL_GPIOSET"); @@ -48,6 +49,7 @@ cccp_read(struct ccdbg *dbg, uint8_t mask) perror("CP2101_IOCTL_GPIOGET"); get = 0; } + printf (" <- %02x\n", get); return get & mask; } @@ -32,4 +32,7 @@ cccp_read(struct ccdbg *dbg, uint8_t mask); void cccp_init(struct ccdbg *dbg); +void +cccp_fini(struct ccdbg *dbg); + #endif /* _CCCP_H_ */ @@ -45,6 +45,14 @@ ccdbg_open(char *file) } void +ccdbg_close(struct ccdbg *dbg) +{ + cccp_fini(dbg); + close (dbg->fd); + free (dbg); +} + +void ccdbg_clock_1_0(struct ccdbg *dbg) { ccdbg_quarter_clock(dbg); diff --git a/ccdbg.c b/ccdbg.c new file mode 100644 index 00000000..a2b5946d --- /dev/null +++ b/ccdbg.c @@ -0,0 +1,35 @@ +/* + * Copyright © 2008 Keith Packard <keithp@keithp.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +#include "ccdbg.h" + +int +main (int argc, char **argv) +{ + struct ccdbg *dbg; + uint8_t status; + + dbg = ccdbg_open("/dev/ttyUSB0"); + if (!dbg) + exit (1); + ccdbg_reset(dbg); + status = ccdbg_read_status(dbg); + printf("Status: 0x%02x\n", status); + ccdbg_close(dbg); + exit (0); +} @@ -26,8 +26,10 @@ #include <stdio.h> #include <stdint.h> #include <assert.h> +#include <fcntl.h> #include <sys/types.h> #include <sys/ioctl.h> +#include <sys/stat.h> #include <cp2101.h> #define CC_DATA CP2101_GPIO_MASK(0) @@ -35,7 +37,7 @@ #define CC_RESET_N CP2101_GPIO_MASK(2) /* painfully slow for now */ -#define CC_CLOCK_US (2 * 1000) +#define CC_CLOCK_US (1000 * 1000) struct ccdbg { int fd; @@ -77,4 +79,51 @@ struct ccdbg { #define CC_STEP_REPLACE (0x64|(n)) #define CC_GET_CHIP_ID 0x68 +/* ccdbg-command.c */ +void +ccdbg_reset(struct ccdbg *dbg); + +uint8_t +ccdbg_read_status(struct ccdbg *dbg); + +uint8_t +ccdbg_rd_config(struct ccdbg *dbg); + +/* ccdbg-io.c */ +void +ccdbg_quarter_clock(struct ccdbg *dbg); + +struct ccdbg * +ccdbg_open(char *file); + +void +ccdbg_close(struct ccdbg *dbg); + +void +ccdbg_clock_1_0(struct ccdbg *dbg); + +void +ccdbg_clock_0_1(struct ccdbg *dbg); + +void +ccdbg_write_bit(struct ccdbg *dbg, uint8_t bit); + +void +ccdbg_write_byte(struct ccdbg *dbg, uint8_t byte); + +uint8_t +ccdbg_read_bit(struct ccdbg *dbg); + +uint8_t +ccdbg_read_byte(struct ccdbg *dbg); + +void +ccdbg_cmd_write(struct ccdbg *dbg, uint8_t cmd, uint8_t *data, int len); + +uint8_t +ccdbg_cmd_write_read8(struct ccdbg *dbg, uint8_t cmd, uint8_t *data, int len); + +uint16_t +ccdbg_cmd_write_read16(struct ccdbg *dbg, uint8_t cmd, uint8_t *data, int len); + #endif /* _CCDBG_H_ */ |