change token type from uintptr_t to uint32_t
This commit is contained in:
1 parent
3cc5b5ba73
commit
13a01fe7a8
5 files changed
+13
-13
No files matched your search
@@ -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)");
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <Arduino.h>
|
||||
#include <Servo.h>
|
||||
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user