From cc6366ec065e36e065d69dfb6921fce03c052dff Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 23 Jan 2019 17:30:40 +0700 Subject: [PATCH] fix pulseIn compile issue #219 use C for countPulseASM --- changelog.md | 3 ++- cores/nRF5/pulse.c | 22 ++++++++++++++++++++++ cores/nRF5/pulse_asm.S | 7 ++++--- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/changelog.md b/changelog.md index 826e5423..7dc83535 100644 --- a/changelog.md +++ b/changelog.md @@ -7,7 +7,8 @@ - Remove Gap.connected(), Gap.getRole() in prefer to BLEConnection API - Added setRssiCallback(), monitorRssi(), getRssi(), stopRssi() for tracking rssi of a connection - rssi_poll and rssi_callback example sketches are added -- Change BLECharacteristic callback signature BLECharacteristic& to BLECharacteristic* +- Change BLECharacteristic callback signature BLECharacteristic& to BLECharacteristic* +- Use AdaCallback thread for BLECharacteristic callbacks # 0.9.3 diff --git a/cores/nRF5/pulse.c b/cores/nRF5/pulse.c index 9dff9f55..f930a980 100644 --- a/cores/nRF5/pulse.c +++ b/cores/nRF5/pulse.c @@ -23,6 +23,28 @@ // See pulse_asm.S extern unsigned long countPulseASM(const volatile uint32_t *port, uint32_t bit, uint32_t stateMask, unsigned long maxloops); +unsigned long countPulseASM(const volatile uint32_t *port, uint32_t bit, uint32_t stateMask, unsigned long maxloops) +{ + unsigned long width = 0; + + // wait for any previous pulse to end + while ((*port & bit) == stateMask) + if (--maxloops == 0) + return 0; + + // wait for the pulse to start + while ((*port & bit) != stateMask) + if (--maxloops == 0) + return 0; + + // wait for the pulse to stop + while ((*port & bit) == stateMask) { + if (++width == maxloops) + return 0; + } + return width; +} + /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds * to 3 minutes in length, but must be called at least a few dozen microseconds diff --git a/cores/nRF5/pulse_asm.S b/cores/nRF5/pulse_asm.S index 34385b6a..309f8667 100644 --- a/cores/nRF5/pulse_asm.S +++ b/cores/nRF5/pulse_asm.S @@ -58,9 +58,9 @@ using the command line: The result has been slightly edited to increase readability. */ - - .cpu cortex-m0plus - .fpu softvfp +/* + .cpu cortex-m4 + .fpu fpv4-sp-d16 .eabi_attribute 20, 1 @ Tag_ABI_FP_denormal .eabi_attribute 21, 1 @ Tag_ABI_FP_exceptions .eabi_attribute 23, 3 @ Tag_ABI_FP_number_model @@ -173,3 +173,4 @@ countPulseASM: pop {r4, r5, pc} .size countPulseASM, .-countPulseASM .ident "GCC: (GNU Tools for ARM Embedded Processors (Arduino build)) 4.8.3 20140228 (release) [ARM/embedded-4_8-branch revision 208322]" +*/