⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 homedemocontroller.c

📁 wireless jennic application note
💻 C
📖 第 1 页 / 共 4 页
字号:
/****************************************************************************
 *
 * MODULE:             Home Demo coordinator code
 *
 * COMPONENT:          $RCSfile: HomeDemoController.c,v $
 *
 * VERSION:            $Name:  $
 *
 * REVISION:           $Revision: 1.5 $
 *
 * DATED:              $Date: 2007/06/21 08:14:40 $
 *
 * STATUS:             $State: Exp $
 *
 * AUTHOR:             CJG
 *
 * DESCRIPTION:
 * Coordinator for demonstrator. Acts as time coordinator for up to four
 * sensor endpoints and manages LCD panel and keys on central coordinator.
 *
 * LAST MODIFIED BY:   $Author: jahme $
 *                     $Modtime: $
 *
 ****************************************************************************
 *
 * This software is owned by Jennic and/or its supplier and is protected
 * under applicable copyright laws. All rights are reserved. We grant You,
 * and any third parties, a license to use this software solely and
 * exclusively on Jennic products. You, and any third parties must reproduce
 * the copyright and warranty notice and any other legend of ownership on each
 * copy or partial copy of the software.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS". JENNIC MAKES NO WARRANTIES, WHETHER
 * EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
 * ACCURACY OR LACK OF NEGLIGENCE. JENNIC SHALL NOT, IN ANY CIRCUMSTANCES,
 * BE LIABLE FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO, SPECIAL,
 * INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY REASON WHATSOEVER.
 *
 * Copyright Jennic Ltd 2005, 2006, 2007. All rights reserved
 *
 ****************************************************************************/

/****************************************************************************/
/***        Include files                                                 ***/
/****************************************************************************/
#include "jendefs.h"
#include "LcdDriver.h"
#include <AppHardwareApi.h>
#include "LedControl.h"
#include "Button.h"
#include "Utilities.h"
#include "gdb.h"
#include "JennicLogo.h"

#include "JZ_Api.h"
#include "HomeDemoProfile.h"
#include "nwk.h"
#include "af.h"

/****************************************************************************/
/***        Macro Definitions                                             ***/
/****************************************************************************/
/* Block (time slice) values */
#define BLOCK_TIME_IN_32K_PERIODS 1600
#define BLOCK_MIN_RX          2
#define BLOCK_UPDATE          (BLOCK_MIN_RX + DEMO_ENDPOINTS)
#define MAX_BLOCKS            20

/* Control screen and alarm values */
#define FRAMES_MISSED_INDICATION 9

/* Channel values */
#define CHANNEL_MIN           11
#define CHANNEL_MAX           26

/* Number of points in graph of previous values. Must be multiple of 2 */
#define DEMO_HISTORY_LEN                  16

/* Number of endpoints in system */
#define DEMO_ENDPOINTS                    4
#define DEMO_ENDPOINT_POSITIONS           4

#define HW_INT_Q_SIZE          8
#define HW_INT_Q_PTR_MASK      0x7

/****************************************************************************/
/***        Type Definitions                                              ***/
/****************************************************************************/
typedef enum
{
    E_SENSOR_TEMP = 0,
    E_SENSOR_HTS,
    E_SENSOR_ALS,
    DEMO_SENSOR_LIST_LEN
} teSensor;

/* Holds all stored data for a particular sensor for a node */
typedef struct
{
    uint8 u8NowValue;
    uint8 au8GraphData[DEMO_HISTORY_LEN];
} tsNodeElementData;

/* Holds all stored data for a node */
typedef struct
{
    tsNodeElementData asNodeElementData[DEMO_SENSOR_LIST_LEN];
    uint64 u64ExtAdr;
    uint16 u16ShortAdr;
    uint8 u8FramesMissed;
    uint8 u8SwitchOn;
} tsNodeData;

/* System states with respect to screen display being shown */
typedef enum
{
    E_STATE_SPLASH,
    E_STATE_NETWORK,
    E_STATE_NODE
} teState;

/* Button values */
typedef enum
{
    E_KEY_0 = BUTTON_0_MASK,
    E_KEY_1 = BUTTON_1_MASK,
    E_KEY_2 = BUTTON_2_MASK,
    E_KEY_3 = BUTTON_3_MASK,
} teKeyValues;

typedef struct
{
    uint32 u32Device;
    uint32 u32ItemBitmap;
} tsHwIntData;

/* All application data with scope within the entire file is kept here,
   including all stored node data, GUI settings and current state */
