Browse Source

Patch MarlinSerial to match up with 32-bit version

Scott Lahteine 7 years ago
parent
commit
de4e19f17e
2 changed files with 31 additions and 37 deletions
  1. 28
    34
      Marlin/MarlinSerial.cpp
  2. 3
    3
      Marlin/MarlinSerial.h

+ 28
- 34
Marlin/MarlinSerial.cpp View File

@@ -28,9 +28,8 @@
28 28
  * Modified 28 September 2010 by Mark Sproul
29 29
  * Modified 14 February 2016 by Andreas Hardtung (added tx buffer)
30 30
  */
31
-#include "MarlinSerial.h"
32 31
 
33
-#include "stepper.h"
32
+#include "MarlinSerial.h"
34 33
 #include "Marlin.h"
35 34
 
36 35
 // Disable HardwareSerial.cpp to support chips without a UART (Attiny, etc.)
@@ -38,15 +37,16 @@
38 37
 #if !defined(USBCON) && (defined(UBRRH) || defined(UBRR0H) || defined(UBRR1H) || defined(UBRR2H) || defined(UBRR3H))
39 38
 
40 39
   #if UART_PRESENT(SERIAL_PORT)
41
-    ring_buffer_r rx_buffer  =  { { 0 }, 0, 0 };
40
+    ring_buffer_r rx_buffer = { { 0 }, 0, 0 };
42 41
     #if TX_BUFFER_SIZE > 0
43
-      ring_buffer_t tx_buffer  =  { { 0 }, 0, 0 };
42
+      ring_buffer_t tx_buffer = { { 0 }, 0, 0 };
44 43
       static bool _written;
45 44
     #endif
46 45
   #endif
47 46
 
48 47
   #if ENABLED(EMERGENCY_PARSER)
49 48
 
49
+    #include "stepper.h"
50 50
     #include "language.h"
51 51
 
52 52
     // Currently looking for: M108, M112, M410
@@ -134,13 +134,12 @@
134 134
       }
135 135
     }
136 136
 
137
-  #endif
138
-
137
+  #endif // EMERGENCY_PARSER
139 138
 
