X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=cccp.c;h=99a0d81f1a11a895d470d558d7fdfe6caa8ac585;hb=cc8db276bc4f2fd7eb00168a5c0689a8457a5c6f;hp=aff75e85e8c4b543a995e75709984275c0759528;hpb=0ffe4ef870b0e564789a1990aeab5b6651868e5b;p=fw%2Faltos diff --git a/cccp.c b/cccp.c index aff75e85..99a0d81f 100644 --- a/cccp.c +++ b/cccp.c @@ -18,8 +18,26 @@ #include "ccdbg.h" -void -cccp_write(struct ccdbg *dbg, uint8_t mask, uint8_t value) +static void +say(char *name, uint8_t bits) +{ + printf("%s: ", name); + if (bits & CC_RESET_N) + printf ("R "); + else + printf (". "); + if (bits & CC_CLOCK) + printf ("C "); + else + printf (". "); + if (bits & CC_DATA) + printf ("D\n"); + else + printf (".\n"); +} + +static void +_cccp_write(struct ccdbg *dbg, uint8_t mask, uint8_t value) { uint16_t set; int ret; @@ -31,23 +49,38 @@ cccp_write(struct ccdbg *dbg, uint8_t mask, uint8_t value) perror("CP2101_IOCTL_GPIOSET"); } +void +cccp_write(struct ccdbg *dbg, uint8_t mask, uint8_t value) +{ + _cccp_write(dbg, mask, value); +// say("w", dbg->debug_data); +} + +uint8_t +cccp_read_all(struct ccdbg *dbg) +{ + int ret; + uint8_t get; + ret = ioctl(dbg->fd, CP2101_IOCTL_GPIOGET, &get); + if (ret < 0) { + perror("CP2101_IOCTL_GPIOGET"); + get = 0; + } + return get; +} + uint8_t cccp_read(struct ccdbg *dbg, uint8_t mask) { uint8_t pull_up; - int ret; uint8_t get; /* tri-state the bits of interest */ pull_up = (~dbg->debug_data) & mask; - if (pull_up) { - cccp_write(dbg, pull_up, pull_up); - } - ret = ioctl(dbg->fd, CP2101_IOCTL_GPIOGET, &get); - if (ret < 0) { - perror("CP2101_IOCTL_GPIOGET"); - get = 0; - } + if (pull_up) + _cccp_write(dbg, pull_up, pull_up); + get = cccp_read_all(dbg); + say("\t\tr", get); return get & mask; } @@ -56,7 +89,6 @@ cccp_init(struct ccdbg *dbg) { /* set all of the GPIOs to a known state */ cccp_write(dbg, 0xf, 0xf); - dbg->clock = 1; } void