Date:2010-11-03 16:20:13 (8 years 10 months ago)
Author:Werner Almesberger
Commit:4e568b0f1af26658b8d785af2855e34c371d0138
Message:Adapted firmware for V2 hardware.

- cntr/cntr.h: new file for variables shared among cntr.c and ep0.c
- cntr/cntr.c (cntr), cntr/ep0.c (cntr): moved to cntr/cntr.h
- fw/common/io.h (VERSION_ID): we can detect the board version by reading
P2_1 (GND on version 1, open on version 2)
- cntr/cntr.c (init_io): added board version detection, board-specific
GPIO initialization, and a LED blink to indicate version 2
- cntr/cntr.h (hw_type), cntr/cntr.c (hw_type), cntr/ep0.c (my_setup),
common/config.h (HW_TYPE): the hardware type is now determined at run
time
Files: cntr/fw/cntr/cntr.c (3 diffs)
cntr/fw/cntr/cntr.h (1 diff)
cntr/fw/cntr/ep0.c (3 diffs)
cntr/fw/common/config.h (1 diff)
cntr/fw/common/io.h (1 diff)

Change Details

cntr/fw/cntr/cntr.c
1818#include "usb.h"
1919#include "cntr/ep0.h"
2020#include "version.h"
21#include "cntr.h"
2122
2223
23/*
24 * Free-running 32 bit counter. The lower two bytes are from hardware Timer 0.
25 * The upper two bytes are maintained by software. At the maximum input clock
26 * frequency of 6 MHz, it wraps around every 11.9 minutes, leaving the host
27 * plenty of time to read it.
28 */
29
3024uint8_t cntr[4];
25enum hw_type hw_type = HW_TYPE_V1;
26
27
28static void delay(unsigned ms)
29{
30        int x;
31
32    while (ms--)
33            for (x = 0; x < 1488; x)
34                        x++;
35}
3136
3237
3338static void init_io(void)
3439{
40    if (VERSION_ID) {
41        /* flash LED a second time */
42        LEDv2 = 0;
43        delay(250);
44        LEDv2 = 1;
45        delay(250);
46
47        PROBE_TERM_MODE |= 1 << PROBE_TERM_BIT;
48
49        hw_type = HW_TYPE_V2;
50    }
51
3552    /*
3653     * Signal Mode Value
3754     *
...... 
3956     * PROBE_ECI open drain 1 (input)
4057     * PROBE_INT0 open drain 1 (input)
4158     *
42     * PROBE_TERM open drain 0
59     * PROBE_TERM open drain 0 version 1
60     * PROBE_TERM push-pull 1 version 2
4361     *
44     * LED push-pull 0 (set up by boot loader)
62     * LEDv1 push-pull 0 (set up by boot loader)
63     * LEDv2 push-pull 0 (set up by boot loader)
4564     *
4665     * all unused open drain 0
4766     */
...... 
5170    P2 = 0;
5271    P3 = 0;
5372
73    if (hw_type == HW_TYPE_V2)
74        PROBE_TERM = 1;
75
5476    /*
5577     * Disable pull-ups
5678     */
cntr/fw/cntr/cntr.h
1/*
2 * cntr/cntr.h - CNTR global variables
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#ifndef CNTR_H
14#define CNTR_H
15
16/*
17 * Free-running 32 bit counter. The lower two bytes are from hardware Timer 0.
18 * The upper two bytes are maintained by software. At the maximum input clock
19 * frequency of 6 MHz, it wraps around every 11.9 minutes, leaving the host
20 * plenty of time to read it.
21 */
22
23extern uint8_t cntr[4];
24
25extern enum hw_type {
26    HW_TYPE_V1 = 0,
27    HW_TYPE_V2 = 1,
28} hw_type;
29
30#endif /* !CNTR_H */
cntr/fw/cntr/ep0.c
2121#include "usb.h"
2222#include "cntr/ep0.h"
2323#include "version.h"
24#include "cntr.h"
2425
2526#define debug(...)
2627#define error(...)
...... 
5152    } while (0)
5253
5354
54extern uint8_t cntr[8];
55static uint8_t id[3] = {
56    EP0CNTR_MAJOR, EP0CNTR_MINOR,
57    /* hw type is set at run time */
58};
5559
56static const uint8_t id[] = { EP0CNTR_MAJOR, EP0CNTR_MINOR, HW_TYPE };
5760static __xdata uint8_t buf[128];
5861
5962
...... 
7477        debug("CNTR_ID\n");
7578        if (setup->wLength > 3)
7679            return 0;
80        id[2] = hw_type;
7781        usb_send(&ep0, id, setup->wLength, NULL, NULL);
7882        return 1;
7983    case CNTR_FROM_DEV(CNTR_BUILD):
cntr/fw/common/config.h
4848    LEDv1 = 0; \
4949    LEDv2 = 0
5050
51
52/* ----- Application configuration ----------------------------------------- */
53
54#define HW_TYPE 0
55
5651#endif /* !CONFIG_H */
cntr/fw/common/io.h
3434
3535#define PROBE_TERM P1_2
3636
37/*
38 * Version ID
39 *
40 * In version 1, P2_1 is used to provide ground to the input side. In version
41 * 2, we use a ground place for this and P2_1 is unconnected. We can therefore
42 * use it to identify the hardware version.
43 */
44
45#define VERSION_ID P2_1
46
3747#endif /* !IO_H */

Archive Download the corresponding diff file



interactive