140 139
   FORCE_INLINE void store_char(unsigned char c) {
141 140
     CRITICAL_SECTION_START;
142
-      uint8_t h = rx_buffer.head;
143
-      uint8_t i = (uint8_t)(h + 1)  & (RX_BUFFER_SIZE - 1);
141
+      const uint8_t h = rx_buffer.head,
142
+                    i = (uint8_t)(h + 1) & (RX_BUFFER_SIZE - 1);
144 143
 
145 144
       // if we should be storing the received character into the location
146 145
       // just before the tail (meaning that the head would advance to the
@@ -162,8 +161,8 @@
162 161
     FORCE_INLINE void _tx_udr_empty_irq(void) {
163 162
       // If interrupts are enabled, there must be more data in the output
164 163
       // buffer. Send the next byte
165
-      uint8_t t = tx_buffer.tail;
166
-      uint8_t c = tx_buffer.buffer[t];
164
+      const uint8_t t = tx_buffer.tail,
165
+                    c = tx_buffer.buffer[t];
167 166
       tx_buffer.tail = (t + 1) & (TX_BUFFER_SIZE - 1);
168 167
 
169 168
       M_UDRx = c;
@@ -189,14 +188,14 @@
189 188
 
190 189
   #ifdef M_USARTx_RX_vect
191 190
     ISR(M_USARTx_RX_vect) {
192
-      unsigned char c  =  M_UDRx;
191
+      const unsigned char c = M_UDRx;
193 192
       store_char(c);
194 193
     }
195 194
   #endif
196 195
 
197 196
   // Public Methods
198 197
 
199
-  void MarlinSerial::begin(long baud) {
198
+  void MarlinSerial::begin(const long baud) {
200 199
     uint16_t baud_setting;
201 200
     bool useU2X = true;
202 201
 
@@ -204,9 +203,7 @@
204 203
       // hard-coded exception for compatibility with the bootloader shipped
205 204
       // with the Duemilanove and previous boards and the firmware on the 8U2
206 205
       // on the Uno and Mega 2560.
207
-      if (baud == 57600) {
208
-        useU2X = false;
209
-      }
206
+      if (baud == 57600) useU2X = false;
210 207
     #endif
211 208
 
212 209
     if (useU2X) {
@@ -240,14 +237,14 @@
240 237
 
241 238
   void MarlinSerial::checkRx(void) {
242 239
     if (TEST(M_UCSRxA, M_RXCx)) {
243
-      uint8_t c  =  M_UDRx;
240
+      const uint8_t c = M_UDRx;
244 241
       store_char(c);
245 242
     }
246 243
   }
247 244
 
248 245
   int MarlinSerial::peek(void) {
249 246
     CRITICAL_SECTION_START;
250
-      int v = rx_buffer.head == rx_buffer.tail ? -1 : rx_buffer.buffer[rx_buffer.tail];
247
+      const int v = rx_buffer.head == rx_buffer.tail ? -1 : rx_buffer.buffer[rx_buffer.tail];
251 248
     CRITICAL_SECTION_END;
252 249
     return v;
253 250
   }
@@ -255,10 +252,9 @@
255 252
   int MarlinSerial::read(void) {
256 253
     int v;
257 254
     CRITICAL_SECTION_START;
258
-      uint8_t t = rx_buffer.tail;
259
-      if (rx_buffer.head == t) {
255
+      const uint8_t t = rx_buffer.tail;
256
+      if (rx_buffer.head == t)
260 257
         v = -1;
261
-      }
262 258
       else {
263 259
         v = rx_buffer.buffer[t];
264 260
         rx_buffer.tail = (uint8_t)(t + 1) & (RX_BUFFER_SIZE - 1);
@@ -269,8 +265,8 @@
269 265
 
270 266
   uint8_t MarlinSerial::available(void) {
271 267
     CRITICAL_SECTION_START;
272
-      uint8_t h = rx_buffer.head,
273
-              t = rx_buffer.tail;
268
+      const uint8_t h = rx_buffer.head,
269
+                    t = rx_buffer.tail;
274 270
     CRITICAL_SECTION_END;
275 271
     return (uint8_t)(RX_BUFFER_SIZE + h - t) & (RX_BUFFER_SIZE - 1);
276 272
   }
@@ -290,13 +286,13 @@
290 286
   #if TX_BUFFER_SIZE > 0
291 287
     uint8_t MarlinSerial::availableForWrite(void) {
292 288
       CRITICAL_SECTION_START;
293
-        uint8_t h = tx_buffer.head;
294
-        uint8_t t = tx_buffer.tail;
289
+        const uint8_t h = tx_buffer.head,
290
+                      t = tx_buffer.tail;
295 291
       CRITICAL_SECTION_END;
296 292
       return (uint8_t)(TX_BUFFER_SIZE + h - t) & (TX_BUFFER_SIZE - 1);
297 293
     }
298 294
 
299
-    void MarlinSerial::write(uint8_t c) {
295
+    void MarlinSerial::write(const uint8_t c) {
300 296
       _written = true;
301 297
       CRITICAL_SECTION_START;
302 298
         bool emty = (tx_buffer.head == tx_buffer.tail);
@@ -312,7 +308,7 @@
312 308
         CRITICAL_SECTION_END;
313 309
         return;
314 310
       }
315
-      uint8_t i = (tx_buffer.head + 1) & (TX_BUFFER_SIZE - 1);
311
+      const uint8_t i = (tx_buffer.head + 1) & (TX_BUFFER_SIZE - 1);
316 312
 
317 313
       // If the output buffer is full, there's nothing for it other than to
318 314
       // wait for the interrupt handler to empty it a bit
@@ -372,25 +368,24 @@
372 368
 
373 369
 
374 370
   void MarlinSerial::print(char c, int base) {
375
-    print((long) c, base);
371
+    print((long)c, base);
376 372
   }
377 373
 
378 374
   void MarlinSerial::print(unsigned char b, int base) {
379
-    print((unsigned long) b, base);
375
+    print((unsigned long)b, base);
380 376
   }
381 377
 
382 378
   void MarlinSerial::print(int n, int base) {
383
-    print((long) n, base);
379
+    print((long)n, base);
384 380
   }
385 381
 
386 382
   void MarlinSerial::print(unsigned int n, int base) {
387
-    print((unsigned long) n, base);
383
+    print((unsigned long)n, base);
388 384
   }
389 385
 
390 386
   void MarlinSerial::print(long n, int base) {
391
-    if (base == 0) {
387
+    if (base == 0)
392 388
       write(n);
393
-    }
394 389
     else if (base == 10) {
395 390
       if (n < 0) {
396 391
         print('-');
@@ -398,9 +393,8 @@
398 393
       }
399 394
       printNumber(n, 10);
400 395
     }
401
-    else {
396
+    else
402 397
       printNumber(n, base);
403
-    }
404 398
   }
405 399
 
406 400
   void MarlinSerial::print(unsigned long n, int base) {

+ 3
- 3
Marlin/MarlinSerial.h View File

@@ -119,21 +119,21 @@
119 119
 
120 120
     public:
121 121
       MarlinSerial() {};
122
-      static void begin(long);
122
+      static void begin(const long);
123 123
       static void end();
124 124
       static int peek(void);
125 125
       static int read(void);
126 126
       static void flush(void);
127 127
       static uint8_t available(void);
128 128
       static void checkRx(void);
129
-      static void write(uint8_t c);
129
+      static void write(const uint8_t c);
130 130
       #if TX_BUFFER_SIZE > 0
131 131
         static uint8_t availableForWrite(void);
132 132
         static void flushTX(void);
133 133
       #endif
134 134
 
135 135
     private:
136
-      static void printNumber(unsigned long, uint8_t);
136
+      static void printNumber(unsigned long, const uint8_t);
137 137
       static void printFloat(double, uint8_t);
138 138
 
139 139
     public:

Loading…
Cancel
Save