Explorar el Código

[LPC176x] Emergency Parser Feature (#10516)

Chris Pepper hace 7 años
padre
commit
2242b98248

+ 3
- 92
Marlin/src/HAL/HAL_AVR/MarlinSerial.cpp Ver fichero

80
   #endif
80
   #endif
81
 
81
 
82
   #if ENABLED(EMERGENCY_PARSER)
82
   #if ENABLED(EMERGENCY_PARSER)
83
-
84
-    bool killed_by_M112; // = false
85
-
86
-    #include "../../module/stepper.h"
87
-
88
-    // Currently looking for: M108, M112, M410
89
-    // If you alter the parser please don't forget to update the capabilities in Conditionals_post.h
90
-
91
-    FORCE_INLINE void emergency_parser(const uint8_t c) {
92
-
93
-      static e_parser_state state = state_RESET;
94
-
95
-      switch (state) {
96
-        case state_RESET:
97
-          switch (c) {
98
-            case ' ': break;
99
-            case 'N': state = state_N;      break;
100
-            case 'M': state = state_M;      break;
101
-            default: state = state_IGNORE;
102
-          }
103
-          break;
104
-
105
-        case state_N:
106
-          switch (c) {
107
-            case '0': case '1': case '2':
108
-            case '3': case '4': case '5':
109
-            case '6': case '7': case '8':
110
-            case '9': case '-': case ' ':   break;
111
-            case 'M': state = state_M;      break;
112
-            default:  state = state_IGNORE;
113
-          }
114
-          break;
115
-
116
-        case state_M:
117
-          switch (c) {
118
-            case ' ': break;
119
-            case '1': state = state_M1;     break;
120
-            case '4': state = state_M4;     break;
121
-            default: state = state_IGNORE;
122
-          }
123
-          break;
124
-
125
-        case state_M1:
126
-          switch (c) {
127
-            case '0': state = state_M10;    break;
128
-            case '1': state = state_M11;    break;
129
-            default: state = state_IGNORE;
130
-          }
131
-          break;
132
-
133
-        case state_M10:
134
-          state = (c == '8') ? state_M108 : state_IGNORE;
135
-          break;
136
-
137
-        case state_M11:
138
-          state = (c == '2') ? state_M112 : state_IGNORE;
139
-          break;
140
-
141
-        case state_M4:
142
-          state = (c == '1') ? state_M41 : state_IGNORE;
143
-          break;
144
-
145
-        case state_M41:
146
-          state = (c == '0') ? state_M410 : state_IGNORE;
147
-          break;
148
-
149
-        case state_IGNORE:
150
-          if (c == '\n') state = state_RESET;
151
-          break;
152
-
153
-        default:
154
-          if (c == '\n') {
155
-            switch (state) {
156
-              case state_M108:
157
-                wait_for_user = wait_for_heatup = false;
158
-                break;
159
-              case state_M112:
160
-                killed_by_M112 = true;
161
-                break;
162
-              case state_M410:
163
-                quickstop_stepper();
164
-                break;
165
-              default:
166
-                break;
167
-            }
168
-            state = state_RESET;
169
-          }
170
-      }
171
-    }
172
-
173
-  #endif // EMERGENCY_PARSER
83
+    #include "../../feature/emergency_parser.h"
84
+  #endif
174
 
85
 
175
   FORCE_INLINE void store_rxd_char() {
86
   FORCE_INLINE void store_rxd_char() {
176
 
87
 
249
     #endif // SERIAL_XON_XOFF
160
     #endif // SERIAL_XON_XOFF
250
 
161
 
251
     #if ENABLED(EMERGENCY_PARSER)
162
     #if ENABLED(EMERGENCY_PARSER)
252
-      emergency_parser(c);
163
+      emergency_parser.update(c);
253
     #endif
164
     #endif
254
   }
165
   }
255
 
166
 

+ 0
- 4
Marlin/src/HAL/HAL_AVR/MarlinSerial.h Ver fichero

94
     extern ring_buffer_pos_t rx_max_enqueued;
94
     extern ring_buffer_pos_t rx_max_enqueued;
95
   #endif
95
   #endif
96
 
96
 
97
-  #if ENABLED(EMERGENCY_PARSER)
98
-    extern bool killed_by_M112;
99
-  #endif
100
-
101
   class MarlinSerial { //: public Stream
97
   class MarlinSerial { //: public Stream
102
 
98
 
103
     public:
99
     public:

+ 3
- 90
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.cpp Ver fichero

107
   #define sw_barrier() asm volatile("": : :"memory");
107
   #define sw_barrier() asm volatile("": : :"memory");
108
 
108
 
109
   #if ENABLED(EMERGENCY_PARSER)
109
   #if ENABLED(EMERGENCY_PARSER)
110
-
111
-    bool killed_by_M112; // = false
112
-
113
-    // Currently looking for: M108, M112, M410
114
-    // If you alter the parser please don't forget to update the capabilities in Conditionals_post.h
115
-
116
-    FORCE_INLINE void emergency_parser(const uint8_t c) {
117
-
118
-      static e_parser_state state = state_RESET;
119
-
120
-      switch (state) {
121
-        case state_RESET:
122
-          switch (c) {
123
-            case ' ': break;
124
-            case 'N': state = state_N;      break;
125
-            case 'M': state = state_M;      break;
126
-            default: state = state_IGNORE;
127
-          }
128
-          break;
129
-
130
-        case state_N:
131
-          switch (c) {
132
-            case '0': case '1': case '2':
133
-            case '3': case '4': case '5':
134
-            case '6': case '7': case '8':
135
-            case '9': case '-': case ' ':   break;
136
-            case 'M': state = state_M;      break;
137
-            default:  state = state_IGNORE;
138
-          }
139
-          break;
140
-
141
-        case state_M:
142
-          switch (c) {
143
-            case ' ': break;
144
-            case '1': state = state_M1;     break;
145
-            case '4': state = state_M4;     break;
146
-            default: state = state_IGNORE;
147
-          }
148
-          break;
149
-
150
-        case state_M1:
151
-          switch (c) {
152
-            case '0': state = state_M10;    break;
153
-            case '1': state = state_M11;    break;
154
-            default: state = state_IGNORE;
155
-          }
156
-          break;
157
-
158
-        case state_M10:
159
-          state = (c == '8') ? state_M108 : state_IGNORE;
160
-          break;
161
-
162
-        case state_M11:
163
-          state = (c == '2') ? state_M112 : state_IGNORE;
164
-          break;
165
-
166
-        case state_M4:
167
-          state = (c == '1') ? state_M41 : state_IGNORE;
168
-          break;
169
-
170
-        case state_M41:
171
-          state = (c == '0') ? state_M410 : state_IGNORE;
172
-          break;
173
-
174
-        case state_IGNORE:
175
-          if (c == '\n') state = state_RESET;
176
-          break;
177
-
178
-        default:
179
-          if (c == '\n') {
180
-            switch (state) {
181
-              case state_M108:
182
-                wait_for_user = wait_for_heatup = false;
183
-                break;
184
-              case state_M112:
185
-                killed_by_M112 = true;
186
-                break;
187
-              case state_M410:
188
-                quickstop_stepper();
189
-                break;
190
-              default:
191
-                break;
192
-            }
193
-            state = state_RESET;
194
-          }
195
-      }
196
-    }
197
-
198
-  #endif // EMERGENCY_PARSER
110
+    #include "../../feature/emergency_parser.h"
111
+  #endif
199
 
112
 
200
   FORCE_INLINE void store_rxd_char() {
113
   FORCE_INLINE void store_rxd_char() {
201
 
114
 
269
     #endif // SERIAL_XON_XOFF
182
     #endif // SERIAL_XON_XOFF
270
 
183
 
271
     #if ENABLED(EMERGENCY_PARSER)
184
     #if ENABLED(EMERGENCY_PARSER)
272
-      emergency_parser(c);
185
+      emergency_parser.update(c);
273
     #endif
186
     #endif
274
   }
187
   }
275
 
188
 

+ 0
- 4
Marlin/src/HAL/HAL_DUE/MarlinSerial_Due.h Ver fichero

74
   extern ring_buffer_pos_t rx_max_enqueued;
74
   extern ring_buffer_pos_t rx_max_enqueued;
75
 #endif
75
 #endif
76
 
76
 
77
-#if ENABLED(EMERGENCY_PARSER)
78
-  extern bool killed_by_M112;
79
-#endif
80
-
81
 class MarlinSerial {
77
 class MarlinSerial {
82
 
78
 
83
 public:
79
 public:

+ 9
- 1
Marlin/src/HAL/HAL_LPC1768/HardwareSerial.cpp Ver fichero

22
 
22
 
23
 #ifdef TARGET_LPC1768
23
 #ifdef TARGET_LPC1768
24
 
24
 
25
-#include "../../inc/MarlinConfig.h"
26
 #include "HardwareSerial.h"
25
 #include "HardwareSerial.h"
27
 
26
 
27
+#include "../../inc/MarlinConfigPre.h"
28
+
29
+#if ENABLED(EMERGENCY_PARSER)
30
+  #include "../../feature/emergency_parser.h"
31
+#endif
32
+
28
 #if SERIAL_PORT == 0 || SERIAL_PORT_2 == 0
33
 #if SERIAL_PORT == 0 || SERIAL_PORT_2 == 0
29
   HardwareSerial Serial = HardwareSerial(LPC_UART0);
34
   HardwareSerial Serial = HardwareSerial(LPC_UART0);
30
 #elif SERIAL_PORT == 1 || SERIAL_PORT_2 == 1
35
 #elif SERIAL_PORT == 1 || SERIAL_PORT_2 == 1
248
   if (IIRValue == UART_IIR_INTID_RDA) {
253
   if (IIRValue == UART_IIR_INTID_RDA) {
249
     // Clear the FIFO
254
     // Clear the FIFO
250
     while (UART_Receive(UARTx, &byte, 1, NONE_BLOCKING)) {
255
     while (UART_Receive(UARTx, &byte, 1, NONE_BLOCKING)) {
256
+      #if ENABLED(EMERGENCY_PARSER)
257
+        emergency_parser.update(byte);
258
+      #endif
251
       if ((RxQueueWritePos + 1) % RX_BUFFER_SIZE != RxQueueReadPos) {
259
       if ((RxQueueWritePos + 1) % RX_BUFFER_SIZE != RxQueueReadPos) {
252
         RxBuffer[RxQueueWritePos] = byte;
260
         RxBuffer[RxQueueWritePos] = byte;
253
         RxQueueWritePos = (RxQueueWritePos + 1) % RX_BUFFER_SIZE;
261
         RxQueueWritePos = (RxQueueWritePos + 1) % RX_BUFFER_SIZE;

+ 2
- 2
Marlin/src/HAL/HAL_LPC1768/HardwareSerial.h Ver fichero

32
   #include "lpc17xx_pinsel.h"
32
   #include "lpc17xx_pinsel.h"
33
 }
33
 }
34
 
34
 
35
+#include "../../inc/MarlinConfigPre.h"
36
+
35
 class HardwareSerial : public Stream {
37
 class HardwareSerial : public Stream {
36
 private:
38
 private:
37
   LPC_UART_TypeDef *UARTx;
39
   LPC_UART_TypeDef *UARTx;
138
     printf("%f" , value );
140
     printf("%f" , value );
139
   }
141
   }
140
 
142
 
141
-
142
-
143
   void println(const char value[]) {
143
   void println(const char value[]) {
144
     printf("%s\n" , value);
144
     printf("%s\n" , value);
145
   }
145
   }

+ 0
- 4
Marlin/src/HAL/HAL_LPC1768/SanityCheck.h Ver fichero

74
     ||  MB(RAMPS_14_RE_ARM_SF))
74
     ||  MB(RAMPS_14_RE_ARM_SF))
75
   #error "Re-ARM with REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and TMC2130 require TMC_USE_SW_SPI"
75
   #error "Re-ARM with REPRAP_DISCOUNT_FULL_GRAPHIC_SMART_CONTROLLER and TMC2130 require TMC_USE_SW_SPI"
76
 #endif
76
 #endif
77
-
78
-#if ENABLED(EMERGENCY_PARSER)
79
-  #error "EMERGENCY_PARSER is not yet implemented for LPC1768. Disable EMERGENCY_PARSER to continue."
80
-#endif

+ 1
- 0
Marlin/src/HAL/HAL_LPC1768/include/Arduino.h Ver fichero

95
 #define vsnprintf_P vsnprintf
95
 #define vsnprintf_P vsnprintf
96
 #define strcpy_P strcpy
96
 #define strcpy_P strcpy
97
 #define snprintf_P snprintf
97
 #define snprintf_P snprintf
98
+#define strlen_P strlen
98
 
99
 
99
 // Time functions
100
 // Time functions
100
 extern "C" {
101
 extern "C" {

+ 0
- 4
Marlin/src/HAL/HAL_LPC1768/include/serial.h Ver fichero

26
 #include <stdarg.h>
26
 #include <stdarg.h>
27
 #include <stdio.h>
27
 #include <stdio.h>
28
 
28
 
29
-extern "C" {
30
-#include <debug_frmwrk.h>
31
-}
32
-
33
 /**
29
 /**
34
  * Generic RingBuffer
30
  * Generic RingBuffer
35
  * T type of the buffer array
31
  * T type of the buffer array

+ 3
- 0
Marlin/src/HAL/HAL_LPC1768/watchdog.cpp Ver fichero

50
   #endif
50
   #endif
51
 }
51
 }
52
 
52
 
53
+#else
54
+  void HAL_clear_reset_source(void) {}
55
+  uint8_t HAL_get_reset_source(void) { return RST_POWER_ON; }
53
 #endif // USE_WATCHDOG
56
 #endif // USE_WATCHDOG
54
 
57
 
55
 #endif // TARGET_LPC1768
58
 #endif // TARGET_LPC1768

+ 0
- 17
Marlin/src/core/serial.h Ver fichero

44
   DEBUG_ALL           = 0xFF
44
   DEBUG_ALL           = 0xFF
45
 };
45
 };
46
 
46
 
47
-#if ENABLED(EMERGENCY_PARSER)
48
-  enum e_parser_state : char {
49
-    state_RESET,
50
-    state_N,
51
-    state_M,
52
-    state_M1,
53
-    state_M10,
54
-    state_M108,
55
-    state_M11,
56
-    state_M112,
57
-    state_M4,
58
-    state_M41,
59
-    state_M410,
60
-    state_IGNORE // to '\n'
61
-  };
62
-#endif
63
-
64
 extern uint8_t marlin_debug_flags;
47
 extern uint8_t marlin_debug_flags;
65
 #define DEBUGGING(F) (marlin_debug_flags & (DEBUG_## F))
48
 #define DEBUGGING(F) (marlin_debug_flags & (DEBUG_## F))
66
 
49
 

+ 121
- 0
Marlin/src/feature/emergency_parser.cpp Ver fichero

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * emergency_parser.cpp - Intercept special commands directly in the serial stream
25
+ */
26
+
27
+#include "../inc/MarlinConfigPre.h"
28
+
29
+#if ENABLED(EMERGENCY_PARSER)
30
+
31
+#include "emergency_parser.h"
32
+
33
+extern volatile bool wait_for_user, wait_for_heatup;
34
+void quickstop_stepper();
35
+
36
+EmergencyParser::State EmergencyParser::state = EmergencyParser::State::RESET;
37
+bool EmergencyParser::killed_by_M112; // = false
38
+
39
+EmergencyParser emergency_parser;
40
+
41
+void EmergencyParser::update(const uint8_t c) {
42
+
43
+  switch (state) {
44
+    case EmergencyParser::State::RESET:
45
+      switch (c) {
46
+        case ' ': break;
47
+        case 'N': state = EmergencyParser::State::N;      break;
48
+        case 'M': state = EmergencyParser::State::M;      break;
49
+        default: state  = EmergencyParser::State::IGNORE;
50
+      }
51
+      break;
52
+
53
+    case EmergencyParser::State::N:
54
+      switch (c) {
55
+        case '0': case '1': case '2':
56
+        case '3': case '4': case '5':
57
+        case '6': case '7': case '8':
58
+        case '9': case '-': case ' ':   break;
59
+        case 'M': state = EmergencyParser::State::M;      break;
60
+        default:  state = EmergencyParser::State::IGNORE;
61
+      }
62
+      break;
63
+
64
+    case EmergencyParser::State::M:
65
+      switch (c) {
66
+        case ' ': break;
67
+        case '1': state = EmergencyParser::State::M1;     break;
68
+        case '4': state = EmergencyParser::State::M4;     break;
69
+        default: state  = EmergencyParser::State::IGNORE;
70
+      }
71
+      break;
72
+
73
+    case EmergencyParser::State::M1:
74
+      switch (c) {
75
+        case '0': state = EmergencyParser::State::M10;    break;
76
+        case '1': state = EmergencyParser::State::M11;    break;
77
+        default: state  = EmergencyParser::State::IGNORE;
78
+      }
79
+      break;
80
+
81
+    case EmergencyParser::State::M10:
82
+      state = (c == '8') ? EmergencyParser::State::M108 : EmergencyParser::State::IGNORE;
83
+      break;
84
+
85
+    case EmergencyParser::State::M11:
86
+      state = (c == '2') ? EmergencyParser::State::M112 : EmergencyParser::State::IGNORE;
87
+      break;
88
+
89
+    case EmergencyParser::State::M4:
90
+      state = (c == '1') ? EmergencyParser::State::M41 : EmergencyParser::State::IGNORE;
91
+      break;
92
+
93
+    case EmergencyParser::State::M41:
94
+      state = (c == '0') ? EmergencyParser::State::M410 : EmergencyParser::State::IGNORE;
95
+      break;
96
+
97
+    case EmergencyParser::State::IGNORE:
98
+      if (c == '\n') state = EmergencyParser::State::RESET;
99
+      break;
100
+
101
+    default:
102
+      if (c == '\n') {
103
+        switch (state) {
104
+          case EmergencyParser::State::M108:
105
+            wait_for_user = wait_for_heatup = false;
106
+            break;
107
+          case EmergencyParser::State::M112:
108
+            killed_by_M112 = true;
109
+            break;
110
+          case EmergencyParser::State::M410:
111
+            quickstop_stepper();
112
+            break;
113
+          default:
114
+            break;
115
+        }
116
+        state = EmergencyParser::State::RESET;
117
+      }
118
+  }
119
+}
120
+
121
+#endif // EMERGENCY_PARSER

+ 61
- 0
Marlin/src/feature/emergency_parser.h Ver fichero

1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+/**
24
+ * emergency_parser.h - Intercept special commands directly in the serial stream
25
+ */
26
+
27
+#ifndef _EMERGENCY_PARSER_H_
28
+#define _EMERGENCY_PARSER_H_
29
+
30
+class EmergencyParser {
31
+
32
+  // Currently looking for: M108, M112, M410
33
+  enum State : char {
34
+    RESET,
35
+    N,
36
+    M,
37
+    M1,
38
+    M10,
39
+    M108,
40
+    M11,
41
+    M112,
42
+    M4,
43
+    M41,
44
+    M410,
45
+    IGNORE // to '\n'
46
+  };
47
+
48
+public:
49
+
50
+  static EmergencyParser::State state;
51
+  static bool killed_by_M112;
52
+
53
+  EmergencyParser() {}
54
+
55
+  static void update(const uint8_t c);
56
+
57
+};
58
+
59
+extern EmergencyParser emergency_parser;
60
+
61
+#endif // _EMERGENCY_PARSER_H_

+ 5
- 1
Marlin/src/module/temperature.cpp Ver fichero

49
   #include "../feature/filwidth.h"
49
   #include "../feature/filwidth.h"
50
 #endif
50
 #endif
51
 
51
 
52
+#if ENABLED(EMERGENCY_PARSER)
53
+  #include "../feature/emergency_parser.h"
54
+#endif
55
+
52
 #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
56
 #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
53
   static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
57
   static void* heater_ttbl_map[2] = { (void*)HEATER_0_TEMPTABLE, (void*)HEATER_1_TEMPTABLE };
54
   static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
58
   static uint8_t heater_ttbllen_map[2] = { HEATER_0_TEMPTABLE_LEN, HEATER_1_TEMPTABLE_LEN };
792
   #endif
796
   #endif
793
 
797
 
794
   #if ENABLED(EMERGENCY_PARSER)
798
   #if ENABLED(EMERGENCY_PARSER)
795
-    if (killed_by_M112) kill(PSTR(MSG_KILLED));
799
+    if (emergency_parser.killed_by_M112) kill(PSTR(MSG_KILLED));
796
   #endif
800
   #endif
797
 
801
 
798
   if (!temp_meas_ready) return;
802
   if (!temp_meas_ready) return;

+ 8
- 0
frameworks/CMSIS/LPC1768/lib/usb/cdcuser.cpp Ver fichero

39
 unsigned short CDC_LineState = 0;
39
 unsigned short CDC_LineState = 0;
40
 unsigned short CDC_SerialState = 0;
40
 unsigned short CDC_SerialState = 0;
41
 
41
 
42
+#include "../../../../../Marlin/src/inc/MarlinConfigPre.h"
43
+
44
+#if ENABLED(EMERGENCY_PARSER)
45
+  #include "../../../../../Marlin/src/feature/emergency_parser.h"
46
+#endif
42
 
47
 
43
 extern HalSerial usb_serial;
48
 extern HalSerial usb_serial;
44
 /*----------------------------------------------------------------------------
49
 /*----------------------------------------------------------------------------
52
   bytesWritten = bytesToWrite;
57
   bytesWritten = bytesToWrite;
53
 
58
 
54
   while (bytesToWrite) {
59
   while (bytesToWrite) {
60
+    #if ENABLED(EMERGENCY_PARSER)
61
+      emergency_parser.update(*buffer);
62
+    #endif
55
     usb_serial.receive_buffer.write(*buffer++);           // Copy Data to buffer
63
     usb_serial.receive_buffer.write(*buffer++);           // Copy Data to buffer
56
     bytesToWrite--;
64
     bytesToWrite--;
57
   }
65
   }

Loading…
Cancelar
Guardar