rainbow: update & bugfix

- renamed getGpio4 to getDataReadyIO
- removed setGpio4
- fixed mapper thread issue (crash when reloading the ROM)
This commit is contained in:
contact@brokestudio.fr 2021-12-27 12:35:12 +01:00
parent 123b4d06c4
commit 68cdbf1d4a
4 changed files with 12 additions and 14 deletions

View File

@ -15,8 +15,7 @@ public:
virtual uint8 tx() = 0; virtual uint8 tx() = 0;
// General purpose I/O pins // General purpose I/O pins
virtual void setGpio4(bool v) = 0; virtual bool getDataReadyIO() = 0;
virtual bool getGpio4() = 0;
}; };
#endif #endif

View File

@ -131,6 +131,7 @@ static SFORMAT SStateRegs[] =
// ESP interface // ESP interface
static EspFirmware *esp = NULL; static EspFirmware *esp = NULL;
static bool esp_running;
static bool esp_enable; static bool esp_enable;
static bool esp_irq_enable; static bool esp_irq_enable;
static bool esp_message_received; static bool esp_message_received;
@ -153,10 +154,10 @@ static void Rainbow13EspMapIrq(int32) {
// Mapper // Mapper
void esp_check_new_message(void) { void esp_check_new_message() {
while (esp != NULL) { while (esp_running) {
// get new message if needed // get new message if needed
if (esp_enable && esp->getGpio4() && !esp_message_received) if (esp_enable && esp->getDataReadyIO() && esp_message_received == false)
{ {
uint8 message_length = esp->tx(); uint8 message_length = esp->tx();
FPGA_WRAM[rx_address << 8] = message_length; FPGA_WRAM[rx_address << 8] = message_length;
@ -391,7 +392,7 @@ static DECLFR(Rainbow13Read) {
case 0x4101: case 0x4101:
{ {
uint8 message_received = esp_message_received ? 1 << 7 : 0; uint8 message_received = esp_message_received ? 1 << 7 : 0;
uint8 esp_rts_flag = esp->getGpio4() ? 0x40 : 0x00; uint8 esp_rts_flag = esp->getDataReadyIO() ? 0x40 : 0x00;
return message_received | esp_rts_flag; return message_received | esp_rts_flag;
} }
case 0x4102: case 0x4102:
@ -903,6 +904,7 @@ static void Rainbow13Power(void) {
esp_enable = false; esp_enable = false;
esp_irq_enable = false; esp_irq_enable = false;
esp_message_received = false; esp_message_received = false;
esp_running = true;
esp_RX = std::thread (esp_check_new_message); esp_RX = std::thread (esp_check_new_message);
} }
@ -945,7 +947,8 @@ static void Rainbow13Close(void)
if (esp) if (esp)
{ {
esp_enable = false; esp_enable = false;
esp_RX.detach(); esp_running = false;
esp_RX.join();
delete esp; delete esp;
esp = NULL; esp = NULL;
} }

View File

@ -211,10 +211,7 @@ uint8 BrokeStudioFirmware::tx() {
return last_byte_read; return last_byte_read;
} }
void BrokeStudioFirmware::setGpio4(bool /*v*/) { bool BrokeStudioFirmware::getDataReadyIO() {
}
bool BrokeStudioFirmware::getGpio4() {
this->receiveDataFromServer(); this->receiveDataFromServer();
this->receivePingResult(); this->receivePingResult();
return !(this->tx_buffer.empty() && this->tx_messages.empty()); return !(this->tx_buffer.empty() && this->tx_messages.empty());
@ -1928,7 +1925,7 @@ std::pair<uint8, uint8> BrokeStudioFirmware::curle_to_net_error(CURLcode curle)
void BrokeStudioFirmware::downloadFile(std::string const& url, uint8 path, uint8 file) { void BrokeStudioFirmware::downloadFile(std::string const& url, uint8 path, uint8 file) {
UDBG("RAINBOW BrokeStudioFirmware download %s -> (%u,%u)\n", url.c_str(), (unsigned int)path, (unsigned int)file); UDBG("RAINBOW BrokeStudioFirmware download %s -> (%u,%u)\n", url.c_str(), (unsigned int)path, (unsigned int)file);
//TODO asynchronous download using curl_multi_* (and maybe a thread, or regular ticks on rx/tx/getGpio4) //TODO asynchronous download using curl_multi_* (and maybe a thread, or regular ticks on rx/tx/getDataReadyIO)
// Directly fail if the curl handle was not properly initialized // Directly fail if the curl handle was not properly initialized
if (this->curl_handle == nullptr) { if (this->curl_handle == nullptr) {

View File

@ -46,8 +46,7 @@ public:
void rx(uint8 v) override; void rx(uint8 v) override;
uint8 tx() override; uint8 tx() override;
virtual void setGpio4(bool v) override; virtual bool getDataReadyIO() override;
virtual bool getGpio4() override;
private: private:
// Defined message types from CPU to ESP // Defined message types from CPU to ESP