Skip to content

Commit

Permalink
Add Silabs ZCL8 XML implementation (project-chip#4613)
Browse files Browse the repository at this point in the history
* Add Silabs ZCL8 XML implementation

- Add silabs implementation of af-gen-event and af-tokens. Not yet
  compatible with CHIP (TODO issue project-chip#3637)

* Restyled by clang-format

* Restyled by prettier-json

* Restyled by prettier-markdown

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and austinh0 committed Feb 3, 2021
1 parent 954ba48 commit aeecfca
Show file tree
Hide file tree
Showing 42 changed files with 25,045 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/bridge-app/bridge-common/bridge-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"package": [
{
"pathRelativity": "relativeToZap",
"path": "../../../../third_party/zap/repo/zcl-builtin/silabs/zcl.json",
"path": "../../../../src/app/zap-templates/zcl/data-model/silabs/zcl.json",
"version": "ZCL Test Data",
"type": "zcl-properties"
},
Expand Down
4 changes: 2 additions & 2 deletions src/app/zap-templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Generate files in headless mode

```
cd ./third_party/zap/repo/
node src-script/zap-generate.js -z ./zcl-builtin/silabs/zcl.json -g ../../../src/app/zap-templates/app-templates.json -i <path to *.zap file> -o <Path to /gen/ folder>
node src-script/zap-generate.js -z ./zcl-builtin/silabs/zcl.json -g ../../../src/app/zap-templates/chip-templates.json -i <path to *.zap file> -o ../../../
node src-script/zap-generate.js -z ../../../../src/app/zap-templates/zcl/zcl.json -g ../../../src/app/zap-templates/app-templates.json -i <path to *.zap file> -o <Path to /gen/ folder>
node src-script/zap-generate.js -z ../../../../src/app/zap-templates/zcl/zcl.json -g ../../../src/app/zap-templates/chip-templates.json -i <path to *.zap file> -o ../../../
```

For more information please see the documentation under `docs/` in
Expand Down
85 changes: 85 additions & 0 deletions src/app/zap-templates/templates/app/af-gen-event.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{{> header}}

// #TODO : This template wasn't tested in any way with CHIP
// Might need a zap submodule update and / or other fixes to make it work.
// ISSUE : #3637


#pragma once

#define EMBER_AF_GENERATED_UC_EVENTS_DEF \
{{#user_endpoint_types}}
{{#user_clusters}}
{{#if (is_enabled enabled)}}
{{#template_options category="tick_events"}}
{{#if (is_lowercase_equal (concatenate ../name ../side) optionLabel)~}}
sl_zigbee_event_t {{optionCode}}Event{{endpoint_type_identifier ../../endpointTypeId}}; \
{{/if}}
{{/template_options}}
{{/if}}
{{/user_clusters}}
{{/user_endpoint_types}}
{{#all_user_clusters}}
{{#template_options category="generic_events"}}
{{#if (is_lowercase_equal (concatenate ../name ../side) optionLabel)~}}
sl_zigbee_event_t {{optionCode}}EndpointEvents[{{user_endpoint_count_by_cluster ../id ../side}}]; \
{{/if}}
{{/template_options}}
{{/all_user_clusters}}


#define EMBER_AF_GENERATED_UC_EVENTS_INIT \
{{#all_user_clusters}}
{{#if (is_enabled enabled)}}
{{#template_options category="tick_events"}}
{{#if (is_lowercase_equal (concatenate ../name ../side) optionLabel)~}}
extern void {{optionCode}}(uint8_t enpoint); \
{{/if}}
{{/template_options}}
{{/if}}
{{/all_user_clusters}}
{{#user_endpoint_types}}
{{#user_clusters}}
{{#if (is_enabled enabled)}}
{{#template_options category="tick_events"}}
{{#if (is_lowercase_equal (concatenate ../name ../side) optionLabel)~}}
sl_zigbee_endpoint_event_init(&{{optionCode}}Event{{endpoint_type_identifier ../../endpointTypeId}}, {{optionCode}}, {{endpoint_type_identifier ../../endpointTypeId}}); \
{{/if}}
{{/template_options}}
{{/if}}
{{/user_clusters}}
{{/user_endpoint_types}}
{{#all_user_clusters}}
{{#if (is_enabled enabled)}}
{{#template_options category="generic_events"}}
{{#if (is_lowercase_equal (concatenate ../name ../side) optionLabel)~}}
extern void {{optionCode}}EndpointEventHandler(uint8_t enpoint); \
{{/if}}
{{/template_options}}
{{/if}}
{{/all_user_clusters}}
{{#user_endpoint_types}}
{{#user_clusters}}
{{#if (is_enabled enabled)}}
{{#template_options category="generic_events"}}
{{#if (is_lowercase_equal (concatenate ../name ../side) optionLabel)~}}
sl_zigbee_endpoint_event_init(&{{optionCode}}EndpointEvents[{{endpoint_type_identifier ../../endpointTypeId}}], {{optionCode}}EndpointEventHandler, {{endpoint_type_identifier ../../endpointTypeId}}); \
{{/if}}
{{/template_options}}
{{/if}}
{{/user_clusters}}
{{/user_endpoint_types}}

// sl_zigbee_event_context_t structs used to populate the sli_zigbee_app_event_context table
#define EMBER_AF_GENERATED_UC_EVENT_CONTEXT \
{{#user_endpoint_types}}
{{#user_clusters}}
{{#if (is_enabled enabled)}}
{{#template_options category="tick_events"}}
{{#if (is_lowercase_equal (concatenate ../name ../side) optionLabel)~}}
{ {{endpoint_type_identifier ../../endpointTypeId}}, {{asHex ../code}}, {{#if (is_client ../side)}}true{{else}}false{{/if}}, EMBER_AF_LONG_POLL, EMBER_AF_OK_TO_SLEEP, &{{optionCode}}Event{{endpoint_type_identifier ../../endpointTypeId}} }, \
{{/if}}
{{/template_options}}
{{/if}}
{{/user_clusters}}
{{/user_endpoint_types}}
146 changes: 146 additions & 0 deletions src/app/zap-templates/templates/app/gen-tokens.zapt
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{{> header}}

// #TODO : This template wasn't tested in any way with CHIP
// Might need a zap submodule update and / or other fixes to make it work.
// ISSUE : #3637


#pragma once

{{#endpoint_config}}
{{#tokens_context}}

{{#each singletons}}
// Creator for attribute: {{name}}, singleton
#define CREATOR_{{define}}_SINGLETON {{asHex ../token_id 4}}
#define NVM3KEY_{{define}}_SINGLETON (NVM3KEY_DOMAIN_ZIGBEE | {{asHex ../token_id 4}})
{{token_next ..}}
{{/each}}
{{#each endpoints}}
{{#each nonSingletons}}
// Creator for attribute: {{name}}, endpoint: {{../id}}
#define CREATOR_{{define}}_{{../id}} {{asHex ../../token_id 4}}
#define NVM3KEY_{{define}}_{{../id}} (NVM3KEY_DOMAIN_ZIGBEE | {{asHex ../../token_id 4}})
{{token_next ../..}}
{{/each}}
{{/each}}

// Types for the tokens
#ifdef DEFINETYPES
{{#each singletons}}
{{#if maxLength}}
typedef uint8_t tokType_{{tokenType}}[{{maxLength}}];
{{else}}
typedef {{as_underlying_type type}} tokType_{{tokenType}};
{{/if}}
{{/each}}
{{#each nonSingletons}}
{{#if maxLength}}
typedef uint8_t tokType_{{tokenType}}[{{maxLength}}];
{{else}}
typedef {{as_underlying_type type}} tokType_{{tokenType}};
{{/if}}
{{/each}}
#endif // DEFINETYPES


#ifdef DEFINETOKENS
{{#each singletons}}
{{#if longDefault}}
DEFINE_BASIC_TOKEN({{define}}_SINGLETON, tokType_{{tokenType}}, { {{longDefault}} })
{{else}}
{{#if defaultValue}}
DEFINE_BASIC_TOKEN({{define}}_SINGLETON, tokType_{{tokenType}}, {{defaultValue}})
{{else}}
DEFINE_BASIC_TOKEN({{define}}_SINGLETON, tokType_{{tokenType}}, 0)
{{/if}}
{{/if}}
{{/each}}
{{#each endpoints}}
{{#each nonSingletons}}
{{#if longDefault}}
DEFINE_BASIC_TOKEN({{define}}_{{../id}}, tokType_{{tokenType}}, { {{longDefault}} })
{{else}}
{{#if defaultValue}}
DEFINE_BASIC_TOKEN({{define}}_{{../id}}, tokType_{{tokenType}}, {{defaultValue}})
{{else}}
DEFINE_BASIC_TOKEN({{define}}_{{../id}}, tokType_{{tokenType}}, 0)
{{/if}}
{{/if}}
{{/each}}
{{/each}}
#endif // DEFINETOKENS


// Macro snippet that loads all the attributes from tokens
#define GENERATED_TOKEN_LOADER(endpoint) do {\
{{#if hasAttributes}}
uint8_t ptr[{{maxSize}}]; \
{{/if}}
{{#if hasNonSingletons}}
uint8_t curNetwork = emberGetCurrentNetwork(); \
uint8_t epNetwork; \
{{/if}}
{{#each singletons}}
halCommonGetToken((tokType_{{tokenType}} *)ptr, TOKEN_{{define}}_SINGLETON); \
{{#if serverSide}}
emberAfWriteServerAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
{{/if}}
{{#unless serverSide}}
emberAfWriteClientAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
{{/unless}}
{{/each}}
{{#each endpoints}}
{{#if hasNonSingletons}}
epNetwork = emberAfNetworkIndexFromEndpoint({{id}}); \
if({{id}} == (endpoint) || (EMBER_BROADCAST_ENDPOINT == (endpoint) && epNetwork == curNetwork)) { \
{{#each nonSingletons}}
halCommonGetToken((tokType_{{tokenType}} *)ptr, TOKEN_{{define}}_{{../id}}); \
{{#if serverSide}}
emberAfWriteServerAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
{{/if}}
{{#unless serverSide}}
emberAfWriteClientAttribute(1, ZCL_{{as_delimited_macro cluster.name}}_CLUSTER_ID, ZCL_{{define}}_ATTRIBUTE_ID, (uint8_t*)ptr, ZCL_{{as_delimited_macro type}}_ATTRIBUTE_TYPE); \
{{/unless}}
{{/each}}
} \
{{/if}}
{{/each}}
} while(false)


// Macro snippet that saves the attribute to token
#define GENERATED_TOKEN_SAVER do { \
uint8_t allZeroData[{{maxSize}}]; \
MEMSET(allZeroData, 0, {{maxSize}}); \
if ( data == NULL ) { data = allZeroData; } \
{{#each clusters}}
{{#if hasSingletons}}
if ( {{hexCode}} == clusterId ) { \
{{#each singletons}}
if ( {{hexCode}} == metadata->attributeId && 0x0000 == emberAfGetMfgCode(metadata) && !emberAfAttributeIsClient(metadata) ) { \
halCommonSetToken(TOKEN_{{define}}_SINGLETON, data); } \
{{/each}}
} \
{{/if}}
{{/each}}
{{#each endpoints}}
{{#if hasNonSingletons}}
if ( {{id}} == endpoint ) { \
{{#each clusters}}
{{#if hasNonSingletons}}
if ( {{hexCode}} == clusterId ) { \
{{#each nonSingletons}}
if ( {{hexCode}} == metadata->attributeId && 0x0000 == emberAfGetMfgCode(metadata) && {{#if serverSide}}!{{/if}}emberAfAttributeIsClient(metadata) ) \
halCommonSetToken(TOKEN_{{define}}_{{../../id}}, data); \
{{/each}}
} \
{{/if}}
{{/each}}
} \
{{/if}}
{{/each}}
} while(false)

{{/tokens_context}}
{{/endpoint_config}}
Loading

0 comments on commit aeecfca

Please sign in to comment.