typedef struct
{
    struct
    {
        tsNodeData   asNodeData[DEMO_ENDPOINTS];
        uint8        u8AssociatedNodes;
    } sNode;

    struct
    {
        teSensor eCurrentSensor;
        uint8    u8CurrentNode;
        uint8    u8GraphPos;
        uint8    u8Keys;
    } sGui;

    struct
    {
        teState eState;
        uint32  u32ZigbeeStackVersion;
        uint32  u32CalibratedTimeout;
        uint8   u8TimeBlock;
        uint8   u8Channel;
    } sSystem;

    /* Queue for hardware interrupts */
    struct
    {
        tsHwIntData    asHwIntData[HW_INT_Q_SIZE];
        volatile uint8 u8ReadPtr;
        volatile uint8 u8WritePtr;
    } sQueue;
} tsDemoData;

/****************************************************************************/
/***        Local Function Prototypes                                     ***/
/****************************************************************************/
PRIVATE void vInitDemoSystem(void);
PRIVATE void vInitCoord(void);
PRIVATE void vSetTimer(void);
PRIVATE void vProcessCurrentTimeBlock(uint8 u8TimeBlock);
PRIVATE void vProcessKeys(uint8 *pu8Keys);
PRIVATE uint8 u8UpdateTimeBlock(uint8 u8TimeBlock);
PRIVATE void vProcessUpdateBlock(void);
PRIVATE void vSendData(uint16 u16Addr, uint8 u8Switch);
PRIVATE void vProcessSplashKeyPress(uint8 u8KeyMap);
PRIVATE void vProcessNetworkKeyPress(uint8 u8KeyMap);
PRIVATE void vProcessNodeKeyPress(uint8 u8KeyMap);
PRIVATE void vBuildNetworkScreen(void);
PRIVATE void vUpdateNetworkScreen(teSensor eSensor);
PRIVATE void vUpdateSplashScreen(void);
PRIVATE void vBuildNodeScreen(uint8 u8Node);
PRIVATE void vUpdateNodeScreen(uint8 u8Node);
PRIVATE void vLcdUpdateElement(tsNodeData *psNodeData, teSensor eSensor,
                               uint8 u8Row, uint8 u8Col, bool_t boShowInfo);
PRIVATE void vDrawGraph(uint8 *pu8GraphData, uint8 u8StartCol,
                        uint8 u8StartRow);
PRIVATE void vStringCopy(char *pcFrom,char *pcTo);
PRIVATE void vValToDec(char *pcOutString, uint8 u8Value, char *pcLabel);
PRIVATE void vAddDesc(void);
#ifdef TEST_BOS_TIMER
PRIVATE void vTimerFired0(void *pvMessage, uint8 u8Len);
#endif

/****************************************************************************/
/***        Exported Variables                                            ***/
/****************************************************************************/

/****************************************************************************/
/***        Local Variables                                               ***/
/****************************************************************************/

/* File scope data */
PRIVATE tsDemoData sDemoData;

/* Row and column positions of info fields on LCD */
static const uint8 au8NodeLcdRow[DEMO_ENDPOINT_POSITIONS] = {0,  0, 3,  3};
static const uint8 au8NodeLcdCol[DEMO_ENDPOINT_POSITIONS] = {0, 64, 0, 64};

static const char *apcNodeNameList[DEMO_ENDPOINTS] = {
    "Hall", "Bedroom", "Lounge", "Bathroom"};

#ifdef TEST_BOS_TIMER
uint8 u8LedFlash0 = 0;
#endif

/****************************************************************************/
/***        Exported Functions                                            ***/
/****************************************************************************/
/****************************************************************************
 *
 * NAME: AppColdStart
 *
 * DESCRIPTION:
 * Entry point for application from boot loader. Initialises system and runs
 * main loop.
 *
 * RETURNS:
 * Never returns.
 *
 ****************************************************************************/
PUBLIC void AppColdStart(void)
{
    /* Debug hooks: include these regardless of whether debugging or not */
    HAL_GDB_INIT();
    HAL_BREAKPOINT();

    /* General initialisation: reset hardware, set some values in PIB */
    JZS_sConfig.u32Channel = CHANNEL_DEFAULT;
    JZS_sConfig.u16PanId = DEMO_PAN_ID;
    JZS_sConfig.u16AppDataLength = 0;

    vInitDemoSystem();

    /* No return from the above function call */
}

/****************************************************************************
 *
 * NAME: AppWarmStart
 *
 * DESCRIPTION:
 * Entry point for application from boot loader. Simply jumps to AppColdStart
 * as, in this instance, application will never warm start.
 *
 * RETURNS:
 * Never returns.
 *
 ****************************************************************************/
