diff --git a/cntr/fw/cntr/cntr.c b/cntr/fw/cntr/cntr.c index 9bd8ead..9f0bf54 100644 --- a/cntr/fw/cntr/cntr.c +++ b/cntr/fw/cntr/cntr.c @@ -18,20 +18,37 @@ #include "usb.h" #include "cntr/ep0.h" #include "version.h" +#include "cntr.h" -/* - * Free-running 32 bit counter. The lower two bytes are from hardware Timer 0. - * The upper two bytes are maintained by software. At the maximum input clock - * frequency of 6 MHz, it wraps around every 11.9 minutes, leaving the host - * plenty of time to read it. - */ - uint8_t cntr[4]; +enum hw_type hw_type = HW_TYPE_V1; + + +static void delay(unsigned ms) +{ + int x; + + while (ms--) + for (x = 0; x < 1488; x) + x++; +} static void init_io(void) { + if (VERSION_ID) { + /* flash LED a second time */ + LEDv2 = 0; + delay(250); + LEDv2 = 1; + delay(250); + + PROBE_TERM_MODE |= 1 << PROBE_TERM_BIT; + + hw_type = HW_TYPE_V2; + } + /* * Signal Mode Value * @@ -39,9 +56,11 @@ static void init_io(void) * PROBE_ECI open drain 1 (input) * PROBE_INT0 open drain 1 (input) * - * PROBE_TERM open drain 0 + * PROBE_TERM open drain 0 version 1 + * PROBE_TERM push-pull 1 version 2 * - * LED push-pull 0 (set up by boot loader) + * LEDv1 push-pull 0 (set up by boot loader) + * LEDv2 push-pull 0 (set up by boot loader) * * all unused open drain 0 */ @@ -51,6 +70,9 @@ static void init_io(void) P2 = 0; P3 = 0; + if (hw_type == HW_TYPE_V2) + PROBE_TERM = 1; + /* * Disable pull-ups */ diff --git a/cntr/fw/cntr/cntr.h b/cntr/fw/cntr/cntr.h new file mode 100644 index 0000000..db248c8 --- /dev/null +++ b/cntr/fw/cntr/cntr.h @@ -0,0 +1,30 @@ +/* + * cntr/cntr.h - CNTR global variables + * + * Written 2010 by Werner Almesberger + * Copyright 2010 Werner Almesberger + * + * 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. + */ + +#ifndef CNTR_H +#define CNTR_H + +/* + * Free-running 32 bit counter. The lower two bytes are from hardware Timer 0. + * The upper two bytes are maintained by software. At the maximum input clock + * frequency of 6 MHz, it wraps around every 11.9 minutes, leaving the host + * plenty of time to read it. + */ + +extern uint8_t cntr[4]; + +extern enum hw_type { + HW_TYPE_V1 = 0, + HW_TYPE_V2 = 1, +} hw_type; + +#endif /* !CNTR_H */ diff --git a/cntr/fw/cntr/ep0.c b/cntr/fw/cntr/ep0.c index fedb589..78277ee 100644 --- a/cntr/fw/cntr/ep0.c +++ b/cntr/fw/cntr/ep0.c @@ -21,6 +21,7 @@ #include "usb.h" #include "cntr/ep0.h" #include "version.h" +#include "cntr.h" #define debug(...) #define error(...) @@ -51,9 +52,11 @@ } while (0) -extern uint8_t cntr[8]; +static uint8_t id[3] = { + EP0CNTR_MAJOR, EP0CNTR_MINOR, + /* hw type is set at run time */ +}; -static const uint8_t id[] = { EP0CNTR_MAJOR, EP0CNTR_MINOR, HW_TYPE }; static __xdata uint8_t buf[128]; @@ -74,6 +77,7 @@ static __bit my_setup(struct setup_request *setup) __reentrant debug("CNTR_ID\n"); if (setup->wLength > 3) return 0; + id[2] = hw_type; usb_send(&ep0, id, setup->wLength, NULL, NULL); return 1; case CNTR_FROM_DEV(CNTR_BUILD): diff --git a/cntr/fw/common/config.h b/cntr/fw/common/config.h index fe97eaf..7a7afd4 100644 --- a/cntr/fw/common/config.h +++ b/cntr/fw/common/config.h @@ -48,9 +48,4 @@ LEDv1 = 0; \ LEDv2 = 0 - -/* ----- Application configuration ----------------------------------------- */ - -#define HW_TYPE 0 - #endif /* !CONFIG_H */ diff --git a/cntr/fw/common/io.h b/cntr/fw/common/io.h index b80448e..6b798dd 100644 --- a/cntr/fw/common/io.h +++ b/cntr/fw/common/io.h @@ -34,4 +34,14 @@ #define PROBE_TERM P1_2 +/* + * Version ID + * + * In version 1, P2_1 is used to provide ground to the input side. In version + * 2, we use a ground place for this and P2_1 is unconnected. We can therefore + * use it to identify the hardware version. + */ + +#define VERSION_ID P2_1 + #endif /* !IO_H */