locking in DC11
This commit is contained in:
parent
a635651474
commit
13c71164e8
4 changed files with 20 additions and 7 deletions
|
@ -211,20 +211,21 @@ void start_network(console *const c)
|
||||||
|
|
||||||
Serial.println(F("* Adding DC11"));
|
Serial.println(F("* Adding DC11"));
|
||||||
dc11 *dc11_ = new dc11(1100, b);
|
dc11 *dc11_ = new dc11(1100, b);
|
||||||
b->add_DC11(dc11_);
|
|
||||||
|
|
||||||
#if !defined(BUILD_FOR_RP2040) && defined(TTY_SERIAL_RX)
|
#if !defined(BUILD_FOR_RP2040) && defined(TTY_SERIAL_RX)
|
||||||
constexpr uint32_t hwSerialConfig = SERIAL_8N1;
|
constexpr uint32_t hwSerialConfig = SERIAL_8N1;
|
||||||
uint32_t bitrate = load_serial_speed_configuration();
|
uint32_t bitrate = load_serial_speed_configuration();
|
||||||
|
|
||||||
Serial.printf("* Init TTY (on DC11), baudrate: %d bps, RX: %d, TX: %d", bitrate, TTY_SERIAL_RX, TTY_SERIAL_TX);
|
Serial.printf("* Init TTY (on DC11), baudrate: %d bps, RX: %d, TX: %d", bitrate, TTY_SERIAL_RX, TTY_SERIAL_TX);
|
||||||
Serial.println(F(""));
|
Serial.println(F(""));
|
||||||
|
|
||||||
Serial_RS232.begin(bitrate, hwSerialConfig, TTY_SERIAL_RX, TTY_SERIAL_TX);
|
Serial_RS232.begin(bitrate, hwSerialConfig, TTY_SERIAL_RX, TTY_SERIAL_TX);
|
||||||
Serial_RS232.setHwFlowCtrlMode(0);
|
Serial_RS232.setHwFlowCtrlMode(0);
|
||||||
|
Serial_RS232.println(F("Go!"));
|
||||||
|
|
||||||
dc11_->set_serial(&Serial_RS232);
|
dc11_->set_serial(&Serial_RS232);
|
||||||
#endif
|
#endif
|
||||||
|
b->add_DC11(dc11_);
|
||||||
|
|
||||||
Serial.println(F("* Starting (NTP-) clock"));
|
Serial.println(F("* Starting (NTP-) clock"));
|
||||||
ntp_ = new ntp("188.212.113.203");
|
ntp_ = new ntp("188.212.113.203");
|
||||||
|
|
|
@ -77,6 +77,6 @@ board_build.filesystem = littlefs
|
||||||
lib_deps = greiman/SdFat@^2.1.2
|
lib_deps = greiman/SdFat@^2.1.2
|
||||||
adafruit/Adafruit NeoPixel
|
adafruit/Adafruit NeoPixel
|
||||||
bblanchon/ArduinoJson@^6.19.4
|
bblanchon/ArduinoJson@^6.19.4
|
||||||
build_flags = -std=gnu++17 -DESP32=1 -ggdb3 -D_GLIBCXX_USE_C99 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -DCONFIG_SPIRAM_USE_MALLOC -DTTY_SERIAL_TX=4 -DTTY_SERIAL_RX=5 -DNEOPIXELS_PIN=40
|
build_flags = -std=gnu++17 -DESP32=1 -ggdb3 -D_GLIBCXX_USE_C99 -DBOARD_HAS_PSRAM -mfix-esp32-psram-cache-issue -DCONFIG_SPIRAM_USE_MALLOC -DTTY_SERIAL_TX=17 -DTTY_SERIAL_RX=18 -DNEOPIXELS_PIN=40
|
||||||
build_unflags = -std=gnu++11
|
build_unflags = -std=gnu++11
|
||||||
extra_scripts = pre:prepare.py
|
extra_scripts = pre:prepare.py
|
||||||
|
|
19
dc11.cpp
19
dc11.cpp
|
@ -248,6 +248,7 @@ void dc11::set_serial(Stream *const s)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_lock<std::mutex> lck(s_lock);
|
||||||
this->s = s;
|
this->s = s;
|
||||||
s->write("Press enter to connect");
|
s->write("Press enter to connect");
|
||||||
|
|
||||||
|
@ -259,8 +260,15 @@ void dc11::serial_handler()
|
||||||
while(!stop_flag) {
|
while(!stop_flag) {
|
||||||
yield();
|
yield();
|
||||||
|
|
||||||
if (s->available() == 0)
|
char c = 0;
|
||||||
continue;
|
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> lck(s_lock);
|
||||||
|
if (s->available() == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
c = s->read();
|
||||||
|
}
|
||||||
|
|
||||||
// 3 is reserved for a serial port
|
// 3 is reserved for a serial port
|
||||||
constexpr const int serial_line = 3;
|
constexpr const int serial_line = 3;
|
||||||
|
@ -274,7 +282,7 @@ void dc11::serial_handler()
|
||||||
registers[serial_line * 4 + 0] |= 0160000; // "ERROR", RING INDICATOR, CARRIER TRANSITION
|
registers[serial_line * 4 + 0] |= 0160000; // "ERROR", RING INDICATOR, CARRIER TRANSITION
|
||||||
}
|
}
|
||||||
|
|
||||||
recv_buffers[serial_line].push_back(s->read());
|
recv_buffers[serial_line].push_back(c);
|
||||||
|
|
||||||
registers[serial_line * 4 + 0] |= 128; // DONE: bit 7
|
registers[serial_line * 4 + 0] |= 128; // DONE: bit 7
|
||||||
|
|
||||||
|
@ -408,8 +416,11 @@ void dc11::write_word(const uint16_t addr, const uint16_t v)
|
||||||
|
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
if (line_nr == 3) {
|
if (line_nr == 3) {
|
||||||
if (s != nullptr)
|
if (s != nullptr) {
|
||||||
|
std::unique_lock<std::mutex> lck(s_lock);
|
||||||
|
|
||||||
s->write(c);
|
s->write(c);
|
||||||
|
}
|
||||||
|
|
||||||
if (is_tx_interrupt_enabled(line_nr))
|
if (is_tx_interrupt_enabled(line_nr))
|
||||||
trigger_interrupt(line_nr, true);
|
trigger_interrupt(line_nr, true);
|
||||||
|
|
1
dc11.h
1
dc11.h
|
@ -49,6 +49,7 @@ private:
|
||||||
std::vector<char> recv_buffers[dc11_n_lines];
|
std::vector<char> recv_buffers[dc11_n_lines];
|
||||||
std::mutex input_lock[dc11_n_lines];
|
std::mutex input_lock[dc11_n_lines];
|
||||||
#if defined(ESP32)
|
#if defined(ESP32)
|
||||||
|
std::mutex s_lock;
|
||||||
Stream *s { nullptr };
|
Stream *s { nullptr };
|
||||||
std::thread *serial_th { nullptr };
|
std::thread *serial_th { nullptr };
|
||||||
bool serial_enabled { false };
|
bool serial_enabled { false };
|
||||||
|
|
Loading…
Add table
Reference in a new issue