Browse Source

Merge pull request #6208 from thinkyhead/rc_parity_with_32bit

Patch MarlinSerial to match up with 32-bit version
Scott Lahteine 7 years ago
parent
commit
883c6762c4
3 changed files with 31 additions and 38 deletions
  1. 0
    1
      Marlin/Marlin.h
  2. 28
    34
      Marlin/MarlinSerial.cpp
  3. 3
    3
      Marlin/MarlinSerial.h

+ 0
- 1
Marlin/Marlin.h View File

40
 #include "fastio.h"
40
 #include "fastio.h"
41
 #include "utility.h"
41
 #include "utility.h"
42
 #include "serial.h"
42
 #include "serial.h"
43
-#include "WString.h"
44
 
43
 
45
 #if ENABLED(PRINTCOUNTER)
44
 #if ENABLED(PRINTCOUNTER)
46
   #include "printcounter.h"
45
   #include "printcounter.h"

+ 28
- 34
Marlin/MarlinSerial.cpp View File

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

+ 3
- 3
Marlin/MarlinSerial.h View File

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

Loading…
Cancel
Save