1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-01 18:32:37 +02:00

Assert improvements

This commit is contained in:
Mitch Bradley
2021-06-28 21:45:49 -10:00
parent cf13e6f9f8
commit 4f09112ad4
3 changed files with 53 additions and 38 deletions

View File

@@ -64,45 +64,47 @@ void grbl_init() {
// Load Grbl settings from non-volatile storage // Load Grbl settings from non-volatile storage
debug_serial("Initializing settings..."); debug_serial("Initializing settings...");
settings_init(); // requires config settings_init(); // requires config
config->load(config_filename->get()); bool configOkay = config->load(config_filename->get());
make_grbl_commands(); make_grbl_commands();
// Setup input polling loop after loading the configuration, // Setup input polling loop after loading the configuration,
// because the polling may depend on the config // because the polling may depend on the config
client_init(); client_init();
report_machine_type(CLIENT_SERIAL); if (configOkay) {
info_serial("Board: %s", config->_board.c_str()); report_machine_type(CLIENT_SERIAL);
info_serial("Board: %s", config->_board.c_str());
if (config->_i2so) { if (config->_i2so) {
info_serial("Initializing I2SO..."); info_serial("Initializing I2SO...");
// The I2S out must be initialized before it can access the expanded GPIO port. Must be initialized _after_ settings! // The I2S out must be initialized before it can access the expanded GPIO port. Must be initialized _after_ settings!
i2s_out_init(); i2s_out_init();
}
if (config->_spi) {
info_serial("Initializing SPI...");
// The SPI must be initialized before we can use it.
config->_spi->init();
// Initialize SD card after SPI:
if (config->_sdCard != nullptr) {
config->_sdCard->init();
} }
if (config->_spi) {
info_serial("Initializing SPI...");
// The SPI must be initialized before we can use it.
config->_spi->init();
// Initialize SD card after SPI:
if (config->_sdCard != nullptr) {
config->_sdCard->init();
}
}
info_serial("Initializing steppers...");
stepper_init(); // Configure stepper pins and interrupt timers
info_serial("Initializing axes...");
config->_axes->read_settings();
config->_axes->init();
config->_control->init();
init_output_pins(); // Configure pinout pins and pin-change interrupt (Renamed due to conflict with esp32 files)
memset(sys_position, 0, sizeof(sys_position)); // Clear machine position.
machine_init(); // user supplied function for special initialization
} }
info_serial("Initializing steppers...");
stepper_init(); // Configure stepper pins and interrupt timers
info_serial("Initializing axes...");
config->_axes->read_settings();
config->_axes->init();
config->_control->init();
init_output_pins(); // Configure pinout pins and pin-change interrupt (Renamed due to conflict with esp32 files)
memset(sys_position, 0, sizeof(sys_position)); // Clear machine position.
machine_init(); // user supplied function for special initialization
// Initialize system state. // Initialize system state.
if (sys.state != State::ConfigAlarm) { if (sys.state != State::ConfigAlarm) {
if (FORCE_INITIALIZATION_ALARM) { if (FORCE_INITIALIZATION_ALARM) {
@@ -166,6 +168,7 @@ static void reset_variables() {
} }
void run_once() { void run_once() {
static int tries = 0;
try { try {
reset_variables(); reset_variables();
// Start Grbl main loop. Processes program inputs and executes them. // Start Grbl main loop. Processes program inputs and executes them.
@@ -188,6 +191,9 @@ void run_once() {
error_all("Critical error in run_once: %s", ex.msg.c_str()); error_all("Critical error in run_once: %s", ex.msg.c_str());
sys.state = State::ConfigAlarm; sys.state = State::ConfigAlarm;
} }
if (++tries > 1) {
while (1) {}
}
// This is inside a loop in Grbl_Esp32.ino // This is inside a loop in Grbl_Esp32.ino
} }

View File

@@ -1,5 +1,7 @@
#pragma once #pragma once
#include "../Machine/MachineConfig.h" // config->_stepType
#include "../Stepper.h" // ST_I2S_*
#include "Motor.h" #include "Motor.h"
#include <driver/rmt.h> #include <driver/rmt.h>
@@ -33,8 +35,11 @@ namespace Motors {
// Configuration handlers: // Configuration handlers:
void validate() const override { void validate() const override {
Assert(!_step_pin.undefined(), "Step pin should be configured."); Assert(_step_pin.defined(), "Step pin should be configured.");
Assert(!_dir_pin.undefined(), "Direction pin should be configured."); Assert(_dir_pin.defined(), "Direction pin should be configured.");
bool isI2SO = config->_stepType == ST_I2S_STREAM || config->_stepType == ST_I2S_STATIC;
Assert(!isI2SO || _step_pin.name().startsWith("I2SO"), "Step pin must be an I2SO pin");
Assert(!isI2SO || _dir_pin.name().startsWith("I2SO"), "Direction pin must be an I2SO pin");
} }
void group(Configuration::HandlerBase& handler) override { void group(Configuration::HandlerBase& handler) override {

View File

@@ -21,6 +21,7 @@
#include "GPIOPinDetail.h" #include "GPIOPinDetail.h"
#include "../Assert.h" #include "../Assert.h"
#include "../Logging.h"
extern "C" void __pinMode(uint8_t pin, uint8_t mode); extern "C" void __pinMode(uint8_t pin, uint8_t mode);
extern "C" int __digitalRead(uint8_t pin); extern "C" int __digitalRead(uint8_t pin);
@@ -133,7 +134,10 @@ namespace Pins {
PinCapabilities GPIOPinDetail::capabilities() const { return _capabilities; } PinCapabilities GPIOPinDetail::capabilities() const { return _capabilities; }
void GPIOPinDetail::write(int high) { void GPIOPinDetail::write(int high) {
Assert(_attributes.has(PinAttributes::Output), "Pin has no output attribute defined. Cannot write to it."); if (!_attributes.has(PinAttributes::Output)) {
log_error(toString());
}
Assert(_attributes.has(PinAttributes::Output), "Pin %s cannot be written", toString());
int value = _readWriteMask ^ high; int value = _readWriteMask ^ high;
__digitalWrite(_index, value); __digitalWrite(_index, value);
} }
@@ -149,9 +153,11 @@ namespace Pins {
// Check the attributes first: // Check the attributes first:
Assert(value.validateWith(this->_capabilities) || _index == 1 || _index == 3, Assert(value.validateWith(this->_capabilities) || _index == 1 || _index == 3,
"The requested attributes don't match the pin capabilities"); "The requested attributes don't match the capabilities for %s",
toString());
Assert(!_attributes.conflictsWith(value) || _index == 1 || _index == 3, Assert(!_attributes.conflictsWith(value) || _index == 1 || _index == 3,
"Attributes on this pin have been set before, and there's a conflict."); "The requested attributes on %s conflict with previous settings",
toString());
_attributes = _attributes | value; _attributes = _attributes | value;
@@ -180,14 +186,12 @@ namespace Pins {
} }
void GPIOPinDetail::attachInterrupt(void (*callback)(void*), void* arg, int mode) { void GPIOPinDetail::attachInterrupt(void (*callback)(void*), void* arg, int mode) {
Assert(_attributes.has(PinAttributes::ISR), Assert(_attributes.has(PinAttributes::ISR), "Pin %s does not support interrupts", toString());
"Pin has no ISR attribute, which means 'setAttr' was not set, or the pin doesn't support ISR's. Cannot bind ISR.");
::attachInterruptArg(_index, callback, arg, mode); ::attachInterruptArg(_index, callback, arg, mode);
} }
void GPIOPinDetail::detachInterrupt() { void GPIOPinDetail::detachInterrupt() {
Assert(_attributes.has(PinAttributes::ISR), Assert(_attributes.has(PinAttributes::ISR), "Pin %s does not support interrupts");
"Pin has no ISR attribute, which means 'setAttr' was not set, or the pin doesn't support ISR's. Cannot unbind ISR.");
::detachInterrupt(_index); ::detachInterrupt(_index);
} }