-
Notifications
You must be signed in to change notification settings - Fork 3k
Replace macros in MbedTester to avoid conflicts #14076
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
Conversation
@gpsimenos, thank you for your changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes the problem but the other can come in. Shall we fix all these defines that are anyway local?
Let's use unnamed namespace and change to lowercase.
namespace {
const auto local_variable = 0x1;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should have requested changes rather than comment. Please review and lets fix all of these local variables, not just one.
@gpsimenos please add a proper description to the header 'This fixes issue #12675.' is insufficient. Description should contain a summary of the problem and how it has been fixed. |
42de04d
to
118e146
Compare
Changes pushed and description/title updated. |
Ping @0xc0170 |
CI started |
@0xc0170 IMHO the UPPERCASE makes it more obvious that those are constants defined somewhere. When you read code like that you won't spot them: MbedTester::MbedTester(const PinList *form_factor, const PinList *exclude_pins)
: _form_factor(form_factor), _exclude_pins(exclude_pins), _control_auto(true), _control_valid(false),
_clk_index(physical_nc), _mosi_index(physical_nc), _miso_index(physical_nc), _aux_index(physical_nc),
_clk(NULL), _mosi(NULL), _miso(NULL), _aux(NULL)
{
// or
if (flash.read(buf, start + offset, length_size) != BD_ERROR_OK) {
sys_pin_mode_disabled();
return false;
}
if (dest->write(buf, length_size) != length_size) {
sys_pin_mode_disabled();
return false;
}
offset += length_size;
uint32_t data_size = (buf[0] << (0 * 8)) |
(buf[1] << (1 * 8)) |
(buf[2] << (2 * 8)) |
(buf[3] << (3 * 8));
if (data_size > firmware_region_size - length_size - crc_size_const) {
data_size = firmware_region_size - length_size - crc_size_const;
}
const uint32_t firmware_size = data_size + length_size + crc_size_const; |
const auto firmware_size_const = 2192012; | ||
const auto firmware_region_size = 0x220000; | ||
const auto firmware_header_size = 0x10000; | ||
const auto flash_sector_size = 0x1000; | ||
const auto length_size = 0x4; | ||
const auto crc_size_const = 0x4; | ||
const auto flash_spi_freq_hz = 2000000; | ||
const auto analog_count = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some variables end with _const
some others don't.
I think UPPERCASE makes it more obvious that those are constants.
const auto firmware_size_const = 2192012; | |
const auto firmware_region_size = 0x220000; | |
const auto firmware_header_size = 0x10000; | |
const auto flash_sector_size = 0x1000; | |
const auto length_size = 0x4; | |
const auto crc_size_const = 0x4; | |
const auto flash_spi_freq_hz = 2000000; | |
const auto analog_count = 4; | |
const auto FIRMWARE_SIZE = 2192012; | |
const auto FIRMWARE_REGION_SIZE = 0x220000; | |
const auto FIRMWARE_HEADER_SIZE = 0x10000; | |
const auto FLASH_SECTOR_SIZE = 0x1000; | |
const auto LENGTH_SIZE = 0x4; | |
const auto CRC_SIZE = 0x4; | |
const auto FLASH_SPI_FREQ_HZ = 2000000; | |
const auto ANALOG_COUNT = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are variables with internal linkage, uppercase would allow them to clash with the preprocessor and would rather indicate they are macros with external linkage - a reason this PR was proposed is to avoid this.
_const
shoud be removed, I'll mark that in the review request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about the k
prefix? or use a named namespace namespace MbedTesterConst {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file has other sort of inconsistencies. Around line 460 lies global static const arrays in full CAPS.
Moving them all to an MbedTesterConst
namespace seems sensible to me.
Lowercase name to avoid clash with preprocessor in a namespace explicit about what those values are is IMHO a good compromise.
I would also recommend to move the magic value for PhysicalIndex to the header file as this is where the type is publicly visible.
Jenkins CI Test : ✔️ SUCCESSBuild Number: 1 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
namespace { | ||
const auto physical_pins = 128; | ||
const auto logical_pins = 8; | ||
const auto firmware_size_const = 2192012; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets remove _const suffix from variables here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
features/frameworks/COMPONENT_FPGA_CI_TEST_SHIELD/source/MbedTester.cpp
Outdated
Show resolved
Hide resolved
Co-authored-by: Ladislas de Toldi <[email protected]>
@0xc0170 Let's CI 😃 |
C istarted |
Jenkins CI Test : ❌ FAILEDBuild Number: 2 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Looks like there's currently some CI instability? The below errors appear in multiple builds:
|
CI restarted |
Jenkins CI Test : ❌ FAILEDBuild Number: 3 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
@0xc0170 unstable network? |
Yes, at least 2-3 jobs I found today failed the same way, restarting now |
CI restarted |
Jenkins CI Test : ✔️ SUCCESSBuild Number: 5 | 🔒 Jenkins CI Job | 🌐 Logs & ArtifactsCLICK for Detailed Summary
|
Summary of changes
This PR replaces macros in MbedTester with regular constant variables in an unnamed namespace, to avoid conflicts with macros defined elsewhere (e.g. in targets).
Impact of changes
Migration actions required
Documentation
Pull request type
Test results
Reviewers