Kaynağa Gözat

Add hidden Serial overflow debug options

etagle 6 yıl önce
ebeveyn
işleme
99af086cea

+ 21
- 0
Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp Dosyayı Görüntüle

72
     uint8_t rx_dropped_bytes = 0;
72
     uint8_t rx_dropped_bytes = 0;
73
   #endif
73
   #endif
74
 
74
 
75
+  #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
76
+    uint8_t rx_buffer_overruns = 0;
77
+  #endif
78
+
79
+  #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
80
+    uint8_t rx_framing_errors = 0;
81
+  #endif
82
+
75
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
83
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
76
     ring_buffer_pos_t rx_max_enqueued = 0;
84
     ring_buffer_pos_t rx_max_enqueued = 0;
77
   #endif
85
   #endif
99
     // Get the next element
107
     // Get the next element
100
     ring_buffer_pos_t i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
108
     ring_buffer_pos_t i = (ring_buffer_pos_t)(h + 1) & (ring_buffer_pos_t)(RX_BUFFER_SIZE - 1);
101
 
109
 
110
+    // This must read the M_UCSRxA register before reading the received byte to detect error causes
111
+    #if ENABLED(SERIAL_STATS_DROPPED_RX)
112
+      if (TEST(M_UCSRxA, M_DORx) && !++rx_dropped_bytes) --rx_dropped_bytes;
113
+    #endif
114
+
115
+    #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
116
+      if (TEST(M_UCSRxA, M_DORx) && !++rx_buffer_overruns) --rx_buffer_overruns;
117
+    #endif
118
+
119
+    #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
120
+      if (TEST(M_UCSRxA, M_FEx) && !++rx_framing_errors) --rx_framing_errors;
121
+    #endif
122
+
102
     // Read the character from the USART
123
     // Read the character from the USART
103
     uint8_t c = M_UDRx;
124
     uint8_t c = M_UDRx;
104
 
125
 

+ 19
- 0
Marlin/src/HAL/HAL_AVR/MarlinSerial.h Dosyayı Görüntüle

62
 #define M_TXCx             SERIAL_REGNAME(TXC,SERIAL_PORT,)
62
 #define M_TXCx             SERIAL_REGNAME(TXC,SERIAL_PORT,)
63
 #define M_RXCIEx           SERIAL_REGNAME(RXCIE,SERIAL_PORT,)
63
 #define M_RXCIEx           SERIAL_REGNAME(RXCIE,SERIAL_PORT,)
64
 #define M_UDREx            SERIAL_REGNAME(UDRE,SERIAL_PORT,)
64
 #define M_UDREx            SERIAL_REGNAME(UDRE,SERIAL_PORT,)
65
+#define M_FEx              SERIAL_REGNAME(FE,SERIAL_PORT,)
66
+#define M_DORx             SERIAL_REGNAME(DOR,SERIAL_PORT,)
67
+#define M_UPEx             SERIAL_REGNAME(UPE,SERIAL_PORT,)
65
 #define M_UDRIEx           SERIAL_REGNAME(UDRIE,SERIAL_PORT,)
68
 #define M_UDRIEx           SERIAL_REGNAME(UDRIE,SERIAL_PORT,)
66
 #define M_UDRx             SERIAL_REGNAME(UDR,SERIAL_PORT,)
69
 #define M_UDRx             SERIAL_REGNAME(UDR,SERIAL_PORT,)
67
 #define M_UBRRxH           SERIAL_REGNAME(UBRR,SERIAL_PORT,H)
70
 #define M_UBRRxH           SERIAL_REGNAME(UBRR,SERIAL_PORT,H)
91
     extern uint8_t rx_dropped_bytes;
94
     extern uint8_t rx_dropped_bytes;
92
   #endif
95
   #endif
93
 
96
 
97
+  #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
98
+    extern uint8_t rx_buffer_overruns;
99
+  #endif
100
+
101
+  #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
102
+    extern uint8_t rx_framing_errors;
103
+  #endif
104
+
94
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
105
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
95
     extern ring_buffer_pos_t rx_max_enqueued;
106
     extern ring_buffer_pos_t rx_max_enqueued;
96
   #endif
107
   #endif
112
         FORCE_INLINE static uint32_t dropped() { return rx_dropped_bytes; }
123
         FORCE_INLINE static uint32_t dropped() { return rx_dropped_bytes; }
113
       #endif
124
       #endif
114
 
125
 
126
+      #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
127
+        FORCE_INLINE static uint32_t buffer_overruns() { return rx_buffer_overruns; }
128
+      #endif
129
+
130
+      #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
131
+        FORCE_INLINE static uint32_t framing_errors() { return rx_framing_errors; }
132
+      #endif
133
+
115
       #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
134
       #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
116
         FORCE_INLINE static ring_buffer_pos_t rxMaxEnqueued() { return rx_max_enqueued; }
