Skip to content

Commit

Permalink
Refactor TL
Browse files Browse the repository at this point in the history
  • Loading branch information
nurikk committed Aug 8, 2020
1 parent 198e542 commit b323f03
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 101 deletions.
14 changes: 10 additions & 4 deletions CC2530DB/GenericApp.ewp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
</option>
<option>
<name>General Xdata Stack Size</name>
<state>0x380</state>
<state>0x500</state>
</option>
<option>
<name>General Ext Stack Size</name>
Expand Down Expand Up @@ -306,6 +306,7 @@
<option>
<name>CCDefines</name>
<state>HAL_BOARD_CHDTECH_DEV</state>
<state>FREEPAD_ENABLE_TL</state>
</option>
<option>
<name>CCPreprocFile</name>
Expand Down Expand Up @@ -1315,7 +1316,7 @@
</option>
<option>
<name>General Xdata Stack Size</name>
<state>0x380</state>
<state>0x500</state>
</option>
<option>
<name>General Ext Stack Size</name>
Expand Down Expand Up @@ -1446,6 +1447,7 @@
<option>
<name>CCDefines</name>
<state>HAL_BOARD_FREEPAD</state>
<state>BDB_REPORTING</state>
</option>
<option>
<name>CCPreprocFile</name>
Expand Down Expand Up @@ -3728,7 +3730,6 @@
<name>CCDefines</name>
<state>HAL_BOARD_FREEPAD</state>
<state>FREEPAD_ENABLE_TL</state>
<state>BDB_REPORTING=TRUE</state>
</option>
<option>
<name>CCPreprocFile</name>
Expand Down Expand Up @@ -4869,7 +4870,6 @@
<option>
<name>CCDefines</name>
<state>HAL_BOARD_FREEPAD</state>
<state>BDB_REPORTING=TRUE</state>
</option>
<option>
<name>CCPreprocFile</name>
Expand Down Expand Up @@ -6303,6 +6303,12 @@
<file>
<name>$PROJ_DIR$\..\zstack-lib\hal_key.h</name>
</file>
<file>
<name>$PROJ_DIR$\..\zstack-lib\tl_resetter.c</name>
</file>
<file>
<name>$PROJ_DIR$\..\zstack-lib\tl_resetter.h</name>
</file>
<file>
<name>$PROJ_DIR$\..\zstack-lib\utils.c</name>
</file>
Expand Down
24 changes: 16 additions & 8 deletions Source/OSAL_FreePadApp.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,35 @@
#ifdef FREEPAD_ENABLE_TL
#include "bdb_touchlink_initiator.h"
#include "stub_aps.h"
#include "tl_resetter.h"
#endif

#include "zcl_freepadapp.h"
#include "Debug.h"
#include "battery.h"
#include "commissioning.h"
#include "factory_reset.h"
#include "battery.h"
#include "Debug.h"
#include "zcl_freepadapp.h"

const pTaskEventHandlerFn tasksArr[] = {macEventLoop,
nwk_event_loop,
Hal_ProcessEvent,
APS_event_loop,
ZDApp_event_loop,
zcl_event_loop,
#ifdef FREEPAD_ENABLE_TL
#ifdef FREEPAD_ENABLE_TL
StubAPS_ProcessEvent,
touchLinkInitiator_event_loop,
#endif
#endif
bdb_event_loop,
zclFreePadApp_event_loop,
zclCommissioning_event_loop,
zclFactoryResetter_loop,
zclBattery_event_loop
};
#ifdef FREEPAD_ENABLE_TL
,
zclTouchLinkRestter_event_loop
#endif
};

const uint8 tasksCnt = sizeof(tasksArr) / sizeof(tasksArr[0]);
uint16 *tasksEvents;
Expand All @@ -52,15 +57,18 @@ void osalInitTasks(void) {
APS_Init(taskID++);
ZDApp_Init(taskID++);
zcl_Init(taskID++);
#ifdef FREEPAD_ENABLE_TL
#ifdef FREEPAD_ENABLE_TL
StubAPS_Init(taskID++);
touchLinkInitiator_Init(taskID++);
#endif
#endif
bdb_Init(taskID++);
zclFreePadApp_Init(taskID++);
zclCommissioning_Init(taskID++);
zclFactoryResetter_Init(taskID++);
zclBattery_Init(taskID++);
#ifdef FREEPAD_ENABLE_TL
zclTouchLinkRestter_Init(taskID++);
#endif
}

/*********************************************************************
Expand Down
6 changes: 3 additions & 3 deletions Source/f8wConfig.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
//-DDEFAULT_CHANLIST=0x00004000 // 14 - 0x0E
//-DDEFAULT_CHANLIST=0x00002000 // 13 - 0x0D
//-DDEFAULT_CHANLIST=0x00001000 // 12 - 0x0C
-DDEFAULT_CHANLIST=0x07FFF800 // 11 - 0x0B
-DDEFAULT_CHANLIST=0x07FFF800 // all

/* Define the default PAN ID.
*
Expand Down Expand Up @@ -122,15 +122,15 @@
-DMAX_BCAST=9

/* The maximum number of groups in the groups table */
-DAPS_MAX_GROUPS=16
-DAPS_MAX_GROUPS=1

