Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: whitequark/libfx2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 9603d4529c4d
Choose a base ref
...
head repository: whitequark/libfx2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: afaae3ce52fc
Choose a head ref
  • 2 commits
  • 1 file changed
  • 1 contributor

Commits on May 20, 2019

  1. Fix some comment typos.

    whitequark committed May 20, 2019
    Copy the full SHA
    6bb8e07 View commit details

Commits on May 21, 2019

  1. Copy the full SHA
    afaae3c View commit details
Showing with 27 additions and 25 deletions.
  1. +27 −25 firmware/library/delay.c
52 changes: 27 additions & 25 deletions firmware/library/delay.c
Original file line number Diff line number Diff line change
@@ -2,41 +2,43 @@
#include <fx2regs.h>
#include <bits/asmargs.h>

// Spin for exactly min(24, DP*4) cycles (i.e. min(96, DP*16) clocks), including the call of
// this function. The implementation is a bit complicated, but the calculations in the callee
// Spin for exactly max(24, DP*4) cycles (i.e. max(96, DP*16) clocks), including the call of
// this function. The implementation is a bit complicated, but the calculations in the caller
// are simpler.
//
// This was originally optimized by @whitequark, and then improved by @8051Enthusiast.
void delay_4c(uint16_t count) __naked {
count;
__asm
; (ljmp delay_4c) ; 0c > 4c
mov acc, dph ; 3c
cjne a, #0, 00000$ ; 4c > 11c [A]
mov acc, dpl ; 3c
subb a, #(24/4+1) ; 2c
inc a ; 1c
jnc 00003$ ; 3c > 20c [B]
_ASM_RET ; 4c > 24c
mov a, dph ; 2c
jnz 00001$ ; 3c > 9c [A]
mov a, dpl ; 2c
add a, #-(20/4+1) ; 2c
jc 00000$ ; 3c > 16c [B]
_ASM_RET ; 4c > 20c
00000$:
mov a, dpl ; [A] > 2c
jz 00002$ ; 3c > 16c [C]
cjne a, #0, 00004$ ; [B] > 4c > 20c [H]
_ASM_RET ; 4c > 24c
00001$:
djnz acc, 00001$ ; [C] > 4Lc > (16+4L)c [D]
; [E] > 1016c > (16+1024H+4L)c [G]
mov a, dpl ; [A] > 2c
jz 00003$ ; 3c > 14c [C]
00002$:
djnz acc, 00002$ ; [C] > 4Lc > (14+4L)c [D]
; [E] > 1016c > (14+1024H+4L)c [G]
00003$:
nop ; [D] > 1c
mov acc, #-2 ; 3c
djnz dph, 00001$ ; 4c > (16+8+4L) [E]
nop ; 1c
mov acc, #-((28+4)/4) ; 3c > (28+4L) [F]
djnz dph, 00002$ ; 4c > (14+8+4L) [E]
mov a, #-((24+4)/4) ; 2c > (24+4L) [F]
; [G] > 1c
; 3c
; 4c > (16+8+1024H+4L)c [E]
; 1c
; 3c > (28+1024H+4L)c [F]
00003$:
djnz acc, 00003$ ; [B] > 4Lc
; 4c > (14+8+1024H+4L)c [E]
; 2c > (24+1024H+4L)c [F]
00004$:
djnz acc, 00004$ ; [H] > 4Lc
_ASM_RET ; 4c > (24+4L)c
; [F] > 992c
; [F] > 996c
; 4c > (1024H+4L)c
__endasm;
}
@@ -156,7 +158,7 @@ void delay_us(uint16_t count) __naked {
count;
__asm;
; (mov dptr, #?) ; 3c
; (ljmp delay_us) ; 4c
; (lcall delay_us) ; 4c
mov a, #17 ; 2c
push acc ; 2c
lcall _delay_us_overhead
@@ -194,14 +196,14 @@ void delay_ms(uint16_t count) __naked {
mov dptr, #1000 ; 3c
lcall _delay_us_overhead

sjmp 00000$ ; 3c
sjmp 00000$ ; 3c => 17c

00002$:
dec sp

// epilog
pop ar6
pop ar7
_ASM_RET ; 4c => 17c
_ASM_RET
__endasm;
}