/****************************************************************************
*
* MODULE: Jenie Application
*
* COMPONENT: $RCSfile: App.c,v $
*
* VERSION:
*
* REVISION: 0.0
*
* DATED: 2008/03/11 13:20:00
*
* STATUS: Exp
*
* AUTHOR: mlook
*
* DESCRIPTION:
*
*
* LAST MODIFIED BY: $Author: mlook $
* $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 2008. All rights reserved
*
****************************************************************************/
/****************************************************************************/
/*** Include files ***/
/****************************************************************************/
#include <jendefs.h>
#include <Jenie.h>
#include <JPI.h> /* Jenie Peripheral Interface {v2} */
#include <Printf.h> /* Basic Printf to UART0-19200-8-NP-1 {v2} */
#include <LedControl.h> /* Led Interface {v2} */
#include <Button.h> /* Button Interface {v3} */
#include "App.h"
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
#define BUTTON_P_MASK (BUTTON_3_MASK << 1) /* Mask for program button {v3} */
#define TIMEOUT_LONG_PRESS 200 /* Long button press timeout (in 10ms) {v4} */
#define TIMEOUT_IDLE_ASLEEP 2 /* Idle timeout when sleeping (in 10ms) */
#define TIMEOUT_IDLE_AWAKE 500 /* Idle timeout when awake (in 10ms) */
#define PERIOD_SLEEP 5000 /* Sleep period (in ms) */
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
PRIVATE bool_t bNetworkUp; /* Network up {v2} */
PRIVATE uint8 au8Led[2]; /* Led states {v2} */
PRIVATE uint8 u8Tick; /* Ticker {v2} */
PRIVATE uint8 u8Button; /* Button state {v3} */
PRIVATE uint64 u64Parent; /* Parent address {v3} */
PRIVATE uint64 u64Last; /* Last address to send to us {v3} */
PRIVATE uint16 au16ButtonTimer[2]; /* Timer for button presses {v4} */
PRIVATE uint32 u32Reg; /* Registered services {v4} */
PRIVATE bool_t bReg; /* Successfully registered services {v4} */
PRIVATE bool_t bBound; /* Bound services {v4} */
PRIVATE bool_t bSentService; /* Data sent to service {v4} */
PRIVATE bool_t bEndDevice; /* Device is an end device {v5} */
PRIVATE bool_t bSleep; /* End device is in sleeping mode {v5} */
PRIVATE uint16 u16IdleTimer; /* Timer for idleness {v5} */
/****************************************************************************
*
* NAME: vApp_CbInit
*
* DESCRIPTION:
* Application initialisation
*
* RETURNS:
* Nothing
*
****************************************************************************/
PUBLIC void vApp_CbInit(bool_t bWarmStart,
bool_t bInitEndDevice) /* Initialising end device {v5} */
{
/* Is this a cold start ? */
if (! bWarmStart)
{
/* Network won't be up */
bNetworkUp = FALSE;
/* We are not in sleep mode {v5} */
bSleep = FALSE;
}
/* Initialise LEDs and buttons {v3} */
vLedInitRfd();
vButtonInitRfd();
/* Reset button timers {v4} */
au16ButtonTimer[0] = 0;
au16ButtonTimer[1] = 0;
/* Turn off LEDs */
au8Led[0] = 0;
au8Led[1] = 0;
/* Don't run idle timer {v5} */
u16IdleTimer = 0;
/* Note if we are an end device {v5} */
bEndDevice = bInitEndDevice;
/* Is this an end device {v5} ? */
if (bEndDevice)
{
/* Warm start and the network is up ? */
if (bWarmStart && bNetworkUp)
{
/* Turn on LEDs indicating we've woken up */
au8Led[0] = 0xFF;
au8Led[1] = 0xFF;
/* Have we woken because of a button press ? */
if (u8ButtonReadRfd())
{
/* Make sure we are not in sleep mode */
bSleep = FALSE;
}
/* Set idle timer dependent upon sleep mode */
if (bSleep) u16IdleTimer = TIMEOUT_IDLE_ASLEEP;
else u16IdleTimer = TIMEOUT_IDLE_AWAKE;
}
/* Set interrupts on buttons to wake us up */
vJPI_DioWake(BUTTON_ALL_MASK_RFD_PIN, 0, 0, BUTTON_ALL_MASK_RFD_PIN);
/* Set sleep period */
eJenie_SetSleepPeriod(PERIOD_SLEEP);
}
}
/****************************************************************************
*
* NAME: vApp_CbMain
*
* DESCRIPTION:
* Main user routine. This is called by the Basic Operating System (BOS)
* at regular intervals.
*
* RETURNS:
* void
*
****************************************************************************/
PUBLIC void vApp_CbMain(void)
{
/* Network is down ? */
if (! bNetworkUp)
{
/* Flash LED0 quickly while we wait for the network to come up */
au8Led[0] = 0x02;
}
/* Network up and permit join is on {v3} ? */
else if (bJenie_GetPermitJoin())
{
/* Flash LED0 quickish while we are allowing joining */
au8Led[0] = 0x04;
}
/* Network up and permit join off and services registered {v4} */
else if (bReg)
{
/* Flash LED0 slowish while we have the service registered */
au8Led[0] = 0x08;
}
/* Led has been left flashing ? */
else if (au8Led[0] != 0 && au8Led[0] != 0xFF)
{
/* Turn off LED */
au8Led[0] = 0x00;
}
}
/****************************************************************************
*
* NAME: vApp_StackMgmtEvent
*
* DESCRIPTION:
* Used to receive stack management events
*
* PARAMETERS: Name RW Usage
* *psStackMgmtEvent R Pointer to event structure
*
* RETURNS:
* void
*
****************************************************************************/
PUBLIC void vApp_CbStackMgmtEvent(teEventType eEventType, void *pvEventPrim)
{
teJenieStatusCode eStatus; /* Jenie status code {v3} */
/* Which event occurred ? */
switch (eEventType)
{
/* Indicates stack is up and running */
case E_JENIE_NETWORK_UP:
{
/* Get pointer to correct primitive structure {v3} */
tsNwkStartUp *psNwkStartUp = (tsNwkStartUp *) pvEventPrim;
/* Output to UART */
vPrintf("vApp_CbStackMgmtEvent(NETWORK_UP, %x:%x, %x:%x, %d, %x, %d)\n",
(uint32)(psNw
App.rar_APP
版权申诉
63 浏览量
2022-09-24
15:26:25
上传
评论
收藏 6KB RAR 举报
小波思基
- 粉丝: 74
- 资源: 1万+