Skip to content

Commit

Permalink
Upgrade zwave_ncp_serial_api_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Aug 15, 2024
1 parent ab7b9ff commit f067adf
Show file tree
Hide file tree
Showing 8 changed files with 507 additions and 401 deletions.
756 changes: 378 additions & 378 deletions src/zwave_ncp_serial_api_controller/.cproject

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/zwave_ncp_serial_api_controller/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#endif /* ZW_CONTROLLER */
#include "AppTimer.h"
#include "ZW_system_startup_api.h"
#include "zpal_retention_register.h"
/* Include app header file - containing version and */
/* SerialAPI functionality support definitions */
#ifdef ZW_SECURITY_PROTOCOL
Expand Down Expand Up @@ -473,6 +474,9 @@ appFileSystemInit(void)
AppNodeInfo = zaf_get_app_node_info();
RadioConfig = zaf_get_radio_config();

// enable the watchdog at init of application
zpal_enable_watchdog(true);

/*
* Handle file system init inside Application Task
* This reduces the default stack needed during initialization
Expand Down Expand Up @@ -902,7 +906,21 @@ ApplicationInitSW(void)
eSerialAPIStartedCapabilities capabilities = (RadioConfig->eRegion == REGION_US_LR) ? SERIAL_API_STARTED_CAPABILITIES_L0NG_RANGE : 0;
compl_workbuf[6 + i] = capabilities;

uint32_t zpal_reset_info = 0;
if (ZPAL_STATUS_OK != zpal_retention_register_read(ZPAL_RETENTION_REGISTER_RESET_INFO, &zpal_reset_info))
{
DPRINT("ERROR while reading the reset information\n");
Request(FUNC_ID_SERIAL_API_STARTED, compl_workbuf, 7 + i);
}
else
{
compl_workbuf[7 + i] = (uint8_t)(zpal_reset_info >> 24);
compl_workbuf[8 + i] = (uint8_t)(zpal_reset_info >> 16);
compl_workbuf[9 + i] = (uint8_t)(zpal_reset_info >> 8);
compl_workbuf[10 + i] = (uint8_t)zpal_reset_info;
DPRINTF("zpal_reset_reason: %u\n", zpal_reset_info);
Request(FUNC_ID_SERIAL_API_STARTED, compl_workbuf, 11 + i);
}

#endif /* #if SUPPORT_STARTUP_NOTIFICATION */
AppTimerDeepSleepPersistentRegister(&mWakeupTimer, false, ZCB_WakeupTimeout); // register for event jobs timeout event
Expand Down
40 changes: 20 additions & 20 deletions src/zwave_ncp_serial_api_controller/cmd_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,26 +128,26 @@ ZW_ADD_CMD(FUNC_ID_GET_TX_TIMERS)

uint8_t i = 0;
// Copy with endian swap
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_0 >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_0 >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_0 >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_0 >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_1 >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_1 >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_1 >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_1 >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_2 >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_2 >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_2 >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_2 >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_3 >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_3 >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_3 >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_3 >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_4 >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_4 >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_4 >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel_4 >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[0] >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[0] >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[0] >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[0] >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[1] >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[1] >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[1] >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[1] >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[2] >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[2] >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[2] >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[2] >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[3] >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[3] >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[3] >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[3] >> 0) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[4] >> 24) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[4] >> 16) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[4] >> 8) & 0xff);
compl_workbuf[i++] = (uint8_t)((sRFStats->tx_time_channel[4] >> 0) & 0xff);

DoRespond_workbuf(i);
}
Expand Down
70 changes: 70 additions & 0 deletions src/zwave_ncp_serial_api_controller/cmds_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,31 @@
#define MAX( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) )
#endif // MAX

