📄 wuart.c
字号:
/****************************************************************************
*
* MODULE Jenie Wireless UART
*
* COMPONENT $RCSfile: Wuart.c,v $
*
* VERSION $Name: $
*
* REVISION $Revision: 1.1 $
*
* DATED $Date: 2007/11/02 12:32:42 $
*
* STATUS $State: Exp $
*
* AUTHOR Ian Morris, Martin Looker
*
* DESCRIPTION Jenie Wireless UART - Wireless UART.
*
* CHANGE HISTORY
*
* $Log: Wuart.c,v $
* Revision 1.1 2007/11/02 12:32:42 mlook
* Adding new application notes
*
*
*
* 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 2005, 2006, 2007. All rights reserved
*
****************************************************************************/
/****************************************************************************/
/*** Include files ***/
/****************************************************************************/
#include <jendefs.h>
#include <AppHardwareApi.h>
#include <gdb.h>
#include "Wuart.h"
#include "Network.h"
#include "Serial.h"
#include "SerialQ.h"
#include "Uart.h"
/****************************************************************************/
/*** Macro Definitions ***/
/****************************************************************************/
#define MAX_DATA_PER_FRAME 64
/****************************************************************************/
/*** Type Definitions ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Function Prototypes ***/
/****************************************************************************/
/****************************************************************************/
/*** Exported Variables ***/
/****************************************************************************/
/****************************************************************************/
/*** Local Variables ***/
/****************************************************************************/
PRIVATE uint8 u8TxFrameHandle = 0;
PRIVATE uint8 u8RxFrameHandle = 0;
/****************************************************************************/
/*** Local Constants ***/
/****************************************************************************/
/****************************************************************************
*
* NAME: vWuart_Init
*
* DESCRIPTION:
* Initialises stack and hardware, sets non-default values in the 802.15.4
* PIB.
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PUBLIC void vWuart_Init(void)
{
/* Initialise the serial port and rx/tx queues */
vSerial_Init();
}
/****************************************************************************
*
* NAME: vWuart_TxData
*
* DESCRIPTION:
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PUBLIC void vWuart_TxData(void)
{
uint8 au8Data[MAX_DATA_PER_FRAME];
uint16 u16Length = 0;
int16 i16RxChar;
/* Are network services up ? */
if (bNetwork_Services_Up())
{
i16RxChar = i16Serial_RxChar();
if (i16RxChar >= 0)
{
au8Data[u16Length++] = u8TxFrameHandle++;
au8Data[u16Length++] = (uint8) i16RxChar;
while ((i16RxChar >= 0) && (u16Length < MAX_DATA_PER_FRAME))
{
i16RxChar = i16Serial_RxChar();
if (i16RxChar >= 0)
{
/* Set payload data */
au8Data[u16Length++] = (uint8) i16RxChar;
}
}
/* Request transmit */
(void) bNetwork_Service_Tx(WUART_SERVICE, u16Length, au8Data);
}
}
}
/****************************************************************************
*
* NAME: vWuart_RxData
*
* DESCRIPTION:
*
* PARAMETERS: Name RW Usage
* None.
*
* RETURNS:
* None.
*
* NOTES:
* None.
****************************************************************************/
PUBLIC void vWuart_RxData(uint16 u16Length, uint8 *pu8Data)
{
uint16 i;
if (pu8Data[0] == u8RxFrameHandle)
{
u8RxFrameHandle++;
/* Copy frame data to serial buffer for output on UART */
for (i = 1; i < u16Length; i++)
{
vSerial_TxChar(pu8Data[i]);
}
}
/* Must have missed a frame */
else if (pu8Data[0] > u8RxFrameHandle)
{
u8RxFrameHandle = pu8Data[0] + 1;
/* Copy frame data to serial buffer for output on UART */
for (i = 1; i < u16Length; i++)
{
vSerial_TxChar(pu8Data[i]);
}
}
/* Must be the same frame as last time */
else if (pu8Data[0] < u8RxFrameHandle)
{
/* Dont do anything as we already have the data */
}
}
/****************************************************************************/
/*** END OF FILE ***/
/****************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -