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

📄 zkbsensor.c

📁 基于Jennic公司Zigbee芯片JN5139做的无线键盘项目源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
 *
 * MODULE:             Wireless Keyboard Demo (ZigBee Endpoint)
 *
 * COMPONENT:          $RCSfile$
 *
 * VERSION:            $Name$
 *
 * REVISION:           $Revision$
 *
 * DATED:              $Date$
 *
 * STATUS:             $State$
 *
 * AUTHOR:             APV Ward
 *
 * DESCRIPTION:
 * Provids a ZigBee (Wireless) socket for a PS2 device.
 *
 * LAST MODIFIED BY:   $Author$
 *                     $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. All rights reserved
 *
 ****************************************************************************/

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

/* Wireless keyboard specific */
#include "ZKBconfig.h"
#include "ZKBgetKey.h"
#include "PS2socket.h"

/****************************************************************************/
/***        Macro Definitions                                             ***/
/****************************************************************************/

#define HW_INT_Q_SIZE          32
#define HW_INT_Q_PTR_MASK      0x1f

/* Application constants and identifiers */
#define	ACK_TIMEOUT_VALUE		5000	/* this * 1/32768 = approximately 150 ms */

/****************************************************************************/
/***        Type Definitions                                              ***/
/****************************************************************************/

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

/* All variables with scope throughout module are in one structure */
typedef struct
{
    /* System status: 32kHz offset and keycode transmit manager */
    struct
    {
        uint32  u32CalibOffset;

		bool_t  boAckPending;
		uint8	u8CurrentKeyCode;

    } sSystem;

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

/****************************************************************************/
/***        Local Function Prototypes                                     ***/
/****************************************************************************/
PRIVATE void  vInitKeyboardDemo (void);
PRIVATE void  vSendData         (uint8 u8datum);

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

/****************************************************************************/
/***        Local Variables                                               ***/
/****************************************************************************/
tsKeybData sKeybStatus;
PRIVATE bool_t bNwkJoined = FALSE;

/****************************************************************************/
/***        Exported Functions                                            ***/
/****************************************************************************/
/****************************************************************************
 *
 * NAME: AppColdStart
 *
 * DESCRIPTION:
 * Entry point for application. Initialises system, starts scan then
 * processes interrupts.
 *
 * RETURNS:
 * void, 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 */
    JZS_sConfig.u32Channel = WKB_FIXED_CHANNEL;
    JZS_sConfig.u16PanId   = WKB_PAN_ID;

	/* no return from the following call, control goes to BOS task switcher */
    vInitKeyboardDemo();
}

/****************************************************************************
 *
 * 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)
{
    /* Sensor has one endpoint (PS2 socket service), which has just      */
    /* one output cluster (PS2 device) and one attribute (PS2 codewords) */

    uint8  u8DeviceVer = 0x00;
    uint8  u8Flags     = 0x00;
    uint16 u16DeviceId = 0x0000;

    uint8   u8InputClusterCnt    = 0;
    uint8  au8InputClusterList[] = {};
    uint8  u8OutputClusterCnt    = 1;
    uint8 au8OutputClusterList[] = {WKB_PS2_SOCKET};

    (void)afmeAddSimpleDesc(WKB_ENDPOINT_PS2,
    						WKB_PROFILE_ID,
    						u16DeviceId,
                             u8DeviceVer,
                             u8Flags,
                             u8InputClusterCnt,
                            au8InputClusterList,
                            u8OutputClusterCnt,
                           au8OutputClusterList);

    JZS_vStartStack();
    return TRUE;
}

/****************************************************************************
 *
 * 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: u32GetCalibOffset
 *
 * DESCRIPTION:
 * Exports the offset value needed to compensate for inaccuracy in the
 * 32kHz RC oscillator.
 *
 * RETURNS:
 * calibration offset as unsigned 32 bit integer
 *
 ****************************************************************************/
PUBLIC uint32 u32GetCalibOffset(void)
{
	return sKeybStatus.sSystem.u32CalibOffset;
}

/****************************************************************************
 *
 * NAME: JZA_eAfKvpObject
 *
 * DESCRIPTION:
 * Called when a KVP transaction has been received with a matching endpoint.
 *
 * Not used in this application - we are not expecting data from the coordinator.
 * For a full PS2 keyboard implementation, the PS2 bus would be bi-directional
 * and control data would flow from, for example, a PC back to the PS2 keyboard.
 * Such control data might include keyboard repeat rates, or caps lock LED control.
 *
 * PARAMETERS:      Name           RW  Usage
 *                  afSrcAddr      R   Address of sender device
 *                  u8DstEndpoint  R   Endpoint at receiver
 *                  pu8ClusterId   R   Pointer to cluster ID
 *                  eCommandTypeId R   KVP command type
 *                  u16AttributeId R   KVP attribute ID
 *                  pu8AfduLength  R   Pointer to length of data
 *                  pu8Afdu        R   Data array
 *
 * RETURNS:
 * AF_ERROR_CODE
 *
 ****************************************************************************/
PUBLIC AF_ERROR_CODE JZA_eAfKvpObject(AF_ADDRTYPE         afSrcAddr,
                                      uint8               u8LQI,
                                      uint8               u8DstEndpoint,
                                      uint8               u8SequenceNum,
                                      uint8              *pu8ClusterId,
                                      AF_COMMAND_TYPE_ID  eCommandTypeId,
                                      uint16              u16AttributeId,
                                      uint8              *pu8AfduLength,
                                      uint8              *pu8Afdu)
{
    return KVP_SUCCESS;
}

/****************************************************************************
 *
 * NAME: JZA_vAfKvpResponse
 *
 * DESCRIPTION:
 * Called when an ack is received in response to an earlier KVP data request.
 *
 * For the wireless keyboard application, this happens when the coordinator
 * has sent an application level ack in response to receiving a keycode message.
 *
 * This call represents the return half of a flow control mechanism that prevents
 * keyboard scans from occuring during stack interrupt activities.
 *
 * PARAMETERS:      Name                   RW  Usage
 *                  srcAddressMod          R   Address of sender device
 *                  transactionSequenceNum R   KVP transaction number
 *                  commandTypeIdentifier  R   KVP command type
 *                  dstEndPoint            R   Endpoint at receiver
 *                  clusterID              R   Cluster ID
 *                  attributeIdentifier    R   KVP attribute ID
 *                  errorCode              R   Result code
 *                  afduLength             R   Length of payload data
 *                  pAfdu                  R   Payload data array
 *
 ****************************************************************************/
PUBLIC void JZA_vAfKvpResponse(AF_ADDRTYPE         srcAddressMod,
                               uint8               u8LQI,
                               uint8               transactionSequenceNum,
                               AF_COMMAND_TYPE_ID  commandTypeIdentifier,
                               uint8               dstEndPoint,
                               uint8               clusterID,
                               uint16              attributeIdentifier,
                               uint8               errorCode,
                               uint8               afduLength,
                               uint8              *pAfdu )
{
	/* Received an Application Framework ack - process it */

⌨️ 快捷键说明

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