Skip to content

Commit

Permalink
[attribute storage] prevent unneeded pointer footprint in static-only…
Browse files Browse the repository at this point in the history
… case

If CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT is zero, no dynamic endpoints can exist
so we don't need the per-dynamic-endpoint storage pointer (which slightly increases
footprint)
  • Loading branch information
plan44 committed Aug 13, 2023
1 parent 005f6ec commit 4eb71f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/app/util/af-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,15 @@ struct EmberAfDefinedEndpoint
*/
chip::DataVersion * dataVersions = nullptr;

#if CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT > 0
/**
* Pointer to the memory block to be used for automatic attribute storage if
* this is a dynamic endpoint. If set, the memory block pointed at
* must have a size equal to endpointType->endpointSize (which is
* the sum of all endpointType->clusters[*].clustersize).
*/
uint8_t * dynamicAttributeStorage = nullptr;
#endif

/**
* Root endpoint id for composed device type.
Expand Down
24 changes: 18 additions & 6 deletions src/app/util/attribute-storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const Emb
emAfEndpoints[index].dataVersions = dataVersionStorage.data();
// Start the endpoint off as disabled.
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isEnabled);
emAfEndpoints[index].parentEndpointId = parentEndpointId;
emAfEndpoints[index].parentEndpointId = parentEndpointId;
#if CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT > 0
emAfEndpoints[index].dynamicAttributeStorage = dynamicAttributeStorage;
#endif

emberAfSetDynamicEndpointCount(MAX_ENDPOINT_COUNT - FIXED_ENDPOINT_COUNT);

Expand All @@ -325,6 +327,7 @@ EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const Emb
}
}

#if CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT > 0
if (dynamicAttributeStorage != nullptr && ep->endpointSize > 0)
{
// Flag the endpoint as enabled here, because otherwise loading attributes cannot work
Expand All @@ -334,7 +337,7 @@ EmberAfStatus emberAfSetDynamicEndpoint(uint16_t index, EndpointId id, const Emb
// set disabled again, so enabling below will detect a transition
emAfEndpoints[index].bitmask.Clear(EmberAfEndpointOptions::isEnabled);
}
//
#endif

// Now enable the endpoint.
emberAfEndpointEnableDisable(id, true);
Expand Down Expand Up @@ -643,6 +646,7 @@ EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord,
continue;
}

#if CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT > 0
bool hasDynamicAttributeStorage = emAfEndpoints[ep].dynamicAttributeStorage != nullptr;
if (hasDynamicAttributeStorage)
{
Expand All @@ -651,6 +655,7 @@ EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord,
// Endpoint processing starts here, so reset the offset.
attributeStorageOffset = 0;
}
#endif

for (clusterIndex = 0; clusterIndex < endpointType->clusterCount; clusterIndex++)
{
Expand All @@ -677,9 +682,12 @@ EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord,
uint8_t * attributeLocation =
(am->mask & ATTRIBUTE_MASK_SINGLETON
? singletonAttributeLocation(am)
: (hasDynamicAttributeStorage ? emAfEndpoints[ep].dynamicAttributeStorage
: attributeData) +
attributeStorageOffset);
#if CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT > 0
: (hasDynamicAttributeStorage ? emAfEndpoints[ep].dynamicAttributeStorage : attributeData)
#else
: attributeData
#endif
+ attributeStorageOffset);

uint8_t *src, *dst;
if (write)
Expand Down Expand Up @@ -720,7 +728,11 @@ EmberAfStatus emAfReadOrWriteAttribute(EmberAfAttributeSearchRecord * attRecord,

// Internal storage is only supported for fixed endpoints
// and dynamic ones with dynamicAttributeStorage assigned.
if (!isDynamicEndpoint || hasDynamicAttributeStorage)
if (!isDynamicEndpoint
#if CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT > 0
|| hasDynamicAttributeStorage
#endif
)
{
return typeSensitiveMemCopy(attRecord->clusterId, dst, src, am, write, readLength);
}
Expand Down

0 comments on commit 4eb71f5

Please sign in to comment.