mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
add marker pins (GPIO12, GPIO14) for logic analyser
° use faster macros for LA markers
This commit is contained in:
@@ -2195,16 +2195,11 @@ void MyESP::begin(const char * app_hostname, const char * app_name, const char *
|
||||
}
|
||||
|
||||
_eeprom_setup(); // set up EEPROM for storing crash data, if compiled with -DCRASH
|
||||
|
||||
_fs_setup(); // SPIFFS setup, do this first to get values
|
||||
_wifi_setup(); // WIFI setup
|
||||
_ota_setup(); // init OTA
|
||||
_webserver_setup(); // init web server
|
||||
|
||||
// print a welcome message
|
||||
myDebug_P(PSTR("\n* %s version %s"), _app_name, _app_version);
|
||||
SerialAndTelnet.flush();
|
||||
|
||||
_setSystemCheck(false); // reset system check
|
||||
_heartbeatCheck(true); // force heartbeat
|
||||
}
|
||||
|
||||
@@ -1799,6 +1799,10 @@ void showerCheck() {
|
||||
// SETUP
|
||||
//
|
||||
void setup() {
|
||||
// LA trigger create a small puls to show setup is starting...
|
||||
INIT_MARKERS(0);
|
||||
LA_PULSE(50);
|
||||
|
||||
// init our own parameters
|
||||
initEMSESP();
|
||||
|
||||
|
||||
45
src/ems.h
45
src/ems.h
@@ -12,6 +12,47 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
/* debug helper for logic analyzer
|
||||
* create marker puls on GPIOx
|
||||
* ° for Rx, we use GPIO14
|
||||
* ° for Tx, we use GPIO12
|
||||
*/
|
||||
#define LOGICANALYZER
|
||||
#ifdef LOGICANALYZER
|
||||
#define RX_MARK_PIN 14
|
||||
#define TX_MARK_PIN 12
|
||||
|
||||
#define RX_MARK_MASK (1<<RX_MARK_PIN)
|
||||
#define TX_MARK_MASK (1<<TX_MARK_PIN)
|
||||
#define MARKERS_MASK (RX_MARK_PIN|TX_MARK_PIN)
|
||||
|
||||
#define GPIO_H(mask) (GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, (mask)))
|
||||
#define GPIO_L(mask) (GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, (mask)))
|
||||
|
||||
#define RX_PULSE(pulse) do { GPIO_H(RX_MARK_MASK); \
|
||||
delayMicroseconds(pulse); \
|
||||
GPIO_L(RX_MARK_MASK); \
|
||||
} while (0)
|
||||
#define TX_PULSE(pulse) do { GPIO_H(TX_MARK_MASK); \
|
||||
delayMicroseconds(pulse); \
|
||||
GPIO_L(TX_MARK_MASK); \
|
||||
} while (0)
|
||||
#define LA_PULSE(pulse) do { GPIO_H(MARKERS_MASK); \
|
||||
delayMicroseconds(pulse); \
|
||||
GPIO_L(MARKERS_MASK); \
|
||||
} while (0)
|
||||
|
||||
#define INIT_MARKERS(void) do { pinMode(RX_MARK_PIN, OUTPUT);\
|
||||
pinMode(TX_MARK_PIN, OUTPUT);\
|
||||
GPIO_L(MARKERS_MASK); \
|
||||
} while (0)
|
||||
#else
|
||||
#define RX_PULSE(pulse)
|
||||
#define TX_PULSE(pulse)
|
||||
#define LA_PULSE(pulse)
|
||||
#define INIT_MARKERS(void)
|
||||
#endif
|
||||
|
||||
#define EMS_ID_NONE 0x00 // used as a dest in broadcast messages and empty device IDs
|
||||
|
||||
// Fixed EMS IDs
|
||||
@@ -64,7 +105,9 @@ typedef enum {
|
||||
|
||||
typedef enum {
|
||||
EMS_TX_STATUS_IDLE, // ready
|
||||
EMS_TX_STATUS_WAIT // waiting for response from last Tx
|
||||
EMS_TX_STATUS_WAIT, // waiting for response from last Tx
|
||||
EMS_TX_WTD_TIMEOUT, // watchdog timeout during send
|
||||
EMS_TX_BRK_DETECT // incoming BRK during Tx
|
||||
} _EMS_TX_STATUS;
|
||||
|
||||
#define EMS_TX_SUCCESS 0x01 // EMS single byte after a Tx Write indicating a success
|
||||
|
||||
@@ -43,6 +43,7 @@ static void emsuart_rx_intr_handler(void * para) {
|
||||
// BREAK detection = End of EMS data block
|
||||
if (USIS(EMSUART_UART) & ((1 << UIBD))) {
|
||||
ETS_UART_INTR_DISABLE(); // disable all interrupts and clear them
|
||||
RX_PULSE(EMSUART_BIT_TIME/2);
|
||||
|
||||
USIC(EMSUART_UART) = (1 << UIBD); // INT clear the BREAK detect interrupt
|
||||
|
||||
@@ -170,6 +171,7 @@ void ICACHE_FLASH_ATTR emsuart_tx_brk() {
|
||||
while (((USS(EMSUART_UART) >> USTXC) & 0xFF) != 0)
|
||||
;
|
||||
|
||||
TX_PULSE(EMSUART_BIT_TIME/2);
|
||||
tmp = ((1 << UCRXRST) | (1 << UCTXRST)); // bit mask
|
||||
USC0(EMSUART_UART) |= (tmp); // set bits
|
||||
USC0(EMSUART_UART) &= ~(tmp); // clear bits
|
||||
@@ -199,17 +201,20 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
|
||||
|
||||
if (EMS_Sys_Status.emsTxMode == 0) { // classic mode logic
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
TX_PULSE(EMSUART_BIT_TIME/4);
|
||||
USF(EMSUART_UART) = buf[i];
|
||||
}
|
||||
emsuart_tx_brk(); // send <BRK>
|
||||
} else if (EMS_Sys_Status.emsTxMode == 1) { // With extra tx delay for EMS+
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
TX_PULSE(EMSUART_BIT_TIME/4);
|
||||
USF(EMSUART_UART) = buf[i];
|
||||
delayMicroseconds(EMSUART_TX_BRK_WAIT); // https://github.com/proddy/EMS-ESP/issues/23#
|
||||
}
|
||||
emsuart_tx_brk(); // send <BRK>
|
||||
} else if (EMS_Sys_Status.emsTxMode == 3) { // Junkers logic by @philrich
|
||||
for (uint8_t i = 0; i < len; i++) {
|
||||
TX_PULSE(EMSUART_BIT_TIME/4);
|
||||
USF(EMSUART_UART) = buf[i];
|
||||
|
||||
// just to be safe wait for tx fifo empty (needed?)
|
||||
@@ -237,6 +242,7 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
|
||||
|
||||
// throw out the telegram...
|
||||
for (uint8_t i = 0; i < len;) {
|
||||
TX_PULSE(EMSUART_BIT_TIME/4);
|
||||
USF(EMSUART_UART) = buf[i++]; // send each Tx byte
|
||||
// wait for echo from busmaster
|
||||
while ((((USS(EMSUART_UART) >> USRXC) & 0xFF) < i || (USIS(EMSUART_UART) & (1 << UIBD)))) {
|
||||
@@ -249,6 +255,7 @@ void ICACHE_FLASH_ATTR emsuart_tx_buffer(uint8_t * buf, uint8_t len) {
|
||||
// otherwise we send the final Tx-BRK in the loopback and re=enable Rx-INT.
|
||||
// worst case, we'll see an additional Rx-BRK...
|
||||
if (!(USIS(EMSUART_UART) & (1 << UIBD))) {
|
||||
TX_PULSE(EMSUART_BIT_TIME/2);
|
||||
// no bus collision - send terminating BRK signal
|
||||
USC0(EMSUART_UART) |= (1 << UCLBE); // enable loopback
|
||||
USC0(EMSUART_UART) |= (1 << UCBRK); // set <BRK>
|
||||
|
||||
Reference in New Issue
Block a user