static const serial_api_setup_cmd_get_region_info_answer_t regions_info[] = {
{.region=REGION_EU, .zw_classic=1, .zw_lr=0, .reserved=0, .included_region=REGION_UNDEFINED},
{.region=REGION_US, .zw_classic=1, .zw_lr=0, .reserved=0, .included_region=REGION_UNDEFINED},
{.region=REGION_ANZ, .zw_classic=1, .zw_lr=0, .reserved=0, .included_region=REGION_UNDEFINED},
{.region=REGION_HK, .zw_classic=1, .zw_lr=0, .reserved=0, .included_region=REGION_UNDEFINED},
{.region=REGION_IN, .zw_classic=1, .zw_lr=0, .reserved=0, .included_region=REGION_UNDEFINED},
{.region=REGION_IL, .zw_classic=1, .zw_lr=0, .reserved=0, .included_region=REGION_UNDEFINED},
{.region=REGION_RU, .zw_classic=1, .zw_lr=0, .reserved=0, .included_region=REGION_UNDEFINED},
{.region=REGION_CN, .zw_classic=1, .zw_lr=0, .reserved=0, .included_region=REGION_UNDEFINED},
{.region=REGION_US_LR, .zw_classic=1, .zw_lr=1, .reserved=0, .included_region=REGION_US},
{.region=REGION_JP, .zw_classic=1, .zw_lr=0, .reserved=0, .included_region=REGION_UNDEFINED},
{.region=REGION_KR, .zw_classic=1, .zw_lr=0, .reserved=0, .included_region=REGION_UNDEFINED},
};
#define REGIONS_INFO_COUNT (sizeof(regions_info)/sizeof(regions_info[0]))
//default answer in case the requested region is not found in the regions_info table.
static const serial_api_setup_cmd_get_region_info_answer_t unknown_region_info =
{
.region = REGION_UNDEFINED,
.zw_classic = 0,
.zw_lr = 0,
.reserved = 0,
.included_region = 0
};
#define REGION_INFO_SIZE (sizeof(serial_api_setup_cmd_get_region_info_answer_t))

