Skip to content

Commit

Permalink
Merge branch 'main' into system-stats-tab
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiw committed Jul 29, 2024
2 parents 8ea3522 + 34c7b4d commit f8fc92e
Show file tree
Hide file tree
Showing 34 changed files with 1,380 additions and 423 deletions.
5 changes: 4 additions & 1 deletion THEORY_OF_OPERATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ The ezDV firmware is split into several tasks to perform various actions. These
* FlexVitaTask - handles audio I/O (analog and digital) to/from a configured Flex radio
* Icom support (`firmware/network/icom`)
* IcomSocketTask - handles UDP connection to one of the Icom remote ports (control, audio, CAT control)
* Network interfaces (`firmware/network/interfaces`)
* WirelessInterface - handles bringup/teardown of the built-in Wi-Fi on the ESP32.
* EthernetInterface - handles bringup/teardown of the W5500 Ethernet module (if attached).
* FreeDVReporterTask - handles reporting to [FreeDV Reporter](https://qso.freedv.org/)
* HttpServerTask - handles serving of ezDV's built-in web interface
* WirelessTask - handles bringup and teardown of the configured Wi-Fi connection
* NetworkTask - handles bringup and teardown of the configured network interfaces (Wi-Fi, Ethernet)
* Storage (`firmware/storage`) -- handles configuration and firmware storage
* SettingsTask - handles storage of configuration settings
* SoftwareUpdateTask - handles updating of the ezDV firmware from the web interface
Expand Down
77 changes: 70 additions & 7 deletions firmware/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
#include "esp_sleep.h"
#include "esp_log.h"

#if CONFIG_EZDV_PRINT_HEAP_USAGE
#include "esp_heap_task_info.h"
#endif // CONFIG_EZDV_PRINT_HEAP_USAGE

#if CONFIG_EZDV_ENABLE_TICK_OUTPUT
#define MAIN_APP_TASK_TICK_INTERVAL (pdMS_TO_TICKS(CONFIG_EZDV_TICK_OUTPUT_INTERVAL))
#else
Expand Down Expand Up @@ -54,16 +58,32 @@ extern "C"
bool rebootDevice = false;
}

void* operator new ( std::size_t count )
{
return heap_caps_malloc(count, MALLOC_CAP_SPIRAM | MALLOC_CAP_32BIT);
}

void operator delete ( void* ptr ) noexcept
{
return heap_caps_free(ptr);
}

void operator delete(void* ptr, std::size_t)
{
return heap_caps_free(ptr);
}

