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: 81f4998a243b
Choose a base ref
...
head repository: whitequark/libfx2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: c5fd82300f7d
Choose a head ref
  • 4 commits
  • 8 files changed
  • 1 contributor

Commits on May 19, 2019

  1. Cleanup. NFC.

    whitequark committed May 19, 2019
    Copy the full SHA
    c6733cd View commit details
  2. Copy the full SHA
    af3301c View commit details
  3. Fix bswap16 to return correct result.

    Also, use optimal exchange sequence for both bswap16 and bswap32.
    whitequark committed May 19, 2019
    Copy the full SHA
    65a89e2 View commit details
  4. Optimize some nops.

    whitequark committed May 19, 2019
    Copy the full SHA
    c5fd823 View commit details
2 changes: 1 addition & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBDIRS = blinky serial boot-uf2-dfu boot-dfu-spiflash
SUBDIRS = blinky printf cdc-acm boot-uf2-dfu boot-dfu-spiflash

all:
@set -e; for dir in $(SUBDIRS); do $(MAKE) -C $${dir} all; done
2 changes: 1 addition & 1 deletion examples/serial/Makefile → examples/cdc-acm/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TARGET = serial
TARGET = cdc-acm
LIBRARIES = fx2 fx2usb fx2isrs
MODEL = small

File renamed without changes.
35 changes: 13 additions & 22 deletions firmware/library/bswap.c
Original file line number Diff line number Diff line change
@@ -4,37 +4,28 @@
uint16_t bswap16(uint16_t value) __naked {
value;
__asm;
mov a, dph
mov dpl, dph
mov dpl, a
#if defined(__SDCC_MODEL_HUGE)
ljmp __sdcc_banked_ret
xch a, dpl ; 2c
xch a, dph ; 2c
xch a, dpl ; 2c
#if !defined(__SDCC_MODEL_HUGE)
ret ; 4c
#else
ret
ljmp __sdcc_banked_ret
#endif
__endasm;
}