void func_id_serial_api_get_init_data(__attribute__((unused)) uint8_t inputLength,
__attribute__((unused)) const uint8_t *pInputBuffer,
uint8_t *pOutputBuffer,
Expand Down Expand Up @@ -202,6 +227,8 @@ void func_id_serial_api_setup(uint8_t inputLength,
BITMASK_ADD_CMD(supportedBitmask, SERIAL_API_SETUP_CMD_TX_GET_MAX_LR_PAYLOAD_SIZE); // (17)
BITMASK_ADD_CMD(supportedBitmask, SERIAL_API_SETUP_CMD_TX_POWERLEVEL_SET_16_BIT); // (18)
BITMASK_ADD_CMD(supportedBitmask, SERIAL_API_SETUP_CMD_TX_POWERLEVEL_GET_16_BIT); // (19)
BITMASK_ADD_CMD(supportedBitmask, SERIAL_API_SETUP_CMD_GET_SUPPORTED_REGION); // (21)
BITMASK_ADD_CMD(supportedBitmask, SERIAL_API_SETUP_CMD_GET_REGION_INFO); // (22)

/* Currently supported command with the highest value is SERIAL_API_SETUP_CMD_NODEID_BASETYPE_SET.
No commands after it. */
Expand Down Expand Up @@ -253,6 +280,49 @@ void func_id_serial_api_setup(uint8_t inputLength,
BYTE_IN_AR(pOutputBuffer, i++) = cmdRes;
break;

case SERIAL_API_SETUP_CMD_GET_SUPPORTED_REGION:
{
uint8_t supported_region_count = 0;
uint8_t region_count_index = i;
i++; //skip suported region count, move to first region value;
for (rfRegion = REGION_EU; rfRegion <= REGION_US_LR; rfRegion++) {
if (true == isRfRegionValid(rfRegion)) {
supported_region_count++;
pOutputBuffer[i] = (uint8_t) rfRegion;
i++;
}
}
for (rfRegion = REGION_JP; rfRegion <= REGION_KR; rfRegion++) {
if (true == isRfRegionValid(rfRegion)) {
supported_region_count++;
pOutputBuffer[i] = (uint8_t) rfRegion;
i++;
}
}
pOutputBuffer[region_count_index] = supported_region_count;
break;
}

case SERIAL_API_SETUP_CMD_GET_REGION_INFO:
{
uint8_t info_idx;
//search for the requested region in the regions_info table.
for (info_idx = 0; info_idx < REGIONS_INFO_COUNT; info_idx++) {
if (regions_info[info_idx].region == pInputBuffer[SAPI_SETUP_GET_REGION_INFO_RX_IDX_REGION]) {
break;
}
}
// Copy the answer in the output buffer.
if (info_idx < REGIONS_INFO_COUNT) {
memcpy(&(pOutputBuffer[i]), &(regions_info[info_idx]), REGION_INFO_SIZE);
} else {
//region not found, answer the unknown region info.
memcpy(&(pOutputBuffer[i]), &unknown_region_info, REGION_INFO_SIZE);
}
i += REGION_INFO_SIZE;
break;
}

case SERIAL_API_SETUP_CMD_TX_POWERLEVEL_SET:
{
zpal_tx_power_t iTxPower, iAdjust;
Expand Down
18 changes: 18 additions & 0 deletions src/zwave_ncp_serial_api_controller/cmds_management.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ typedef enum
SERIAL_API_SETUP_CMD_TX_GET_MAX_LR_PAYLOAD_SIZE = 17,
SERIAL_API_SETUP_CMD_TX_POWERLEVEL_SET_16_BIT = 18,
SERIAL_API_SETUP_CMD_TX_POWERLEVEL_GET_16_BIT = 19,
SERIAL_API_SETUP_CMD_GET_SUPPORTED_REGION = 21,
SERIAL_API_SETUP_CMD_GET_REGION_INFO = 22,
} eSerialAPISetupCmd;

/* SERIAL_API_SETUP_CMD_NODEID_BASETYPE_SET definitions */
Expand Down Expand Up @@ -74,6 +76,22 @@ extern eSerialAPISetupNodeIdBaseType nodeIdBaseType;
#define SERIAL_API_SETUP_CMD_NODEID_BASETYPE_SET_CMD_LENGTH_MIN 2
#define SERIAL_API_SETUP_CMD_MAX_LR_TX_PWR_SET_CMD_LENGTH_MIN 3

// --------------------------------
// Definitions related to the sub command get region info
/// Index of the region in received buffer
#define SAPI_SETUP_GET_REGION_INFO_RX_IDX_REGION (1)
/// structure used to describe the format of a get region info answer.
#pragma pack(push)
#pragma pack(1)
typedef struct {
uint8_t region;
uint8_t zw_classic:1; ///< the region supports classic Z-Wave
uint8_t zw_lr:1; ///< the region supports Z-Wave Long Range
uint8_t reserved:6; ///< reserved for future use
uint8_t included_region; ///< the selected region include this one (e.g. US_LR include US)
} serial_api_setup_cmd_get_region_info_answer_t;
#pragma pack(pop)

/**
* Must be called upon receiving a "Node List Command".
* @param inputLength Length of data in input buffer.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="ASCII"?>
<device:XMLDevice xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:device="http://www.silabs.com/ss/hwconfig/document/device.ecore" name="pin_tool.ZGM130S037HGN" partId="mcu.arm.efr32.zg13.zgm130s037hgn" contextId="com.silabs.sdk.stack.super:4.4.3._-295637086">
<device:XMLDevice xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:device="http://www.silabs.com/ss/hwconfig/document/device.ecore" name="pin_tool.ZGM130S037HGN" partId="mcu.arm.efr32.zg13.zgm130s037hgn" contextId="com.silabs.sdk.stack.super:4.4.4._-295637083">
<mode name="DefaultMode">
<property object="DBG" propertyId="ABModule.selectedRequirement" value="dbg%T%SL_DEBUG%T%sl_debug_swo_config.h"/>
<property object="DBG" propertyId="ABPeripheral.included" value="true"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ include:
- {path: utils.h}
- {path: virtual_slave_node_info.h}
- {path: zaf_config_security.h}
sdk: {id: gecko_sdk, version: 4.4.3}
sdk: {id: gecko_sdk, version: 4.4.4}
toolchain_settings: []
component:
- {id: ZGM130S037HGN}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="ASCII"?>
<model:MDescriptors xmlns:model="http://www.silabs.com/ss/Studio.ecore">
<descriptors name="zwave_ncp_serial_api_controller">
<properties key="projectCommon.sdkId" value="com.silabs.sdk.stack.super:4.4.3._-295637086"/>
<properties key="projectCommon.sdkId" value="com.silabs.sdk.stack.super:4.4.4._-295637083"/>
<properties key="universalConfig.relativeWorkspacePath" value="../zwave_ncp_serial_api_controller.slcw"/>
<properties key="universalConfig.generationDirectory" value=""/>
<properties key="universalConfig.toolchainCompatibility" value="iar gcc"/>
Expand Down

0 comments on commit f067adf

Please sign in to comment.