Skip to content
Draft
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
36 changes: 35 additions & 1 deletion src/deck/backends/deck_backend_deckctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#include "autoconf.h"
#include "i2cdev.h"
#include "deckctrl_gpio.h"

#include "mem.h"

#define DEBUG_MODULE "DECKCTRL"
#include "debug.h"
Expand Down Expand Up @@ -91,6 +91,9 @@ static const DeckDiscoveryBackend_t deckctrlBackend;
#define DECKCTRL_MEM_BOARD_REV_OFFSET 6 ///< Board revision ASCII character
#define DECKCTRL_MEM_PRODUCT_NAME_OFFSET 7 ///< Product name (null-terminated, max 14 chars)

#define DECKCTRL_CONFIG_PAGE_SIZE 2048 ///< Size of configuration memory page
#define DECKCTRL_SERIAL_SIZE 12 ///< Size of serial number stored in memory

/**
* Static storage for discovered decks
*
Expand All @@ -102,6 +105,26 @@ static char product_names[CONFIG_DECK_BACKEND_DECKCTRL_MAX_DECKS][16]; ///
static DeckCtrlContext deck_contexts[CONFIG_DECK_BACKEND_DECKCTRL_MAX_DECKS]; ///< Backend-specific contexts
static int deck_count = 0; ///< Number of decks discovered so far

static MemoryHandlerDef_t deckctrl_memory_handlers[CONFIG_DECK_BACKEND_DECKCTRL_MAX_DECKS];

static bool deckctrlMemoryRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
return i2cdevReadReg16(I2C1_DEV, deck_contexts[internal_id].i2cAddress, memAddr, readLen, buffer);
}

static bool deckctrlMemoryWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {
return i2cdevWriteReg16(I2C1_DEV, deck_contexts[internal_id].i2cAddress, memAddr, writeLen, buffer);
}

static uint32_t deckctrlMemorySize(const uint8_t internal_id) {
return DECKCTRL_CONFIG_PAGE_SIZE;
}

static bool deckctrlMemorySerialNbr(const uint8_t internal_id, const uint8_t max_length, uint8_t* buffer) {
ASSERT(max_length >= DECKCTRL_SERIAL_SIZE);
uint8_t* adj_buffer = (uint8_t*) (buffer + max_length - DECKCTRL_SERIAL_SIZE);
return i2cdevReadReg16(I2C1_DEV, deck_contexts[internal_id].i2cAddress, 0x1900, DECKCTRL_SERIAL_SIZE, buffer);
}

/**
* @brief Initialize the DeckCtrl discovery backend
*
Expand Down Expand Up @@ -242,6 +265,17 @@ static DeckInfo* deckctrl_getNextDeck(void)
deck_contexts[current_deck].i2cAddress = deck_address;
info->backendContext = &deck_contexts[current_deck];

deckctrl_memory_handlers[current_deck] = (MemoryHandlerDef_t) {
.type = MEM_TYPE_DECKCTRL,
.getSize = deckctrlMemorySize,
.read = deckctrlMemoryRead,
.write = deckctrlMemoryWrite,
.getSerialNbr = deckctrlMemorySerialNbr,
.internal_id = current_deck,
};

memoryRegisterHandler(&deckctrl_memory_handlers[current_deck]);

return info;
}

Expand Down
58 changes: 58 additions & 0 deletions src/deck/backends/deck_backend_onewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@

#include "deck_discovery.h"
#include "deck.h"
#include "mem.h"
#include "ow.h"
#include "crc32.h"
#include "cfassert.h"

#define DEBUG_MODULE "DECK_BACKEND_OW"
#include "debug.h"
Expand All @@ -49,6 +51,46 @@ static DeckInfo deckBuffer; // Buffer for returning deck info
// Dummy driver for decks that do not have a driver implemented
extern const DeckDriver dummyDriver;

#define MAX_OW_DECK_COUNT 4
static MemoryHandlerDef_t ow_memory_handlers[MAX_OW_DECK_COUNT]; // Support up to 4 OW decks

static bool owMemoryRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {

bool result = false;

if (memAddr + readLen <= OW_MAX_SIZE) {
if (owRead(internal_id, memAddr, readLen, buffer)) {
result = true;
}
}

return result;
}

static bool owMemoryWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {

bool result = false;

if (memAddr + writeLen <= OW_MAX_SIZE) {
if (owWrite(internal_id, memAddr, writeLen, buffer)) {
result = true;
}
}

return result;
}

static uint32_t owMemorySize(const uint8_t internal_id) {
return OW_MAX_SIZE;
}

bool owMemorySerialNbr(const uint8_t internal_id, const uint8_t max_length, uint8_t* buffer) {
ASSERT(max_length >= sizeof(OwSerialNum));
// Make sure we will the serial from LSB
uint8_t* adj_buffer = (uint8_t*) (buffer + max_length - sizeof(OwSerialNum));
return owGetinfo(internal_id, (OwSerialNum*) adj_buffer);
}

static bool owBackendInit(void) {
OW_BACKEND_DEBUG("Initializing OneWire backend\n");
currentDeck = 0;
Expand All @@ -63,6 +105,11 @@ static bool owBackendInit(void) {
return false;
}

if (totalDecks > MAX_OW_DECK_COUNT) {
DEBUG_PRINT("OneWire found more decks (%d) than supported (%d)\n", totalDecks, MAX_OW_DECK_COUNT);
return false;
}

OW_BACKEND_DEBUG("OneWire found %d deck(s)\n", totalDecks);
#else
OW_BACKEND_DEBUG("Ignoring all OW decks because backend is disabled.\n");
Expand Down Expand Up @@ -212,6 +259,17 @@ static DeckInfo* owBackendGetNextDeck(void) {
#endif
}

ow_memory_handlers[currentDeck] = (MemoryHandlerDef_t) {
.type = MEM_TYPE_OW,
.getSize = owMemorySize,
.read = owMemoryRead,
.write = owMemoryWrite,
.getSerialNbr = owMemorySerialNbr,
.internal_id = currentDeck,
};

memoryRegisterHandler(&ow_memory_handlers[currentDeck]);

currentDeck++;
return &deckBuffer;
}
Expand Down
10 changes: 5 additions & 5 deletions src/deck/core/deck_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@

static const uint32_t DECK_MEM_MAX_SIZE = 0x10000000;

static uint32_t handleMemGetSize(void) { return DECK_MEM_MAX_SIZE * (DECK_MAX_COUNT + 1); }
TESTABLE_STATIC bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
TESTABLE_STATIC bool handleMemWrite(const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer);
static uint32_t handleMemGetSize(const uint8_t internal_id) { return DECK_MEM_MAX_SIZE * (DECK_MAX_COUNT + 1); }
TESTABLE_STATIC bool handleMemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
TESTABLE_STATIC bool handleMemWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer);
static const MemoryHandlerDef_t memoryDef = {
.type = MEM_TYPE_DECK_MEM,
.getSize = handleMemGetSize,
Expand Down Expand Up @@ -304,7 +304,7 @@ static bool handleDeckSectionWrite(const uint32_t memAddr, const uint8_t writeLe
return result;
}

TESTABLE_STATIC bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
TESTABLE_STATIC bool handleMemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
bool result = false;
int nrOfDecks = deckCount();

Expand All @@ -324,7 +324,7 @@ TESTABLE_STATIC bool handleMemRead(const uint32_t memAddr, const uint8_t readLen
return result;
}

TESTABLE_STATIC bool handleMemWrite(const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {
TESTABLE_STATIC bool handleMemWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {
bool result = false;
int nrOfDecks = deckCount();

Expand Down
12 changes: 6 additions & 6 deletions src/deck/core/deckctrl_dfu_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ static const uint32_t DECK_CTRL_MEM_SIZE = 0x8000;
static const uint32_t DECK_CTRL_MEM_OFFSET = 0x10000;
static const uint32_t DECK_MEM_MAX_SIZE = DECK_CTRL_MEM_OFFSET + DECK_CTRL_MEM_SIZE;

static uint32_t handleMemGetSize(void) {
static uint32_t handleMemGetSize(const uint8_t internal_id) {
return DECK_MEM_MAX_SIZE;
}

bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
bool handleMemWrite(const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer);
bool handleMemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
bool handleMemWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer);

static const MemoryHandlerDef_t memoryDef = {
.type = MEM_TYPE_DECK_CTRL_DFU,
.type = MEM_TYPE_DECKCTRL_DFU,
.getSize = handleMemGetSize,
.read = handleMemRead,
.write = handleMemWrite,
Expand Down Expand Up @@ -119,7 +119,7 @@ static void enableDFUViaNRF(void * arg) {
syslinkSendPacket(&slp);
}

bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
bool handleMemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {

if (memAddr < DECK_CTRL_MEM_OFFSET) {
for (unsigned int i = 0; i < readLen; i++) {
Expand Down Expand Up @@ -148,7 +148,7 @@ bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffe
return true;
}

bool handleMemWrite(const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {
bool handleMemWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {

if (memAddr < DECK_CTRL_MEM_OFFSET) {
for (unsigned int i = 0; i < writeLen; i++) {
Expand Down
20 changes: 10 additions & 10 deletions src/deck/drivers/src/ledring12.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ static ledtimings ledringtimingsmem;
static bool isInit = false;

// Memory handler for ledringmem
static uint32_t handleLedringmemGetSize(void) { return sizeof(ledringmem); }
static bool handleLedringmemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
static bool handleLedringmemWrite(const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer);
static uint32_t handleLedringmemGetSize(const uint8_t internal_id) { return sizeof(ledringmem); }
static bool handleLedringmemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
static bool handleLedringmemWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer);
static const MemoryHandlerDef_t ledringmemDef = {
.type = MEM_TYPE_LED12,
.getSize = handleLedringmemGetSize,
Expand All @@ -85,9 +85,9 @@ static const MemoryHandlerDef_t ledringmemDef = {
};

// Memory handler for timingmem
static uint32_t handleTimingmemGetSize(void) { return sizeof(ledringtimingsmem); }
static bool handleTimingmemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
static bool handleTimingmemWrite(const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer);
static uint32_t handleTimingmemGetSize(const uint8_t internal_id) { return sizeof(ledringtimingsmem); }
static bool handleTimingmemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
static bool handleTimingmemWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer);
static const MemoryHandlerDef_t timingmemDef = {
.type = MEM_TYPE_LEDMEM,
.getSize = handleTimingmemGetSize,
Expand Down Expand Up @@ -1123,7 +1123,7 @@ static void ledring12Init(DeckInfo *info)
xTimerStart(timer, 100);
}

static bool handleLedringmemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
static bool handleLedringmemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
bool result = false;

if (memAddr + readLen <= sizeof(ledringmem)) {
Expand All @@ -1135,7 +1135,7 @@ static bool handleLedringmemRead(const uint32_t memAddr, const uint8_t readLen,
return result;
}

static bool handleLedringmemWrite(const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {
static bool handleLedringmemWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {
bool result = false;

if ((memAddr + writeLen) <= sizeof(ledringmem)) {
Expand All @@ -1146,7 +1146,7 @@ static bool handleLedringmemWrite(const uint32_t memAddr, const uint8_t writeLen
return result;
}

static bool handleTimingmemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
static bool handleTimingmemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
bool result = false;

if (memAddr + readLen <= sizeof(ledringtimingsmem.timings)) {
Expand All @@ -1158,7 +1158,7 @@ static bool handleTimingmemRead(const uint32_t memAddr, const uint8_t readLen, u
return result;
}

static bool handleTimingmemWrite(const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {
static bool handleTimingmemWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {
bool result = false;

if ((memAddr + writeLen) <= sizeof(ledringtimingsmem.timings)) {
Expand Down
6 changes: 3 additions & 3 deletions src/deck/drivers/src/locodeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ static STATS_CNT_RATE_DEFINE(spiReadCount, 1000);
#define MEM_LOCO2_ANCHOR_PAGE_SIZE 0x0100
#define MEM_LOCO2_PAGE_LEN (3 * sizeof(float) + 1)

static uint32_t handleMemGetSize(void) { return MEM_LOCO_ANCHOR_BASE + MEM_LOCO_ANCHOR_PAGE_SIZE * 256; }
static bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* dest);
static uint32_t handleMemGetSize(const uint8_t internal_id) { return MEM_LOCO_ANCHOR_BASE + MEM_LOCO_ANCHOR_PAGE_SIZE * 256; }
static bool handleMemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* dest);
static const MemoryHandlerDef_t memDef = {
.type = MEM_TYPE_LOCO2,
.getSize = handleMemGetSize,
Expand All @@ -180,7 +180,7 @@ static void rxFailedCallback(dwDevice_t * dev) {
timeout = algorithm->onEvent(dev, eventReceiveFailed);
}

static bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* dest) {
static bool handleMemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* dest) {
bool result = false;

static uint8_t unsortedAnchorList[MEM_ANCHOR_ID_LIST_LENGTH];
Expand Down
6 changes: 3 additions & 3 deletions src/deck/drivers/src/usddeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ static void usdTimer(xTimerHandle timer);
static SemaphoreHandle_t shutdownMutex;

// Handling from the memory module
static uint32_t handleMemGetSize(void) { return usddeckFileSize(); }
static bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
static uint32_t handleMemGetSize(const uint8_t internal_id) { return usddeckFileSize(); }
static bool handleMemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
static const MemoryHandlerDef_t memDef = {
.type = MEM_TYPE_USD,
.getSize = handleMemGetSize,
Expand Down Expand Up @@ -794,7 +794,7 @@ bool usddeckRead(uint32_t offset, uint8_t* buffer, uint16_t length)
return result;
}

static bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
static bool handleMemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
bool result = false;

if (memAddr + readLen <= usddeckFileSize()) {
Expand Down
10 changes: 5 additions & 5 deletions src/drivers/src/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
static bool eepromTestWriteRead(void);
#endif

static uint32_t handleMemGetSize(void) { return EEPROM_SIZE; }
static bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
static bool handleMemWrite(const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer);
static uint32_t handleMemGetSize(const uint8_t internal_id) { return EEPROM_SIZE; }
static bool handleMemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer);
static bool handleMemWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer);
static const MemoryHandlerDef_t memDef = {
.type = MEM_TYPE_EEPROM,
.getSize = handleMemGetSize,
Expand Down Expand Up @@ -211,7 +211,7 @@ bool eepromWritePage(uint8_t* buffer, uint16_t writeAddr)
return false;
}

static bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
static bool handleMemRead(const uint8_t internal_id, const uint32_t memAddr, const uint8_t readLen, uint8_t* buffer) {
bool result = false;

if (memAddr + readLen <= EEPROM_SIZE) {
Expand All @@ -223,7 +223,7 @@ static bool handleMemRead(const uint32_t memAddr, const uint8_t readLen, uint8_t
return result;
}

static bool handleMemWrite(const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {
static bool handleMemWrite(const uint8_t internal_id, const uint32_t memAddr, const uint8_t writeLen, const uint8_t* buffer) {
bool result = false;

if (memAddr + writeLen <= EEPROM_SIZE) {
Expand Down
3 changes: 0 additions & 3 deletions src/hal/interface/ow.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ typedef struct owSerialNum_s
} OwSerialNum;

void owInit();
bool owTest();
void owCommonInit();
bool owCommonTest();
void owSyslinkReceive(SyslinkPacket *slp);
bool owScan(uint8_t *nMem);
bool owGetinfo(uint8_t selectMem, OwSerialNum *serialNum);
Expand Down
1 change: 0 additions & 1 deletion src/hal/src/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ obj-y += amg8833.o
obj-y += buzzer.o
obj-y += freeRTOSdebug.o
obj-y += ledseq.o
obj-y += ow_common.o
obj-y += ow_syslink.o
obj-y += pca9555.o
obj-y += pca95x4.o
Expand Down
Loading
Loading