namespace ezdv
{

App::App()
: ezdv::task::DVTask("MainApp", 1, 4096, tskNO_AFFINITY, 10, MAIN_APP_TASK_TICK_INTERVAL)
, audioMixer_(nullptr)
, beeperTask_(nullptr)
, freedvTask_(nullptr)
, max17048_(&i2cMaster_)
, tlv320Device_(nullptr)
, wirelessTask_(nullptr)
, networkTask_(nullptr)
, settingsTask_(nullptr)
, softwareUpdateTask_(nullptr)
, uiTask_(nullptr)
Expand Down Expand Up @@ -401,11 +421,11 @@ void App::onTaskStart_()
start(uiTask_, pdMS_TO_TICKS(1000));

// Start Wi-Fi
wirelessTask_ = new network::WirelessTask(freedvTask_, tlv320Device_, audioMixer_, voiceKeyerTask_);
assert(wirelessTask_ != nullptr);
networkTask_ = new network::NetworkTask(freedvTask_, tlv320Device_, audioMixer_, voiceKeyerTask_);
assert(networkTask_ != nullptr);

wirelessTask_->setWiFiOverride(wifiOverrideEnabled_);
start(wirelessTask_, pdMS_TO_TICKS(5000));
networkTask_->setWiFiOverride(wifiOverrideEnabled_);
start(networkTask_, pdMS_TO_TICKS(5000));

// Start storage handling
settingsTask_ = new storage::SettingsTask();
Expand Down Expand Up @@ -459,9 +479,9 @@ void App::onTaskSleep_()
if (!rfComplianceEnabled_)
{
// Sleep Wi-Fi
if (wirelessTask_ != nullptr)
if (networkTask_ != nullptr)
{
sleep(wirelessTask_, pdMS_TO_TICKS(5000));
sleep(networkTask_, pdMS_TO_TICKS(5000));
}

// Sleep UI
Expand Down Expand Up @@ -635,6 +655,47 @@ static esp_err_t print_real_time_stats(TickType_t xTicksToWait)
}
#endif // CONFIG_EZDV_OUTPUT_TASK_LIST

#if CONFIG_EZDV_PRINT_HEAP_USAGE
#define MAX_TASK_NUM 20 // Max number of per tasks info that it can store
#define MAX_BLOCK_NUM 20 // Max number of per block info that it can store

static void esp_dump_per_task_heap_info(void)
{
size_t s_prepopulated_num = 0;
heap_task_totals_t s_totals_arr[MAX_TASK_NUM];
heap_task_block_t s_block_arr[MAX_BLOCK_NUM];

heap_task_info_params_t heap_info;
memset(&heap_info, 0, sizeof(heap_info));

memset(&s_totals_arr, 0, sizeof(s_totals_arr));
memset(&s_block_arr, 0, sizeof(s_block_arr));

heap_info.caps[0] = MALLOC_CAP_INTERNAL;
heap_info.mask[0] = MALLOC_CAP_INTERNAL;
heap_info.caps[1] = MALLOC_CAP_SPIRAM;
heap_info.mask[1] = MALLOC_CAP_SPIRAM;
heap_info.tasks = NULL; // Passing NULL captures heap info for all tasks
heap_info.num_tasks = 0;
heap_info.totals = s_totals_arr; // Gets task wise allocation details
heap_info.num_totals = &s_prepopulated_num;
heap_info.max_totals = MAX_TASK_NUM; // Maximum length of "s_totals_arr"
heap_info.blocks = s_block_arr; // Gets block wise allocation details. For each block, gets owner task, address and size
heap_info.max_blocks = MAX_BLOCK_NUM; // Maximum length of "s_block_arr"

heap_caps_get_per_task_info(&heap_info);

for (int i = 0 ; i < *heap_info.num_totals; i++) {
printf("Task %s -> ", heap_info.totals[i].task ? pcTaskGetName(heap_info.totals[i].task) : "Pre-Scheduler allocs");
printf("CAP_INTERNAL: %d CAP_SPIRAM: %d\n",
heap_info.totals[i].size[0], // Heap size with CAP_INTERNAL capabilities
heap_info.totals[i].size[1]); // Heap size with CAP_SPIRAM capabilities
}

printf("\n\n");
}
#endif // CONFIG_EZDV_PRINT_HEAP_USAGE

void App::onTaskTick_()
{
#if CONFIG_EZDV_ENABLE_TICK_OUTPUT
Expand All @@ -651,6 +712,8 @@ void App::onTaskTick_()
ESP_LOGI(CURRENT_LOG_TAG, "heap free (internal): %d", heap_caps_get_free_size(MALLOC_CAP_INTERNAL));
ESP_LOGI(CURRENT_LOG_TAG, "heap free (SPIRAM): %d", heap_caps_get_free_size(MALLOC_CAP_SPIRAM));
ESP_LOGI(CURRENT_LOG_TAG, "heap free (DMA): %d", heap_caps_get_free_size(MALLOC_CAP_DMA));

//esp_dump_per_task_heap_info();
#endif // CONFIG_EZDV_PRINT_HEAP_USAGE

#if CONFIG_EZDV_OUTPUT_TASK_LIST
Expand Down
4 changes: 2 additions & 2 deletions firmware/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "driver/LedArray.h"
#include "driver/MAX17048.h"
#include "driver/TLV320.h"
#include "network/WirelessTask.h"
#include "network/NetworkTask.h"
#include "storage/SettingsTask.h"
#include "storage/SoftwareUpdateTask.h"
#include "ui/UserInterfaceTask.h"
Expand Down Expand Up @@ -70,7 +70,7 @@ class App : public DVTask
driver::LedArray ledArray_;
driver::MAX17048 max17048_;
driver::TLV320* tlv320Device_;
network::WirelessTask* wirelessTask_;
network::NetworkTask* networkTask_;
storage::SettingsTask* settingsTask_;
storage::SoftwareUpdateTask* softwareUpdateTask_;
ui::UserInterfaceTask* uiTask_;
Expand Down
6 changes: 5 additions & 1 deletion firmware/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ set(SOURCES
"network/icom/LoginState.cpp"
"network/icom/StateMachine.cpp"
"network/icom/TrackedPacketState.cpp"
"network/interfaces/EthernetInterface.cpp"
"network/interfaces/INetworkInterface.cpp"
"network/interfaces/WirelessInterface.cpp"
"network/FreeDVReporterTask.cpp"
"network/HttpServerTask.cpp"
"network/NetworkMessage.cpp"
"network/NetworkTask.cpp"
"network/PskReporterTask.cpp"
"network/ReportingMessage.cpp"
"network/WirelessTask.cpp"
"storage/SettingsMessage.cpp"
"storage/SettingsTask.cpp"
"storage/SoftwareUpdateMessage.cpp"
Expand Down Expand Up @@ -78,6 +81,7 @@ if(${ESP_PLATFORM})
wear_levelling
esp_http_server
esp_netif
esp_eth
esp_timer
esp_wifi
esp_websocket_client
Expand Down
37 changes: 31 additions & 6 deletions firmware/main/driver/TLV320.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,21 @@ void TLV320::onTaskStart_()
{
// To begin, we need to hard reset the TLV320.
ESP_LOGI(CURRENT_LOG_TAG, "reset TLV320");
initializeI2S_();
initializeResetGPIO_();
tlv320HardReset_();

// Make sure the TLV320 is actually there. If not, no point in continuing.
bool result = false;
getConfigurationOption_(0, 0, &result);
if (!result)
{
ESP_LOGW(CURRENT_LOG_TAG, "Cannot communicate with TLV320, possibly using ezDV on board without one");
return;
}

// Initialize I2S.
initializeI2S_();

// Enable required clocks.
ESP_LOGI(CURRENT_LOG_TAG, "configure clocks");
tlv320ConfigureClocks_();
Expand Down Expand Up @@ -114,10 +125,18 @@ void TLV320::onTaskStart_()
void TLV320::onTaskSleep_()
{
// Stop reading from I2S.
i2s_channel_disable(i2sRxDevice_);
i2s_del_channel(i2sRxDevice_);
i2s_channel_disable(i2sTxDevice_);
i2s_del_channel(i2sTxDevice_);
if (i2sRxDevice_ != nullptr)
{
i2s_channel_disable(i2sRxDevice_);
i2s_del_channel(i2sRxDevice_);
}

if (i2sTxDevice_ != nullptr)
{
i2s_channel_disable(i2sTxDevice_);
i2s_del_channel(i2sTxDevice_);
}

i2sRxDevice_ = nullptr;
i2sTxDevice_ = nullptr;

Expand Down Expand Up @@ -206,7 +225,7 @@ void TLV320::setConfigurationOptionMultiple_(uint8_t page, uint8_t reg, uint8_t*
i2cDevice_->writeBytes(reg, val, size);
}

uint8_t TLV320::getConfigurationOption_(uint8_t page, uint8_t reg)
uint8_t TLV320::getConfigurationOption_(uint8_t page, uint8_t reg, bool* readResult)
{
if (page != currentPage_)
{
Expand All @@ -219,6 +238,12 @@ uint8_t TLV320::getConfigurationOption_(uint8_t page, uint8_t reg)
{
ESP_LOGE(CURRENT_LOG_TAG, "Could not read bytes from I2C!");
}

if (readResult != nullptr)
{
*readResult = rv;
}

return result[0];
}

Expand Down
2 changes: 1 addition & 1 deletion firmware/main/driver/TLV320.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class TLV320 : public DVTask, public audio::AudioInput
void setPage_(uint8_t page);
void setConfigurationOption_(uint8_t page, uint8_t reg, uint8_t val);
void setConfigurationOptionMultiple_(uint8_t page, uint8_t reg, uint8_t* val, uint8_t size);
uint8_t getConfigurationOption_(uint8_t page, uint8_t reg);
uint8_t getConfigurationOption_(uint8_t page, uint8_t reg, bool* readResult = nullptr);

void setVolumeCommon_(uint8_t reg, int8_t vol);

Expand Down
24 changes: 12 additions & 12 deletions firmware/main/http_server_files/index.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<button id="voiceKeyerTab" class="nav-link" data-bs-toggle="tab" data-bs-target="#voiceKeyerTabForm" aria-current="page-voice-keyer">Voice Keyer</button>
</li>
<li class="nav-item">
<button id="wifiTab" class="nav-link" data-bs-toggle="tab" data-bs-target="#wifiTabForm" aria-current="page-wifi">Wi-Fi</button>
<button id="wifiTab" class="nav-link" data-bs-toggle="tab" data-bs-target="#wifiTabForm" aria-current="page-wifi">Network</button>
</li>
<li class="nav-item">
<button id="radioTab" class="nav-link" data-bs-toggle="tab" data-bs-target="#radioTabForm" aria-current="page-radio" disabled>Radio</button>
<button id="radioTab" class="nav-link" data-bs-toggle="tab" data-bs-target="#radioTabForm" aria-current="page-radio">Radio</button>
</li>
<li class="nav-item">
<button id="updateTab" class="nav-link" data-bs-toggle="tab" data-bs-target="#updateTabForm" aria-current="page-update">Firmware Update</button>
Expand Down Expand Up @@ -271,17 +271,23 @@
<div class="row mb-3" id="wifiSuccessAlertRow">
<div class="col-xs-12 col-md-6">
<div class="alert alert-success" role="alert">
Your Wi-Fi configuration has been saved. Please restart ezDV for the changes to take effect.
Your network configuration has been saved. Please restart ezDV for the changes to take effect.
</div>
</div>
</div>
<div class="row mb-3" id="wifiFailAlertRow">
<div class="col-xs-12 col-md-6">
<div class="alert alert-danger" role="alert">
Could not save Wi-Fi configuration. Please verify your settings below and try again.
Could not save network configuration. Please verify your settings below and try again.
</div>
</div>
</div>
<div class="row mb-3">
<label for="wifiHostname" class="col-xs-4 col-md-2 col-form-label">Hostname</label>
<div class="col-xs-8 col-md-4">
<input id="wifiHostname" type="text" value="ezdv" class="form-control" />
</div>
</div>
<div class="row mb-3">
<div class="col-xs-12 col-md-6">
<div class="form-check">
Expand All @@ -293,12 +299,6 @@
</div>
</div>
</div>
<div class="row mb-3 wifi-enable-row">
<label for="wifiHostname" class="col-xs-4 col-md-2 col-form-label">Hostname</label>
<div class="col-xs-8 col-md-4">
<input id="wifiHostname" type="text" value="ezdv" class="form-control" />
</div>
</div>
<div class="row mb-3 wifi-enable-row">
<label for="wifiMode" class="col-xs-4 col-md-2 col-form-label">Wireless Mode</label>
<div class="col-xs-8 col-md-4">
Expand Down Expand Up @@ -380,7 +380,7 @@
<div class="row mb-3" id="radioSuccessAlertRow">
<div class="col-xs-12 col-md-6">
<div class="alert alert-success" role="alert">
Your radio configuration has been saved. For Wi-Fi related changes, please restart ezDV for the changes to take effect.
Your radio configuration has been saved. For network related changes, please restart ezDV for the changes to take effect.
</div>
</div>
</div>
Expand Down Expand Up @@ -412,7 +412,7 @@
<div class="form-check">
<input type="checkbox" id="radioEnable" class="form-check-input" />
<label class="form-check-label" for="radioEnable">
Use Wi-Fi Network for Radio RX/TX
Use Network for Radio RX/TX
</label>
</div>
</div>
Expand Down
10 changes: 1 addition & 9 deletions firmware/main/http_server_files/localscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,11 @@ var updateWifiFormState = function()
{
if ($("#wifiEnable").is(':checked'))
{
$(".wifi-enable-row").show();

// Enable Radio tab.
$("#radioTab").prop("disabled", false);
$(".wifi-enable-row").show();
}
else
{
$(".wifi-enable-row").hide();

// Additionally disable Radio tab since there's
// no point in setting up anything there if there's
// no Wi-Fi.
$("#radioTab").prop("disabled", true);
}

if ($("#wifiMode").val() == 0)
Expand Down
2 changes: 2 additions & 0 deletions firmware/main/network/FreeDVReporterTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ void FreeDVReporterTask::onTaskStart_()

void FreeDVReporterTask::onTaskSleep_()
{
reportingRefCount_ = 0;

if (reportingEnabled_)
{
stopSocketIoConnection_();
Expand Down
22 changes: 11 additions & 11 deletions firmware/main/network/HttpServerTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,23 +1002,23 @@ void HttpServerTask::onUpdateWifiMessage_(DVTask* origin, UpdateWifiMessage* mes

bool settingsValid = true;

auto hostnameJSON = cJSON_GetObjectItem(message->request, "hostname");
if (hostnameJSON != nullptr)
{
hostname = cJSON_GetStringValue(hostnameJSON);
settingsValid &= strlen(hostname) > 0;
}
else
{
settingsValid = false;
}

auto enabledJSON = cJSON_GetObjectItem(message->request, "enabled");
if (enabledJSON != nullptr)
{
enabled = cJSON_IsTrue(enabledJSON);
if (enabled)
{
auto hostnameJSON = cJSON_GetObjectItem(message->request, "hostname");
if (hostnameJSON != nullptr)
{
hostname = cJSON_GetStringValue(hostnameJSON);
settingsValid &= strlen(hostname) > 0;
}
else
{
settingsValid = false;
}

auto modeJSON = cJSON_GetObjectItem(message->request, "mode");
if (modeJSON != nullptr)
{
Expand Down
Loading

0 comments on commit f8fc92e

Please sign in to comment.