135
         FORCE_INLINE static ring_buffer_pos_t rxMaxEnqueued() { return rx_max_enqueued; }
117
       #endif
136
       #endif

+ 21
- 0
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp Dosyayı Görüntüle

98
     uint8_t rx_dropped_bytes = 0;
98
     uint8_t rx_dropped_bytes = 0;
99
   #endif
99
   #endif
100
 
100
 
101
+  #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
102
+    uint8_t rx_buffer_overruns = 0;
103
+  #endif
104
+
105
+  #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
106
+    uint8_t rx_framing_errors = 0;
107
+  #endif
108
+
101
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
109
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
102
     ring_buffer_pos_t rx_max_enqueued = 0;
110
     ring_buffer_pos_t rx_max_enqueued = 0;
103
   #endif
111
   #endif
308
 
316
 
309
     // Acknowledge errors
317
     // Acknowledge errors
310
     if ((status & UART_SR_OVRE) || (status & UART_SR_FRAME)) {
318
     if ((status & UART_SR_OVRE) || (status & UART_SR_FRAME)) {
319
+
320
+      #if ENABLED(SERIAL_STATS_DROPPED_RX)
321
+        if (status & UART_SR_OVRE && !++rx_dropped_bytes) --rx_dropped_bytes;
322
+      #endif
323
+
324
+      #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
325
+        if (status & UART_SR_OVRE && !++rx_buffer_overruns) --rx_buffer_overruns;
326
+      #endif
327
+
328
+      #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
329
+        if (status & UART_SR_FRAME && !++rx_framing_errors) --rx_framing_errors;
330
+      #endif
331
+
311
       // TODO: error reporting outside ISR
332
       // TODO: error reporting outside ISR
312
       HWUART->UART_CR = UART_CR_RSTSTA;
333
       HWUART->UART_CR = UART_CR_RSTSTA;
313
     }
334
     }

+ 16
- 0
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h Dosyayı Görüntüle

70
   extern uint8_t rx_dropped_bytes;
70
   extern uint8_t rx_dropped_bytes;
71
 #endif
71
 #endif
72
 
72
 
73
+#if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
74
+  extern uint8_t rx_buffer_overruns;
75
+#endif
76
+
77
+#if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
78
+  extern uint8_t rx_framing_errors;
79
+#endif
80
+
73
 #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
81
 #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
74
   extern ring_buffer_pos_t rx_max_enqueued;
82
   extern ring_buffer_pos_t rx_max_enqueued;
75
 #endif
83
 #endif
91
     FORCE_INLINE static uint32_t dropped() { return rx_dropped_bytes; }
99
     FORCE_INLINE static uint32_t dropped() { return rx_dropped_bytes; }
92
   #endif
100
   #endif
93
 
101
 
102
+  #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
103
+    FORCE_INLINE static uint32_t buffer_overruns() { return rx_buffer_overruns; }
104
+  #endif
105
+
106
+  #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
107
+    FORCE_INLINE static uint32_t framing_errors() { return rx_framing_errors; }
108
+  #endif
109
+
94
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
110
   #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
95
     FORCE_INLINE static ring_buffer_pos_t rxMaxEnqueued() { return rx_max_enqueued; }
111
     FORCE_INLINE static ring_buffer_pos_t rxMaxEnqueued() { return rx_max_enqueued; }
96
   #endif
112
   #endif

+ 17
- 0
Marlin/src/gcode/control/M111.cpp Dosyayı Görüntüle

58
   }
58
   }
59
   else {
59
   else {
60
     SERIAL_ECHOPGM(MSG_DEBUG_OFF);
60
     SERIAL_ECHOPGM(MSG_DEBUG_OFF);
61
+    #if !defined(__AVR__) || !defined(USBCON)
62
+      #if ENABLED(SERIAL_STATS_RX_BUFFER_OVERRUNS)
63
+        SERIAL_ECHOLNPAIR("Buffer Overruns: ", customizedSerial.buffer_overruns());
64
+      #endif
65
+
66
+      #if ENABLED(SERIAL_STATS_RX_FRAMING_ERRORS)
67
+        SERIAL_ECHOLNPAIR("Framing Errors: ", customizedSerial.framing_errors());
68
+      #endif
69
+
70
+      #if ENABLED(SERIAL_STATS_DROPPED_RX)
71
+        SERIAL_ECHOLNPAIR("Dropped bytes: ", customizedSerial.dropped());
72
+      #endif
73
+
74
+      #if ENABLED(SERIAL_STATS_MAX_RX_QUEUED)
75
+        SERIAL_ECHOLNPAIR("Max RX Queue Size: ", customizedSerial.rxMaxEnqueued());
76
+      #endif
77
+    #endif //  !defined(__AVR__) || !defined(USBCON)
61
   }
78
   }
62
   SERIAL_EOL();
79
   SERIAL_EOL();
63
 }
80
 }

Loading…
İptal
Kaydet