From 34cfbc90cdb95288e5ec928baf5484f580426e9c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 22 May 2017 13:47:43 -0500 Subject: [PATCH] Use new attribute macros in more places --- Marlin/macros.h | 12 ++++++------ Marlin/nozzle.cpp | 32 ++++++++++++++++---------------- Marlin/nozzle.h | 42 +++++++++++++++++++++--------------------- Marlin/spi.h | 31 ++++++++++--------------------- Marlin/temperature.cpp | 2 +- Marlin/temperature.h | 3 +-- 6 files changed, 55 insertions(+), 67 deletions(-) diff --git a/Marlin/macros.h b/Marlin/macros.h index 3e3237a1d..e7283f867 100644 --- a/Marlin/macros.h +++ b/Marlin/macros.h @@ -29,12 +29,12 @@ #define XYZ 3 #define FORCE_INLINE __attribute__((always_inline)) inline - -#define _O0 __attribute__((optimize("O0"))) -#define _Os __attribute__((optimize("Os"))) -#define _O1 __attribute__((optimize("O1"))) -#define _O2 __attribute__((optimize("O2"))) -#define _O3 __attribute__((optimize("O3"))) +#define _UNUSED __attribute__((unused)) +#define _O0 __attribute__((optimize("O0"))) +#define _Os __attribute__((optimize("Os"))) +#define _O1 __attribute__((optimize("O1"))) +#define _O2 __attribute__((optimize("O2"))) +#define _O3 __attribute__((optimize("O3"))) // Bracket code that shouldn't be interrupted #ifndef CRITICAL_SECTION_START diff --git a/Marlin/nozzle.cpp b/Marlin/nozzle.cpp index 92f697df1..569fba62a 100644 --- a/Marlin/nozzle.cpp +++ b/Marlin/nozzle.cpp @@ -12,9 +12,9 @@ * @param strokes number of strokes to execute */ void Nozzle::stroke( - __attribute__((unused)) point_t const &start, - __attribute__((unused)) point_t const &end, - __attribute__((unused)) uint8_t const &strokes + _UNUSED point_t const &start, + _UNUSED point_t const &end, + _UNUSED uint8_t const &strokes ) { #if ENABLED(NOZZLE_CLEAN_FEATURE) @@ -56,10 +56,10 @@ void Nozzle::stroke( * @param objects number of objects to create */ void Nozzle::zigzag( - __attribute__((unused)) point_t const &start, - __attribute__((unused)) point_t const &end, - __attribute__((unused)) uint8_t const &strokes, - __attribute__((unused)) uint8_t const &objects + _UNUSED point_t const &start, + _UNUSED point_t const &end, + _UNUSED uint8_t const &strokes, + _UNUSED uint8_t const &objects ) { #if ENABLED(NOZZLE_CLEAN_FEATURE) const float A = nozzle_clean_horizontal ? nozzle_clean_height : nozzle_clean_length, // [twice the] Amplitude @@ -114,10 +114,10 @@ void Nozzle::zigzag( * @param radius radius of circle */ void Nozzle::circle( - __attribute__((unused)) point_t const &start, - __attribute__((unused)) point_t const &middle, - __attribute__((unused)) uint8_t const &strokes, - __attribute__((unused)) float const &radius + _UNUSED point_t const &start, + _UNUSED point_t const &middle, + _UNUSED uint8_t const &strokes, + _UNUSED float const &radius ) { #if ENABLED(NOZZLE_CLEAN_FEATURE) if (strokes == 0) return; @@ -177,10 +177,10 @@ void Nozzle::circle( * @param argument depends on the cleaning pattern */ void Nozzle::clean( - __attribute__((unused)) uint8_t const &pattern, - __attribute__((unused)) uint8_t const &strokes, - __attribute__((unused)) float const &radius, - __attribute__((unused)) uint8_t const &objects + _UNUSED uint8_t const &pattern, + _UNUSED uint8_t const &strokes, + _UNUSED float const &radius, + _UNUSED uint8_t const &objects ) { #if ENABLED(NOZZLE_CLEAN_FEATURE) #if ENABLED(DELTA) @@ -209,7 +209,7 @@ void Nozzle::clean( } void Nozzle::park( - __attribute__((unused)) uint8_t const &z_action + _UNUSED uint8_t const &z_action ) { #if ENABLED(NOZZLE_PARK_FEATURE) float const z = current_position[Z_AXIS]; diff --git a/Marlin/nozzle.h b/Marlin/nozzle.h index 944dd5d21..39c007f63 100644 --- a/Marlin/nozzle.h +++ b/Marlin/nozzle.h @@ -50,10 +50,10 @@ class Nozzle { * @param strokes number of strokes to execute */ static void stroke( - __attribute__((unused)) point_t const &start, - __attribute__((unused)) point_t const &end, - __attribute__((unused)) uint8_t const &strokes - ) __attribute__((optimize ("Os"))); + _UNUSED point_t const &start, + _UNUSED point_t const &end, + _UNUSED uint8_t const &strokes + ) _Os; /** * @brief Zig-zag clean pattern @@ -65,11 +65,11 @@ class Nozzle { * @param objects number of objects to create */ static void zigzag( - __attribute__((unused)) point_t const &start, - __attribute__((unused)) point_t const &end, - __attribute__((unused)) uint8_t const &strokes, - __attribute__((unused)) uint8_t const &objects - ) __attribute__((optimize ("Os"))); + _UNUSED point_t const &start, + _UNUSED point_t const &end, + _UNUSED uint8_t const &strokes, + _UNUSED uint8_t const &objects + ) _Os; /** * @brief Circular clean pattern @@ -80,11 +80,11 @@ class Nozzle { * @param radius radius of circle */ static void circle( - __attribute__((unused)) point_t const &start, - __attribute__((unused)) point_t const &middle, - __attribute__((unused)) uint8_t const &strokes, - __attribute__((unused)) float const &radius - ) __attribute__((optimize ("Os"))); + _UNUSED point_t const &start, + _UNUSED point_t const &middle, + _UNUSED uint8_t const &strokes, + _UNUSED float const &radius + ) _Os; public: /** @@ -95,15 +95,15 @@ class Nozzle { * @param argument depends on the cleaning pattern */ static void clean( - __attribute__((unused)) uint8_t const &pattern, - __attribute__((unused)) uint8_t const &strokes, - __attribute__((unused)) float const &radius, - __attribute__((unused)) uint8_t const &objects = 0 - ) __attribute__((optimize ("Os"))); + _UNUSED uint8_t const &pattern, + _UNUSED uint8_t const &strokes, + _UNUSED float const &radius, + _UNUSED uint8_t const &objects = 0 + ) _Os; static void park( - __attribute__((unused)) uint8_t const &z_action - ) __attribute__((optimize ("Os"))); + _UNUSED uint8_t const &z_action + ) _Os; }; #endif diff --git a/Marlin/spi.h b/Marlin/spi.h index 349246952..c4b86005a 100644 --- a/Marlin/spi.h +++ b/Marlin/spi.h @@ -27,37 +27,26 @@ #include "softspi.h" template -class Spi { - static SoftSPI softSpi; +class SPI { + static SoftSPI softSPI; public: - inline __attribute__((always_inline)) - static void init() { - softSpi.begin(); - } - inline __attribute__((always_inline)) - static void send(uint8_t data) { - softSpi.send(data); - } - inline __attribute__((always_inline)) - static uint8_t receive() { - return softSpi.receive(); - } + FORCE_INLINE static void init() { softSPI.begin(); } + FORCE_INLINE static void send(uint8_t data) { softSPI.send(data); } + FORCE_INLINE static uint8_t receive() { return softSPI.receive(); } }; -//hardware spi +// Hardware SPI template<> -class Spi { +class SPI { public: - inline __attribute__((always_inline)) - static void init() { + FORCE_INLINE static void init() { OUT_WRITE(SCK_PIN, LOW); OUT_WRITE(MOSI_PIN, HIGH); SET_INPUT(MISO_PIN); WRITE(MISO_PIN, HIGH); } - inline __attribute__((always_inline)) - static uint8_t receive() { + FORCE_INLINE static uint8_t receive() { SPDR = 0; for (;!TEST(SPSR, SPIF);); return SPDR; @@ -65,4 +54,4 @@ class Spi { }; -#endif +#endif // __SPI_H__ diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index d7d681430..f94d98b96 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -935,7 +935,7 @@ void Temperature::updateTemperaturesFromRawValues() { #ifndef MAX6675_DO_PIN #define MAX6675_DO_PIN MISO_PIN #endif - Spi max6675_spi; + SPI max6675_spi; #endif /** diff --git a/Marlin/temperature.h b/Marlin/temperature.h index a3c4372df..9b85bbde1 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -288,8 +288,7 @@ class Temperature { /** * Call periodically to manage heaters */ - //static void manage_heater(); // changed to address compiler error - static void manage_heater() __attribute__((__optimize__("O2"))); + static void manage_heater() _O2; // Added _O2 to work around a compiler error /** * Preheating hotends