mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-01 10:23:19 +02:00
Fixed $system/control=reset problem
It was fairly insidious - the client read loop alway thought that serial data is available, due to a problem with uint8_t vs int. With uint8_t, there was no way to receive a -1 return value from the various low level read routines. I also fixed an ordering problem with config vs client input. It is necessary to do the config first because client input depends on the config.
This commit is contained in:
@@ -30,6 +30,7 @@
|
|||||||
#include "Limits.h"
|
#include "Limits.h"
|
||||||
#include "Protocol.h"
|
#include "Protocol.h"
|
||||||
#include "System.h"
|
#include "System.h"
|
||||||
|
#include "Uart.h"
|
||||||
|
|
||||||
#include "WebUI/WifiConfig.h"
|
#include "WebUI/WifiConfig.h"
|
||||||
#include "WebUI/InputBuffer.h"
|
#include "WebUI/InputBuffer.h"
|
||||||
@@ -42,7 +43,7 @@ extern void make_grbl_commands();
|
|||||||
|
|
||||||
void grbl_init() {
|
void grbl_init() {
|
||||||
try {
|
try {
|
||||||
client_init(); // Setup serial baud rate and interrupts
|
uartInit(); // Setup serial port
|
||||||
|
|
||||||
debug_serial("Initializing WiFi...");
|
debug_serial("Initializing WiFi...");
|
||||||
WiFi.persistent(false);
|
WiFi.persistent(false);
|
||||||
@@ -65,6 +66,10 @@ void grbl_init() {
|
|||||||
config->load(config_filename->get());
|
config->load(config_filename->get());
|
||||||
make_grbl_commands();
|
make_grbl_commands();
|
||||||
|
|
||||||
|
// Setup input polling loop after loading the configuration,
|
||||||
|
// because the polling may depend on the config
|
||||||
|
client_init();
|
||||||
|
|
||||||
report_machine_type(CLIENT_SERIAL);
|
report_machine_type(CLIENT_SERIAL);
|
||||||
info_serial("Board: %s", config->_board.c_str());
|
info_serial("Board: %s", config->_board.c_str());
|
||||||
|
|
||||||
|
@@ -106,11 +106,7 @@ void client_init() {
|
|||||||
xTaskCreatePinnedToCore(heapCheckTask, "heapTask", 2000, NULL, 1, NULL, 1);
|
xTaskCreatePinnedToCore(heapCheckTask, "heapTask", 2000, NULL, 1, NULL, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Uart0.setPins(GPIO_NUM_1, GPIO_NUM_3); // Tx 1, Rx 3 - standard hardware pins
|
|
||||||
Uart0.begin(BAUD_RATE, Uart::Data::Bits8, Uart::Stop::Bits1, Uart::Parity::None);
|
|
||||||
|
|
||||||
client_reset_read_buffer(CLIENT_ALL);
|
client_reset_read_buffer(CLIENT_ALL);
|
||||||
Uart0.write("\r\n"); // create some white space after ESP32 boot info
|
|
||||||
clientCheckTaskHandle = 0;
|
clientCheckTaskHandle = 0;
|
||||||
|
|
||||||
// create a task to check for incoming data
|
// create a task to check for incoming data
|
||||||
@@ -126,7 +122,7 @@ void client_init() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint8_t getClientChar(uint8_t& data) {
|
static ClientType getClientChar(int& data) {
|
||||||
if (client_buffer[CLIENT_SERIAL].availableforwrite() && (data = Uart0.read()) != -1) {
|
if (client_buffer[CLIENT_SERIAL].availableforwrite() && (data = Uart0.read()) != -1) {
|
||||||
return CLIENT_SERIAL;
|
return CLIENT_SERIAL;
|
||||||
}
|
}
|
||||||
@@ -150,22 +146,23 @@ static uint8_t getClientChar(uint8_t& data) {
|
|||||||
// this task runs and checks for data on all interfaces
|
// this task runs and checks for data on all interfaces
|
||||||
// Realtime stuff is acted upon, then characters are added to the appropriate buffer
|
// Realtime stuff is acted upon, then characters are added to the appropriate buffer
|
||||||
void clientCheckTask(void* pvParameters) {
|
void clientCheckTask(void* pvParameters) {
|
||||||
uint8_t data = 0;
|
int data = 0; // Must be int so -1 value is possible
|
||||||
uint8_t client; // who sent the data
|
ClientType client; // who sent the data
|
||||||
while (true) { // run continuously
|
while (true) { // run continuously
|
||||||
std::atomic_thread_fence(std::memory_order::memory_order_seq_cst); // read fence for settings
|
std::atomic_thread_fence(std::memory_order::memory_order_seq_cst); // read fence for settings
|
||||||
while ((client = getClientChar(data)) != CLIENT_ALL) {
|
while ((client = getClientChar(data)) != CLIENT_ALL) {
|
||||||
|
uint8_t clientByte = uint8_t(data);
|
||||||
// Pick off realtime command characters directly from the serial stream. These characters are
|
// Pick off realtime command characters directly from the serial stream. These characters are
|
||||||
// not passed into the main buffer, but these set system state flag bits for realtime execution.
|
// not passed into the main buffer, but these set system state flag bits for realtime execution.
|
||||||
if (is_realtime_command(data)) {
|
if (is_realtime_command(clientByte)) {
|
||||||
execute_realtime_command(static_cast<Cmd>(data), client);
|
execute_realtime_command(static_cast<Cmd>(clientByte), client);
|
||||||
} else {
|
} else {
|
||||||
if (config->_sdCard->get_state(false) < SDCard::State::Busy) {
|
if (config->_sdCard->get_state(false) < SDCard::State::Busy) {
|
||||||
vTaskEnterCritical(&myMutex);
|
vTaskEnterCritical(&myMutex);
|
||||||
client_buffer[client].write(data);
|
client_buffer[client].write(clientByte);
|
||||||
vTaskExitCritical(&myMutex);
|
vTaskExitCritical(&myMutex);
|
||||||
} else {
|
} else {
|
||||||
if (data == '\r' || data == '\n') {
|
if (clientByte == '\r' || clientByte == '\n') {
|
||||||
grbl_sendf(client, "error %d\r\n", Error::AnotherInterfaceBusy);
|
grbl_sendf(client, "error %d\r\n", Error::AnotherInterfaceBusy);
|
||||||
info_client(client, "SD card job running");
|
info_client(client, "SD card job running");
|
||||||
}
|
}
|
||||||
|
@@ -19,6 +19,7 @@
|
|||||||
* UART driver that accesses the ESP32 hardware FIFOs directly.
|
* UART driver that accesses the ESP32 hardware FIFOs directly.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "Logging.h"
|
||||||
#include "Uart.h"
|
#include "Uart.h"
|
||||||
|
|
||||||
#include <esp_system.h>
|
#include <esp_system.h>
|
||||||
@@ -66,7 +67,7 @@ int Uart::read(TickType_t timeout) {
|
|||||||
}
|
}
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
int res = uart_read_bytes(_uart_num, &c, 1, timeout);
|
int res = uart_read_bytes(_uart_num, &c, 1, timeout);
|
||||||
return res != 1 ? -1 : c;
|
return res == 1 ? c : -1;
|
||||||
}
|
}
|
||||||
int Uart::read() {
|
int Uart::read() {
|
||||||
return read(0);
|
return read(0);
|
||||||
@@ -110,3 +111,9 @@ bool Uart::flushTxTimed(TickType_t ticks) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Uart Uart0(0);
|
Uart Uart0(0);
|
||||||
|
|
||||||
|
void uartInit() {
|
||||||
|
Uart0.setPins(GPIO_NUM_1, GPIO_NUM_3); // Tx 1, Rx 3 - standard hardware pins
|
||||||
|
Uart0.begin(BAUD_RATE, Uart::Data::Bits8, Uart::Stop::Bits1, Uart::Parity::None);
|
||||||
|
Uart0.write("\r\n"); // create some white space after ESP32 boot info
|
||||||
|
}
|
||||||
|
@@ -71,3 +71,5 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern Uart Uart0;
|
extern Uart Uart0;
|
||||||
|
|
||||||
|
extern void uartInit();
|
||||||
|
Reference in New Issue
Block a user