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

📄 rfsendpacket.c

📁 ti-Chipcon CC1010 1G以下Soc源码库。包括rf,powermodes,clockmodes,flashRW,interrupts,timer,pwm,uart...所有底层驱动源码
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                            CHIPCON CC1010                    *
 *      ***   + +   ***                   HAL - RFSendPacket                 *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 *                                                                           *
 *****************************************************************************
 * Author:              ROH                                                  *
 *****************************************************************************
 * Revision history:                                                         *
 *                                                                           *
 * $Log: RFSendPacket.c,v $
 * Revision 1.1  2002/10/14 13:04:34  tos
 * Initial version in CVS.
 *
 *                                                                           *
 ****************************************************************************/

#include <chipcon/hal.h>

#define CRC16_POLY 0x1021
#define CRC16_INIT 0xFFFF
#define CRC_OK     0

//----------------------------------------------------------------------------
//  void halRFSendPacket(...)
//
//  Description:
//      Used to send a packet using the current RF configuration. (It is
//      assumed that halRFSetRxTxOff(...) has been called with the appropriate
//      RX/TX pair and mode RF_TX.) First _numPreambles_ preamble bytes
//      (RF_PREAMBLE_BYTE) are transmitted followed by a synchronization byte
//      (RF_SUITABLE_SYNC_BYTE), the _length_ byte, the data
//      pointed to by _packetData_ (_length_ bytes) and then, finally, the 
//      CRC-16 (CCITT) of the data.
//
//  Arguments:
//      byte numPreambles
//          The number of preamble bytes (RF_PREAMBLE_BYTE) to transmit.
//      byte* packetData
//          A pointer to the actual data to transmit.
//      byte length
//          The number of bytes to transmit. (Max 253)
//
//  Return value:
//      void
//----------------------------------------------------------------------------
void halRFSendPacket(byte numPreambles, byte* packetData, byte length) {
    byte crcData, i;
    word crcReg;

    // Set the first byte to transmit & turn on TX                    
    RFCON|=0x01;                        // Ensure that bytemode is selected
    RF_SEND_BYTE(RF_PREAMBLE_BYTE);         
    RF_START_TX();
    
    // Send remaining preambles
    while (--numPreambles)
        RF_WAIT_AND_SEND_BYTE(RF_PREAMBLE_BYTE);

    // Send sync byte + length byte
    RF_WAIT_AND_SEND_BYTE(RF_SUITABLE_SYNC_BYTE);
    RF_WAIT_AND_SEND_BYTE(length);
    crcReg=CRC16_INIT;

    // Send data
    while (length--) {
        crcData=*packetData++;

        // Update CRC
        RF_WAIT_AND_SEND_BYTE(crcData);
      	for (i=0; i<8; i++) {
    		if ( ((crcReg&0x8000)>>8) ^ (crcData&0x80) )
    			crcReg=(crcReg<<1)^CRC16_POLY;
    		else
    			crcReg=(crcReg<<1);
    		crcData<<=1;
    	}
    }

    // Send CRC-16
    RF_WAIT_AND_SEND_BYTE((crcReg>>8)&0xFF);
    RF_WAIT_AND_SEND_BYTE(crcReg&0xFF);
    
    // Send extra byte + 1 bit to empty buffer
    RF_WAIT_AND_SEND_BYTE(0);
    while (!RF_READY_TO_SEND());    
    RFCON&=~0x01;                        // Ensure that bitmode is selected
    
}    

 

⌨️ 快捷键说明

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