mirror of
https://github.com/Utyff/Zintercom.git
synced 2026-01-12 09:17:41 +03:00
init commit
This commit is contained in:
70
Source/OSAL_App.c
Normal file
70
Source/OSAL_App.c
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "OSAL.h"
|
||||
#include "OSAL_Tasks.h"
|
||||
#include "ZComDef.h"
|
||||
#include "hal_drivers.h"
|
||||
|
||||
#include "APS.h"
|
||||
#include "ZDApp.h"
|
||||
#include "nwk.h"
|
||||
|
||||
#if defined ( MT_TASK )
|
||||
#include "MT.h"
|
||||
#include "MT_TASK.h"
|
||||
#endif
|
||||
|
||||
#include "commissioning.h"
|
||||
#include "factory_reset.h"
|
||||
#include "Debug.h"
|
||||
#include "battery.h"
|
||||
|
||||
#include "bdb_interface.h"
|
||||
#include "zcl_app.h"
|
||||
|
||||
const pTaskEventHandlerFn tasksArr[] = {macEventLoop,
|
||||
nwk_event_loop,
|
||||
Hal_ProcessEvent,
|
||||
#if defined( MT_TASK )
|
||||
MT_ProcessEvent,
|
||||
#endif
|
||||
APS_event_loop,
|
||||
ZDApp_event_loop,
|
||||
zcl_event_loop,
|
||||
bdb_event_loop,
|
||||
zclApp_event_loop,
|
||||
zclCommissioning_event_loop,
|
||||
zclFactoryResetter_loop
|
||||
#ifdef ZIC_BATTERY_MODE
|
||||
,
|
||||
zclBattery_event_loop
|
||||
#endif
|
||||
};
|
||||
|
||||
const uint8 tasksCnt = sizeof(tasksArr) / sizeof(tasksArr[0]);
|
||||
uint16 *tasksEvents;
|
||||
|
||||
void osalInitTasks(void) {
|
||||
uint8 taskID = 0;
|
||||
DebugInit();
|
||||
|
||||
tasksEvents = (uint16 *)osal_mem_alloc(sizeof(uint16) * tasksCnt);
|
||||
osal_memset(tasksEvents, 0, (sizeof(uint16) * tasksCnt));
|
||||
macTaskInit(taskID++);
|
||||
nwk_init(taskID++);
|
||||
Hal_Init(taskID++);
|
||||
#if defined( MT_TASK )
|
||||
MT_TaskInit( taskID++ );
|
||||
#endif
|
||||
APS_Init(taskID++);
|
||||
ZDApp_Init(taskID++);
|
||||
zcl_Init(taskID++);
|
||||
bdb_Init(taskID++);
|
||||
zclApp_Init(taskID++);
|
||||
zclCommissioning_Init(taskID++);
|
||||
zclFactoryResetter_Init(taskID++);
|
||||
#ifdef ZIC_BATTERY_MODE
|
||||
zclBattery_Init(taskID++);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
472
Source/hal_board_cfg.h
Normal file
472
Source/hal_board_cfg.h
Normal file
@@ -0,0 +1,472 @@
|
||||
#ifndef HAL_BOARD_CFG_H
|
||||
#define HAL_BOARD_CFG_H
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Includes
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#include "hal_mcu.h"
|
||||
#include "hal_defs.h"
|
||||
#include "hal_types.h"
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* CC2590/CC2591 support
|
||||
*
|
||||
* Define HAL_PA_LNA_CC2590 if CC2530+CC2590EM is used
|
||||
* Define HAL_PA_LNA if CC2530+CC2591EM is used
|
||||
* Note that only one of them can be defined
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
#define xHAL_PA_LNA
|
||||
#define xHAL_PA_LNA_CC2590
|
||||
#define xHAL_PA_LNA_SE2431L
|
||||
#define xHAL_PA_LNA_CC2592
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Clock Speed
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define HAL_CPU_CLOCK_MHZ 32
|
||||
|
||||
/* This flag should be defined if the SoC uses the 32MHz crystal
|
||||
* as the main clock source (instead of DCO).
|
||||
*/
|
||||
#define HAL_CLOCK_CRYSTAL
|
||||
|
||||
/* 32 kHz clock source select in CLKCONCMD */
|
||||
#if !defined (OSC32K_CRYSTAL_INSTALLED) || (defined (OSC32K_CRYSTAL_INSTALLED) && (OSC32K_CRYSTAL_INSTALLED == TRUE))
|
||||
#define OSC_32KHZ 0x00 /* external 32 KHz xosc */
|
||||
#else
|
||||
#define OSC_32KHZ 0x80 /* internal 32 KHz rcosc */
|
||||
#endif
|
||||
|
||||
#define HAL_CLOCK_STABLE() st( while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); )
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* LED Configuration
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#if defined (HAL_BOARD_CHDTECH_DEV)
|
||||
#define HAL_NUM_LEDS 4
|
||||
#elif defined(HAL_BOARD_TARGET)
|
||||
#define HAL_NUM_LEDS 4
|
||||
#else
|
||||
#error Unknown Board Indentifier
|
||||
#endif
|
||||
|
||||
#define HAL_LED_BLINK_DELAY() st( { volatile uint32 i; for (i=0; i<0x5800; i++) { }; } )
|
||||
|
||||
#if defined(HAL_BOARD_TARGET)
|
||||
//blue
|
||||
#define LED1_BV BV(4)
|
||||
#define LED1_SBIT P1_4
|
||||
#define LED1_DDR P1DIR
|
||||
#define LED1_POLARITY ACTIVE_LOW
|
||||
//green
|
||||
#define LED2_BV BV(1)
|
||||
#define LED2_SBIT P1_1
|
||||
#define LED2_DDR P1DIR
|
||||
#define LED2_POLARITY ACTIVE_LOW
|
||||
//red
|
||||
#define LED3_BV BV(0)
|
||||
#define LED3_SBIT P1_0
|
||||
#define LED3_DDR P1DIR
|
||||
#define LED3_POLARITY ACTIVE_LOW
|
||||
//ex
|
||||
#define LED4_BV BV(4)
|
||||
#define LED4_SBIT P1_5
|
||||
#define LED4_DDR P1DIR
|
||||
#define LED4_POLARITY ACTIVE_LOW
|
||||
|
||||
|
||||
#elif defined(HAL_BOARD_CHDTECH_DEV)
|
||||
//blue
|
||||
#define LED1_BV BV(4)
|
||||
#define LED1_SBIT P1_4
|
||||
#define LED1_DDR P1DIR
|
||||
#define LED1_POLARITY ACTIVE_LOW
|
||||
//green
|
||||
#define LED2_BV BV(1)
|
||||
#define LED2_SBIT P1_1
|
||||
#define LED2_DDR P1DIR
|
||||
#define LED2_POLARITY ACTIVE_LOW
|
||||
//red
|
||||
#define LED3_BV BV(0)
|
||||
#define LED3_SBIT P1_0
|
||||
#define LED3_DDR P1DIR
|
||||
#define LED3_POLARITY ACTIVE_LOW
|
||||
//ex
|
||||
#define LED4_BV BV(4)
|
||||
#define LED4_SBIT P1_5
|
||||
#define LED4_DDR P1DIR
|
||||
#define LED4_POLARITY ACTIVE_LOW
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Push Button Configuration
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define ACTIVE_LOW !
|
||||
#define ACTIVE_HIGH !! /* double negation forces result to be '1' */
|
||||
|
||||
/* S1 */
|
||||
#define PUSH1_BV BV(1)
|
||||
#define PUSH1_SBIT P0_1
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* OSAL NV implemented by internal flash pages.
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// Flash is partitioned into 8 banks of 32 KB or 16 pages.
|
||||
#define HAL_FLASH_PAGE_PER_BANK 16
|
||||
// Flash is constructed of 128 pages of 2 KB.
|
||||
#define HAL_FLASH_PAGE_SIZE 2048
|
||||
#define HAL_FLASH_WORD_SIZE 4
|
||||
|
||||
// CODE banks get mapped into the XDATA range 8000-FFFF.
|
||||
#define HAL_FLASH_PAGE_MAP 0x8000
|
||||
|
||||
// The last 16 bytes of the last available page are reserved for flash lock bits.
|
||||
// NV page definitions must coincide with segment declaration in project *.xcl file.
|
||||
#if defined NON_BANKED
|
||||
#define HAL_FLASH_LOCK_BITS 16
|
||||
#define HAL_NV_PAGE_END 30
|
||||
#define HAL_NV_PAGE_CNT 2
|
||||
#else
|
||||
#define HAL_FLASH_LOCK_BITS 16
|
||||
#define HAL_NV_PAGE_END 126
|
||||
#define HAL_NV_PAGE_CNT 6
|
||||
#endif
|
||||
|
||||
// Re-defining Z_EXTADDR_LEN here so as not to include a Z-Stack .h file.
|
||||
#define HAL_FLASH_IEEE_SIZE 8
|
||||
#define HAL_FLASH_IEEE_PAGE (HAL_NV_PAGE_END+1)
|
||||
#define HAL_FLASH_IEEE_OSET (HAL_FLASH_PAGE_SIZE - HAL_FLASH_LOCK_BITS - HAL_FLASH_IEEE_SIZE)
|
||||
#define HAL_INFOP_IEEE_OSET 0xC
|
||||
|
||||
#define HAL_FLASH_DEV_PRIVATE_KEY_OSET 0x7D2
|
||||
#define HAL_FLASH_CA_PUBLIC_KEY_OSET 0x7BC
|
||||
#define HAL_FLASH_IMPLICIT_CERT_OSET 0x78C
|
||||
|
||||
#define HAL_NV_PAGE_BEG (HAL_NV_PAGE_END-HAL_NV_PAGE_CNT+1)
|
||||
// Used by DMA macros to shift 1 to create a mask for DMA registers.
|
||||
#define HAL_NV_DMA_CH 0
|
||||
#define HAL_DMA_CH_RX 3
|
||||
#define HAL_DMA_CH_TX 4
|
||||
|
||||
#define HAL_NV_DMA_GET_DESC() HAL_DMA_GET_DESC0()
|
||||
#define HAL_NV_DMA_SET_ADDR(a) HAL_DMA_SET_ADDR_DESC0((a))
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Serial Boot Loader: reserving the first 4 pages of flash and other memory in cc2530-sb.xcl.
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define HAL_SB_IMG_ADDR 0x2000
|
||||
#define HAL_SB_CRC_ADDR 0x2090
|
||||
// Size of internal flash less 4 pages for boot loader, 6 pages for NV, & 1 page for lock bits.
|
||||
#define HAL_SB_IMG_SIZE (0x40000 - 0x2000 - 0x3000 - 0x0800)
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Macros
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* ----------- RF-frontend Connection Initialization ---------- */
|
||||
#if defined HAL_PA_LNA || defined HAL_PA_LNA_CC2590 || \
|
||||
defined HAL_PA_LNA_SE2431L || defined HAL_PA_LNA_CC2592
|
||||
extern void MAC_RfFrontendSetup(void);
|
||||
#define HAL_BOARD_RF_FRONTEND_SETUP() MAC_RfFrontendSetup()
|
||||
#else
|
||||
#define HAL_BOARD_RF_FRONTEND_SETUP()
|
||||
#endif
|
||||
|
||||
/* ----------- Cache Prefetch control ---------- */
|
||||
#define PREFETCH_ENABLE() st( FCTL = 0x08; )
|
||||
#define PREFETCH_DISABLE() st( FCTL = 0x04; )
|
||||
|
||||
/* ----------- Board Initialization ---------- */
|
||||
#if defined (HAL_BOARD_CHDTECH_DEV) || (!defined(HAL_PA_LNA) && !defined(HAL_PA_LNA_CC2592))
|
||||
#define HAL_BOARD_INIT() \
|
||||
{ \
|
||||
uint16 i; \
|
||||
\
|
||||
SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ \
|
||||
while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ \
|
||||
asm("NOP"); /* chip bug workaround */ \
|
||||
for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ \
|
||||
CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */ \
|
||||
while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); /* Wait for the change to be effective */ \
|
||||
SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ \
|
||||
\
|
||||
/* Turn on cache prefetch mode */ \
|
||||
PREFETCH_ENABLE(); \
|
||||
\
|
||||
LED1_DDR |= LED1_BV; \
|
||||
LED2_DDR |= LED2_BV; \
|
||||
LED3_DDR |= LED3_BV; \
|
||||
}
|
||||
|
||||
#elif defined (HAL_PA_LNA)
|
||||
#define HAL_BOARD_INIT() \
|
||||
{ \
|
||||
uint16 i; \
|
||||
\
|
||||
SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ \
|
||||
while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ \
|
||||
asm("NOP"); /* chip bug workaround */ \
|
||||
for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ \
|
||||
CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */ \
|
||||
while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); /* Wait for the change to be effective */ \
|
||||
SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ \
|
||||
\
|
||||
/* Turn on cache prefetch mode */ \
|
||||
PREFETCH_ENABLE(); \
|
||||
\
|
||||
/* set direction for GPIO outputs */ \
|
||||
/* For SE2431L PA LNA this sets ANT_SEL to output */ \
|
||||
/* For CC2592 this enables LNA */ \
|
||||
P1DIR |= BV(0) | BV(1); \
|
||||
\
|
||||
/* Set PA/LNA HGM control P0_7 */ \
|
||||
P0DIR |= BV(7); \
|
||||
\
|
||||
\
|
||||
/* setup RF frontend if necessary */ \
|
||||
HAL_BOARD_RF_FRONTEND_SETUP(); \
|
||||
LED1_DDR |= LED1_BV; \
|
||||
LED2_DDR |= LED2_BV; \
|
||||
LED3_DDR |= LED3_BV; \
|
||||
}
|
||||
|
||||
#elif defined (HAL_PA_LNA_CC2592) || defined (HAL_PA_LNA_SE2431L)
|
||||
#define HAL_BOARD_INIT() \
|
||||
{ \
|
||||
uint16 i; \
|
||||
\
|
||||
SLEEPCMD &= ~OSC_PD; /* turn on 16MHz RC and 32MHz XOSC */ \
|
||||
while (!(SLEEPSTA & XOSC_STB)); /* wait for 32MHz XOSC stable */ \
|
||||
asm("NOP"); /* chip bug workaround */ \
|
||||
for (i=0; i<504; i++) asm("NOP"); /* Require 63us delay for all revs */ \
|
||||
CLKCONCMD = (CLKCONCMD_32MHZ | OSC_32KHZ); /* Select 32MHz XOSC and the source for 32K clock */ \
|
||||
while (CLKCONSTA != (CLKCONCMD_32MHZ | OSC_32KHZ)); /* Wait for the change to be effective */ \
|
||||
SLEEPCMD |= OSC_PD; /* turn off 16MHz RC */ \
|
||||
\
|
||||
/* Turn on cache prefetch mode */ \
|
||||
PREFETCH_ENABLE(); \
|
||||
\
|
||||
/* set direction for GPIO outputs */ \
|
||||
/* For SE2431L PA LNA this sets ANT_SEL to output */ \
|
||||
/* For CC2592 this enables LNA */ \
|
||||
P1DIR |= BV(0) | BV(1); \
|
||||
\
|
||||
/* Set PA/LNA HGM control P0_7 */ \
|
||||
P0DIR |= BV(7); \
|
||||
\
|
||||
\
|
||||
/* setup RF frontend if necessary */ \
|
||||
HAL_BOARD_RF_FRONTEND_SETUP(); \
|
||||
LED1_DDR |= LED1_BV; \
|
||||
LED2_DDR |= LED2_BV; \
|
||||
LED3_DDR |= LED3_BV; \
|
||||
}
|
||||
#endif
|
||||
|
||||
/* ----------- Debounce ---------- */
|
||||
#define HAL_DEBOUNCE(expr) { int i; for (i=0; i<500; i++) { if (!(expr)) i = 0; } }
|
||||
|
||||
/* ----------- Push Buttons ---------- */
|
||||
#define HAL_PUSH_BUTTON1() (0)
|
||||
#define HAL_PUSH_BUTTON2() (0)
|
||||
#define HAL_PUSH_BUTTON3() (0)
|
||||
#define HAL_PUSH_BUTTON4() (0)
|
||||
#define HAL_PUSH_BUTTON5() (0)
|
||||
#define HAL_PUSH_BUTTON6() (0)
|
||||
|
||||
/* ----------- LED's ---------- */
|
||||
#define HAL_TURN_OFF_LED1() st( LED1_SBIT = LED1_POLARITY (0); )
|
||||
#define HAL_TURN_OFF_LED2() st( LED2_SBIT = LED2_POLARITY (0); )
|
||||
#define HAL_TURN_OFF_LED3() st( LED3_SBIT = LED3_POLARITY (0); )
|
||||
#define HAL_TURN_OFF_LED4() st( LED4_SBIT = LED4_POLARITY (0); )
|
||||
|
||||
#define HAL_TURN_ON_LED1() st( LED1_SBIT = LED1_POLARITY (1); )
|
||||
#define HAL_TURN_ON_LED2() st( LED2_SBIT = LED2_POLARITY (1); )
|
||||
#define HAL_TURN_ON_LED3() st( LED3_SBIT = LED3_POLARITY (1); )
|
||||
#define HAL_TURN_ON_LED4() st( LED4_SBIT = LED4_POLARITY (1); )
|
||||
|
||||
#define HAL_TOGGLE_LED1() st( if (LED1_SBIT) { LED1_SBIT = 0; } else { LED1_SBIT = 1;} )
|
||||
#define HAL_TOGGLE_LED2() st( if (LED2_SBIT) { LED2_SBIT = 0; } else { LED2_SBIT = 1;} )
|
||||
#define HAL_TOGGLE_LED3() st( if (LED3_SBIT) { LED3_SBIT = 0; } else { LED3_SBIT = 1;} )
|
||||
#define HAL_TOGGLE_LED4() st( if (LED4_SBIT) { LED4_SBIT = 0; } else { LED4_SBIT = 1;} )
|
||||
|
||||
#define HAL_STATE_LED1() (LED1_POLARITY (LED1_SBIT))
|
||||
#define HAL_STATE_LED2() (LED2_POLARITY (LED2_SBIT))
|
||||
#define HAL_STATE_LED3() (LED3_POLARITY (LED3_SBIT))
|
||||
#define HAL_STATE_LED4() (LED4_POLARITY (LED4_SBIT))
|
||||
|
||||
/* ----------- XNV ---------- */
|
||||
#define XNV_SPI_BEGIN() st(P1_3 = 0;)
|
||||
#define XNV_SPI_TX(x) st(U1CSR &= ~0x02; U1DBUF = (x);)
|
||||
#define XNV_SPI_RX() U1DBUF
|
||||
#define XNV_SPI_WAIT_RXRDY() st(while (!(U1CSR & 0x02));)
|
||||
#define XNV_SPI_END() st(P1_3 = 1;)
|
||||
|
||||
// The TI reference design uses UART1 Alt. 2 in SPI mode.
|
||||
#define XNV_SPI_INIT() \
|
||||
st( \
|
||||
/* Mode select UART1 SPI Mode as master. */\
|
||||
U1CSR = 0; \
|
||||
\
|
||||
/* Setup for 115200 baud. */\
|
||||
U1GCR = 11; \
|
||||
U1BAUD = 216; \
|
||||
\
|
||||
/* Set bit order to MSB */\
|
||||
U1GCR |= BV(5); \
|
||||
\
|
||||
/* Set UART1 I/O to alternate 2 location on P1 pins. */\
|
||||
PERCFG |= 0x02; /* U1CFG */\
|
||||
\
|
||||
/* Select peripheral function on I/O pins but SS is left as GPIO for separate control. */\
|
||||
P1SEL |= 0xE0; /* SELP1_[7:4] */\
|
||||
/* P1.1,2,3: reset, LCD CS, XNV CS. */\
|
||||
P1SEL &= ~0x0E; \
|
||||
P1 |= 0x0E; \
|
||||
P1_1 = 0; \
|
||||
P1DIR |= 0x0E; \
|
||||
\
|
||||
/* Give UART1 priority over Timer3. */\
|
||||
P2SEL &= ~0x20; /* PRI2P1 */\
|
||||
\
|
||||
/* When SPI config is complete, enable it. */\
|
||||
U1CSR |= 0x40; \
|
||||
/* Release XNV reset. */\
|
||||
P1_1 = 1; \
|
||||
)
|
||||
|
||||
/* ----------- Minimum safe bus voltage ---------- */
|
||||
|
||||
// Vdd/3 / Internal Reference X ENOB --> (Vdd / 3) / 1.15 X 127
|
||||
#define VDD_2_0 74 // 2.0 V required to safely read/write internal flash.
|
||||
#define VDD_2_7 100 // 2.7 V required for the Numonyx device.
|
||||
#define VDD_MIN_RUN (VDD_2_0+4) // VDD_MIN_RUN = VDD_MIN_NV
|
||||
#define VDD_MIN_NV (VDD_2_0+4) // 5% margin over minimum to survive a page erase and compaction.
|
||||
#define VDD_MIN_GOOD (VDD_2_0+8) // 10% margin over minimum to survive a page erase and compaction.
|
||||
#define VDD_MIN_XNV (VDD_2_7+5) // 5% margin over minimum to survive a page erase and compaction.
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* Driver Configuration
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* Set to TRUE enable H/W TIMER usage, FALSE disable it */
|
||||
#ifndef HAL_TIMER
|
||||
#define HAL_TIMER FALSE
|
||||
#endif
|
||||
|
||||
/* Set to TRUE enable ADC usage, FALSE disable it */
|
||||
#ifndef HAL_ADC
|
||||
#define HAL_ADC TRUE
|
||||
#endif
|
||||
|
||||
/* Set to TRUE enable DMA usage, FALSE disable it */
|
||||
#ifndef HAL_DMA
|
||||
#define HAL_DMA TRUE
|
||||
#endif
|
||||
|
||||
/* Set to TRUE enable Flash access, FALSE disable it */
|
||||
#ifndef HAL_FLASH
|
||||
#define HAL_FLASH TRUE
|
||||
#endif
|
||||
|
||||
/* Set to TRUE enable AES usage, FALSE disable it */
|
||||
#ifndef HAL_AES
|
||||
#define HAL_AES TRUE
|
||||
#endif
|
||||
|
||||
#ifndef HAL_AES_DMA
|
||||
#define HAL_AES_DMA TRUE
|
||||
#endif
|
||||
|
||||
/* Set to TRUE enable LCD usage, FALSE disable it */
|
||||
#ifndef HAL_LCD
|
||||
#define HAL_LCD TRUE
|
||||
#endif
|
||||
|
||||
/* Set to TRUE enable LED usage, FALSE disable it */
|
||||
#ifndef HAL_LED
|
||||
#define HAL_LED TRUE
|
||||
#endif
|
||||
#if (!defined BLINK_LEDS) && (HAL_LED == TRUE)
|
||||
#define BLINK_LEDS
|
||||
#endif
|
||||
|
||||
/* Set to TRUE enable KEY usage, FALSE disable it */
|
||||
#ifndef HAL_KEY
|
||||
#define HAL_KEY TRUE
|
||||
#endif
|
||||
|
||||
/* Set to TRUE enable UART usage, FALSE disable it */
|
||||
#ifndef HAL_UART
|
||||
#if (defined ZAPP_P1) || (defined ZAPP_P2) || (defined ZTOOL_P1) || (defined ZTOOL_P2)
|
||||
#define HAL_UART TRUE
|
||||
#else
|
||||
#define HAL_UART FALSE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HAL_UART
|
||||
#ifndef HAL_UART_DMA
|
||||
#if HAL_DMA
|
||||
#if (defined ZAPP_P2) || (defined ZTOOL_P2)
|
||||
#define HAL_UART_DMA 2
|
||||
#else
|
||||
#define HAL_UART_DMA 1
|
||||
#endif
|
||||
#else
|
||||
#define HAL_UART_DMA 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAL_UART_ISR
|
||||
#if HAL_UART_DMA // Default preference for DMA over ISR.
|
||||
#define HAL_UART_ISR 0
|
||||
#elif (defined ZAPP_P2) || (defined ZTOOL_P2)
|
||||
#define HAL_UART_ISR 2
|
||||
#else
|
||||
#define HAL_UART_ISR 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (HAL_UART_DMA && (HAL_UART_DMA == HAL_UART_ISR))
|
||||
#error HAL_UART_DMA & HAL_UART_ISR must be different.
|
||||
#endif
|
||||
|
||||
// Used to set P2 priority - USART0 over USART1 if both are defined.
|
||||
#if ((HAL_UART_DMA == 1) || (HAL_UART_ISR == 1))
|
||||
#define HAL_UART_PRIPO 0x00
|
||||
#else
|
||||
#define HAL_UART_PRIPO 0x40
|
||||
#endif
|
||||
|
||||
#else
|
||||
#define HAL_UART_DMA 0
|
||||
#define HAL_UART_ISR 0
|
||||
#endif
|
||||
|
||||
/* USB is not used for CC2530 configuration */
|
||||
#define HAL_UART_USB 0
|
||||
#endif
|
||||
/*******************************************************************************************************
|
||||
*/
|
||||
91
Source/preinclude.h
Normal file
91
Source/preinclude.h
Normal file
@@ -0,0 +1,91 @@
|
||||
#define TC_LINKKEY_JOIN
|
||||
#define NV_INIT
|
||||
#define NV_RESTORE
|
||||
|
||||
#define TP2_LEGACY_ZC
|
||||
// patch sdk
|
||||
// #define ZDSECMGR_TC_ATTEMPT_DEFAULT_KEY TRUE
|
||||
|
||||
#define NWK_AUTO_POLL
|
||||
#define MULTICAST_ENABLED FALSE
|
||||
|
||||
#define ZCL_READ
|
||||
#define ZCL_WRITE
|
||||
#define ZCL_BASIC
|
||||
#define ZCL_IDENTIFY
|
||||
#define ZCL_REPORTING_DEVICE
|
||||
|
||||
#define DISABLE_GREENPOWER_BASIC_PROXY
|
||||
//#define BDB_FINDING_BINDING_CAPABILITY_ENABLED 1
|
||||
#define BDB_REPORTING TRUE
|
||||
|
||||
|
||||
#define HAL_BUZZER FALSE
|
||||
#define HAL_KEY TRUE
|
||||
#define ISR_KEYINTERRUPT
|
||||
|
||||
|
||||
#define HAL_LED TRUE
|
||||
#define HAL_ADC FALSE
|
||||
#define HAL_LCD FALSE
|
||||
|
||||
#define BLINK_LEDS TRUE
|
||||
|
||||
// one of this boards
|
||||
// #define HAL_BOARD_TARGET
|
||||
// #define HAL_BOARD_CHDTECH_DEV
|
||||
|
||||
#if !defined(HAL_BOARD_TARGET) && !defined(HAL_BOARD_CHDTECH_DEV)
|
||||
#error "Board type must be defined"
|
||||
#endif
|
||||
|
||||
#if defined(HAL_BOARD_TARGET)
|
||||
#define HAL_KEY_P0_INPUT_PINS BV(1)
|
||||
#define HAL_KEY_P2_INPUT_PINS BV(0)
|
||||
//#define CO2_UART_PORT 0x00
|
||||
//#define HAL_UART_DMA 1
|
||||
//#define HAL_UART_ISR 0
|
||||
#define INT_HEAP_LEN 2256
|
||||
#elif defined(HAL_BOARD_CHDTECH_DEV)
|
||||
#define HAL_UART_DMA 1
|
||||
#define HAL_UART_ISR 2
|
||||
//#define CO2_UART_PORT 0x01
|
||||
//#define HAL_KEY_P0_INPUT_PINS 0x21//pins 1 and 2. BV(1) bv(1) pin 2. bit (1 << n)
|
||||
#define HAL_KEY_P0_INPUT_PINS BV(1)
|
||||
#define HAL_KEY_P2_INPUT_PINS BV(0)
|
||||
#define DO_DEBUG_UART
|
||||
#endif
|
||||
|
||||
#define FACTORY_RESET_HOLD_TIME_LONG 5000
|
||||
|
||||
|
||||
#ifdef DO_DEBUG_UART
|
||||
#define HAL_UART TRUE
|
||||
#define HAL_UART_DMA 1
|
||||
#define INT_HEAP_LEN 2060
|
||||
#endif
|
||||
|
||||
// #define INT_HEAP_LEN (2685 - 0x4B - 0xBB-0x50-0xae)
|
||||
// #define HAL_UART TRUE
|
||||
// #define HAL_UART_DMA 2
|
||||
#define HAL_UART TRUE
|
||||
|
||||
|
||||
//#define BME280_32BIT_ENABLE
|
||||
//i2c bme280
|
||||
//#define OCM_CLK_PORT 1
|
||||
//#define OCM_CLK_PIN 6
|
||||
|
||||
//#define OCM_DATA_PORT 1
|
||||
//#define OCM_DATA_PIN 7
|
||||
|
||||
|
||||
//#define DS18B20_PORT 0
|
||||
//#define TSENS_SBIT P0_0
|
||||
//#define TSENS_BV BV(0)
|
||||
//#define TSENS_DIR P0DIR
|
||||
|
||||
|
||||
|
||||
|
||||
#include "hal_board_cfg.h"
|
||||
2
Source/version.h
Normal file
2
Source/version.h
Normal file
@@ -0,0 +1,2 @@
|
||||
extern const uint8 zclApp_DateCode[];
|
||||
extern const char zclApp_DateCodeNT[];
|
||||
369
Source/zcl_app.c
Normal file
369
Source/zcl_app.c
Normal file
@@ -0,0 +1,369 @@
|
||||
|
||||
#include "AF.h"
|
||||
#include "OSAL.h"
|
||||
#include "OSAL_Clock.h"
|
||||
#include "OSAL_PwrMgr.h"
|
||||
#include "ZComDef.h"
|
||||
#include "ZDApp.h"
|
||||
#include "ZDObject.h"
|
||||
#include "math.h"
|
||||
|
||||
#include "nwk_util.h"
|
||||
#include "zcl.h"
|
||||
#include "zcl_app.h"
|
||||
#include "zcl_diagnostic.h"
|
||||
#include "zcl_general.h"
|
||||
#include "zcl_ms.h"
|
||||
|
||||
#include "bdb.h"
|
||||
#include "bdb_interface.h"
|
||||
#include "bdb_touchlink.h"
|
||||
#include "bdb_touchlink_target.h"
|
||||
|
||||
#include "gp_interface.h"
|
||||
|
||||
#include "Debug.h"
|
||||
|
||||
#include "OnBoard.h"
|
||||
|
||||
#include "commissioning.h"
|
||||
#include "factory_reset.h"
|
||||
/* HAL */
|
||||
|
||||
#include "hal_drivers.h"
|
||||
|
||||
#include "hal_key.h"
|
||||
#include "hal_led.h"
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
#include "battery.h"
|
||||
|
||||
#include "version.h"
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
byte zclApp_TaskID;
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL FUNCTIONS
|
||||
*/
|
||||
//void user_delay_ms(uint32_t period);
|
||||
//void user_delay_ms(uint32_t period) { MicroWait(period * 1000); }
|
||||
/*********************************************************************
|
||||
* LOCAL VARIABLES
|
||||
*/
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* LOCAL FUNCTIONS
|
||||
*/
|
||||
|
||||
static void zclApp_BasicResetCB(void);
|
||||
static void zclApp_RestoreAttributesFromNV(void);
|
||||
static void zclApp_SaveAttributesToNV(void);
|
||||
static void zclApp_HandleKeys(byte portAndAction, byte keyCode);
|
||||
static ZStatus_t zclApp_ReadWriteAuthCB(afAddrType_t *srcAddr, zclAttrRec_t *pAttr, uint8 oper);
|
||||
|
||||
static void zclApp_Report(void);
|
||||
static void zclApp_OneReport(void);
|
||||
static void zclApp_ConfigInit(bool restart);
|
||||
|
||||
static void zclApp_BtnClick(void);
|
||||
static void zclApp_RingRun(void);
|
||||
static void zclApp_RingEnd(void);
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* ZCL General Profile Callback table
|
||||
*/
|
||||
static zclGeneral_AppCallbacks_t zclApp_CmdCallbacks = {
|
||||
zclApp_BasicResetCB, // Basic Cluster Reset command
|
||||
NULL, // Identify Trigger Effect command
|
||||
NULL, // On/Off cluster commands
|
||||
NULL, // On/Off cluster enhanced command Off with Effect
|
||||
NULL, // On/Off cluster enhanced command On with Recall Global Scene
|
||||
NULL, // On/Off cluster enhanced command On with Timed Off
|
||||
NULL, // RSSI Location command
|
||||
NULL // RSSI Location Response command
|
||||
};
|
||||
void zclApp_Init(byte task_id) {
|
||||
HalLedSet(HAL_LED_ALL, HAL_LED_MODE_BLINK);
|
||||
|
||||
zclApp_RestoreAttributesFromNV();
|
||||
|
||||
zclApp_TaskID = task_id;
|
||||
|
||||
bdb_RegisterSimpleDescriptor(&zclApp_FirstEP);
|
||||
|
||||
zclGeneral_RegisterCmdCallbacks(zclApp_FirstEP.EndPoint, &zclApp_CmdCallbacks);
|
||||
|
||||
zcl_registerAttrList(zclApp_FirstEP.EndPoint, zclApp_AttrsCount, zclApp_AttrsFirstEP);
|
||||
|
||||
zcl_registerReadWriteCB(zclApp_FirstEP.EndPoint, NULL, zclApp_ReadWriteAuthCB);
|
||||
zcl_registerForMsg(zclApp_TaskID);
|
||||
RegisterForKeys(zclApp_TaskID);
|
||||
|
||||
LREP("Build %s \r\n", zclApp_DateCodeNT);
|
||||
|
||||
zclApp_ConfigInit(TIMER_START);
|
||||
#if defined( ZIC_BATTERY_MODE )
|
||||
ZMacSetTransmitPower(TX_PWR_PLUS_4); // set 4dBm
|
||||
#endif
|
||||
}
|
||||
static void zclApp_HandleKeys(byte portAndAction, byte keyCode) {
|
||||
LREP("zclApp_HandleKeys portAndAction=0x%X keyCode=0x%X\r\n", portAndAction, keyCode);
|
||||
if (keyCode == 1) {
|
||||
zclFactoryResetter_HandleKeys(portAndAction, keyCode);
|
||||
}
|
||||
zclCommissioning_HandleKeys(portAndAction, keyCode);
|
||||
if (portAndAction & HAL_KEY_PRESS) {
|
||||
if (keyCode == 1) {
|
||||
LREPMaster("Key press\r\n");
|
||||
osal_start_reload_timer(zclApp_TaskID, APP_BTN_CLICK_EVT, 250);
|
||||
}
|
||||
else if (keyCode == 2) {
|
||||
LREPMaster("Ring start\r\n");
|
||||
osal_start_reload_timer(zclApp_TaskID, APP_RING_RUN_EVT, 500);
|
||||
}
|
||||
}
|
||||
if (portAndAction & HAL_KEY_RELEASE) {
|
||||
#if defined( ZIC_BATTERY_MODE )
|
||||
zclBattery_Report();
|
||||
#endif
|
||||
if (keyCode == 2) {
|
||||
zclApp_RingEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint16 zclApp_event_loop(uint8 task_id, uint16 events) {
|
||||
LREP("events 0x%x \r\n", events);
|
||||
if (events & SYS_EVENT_MSG) {
|
||||
afIncomingMSGPacket_t *MSGpkt;
|
||||
while ((MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive(zclApp_TaskID))) {
|
||||
LREP("MSGpkt->hdr.event 0x%X clusterId=0x%X\r\n", MSGpkt->hdr.event, MSGpkt->clusterId);
|
||||
switch (MSGpkt->hdr.event) {
|
||||
case KEY_CHANGE:
|
||||
zclApp_HandleKeys(((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys);
|
||||
break;
|
||||
|
||||
case ZCL_INCOMING_MSG:
|
||||
if (((zclIncomingMsg_t *)MSGpkt)->attrCmd) {
|
||||
osal_mem_free(((zclIncomingMsg_t *)MSGpkt)->attrCmd);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Release the memory
|
||||
osal_msg_deallocate((uint8 *)MSGpkt);
|
||||
}
|
||||
// return unprocessed events
|
||||
return (events ^ SYS_EVENT_MSG);
|
||||
}
|
||||
if (events & APP_REPORT_EVT) {
|
||||
LREPMaster("APP_REPORT_EVT\r\n");
|
||||
zclApp_Report();
|
||||
return (events ^ APP_REPORT_EVT);
|
||||
}
|
||||
|
||||
if (events & APP_SAVE_ATTRS_EVT) {
|
||||
LREPMaster("APP_SAVE_ATTRS_EVT\r\n");
|
||||
zclApp_SaveAttributesToNV();
|
||||
zclApp_ConfigInit(TIMER_RESTART);
|
||||
return (events ^ APP_SAVE_ATTRS_EVT);
|
||||
}
|
||||
|
||||
if (events & APP_BTN_CLICK_EVT) {
|
||||
LREPMaster("APP_BTN_CLICK_EVT\r\n");
|
||||
zclApp_BtnClick();
|
||||
return (events ^ APP_BTN_CLICK_EVT);
|
||||
}
|
||||
if (events & APP_RING_RUN_EVT) {
|
||||
LREPMaster("APP_RING_RUN_EVT\r\n");
|
||||
zclApp_RingRun();
|
||||
return (events ^ APP_RING_RUN_EVT);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void zclApp_RingRun(void) {
|
||||
|
||||
zclApp_State.RingRunStep++;
|
||||
LREP("zclApp_State.RingRunStep %d\r\n", zclApp_State.RingRunStep);
|
||||
LREP("zclApp_State.State %d\r\n", zclApp_State.State);
|
||||
switch (zclApp_State.State) {
|
||||
case Idle:
|
||||
zclApp_State.State = Ring;
|
||||
zclApp_OneReport();
|
||||
if (zclApp_Config.ModeOpen == Drop){
|
||||
zclApp_State.State = Droped;
|
||||
HalLedSet(CATCH_PIN, HAL_LED_MODE_ON);
|
||||
}
|
||||
break;
|
||||
case Ring:
|
||||
if ((zclApp_Config.ModeOpen == Once) || (zclApp_Config.ModeOpen == Always)){
|
||||
if (zclApp_State.RingRunStep > (zclApp_Config.TimeRing * 2)) {
|
||||
zclApp_State.State = Talk;
|
||||
HalLedSet(CATCH_PIN, HAL_LED_MODE_ON);
|
||||
HalLedSet(ANSWER_PIN, HAL_LED_MODE_ON);
|
||||
zclApp_OneReport();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Talk:
|
||||
if ((zclApp_Config.ModeOpen == Once) || (zclApp_Config.ModeOpen == Always)){
|
||||
if (zclApp_State.RingRunStep > ((zclApp_Config.TimeRing + zclApp_Config.TimeTalk) * 2)) {
|
||||
zclApp_State.State = Open;
|
||||
HalLedSet(OPEN_PIN, HAL_LED_MODE_ON);
|
||||
zclApp_OneReport();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Open:
|
||||
if ((zclApp_Config.ModeOpen == Once) || (zclApp_Config.ModeOpen == Always)){
|
||||
if (zclApp_State.RingRunStep > ((zclApp_Config.TimeRing + zclApp_Config.TimeTalk+ zclApp_Config.TimeOpen) * 2)) {
|
||||
zclApp_RingEnd();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Droped:
|
||||
switch (zclApp_State.RingRunStep) {
|
||||
case 2:
|
||||
zclApp_OneReport();
|
||||
HalLedSet(ANSWER_PIN, HAL_LED_MODE_ON);
|
||||
break;
|
||||
case 3:
|
||||
zclApp_RingEnd();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void zclApp_RingEnd(void) {
|
||||
LREPMaster("Ring end\r\n");
|
||||
if (zclApp_Config.ModeSound == true) {
|
||||
HalLedSet(CATCH_PIN, HAL_LED_MODE_OFF);
|
||||
}
|
||||
HalLedSet(ANSWER_PIN, HAL_LED_MODE_OFF);
|
||||
HalLedSet(OPEN_PIN, HAL_LED_MODE_OFF);
|
||||
osal_stop_timerEx(zclApp_TaskID, APP_RING_RUN_EVT);
|
||||
osal_clear_event(zclApp_TaskID, APP_RING_RUN_EVT);
|
||||
zclApp_State.RingRunStep = 0;
|
||||
zclApp_State.State = Idle;
|
||||
if (zclApp_Config.ModeOpen == Once) {
|
||||
zclApp_Config.ModeOpen = Never;
|
||||
}
|
||||
zclApp_OneReport();
|
||||
}
|
||||
|
||||
static void zclApp_BtnClick(void) {
|
||||
|
||||
static uint8 currentBtnClickPhase = 0;
|
||||
LREP("currentBtnClickPhase %d\r\n", currentBtnClickPhase);
|
||||
switch (currentBtnClickPhase++) {
|
||||
|
||||
case 0:
|
||||
//HalLedSet(LED_PIN, HAL_LED_MODE_ON);
|
||||
HAL_TURN_ON_LED1();
|
||||
if (zclApp_Config.ModeOpen < Drop) {
|
||||
zclApp_Config.ModeOpen++;
|
||||
}
|
||||
else {
|
||||
zclApp_Config.ModeOpen = Never;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
zclApp_OneReport();
|
||||
break;
|
||||
case 2:
|
||||
//HalLedSet(LED_PIN, HAL_LED_MODE_OFF);
|
||||
HAL_TURN_OFF_LED1();
|
||||
break;
|
||||
default:
|
||||
osal_stop_timerEx(zclApp_TaskID, APP_BTN_CLICK_EVT);
|
||||
osal_clear_event(zclApp_TaskID, APP_BTN_CLICK_EVT);
|
||||
currentBtnClickPhase = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void zclApp_Report(void) {
|
||||
zclApp_OneReport();
|
||||
}
|
||||
|
||||
static void zclApp_OneReport(void) {
|
||||
HalLedSet(LED_PIN, HAL_LED_MODE_BLINK);
|
||||
bdb_RepChangedAttrValue(zclApp_FirstEP.EndPoint, ZCL_INTERCOM, ATTRID_MODEOPEN);
|
||||
}
|
||||
|
||||
static void zclApp_BasicResetCB(void) {
|
||||
LREPMaster("BasicResetCB\r\n");
|
||||
zclApp_ResetAttributesToDefaultValues();
|
||||
zclApp_SaveAttributesToNV();
|
||||
}
|
||||
|
||||
static ZStatus_t zclApp_ReadWriteAuthCB(afAddrType_t *srcAddr, zclAttrRec_t *pAttr, uint8 oper) {
|
||||
LREPMaster("AUTH CB called\r\n");
|
||||
osal_start_timerEx(zclApp_TaskID, APP_SAVE_ATTRS_EVT, 2000);
|
||||
return ZSuccess;
|
||||
}
|
||||
|
||||
static void zclApp_SaveAttributesToNV(void) {
|
||||
uint8 writeStatus = osal_nv_write(NW_APP_CONFIG, 0, sizeof(application_config_t), &zclApp_Config);
|
||||
LREP("Saving attributes to NV write=%d\r\n", writeStatus);
|
||||
}
|
||||
|
||||
static void zclApp_ConfigInit(bool restart) {
|
||||
if (restart) {
|
||||
LREP("Stop report timer event\r\n");
|
||||
osal_stop_timerEx(zclApp_TaskID, APP_REPORT_EVT);
|
||||
osal_clear_event(zclApp_TaskID, APP_REPORT_EVT);
|
||||
}
|
||||
uint32 ReportInterval = (uint32)zclApp_Config.TimeReport * (uint32)60;
|
||||
LREP("Start report with interval %d seconds\r\n", ReportInterval);
|
||||
osal_start_reload_timer(zclApp_TaskID, APP_REPORT_EVT, ((uint32)ReportInterval*(uint32)1000));
|
||||
if (zclApp_Config.ModeSound == false) {
|
||||
HalLedSet(CATCH_PIN, HAL_LED_MODE_ON);
|
||||
}
|
||||
else {
|
||||
HalLedSet(CATCH_PIN, HAL_LED_MODE_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
static void zclApp_RestoreAttributesFromNV(void) {
|
||||
uint8 status = osal_nv_item_init(NW_APP_CONFIG, sizeof(application_config_t), NULL);
|
||||
LREP("Restoring attributes from NV status=%d \r\n", status);
|
||||
if (status == NV_ITEM_UNINIT) {
|
||||
uint8 writeStatus = osal_nv_write(NW_APP_CONFIG, 0, sizeof(application_config_t), &zclApp_Config);
|
||||
LREP("NV was empty, writing %d\r\n", writeStatus);
|
||||
}
|
||||
if (status == ZSUCCESS) {
|
||||
LREPMaster("Reading from NV\r\n");
|
||||
osal_nv_read(NW_APP_CONFIG, 0, sizeof(application_config_t), &zclApp_Config);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
****************************************************************************/
|
||||
164
Source/zcl_app.h
Normal file
164
Source/zcl_app.h
Normal file
@@ -0,0 +1,164 @@
|
||||
#ifndef ZCL_APP_H
|
||||
#define ZCL_APP_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************************************************************
|
||||
* INCLUDES
|
||||
*/
|
||||
#include "version.h"
|
||||
#include "zcl.h"
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
#define APP_REPORT_DELAY ((uint32)60 * (uint32)1000) // 1 minute
|
||||
// Application Events
|
||||
#define APP_REPORT_EVT 0x0001
|
||||
#define APP_SAVE_ATTRS_EVT 0x0002
|
||||
#define APP_BTN_CLICK_EVT 0x0004
|
||||
#define APP_RING_RUN_EVT 0x0008
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
#define NW_APP_CONFIG 0x0402
|
||||
|
||||
#define R ACCESS_CONTROL_READ
|
||||
// ACCESS_CONTROL_AUTH_WRITE
|
||||
#define RW (R | ACCESS_CONTROL_WRITE | ACCESS_CONTROL_AUTH_WRITE)
|
||||
#define RR (R | ACCESS_REPORTABLE)
|
||||
|
||||
//READ REPORT WRITE
|
||||
#define RRW (R | ACCESS_REPORTABLE | ACCESS_CONTROL_WRITE | ACCESS_CONTROL_AUTH_WRITE)
|
||||
|
||||
#define BASIC ZCL_CLUSTER_ID_GEN_BASIC
|
||||
#define GEN_ON_OFF ZCL_CLUSTER_ID_GEN_ON_OFF
|
||||
#define POWER_CFG ZCL_CLUSTER_ID_GEN_POWER_CFG
|
||||
|
||||
|
||||
|
||||
//Intercom
|
||||
#define ZCL_INTERCOM 0x0101
|
||||
|
||||
#define ATTRID_STATE 0x0050
|
||||
#define ATTRID_MODEOPEN 0x0051
|
||||
#define ATTRID_MODESOUND 0x0052
|
||||
#define ATTRID_TIMERING 0x0053
|
||||
#define ATTRID_TIMETALK 0x0054
|
||||
#define ATTRID_TIMEOPEN 0x0055
|
||||
#define ATTRID_TIMEREPORT 0x0056
|
||||
|
||||
#define LED_PIN HAL_LED_1
|
||||
#define CATCH_PIN HAL_LED_2
|
||||
#define ANSWER_PIN HAL_LED_3
|
||||
#define OPEN_PIN HAL_LED_4
|
||||
|
||||
#define TIMER_RESTART TRUE
|
||||
#define TIMER_START FALSE
|
||||
|
||||
#define ZIC_WORKMODE_NEVER 0
|
||||
#define ZIC_WORKMODE_ONCE 1
|
||||
#define ZIC_WORKMODE_ALWAYS 2
|
||||
#define ZIC_WORKMODE_DROP 3
|
||||
|
||||
|
||||
#define ZIC_WORKSTATE_IDLE 0
|
||||
#define ZIC_WORKSTATE_RING 1
|
||||
#define ZIC_WORKSTATE_TALK 2
|
||||
#define ZIC_WORKSTATE_OPEN 3
|
||||
#define ZIC_WORKSTATE_DROP 4
|
||||
|
||||
#define ZCL_UINT8 ZCL_DATATYPE_UINT8
|
||||
#define ZCL_UINT16 ZCL_DATATYPE_UINT16
|
||||
#define ZCL_INT16 ZCL_DATATYPE_INT16
|
||||
#define ZCL_INT8 ZCL_DATATYPE_INT8
|
||||
#define ZCL_INT32 ZCL_DATATYPE_INT32
|
||||
#define ZCL_UINT32 ZCL_DATATYPE_UINT32
|
||||
#define ZCL_SINGLE ZCL_DATATYPE_SINGLE_PREC
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
typedef enum {
|
||||
Never,
|
||||
Once,
|
||||
Always,
|
||||
Drop
|
||||
} WorkMode_t;
|
||||
|
||||
typedef enum {
|
||||
Idle,
|
||||
Ring,
|
||||
Talk,
|
||||
Open,
|
||||
Droped
|
||||
} WorkState_t;
|
||||
|
||||
typedef struct {
|
||||
WorkMode_t ModeOpen;
|
||||
uint8 ModeSound;
|
||||
uint8 TimeRing;
|
||||
uint8 TimeTalk;
|
||||
uint8 TimeOpen;
|
||||
uint8 TimeReport;
|
||||
} application_config_t;
|
||||
|
||||
typedef struct {
|
||||
WorkState_t State;
|
||||
uint8 RingRunStep;
|
||||
} device_state_t;
|
||||
|
||||
|
||||
/*
|
||||
typedef enum {
|
||||
UNKNOWN, SENSEAIR, MHZ19
|
||||
} SensorType_t;
|
||||
*/
|
||||
/*********************************************************************
|
||||
* VARIABLES
|
||||
*/
|
||||
|
||||
extern SimpleDescriptionFormat_t zclApp_FirstEP;
|
||||
extern CONST zclAttrRec_t zclApp_AttrsFirstEP[];
|
||||
extern CONST uint8 zclApp_AttrsCount;
|
||||
|
||||
|
||||
extern const uint8 zclApp_ManufacturerName[];
|
||||
extern const uint8 zclApp_ModelId[];
|
||||
extern const uint8 zclApp_PowerSource;
|
||||
|
||||
extern uint8 zclApp_BatteryVoltage;
|
||||
extern uint8 zclApp_BatteryPercentageRemainig;
|
||||
extern uint16 zclApp_BatteryVoltageRawAdc;
|
||||
|
||||
extern application_config_t zclApp_Config;
|
||||
extern device_state_t zclApp_State;
|
||||
// APP_TODO: Declare application specific attributes here
|
||||
|
||||
/*********************************************************************
|
||||
* FUNCTIONS
|
||||
*/
|
||||
|
||||
/*
|
||||
* Initialization for the task
|
||||
*/
|
||||
extern void zclApp_Init(byte task_id);
|
||||
|
||||
/*
|
||||
* Event Process for the task
|
||||
*/
|
||||
extern UINT16 zclApp_event_loop(byte task_id, UINT16 events);
|
||||
|
||||
extern void zclApp_ResetAttributesToDefaultValues(void);
|
||||
|
||||
/*********************************************************************
|
||||
*********************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* ZCL_APP_H */
|
||||
154
Source/zcl_app_data.c
Normal file
154
Source/zcl_app_data.c
Normal file
@@ -0,0 +1,154 @@
|
||||
#include "AF.h"
|
||||
#include "OSAL.h"
|
||||
#include "ZComDef.h"
|
||||
#include "ZDConfig.h"
|
||||
|
||||
#include "zcl.h"
|
||||
#include "zcl_general.h"
|
||||
#include "zcl_ha.h"
|
||||
#include "zcl_ms.h"
|
||||
|
||||
#include "zcl_app.h"
|
||||
|
||||
#include "battery.h"
|
||||
#include "version.h"
|
||||
|
||||
#include "bdb_touchlink.h"
|
||||
#include "bdb_touchlink_target.h"
|
||||
#include "stub_aps.h"
|
||||
|
||||
/*********************************************************************
|
||||
* CONSTANTS
|
||||
*/
|
||||
|
||||
#define APP_DEVICE_VERSION 2
|
||||
#define APP_FLAGS 0
|
||||
|
||||
#define APP_HWVERSION 1
|
||||
#define APP_ZCLVERSION 1
|
||||
|
||||
/*********************************************************************
|
||||
* TYPEDEFS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* MACROS
|
||||
*/
|
||||
|
||||
/*********************************************************************
|
||||
* GLOBAL VARIABLES
|
||||
*/
|
||||
|
||||
// Global attributes
|
||||
const uint16 zclApp_clusterRevision_all = 0x0002;
|
||||
|
||||
// Basic Cluster
|
||||
const uint8 zclApp_HWRevision = APP_HWVERSION;
|
||||
const uint8 zclApp_ZCLVersion = APP_ZCLVERSION;
|
||||
|
||||
const uint8 zclApp_ApplicationVersion = 3;
|
||||
const uint8 zclApp_StackVersion = 4;
|
||||
|
||||
//{lenght, 'd', 'a', 't', 'a'}
|
||||
const uint8 zclApp_ManufacturerName[] = {6, 'x', 'y', 'z', 'r', 'o', 'e'};
|
||||
const uint8 zclApp_ModelId[] = {13, 'D', 'I', 'Y', '_', 'Z', 'i', 'n', 't', 'e', 'r', 'c', 'o', 'm'};
|
||||
|
||||
#if defined(ZIC_BATTERY_MODE)
|
||||
const uint8 zclApp_PowerSource = POWER_SOURCE_BATTERY;
|
||||
#define DEFAULT_TimeReport 30 //minutes
|
||||
#else
|
||||
const uint8 zclApp_PowerSource = POWER_SOURCE_DC;
|
||||
#define DEFAULT_TimeReport 1 //minutes
|
||||
#endif
|
||||
|
||||
#define DEFAULT_ModeOpen Never
|
||||
#define DEFAULT_ModeSound TRUE
|
||||
|
||||
#define DEFAULT_TimeRing 3 //seconds to ring, before answer
|
||||
#define DEFAULT_TimeTalk 1 //seconds to talk, before open
|
||||
#define DEFAULT_TimeOpen 2 //seconds to hold open
|
||||
|
||||
|
||||
application_config_t zclApp_Config = {
|
||||
.ModeOpen = DEFAULT_ModeOpen,
|
||||
.ModeSound = DEFAULT_ModeSound,
|
||||
.TimeRing = DEFAULT_TimeRing,
|
||||
.TimeTalk = DEFAULT_TimeTalk,
|
||||
.TimeOpen = DEFAULT_TimeOpen,
|
||||
.TimeReport = DEFAULT_TimeReport,
|
||||
};
|
||||
|
||||
device_state_t zclApp_State = {
|
||||
.State = Idle,
|
||||
.RingRunStep = 0,
|
||||
};
|
||||
|
||||
|
||||
/*********************************************************************
|
||||
* ATTRIBUTE DEFINITIONS - Uses REAL cluster IDs
|
||||
*/
|
||||
|
||||
CONST zclAttrRec_t zclApp_AttrsFirstEP[] = {
|
||||
{BASIC, {ATTRID_BASIC_APPL_VERSION, ZCL_UINT8, R, (void *)&zclApp_ApplicationVersion}},
|
||||
{BASIC, {ATTRID_BASIC_STACK_VERSION, ZCL_UINT8, R, (void *)&zclApp_StackVersion}},
|
||||
{BASIC, {ATTRID_BASIC_HW_VERSION, ZCL_UINT8, R, (void *)&zclApp_HWRevision}},
|
||||
{BASIC, {ATTRID_BASIC_ZCL_VERSION, ZCL_UINT8, R, (void *)&zclApp_ZCLVersion}},
|
||||
{BASIC, {ATTRID_BASIC_MANUFACTURER_NAME, ZCL_DATATYPE_CHAR_STR, R, (void *)zclApp_ManufacturerName}},
|
||||
{BASIC, {ATTRID_BASIC_MODEL_ID, ZCL_DATATYPE_CHAR_STR, R, (void *)zclApp_ModelId}},
|
||||
{BASIC, {ATTRID_BASIC_POWER_SOURCE, ZCL_DATATYPE_ENUM8, R, (void *)&zclApp_PowerSource}},
|
||||
{BASIC, {ATTRID_CLUSTER_REVISION, ZCL_UINT16, R, (void *)&zclApp_clusterRevision_all}},
|
||||
{BASIC, {ATTRID_BASIC_DATE_CODE, ZCL_DATATYPE_CHAR_STR, R, (void *)zclApp_DateCode}},
|
||||
{BASIC, {ATTRID_BASIC_SW_BUILD_ID, ZCL_DATATYPE_CHAR_STR, R, (void *)zclApp_DateCode}},
|
||||
|
||||
#if defined(ZIC_BATTERY_MODE)
|
||||
{POWER_CFG, {ATTRID_POWER_CFG_BATTERY_VOLTAGE, ZCL_UINT8, RR, (void *)&zclBattery_Voltage}},
|
||||
/**
|
||||
* FYI: calculating battery percentage can be tricky, since this device can be powered from 2xAA or 1xCR2032 batteries
|
||||
* */
|
||||
{POWER_CFG, {ATTRID_POWER_CFG_BATTERY_PERCENTAGE_REMAINING, ZCL_UINT8, RR, (void *)&zclBattery_PercentageRemainig}},
|
||||
#endif
|
||||
{ZCL_INTERCOM, {ATTRID_STATE, ZCL_DATATYPE_ENUM8, RRW, (void *)&zclApp_State.State}},
|
||||
|
||||
{ZCL_INTERCOM, {ATTRID_MODEOPEN, ZCL_DATATYPE_ENUM8, RRW, (void *)&zclApp_Config.ModeOpen}},
|
||||
{ZCL_INTERCOM, {ATTRID_MODESOUND, ZCL_DATATYPE_BOOLEAN, RRW, (void *)&zclApp_Config.ModeSound}},
|
||||
|
||||
{ZCL_INTERCOM, {ATTRID_TIMERING, ZCL_UINT8, RW, (void *)&zclApp_Config.TimeRing}},
|
||||
{ZCL_INTERCOM, {ATTRID_TIMETALK, ZCL_UINT8, RW, (void *)&zclApp_Config.TimeTalk}},
|
||||
{ZCL_INTERCOM, {ATTRID_TIMEOPEN, ZCL_UINT8, RW, (void *)&zclApp_Config.TimeOpen}},
|
||||
{ZCL_INTERCOM, {ATTRID_TIMEREPORT, ZCL_UINT8, RW, (void *)&zclApp_Config.TimeReport}},
|
||||
};
|
||||
|
||||
|
||||
uint8 CONST zclApp_AttrsCount = (sizeof(zclApp_AttrsFirstEP) / sizeof(zclApp_AttrsFirstEP[0]));
|
||||
|
||||
const cId_t zclApp_InClusterList[] = {ZCL_CLUSTER_ID_GEN_BASIC};
|
||||
|
||||
#define APP_MAX_INCLUSTERS (sizeof(zclApp_InClusterList) / sizeof(zclApp_InClusterList[0]))
|
||||
|
||||
const cId_t zclApp_OutClusterList[] = {ZCL_INTERCOM};
|
||||
|
||||
|
||||
#define APP_MAX_OUT_CLUSTERS (sizeof(zclApp_OutClusterList) / sizeof(zclApp_OutClusterList[0]))
|
||||
|
||||
|
||||
SimpleDescriptionFormat_t zclApp_FirstEP = {
|
||||
1, // int Endpoint;
|
||||
ZCL_HA_PROFILE_ID, // uint16 AppProfId[2];
|
||||
ZCL_HA_DEVICEID_SIMPLE_SENSOR, // uint16 AppDeviceId[2];
|
||||
APP_DEVICE_VERSION, // int AppDevVer:4;
|
||||
APP_FLAGS, // int AppFlags:4;
|
||||
APP_MAX_INCLUSTERS, // byte AppNumInClusters;
|
||||
(cId_t *)zclApp_InClusterList, // byte *pAppInClusterList;
|
||||
APP_MAX_OUT_CLUSTERS, // byte AppNumInClusters;
|
||||
(cId_t *)zclApp_OutClusterList // byte *pAppInClusterList;
|
||||
};
|
||||
|
||||
|
||||
void zclApp_ResetAttributesToDefaultValues(void) {
|
||||
zclApp_Config.ModeOpen = DEFAULT_ModeOpen;
|
||||
zclApp_Config.ModeSound = DEFAULT_ModeSound;
|
||||
zclApp_Config.TimeRing = DEFAULT_TimeRing;
|
||||
zclApp_Config.TimeTalk = DEFAULT_TimeTalk;
|
||||
zclApp_Config.TimeOpen = DEFAULT_TimeOpen;
|
||||
zclApp_Config.TimeReport = DEFAULT_TimeReport;
|
||||
}
|
||||
Reference in New Issue
Block a user