uint32_t bswap32(uint32_t value) __naked {
value;
__asm;
#if defined(__SDCC_MODEL_SMALL)
ar0 = 0x00
push ar0
#endif
mov r0, a
mov a, dpl
mov dpl, r0
mov r0, b
mov b, dph
mov dph, r0
#if defined(__SDCC_MODEL_SMALL)
pop ar0
#endif
#if defined(__SDCC_MODEL_HUGE)
ljmp __sdcc_banked_ret
xch a, dpl ; 2c
xch a, b ; 2c
xch a, dph ; 2c
xch a, b ; 2c
#if !defined(__SDCC_MODEL_HUGE)
ret ; 4c
#else
ret
ljmp __sdcc_banked_ret
#endif
__endasm;
}
8 changes: 4 additions & 4 deletions firmware/library/delay.c
Original file line number Diff line number Diff line change
@@ -200,7 +200,7 @@ void delay_ms(uint16_t count) __naked {
mov r7, dph

// overhead = (cycle tally)
mov a, #18
mov a, #17
push acc

00000$:
@@ -211,10 +211,10 @@ void delay_ms(uint16_t count) __naked {
dec r6 ; 1c
cjne r6, #0xff, 00001$ ; 4c
dec r7 ; 1c

00001$:
mov dpl, #(1000&0xff) ; 2c
mov dph, #(1000>>8) ; 2c

// count_us = 1000
mov dptr, #1000 ; 3c
lcall _delay_us_overhead

sjmp 00000$ ; 3c
29 changes: 15 additions & 14 deletions firmware/library/include/fx2debug.h
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
push ar3 \
push ar2 \
\
mov r2, _ASM_HASH 4 \
mov r2, _ASM_HASH (00002$-00001$) \
mov r3, _ASM_HASH 0 \
mov r4, dpl \
mov r5, dpl \
@@ -45,28 +45,29 @@
mov a, r3 \
00001$: \
clr _ASM_REG(tx) ; 2c \
sjmp 00002$ ; 3c \
sjmp 00003$ ; 3c \
00002$: \
mov _ASM_REG(tx), c \
sjmp 00002$ \
sjmp 00003$ \
mov _ASM_REG(tx), c \
sjmp 00002$ \
sjmp 00003$ \
mov _ASM_REG(tx), c \
sjmp 00002$ \
sjmp 00003$ \
mov _ASM_REG(tx), c \
sjmp 00002$ \
sjmp 00003$ \
mov _ASM_REG(tx), c \
sjmp 00002$ \
sjmp 00003$ \
mov _ASM_REG(tx), c \
sjmp 00002$ \
sjmp 00003$ \
mov _ASM_REG(tx), c \
sjmp 00002$ \
sjmp 00003$ \
mov _ASM_REG(tx), c \
sjmp 00002$ \
sjmp 00003$ \
setb _ASM_REG(tx) \
sjmp 00002$ \
sjmp 00003$ \
sjmp 00003$ \
sjmp 00004$ \
\
00002$: \
00003$: \
add a, r2 ; 1c \
mov r3, a ; 1c \
\
@@ -82,7 +83,7 @@
mov a, r3 ; 1c \
jmp @a+dptr ; 3c \
\
00003$: \
00004$: \
mov dpl, r5 \
\
pop ar2 \
27 changes: 15 additions & 12 deletions firmware/library/include/fx2delay.h
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@

#if !defined(__SDCC_MODEL_HUGE)
#pragma callee_saves delay_ms
#pragma callee_saves _delay_us_overhead
#pragma callee_saves delay_us
#pragma callee_saves delay_4c
#endif
@@ -20,7 +19,7 @@ void delay_ms(uint16_t count_ms);
* `count_us` must be no greater than 21845, and `overh_c` must be no greater than 128.
*
* This function is cycle-accurate at any CPU clock frequency provided that the delay is not less
* than the intrinsic overhead of up to 100 processor cycles.
* than the intrinsic overhead of up to 100 processor cycles (9..33 microseconds).
*/
void delay_us_overhead(uint16_t count_us, uint8_t overh_c) __reentrant;

@@ -32,7 +31,7 @@ void delay_us(uint16_t count_us);

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

@@ -57,9 +56,15 @@ void delay_4c(uint16_t count_4c);
#endif

#ifndef DOXYGEN
#define _NOP2 __asm__("nop \n nop")
#define _NOP3 __asm__("nop \n nop \n nop")
#define _NOPn(n) __asm__("lcall _nop" #n)
// Accumulator doesn't need to be preserved
#define _NOP1 __asm__("nop") // 1b 1c
#define _NOP2 __asm__("nop \n nop") // 2b 2c
#define _NOP3 __asm__("ajmp .+2") // 2b 3c
#define _NOP4 __asm__("nop \n movc a, @a+pc") // 2b 4c
#define _NOP5 __asm__("nop \n nop \n movc a, @a+pc") // 3b 5c
#define _NOP6 __asm__("ajmp .+2 \n movc a, @a+pc") // 3b 6c
#define _NOP7 __asm__("acall .+2 \n ret") // 3b 7c
#define _NOPn(n) __asm__("lcall _nop"#n) // 3b nc 8<=n<=16
#endif

/**
@@ -68,21 +73,19 @@ void delay_4c(uint16_t count_4c);
* See TRM 15.15 for details.
*
* This macro produces very compact code, using only 2 or 3 bytes per instance.
* This comes with a tradeoff that `SYNCDELAYLEN` values between 4 and 7
* result in a 8 cycle delay.
*/
#if SYNCDELAYLEN == 2
#define SYNCDELAY _NOP2
#elif SYNCDELAYLEN == 3
#define SYNCDELAY _NOP3
#elif SYNCDELAYLEN == 4
#define SYNCDELAY _NOPn(8) // lcall 4c ret 4c
#define SYNCDELAY _NOP4
#elif SYNCDELAYLEN == 5
#define SYNCDELAY _NOPn(8) // lcall 4c ret 4c
#define SYNCDELAY _NOP5
#elif SYNCDELAYLEN == 6
#define SYNCDELAY _NOPn(8) // lcall 4c ret 4c
#define SYNCDELAY _NOP6
#elif SYNCDELAYLEN == 7
#define SYNCDELAY _NOPn(8) // lcall 4c ret 4c
#define SYNCDELAY _NOP7
#elif SYNCDELAYLEN == 8
#define SYNCDELAY _NOPn(8)
#elif SYNCDELAYLEN == 9
3 changes: 2 additions & 1 deletion firmware/library/uf2scsi.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <fx2lib.h>
#include <fx2uf2.h>
@@ -102,7 +103,7 @@ bool uf2_scsi_data_in(uint8_t lun, __xdata uint8_t *buffer, uint16_t length) __r
xmemclr(buffer, length);

data->additional_length = sizeof(struct scsi_inquiry_data) -
(__builtin_offsetof(struct scsi_inquiry_data, additional_length) +
(offsetof(struct scsi_inquiry_data, additional_length) +
sizeof(data->additional_length));

// SBC-2 (Direct access block device).