/* Number of entries in the regular routing table plus additional
* entries for route repair
*/
-DMAX_RTG_ENTRIES=40

/* Maximum number of entries in the Binding table. */
-DNWK_MAX_BINDING_ENTRIES=4
-DNWK_MAX_BINDING_ENTRIES=40

/* Maximum number of cluster IDs for each binding table entry.
* Note that any value other than the default value may cause a
Expand Down
63 changes: 24 additions & 39 deletions Source/preinclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,65 +45,50 @@
// #define HAL_BOARD_CHDTECH_DEV

#if !defined(HAL_BOARD_FREEPAD) && !defined(HAL_BOARD_CHDTECH_DEV)
#error "Board type must be defined"
#error "Board type must be defined"
#endif

#ifdef HAL_BOARD_FREEPAD
#define FREEPAD_BUTTONS_COUNT 20
#elif defined(HAL_BOARD_CHDTECH_DEV)
#define FREEPAD_BUTTONS_COUNT 2
#endif
#define INT_HEAP_LEN 3000

#ifdef NWK_MAX_BINDING_ENTRIES
#undef NWK_MAX_BINDING_ENTRIES
#endif
#define NWK_MAX_BINDING_ENTRIES MAX(10, ((2 * FREEPAD_BUTTONS_COUNT)))

#undef APS_MAX_GROUPS
#define APS_MAX_GROUPS 1
#define FREEPAD_BUTTONS_COUNT 20

#if defined(HAL_BOARD_FREEPAD)
#define POWER_SAVING
#define POWER_SAVING
#endif


#if defined(HAL_BOARD_CHDTECH_DEV)
#define DO_DEBUG_UART
// #define DO_DEBUG_UART
// #define OSALMEM_METRICS TRUE
#endif

#ifdef DO_DEBUG_UART
#define HAL_UART TRUE
#define HAL_UART_DMA 1
#define INT_HEAP_LEN (2685 - 0x4B - 0xBB)
#define HAL_UART TRUE
#define HAL_UART_DMA 1
#define INT_HEAP_LEN 2197
#endif

#ifdef DO_DEBUG_MT
#define HAL_UART TRUE
#define HAL_UART_DMA 1
#define HAL_UART_ISR 2
#define INT_HEAP_LEN (2688-0xC4-0x15-0x44-0x20-0x1E)
#define HAL_UART TRUE
#define HAL_UART_DMA 1
#define HAL_UART_ISR 2
#define INT_HEAP_LEN (2688-0xC4-0x15-0x44-0x20-0x1E)

#define MT_TASK
#define MT_TASK

#define MT_UTIL_FUNC
#define MT_UART_DEFAULT_BAUDRATE HAL_UART_BR_115200
#define MT_UART_DEFAULT_OVERFLOW FALSE
#define MT_UTIL_FUNC
#define MT_UART_DEFAULT_BAUDRATE HAL_UART_BR_115200
#define MT_UART_DEFAULT_OVERFLOW FALSE

#define ZTOOL_P1

#define MT_APP_FUNC
#define MT_APP_CNF_FUNC
#define MT_SYS_FUNC
#define MT_ZDO_FUNC
#define MT_ZDO_MGMT
#define MT_DEBUG_FUNC
#define ZTOOL_P1

#define MT_APP_FUNC
#define MT_APP_CNF_FUNC
#define MT_SYS_FUNC
#define MT_ZDO_FUNC
#define MT_ZDO_MGMT
#define MT_DEBUG_FUNC
#endif



#ifndef INT_HEAP_LEN
#define INT_HEAP_LEN 2900
#endif

#include "hal_board_cfg.h"
54 changes: 10 additions & 44 deletions Source/zcl_freepadapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@

#include "bdb.h"
#include "bdb_interface.h"
#ifdef FREEPAD_ENABLE_TL
#include "bdb_touchlink.h"
#include "bdb_touchlink_initiator.h"
#endif

#include "Debug.h"
#include "commissioning.h"
#include "factory_reset.h"
#include "onboard.h"
#include "tl_resetter.h"

/* HAL */
#include "hal_drivers.h"
Expand Down Expand Up @@ -81,10 +78,6 @@ static void zclFreePadApp_BasicResetCB(void);
static ZStatus_t zclFreePadApp_ReadWriteAuthCB(afAddrType_t *srcAddr, zclAttrRec_t *pAttr, uint8 oper);
static void zclFreePadApp_SaveAttributesToNV(void);
static void zclFreePadApp_RestoreAttributesFromNV(void);
#ifdef FREEPAD_ENABLE_TL
static void zclFreePadApp_StartTL(void);
ZStatus_t zclFreePadApp_TL_NotifyCb(epInfoRec_t *pData);
#endif
/*********************************************************************
* ZCL General Profile Callback table
*/
Expand Down Expand Up @@ -142,10 +135,6 @@ void zclFreePadApp_Init(byte task_id) {
// Register for all key events - This app will handle all key events
RegisterForKeys(zclFreePadApp_TaskID);

#ifdef FREEPAD_ENABLE_TL
touchLinkInitiator_RegisterNotifyTLCB(zclFreePadApp_TL_NotifyCb);
#endif

LREP("Started build %s \r\n", zclFreePadApp_DateCodeNT);
ZMacSetTransmitPower(TX_PWR_PLUS_4); // set 4dBm
}
Expand Down Expand Up @@ -273,14 +262,6 @@ uint16 zclFreePadApp_event_loop(uint8 task_id, uint16 events) {
zclFreePadApp_SaveAttributesToNV();
return (events ^ FREEPADAPP_SAVE_ATTRS_EVT);
}
#ifdef FREEPAD_ENABLE_TL
if (events & FREEPADAPP_TL_START_EVT) {
LREPMaster("FREEPADAPP_TL_START_EVT\r\n");
HalLedSet(HAL_LED_1, HAL_LED_MODE_FLASH);
zclFreePadApp_StartTL();
return (events ^ FREEPADAPP_TL_START_EVT);
}
#endif
// Discard unknown events
return 0;
}
Expand Down Expand Up @@ -313,11 +294,9 @@ static void zclFreePadApp_HandleKeys(byte shift, byte keyCode) {
prevKeyCode = keyCode;

if (keyCode == HAL_KEY_CODE_RELEASE_KEY) {
zclFactoryResetter_HandleKeys(0x40, keyCode);
zclBattery_HandleKeys(0x40, keyCode);
#ifdef FREEPAD_ENABLE_TL
osal_stop_timerEx(zclFreePadApp_TaskID, FREEPADAPP_TL_START_EVT);
#endif
zclFactoryResetter_HandleKeys(HAL_KEY_RELEASE, keyCode);
zclBattery_HandleKeys(HAL_KEY_RELEASE, keyCode);
zclTouchLinkRestter_HandleKeys(HAL_KEY_RELEASE, keyCode);
byte prevButton = zclFreePadApp_KeyCodeToButton(currentKeyCode);
uint8 prevSwitchType = zclFreePadApp_SwitchTypes[prevButton - 1];

Expand All @@ -339,14 +318,14 @@ static void zclFreePadApp_HandleKeys(byte shift, byte keyCode) {

} else {
byte button = zclFreePadApp_KeyCodeToButton(keyCode);
// TODO: implement proper keys task
zclCommissioning_HandleKeys(HAL_KEY_PRESS, keyCode);
zclFactoryResetter_HandleKeys(HAL_KEY_PRESS, keyCode);

#ifdef FREEPAD_ENABLE_TL
if (button == 2) {
osal_start_timerEx(zclFreePadApp_TaskID, FREEPADAPP_TL_START_EVT, FREEPADAPP_TL_START_DELAY);
if (button == 1) {
zclFactoryResetter_HandleKeys(HAL_KEY_PRESS, keyCode);
}
#endif

zclTouchLinkRestter_HandleKeys(HAL_KEY_PRESS, button);

uint8 switchType = zclFreePadApp_SwitchTypes[button - 1];

HalLedSet(HAL_LED_1, HAL_LED_MODE_BLINK);
Expand All @@ -373,8 +352,6 @@ static void zclFreePadApp_HandleKeys(byte shift, byte keyCode) {
}
}



static void zclFreePadApp_RestoreAttributesFromNV(void) {
LREPMaster("Restoring attributes to NV\r\n");

Expand All @@ -399,16 +376,5 @@ static void zclFreePadApp_SaveAttributesToNV(void) {
}
}

#ifdef FREEPAD_ENABLE_TL
static void zclFreePadApp_StartTL(void) {
LREPMaster("zclFreePadApp_StartTL\r\n");
touchLinkInitiator_StartDevDisc();
}

ZStatus_t zclFreePadApp_TL_NotifyCb(epInfoRec_t *pData) {
LREPMaster("zclFreePadApp_TL_NotifyCb\r\n");
return touchLinkInitiator_ResetToFNSelectedTarget();
}
#endif
/****************************************************************************
****************************************************************************/
3 changes: 1 addition & 2 deletions Source/zcl_freepadapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ extern "C" {
#define FREEPADAPP_SEND_KEYS_EVT 0x0001
#define FREEPADAPP_HOLD_START_EVT 0x0002
#define FREEPADAPP_SAVE_ATTRS_EVT 0x0004
#define FREEPADAPP_TL_START_EVT 0x0008

#define FREEPADAPP_SEND_KEYS_DELAY 250
#define FREEPADAPP_HOLD_START_DELAY (FREEPADAPP_SEND_KEYS_DELAY + 750)
#define FREEPADAPP_TL_START_DELAY 5 * 1000


#define FREEPAD_ATTRS_COUNT 2

Expand Down
Loading

0 comments on commit b323f03

Please sign in to comment.