-
Notifications
You must be signed in to change notification settings - Fork 66
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
Get rid of fixed device numbers #253
Conversation
Firmware for this pull request: |
OK, I had to look back at ancient history to dust off some old discussions. |
src/Config.cpp
Outdated
switch (command) { | ||
case kTypeButton: | ||
numberButtons++; | ||
copy_success = readEndCommandFromEEPROM(&addreeprom); // check EEPROM until end of name |
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 statement occurs identical for each and every "case"; maybe better put just one instance at the end
src/Config.cpp
Outdated
// go through the EEPROM and calculate the number of devices for each type | ||
do // go through the EEPROM until it is NULL terminated | ||
{ | ||
switch (command) { |
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.
The "switch" could probably be avoided by placing the counter in an array indexed with the command
value (as long as the kTypeXxxxx
values are reasonably not sparse.
The whole case could disappear in something like numberDevice[command]++;
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.
The kTypeXxxxx
values are not perfect for an array due to the deprecated devices, but it makes still sense.
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.
The
kTypeXxxxx
values are not perfect for an array due to the deprecated devices, but it makes still sense.
Exactly; however, each "useless" element would only cost 1 byte of RAM, while the total flash gain could be more interesting (still to be verified).
Up to now it is also not perfectly done. We have assumptions what could fit into the device buffer, but never checked all combinations of possible devices if they will fit into the device buffer. Therefore we send the At least this message must be kept, but I was also thinking about to calculate the remaining space in the device buffer on the connector side like you mentioned. Each device type has a fixed size which is required in the device buffer, the size of the device buffer could be part of the json file. One exception is the upcoming custom device. In this case the size is unknown which could lead to report the size within the json file (and due to this for all devices?) I am still searching where the huge memory of all device index arrays is gone to. The proMicro has in sum 70 devices of 11 different types. The saving should be (70-11)*8=472bytes*, but the compiler reports only ~70bytes. Thanks a lot for your comments and a nice vacation! *each array entry for the device index arrays needs 8 bytes, for all devices one pointer of this size still required |
Just a vague idea: maybe the connector could send a message when adding (or removing) a device, during configuration (before saving it to the board), to which the board could return the required storage size increment/decrement. (Adding "no device" would return the occupation level for the currently saved configuration). Then the connector could show the updated prospect memory occupation (possibly in %).
That is something I'm also curious to investigate. Have you already tried using the memory analysis ("Inspect") function of PlatformIO? |
I tried this, but unfortunately the inspection aborts due to a failure (have to check at home which one). I had this a couple of times also on other projects. |
This could be a way. Since the same memory for devices is available it should be no problem for existing configurations (not to say it's not required). Maybe a worst case calculation with considering the available pins and the most consuming device might help |
Made again the failure to trust hovering about sizeof(). Sometimes it reports wrong values. A pointer is 2 byte instead of 8byte. So the formula must be (70-11)*2bytes = 118 bytes which should be saved. Compared this to 76bytes saving makes much more sense. 42 bytes less saving for the new functions seems reasonable... |
src/config.h
Outdated
@@ -23,6 +23,8 @@ enum { | |||
kTypeMuxDriver, // 13 Multiplexer selector support (generates select outputs) | |||
kTypeDigInMux, // 14 Digital input multiplexer support (example: 74HCT4067, 74HCT4051) | |||
kTypeStepper // new stepper type with settings for backlash and deactivate output | |||
// if new device types are added, change 'kTypeStepper' for the array numberDevices[] in readConfig() to the new one!! |
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.
Suggestion: add a last entry like this (comments removed for clarity)
// ...
kTypeDigInMux,
kTypeStepper,
// Add new devices here,
kTypeMAXCOUNT
and use that value for the array size in getArraysizes()
. This way no manual update will be required when adding devices.
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.
Again a very good idea!
Yes, that's an important thing to know. During development, whenever possible, I usually write a section of debug code like this: void report(void)
{
sprintf(sbuf, "Size of %s: %d bytes\n\r", "MyClass1", sizeof(MyClass1) ); Serial.println(sbuf);
sprintf(sbuf, "Size of %s: %d bytes\n\r", "MyType2", sizeof(MyType2) ); Serial.println(sbuf);
//...
} so as to have the actual running code report the relevant sizes once and for all. |
Firmware for this pull request: |
According the below calculations for the device buffer w/o fixed device numbers the limitations are coming from the max. pins which are availabe (except for the Nano/Uno) if the device buffer will be increased for the Mega and ProMicro. For the Mega it's no problem, he has plenty of available RAM. For the ProMicro we could benefit from the RAM saving (with spending additional 3 bytes). This would mean that we stay with the definition of max. devices within each board.json file. It is also still sensefull to limit the max. input (and output?) devices per type to considere the processing time. In this case an online check of the RAM usage of the device buffer is not required, either on the connector side nor on the FW side. Or we are just using the existing message, that the device buffer is filled and no more device could be added. This will only happpen for the Nano/Uno. Here also an online check of the RAM usage of the device buffer is not required, either on the connector side nor on the FW side. "Problems" with the processing time due to too much input (output?) devices would be in the responsibility of the user. Hints who many devices per type should not be exceeded should be done. In this case no limitation in the board.json files are required. However, more than these changes would not be required as no communication with the connector is required (except the existing warning which might be required for the Nano/Uno). Required device memory for AVR's
Required bytes per pin per device
Mega: required bytes in device buffer actually:
required bytes in device buffer w/o fixed device numbers:
Nano/Uno: required bytes in device buffer actually:
required bytes in device buffer w/o fixed device numbers:
ProMicro: required bytes in device buffer actually:
required bytes in device buffer w/o fixed device numbers:
Raspberry Pico: required bytes in device buffer actually, does not change for w&o fixed device numbers:
Limitations for max. devices are
|
This reverts commit 27abcd9.
Firmware for this pull request: |
Firmware for this pull request: |
This reverts commit 974b9a2.
Description of changes
The number of devices of each type will be calculated before the config gets loaded from the EEPROM.
With this information the device buffer gets filled up with the defined devices.
The device index array isn't needed anymore, instead a pointer to the first device of a type is stored.
fixes #174
Notes: