Skip to content

Commit

Permalink
Merge branch 'master' into bracz-magsensor
Browse files Browse the repository at this point in the history
* master:
  Fixes compilation warnings.
  Adds support for unaligned reads and writes to the TivaEEPROMFile driver. (#704)
  Removes the driverlib from the path for CC322x.mk Removes a duplicate entry from the clang-format file.
  Stores the last offset in the configuration space when generating the XML. (#693)
  • Loading branch information
balazsracz committed Apr 1, 2023
2 parents 9fe6d45 + 5c83605 commit f9cf60b
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Standard: Cpp11
IndentWidth: 4
TabWidth: 8
UseTab: Never
BreakBeforeBraces: Allman
# BreakBeforeBraces: Allman
IndentFunctionDeclarationAfterType: false
SpacesInParentheses: false
SpacesInAngles: false
Expand Down
1 change: 0 additions & 1 deletion etc/cc322x.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ ifdef TICC3220SDKPATH
INCLUDES += -DSL_PLATFORM_MULTI_THREADED -DSL_FULL -DTARGET_IS_CC3220 \
-I$(OPENMRNPATH)/src/freertos_drivers/ti \
-I$(OPENMRNPATH)/src/freertos_drivers/net_cc32xx \
-I$(TICC3220SDKPATH)/source/ti/devices/cc32xx/driverlib \
-I$(TICC3220SDKPATH)/source/ti/devices/cc32xx \
-I$(TICC3220SDKPATH)/source/ti/posix/gcc

Expand Down
82 changes: 74 additions & 8 deletions src/freertos_drivers/ti/TivaEEPROMFile.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,44 @@ public:
/// @return number of bytes written upon success, -errno upon failure
ssize_t write(unsigned int index, const void *buf, size_t len) override
{
HASSERT(index % 4 == 0);
HASSERT(len % 4 == 0);
MAP_EEPROMProgram((uint32_t *)buf, index + byteOffset_, len);
return len;
size_t count = 0;
uint8_t *b = (uint8_t *)buf;
// Partial write at the beginning.
if (index & 0x3)
{
uint32_t rd = 0;
MAP_EEPROMRead(&rd, (index + byteOffset_) & ~0x3, 4);
size_t actual_len = 4 - (index & 0x3);
actual_len = std::min(len, actual_len);
memcpy(((uint8_t*)&rd) + (index & 0x3), b, actual_len);
MAP_EEPROMProgram(&rd, (index + byteOffset_) & ~0x3, 4);
len -= actual_len;
index += actual_len;
b += actual_len;
count += actual_len;
}
// Full writes in the middle.
size_t word_len = len & ~0x3;
if (word_len)
{
HASSERT((index & 0x3) == 0);
MAP_EEPROMProgram((uint32_t *)b, index + byteOffset_, word_len);
index += word_len;
b += word_len;
len -= word_len;
count += word_len;
}
// Partial write at the end.
if (len & 0x3)
{
HASSERT((index & 0x3) == 0);
uint32_t rd = 0;
MAP_EEPROMRead(&rd, index + byteOffset_, 4);
memcpy(&rd, b, len);
MAP_EEPROMProgram(&rd, (index + byteOffset_), 4);
count += len;
}
return count;
}

/// Read from the eeprom.
Expand All @@ -88,10 +122,42 @@ public:
/// @return number of bytes read upon success, -errno upon failure
ssize_t read(unsigned int index, void *buf, size_t len) override
{
HASSERT(index % 4 == 0);
HASSERT(len % 4 == 0);
MAP_EEPROMRead((uint32_t *)buf, index + byteOffset_, len);
return len;
size_t count = 0;
uint8_t *b = (uint8_t *)buf;
// Partial read at the beginning.
if (index & 0x3)
{
uint32_t rd = 0;
MAP_EEPROMRead(&rd, (index + byteOffset_) & ~0x3, 4);
size_t actual_len = 4 - (index & 0x3);
actual_len = std::min(len, actual_len);
memcpy(b, ((uint8_t *)&rd) + (index & 0x3), actual_len);
len -= actual_len;
index += actual_len;
b += actual_len;
count += actual_len;
}
// Full reads in the middle.
size_t word_len = len & ~0x3;
if (word_len)
{
HASSERT((index & 0x3) == 0);
MAP_EEPROMRead((uint32_t *)b, index + byteOffset_, word_len);
index += word_len;
b += word_len;
len -= word_len;
count += word_len;
}
// Partial read at the end.
if (len & 0x3)
{
HASSERT((index & 0x3) == 0);
uint32_t rd = 0;
MAP_EEPROMRead(&rd, index + byteOffset_, 4);
memcpy(b, &rd, len);
count += len;
}
return count;
}

private:
Expand Down
2 changes: 2 additions & 0 deletions src/openlcb/CompileCdiMain.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ void render_cdi_helper(const CdiType &t, string ns, string name)
printf("extern const size_t %s_SIZE;\n", name.c_str());
printf("const size_t %s_SIZE = sizeof(%s_DATA);\n", name.c_str(),
name.c_str());
printf("const size_t %s_END_OFFSET = %u;\n", name.c_str(),
(unsigned)t.end_offset());
printf("\n} // namespace %s\n\n", ns.c_str());
}
}
Expand Down

0 comments on commit f9cf60b

Please sign in to comment.