Add prototypes, add stub mainline, add .gitignore
authorKeith Packard <keithp@keithp.com>
Fri, 28 Nov 2008 01:07:15 +0000 (17:07 -0800)
committerKeith Packard <keithp@keithp.com>
Fri, 28 Nov 2008 01:07:15 +0000 (17:07 -0800)
.gitignore [new file with mode: 0644]
Makefile
cccp.c
cccp.h
ccdbg-io.c
ccdbg.c [new file with mode: 0644]
ccdbg.h

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..fe255c6
--- /dev/null
@@ -0,0 +1,2 @@
+ccdbg
+*.o
index 54fd11f4ed2b695f188966ee0c9cf33106bafd11..8e80e65c587a874e7391acf3dc87ad86014d7500 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,11 @@
 KERNEL=/local/src/linux-2.6-aiko-64
 KINC=$(KERNEL)/drivers/usb/serial
 
 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
 INCS=ccdbg.h cccp.h
 
 PROG=ccdbg
diff --git a/cccp.c b/cccp.c
index aff75e85e8c4b543a995e75709984275c0759528..e5ee766aaea3ade46c77039eb2507f55bdbc40ff 100644 (file)
--- 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);
 
        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");
        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;
        }
                perror("CP2101_IOCTL_GPIOGET");
                get = 0;
        }
+       printf (" <- %02x\n", get);
        return get & mask;
 }
 
        return get & mask;
 }
 
diff --git a/cccp.h b/cccp.h
index e71aa08eaf6b2ae10d92cbec36c258056b8bbd1a..ed952b016b702b643ad561e5746de1666397b10d 100644 (file)
--- 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_init(struct ccdbg *dbg);
 
+void
+cccp_fini(struct ccdbg *dbg);
+
 #endif /* _CCCP_H_ */
 #endif /* _CCCP_H_ */
index 2019885d1b521963bb150d4ec89cd206a3907f2b..e72ffbf08ca9a6a6be91270a17b76227a7e6a67e 100644 (file)
@@ -44,6 +44,14 @@ ccdbg_open(char *file)
        return dbg;
 }
 
        return dbg;
 }
 
+void
+ccdbg_close(struct ccdbg *dbg)
+{
+       cccp_fini(dbg);
+       close (dbg->fd);
+       free (dbg);
+}
+
 void
 ccdbg_clock_1_0(struct ccdbg *dbg)
 {
 void
 ccdbg_clock_1_0(struct ccdbg *dbg)
 {
diff --git a/ccdbg.c b/ccdbg.c
new file mode 100644 (file)
index 0000000..a2b5946
--- /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);
+}
diff --git a/ccdbg.h b/ccdbg.h
index 8f937bd431e618c89dc649e6ad3f5100008422ee..32283c0d8e09527c74f6df6814555d3538c34d67 100644 (file)
--- a/ccdbg.h
+++ b/ccdbg.h
 #include <stdio.h>
 #include <stdint.h>
 #include <assert.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <assert.h>
+#include <fcntl.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
 #include <sys/types.h>
 #include <sys/ioctl.h>
+#include <sys/stat.h>
 #include <cp2101.h>
 
 #define CC_DATA                CP2101_GPIO_MASK(0)
 #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_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;
 
 struct ccdbg {
        int     fd;
@@ -77,4 +79,51 @@ struct ccdbg {
 #define CC_STEP_REPLACE                (0x64|(n))
 #define CC_GET_CHIP_ID         0x68
 
 #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_ */
 #endif /* _CCDBG_H_ */