Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multi-deck multi-memory OTA flashing #1381

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/deck/core/deck_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ static void populateDeckMemoryInfos(uint8_t buffer[], const int deckNr) {

const DeckMemDef_t* deckMemDef = info->driver->memoryDef;
if (deckMemDef) {
uint32_t baseAddress = (deckNr + 1) * DECK_MEM_MAX_SIZE;
uint32_t baseAddress = (2 * deckNr + 1) * DECK_MEM_MAX_SIZE;
populateDeckMemoryInfoBuffer(deckMemDef, info->driver->name,
baseAddress, buffer);
}

const DeckMemDef_t* deckMemDefSecondary = info->driver->memoryDefSecondary;
if (deckMemDefSecondary) {
uint32_t baseAddress = (deckNr + 2) * DECK_MEM_MAX_SIZE;
uint32_t baseAddress = (2 * deckNr + 2) * DECK_MEM_MAX_SIZE;
populateDeckMemoryInfoBuffer(deckMemDefSecondary, info->driver->name,
baseAddress, buffer + DECK_MEMORY_INFO_SIZE);
}
Expand Down Expand Up @@ -234,7 +234,7 @@ static bool handleDeckSectionRead(const uint32_t memAddr, const uint8_t readLen,

if (deckMemDef) {
if (deckMemDef->read) {
uint32_t baseAddress = (deckNr + 1) * DECK_MEM_MAX_SIZE + selector * DECK_MEM_MAX_SIZE;
uint32_t baseAddress = (2 * deckNr + 1) * DECK_MEM_MAX_SIZE + selector * DECK_MEM_MAX_SIZE;
uint32_t deckAddress = memAddr - baseAddress;
result = deckMemDef->read(deckAddress, readLen, buffer);
}
Expand Down Expand Up @@ -295,7 +295,7 @@ static bool handleDeckSectionWrite(const uint32_t memAddr, const uint8_t writeLe

if (deckMemDef) {
if (deckMemDef->write) {
uint32_t baseAddress = (deckNr + 1) * DECK_MEM_MAX_SIZE + selector * DECK_MEM_MAX_SIZE;
uint32_t baseAddress = (deckNr * 2 + 1) * DECK_MEM_MAX_SIZE + selector * DECK_MEM_MAX_SIZE;
uint32_t deckAddress = memAddr - baseAddress;
result = deckMemDef->write(deckAddress, writeLen, buffer, deckMemDef);
}
Expand Down
40 changes: 38 additions & 2 deletions test/deck/core/test_deck_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ void testBaseAddressSecondDeckPrimary() {
deckInfo_ExpectAndReturn(0, &stockInfo);
deckInfo_ExpectAndReturn(1, &stockInfo);

uint32_t expected = DECK_MEM_MAP_SIZE * 2;
uint32_t expected = DECK_MEM_MAP_SIZE * 3;

// Test
handleMemRead(0, BUF_SIZE, buffer);
Expand All @@ -468,7 +468,7 @@ void testBaseAddressSecondDeckSecondary() {

stockDriver.memoryDefSecondary = &stockSecondaryMemDef;

uint32_t expected = DECK_MEM_MAP_SIZE * 2 + DECK_MEM_MAP_SIZE;
uint32_t expected = DECK_MEM_MAP_SIZE * 3 + DECK_MEM_MAP_SIZE;

// Test
handleMemRead(0, BUF_SIZE, buffer);
Expand Down Expand Up @@ -624,6 +624,24 @@ void testWriteToSecondaryDeckMemory() {
TEST_ASSERT_TRUE(actual);
}

void testWriteToSecondDeckPrimaryMemory() {
// // Fixture
stockPrimaryMemDef.write = mockWrite;

deckCount_ExpectAndReturn(2);
deckInfo_ExpectAndReturn(1, &stockInfo);

// Test
bool actual = handleMemWrite(DECK_MEM_MAP_SIZE * 3 + 100, 30, buffer);

// Assert
TEST_ASSERT_TRUE(write_isCalled);
TEST_ASSERT_EQUAL_UINT32(100, write_vAddr);
TEST_ASSERT_EQUAL_UINT8(30, write_len);
TEST_ASSERT_TRUE(actual);
}


void testWriteToSecondaryDeckMemoryPassesInMemDef() {
// Fixture
stockSecondaryMemDef.write = mockWrite;
Expand All @@ -639,6 +657,24 @@ void testWriteToSecondaryDeckMemoryPassesInMemDef() {
TEST_ASSERT_EQUAL_PTR(stockDriver.memoryDefSecondary, write_memDef);
}

void testWriteToSecondDeckSecondaryMemory() {
// Fixture
stockSecondaryMemDef.write = mockWrite;
stockDriver.memoryDefSecondary = &stockSecondaryMemDef;

deckCount_ExpectAndReturn(2);
deckInfo_ExpectAndReturn(1, &stockInfo);

// Test
bool actual = handleMemWrite(DECK_MEM_MAP_SIZE * 4 + 100, 30, buffer);

// Assert
TEST_ASSERT_TRUE(write_isCalled);
TEST_ASSERT_EQUAL_UINT32(100, write_vAddr);
TEST_ASSERT_EQUAL_UINT8(30, write_len);
TEST_ASSERT_TRUE(actual);
}

void testWriteToDeckWithoutWriteFunction() {
// Fixture
stockPrimaryMemDef.write = 0;
Expand Down
Loading