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: afaae3ce52fc
Choose a base ref
...
head repository: whitequark/libfx2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bbadc922b3b4
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Jun 25, 2019

  1. Fix unbalanced stack in delay_us_overhead() in case of early return.

    Also, mark all delay functions as reentrant instead of messing with
    the callee_saves pragma. It's cleaner and they're all naked anyway.
    whitequark committed Jun 25, 2019
    Copy the full SHA
    bbadc92 View commit details
Showing with 10 additions and 15 deletions.
  1. +7 −6 firmware/library/delay.c
  2. +3 −9 firmware/library/include/fx2delay.h
13 changes: 7 additions & 6 deletions firmware/library/delay.c
Original file line number Diff line number Diff line change
@@ -140,16 +140,17 @@ void delay_us_overhead(uint16_t count, uint8_t caller_overh) __naked __reentrant
subb a, #0 ; 2c
mov dph, a ; 1c

pop ar0 ; 2c
pop ar1 ; 2c
pop ar6 ; 2c
pop ar7 ; 2c

// if(underflow) return
jnc 00001$ ; 4c
jnc 00001$ ; 4c => 36c
_ASM_RET

00001$:
// delay_4c(iters)
pop ar0 ; 2c
pop ar1 ; 2c
pop ar6 ; 2c
pop ar7 ; 2c => 36c
// else delay_4c(iters)
ljmp _delay_4c
__endasm;
}
12 changes: 3 additions & 9 deletions firmware/library/include/fx2delay.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
#ifndef FX2DELAY_H
#define FX2DELAY_H

#if !defined(__SDCC_MODEL_HUGE)
#pragma callee_saves delay_ms
#pragma callee_saves delay_us
#pragma callee_saves delay_4c
#endif

#include <stdint.h>

/**
* Spin for the given number of milliseconds.
*/
void delay_ms(uint16_t count_ms);
void delay_ms(uint16_t count_ms) __reentrant;

/**
* Spin for the given number of microseconds, minus `overh_c` processor cycles.
@@ -27,13 +21,13 @@ void delay_us_overhead(uint16_t count_us, uint8_t overh_c) __reentrant;
* Equivalent to `delay_us_overhead(count_us, 3)` where 3 is the number of cycles of overhead
* when `delay_us` is called with a constant argument.
*/
void delay_us(uint16_t count_us);
void delay_us(uint16_t count_us) __reentrant;

/**
* Spin for `count * 4` processor cycles, or `count * 16` clock cycles.
* Takes exactly 24 processor cycles (2..8 microseconds) if `count` is less than `6`.
*/
void delay_4c(uint16_t count_4c);
void delay_4c(uint16_t count_4c) __reentrant;

/**
* Synchronization delay length.