Skip to content

Commit

Permalink
Remove volatile modifier from hal_port_t. A hal port is always cast
Browse files Browse the repository at this point in the history
into a pointer by SHMPTR(), which forcefully drops the volatile attribute.
In modern C/C++ a warning is emitted when you declare volatile scalar
arguments or volatile return values. Using volatile in these cases have
always been problematic for what they actually mean and should do.

Note that not all volatile modifiers are removed because many are in
the context of pointer references, where they are important.
  • Loading branch information
BsAtHome committed Dec 1, 2024
1 parent fa261b5 commit 6b61433
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 34 deletions.
3 changes: 2 additions & 1 deletion src/hal/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,11 @@ typedef volatile rtapi_u32 hal_u32_t;
typedef volatile rtapi_s32 hal_s32_t;
typedef volatile rtapi_u64 hal_u64_t;
typedef volatile rtapi_s64 hal_s64_t;
typedef volatile int hal_port_t;
typedef int hal_port_t;
typedef double real_t __attribute__((aligned(8)));
typedef rtapi_u64 ireal_t __attribute__((aligned(8))); // integral type as wide as real_t / hal_float_t

#define hal_float_nv_t real_t
#define hal_float_t volatile real_t

/** HAL "data union" structure
Expand Down
8 changes: 4 additions & 4 deletions src/hal/halmodule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,19 @@ PyObject *to_python(bool b) {
return PyBool_FromLong(b);
}

PyObject *to_python(hal_u32_t u) {
PyObject *to_python(rtapi_u32 u) {
return PyLong_FromUnsignedLong(u);
}

PyObject *to_python(hal_s32_t i) {
PyObject *to_python(rtapi_s32 i) {
return PyLong_FromLong(i);
}

PyObject *to_python(hal_u64_t u) {
PyObject *to_python(rtapi_u64 u) {
return PyLong_FromUnsignedLongLong(u);
}

PyObject *to_python(hal_s64_t i) {
PyObject *to_python(rtapi_s64 i) {
return PyLong_FromLongLong(i);
}

Expand Down
28 changes: 14 additions & 14 deletions src/hal/user_comps/xhc-whb04b-6/hal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ bool Hal::isInitialized()
return mIsInitialized;
}
// ----------------------------------------------------------------------
hal_float_t Hal::getAxisXPosition(bool absolute) const
hal_float_nv_t Hal::getAxisXPosition(bool absolute) const
{
if (absolute)
{
Expand All @@ -588,7 +588,7 @@ hal_float_t Hal::getAxisXPosition(bool absolute) const
return *memory->in.axisXPositionRelative;
}
// ----------------------------------------------------------------------
hal_float_t Hal::getAxisYPosition(bool absolute) const
hal_float_nv_t Hal::getAxisYPosition(bool absolute) const
{
if (absolute)
{
Expand All @@ -597,7 +597,7 @@ hal_float_t Hal::getAxisYPosition(bool absolute) const
return *memory->in.axisYPositionRelative;
}
// ----------------------------------------------------------------------
hal_float_t Hal::getAxisZPosition(bool absolute) const
hal_float_nv_t Hal::getAxisZPosition(bool absolute) const
{
if (absolute)
{
Expand All @@ -606,7 +606,7 @@ hal_float_t Hal::getAxisZPosition(bool absolute) const
return *memory->in.axisZPositionRelative;
}
// ----------------------------------------------------------------------
hal_float_t Hal::getAxisAPosition(bool absolute) const
hal_float_nv_t Hal::getAxisAPosition(bool absolute) const
{
if (absolute)
{
Expand All @@ -615,7 +615,7 @@ hal_float_t Hal::getAxisAPosition(bool absolute) const
return *memory->in.axisAPositionRelative;
}
// ----------------------------------------------------------------------
hal_float_t Hal::getAxisBPosition(bool absolute) const
hal_float_nv_t Hal::getAxisBPosition(bool absolute) const
{
if (absolute)
{
Expand All @@ -624,7 +624,7 @@ hal_float_t Hal::getAxisBPosition(bool absolute) const
return *memory->in.axisBPositionRelative;
}
// ----------------------------------------------------------------------
hal_float_t Hal::getAxisCPosition(bool absolute) const
hal_float_nv_t Hal::getAxisCPosition(bool absolute) const
{
if (absolute)
{
Expand Down Expand Up @@ -692,7 +692,7 @@ void Hal::setAxisCActive(bool enabled)
*mHalCout << "hal C axis active" << endl;
}
// ----------------------------------------------------------------------
void Hal::setStepSize(const hal_float_t stepSize)
void Hal::setStepSize(const hal_float_nv_t stepSize)
{
*memory->out.axisXJogScale = stepSize;
*memory->out.axisYJogScale = stepSize;
Expand Down Expand Up @@ -848,32 +848,32 @@ void Hal::setFeedMinus(bool enabled)
setPin(enabled, KeyCodes::Buttons.feed_minus.text);
}
// ----------------------------------------------------------------------
hal_float_t Hal::getspindleSpeedCmd() const
hal_float_nv_t Hal::getspindleSpeedCmd() const
{
return *memory->in.spindleSpeedCmd;
}
// ----------------------------------------------------------------------
hal_float_t Hal::getspindleSpeedChangeIncrease() const
hal_float_nv_t Hal::getspindleSpeedChangeIncrease() const
{
return *memory->out.spindleDoIncrease;
}
// ----------------------------------------------------------------------
hal_float_t Hal::getspindleSpeedChangeDecrease() const
hal_float_nv_t Hal::getspindleSpeedChangeDecrease() const
{
return *memory->out.spindleDoDecrease;
}
// ----------------------------------------------------------------------
hal_float_t Hal::getSpindleOverrideValue() const
hal_float_nv_t Hal::getSpindleOverrideValue() const
{
return *memory->in.spindleOverrideValue;
}
// ----------------------------------------------------------------------
hal_float_t Hal::getFeedOverrideMaxVel() const
hal_float_nv_t Hal::getFeedOverrideMaxVel() const
{
return *memory->in.feedOverrideMaxVel;
}
// ----------------------------------------------------------------------
hal_float_t Hal::getFeedOverrideValue() const
hal_float_nv_t Hal::getFeedOverrideValue() const
{
return *memory->in.feedOverrideValue;
}
Expand Down Expand Up @@ -913,7 +913,7 @@ void Hal::setFeedValueSelectedLead(bool selected)
*memory->out.feedValueSelected_lead = selected;
}
// ----------------------------------------------------------------------
void Hal::setFeedOverrideScale(hal_float_t scale)
void Hal::setFeedOverrideScale(hal_float_nv_t scale)
{
*memory->out.feedOverrideScale = scale;
}
Expand Down
28 changes: 14 additions & 14 deletions src/hal/user_comps/xhc-whb04b-6/hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class Hal

//! Sets the new feed rate. The step mode must be set accordingly.
//! \param feedRate the new feed rate independent of step mode
void setStepSize(const hal_float_t feedRate);
void setStepSize(const hal_float_nv_t feedRate);
//! If lead is active.
void setLead();
//! Sets the hal state of the respective pin (reset). Usually called in case the reset
Expand Down Expand Up @@ -416,13 +416,13 @@ class Hal
void setFeedMinus(bool enabled);
//! Returns the current Max Velocity value.
//! \sa Hal::In::feedOverrideMaxVel
hal_float_t getFeedOverrideMaxVel() const;
hal_float_nv_t getFeedOverrideMaxVel() const;
//! Returns the current feed override value.
//! \sa Hal::In::feedOverrideValue
//! \return the current feed override value v: 0 <= v <= 1
hal_float_t getFeedOverrideValue() const;
hal_float_nv_t getFeedOverrideValue() const;
//! \xrefitem HalMemory::Out::feedOverrideScale setter
void setFeedOverrideScale(hal_float_t scale);
void setFeedOverrideScale(hal_float_nv_t scale);

//! Propagates the feed value 0.001 selection state to hal.
//! \sa Hal::Out::feedValueSelected_2
Expand Down Expand Up @@ -455,13 +455,13 @@ class Hal

//! Returns the spindle speed.
//! \return the spindle speed in rounds per second
hal_float_t getspindleSpeedCmd() const;
hal_float_t getspindleSpeedChangeIncrease() const;
hal_float_t getspindleSpeedChangeDecrease() const;
hal_float_nv_t getspindleSpeedCmd() const;
hal_float_nv_t getspindleSpeedChangeIncrease() const;
hal_float_nv_t getspindleSpeedChangeDecrease() const;
//! Returns the current spindle override value.
//! \sa Hal::In::spindleOverrideValue
//! \return the current spindle override value v: 0 <= v <= 1
hal_float_t getSpindleOverrideValue() const;
hal_float_nv_t getSpindleOverrideValue() const;
//! \sa setSpindleOverridePlus(bool, size_t)
void setSpindleOverridePlus(bool enabled);
//! \sa setSpindleOverrideMinus(bool, size_t)
Expand Down Expand Up @@ -548,17 +548,17 @@ class Hal
//! Returns the axis position.
//! \param absolute true absolute, false relative
//! \return the absolute or relative position in machine units
hal_float_t getAxisXPosition(bool absolute) const;
hal_float_nv_t getAxisXPosition(bool absolute) const;
//! \xrefitem getAxisXPosition(bool)
hal_float_t getAxisYPosition(bool absolute) const;
hal_float_nv_t getAxisYPosition(bool absolute) const;
//! \xrefitem getAxisXPosition(bool)
hal_float_t getAxisZPosition(bool absolute) const;
hal_float_nv_t getAxisZPosition(bool absolute) const;
//! \xrefitem getAxisXPosition(bool)
hal_float_t getAxisAPosition(bool absolute) const;
hal_float_nv_t getAxisAPosition(bool absolute) const;
//! \xrefitem getAxisXPosition(bool)
hal_float_t getAxisBPosition(bool absolute) const;
hal_float_nv_t getAxisBPosition(bool absolute) const;
//! \xrefitem getAxisXPosition(bool)
hal_float_t getAxisCPosition(bool absolute) const;
hal_float_nv_t getAxisCPosition(bool absolute) const;


private:
Expand Down
2 changes: 1 addition & 1 deletion src/libnml/buffer/shmem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extern "C" {
static double last_non_zero_x;
static double last_x;

static int not_zero(volatile double x)
static int not_zero(double x)
{
last_x = x;
if (x < -1E-6 && last_x < -1E-6) {
Expand Down

0 comments on commit 6b61433

Please sign in to comment.