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

📄 radio.c

📁 CC1110点对多点FDMA传输方式C源码
💻 C
字号:
/******************************************************************************
*                                                                             *
*    ****       ******       ****
*     ****     ********     ****
*      ****   ****  ****   ****
*       **** ****    **** ****              wxl
*        *******      *******
*         *****        *****                    成都无线龙通讯科技有限公司
*                                                                             *
*******************************************************************************
Target:       cc1110                          使用芯片:       cc1110
Author:       WXL                             程 序 员:      无线龙
data:         1/12-2007                       日    期:      1/12-2007
******************************************************************************/
/**********************************头文件**************************************/
#include <string.h>
#include "cul.h"

extern volatile BYTE sppRxStatus;
extern volatile BYTE sppTxStatus;
SPP_STRUCT rxData;
SPP_STRUCT txData;

//-----------------------------------------------------------------------------
// See cul.h for a description of this function.
//-----------------------------------------------------------------------------
void radioInit(UINT32 frequency, BYTE localAddress,int state)
{
   sppInit(frequency,localAddress,state);

   return;
}


//-----------------------------------------------------------------------------
// See cul.h for a description of this function.
//-----------------------------------------------------------------------------
BOOL radioSend(BYTE* transmitData, WORD dataLength, BYTE remoteAddress, BYTE doAck)
{
   WORD sent = 0;
   BOOL status = TRUE;
   WORD remaining;
   BYTE retries;
   BYTE res;
   UINT8 timeOut;
   txData.destAddress = remoteAddress;
   txData.flags = doAck;


   while((sent < dataLength) && (status == TRUE))
   {
      retries = ACK_RETRIES;
      remaining = dataLength-sent;


      if(remaining > SPP_MAX_PAYLOAD_LENGTH)
      {
         memmove(txData.payload, transmitData + sent, SPP_MAX_PAYLOAD_LENGTH);
         txData.payloadLength = SPP_MAX_PAYLOAD_LENGTH;
         sent += SPP_MAX_PAYLOAD_LENGTH;
      }
      else
      {
         memmove(txData.payload, transmitData + sent, dataLength);
         txData.payloadLength = dataLength;
         sent += dataLength;
      }

      while(retries)
      {
         res = sppSend(&txData);
         if(res == CHANNEL_BUSY)
         {
            halWait(10);
            retries--;
            if(retries == 0)
            {
               status = FALSE;
            }
         }
         else
         {
            retries = 0;
         }
      }
      timeOut = (ACK_TIMEOUT << 3);
      while((sppTxStatus == TX_IN_PROGRESS) && timeOut)
      {
        halWait(1);
        if(!(--timeOut)){
          sppTxStatus = DEST_UNREACHABLE;
        }
      }


      if(sppTxStatus == DEST_UNREACHABLE)
      {
         status = FALSE;
      }
   }

   return status;
}





//-----------------------------------------------------------------------------
// See cul.h for a description of this function.
//-----------------------------------------------------------------------------
BOOL radioReceive(BYTE** receiveData, BYTE* length, WORD timeout, BYTE* sender)
{
   BOOL status = TRUE;
   BOOL continueWaiting = TRUE;
   BOOL useTimeout = FALSE;

   if(timeout)
   {
      useTimeout = TRUE;
   }



   sppReceive(&rxData);

   while((sppRxStatus != RX_COMPLETE) && (continueWaiting))
   {
      if(useTimeout)
      {
         halWait(0x01);
         timeout--;
         if(timeout == 0)
         {
            continueWaiting = FALSE;
            status = FALSE;
         }
      }
   }

   if(status == TRUE)
   {
      *receiveData = rxData.payload;
      *length = rxData.payloadLength;
      *sender = rxData.srcAddress;
   }

   return status;
}

⌨️ 快捷键说明

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