PUBLIC void AppWarmStart(void)
{
    AppColdStart();
}

/****************************************************************************
 *
 * NAME: JZA_boAppStart
 *
 * DESCRIPTION:
 * Called by Zigbee stack during initialisation. Sets up the profile
 * information and starts the networking activity
 *
 * RETURNS:
 * TRUE
 *
 ****************************************************************************/
PUBLIC bool_t JZA_boAppStart(void)
{
#ifdef TEST_BOS_TIMER
    bBosCreateTimer(vTimerFired0, NULL, 0, 10, NULL);
#endif

    return TRUE;
}

/****************************************************************************
 *
 * NAME: JZA_vAppEventHandler
 *
 * DESCRIPTION:
 * Called regularly by the task scheduler. This function reads the hardware
 * event queue and processes the events therein. It is important that this
 * function exits after a relatively short time so that the other tasks are
 * not adversely affected.
 *
 ****************************************************************************/
PUBLIC void JZA_vAppEventHandler(void)
{
    tsHwIntData *psHwIntData;

    /* Check queue for hardware interrupts, and process */
    while (sDemoData.sQueue.u8WritePtr != sDemoData.sQueue.u8ReadPtr)
    {
        /* Get entry from queue */
        psHwIntData = &sDemoData.sQueue.asHwIntData[sDemoData.sQueue.u8ReadPtr];

        switch (psHwIntData->u32Device)
        {
        case E_AHI_DEVICE_SYSCTRL:
            /* Check for wake timer */
            if (psHwIntData->u32ItemBitmap & (1 << E_AHI_SYSCTRL_WK1))
            {
                /* Set the timer for the next interval */
                vSetTimer();

                /* Perform scheduler action */
                vProcessCurrentTimeBlock(sDemoData.sSystem.u8TimeBlock);

                /* Check keys */
                vProcessKeys(&sDemoData.sGui.u8Keys);

                /* Increment scheduler time block for next time */
                sDemoData.sSystem.u8TimeBlock = u8UpdateTimeBlock(sDemoData.sSystem.u8TimeBlock);
            }

        default:
            break;
        }

        /* Move read pointer forwards, wrapping around if necessary */
        sDemoData.sQueue.u8ReadPtr = (sDemoData.sQueue.u8ReadPtr + 1) & HW_INT_Q_PTR_MASK;
    }
}

/****************************************************************************
 *
 * NAME: JZA_vPeripheralEvent
 *
 * DESCRIPTION:
 * Called when a hardware event causes an interrupt. This function is called
 * from within the interrupt context so should be brief. In this case, the
 * information is placed on a simple FIFO queue to be processed later.
 *
 * PARAMETERS: Name          RW  Usage
 *             u32Device     R   Peripheral generating interrupt
 *             u32ItemBitmap R   Bitmap of interrupt sources within peripheral
 *
 ****************************************************************************/
PUBLIC void JZA_vPeripheralEvent(uint32 u32Device, uint32 u32ItemBitmap)
{
    tsHwIntData *psHwIntData;
    uint8        u8WriteNextPtr;

    /* Queue event for subsequent processing by JZ_vAppEventHandler */
    u8WriteNextPtr = (sDemoData.sQueue.u8WritePtr + 1) & HW_INT_Q_PTR_MASK;

    if (u8WriteNextPtr != sDemoData.sQueue.u8ReadPtr)
    {
        /* There is space on queue */
        psHwIntData = &sDemoData.sQueue.asHwIntData[sDemoData.sQueue.u8WritePtr];
        psHwIntData->u32Device = u32Device;
        psHwIntData->u32ItemBitmap = u32ItemBitmap;

        sDemoData.sQueue.u8WritePtr = u8WriteNextPtr;
    }

    /* If no space on queue, interrupt is silently discarded */
}

/****************************************************************************
 *
 * NAME: JZA_vAppDefineTasks
 *
 * DESCRIPTION:
 * Called by Zigbee stack during initialisation to allow the application to
 * initialise any tasks that it requires. This application requires none.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PUBLIC void JZA_vAppDefineTasks(void)
{
}

/****************************************************************************
 *
 * NAME: JZA_eAfKvpObject
 *
 * DESCRIPTION:
 * Receives incoming KVP data frames
 *
 * PARAMETERS:      Name                RW  Usage
 *                  eAddrMode           R   Address mode of incoming frame
 *                  u16AddrSrc          R   Network address of source node
 *                  u8SrcEP             R   Endpoint address of source node
 *                  u8LQI               R   Link Quality Indication

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -