1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-25 20:14:40 +02:00
ben-wpan/atusb/fw
Werner Almesberger 42483d67b4 atusb/fw/: added improved support for interrupt synchronization
At an interrupt barrier, the host must be able to ensure that no
interrupt generated before reaching the barrier is still pending and
will be delivered after crossing the barrier.

For this, we introduce the following concept:

- interrupts have a serial number. This number is sent to the host
  on EP 1 (currently bulk) to signal the interrupt, instead of the
  zero byte we used previously.

- the new request ATUSB_SPI_WRITE2_SYNC returns the interrupt
  serial number from after the register write (the register write
  itself is the interrupt barrier).

- the host can now check if the serial indicated from bulk and the
  serial from ATUSB_SPI_WRITE2_SYNC are the same. If yes, interrupts
  are synchronized. If not, it has to wait for the interrupt to be
  signaled on EP 1.

We should also consider the case that the interrupt serial has gotten
ahead of ATUSB_SPI_WRITE2_SYNC. But that seems to happen rarely. In
any case, it's something for the host driver to worry about, not for
the firmware.

- board.h (irq_serial), board_app.c (irq_serial, INT0_vect): count
  the interrupt serial number and return it when signaling the
  interrupt
- include/atusb/ep0.h (ATUSB_SPI_WRITE2_SYNC), ep0.c (my_setup):
  new request ATUSB_SPI_WRITE2_SYNC that does a register write, then
  returns the interrupt serial
2011-07-07 15:51:07 -03:00
..
an moved atusb/fw3/ to atusb/fw/ 2011-02-22 00:24:07 -03:00
include atusb/fw/: added improved support for interrupt synchronization 2011-07-07 15:51:07 -03:00
usb atusb/fw/: remove unused items when building the USB driver for the boot loader 2011-06-26 06:59:13 -03:00
atusb.c atusb/fw/: added reporting of RF interrupts via bulk EP1 2011-06-20 15:49:33 -03:00
board_app.c atusb/fw/: added improved support for interrupt synchronization 2011-07-07 15:51:07 -03:00
board.c atusb/fw/: moved timer initialization to board_app.c as well 2011-06-11 01:52:16 -03:00
board.h atusb/fw/: added improved support for interrupt synchronization 2011-07-07 15:51:07 -03:00
boot.c atusb/fw/boot.c: adjusted the delay loop and don't race with dfu-util 2011-06-11 14:26:52 -03:00
descr.c atusb/fw/: added reporting of RF interrupts via bulk EP1 2011-06-20 15:49:33 -03:00
ep0.c atusb/fw/: added improved support for interrupt synchronization 2011-07-07 15:51:07 -03:00
flash.c atusb/fw: introduced function flash_end_write to properly finish flashing 2011-03-11 17:56:41 -03:00
Makefile atusb/fw/Makefile: introduce target-specific compliation variants 2011-06-26 06:56:01 -03:00
README atusb/fw/README: boot loader flashing time was a bit too optimistic (15 -> 30 s) 2011-05-09 23:44:51 -03:00
sernum.c atusb/fw: use the unique serial number of the ATmega8/16/32U2 for iSerialNumber 2011-05-10 17:23:08 -03:00
sernum.h atusb/fw: use the unique serial number of the ATmega8/16/32U2 for iSerialNumber 2011-05-10 17:23:08 -03:00
spi.c atusb/fw/: added "lazy enabling" of UART-SPI after ATUSB_GPIO 2011-06-09 14:02:26 -03:00
spi.h atusb/fw/: added "lazy enabling" of UART-SPI after ATUSB_GPIO 2011-06-09 14:02:26 -03:00
version.h moved atusb/fw3/ to atusb/fw/ 2011-02-22 00:24:07 -03:00

Requires a very recent toolchain, because ATmega32U2 is relatively new.

- Building:

  make

- Uploading the firmware to a Ben (for flashing with the atusb-pgm cable):

  make HOST=<hostname> upload

  Example:

  make HOST=ben upload

  HOST defaults to "jlime".

- Flashing the boot loader:

  Prerequisite: avrdude on the Ben.

  Disconnect the atusb board from USB. Insert the atusb-pgm connector into
  the Ben. Place the atusb-pgm adapter on the exposed contact pads of the
  atusb board and push it down. Then run

  make prog

  This takes about 30 seconds. If the programming fails with an error
  message like "Yikes!  Invalid device signature.", verify that the
  atusb-pgm board is properly connected and placed, then try again.

- Uploading the application:

  Prerequisite: dfu-util installed on the PC.

  Insert atusb into the PC, then run

  make dfu

  Note: since the boot loader resets the USB bus after timing out,
  this operation can fail with a message like "No DFU capable USB device
  found". Just retry, and it will eventually get through.

--------------------------

Making the toolchain:

# patches according to
# http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&p=789527

# some gcc prerequisites

apt-get remove avr-libc gcc-avr binutils-avr
apt-get install libmpfr-dev libmpc-dev

# binutils

wget http://ftp.gnu.org/gnu/binutils/binutils-2.21.tar.bz2
tar xfj binutils-2.21.tar.bz2 
cd binutils-2.21
./configure --target=avr --disable-nls
make
make install

# gcc

wget http://ftpmirror.gnu.org/gcc/gcc-4.5.2/gcc-4.5.2.tar.bz2
wget -O gcc_452_avr.patch http://gcc.gnu.org/bugzilla/attachment.cgi?id=23050
tar xfj gcc-4.5.2.tar.bz2
cd gcc-4.5.2
patch -p1 -s <../gcc_452_avr.patch
mkdir obj-avr
cd obj-avr
../configure --target=avr --enable-languages=c \
    --disable-nls --disable-libssp --with-dwarf2
make
make install

wget http://download.savannah.gnu.org/releases/avr-libc/avr-libc-1.7.1.tar.bz2
tar xfj avr-libc-1.7.1.tar.bz2 
cd avr-libc-1.7.1
./bootstrap	# the automake at the end takes a while
./configure --build=`./config.guess` --host=avr
make
make install