Z-Stack-firmware/coordinator/Z-Stack_Home_1.2/firmware.patch

447 lines
15 KiB
Diff

From 79b43ef6bb5d3ab40e60c26f1419ba6143559d48 Mon Sep 17 00:00:00 2001
From: Koen Kanters <koenkanters94@gmail.com>
Date: Tue, 28 Jul 2020 19:39:55 +0200
Subject: [PATCH 1/1] Own changes
---
.../hal/target/CC2530ZNP/hal_board_cfg.h | 6 +-
Components/mt/MT_SYS.c | 16 +++
Components/mt/revision_info.h | 1 +
Components/stack/af/AF.c | 26 +++-
Components/stack/zdo/ZDApp.c | 10 +-
Components/stack/zdo/ZDSecMgr.c | 17 +++
Projects/zstack/ZMain/TI2530ZNP/OnBoard.c | 9 ++
.../zstack/ZNP/CC253x/Source/preinclude.h | 123 ++++++++++++++++++
Projects/zstack/ZNP/Source/znp.cfg | 4 +-
Projects/zstack/ZNP/Source/znp_app.c | 22 +++-
10 files changed, 223 insertions(+), 11 deletions(-)
create mode 100644 Components/mt/revision_info.h
create mode 100644 Projects/zstack/ZNP/CC253x/Source/preinclude.h
diff --git a/Components/hal/target/CC2530ZNP/hal_board_cfg.h b/Components/hal/target/CC2530ZNP/hal_board_cfg.h
index 0459c86..1e40362 100644
--- a/Components/hal/target/CC2530ZNP/hal_board_cfg.h
+++ b/Components/hal/target/CC2530ZNP/hal_board_cfg.h
@@ -314,7 +314,7 @@ extern unsigned char znpCfg0;
*/
/* ----------- RF-frontend Connection Initialization ---------- */
-#if defined HAL_PA_LNA || defined HAL_PA_LNA_CC2590
+#if defined HAL_PA_LNA || defined HAL_PA_LNA_CC2590 || defined HAL_PA_LNA_CC2592
extern void MAC_RfFrontendSetup(void);
#define HAL_BOARD_RF_FRONTEND_SETUP() MAC_RfFrontendSetup()
#else
@@ -343,7 +343,7 @@ extern void MAC_RfFrontendSetup(void);
#endif
/* ----------- Board Initialization ---------- */
-#if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && !defined (HAL_PA_LNA_CC2590)
+#if defined (HAL_BOARD_CC2530EB_REV17) && !defined (HAL_PA_LNA) && !defined (HAL_PA_LNA_CC2590) && !defined (HAL_PA_LNA_CC2592)
#define HAL_BOARD_INIT() st \
( \
@@ -362,7 +362,7 @@ extern void MAC_RfFrontendSetup(void);
PREFETCH_ENABLE(); \
)
-#elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || defined (HAL_PA_LNA_CC2590)
+#elif defined (HAL_BOARD_CC2530EB_REV13) || defined (HAL_PA_LNA) || defined (HAL_PA_LNA_CC2590)|| defined (HAL_PA_LNA_CC2592)
#ifdef HAL_ENABLE_WIFI_COEX_PINS
#define HAL_BOARD_ENABLE_WIFI_COEX_PINS() st \
diff --git a/Components/mt/MT_SYS.c b/Components/mt/MT_SYS.c
index 35aae57..1f8ee82 100644
--- a/Components/mt/MT_SYS.c
+++ b/Components/mt/MT_SYS.c
@@ -2141,6 +2141,21 @@ static void MT_SysSnifferParameters( uint8 *pBuf )
*****************************************************************************/
static void powerOffSoc(void)
{
+#if defined(FIRMWARE_CC2530) || defined(FIRMWARE_CC2530_CC2591) || defined(FIRMWARE_CC2530_CC2592)
+ HAL_DISABLE_INTERRUPTS();
+ STIF = 0; //HAL_SLEEP_TIMER_CLEAR_INT;
+ if (ZNP_CFG1_UART == znpCfg1)
+ {
+ HalUARTSuspend();
+ }
+
+ /* Prep CC2530 power mode */
+ //HAL_SLEEP_PREP_POWER_MODE(3);
+ SLEEPCMD &= ~PMODE; /* clear mode bits */
+ SLEEPCMD |= 3; /* set mode bits to PM3 */
+ while (!(STLOAD & LDRDY));
+ SystemReset();
+#else
HAL_DISABLE_INTERRUPTS();
/* turn off the RF front end device */
@@ -2181,6 +2196,7 @@ static void powerOffSoc(void)
PCON = halSleepPconValue;
asm("NOP");
}
+#endif
}
#endif
diff --git a/Components/mt/revision_info.h b/Components/mt/revision_info.h
new file mode 100644
index 0000000..f9343d6
--- /dev/null
+++ b/Components/mt/revision_info.h
@@ -0,0 +1 @@
+#define CODE_REVISION_NUMBER 20201128
diff --git a/Components/stack/af/AF.c b/Components/stack/af/AF.c
index c6183b6..128b194 100644
--- a/Components/stack/af/AF.c
+++ b/Components/stack/af/AF.c
@@ -372,10 +372,18 @@ void afIncomingData( aps_FrameFormat_t *aff, zAddrType_t *SrcAddress, uint16 Src
#if !defined ( APS_NO_GROUPS )
// Find the first endpoint for this group
grpEp = aps_FindGroupForEndpoint( aff->GroupID, APS_GROUPS_FIND_FIRST );
- if ( grpEp == APS_GROUPS_EP_NOT_FOUND )
- return; // No endpoint found
-
- epDesc = afFindEndPointDesc( grpEp );
+ if ( grpEp == APS_GROUPS_EP_NOT_FOUND ) {
+ // No endpoint found, default to endpoint 1.
+ // In the original source code there is a return here.
+ // This prevent the messags from being forwarded.
+ // For our use-case we want to capture all messages.
+ // Even if the coordinator is not in the group.
+ epDesc = afFindEndPointDesc( 1 );
+ }
+ else {
+ epDesc = afFindEndPointDesc( grpEp );
+ }
+
if ( epDesc == NULL )
return; // Endpoint descriptor not found
@@ -392,6 +400,12 @@ void afIncomingData( aps_FrameFormat_t *aff, zAddrType_t *SrcAddress, uint16 Src
epDesc = pList->epDesc;
}
}
+ else if ( aff->DstEndPoint == 10 || aff->DstEndPoint == 11 ) {
+ if ( (epDesc = afFindEndPointDesc( 1 )) )
+ {
+ pList = afFindEndPointDescList( epDesc->endPoint );
+ }
+ }
else if ( (epDesc = afFindEndPointDesc( aff->DstEndPoint )) )
{
pList = afFindEndPointDescList( epDesc->endPoint );
@@ -422,7 +436,9 @@ void afIncomingData( aps_FrameFormat_t *aff, zAddrType_t *SrcAddress, uint16 Src
// if the Wildcard ProfileID is received the message should not be sent to ZDO endpoint
if ( (aff->ProfileID == epProfileID) ||
((epDesc->endPoint == ZDO_EP) && (aff->ProfileID == ZDO_PROFILE_ID)) ||
- ((epDesc->endPoint != ZDO_EP) && ( aff->ProfileID == ZDO_WILDCARD_PROFILE_ID )) )
+ ((epDesc->endPoint != ZDO_EP) && ( aff->ProfileID == ZDO_WILDCARD_PROFILE_ID )) ||
+ // Fix below is to support PGC410EU: https://github.com/Koenkk/zigbee2mqtt/issues/4055
+ ((epDesc->endPoint == 2) && ( aff->ProfileID == 0xFC01 )) )
{
// Save original endpoint
uint8 endpoint = aff->DstEndPoint;
diff --git a/Components/stack/zdo/ZDApp.c b/Components/stack/zdo/ZDApp.c
index 242be04..cfad5e9 100644
--- a/Components/stack/zdo/ZDApp.c
+++ b/Components/stack/zdo/ZDApp.c
@@ -3148,6 +3148,14 @@ void ZDO_NetworkStatusCB( uint16 nwkDstAddr, uint8 statusCode, uint16 dstAddr )
// Routing error for dstAddr, this is informational and a Route
// Request should happen automatically.
}
+
+ if ( (nwkDstAddr == NLME_GetShortAddr())
+ && (statusCode == NWKSTAT_SOURCE_ROUTE_FAILURE) )
+ {
+ // Received a source route failure, remove route and rediscover.
+ RTG_RemoveRtgEntry( dstAddr, 0 );
+ NLME_RouteDiscoveryRequest( dstAddr, 0, 30 );
+ }
}
/******************************************************************************
@@ -3463,7 +3471,7 @@ void ZDApp_NVUpdate( void )
*/
uint16 ZDApp_CoordStartPANIDConflictCB( uint16 panid )
{
- return ( panid + 1 );
+ return ( panid );
}
/*********************************************************************
diff --git a/Components/stack/zdo/ZDSecMgr.c b/Components/stack/zdo/ZDSecMgr.c
index 2eacc11..a910a06 100644
--- a/Components/stack/zdo/ZDSecMgr.c
+++ b/Components/stack/zdo/ZDSecMgr.c
@@ -42,6 +42,8 @@ extern "C"
{
#endif
+#define SLEEP(_count) do {volatile uint32 count = (_count); while (count--);} while (0)
+
/******************************************************************************
* INCLUDES
*/
@@ -1114,14 +1116,22 @@ ZStatus_t ZDSecMgrDeviceJoin( ZDSecMgrDevice_t* device )
ZStatus_t status = ZSuccess;
uint16 ami;
+ // Add sleeps, see https://github.com/Koenkk/zigbee2mqtt/issues/3177
+ SLEEP(0x3E8);
+
// attempt to validate device that joined/rejoined without security
if ( device->secure == FALSE )
{
+ SLEEP(0x3E8);
status = ZDSecMgrDeviceValidate( device );
}
+
+ SLEEP(0x3E8);
if ( status == ZSuccess )
{
+ SLEEP(0x3E8);
+
// Add the device to the address manager
ZDSecMgrAddrStore( device->nwkAddr, device->extAddr, &ami );
@@ -1129,18 +1139,25 @@ ZStatus_t ZDSecMgrDeviceJoin( ZDSecMgrDevice_t* device )
if ( ( device->devStatus & DEV_SEC_INIT_STATUS ) &&
( device->secure == FALSE ) )
{
+ SLEEP(0x3E8);
//send the nwk key data to the joining device
status = ZDSecMgrSendNwkKey( device );
}
+
+ SLEEP(0x3E8);
if ( status != ZSuccess )
{
+ SLEEP(0x3E8);
ZDSecMgrAddrClear( device->extAddr );
}
}
+
+ SLEEP(0x3E8);
if ( status != ZSuccess )
{
+ SLEEP(0x3E8);
// not allowed or transport key failed, remove the device
ZDSecMgrDeviceRemove( device );
}
diff --git a/Projects/zstack/ZMain/TI2530ZNP/OnBoard.c b/Projects/zstack/ZMain/TI2530ZNP/OnBoard.c
index 7c6c77e..8265ff1 100644
--- a/Projects/zstack/ZMain/TI2530ZNP/OnBoard.c
+++ b/Projects/zstack/ZMain/TI2530ZNP/OnBoard.c
@@ -144,8 +144,17 @@ void InitBoard( uint8 level )
#if defined CC2531ZNP
znpCfg1 = ZNP_CFG1_UART;
+#elif defined FIRMWARE_CC2530_CC2591 || defined(FIRMWARE_CC2530_CC2592)
+ znpCfg1 = ZNP_CFG1_UART;
+ znpCfg0 = ZNP_CFG0_32K_OSC;
#elif defined CC2530_MK
+
+ #if defined FIRMWARE_CC2530
+ znpCfg1 = ZNP_CFG1_UART;
+ #else
znpCfg1 = ZNP_CFG1_SPI;
+ #endif
+
znpCfg0 = ZNP_CFG0_32K_OSC;
#else
znpCfg1 = P2_0;
diff --git a/Projects/zstack/ZNP/CC253x/Source/preinclude.h b/Projects/zstack/ZNP/CC253x/Source/preinclude.h
new file mode 100644
index 0000000..5ab4fd5
--- /dev/null
+++ b/Projects/zstack/ZNP/CC253x/Source/preinclude.h
@@ -0,0 +1,123 @@
+// Shared accross all firmwares
+#define ASSERT_RESET
+
+#if defined FIRMWARE_SBL
+ #define MAKE_CRC_SHDW
+#else
+ #define FAKE_CRC_SHDW
+#endif
+
+#define TC_LINKKEY_JOIN
+#define SECURE 1
+#define INCLUDE_REVISION_INFORMATION
+
+// Save memory
+#undef APS_MAX_GROUPS
+#define APS_MAX_GROUPS 1
+#undef NWK_MAX_BINDING_ENTRIES
+#define NWK_MAX_BINDING_ENTRIES 1
+
+/**
+ * Disabling MULTICAST is required in order for proper group support.
+ * If MULTICAST is not disabled, the group adress is not included in the APS header
+ */
+#define MULTICAST_ENABLED FALSE
+
+/**
+ * Reduce BCAST_DELIVERY_TIME and increase MAX_BCAST time.
+ * BCAST_DELIVERY_TIME is the length of time a broadcast message is kept in the broadcast table
+ * MAX_BCAST is the max number of messages that are in the broadcast table
+ * If e.g. BCAST_DELIVERY_TIME = 1 second and MAX_BCAST = 10; 10 broadcast messages per second can be send.
+ *
+ * Zigbee2mqtt has a fixed delay of 170ms between each command.
+ * Therefore a BCAST_DELIVERY_TIME = 20 (= 2 seconds) and MAX_BCAST = 12 allows us to send
+ * 2 / 12 = 1 group command per 166ms, which is just below the zigbee2mqtt delay.
+ * Therefore the broadcast table will never get full.
+ */
+#define BCAST_DELIVERY_TIME 20
+#undef MAX_BCAST // avoids incompatible redefinition of macro warning
+#define MAX_BCAST 12
+
+// See swra635.pdf
+#define HAL_LCD FALSE
+#define HAL_ADC FALSE
+
+/**
+ * Enable MTO routing/source routing
+ * Source routing could have issues: https://github.com/Koenkk/zigbee2mqtt/issues/1408
+ */
+#define CONCENTRATOR_ENABLE TRUE
+#define CONCENTRATOR_DISCOVERY_TIME 60
+
+#if defined SOURCE_ROUTING
+ #define CONCENTRATOR_ROUTE_CACHE TRUE
+ #define MAX_RTG_SRC_ENTRIES 40
+ #undef MAX_RTG_ENTRIES
+ #define MAX_RTG_ENTRIES 40
+ #define MAX_NEIGHBOR_ENTRIES 16
+ #define SRC_RTG_EXPIRY_TIME 0
+#else
+ #define CONCENTRATOR_ROUTE_CACHE FALSE
+ #define MAX_RTG_SRC_ENTRIES 1 // Source table is not used, reduce to minimal size
+ #undef MAX_RTG_ENTRIES
+ #define MAX_RTG_ENTRIES 30
+ #define MAX_NEIGHBOR_ENTRIES 12
+#endif
+
+// CC2531
+#if defined FIRMWARE_CC2531
+ #define CC2531ZNP
+ #if defined SOURCE_ROUTING
+ #define NWK_MAX_DEVICE_LIST 5
+ #define MAXMEMHEAP 3309
+ #else
+ #define NWK_MAX_DEVICE_LIST 20
+ #define MAXMEMHEAP 3285
+ #endif
+
+// CC2530
+#elif defined FIRMWARE_CC2530
+ #define HAL_UART_DMA_RX_MAX 128
+ #define ENABLE_MT_SYS_RESET_SHUTDOWN
+ #define ZTOOL_P1
+ #define CC2530_MK
+
+ #if defined SOURCE_ROUTING
+ #define NWK_MAX_DEVICE_LIST 5
+ #define MAXMEMHEAP 3189
+ #else
+ #define NWK_MAX_DEVICE_LIST 16
+ #define MAXMEMHEAP 3277
+ #endif
+
+// CC2530 + CC2591
+#elif defined FIRMWARE_CC2530_CC2591
+ #define ENABLE_MT_SYS_RESET_SHUTDOWN
+ #define ZTOOL_P1
+ #define HAL_UART_DMA_RX_MAX 128
+ #define HAL_PA_LNA
+
+ #if defined SOURCE_ROUTING
+ #define NWK_MAX_DEVICE_LIST 5
+ #define MAXMEMHEAP 3187
+ #else
+ #define NWK_MAX_DEVICE_LIST 16
+ #define MAXMEMHEAP 3275
+ #endif
+
+// CC2530 + CC2592
+#elif defined FIRMWARE_CC2530_CC2592
+ #define ENABLE_MT_SYS_RESET_SHUTDOWN
+ #define ZTOOL_P1
+ #define HAL_UART_DMA_RX_MAX 128
+ #define HAL_PA_LNA_CC2592
+
+ #if defined SOURCE_ROUTING
+ #define NWK_MAX_DEVICE_LIST 5
+ #define MAXMEMHEAP 3187
+ #else
+ #define NWK_MAX_DEVICE_LIST 16
+ #define MAXMEMHEAP 3275
+ #endif
+
+#endif
diff --git a/Projects/zstack/ZNP/Source/znp.cfg b/Projects/zstack/ZNP/Source/znp.cfg
index 7e524a9..d5b88a3 100644
--- a/Projects/zstack/ZNP/Source/znp.cfg
+++ b/Projects/zstack/ZNP/Source/znp.cfg
@@ -101,4 +101,6 @@
-DMT_ZDO_EXTENSIONS
/* MT_APP interface - useful when ZAP defines ZAP_ZNP_MT for MT_SYS_APP_MSG pass-through. */
--DMT_APP_FUNC
\ No newline at end of file
+-DMT_APP_FUNC
+
+--preinclude=preinclude.h
\ No newline at end of file
diff --git a/Projects/zstack/ZNP/Source/znp_app.c b/Projects/zstack/ZNP/Source/znp_app.c
index 470ff12..e42ac65 100644
--- a/Projects/zstack/ZNP/Source/znp_app.c
+++ b/Projects/zstack/ZNP/Source/znp_app.c
@@ -390,12 +390,23 @@ static void npInit(void)
halUARTCfg_t uartConfig;
uartConfig.configured = TRUE;
+
+#if defined(FIRMWARE_CC2530) || defined(FIRMWARE_CC2530_CC2591) || defined(FIRMWARE_CC2530_CC2592)
+ uartConfig.baudRate = HAL_UART_BR_115200;
+#else
uartConfig.baudRate = ZNP_UART_BAUD;
-#ifdef ZNP_ALT
+#endif
+
+#if defined(FIRMWARE_CC2530) || defined(FIRMWARE_CC2530_CC2591) || defined(FIRMWARE_CC2530_CC2592)
uartConfig.flowControl = FALSE;
#else
+ #ifdef ZNP_ALT
+ uartConfig.flowControl = FALSE;
+ #else
uartConfig.flowControl = TRUE;
+ #endif
#endif
+
uartConfig.flowControlThreshold = HAL_UART_FLOW_THRESHOLD;
uartConfig.rx.maxBufSize = HAL_UART_RX_BUF_SIZE;
uartConfig.tx.maxBufSize = HAL_UART_TX_BUF_SIZE;
@@ -404,6 +415,15 @@ static void npInit(void)
uartConfig.callBackFunc = npUartCback;
HalUARTOpen(HAL_UART_PORT, &uartConfig);
MT_UartRegisterTaskID(znpTaskId);
+
+#if defined FIRMWARE_CC2530_CC2591 || defined(FIRMWARE_CC2530_CC2592)
+ //Add TX Setting
+ #if defined HAL_PA_LNA || defined HAL_PA_LNA_CC2592
+ ZMacSetTransmitPower(TX_PWR_PLUS_19);
+ #else
+ ZMacSetTransmitPower(TX_PWR_PLUS_4);
+ #endif
+#endif
}
else
{
--
2.18.0.windows.1