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
- usb/atu2.c (NUM_EPS), board.h (NUM_EPS): moved definition to
board.h
- board.h (NUM_EPS): use one EP for the boot loader, two for the
application
- usb/atu2.c (ep_init): initialize EP 1 only in an application build
- board.h (gpio_cleanup), board_app.c (gpio_cleanup): restore INT0
when done manipulating GPIOs
- board.c (gpio): updated comment explaining how to restore INT0
- include/atusb/ep0.h (enum atspi_requests), ep0.c
(ATUSB_GPIO_CLEANUP): new request to return to normal operation
after ATUSB_GPIO
- board.h (board_app_init), board_app.c (board_app_init): new function
for application-specific board initialization
- atusb.c (main): call board_app_init
- board_app.c (INT0_vect): on RF interrupt, read REG_IRQ_STATUS and
send the status byte on EP1
- board_app.c (board_app_init): set up interrupt on rising edge of
INT0 (INT_RF)
- descr.c (config_descriptor): added EP1 as bulk IN
- board.c (board_init), board_app.h (timer_init), board_app.c
(timer_init): moved timer initialization from board_init to
new function timer_init
- atusb.c (main): call timer_init
The measured values are:
board idle, looping 9 mA
LED on + 5 mA
TX CW (+3 dBm) +14 mA
------
28 mA
======
Adding a margin of 12 mA, we get 40 mA. DFU used 30 mA so far, the
application 50 mA.
- board.h (BOARD_MAX_mA): define maximum USB bus current
- descr.c (config_descriptor), usb/dfu.c (config_descriptor):
use BOARD_MAX_mA for bMaxPower instead of hard-coding values
reset_rf now resets all GPIOs to their default state. This way, we
can easily recover from an incomplete or incorrect use of ATUSB_GPIO.
- atusb.c (main), board.c (reset_rf): moved call to spi_init into
reset_rf
- board.c (reset_rf, board_init): moved GPIO setup to reset_rf
- board.c (reset_rf): set GPIOs to reset defaults
- board.h (gpio), board.c: read/modify/write all settings of GPIO
ports
- include/atusb/ep0.h (enum atspi_requests): added new request
ATUSB_GPIO
- ep0.c (my_setup): ATUSB_GPIO reads/reconfigures a GPIO port
- atusb.c (main): poll the 16 bit timer for overflows
- board.h (timer_poll, timer_read), (board.c (timer_h, timer_poll,
timer_read, board_init): added support for a free-running 48 bit timer
(16 bits in hardware, 32 bits in software)
- include/atusb/ep0.h (ATUSB_TIMER), ep0.c (my_setup): new request
ATUSB_TIMER to retrieve the value of the 8 MHz counter
- include/atusb/ep0.h (enum atspi_requests): describe what the groups
of requests do
- usb/usb.h (USB_LANGID_ENGLISH_US): added USB LANGID for US-English
- board.h (board_sernum), board.c (board_sernum, hex, get_sernum,
board_init): provide the board's serial number in "board_sernum"
(UTF-encoded)
- sernum.h (sernum_get_descr), sernum.c (sernum_get_descr): return
string descriptors for the serial number
- descr.c (device_descriptor), usb/dfu.c (device_descriptor):
set iSerialNumber if serial number is available
- atusb.c (main), usb/dfu.c (my_descr): call sernum_get_descr for
unknown descriptors
- Makefile (OBJS, BOOT_OBJS): added sernum.o
- board.c (board_init): disable the watchdog timer (tricky !)
- board.h (reset_cpu), board.c: enable the watchdog timer to cause a
CPU reset
- ep0.c (my_setup): uncommented and updated ATUSB_RESET handler
- boot.c: basic boot loader that runs DFU for 2 s, then starts the payload
- board.h (DFU_USB_VENDOR, DFU_USB_PRODUCT): added USB IDs for DFU
- flash.c: stubs for board-specific Flash functions
- Makefile: build boot.hex for the boot loader
- Makefile (prog): load the boot loader at its rightful place
- Makefile (prog): also set hfuse and the lock fuse