Skip to content

Commit

Permalink
fix pmem -> make backup_ram_t data members volatile (#1135)
Browse files Browse the repository at this point in the history
* fix pmem -> make backup_ram_t data members volatile

plus add calculated crc to the pmem debug screen

* rename pmem debug menu to p.mem

As this is how its refered to in the wiki and other screens

* p.mem looked strange with capital P

---------

Co-authored-by: Eisenberger Tamas <e.tamas@iwstudio.hu>
  • Loading branch information
u-foka and u-foka authored Jun 9, 2023
1 parent b87d26f commit b9de191
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
20 changes: 17 additions & 3 deletions firmware/application/apps/ui_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include "radio.hpp"
#include "string_format.hpp"
#include "crc.hpp"

#include "audio.hpp"

Expand Down Expand Up @@ -381,22 +382,35 @@ DebugMenuView::DebugMenuView(NavigationView& nav) {
{"Peripherals", ui::Color::dark_cyan(), &bitmap_icon_peripherals, [&nav]() { nav.push<DebugPeripheralsMenuView>(); }},
{"Temperature", ui::Color::dark_cyan(), &bitmap_icon_temperature, [&nav]() { nav.push<TemperatureView>(); }},
{"Buttons Test", ui::Color::dark_cyan(), &bitmap_icon_controls, [&nav]() { nav.push<DebugControlsView>(); }},
{"Pmem", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { nav.push<DebugPmemView>(); }},
{"p.mem", ui::Color::dark_cyan(), &bitmap_icon_memory, [&nav]() { nav.push<DebugPmemView>(); }},
});
set_max_rows(2); // allow wider buttons
}

/* DebugPmemView *********************************************************/

uint32_t pmem_checksum(volatile const uint32_t data[63]) {
CRC<32> crc{0x04c11db7, 0xffffffff, 0xffffffff};
for (size_t i = 0; i < 63; i++) {
const auto word = data[i];
crc.process_byte((word >> 0) & 0xff);
crc.process_byte((word >> 8) & 0xff);
crc.process_byte((word >> 16) & 0xff);
crc.process_byte((word >> 24) & 0xff);
}
return crc.checksum();
}

DebugPmemView::DebugPmemView(NavigationView& nav)
: data{*reinterpret_cast<pmem_data*>(memory::map::backup_ram.base())}, registers_widget(RegistersWidgetConfig{page_size, 8}, std::bind(&DebugPmemView::registers_widget_feed, this, std::placeholders::_1)) {
static_assert(sizeof(pmem_data) == memory::map::backup_ram.size());

add_children({&text_page, &registers_widget, &text_checksum, &button_ok});
add_children({&text_page, &registers_widget, &text_checksum, &text_checksum2, &button_ok});

registers_widget.set_parent_rect({0, 32, 240, 192});

text_checksum.set("Size: " + to_string_dec_uint(portapack::persistent_memory::data_size()) + " CRC: " + to_string_hex(data.check_value, 8));
text_checksum.set("Size: " + to_string_dec_uint(portapack::persistent_memory::data_size(), 3) + " CRC: " + to_string_hex(data.check_value, 8));
text_checksum2.set("Calculated CRC: " + to_string_hex(pmem_checksum(data.regfile), 8));

button_ok.on_select = [&nav](Button&) {
nav.pop();
Expand Down
7 changes: 4 additions & 3 deletions firmware/application/apps/ui_debug.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ class DebugPmemView : public View {
DebugPmemView(NavigationView& nav);
void focus() override;
bool on_encoder(const EncoderEvent delta) override;
std::string title() const override { return "Pmem"; }
std::string title() const override { return "p.mem"; }

private:
struct pmem_data {
Expand All @@ -282,13 +282,14 @@ class DebugPmemView : public View {

int32_t page{0};

const pmem_data& data;
volatile const pmem_data& data;

Text text_page{{16, 16, 208, 16}};

RegistersWidget registers_widget;

Text text_checksum{{16, 240, 208, 16}};
Text text_checksum{{16, 232, 208, 16}};
Text text_checksum2{{16, 248, 208, 16}};

Button button_ok{
{240 / 3, 270, 240 / 3, 24},
Expand Down
4 changes: 2 additions & 2 deletions firmware/common/portapack_persistent_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,8 @@ struct data_t {

struct backup_ram_t {
private:
uint32_t regfile[63];
uint32_t check_value;
volatile uint32_t regfile[63];
volatile uint32_t check_value;

static void copy(const backup_ram_t& src, backup_ram_t& dst) {
for (size_t i = 0; i < 63; i++) {
Expand Down

0 comments on commit b9de191

Please sign in to comment.