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

📄 fhspp.c

📁 ti-Chipcon CC1010 1G以下Soc源码库。包括rf,powermodes,clockmodes,flashRW,interrupts,timer,pwm,uart...所有底层驱动源码
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                            CHIPCON CC1010                    *
 *      ***   + +   ***                        FHSPP                         *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 * This file contains the implementations of all the functions from the      *
 * Frequency Hopping Simple Packet Protocol library, which is found in Cul.h,*
 * as well as some internal utility functions.                               *
 *****************************************************************************
 * Author:              OGR                                                  *
 *****************************************************************************
 * Revision history:                                                         *
 *                                                                           *
 * $Log: Fhspp.c,v $
 * Revision 1.1  2003/07/29 11:24:48  tos
 * Initial version in CVS.
 *
 *
 *                                                                           *
 ****************************************************************************/

#include <string.h>
#include <chipcon/cul.h>

xdata bool receiving = FALSE;
xdata word recvTime;
xdata bool changed = FALSE;
xdata SPP_RX_INFO xdata* recvInfo = NULL;
xdata SPP_TX_INFO xdata* sendInfo = NULL;
extern xdata byte sendBuffer[];

//----------------------------------------------------------------------------
//  void markFinished()
//
//  Description:
//      Internal function only to be used by FHSPP itself.
//      Updates the SPP_TX_INFO structure to indicate
//      that the transmission finished successfully.
//
//  Arguments:
//      None.
//          
//  Return value:
//      void
//----------------------------------------------------------------------------
void markFinished() {
	if (sendInfo) {
		sendInfo->flags ^= SPP_SEQUENCE_BIT;
		sendInfo->status = SPP_TX_FINISHED;
		sendInfo = NULL;
	}
} // end markFinished

//----------------------------------------------------------------------------
//  void receivePacket()
//
//  Description:
//      Internal function only to be used by FHSPP itself.
//      Copies an incoming message into the SPP_RX_INFO structure
//      and updates the information fields.
//
//  Arguments:
//      None.
//          
//  Return value:
//      void
//----------------------------------------------------------------------------
void receivePacket() {
	byte len = messageLength-2;
	if (recvInfo==NULL)
		return;
	if (recvInfo->maxDataLen<len)
		len = recvInfo->maxDataLen;
	recvInfo->dataLen = len;
	memcpy(recvInfo->pDataBuffer,message+2,len);
	recvInfo->flags = message[0];
	recvInfo->source = message[1];
	recvInfo->status = SPP_RX_FINISHED;
	receiving = FALSE;
	recvInfo = NULL;
} // end receivePacket

//----------------------------------------------------------------------------
//  void receiveTimeout()
//
//  Description:
//      Internal function only to be used by FHSPP itself.
//      Cancels a reception that times out.
//
//  Arguments:
//      None.
//          
//  Return value:
//      void
//----------------------------------------------------------------------------
void receiveTimeout() {
	if (changed) {
		changed = FALSE;
		recvTime = sppSettings.rxTimeout;
		sppSetTimerCB(SPP_CUSTOM_1_TIMER,receiveTimeout,&recvTime);
	} else if (recvInfo) {
		recvInfo->status = SPP_RX_TIMEOUT;
		recvInfo = NULL;
		receiving = FALSE;
	}
} // end receiveTimeout

//----------------------------------------------------------------------------
//  void updateID()
//
//  Description:
//      Internal function only to be used by FHSPP itself.
//      Updates the ID to reflect the sppSettings.
//
//  Arguments:
//      None.
//          
//  Return value:
//      void
//----------------------------------------------------------------------------
void updateID() {
	sppSettings.myAddress &= ~0x80;
	setOwnID(sppSettings.myAddress);
} // end updateID

// emulates sppSend
byte fhsppSend (SPP_TX_INFO xdata *pTXInfo) {
	if (getSendStatus()!=IDLE || receiving) return SPP_BUSY;
	setCallbackFunction(markFinished);
	sendInfo = pTXInfo;
	updateID();
	sendBuffer[0] = pTXInfo->flags;
	sendBuffer[1] = sppSettings.myAddress;
	memcpy(sendBuffer+2,pTXInfo->pDataBuffer,pTXInfo->dataLen);
	newSending(sendBuffer, pTXInfo->dataLen+2, pTXInfo->destination);
	pTXInfo->status = SPP_TX_TRANSMITTING;
	return SPP_RX_STARTED;
} // end fhsppSend

// emulates sppReceive
byte fhsppReceive (SPP_RX_INFO xdata *pRXInfo) {
	if (getSendStatus()!=IDLE || receiving) return SPP_BUSY;
	receiving = TRUE;
	updateID();
	pRXInfo->status = SPP_RX_WAITING;
	if (!changed) {
		changed = TRUE;
		receiveTimeout();
	}
	recvInfo = pRXInfo;
	setReceivingFunction(receivePacket);
	return SPP_TX_STARTED;
} // end fhsppReceive

// emulates sppStatus
byte fhsppStatus(void) {
	if (getSendStatus()!=IDLE) return SPP_TX_MODE;
	if (receiving) return SPP_RX_MODE;
	return SPP_IDLE_MODE;
} // end fhsppStatus

// emulates sppReset
void fhsppReset(void) {
	receiving = FALSE;
	cancelSending();
	if (sendInfo) {
		sendInfo->status = SPP_TX_RESET;
		sendInfo = NULL;
	}
	if (recvInfo) {
		recvInfo->status = SPP_RX_RESET;
		recvInfo = NULL;
	}
} // end fhsppReset

⌨️ 快捷键说明

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