📄 wsn_coordinator.c
字号:
/****************************************************************************
*
* MODULE: WSN_Coordinator.c
*
* COMPONENT: $RCSfile: $
*
* VERSION: $Name: $
*
* REVISION: $Revision: $
*
* DATED: $Date: $
*
* STATUS: $State: $
*
* AUTHOR: IDM
*
* DESCRIPTION:
*
* Implements a Wireless Sensor Network Coordinator Node using Jennic Zigbee
* stack. Receives data from compatible nodes via the radio and retransmits to
* to host using UART.
*
* LAST MODIFIED BY: $Author: $
* $Modtime: $
*
****************************************************************************
*
* (c) Copyright 2006 JENNIC Ltd
*
****************************************************************************/
/****************************************************************************/
/*** Include files ***/
/****************************************************************************/
#include "jendefs.h"
#include "AppHardwareApi.h"
#include "Utilities.h"
#include "serial.h"
#include "printf.h"
#include "JZ_Api.h"
#include "WSN_Profile.h"
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
#define LED_OUTPUTS_MASK 0x0000C000UL
#define LED1_MASK 0x00004000UL
#define LED2_MASK 0x00008000UL
#define LED_INIT (vAHI_DioSetDirection(0, LED_OUTPUTS_MASK))
#define LED_1_OFF (vAHI_DioSetOutput(LED1_MASK, 0))
#define LED_1_ON (vAHI_DioSetOutput(0, LED1_MASK))
#define LED_2_OFF (vAHI_DioSetOutput(LED2_MASK, 0))
#define LED_2_ON (vAHI_DioSetOutput(0, LED2_MASK))
#define HW_INT_Q_SIZE 32
#define HW_INT_Q_PTR_MASK 0x1f
/* Timing values */
#define APP_TICK_PERIOD_ms 500
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
typedef struct
{
uint32 u32Device;
uint32 u32ItemBitmap;
} tsHwIntData;
typedef struct
{
tsHwIntData asHwIntData[HW_INT_Q_SIZE];
volatile uint8 u8ReadPtr;
volatile uint8 u8WritePtr;
} tsHwEventQueue;
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
PRIVATE void vInit(void);
PRIVATE void vToggleLed(uint8 u8Dummy);
PRIVATE void vTxSerialDataFrame(uint16 u16NodeId,
uint16 u16Humidity,
uint16 u16Temperature,
uint16 u16BattVoltage);
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
tsHwEventQueue sHwEventQueue;
bool_t bAppTimerStarted = FALSE;
/****************************************************************************
*
* NAME: AppColdStart
*
* DESCRIPTION:
* Entry point for application from boot loader. Initialises system and runs
* main loop.
*
* RETURNS:
* Never returns.
*
****************************************************************************/
PUBLIC void AppColdStart(void)
{
/* Set network information */
JZS_sConfig.u32Channel = WSN_CHANNEL;
JZS_sConfig.u16PanId = WSN_PAN_ID;
/* General initialisation */
vInit();
/* 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();
}
/****************************************************************************/
/*** Local Functions ***/
/****************************************************************************/
/****************************************************************************
*
* NAME: vInit
*
* DESCRIPTION:
* Initialises Zigbee stack and hardware. Final action is to start BOS, from
* which there is no return. Subsequent application actions occur in the
* functions defined above.
*
* RETURNS:
* No return from this function
*
****************************************************************************/
PRIVATE void vInit(void)
{
/* Initialise Zigbee stack */
(void)JZS_u32InitSystem();
/* Set DIO for LEDs */
LED_INIT;
LED_1_OFF;
LED_2_OFF;
/* Intialise serial comms */
vSerial_Init();
/* Initialise hardware event queue pointers */
sHwEventQueue.u8ReadPtr = 0;
sHwEventQueue.u8WritePtr = 0;
/* Start BOS */
BOSIntSystem();
BOSStartSystem();
/* No return from the above function call */
}
/****************************************************************************
*
* NAME: vTxSerialDataFrame
*
* DESCRIPTION:
* Transmits node data (address and sensor readings) to host via serial port.
*
* PARAMETERS: Name RW Usage
* u16NodeId R Short address of node that generated the data
* u16Humidity R Reading from humidity sensor (%)
* u16Temperature R Reading from temperature sensor (degrees C)
* u16BattVoltage R ADC reading of supply voltage (mv)
*
****************************************************************************/
PRIVATE void vTxSerialDataFrame(uint16 u16NodeId,
uint16 u16Humidity,
uint16 u16Temperature,
uint16 u16BattVoltage)
{
printf("\n\r\n\rAddress = %x", u16NodeId);
printf("\n\rHumidity = %d", u16Humidity);
printf("\n\rTemperature = %d", u16Temperature);
printf("\n\rVoltage = %d", u16BattVoltage);
}
/****************************************************************************
*
* NAME: vToggleLed
*
* DESCRIPTION:
* Gets called by a BOS timer. Toggles LED1 to indicate we are alive.
*
****************************************************************************/
PRIVATE void vToggleLed(uint8 u8Dummy)
{
static bool_t bToggle;
if (bToggle)
{
LED_1_OFF;
}
else
{
LED_1_ON;
}
bToggle = !bToggle;
BOSStartTimer(vToggleLed, 0, (APP_TICK_PERIOD_ms / 10));
}
/****************************************************************************/
/*** Functions called by the stack ***/
/****************************************************************************/
/****************************************************************************
*
* 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.
*
****************************************************************************/
void JZA_vAppEventHandler(void)
{
tsHwIntData *psHwIntData;
if (!bAppTimerStarted)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -