From ad7de09a620c167ac3bed878e2738cc7271c0d9c Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Thu, 25 Jun 2020 13:17:07 +0200 Subject: [PATCH 1/4] fix send_telegram TX_READ for EMS+ --- src/telegram.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/telegram.cpp b/src/telegram.cpp index 7d1a6a05e..b87eb4540 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -300,7 +300,8 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) { } telegram_raw[1] = dest; - uint8_t message_p = 0; // this is the position in the telegram where we want to put our message data + uint8_t message_p = 0; // this is the position in the telegram where we want to put our message data + uint8_t message_p0 = 0; // this is the position of start of message data if (telegram->type_id > 0xFF) { // it's EMS 2.0/+ @@ -319,6 +320,7 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) { telegram_raw[5] = (telegram->type_id >> 8) - 1; // type, 1st byte, high-byte, subtract 0x100 telegram_raw[6] = telegram->type_id & 0xFF; // type, 2nd byte, low-byte message_p = 7; + message_p0 = 1; // data[0] is in raw[4] } } else { // EMS 1.0 @@ -332,7 +334,7 @@ void TxService::send_telegram(const QueuedTxTelegram & tx_telegram) { return; // too big } - for (uint8_t i = 0; i < telegram->message_length; i++) { + for (uint8_t i = message_p0; i < telegram->message_length; i++) { telegram_raw[message_p++] = telegram->message_data[i]; } From 55da8a77d2d1c3b8fa282f1a91ee15497ddf3b89 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sat, 27 Jun 2020 14:42:30 +0200 Subject: [PATCH 2/4] add wWSetTemp to boiller mqtt, add wwmode to thermostat --- src/devices/boiler.cpp | 12 ++++++--- src/devices/thermostat.cpp | 54 +++++++++++++++++++++++++++++++++++++- src/devices/thermostat.h | 6 +++++ 3 files changed, 67 insertions(+), 5 deletions(-) diff --git a/src/devices/boiler.cpp b/src/devices/boiler.cpp index 4fc35f0fe..304593520 100644 --- a/src/devices/boiler.cpp +++ b/src/devices/boiler.cpp @@ -177,6 +177,9 @@ void Boiler::publish_values() { if (Helpers::hasValue(wWSelTemp_)) { doc["wWSelTemp"] = wWSelTemp_; } + if (Helpers::hasValue(wWSetTmp_)) { + doc["wWSetTemp"] = wWSetTmp_; + } if (Helpers::hasValue(wWDisinfectTemp_)) { doc["wWDisinfectionTemp"] = wWDisinfectTemp_; } @@ -696,20 +699,21 @@ void Boiler::set_warmwater_mode(const uint8_t comfort) { uint8_t set; if (comfort == 1) { LOG_INFO(F("Setting boiler warm water to hot")); - set = 1; + set = 0; } else if (comfort == 2) { LOG_INFO(F("Setting boiler warm water to eco")); - set = 0; + set = 0xD8; } else if (comfort == 3) { LOG_INFO(F("Setting boiler warm water to intelligent")); - set = 2; + set = 0xEC; } else { return; // do nothing } - write_command(EMS_TYPE_UBAParameterWW, 9, comfort); + write_command(EMS_TYPE_UBAParameterWW, 9, set); // some boilers do not have this setting, than it's done by thermostat // Test for RC35, but not a good way, we are here in boiler context. // EMSESP::send_write_request(0x37, 0x10, 2, &set, 1, 0); // for RC35, maybe work also on RC300 + } // turn on/off warm water diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index efdfc02e9..721ae7bed 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -58,6 +58,7 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i register_telegram_type(set_typeids[i], F("RC35Set"), false, std::bind(&Thermostat::process_RC35Set, this, _1)); } register_telegram_type(EMS_TYPE_IBASettings, F("IBASettings"), true, std::bind(&Thermostat::process_IBASettings, this, _1)); + register_telegram_type(EMS_TYPE_wwSettings, F("WWSettings"), true, std::bind(&Thermostat::process_RC35wwSettings, this, _1)); // RC20 } else if (flags == EMSdevice::EMS_DEVICE_FLAG_RC20) { @@ -282,6 +283,10 @@ void Thermostat::thermostat_cmd(const char * message) { set_control(ctrl, hc_num); } } + if (nullptr != doc["wwmode"]) { + std::string mode = doc["wwmode"]; + set_ww_mode(mode); + } if (float ct = doc["calinttemp"]) { set_settings_calinttemp((int8_t)(ct * 10)); } @@ -1039,6 +1044,11 @@ void Thermostat::process_IBASettings(std::shared_ptr telegram) { telegram->read_value(ibaClockOffset_, 12); // offset (in sec) to clock, 0xff = -1 s, 0x02 = 2 s } +// Settings WW 0x37 - RC35 +void Thermostat::process_RC35wwSettings(std::shared_ptr telegram) { + telegram->read_value(wwMode_, 2); // 0 off, 1-on, 2-auto +} + // type 0x6F - FR10/FR50/FR100 Junkers void Thermostat::process_JunkersMonitor(std::shared_ptr telegram) { // ignore single byte telegram messages @@ -1263,6 +1273,28 @@ void Thermostat::set_control(const uint8_t ctrl, const uint8_t hc_num) { } } +// Set the WW mode in 0x37, 0-off, 1-on, 2-auto +void Thermostat::set_ww_mode(const uint8_t mode) { + if (mode > 2) { + LOG_WARNING(F("set wWMode: Invalid control mode: %d"), mode); + return; + } + if ((flags() & 0x0F) == EMS_DEVICE_FLAG_RC35 || (flags() & 0x0F) == EMS_DEVICE_FLAG_RC30_1) { + LOG_INFO(F("Setting wWMode to %d"), mode); + write_command(0x37, 2, mode); + } +} +// sets the thermostat ww working mode, where mode is a string +void Thermostat::set_ww_mode(const std::string & mode) { + if (strcasecmp("off",mode.c_str()) == 0) { + set_ww_mode(0); + } if (strcasecmp("on",mode.c_str()) == 0) { + set_ww_mode(1); + } else if (strcasecmp("auto",mode.c_str()) == 0) { + set_ww_mode(2); + } +} + // sets the thermostat working mode, where mode is a string void Thermostat::set_mode(const std::string & mode, const uint8_t hc_num) { if (mode_tostring(HeatingCircuit::Mode::OFF) == mode) { @@ -1359,7 +1391,11 @@ void Thermostat::set_mode(const uint8_t mode, const uint8_t hc_num) { } break; case EMSdevice::EMS_DEVICE_FLAG_JUNKERS: - offset = EMS_OFFSET_JunkersSetMessage_set_mode; + if ((flags() & EMS_DEVICE_FLAG_JUNKERS_2) == EMS_DEVICE_FLAG_JUNKERS_2) { + offset = EMS_OFFSET_JunkersSetMessage2_set_mode; + } else { + offset = EMS_OFFSET_JunkersSetMessage_set_mode; + } validate_typeid = monitor_typeids[hc_p]; if (mode == HeatingCircuit::Mode::NOFROST) { set_mode_value = 0x01; @@ -1621,6 +1657,22 @@ void Thermostat::console_commands(Shell & shell, unsigned int context) { }; }); + EMSESPShell::commands->add_command( + ShellContext::THERMOSTAT, + CommandFlags::ADMIN, + flash_string_vector{F_(change), F_(mode)}, + flash_string_vector{F_(mode_mandatory)}, + [=](Shell & shell __attribute__((unused)), const std::vector & arguments) { + set_ww_mode(arguments.front()); + }, + [](Shell & shell __attribute__((unused)), const std::vector & arguments __attribute__((unused))) -> const std::vector { + return std::vector{read_flash_string(F("off")), + read_flash_string(F("on")), + read_flash_string(F("auto")) + + }; + }); + EMSESPShell::commands->add_command(ShellContext::THERMOSTAT, CommandFlags::USER, flash_string_vector{F_(show)}, diff --git a/src/devices/thermostat.h b/src/devices/thermostat.h index bf25c4abe..026aa65c5 100644 --- a/src/devices/thermostat.h +++ b/src/devices/thermostat.h @@ -130,6 +130,7 @@ class Thermostat : public EMSdevice { uint8_t wwSystem_ = EMS_VALUE_UINT_NOTSET; uint8_t wwExtra_ = EMS_VALUE_UINT_NOTSET; + uint8_t wwMode_ = EMS_VALUE_UINT_NOTSET; std::vector> heating_circuits_; // each thermostat can have multiple heating circuits @@ -195,6 +196,7 @@ class Thermostat : public EMSdevice { static constexpr uint8_t EMS_OFFSET_JunkersSetMessage_night_temp = 16; // EMS offset to set temperature on thermostat for night mode static constexpr uint8_t EMS_OFFSET_JunkersSetMessage_no_frost_temp = 15; // EMS offset to set temperature on thermostat for no frost mode static constexpr uint8_t EMS_OFFSET_JunkersSetMessage_set_mode = 14; // EMS offset to set mode on thermostat + static constexpr uint8_t EMS_OFFSET_JunkersSetMessage2_set_mode = 4; // EMS offset to set mode on thermostat static constexpr uint8_t EMS_OFFSET_JunkersSetMessage2_no_frost_temp = 5; static constexpr uint8_t EMS_OFFSET_JunkersSetMessage2_eco_temp = 6; static constexpr uint8_t EMS_OFFSET_JunkersSetMessage3_heat = 7; @@ -204,6 +206,7 @@ class Thermostat : public EMSdevice { // Installation settings static constexpr uint8_t EMS_TYPE_IBASettings = 0xA5; // installation settings + static constexpr uint8_t EMS_TYPE_wwSettings = 0x37; // ww settings std::shared_ptr heating_circuit(std::shared_ptr telegram); std::shared_ptr heating_circuit(const uint8_t hc_num); @@ -211,6 +214,7 @@ class Thermostat : public EMSdevice { void process_RCOutdoorTemp(std::shared_ptr telegram); void process_IBASettings(std::shared_ptr telegram); void process_RCTime(std::shared_ptr telegram); + void process_RC35wwSettings(std::shared_ptr telegram); void process_RC35Monitor(std::shared_ptr telegram); void process_RC35Set(std::shared_ptr telegram); @@ -246,6 +250,8 @@ class Thermostat : public EMSdevice { void set_settings_building(const uint8_t bg); void set_settings_language(const uint8_t lg); void set_control(const uint8_t ctrl, const uint8_t hc_num); + void set_ww_mode(const uint8_t mode); + void set_ww_mode(const std::string & mode); void set_mode(const uint8_t mode, const uint8_t hc_num); void set_mode(const std::string & mode, const uint8_t hc_num); void set_temperature(const float temperature, const std::string & mode, const uint8_t hc_num); From b45dc92159f2e1c4b6fe95d53a8beb1b5d770f8d Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Sat, 27 Jun 2020 14:57:01 +0200 Subject: [PATCH 3/4] publish thermostat wwMode --- src/devices/thermostat.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index 76dbf1f32..81acbb3b1 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -494,6 +494,15 @@ void Thermostat::publish_values() { rootThermostat["building"] = "heavy"; } } + if (Helpers::hasValue(wwMode_)) { + if (wwMode_ == 0) { + rootThermostat["wwmode"] = "off"; + } else if (wwMode_ == 1) { + rootThermostat["wwmode"] = "on"; + } else if (wwMode_ == 2) { + rootThermostat["wwmode"] = "auto"; + } + } if (mqtt_format_ == Settings::MQTT_format::SINGLE) { Mqtt::publish("thermostat_data", doc); rootThermostat = doc.to(); // clear object From 1b00a4405b1098c8c15e3e379cffc9c7a6f7a278 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Tue, 30 Jun 2020 16:36:45 +0200 Subject: [PATCH 4/4] Junkers modes sorted. --- src/devices/thermostat.cpp | 32 ++++++++++++++++++++++----- src/devices/thermostat.h | 2 +- src/emsesp.cpp | 2 +- src/telegram.cpp | 45 +++++++++++++++++++++++++++----------- src/uart/emsuart_esp32.cpp | 25 +++------------------ 5 files changed, 63 insertions(+), 43 deletions(-) diff --git a/src/devices/thermostat.cpp b/src/devices/thermostat.cpp index 4b8229b6e..a8f158db2 100644 --- a/src/devices/thermostat.cpp +++ b/src/devices/thermostat.cpp @@ -261,6 +261,12 @@ void Thermostat::thermostat_cmd(const char * message) { if (float f = doc[hc_name]["nofrosttemp"]) { set_temperature(f, HeatingCircuit::Mode::NOFROST, hc_num); } + if (float f = doc[hc_name]["ecotemp"]) { + set_temperature(f, HeatingCircuit::Mode::ECO, hc_num); + } + if (float f = doc[hc_name]["heattemp"]) { + set_temperature(f, HeatingCircuit::Mode::HEAT, hc_num); + } if (float f = doc[hc_name]["summertemp"]) { set_temperature(f, HeatingCircuit::Mode::SUMMER, hc_num); } @@ -341,6 +347,12 @@ void Thermostat::thermostat_cmd(const char * message) { if (float f = doc["nofrosttemp"]) { set_temperature(f, HeatingCircuit::Mode::NOFROST, hc_num); } + if (float f = doc["ecotemp"]) { + set_temperature(f, HeatingCircuit::Mode::ECO, hc_num); + } + if (float f = doc["heattemp"]) { + set_temperature(f, HeatingCircuit::Mode::HEAT, hc_num); + } if (float f = doc["summertemp"]) { set_temperature(f, HeatingCircuit::Mode::SUMMER, hc_num); } @@ -785,6 +797,8 @@ uint8_t Thermostat::HeatingCircuit::get_mode(uint8_t flags) const { return HeatingCircuit::Mode::MANUAL; } else if (mode == 2) { return HeatingCircuit::Mode::AUTO; + } else if (mode == 3) { + return HeatingCircuit::Mode::HOLIDAY; } } else { // default for all other thermostats if (mode == 0) { @@ -806,9 +820,11 @@ uint8_t Thermostat::HeatingCircuit::get_mode_type(uint8_t flags) const { if (flags == EMS_DEVICE_FLAG_JUNKERS) { if (mode_type == 3) { - return HeatingCircuit::Mode::DAY; + return HeatingCircuit::Mode::HEAT; } else if (mode == 2) { - return HeatingCircuit::Mode::NIGHT; + return HeatingCircuit::Mode::ECO; + } else if (mode == 1) { + return HeatingCircuit::Mode::NOFROST; } } else if ((flags == EMS_DEVICE_FLAG_RC35) || (flags == EMS_DEVICE_FLAG_RC30_1)) { if (mode_type == 0) { @@ -1130,8 +1146,8 @@ void Thermostat::process_JunkersMonitor(std::shared_ptr telegram telegram->read_value(hc->curr_roomTemp, 4); // value is * 10 telegram->read_value(hc->setpoint_roomTemp, 2); // value is * 10 - telegram->read_bitvalue(hc->mode_type, 0, 0); // first bit 1=day, 0=night - telegram->read_value(hc->mode, 1); // 1 = manual, 2 = auto + telegram->read_value(hc->mode_type, 0); // 1 = nofrost, 2 = eco, 3 = heat + telegram->read_value(hc->mode, 1); // 1 = manual, 2 = auto } // type 0x02A5 - data from the Nefit RC1010/3000 thermostat (0x18) and RC300/310s on 0x10 @@ -1458,7 +1474,7 @@ void Thermostat::set_mode(const uint8_t mode, const uint8_t hc_num) { validate_typeid = monitor_typeids[hc_p]; if (mode == HeatingCircuit::Mode::NOFROST) { set_mode_value = 0x01; - } else if (mode == HeatingCircuit::Mode::ECO) { + } else if (mode == HeatingCircuit::Mode::ECO || (mode == HeatingCircuit::Mode::NIGHT)) { set_mode_value = 0x02; } else if ((mode == HeatingCircuit::Mode::DAY) || (mode == HeatingCircuit::Mode::HEAT)) { set_mode_value = 0x03; // comfort @@ -1603,15 +1619,17 @@ void Thermostat::set_temperature(const float temperature, const uint8_t mode, co offset = EMS_OFFSET_JunkersSetMessage_no_frost_temp; break; case HeatingCircuit::Mode::NIGHT: + case HeatingCircuit::Mode::ECO: offset = EMS_OFFSET_JunkersSetMessage_night_temp; break; + case HeatingCircuit::Mode::HEAT: case HeatingCircuit::Mode::DAY: offset = EMS_OFFSET_JunkersSetMessage_day_temp; break; default: case HeatingCircuit::Mode::AUTO: // automatic selection, if no type is defined, we use the standard code uint8_t mode_type = hc->get_mode_type(flags()); - offset = (mode_type == HeatingCircuit::Mode::NIGHT) ? EMS_OFFSET_JunkersSetMessage_night_temp : EMS_OFFSET_JunkersSetMessage_day_temp; + offset = (mode_type == HeatingCircuit::Mode::NIGHT || mode_type == HeatingCircuit::Mode::ECO) ? EMS_OFFSET_JunkersSetMessage_night_temp : EMS_OFFSET_JunkersSetMessage_day_temp; break; } @@ -1622,10 +1640,12 @@ void Thermostat::set_temperature(const float temperature, const uint8_t mode, co offset = EMS_OFFSET_JunkersSetMessage2_no_frost_temp; break; case HeatingCircuit::Mode::ECO: + case HeatingCircuit::Mode::NIGHT: offset = EMS_OFFSET_JunkersSetMessage2_eco_temp; break; default: case HeatingCircuit::Mode::HEAT: + case HeatingCircuit::Mode::DAY: offset = EMS_OFFSET_JunkersSetMessage3_heat; break; } diff --git a/src/devices/thermostat.h b/src/devices/thermostat.h index 028bf6907..badfdabf7 100644 --- a/src/devices/thermostat.h +++ b/src/devices/thermostat.h @@ -188,7 +188,7 @@ class Thermostat : public EMSdevice { static constexpr uint8_t EMS_OFFSET_RCPLUSSet_temp_setpoint = 8; // temp setpoint, when changing of templevel (in auto) value is reset to FF static constexpr uint8_t EMS_OFFSET_RCPLUSSet_manual_setpoint = 10; // manual setpoint - static constexpr uint8_t EMS_OFFSET_JunkersStatusMessage_daymode = 0; // 3 = day, 2 = night + static constexpr uint8_t EMS_OFFSET_JunkersStatusMessage_daymode = 0; // 3 = day, 2 = night, 1 = nofrost static constexpr uint8_t EMS_OFFSET_JunkersStatusMessage_mode = 1; // current mode, 1 = manual, 2 = auto static constexpr uint8_t EMS_OFFSET_JunkersStatusMessage_setpoint = 2; // setpoint temp static constexpr uint8_t EMS_OFFSET_JunkersStatusMessage_curr = 4; // current temp diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 28a54f6bc..7a56927b5 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -868,7 +868,7 @@ void EMSESP::console_commands(Shell & shell, unsigned int context) { uint8_t watch = emsesp::EMSESP::watch(); if (watch == WATCH_OFF) { - shell.printfln(F("Watch is off")); + shell.printfln(F("Watching telegrams is off")); return; } diff --git a/src/telegram.cpp b/src/telegram.cpp index 1c8326511..7b78a96f2 100644 --- a/src/telegram.cpp +++ b/src/telegram.cpp @@ -85,19 +85,38 @@ std::string Telegram::to_string() const { if (message_length == 0) { return read_flash_string(F("")); } - - std::string str(160, '\0'); - char buffer[4]; - char * p = &str[0]; - for (uint8_t i = 0; i < this->message_length; i++) { - Helpers::hextoa(buffer, this->message_data[i]); - *p++ = buffer[0]; - *p++ = buffer[1]; - *p++ = ' '; // space + uint8_t data[EMS_MAX_TELEGRAM_LENGTH]; + uint8_t length = 0; + data[0] = this->src ^ RxService::ems_mask(); + if (this->operation == Telegram::Operation::TX_READ) { + data[1] = this->dest | 0x80; + data[4] = this->message_data[0]; + if (this->type_id > 0xFF) { + data[2] = 0xFF; + data[5] = (this->type_id >> 8) - 1; + data[6] = this->type_id & 0xFF; + length = 7; + } else { + data[2] = this->type_id; + length = 5; + } } - *--p = '\0'; // null terminate just in case, loosing the trailing space - - return str; + if (this->operation == Telegram::Operation::TX_WRITE) { + data[1] = this->dest; + if (this->type_id > 0xFF) { + data[2] = 0xFF; + data[4] = (this->type_id >> 8) - 1; + data[5] = this->type_id & 0xFF; + length = 6; + } else { + data[2] = this->type_id; + length = 4; + } + for (uint8_t i = 0; i < this->message_length; i++) { + data[length++] = this->message_data[i]; + } + } + return Helpers::data_to_hex(data, length); } // returns telegram's full telegram message in hex @@ -538,7 +557,7 @@ void TxService::retry_tx(const uint8_t operation, const uint8_t * data, const ui return; } - LOG_DEBUG(F("[DEBUG] Last Tx %s operation failed. Retry #%d. sent message data: %s, received: %s"), + LOG_DEBUG(F("[DEBUG] Last Tx %s operation failed. Retry #%d. sent message: %s, received: %s"), (operation == Telegram::Operation::TX_WRITE) ? F("Write") : F("Read"), retry_count_, telegram_last_->to_string().c_str(), diff --git a/src/uart/emsuart_esp32.cpp b/src/uart/emsuart_esp32.cpp index eed59d19b..580ea3ac7 100644 --- a/src/uart/emsuart_esp32.cpp +++ b/src/uart/emsuart_esp32.cpp @@ -60,7 +60,7 @@ void EMSuart::emsuart_recvTask(void * para) { void IRAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) { static uint8_t rxbuf[EMS_MAXBUFFERSIZE]; static uint8_t length; - UART_MUTEX_LOCK(); + if (EMS_UART.int_st.rxfifo_full) { EMS_UART.int_clr.rxfifo_full = 1; emsTxBufIdx++; @@ -93,7 +93,6 @@ void IRAM_ATTR EMSuart::emsuart_rx_intr_handler(void * para) { xRingbufferSendFromISR(buf_handle, rxbuf, length - 1, &baseType); } drop_next_rx = false; - UART_MUTEX_UNLOCK(); } } @@ -102,17 +101,16 @@ void IRAM_ATTR EMSuart::emsuart_tx_timer_intr_handler() { if (emsTxBufIdx > EMS_MAXBUFFERSIZE) { return; } - UART_MUTEX_LOCK(); + emsTxBufIdx++; + if (emsTxBufIdx < emsTxBufLen) { EMS_UART.fifo.rw_byte = emsTxBuf[emsTxBufIdx]; - timerWrite(timer, 0); timerAlarmWrite(timer, emsTxWait, false); timerAlarmEnable(timer); } else if (emsTxBufIdx == emsTxBufLen) { EMS_UART.conf0.txd_brk = 1; // after send } - UART_MUTEX_UNLOCK(); } /* @@ -126,7 +124,6 @@ void EMSuart::start(uint8_t tx_mode) { return; } tx_mode_ = tx_mode; - UART_MUTEX_LOCK(); uart_config_t uart_config = { .baud_rate = EMSUART_BAUD, @@ -151,24 +148,20 @@ void EMSuart::start(uint8_t tx_mode) { emsTxBufLen = 0; timer = timerBegin(1, 80, true); // timer prescale to 1 µs, countup timerAttachInterrupt(timer, &emsuart_tx_timer_intr_handler, true); // Timer with edge interrupt - UART_MUTEX_UNLOCK(); } /* * Stop, disables interrupt */ void EMSuart::stop() { - UART_MUTEX_LOCK(); EMS_UART.int_ena.val = 0; // disable all intr. // timerAlarmDisable(timer); - UART_MUTEX_UNLOCK(); }; /* * Restart Interrupt */ void EMSuart::restart() { - UART_MUTEX_LOCK(); if (EMS_UART.int_raw.brk_det) { EMS_UART.int_clr.brk_det = 1; // clear flag drop_next_rx = true; // and drop first frame @@ -176,7 +169,6 @@ void EMSuart::restart() { EMS_UART.int_ena.brk_det = 1; // activate only break emsTxBufIdx = 0; emsTxBufLen = 0; - UART_MUTEX_UNLOCK(); } /* @@ -184,12 +176,10 @@ void EMSuart::restart() { */ void EMSuart::send_poll(uint8_t data) { // if (tx_mode_ >= 6 || tx_mode_ < 4) { // modes 1, 2, 3 also here - UART_MUTEX_LOCK(); if (tx_mode_ >= 5) { EMS_UART.fifo.rw_byte = data; emsTxBufIdx = 0; emsTxBufLen = 1; - timerWrite(timer, 0); timerAlarmWrite(timer, emsTxWait, false); timerAlarmEnable(timer); } else if (tx_mode_ == 5) { @@ -222,7 +212,6 @@ void EMSuart::send_poll(uint8_t data) { } EMS_UART.conf0.txd_brk = 1; // } - UART_MUTEX_UNLOCK(); } /* @@ -234,7 +223,6 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) { if (len == 0 || len >= EMS_MAXBUFFERSIZE) { return EMS_TX_STATUS_ERR; } - UART_MUTEX_LOCK(); // if (tx_mode_ >= 6 || tx_mode_ < 4) { // timer controlled modes, also modes 1, 2, 3 because delays not working if (tx_mode_ >= 5) { // timer controlled modes @@ -244,10 +232,8 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) { EMS_UART.fifo.rw_byte = buf[0]; emsTxBufIdx = 0; emsTxBufLen = len; - timerWrite(timer, 0); timerAlarmWrite(timer, emsTxWait, false); timerAlarmEnable(timer); - UART_MUTEX_UNLOCK(); return EMS_TX_STATUS_OK; } @@ -260,7 +246,6 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) { emsTxBufLen = len; EMS_UART.conf1.rxfifo_full_thrhd = 1; EMS_UART.int_ena.rxfifo_full = 1; - UART_MUTEX_UNLOCK(); return EMS_TX_STATUS_OK; } @@ -269,7 +254,6 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) { EMS_UART.fifo.rw_byte = buf[i]; } EMS_UART.conf0.txd_brk = 1; // after send - UART_MUTEX_UNLOCK(); return EMS_TX_STATUS_OK; } @@ -281,7 +265,6 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) { EMS_UART.conf0.txd_brk = 1; // after send, cleard by hardware after send // delayMicroseconds(EMSUART_TX_WAIT_BRK); // EMS_UART.conf0.txd_brk = 0; - UART_MUTEX_UNLOCK(); return EMS_TX_STATUS_OK; } @@ -293,7 +276,6 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) { EMS_UART.conf0.txd_brk = 1; // after send, cleard by hardware after send // delayMicroseconds(EMSUART_TX_WAIT_BRK); // EMS_UART.conf0.txd_brk = 0; - UART_MUTEX_UNLOCK(); return EMS_TX_STATUS_OK; } @@ -312,7 +294,6 @@ uint16_t EMSuart::transmit(uint8_t * buf, uint8_t len) { EMS_UART.conf0.txd_brk = 1; // after send, cleard by hardware after send // delayMicroseconds(EMSUART_TX_WAIT_BRK); // EMS_UART.conf0.txd_brk = 0; - UART_MUTEX_UNLOCK(); return EMS_TX_STATUS_OK; }