Skip to content

Commit f2996d3

Browse files
committed
Create 2019-09-24
1 parent daa46b6 commit f2996d3

18 files changed

Lines changed: 703 additions & 4097 deletions
-341 KB
Binary file not shown.
-229 KB
Binary file not shown.
356 KB
Binary file not shown.
238 KB
Binary file not shown.

hex/uArmPro_V4.4.0_release_20190327.hex

Lines changed: 0 additions & 3868 deletions
This file was deleted.

src/gcode.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,14 @@ uint8_t gc_execute_line(char *line)
337337

338338
if ( bit_istrue(command_words,bit(word_bit)) ) { FAIL(STATUS_GCODE_MODAL_GROUP_VIOLATION); }
339339
command_words |= bit(word_bit);
340-
break;
340+
break;
341+
case 'S':
342+
if (mantissa > 0) { FAIL(STATUS_GCODE_COMMAND_VALUE_NOT_INTEGER); } // [No Mxx.x commands]
343+
rtn = uarm_execute_s_cmd( int_value, line+char_counter, &char_counter );
344+
if( (rtn != UARM_CMD_NOTFIND) && (rtn != UARM_SYS_ABORT) ){ return rtn; }
345+
346+
if ( bit_istrue(command_words,bit(word_bit)) ) { FAIL(STATUS_GCODE_MODAL_GROUP_VIOLATION); }
347+
command_words |= bit(word_bit);
341348
// NOTE: All remaining letters assign values.
342349
default:
343350

src/protocol.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void protocol_execute_realtime()
194194
{
195195
uint8_t rt_exec; // Temp variable to avoid calling volatile multiple times.
196196

197-
do { // If system is suspended, suspend loop restarts here.
197+
// do { // If system is suspended, suspend loop restarts here.
198198

199199
// Check and execute alarms.
200200
rt_exec = sys_rt_exec_alarm; // Copy volatile sys_rt_exec_alarm.
@@ -376,7 +376,7 @@ void protocol_execute_realtime()
376376
}
377377
}
378378

379-
} while(sys.suspend); // Check for system suspend state before exiting.
379+
// } while(sys.suspend); // Check for system suspend state before exiting.
380380

381381
}
382382

@@ -405,4 +405,7 @@ void protocol_buffer_synchronize()
405405
// when one of these conditions exist respectively: There are no more blocks sent (i.e. streaming
406406
// is finished, single commands), a command that needs to wait for the motions in the buffer to
407407
// execute calls a buffer sync, or the planner buffer is full and ready to go.
408-
void protocol_auto_cycle_start() { bit_true_atomic(sys_rt_exec_state, EXEC_CYCLE_START); }
408+
void protocol_auto_cycle_start() {
409+
if( sys.suspend ){ return; }
410+
bit_true_atomic(sys_rt_exec_state, EXEC_CYCLE_START);
411+
}

src/serial.c

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ enum serial_mode_e{
3434
UART0 = 0,
3535
UART1,
3636
UART2,
37+
UART3,
3738
} current_uart = UART0;
3839

3940

@@ -119,7 +120,24 @@ void serial_init()
119120
// enable interrupt on complete reception of a byte
120121
UCSR2B |= 1<<RXCIE2;
121122

122-
123+
/******************** uart3 ********************/
124+
// Set baud rate
125+
#if BAUD_RATE < 57600
126+
uint16_t UBRR3_value = ((F_CPU / (8L * BAUD_RATE)) - 1)/2 ;
127+
UCSR3A &= ~(1 << U2X3); // baud doubler off - Only needed on Uno XXX
128+
#else
129+
uint16_t UBRR3_value = ((F_CPU / (4L * BAUD_RATE)) - 1)/2;
130+
UCSR3A |= (1 << U2X3); // baud doubler on for high baud rates, i.e. 115200
131+
#endif
132+
UBRR3H = UBRR3_value >> 8;
133+
UBRR3L = UBRR3_value;
134+
135+
// enable rx and tx
136+
UCSR3B |= 1<<RXEN3;
137+
UCSR3B |= 1<<TXEN3;
138+
139+
// enable interrupt on complete reception of a byte
140+
UCSR3B |= 1<<RXCIE3;
123141
// defaults to 8-bit, no parity, 1 stop bit
124142
}
125143

