From: Keith Packard Date: Fri, 28 Nov 2008 01:07:15 +0000 (-0800) Subject: Add prototypes, add stub mainline, add .gitignore X-Git-Tag: 0.5~58^2~108 X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=commitdiff_plain;h=01cb2799875e086ee6096627c058ee235bbc33d5 Add prototypes, add stub mainline, add .gitignore --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..fe255c6f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +ccdbg +*.o diff --git a/Makefile b/Makefile index 54fd11f4..8e80e65c 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/cccp.c b/cccp.c index aff75e85..e5ee766a 100644 --- a/cccp.c +++ b/cccp.c @@ -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; } diff --git a/cccp.h b/cccp.h index e71aa08e..ed952b01 100644 --- a/cccp.h +++ b/cccp.h @@ -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_ */ diff --git a/ccdbg-io.c b/ccdbg-io.c index 2019885d..e72ffbf0 100644 --- a/ccdbg-io.c +++ b/ccdbg-io.c @@ -44,6 +44,14 @@ ccdbg_open(char *file) return dbg; } +void +ccdbg_close(struct ccdbg *dbg) +{ + cccp_fini(dbg); + close (dbg->fd); + free (dbg); +} + void ccdbg_clock_1_0(struct ccdbg *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 + * + * 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); +} diff --git a/ccdbg.h b/ccdbg.h index 8f937bd4..32283c0d 100644 --- a/ccdbg.h +++ b/ccdbg.h @@ -26,8 +26,10 @@ #include #include #include +#include #include #include +#include #include #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_ */