mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-11-22 12:22:48 +02:00
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
This commit is contained in:
parent
f5388cac42
commit
4e568b0f1a
@ -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
|
||||
*/
|
||||
|
30
cntr/fw/cntr/cntr.h
Normal file
30
cntr/fw/cntr/cntr.h
Normal file
@ -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 */
|
@ -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):
|
||||
|
@ -48,9 +48,4 @@
|
||||
LEDv1 = 0; \
|
||||
LEDv2 = 0
|
||||
|
||||
|
||||
/* ----- Application configuration ----------------------------------------- */
|
||||
|
||||
#define HW_TYPE 0
|
||||
|
||||
#endif /* !CONFIG_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 */
|
||||
|
Loading…
Reference in New Issue
Block a user