- 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
The code is quite special-cased. Some more changes will be necessary
for interrupt or OUT EPs.
- atu2.c (NUM_EPS): increased from 1 to 2
- atu2.c (ep_rx): send zero-length packet also for EPs != 0
- atu2.c (handle_ep): clear FIFOCON when sending data on EP != 0
- atu2.c (ep_init): configure EP 1 as bulk IN with size 64
- usb.c (NUM_EPS): we don't need to define NUM_EPS here
With warnings treated as errors I get this:
In file included from flash.c:19:0:
usb/dfu.h:107:35: error: 'struct setup_request' declared inside parameter list
usb/dfu.h:107:35: error: its scope is only this definition or declaration, which
is probably not what you want
make: *** [flash.o] Error 1
Struct setup_request is declared in usb.h so include it.
Signed-off-by: Stefan Schmidt <stefan@datenfreihafen.org>
- usb/usb.h (usb_ep_change), usb/atu2.c (usb_ep_change): new function
called by the USB stack to notify the hardware-specific driver of
an endpoint state change (EP_TX or EP_RX)
- usb/usb.c (usb_io): call usb_ep_change
- usb/atu2.c (handle_ep): mask TXINI if we have nothing to send
Note: this change surprisingly _increases_ the DFU wait in the boot
loader. Not yet sure why.
- boot.c (main): move the interrupt vectors to the boot loader
section
- atusb.c (main): move the interrupt vectors to the application
section
- boot.c (main): enable global interrupts while looping (disable
them before jumping to the application)
- board_app.c (__timer_read, timer_read): removed wrapped since
we're now always called with interrupts disabled
- usb/atu2.c (ep_init): enable endpoint interrupts
- usb/atu2.c (usb_init): enable device interrupts
- usb/atu2.c (usb_poll, USB_GEN_vect, USB_COM_vect): moved poll
loop code into separate handlers for device and endpoint
interrupts
- boot.c (main), atusb.c (main): removed call to usb_poll
The old code could accidently acknowledge interrupts that appeared
between the read and the write in UxINTx &= mask.
- atu2.c (handle_ep): writing to UEINTX implies a race-free "and"
- atu2.c (usb_poll): writing to UDINT implies a race-free "and"
This allows us to do other things as well, e.g., change state.
- ep0.c (ep0_init), usb/dfu.c (dfu_init): use user_setup
- usb/atu2.c (usb_poll): no need to reset user_setup - the user's
reset function can do that
- usb/usb.h (user_setups), usb/usb.c (handle_setup): removed
user_setups
- usb/usb.h (user_set_interface), usb/usb.c (user_set_interface,
handle_setup): callback for SET_INTERFACE
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
- ep0.c (ep0_init), usb/dfu.c (dfu_init): set user_setups[0] instead
of user_setup
- usb/atu2.c (usb_poll): reset user_setup on bus reset
- usb/usb.h (user_setups), usb/usb.c (user_setups): array of
interface-specific setup functions
- usb/usb.c (handle_setup): in SET_INTERFACE, select setup function
from user_setups according to interface
- usb/usb.c (handle_setup): if user_setup is not set (e.g., the
optional SET_INTERFACE was never issued), fall back to user_setups[0]
- 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
- usb/atu2.c (ep_init): moved before usb_poll
- usb/atu2.c (usb_poll): register bit was used as mask, not as shift
- usb/atu2.c (usb_poll): call ep_init on USB bus reset
- usb/atu2.c (usb_reset): don't make USB bus reset force a hardware reset
- Makefile (.PHONY, dfu): new target to upload the application with DFU
- usb/usb.h, usb/atu2.c (usb_reset): reset the USB bus by detaching and
re-attaching the device
- boot.c (main): force a USB reset before running the payload
- usb/atu2.c (usb_poll): test for USB reset from the host (in progress)
- usb/dfu.c (my_reset, dfu_init): register user USB reset handler
- dfu.h (flash_end_write), flash.c (flash_end_write): write any incomplete
buffer
- flash.c (flash_write, flash_end_write): call boot_rww_enable only at the
very end, it won't erase our buffer in mid-page
- usb/dfu.c (my_setup): call flash_end_write at the end of a download
- dfu.c: updated includes
- dfu.c (device_descriptor): renamed USB IDs from USB_VENDOR/PRODUCT to
DFU_USB_VENDOR/PRODUCT to allow differentiation
- dfu.c: changed all __bit to "int"
- dfu.c: removed all __xdata and __reentrant
- dfu.c: changed "ep0" to "eps[0]"
- dfu.c (payload, flash_erase_page, flash_write_byte, block_write,
block_receive, block_transmit, my_setup): abstracted Flash interface
and removed target-specific operations
- dfu.h: added prototypes for target-specific Flash operations
- dfu,c (my_setup, my_descr): removed SDCC-specific hacks
- dfu.c (my_reset): commented out - did we actually use this ?