@@ -152,6 +170,9 @@ void serial_write(uint8_t data) {
152170
case UART2:
153171
UCSR2B |= (1 << UDRIE2);
154172
break;
173+
case UART3:
174+
UCSR3B |= (1 << UDRIE3);
175+
break;
155176
}
156177

157178
}
@@ -243,6 +264,34 @@ ISR(USART2_UDRE_vect)
243264
if (tail == serial_tx_buffer_head) { UCSR2B &= ~(1 << UDRIE2); }
244265
}
245266

267+
ISR(USART3_UDRE_vect)
268+
{
269+
uint8_t tail = serial_tx_buffer_tail; // Temporary serial_tx_buffer_tail (to optimize for volatile)
270+
271+
#ifdef ENABLE_XONXOFF
272+
if (flow_ctrl == SEND_XOFF) {
273+
UDR3 = XOFF_CHAR;
274+
flow_ctrl = XOFF_SENT;
275+
} else if (flow_ctrl == SEND_XON) {
276+
UDR3 = XON_CHAR;
277+
flow_ctrl = XON_SENT;
278+
} else
279+
#endif
280+
{
281+
// Send a byte from the buffer
282+
UDR3 = serial_tx_buffer[tail];
283+
284+
// Update tail position
285+
tail++;
286+
if (tail == TX_BUFFER_SIZE) { tail = 0; }
287+
288+
serial_tx_buffer_tail = tail;
289+
}
290+
291+
// Turn off Data Register Empty Interrupt to stop tx-streaming if this concludes the transfer
292+
if (tail == serial_tx_buffer_head) { UCSR3B &= ~(1 << UDRIE3); }
293+
}
294+
246295

247296
// Fetches the first byte in the serial read buffer. Called by main program.
248297
uint8_t serial_read()
@@ -267,6 +316,8 @@ uint8_t serial_read()
267316
break;
268317
case UART2: UCSR2B |= (1 << UDRIE2); // Force TX
269318
break;
319+
case UART3: UCSR3B |= (1 << UDRIE3); // Force TX
320+
break;
270321
}
271322
}
272323
#endif
@@ -381,6 +432,42 @@ ISR(USART2_RX_vect)
381432
}
382433
}
383434

435+
ISR(USART3_RX_vect)
436+
{
437+
uint8_t data = UDR3;
438+
uint8_t next_head;
439+
current_uart = UART3;
440+
441+
// Pick off realtime command characters directly from the serial stream. These characters are
442+
// not passed into the buffer, but these set system state flag bits for realtime execution.
443+
switch (data) {
444+
case CMD_STATUS_REPORT: bit_true_atomic(sys_rt_exec_state, EXEC_STATUS_REPORT); break; // Set as true
445+
case CMD_CYCLE_START: bit_true_atomic(sys_rt_exec_state, EXEC_CYCLE_START); break; // Set as true
446+
case CMD_FEED_HOLD: bit_true_atomic(sys_rt_exec_state, EXEC_FEED_HOLD); break; // Set as true
447+
case CMD_SAFETY_DOOR: bit_true_atomic(sys_rt_exec_state, EXEC_SAFETY_DOOR); break; // Set as true
448+
case CMD_RESET: mc_reset(); break; // Call motion control reset routine.
449+
default: // Write character to buffer
450+
next_head = serial_rx_buffer_head + 1;
451+
if (next_head == RX_BUFFER_SIZE) { next_head = 0; }
452+
453+
// Write data to buffer unless it is full.
454+
if (next_head != serial_rx_buffer_tail) {
455+
serial_rx_buffer[serial_rx_buffer_head] = data;
456+
serial_rx_buffer_head = next_head;
457+
458+
#ifdef ENABLE_XONXOFF
459+
if ((serial_get_rx_buffer_count() >= RX_BUFFER_FULL) && flow_ctrl == XON_SENT) {
460+
flow_ctrl = SEND_XOFF;
461+
UCSR3B |= (1 << UDRIE3); // Force TX
462+
}
463+
#endif
464+
465+
}
466+
//TODO: else alarm on overflow?
467+
}
468+
}
469+
470+
384471

385472
void serial_reset_read_buffer()
386473
{

0 commit comments

Comments
 (0)