Skip to content

Commit

Permalink
Merge pull request #1381 from bitcraze/rik/otafix
Browse files Browse the repository at this point in the history
Fix multi-deck multi-memory OTA flashing
  • Loading branch information
gemenerik committed Jun 4, 2024
2 parents 46c1387 + c2b9497 commit a7c9157
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
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

0 comments on commit a7c9157

Please sign in to comment.