From 13a01fe7a86725b28c7e2108d335905286eccf3e Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 27 Aug 2020 15:41:47 +0700 Subject: [PATCH] change token type from uintptr_t to uint32_t --- cores/nRF5/HardwarePWM.cpp | 12 ++++++------ cores/nRF5/HardwarePWM.h | 8 ++++---- cores/nRF5/Tone.cpp | 2 +- cores/nRF5/wiring_analog.cpp | 2 +- libraries/Servo/src/nrf52/Servo.cpp | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cores/nRF5/HardwarePWM.cpp b/cores/nRF5/HardwarePWM.cpp index 47c59a86..d2ad8e5b 100644 --- a/cores/nRF5/HardwarePWM.cpp +++ b/cores/nRF5/HardwarePWM.cpp @@ -54,10 +54,10 @@ HardwarePWM* HwPWMx[] = }; #if CFG_DEBUG -bool can_stringify_token(uintptr_t token) +bool can_stringify_token(uint32_t token) { uint8_t * t = (uint8_t *)&token; - for (size_t i = 0; i < sizeof(uintptr_t); ++i, ++t) + for (size_t i = 0; i < sizeof(uint32_t); ++i, ++t) { uint8_t x = *t; if ((x < 0x20) || (x > 0x7E)) return false; @@ -71,7 +71,7 @@ void HardwarePWM::DebugOutput(Stream& logger) logger.printf("HwPWM Debug:"); for (size_t i = 0; i < count; i++) { HardwarePWM const * pwm = HwPWMx[i]; - uintptr_t token = pwm->_owner_token; + uint32_t token = pwm->_owner_token; logger.printf(" || %d:", i); if (can_stringify_token(token)) { uint8_t * t = (uint8_t*)(&token); @@ -271,7 +271,7 @@ uint8_t HardwarePWM::freeChannelCount(void) const } // returns true ONLY when (1) no PWM channel has a pin, and (2) the owner token is nullptr -bool HardwarePWM::takeOwnership(uintptr_t token) +bool HardwarePWM::takeOwnership(uint32_t token) { if (token == 0) { LOG_LV1("HwPWM", "zero / nullptr is not a valid ownership token (attempted use in takeOwnership)"); @@ -288,12 +288,12 @@ bool HardwarePWM::takeOwnership(uintptr_t token) if ( this->enabled() ) return false; // Use C++11 atomic CAS operation - uintptr_t expectedValue = 0U; + uint32_t expectedValue = 0U; return this->_owner_token.compare_exchange_strong(expectedValue, token); } // returns true ONLY when (1) no PWM channel has a pin attached, and (2) the owner token matches -bool HardwarePWM::releaseOwnership(uintptr_t token) +bool HardwarePWM::releaseOwnership(uint32_t token) { if (token == 0) { LOG_LV1("HwPWM", "zero / nullptr is not a valid ownership token (attempted use in releaseOwnership)"); diff --git a/cores/nRF5/HardwarePWM.h b/cores/nRF5/HardwarePWM.h index 55623bf5..47ec16c5 100644 --- a/cores/nRF5/HardwarePWM.h +++ b/cores/nRF5/HardwarePWM.h @@ -51,7 +51,7 @@ class HardwarePWM private: enum { MAX_CHANNELS = 4 }; // Max channel per group NRF_PWM_Type * const _pwm; - std::atomic_uintptr_t _owner_token; + std::atomic_uint32_t _owner_token; uint16_t _seq0[MAX_CHANNELS]; @@ -70,13 +70,13 @@ class HardwarePWM // Cooperative ownership sharing // returns true ONLY when (1) no PWM channel has a pin, and (2) the owner token is nullptr - bool takeOwnership (uintptr_t token); + bool takeOwnership (uint32_t token); // returns true ONLY when (1) no PWM channel has a pin attached, and (2) the owner token matches - bool releaseOwnership(uintptr_t token); + bool releaseOwnership(uint32_t token); // allows caller to verify that they own the peripheral - bool isOwner(uintptr_t token) const + bool isOwner(uint32_t token) const { return this->_owner_token == token; } diff --git a/cores/nRF5/Tone.cpp b/cores/nRF5/Tone.cpp index b4b44113..b29a6ddd 100644 --- a/cores/nRF5/Tone.cpp +++ b/cores/nRF5/Tone.cpp @@ -48,7 +48,7 @@ static HardwarePWM * const _HwPWM = HwPWMx[2]; // Defined a struct, to simplify validation testing ... also provides context when debugging class TonePwmConfig { private: - const uintptr_t toneToken = 0x656e6f54; //< 'T' 'o' 'n' 'e' + const uint32_t toneToken = 0x656e6f54; //< 'T' 'o' 'n' 'e' uint64_t pulse_count; //< total number of PWM pulses uint32_t seq0_refresh; //< count of pulses for each SEQ0 iteration uint32_t seq1_refresh; //< count of pulses for each SEQ1 iteration diff --git a/cores/nRF5/wiring_analog.cpp b/cores/nRF5/wiring_analog.cpp index 93c78fbb..7065b89a 100644 --- a/cores/nRF5/wiring_analog.cpp +++ b/cores/nRF5/wiring_analog.cpp @@ -47,7 +47,7 @@ extern "C" { static uint8_t _analogResolution = 8; // default is 256 levels -static uintptr_t _analogToken = 0x676f6c41; // 'A' 'l' 'o' 'g' +static uint32_t _analogToken = 0x676f6c41; // 'A' 'l' 'o' 'g' /** * This will apply to all PWM Hardware currently used by analogWrite(), diff --git a/libraries/Servo/src/nrf52/Servo.cpp b/libraries/Servo/src/nrf52/Servo.cpp index 506a9519..015bddf5 100644 --- a/libraries/Servo/src/nrf52/Servo.cpp +++ b/libraries/Servo/src/nrf52/Servo.cpp @@ -21,7 +21,7 @@ #include #include -static uintptr_t _servoToken = 0x76726553; // 'S' 'e' 'r' 'v' +static uint32_t _servoToken = 0x76726553; // 'S' 'e' 'r' 'v' static servo_t servos[MAX_SERVOS]; // static array of servo structures uint8_t ServoCount = 0; // the total number of attached servos