Skip to content

Commit

Permalink
usbdrv/usbdrvasm165.inc:
Browse files Browse the repository at this point in the history
replaced comparison in USB ISR to save program cycles: was program counter comparison, now a magic word comparison

main.c:
adds magic word as first pushes onto stack, clears magic word before jumping to app

bootloader runs and enumerates with PC, haven't tested with app yet
  • Loading branch information
Louis committed May 13, 2012
1 parent 9b18d95 commit 5660da2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 11 deletions.
19 changes: 19 additions & 0 deletions firmware/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ static inline __attribute__((noreturn)) void leaveBootloader(void)
#endif

#ifdef TINY85MODE
// clear magic word from bottom of stack before jumping to the app
*(uint8_t*)(RAMEND) = 0x00;
*(uint8_t*)(RAMEND-1) = 0x00;

// jump to application reset vector at end of flash
asm volatile ("rjmp __vectors - 4");
#else
Expand Down Expand Up @@ -498,6 +502,21 @@ uchar usbFunctionRead(uchar *data, uchar len)

/* ------------------------------------------------------------------------ */

#ifdef TINY85MODE
void PushMagicWord (void) __attribute__ ((naked)) __attribute__ ((section (".init3")));

// put the word "B007" at the bottom of the stack (RAMEND - RAMEND-1)
void PushMagicWord (void)
{
asm volatile("ldi r16, 0xB0"::);
asm volatile("push r16"::);
asm volatile("ldi r16, 0x07"::);
asm volatile("push r16"::);
}
#endif

/* ------------------------------------------------------------------------ */

static inline void initForUsbConnectivity(void)
{
usbInit();
Expand Down
22 changes: 11 additions & 11 deletions firmware/usbdrv/usbdrvasm165.inc
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ of CPU cycles, but even an exact number of cycles!
USB_INTR_VECTOR:
;order of registers pushed: YL, SREG [sofError], r0, YH, shift, x1, x2, x3, x4, cnt
push YL ; push only what is necessary to sync with edge ASAP
in YL, SREG ; [-36]
push YL ; [-34]
in YL, SREG ;
push YL ;

#ifdef TINY85MODE
push YH ; [-32]
in YL, SPL ; [-30]
in YH, SPH ; [-28]
adiw YL, 4 ; [-26]
ld YL, Y ; [-25] YL now contains the high byte of the program counter (word address)
cpi YL, ((BOOTLOADER_ADDRESS/256)/2) ; [-23]
brge cleanupBootloaderIntStack ; [-22] branch if high byte of program counter >= start of boot loader
lds YL, RAMEND
cpi YL, 0xB0
brne cleanupAndJumpToApp

lds YL, RAMEND-1
cpi YL, 0x07
breq cleanupBootloaderIntStack

cleanupAndJumpToApp:
; program counter was in application space, put registers back to normal and jump to app
pop YH
pop YL
out SREG, YL
pop YL
rjmp __vectors - TINYVECTOR_USBPLUS_OFFSET

cleanupBootloaderIntStack:
pop YH ; [-20]
CLR YL
#endif
;----------------------------------------------------------------------------
; Synchronize with sync pattern:
Expand Down

0 comments on commit 5660da2

Please sign in to comment.