📄 zkbcoordinator.c
字号:
/****************************************************************************
*
* MODULE: Wireless Keyboard Demo (ZigBee Coordinator)
*
* COMPONENT: $RCSfile$
*
* VERSION: $Name$
*
* REVISION: $Revision$
*
* DATED: $Date$
*
* STATUS: $State$
*
* AUTHOR: APV Ward
*
* DESCRIPTION:
* Provides a display for a ZigBee (wireless) keyboard demonstrator.
*
* 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 "Utilities.h"
#include "gdb.h"
#include "JZ_Api.h"
#include "LedControl.h"
#include "ZKBconfig.h"
#include "PS2protocol.h"
#include "ZKBlcd.h"
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
#define HW_INT_Q_SIZE 32
#define HW_INT_Q_PTR_MASK 0x1f
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
/* peripheral interrupt control */
typedef struct
{
uint32 u32Device;
uint32 u32ItemBitmap;
} tsHwIntData;
/* Appliocation status kept in this data structure */
typedef struct
{
struct
{
uint8 u8RxSeqNum;
} sAppl;
struct
{
uint32 u32CalibOffset;
} sSystem;
/* Queue for hardware interrupts */
struct
{
tsHwIntData asHwIntData[HW_INT_Q_SIZE];
volatile uint8 u8ReadPtr;
volatile uint8 u8WritePtr;
} sQueue;
} tsKbdDemoStatus;
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
PRIVATE void vInitKeyboardDemo (void);
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
/* File scope data */
PRIVATE tsKbdDemoStatus sKbdDemoStat;
/****************************************************************************/
/*** 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 = WKB_FIXED_CHANNEL;
JZS_sConfig.u16PanId = WKB_PAN_ID;
vInitKeyboardDemo();
/* No return from the above function call - we now enter the BOS kernel */
}
/****************************************************************************
*
* 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 JZA_boAppStart(void)
{
/* This function repeatedly called from the BOS, until TRUE is returned */
/* Define an application endpoint - do so with a ZigBee simple descriptor */
uint8 u8DeviceVer = 0x00;
uint8 u8Flags = 0x00;
uint16 u16DeviceId = 0x0000;
uint8 u8InputClusterCnt = 1;
uint8 au8InputClusterList[] = {WKB_CLUSTER_ID};
uint8 u8OutputClusterCnt = 0;
uint8 au8OutputClusterList[] = {};
(void)afmeAddSimpleDesc(WKB_ENDPOINT_LCD,
WKB_PROFILE_ID,
u16DeviceId,
u8DeviceVer,
u8Flags,
u8InputClusterCnt,
au8InputClusterList,
u8OutputClusterCnt,
au8OutputClusterList);
/* At this point, we could wait upon some other activity completing before */
/* returning TRUE (which then starts the application */
JZS_vStartStack();
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;
if (JZS_eStackState <= JZS_STATE_JOINING)
{
return;
}
/* Check queue for hardware interrupts, and process. Only process one per call */
while (sKbdDemoStat.sQueue.u8WritePtr != sKbdDemoStat.sQueue.u8ReadPtr)
{
psHwIntData = &sKbdDemoStat.sQueue.asHwIntData[sKbdDemoStat.sQueue.u8ReadPtr];
switch (psHwIntData->u32Device)
{
case E_AHI_DEVICE_SYSCTRL:
/* Check for wake timer */
if (psHwIntData->u32ItemBitmap & (1 << E_AHI_SYSCTRL_WK1))
{
/* No hardware events used in this application. */
/* This stub included as an example event handler */
}
default:
break;
}
sKbdDemoStat.sQueue.u8ReadPtr = (sKbdDemoStat.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
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -