亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? spp.c

?? CC2430多功能調試程序
?? C
字號:
/******************************************************************************
Filename:     spp.c
Target:       cc2430
Revised:      16/12-2005
Revision:     1.0
******************************************************************************/
#include <string.h>
#include "cul.h"
#include <stdio.h>

// protos
void rxCallBack(void);
void ackTimeout(void);
BOOL ackReceived(BYTE sourceAddress);
void sendAck(SPP_RX_STRUCT* receivedPacket);
void waitForAck(void);


static DMA_DESC* dmaTx;          // pointer to the DMA descriptor for transmit.
static DMA_DESC* dmaRx;          // pointer to the DMA descriptor for receive.
static BYTE dmaNumberTx = 0;     // number indicating which DMA channel is used for transmit.
static BYTE dmaNumberRx = 0;     // number indicating which DMA channel is used for receive.
static BYTE myAddress;
volatile BYTE sppRxStatus = 0;
volatile BYTE  sppTxStatus = 0;
static BYTE pAckBuffer[7];
static SPP_TX_STRUCT* pAckData;
static volatile UINT8 retransmissionCounter;
static UINT8 ackTimerNumber;
static FUNCTION* rxCallBackFunction;


//-----------------------------------------------------------------------------
// See cul.h for a description of this function.
//-----------------------------------------------------------------------------
void sppSetRxCallBackFunction(FUNCTION* callBackFunction)
{
   rxCallBackFunction = callBackFunction;
} // Ends sppSetRxCallBackFunction()




void sendAck(SPP_RX_STRUCT* receivedPacket)
{
   RFD = SPP_HEADER_AND_FOOTER_LENGTH + SPP_ACK_LENGTH;
   RFD = receivedPacket->srcAddress;
   RFD = myAddress;
   RFD = ACK;
   RFD = 0;
   RFIF &= ~IRQ_TXDONE;
   ISTXON;
   while(!(RFIF & IRQ_TXDONE));

   return;
}

//------------------------------------------------------------------------------------------------------
// void rxCallBack(...)
//
//  Description:
//      This function is called by the interrupt routine when the Rx DMA channel
//      finishes the data transfer. The received packet's destination address
//      is checked. If not addressed to this node, or if the CRC value is not
//      correct, the packet is erased. An ACK is sent if the packet
//      tells to. A user defined callback function may is run if set (set
//      with setRxCallBackFunction())
//
//  Arguments:
//      void
//
//  Return value:
//      void
//-----------------------------------------------------------------------------
void rxCallBack(void)
{
   SPP_RX_STRUCT __xdata* receivedPacket;
   BYTE res = FALSE;

   if(RXFIFOCNT > 0)
   {
      ISFLUSHRX;
      ISFLUSHRX;
   }

   // Investigating the received packet.
   // Checking the destination address and that the CRC is OK.
   // The message is ACK'ed if it tells to.
   receivedPacket = (SPP_RX_STRUCT __xdata*) GET_DMA_DEST(dmaRx);
   receivedPacket->payloadLength = receivedPacket->payloadLength-SPP_HEADER_AND_FOOTER_LENGTH;

   if((receivedPacket->destAddress == myAddress) || (receivedPacket->destAddress == BROADCAST_ADDRESS))
   {
      if(receivedPacket->payload[receivedPacket->payloadLength+1] & 0x80)
      {
         if(receivedPacket->flags == ACK)
         {
            res = ackReceived(receivedPacket->srcAddress);
         }
         else
         {
            sppRxStatus = PACKET_RECEIVED;
            res = TRUE;
            if(receivedPacket->flags & DO_ACK)
            {
               sendAck(receivedPacket);
            }
            sppRxStatus = RX_COMPLETE;
            if(rxCallBackFunction)
            {
               rxCallBackFunction();
            }
         }
      }
   }

   if(res == FALSE)
   {
      ISFLUSHRX;
      ISFLUSHRX;

      // rearming DMA channel
      DMA_ARM_CHANNEL(dmaNumberRx);
      RFIM |= IRQ_SFD;
      sppRxStatus = RX_WAIT;
   }
   return;
}   // ends rxCallBack




//-----------------------------------------------------------------------------
// void ackTimeout(...)
//
//  Description:
//      This function resends a packet if it is not ACK'ed by the recipient
//      within _ACK_TIMEOUT_ m-seconds. The message is resent _ACK_RETRIES_ times.
//      If the message remains un-ACK'ed, transmission is aborted and spp TX
//      status is set to DEST_UNREACHABLE.
//
//  Arguments:
//      void
//
//  Return value:
//      void
//-----------------------------------------------------------------------------
void ackTimeout(void){
   culTimer4AdmClear(ackTimerNumber);

   if(pAckData != NULL)
   {
      if(retransmissionCounter < ACK_RETRIES)
      {
         // Resending the message.
         pAckData->flags |= RETRANSMISSION;

         TIMER4_RUN(FALSE);

         sppSend(pAckData);

         T4CNT = 0;
         TIMER4_RUN(TRUE);

         retransmissionCounter++;
      }
      else
      {
         // The packet has been resent too many times. Assuming that the node is unreacheble.
         pAckData = 0;
         retransmissionCounter = 0;
         sppTxStatus = DEST_UNREACHABLE;
         RFIM &= ~IRQ_FIFOP;
      }
   }
   return;
} // ends ackTimeout




//-----------------------------------------------------------------------------
// See cul.h for a description of this function.
//-----------------------------------------------------------------------------
BOOL sppInit(UINT32 frequency, BYTE address){
   BYTE res = 0;
   BOOL status = TRUE;

   sppSetAddress(address);

   // Clearing the states of the spp.
   sppTxStatus = TX_IDLE;
   sppRxStatus = RX_IDLE;
   retransmissionCounter = 0;
   ackTimerNumber = 0;
   pAckData = 0;

   // Clearing the RF interrupt flags and enable mask and enabling RF interrupts
   RFIF = 0;
   RFIM = 0;
   INT_SETFLAG(INUM_RF,INT_CLR);
   INT_ENABLE(INUM_RF,INT_ON);

   // Setting the frequency and initialising the radio
   res = halRfConfig(frequency);
   if(res == FALSE){
      status = FALSE;
   }

   // Setting the number of bytes to assert the FIFOP flag
   IOCFG0 = 7;

   INT_SETFLAG(INUM_RFERR, INT_CLR);
   INT_ENABLE(INUM_RFERR, INT_ON);

   // Flushing both Tx and Rx FiFo. The flush-Rx is issued twice to reset the SFD.
   // Calibrating the radio and turning on Rx to evaluate the CCA.
   SRXON;
   SFLUSHTX;
   SFLUSHRX;
   SFLUSHRX;
   STXCALN;
   ISSTART;


   // Using the timer 4 administrator to generate interrupt to check if a message is unacked...
   culTimer4AdmInit();

   // Initialising the DMA administrator
   culDmaInit();

   // Requesting a DMA channel for transmit data. No callback function is used. Instead the TX_DONE
   // interrupt is used to determine when a transfer is finished. Configuring the DMA channel for
   // transmit. The data address and length will be set prior to each specific transmission.
   dmaTx = culDmaAllocChannel(&dmaNumberTx, 0);
   if((dmaNumberTx == 0) || (dmaNumberTx > 4)){
      status = FALSE;
   }

   culDmaToRadio(dmaTx, 0, 0, FALSE);

   // Requesting a DMA channel for receiving data. Giving the address of the callback function.
   // Configuring the DMA channel for receive. The data address will be set prior to each specific
   // reception.
   dmaRx = culDmaAllocChannel(&dmaNumberRx, &rxCallBack);
   if((dmaNumberRx == 0) || (dmaNumberRx > 4)){
      status = FALSE;
   }
   culDmaFromRadio(dmaRx, 0, TRUE);

   // Making sure that none of the channels are armed.
   DMA_ABORT_CHANNEL(dmaNumberRx);
   DMA_ABORT_CHANNEL(dmaNumberTx);
   INT_ENABLE(INUM_DMA, INT_ON);

   return status;
} // ends sppInit




//-----------------------------------------------------------------------------
// See cul.h for a description of this function.
//-----------------------------------------------------------------------------
void sppSetAddress(BYTE address){
   myAddress = address;
} // Ends sppSetAddress()




// Internal function which enables the timeout when waiting for an ACK.
void waitForAck(void)
{
   ackTimerNumber = culTimer4AdmSet(ACK_TIMEOUT, &ackTimeout);
   SET_DMA_DEST(dmaRx,pAckBuffer);
   SET_DMA_LENGTH(dmaRx,7);

}   // Ends waitForAck()




//-----------------------------------------------------------------------------
// See cul.h for a description of this function.
//-----------------------------------------------------------------------------
BYTE sppSend(SPP_TX_STRUCT* pPacketPointer){
   BYTE res = TRUE;

   // If data is to be transmitted, the DMA is set up.
   if(pPacketPointer->payloadLength)
   {
      if (pPacketPointer->payloadLength > SPP_MAX_PAYLOAD_LENGTH)
      {
         res = TOO_LONG;
         sppTxStatus = TX_IDLE;
      }
      else
      {
         // Setting up the DMA
         DMA_ABORT_CHANNEL(dmaNumberTx);
         SET_DMA_SOURCE(dmaTx,pPacketPointer->payload);
         SET_DMA_LENGTH(dmaTx,pPacketPointer->payloadLength);
      }
   }

   // Proceed if the packet length is OK.
   if (res == TRUE)
   {
      // Flipping the sequence bit if the transfer is not a retransmission.
      if(!(pPacketPointer->flags & RETRANSMISSION))
      {
         pPacketPointer->flags ^= SEQUENCE_BIT;
      }

      // Clearing RF interrupt flags and enabling RF interrupts.
      if(FSMSTATE == 6 && RXFIFOCNT > 0)
      {
         ISFLUSHRX;
         ISFLUSHRX;
      }

      RFIF &= ~IRQ_TXDONE;
      RFIM &= ~IRQ_SFD;
      INT_SETFLAG(INUM_RF, INT_CLR);

      // Writing the total packet length, addresses and flags to Tx FiFo.
      // Transferring the payload if any.
      RFD = (pPacketPointer->payloadLength + SPP_HEADER_AND_FOOTER_LENGTH);
      RFD = pPacketPointer->destAddress;
      RFD = myAddress;
      RFD = pPacketPointer->flags;
      if(pPacketPointer->payloadLength)
      {
         DMA_ARM_CHANNEL(dmaNumberTx);
         DMA_START_CHANNEL(dmaNumberTx);
      }

      // If the RSSI value is not valid, enable receiver
      if(RSSIL == 0x80)
      {
         ISRXON;
         // Turning on Rx and waiting 320u-sec to make the RSSI value become valid.
         halWait(1);
      }

      //Transmitting
      ISTXONCCA;
      //if(TX_ACTIVE)
      if(FSMSTATE > 30)
      {
         // Asserting the status flag and enabling ACK reception if expected.
         sppTxStatus = TX_IN_PROGRESS;

         if(pPacketPointer->flags & DO_ACK)
         {
            pAckData = pPacketPointer;
            DMA_ABORT_CHANNEL(dmaNumberRx);
            waitForAck();
         }
         else
         {
            pAckData = NULL;
         }
         RFIM |= IRQ_TXDONE;
      }
      else
      {
         ISFLUSHTX;
         res = CHANNEL_BUSY;
         RFIM &= ~IRQ_TXDONE;
         // De-flipping the sequence bit.
         if(!(pPacketPointer->flags & RETRANSMISSION))
         {
            pPacketPointer->flags ^= SEQUENCE_BIT;
         }
      }
   }
   return res;
} // ends sppSend




// Internal function which is called when an ack is received.
// If the ACK is from the expected node, the retransmission of the packet is cancelled.
BOOL ackReceived(BYTE sourceAddress)
{
   BOOL res = FALSE;
   if(sourceAddress == pAckData->destAddress)
   {
      res = TRUE;
      culTimer4AdmClear(ackTimerNumber);
      sppTxStatus = TX_SUCCESSFUL;
      retransmissionCounter = 0;
      pAckData = 0;
   }

   return res;
}  //Ends ackReceived()



//-----------------------------------------------------------------------------
// See cul.h for a description of this function.
//-----------------------------------------------------------------------------
#pragma vector=RF_VECTOR
__interrupt void spp_rf_IRQ(void)
{
   BYTE enabledAndActiveInterrupt;

   INT_GLOBAL_ENABLE(INT_OFF);
   enabledAndActiveInterrupt = RFIF;
   RFIF = 0x00;                        // Clear all interrupt flags
   INT_SETFLAG(INUM_RF, INT_CLR);    // Clear MCU interrupt flag
   enabledAndActiveInterrupt &= RFIM;

   // Start of frame delimiter (SFD)
   if(enabledAndActiveInterrupt & IRQ_SFD)
   {
      if(sppRxStatus == RX_WAIT)
      {
         sppRxStatus = RX_IN_PROGRESS;
         RFIM &= ~IRQ_SFD;
      }
   }

   // Transmission of a packet is finished. Enabling reception of ACK if required.
   if(enabledAndActiveInterrupt & IRQ_TXDONE)
   {
      if(sppTxStatus == TX_IN_PROGRESS)
      {
         if(pAckData == NULL)
         {
            sppTxStatus = TX_SUCCESSFUL;
         }
         else
         {
            DMA_ARM_CHANNEL(dmaNumberRx);
         }
      }

      // Clearing the tx done interrupt enable
      RFIM &= ~IRQ_TXDONE;

   }
   INT_GLOBAL_ENABLE(INT_ON);
}





//-----------------------------------------------------------------------------
// See cul.h for a description of this function.
//-----------------------------------------------------------------------------
void sppReceive(SPP_RX_STRUCT* pReceiveData){

   sppRxStatus = RX_WAIT;

   DMA_ABORT_CHANNEL(dmaNumberRx);
   // Setting the address to where the received data are to be written.
   SET_DMA_DEST(dmaRx,pReceiveData);
   SET_DMA_LENGTH(dmaRx,255);

   // Arming the DMA channel. The receiver will initate the transfer when a packet is received.
   DMA_ARM_CHANNEL(dmaNumberRx);

   if(FSMSTATE == 6 && RXFIFOCNT > 0)
   {
      ISFLUSHRX;
      ISFLUSHRX;
   }

   // Turning on the receiver
   ISRXON;

   return;
}



//-----------------------------------------------------------------------------
// See cul.h for a description of this function.
//-----------------------------------------------------------------------------
#pragma vector=RFERR_VECTOR
__interrupt static void rf_error_IRQ(void)
{
   INT_GLOBAL_ENABLE(INT_OFF);

   // If Rx overflow occurs, the Rx FiFo is reset.
   // The Rx DMA is reset and reception is started over.
   if(FSMSTATE == 17)
   {
      STOP_RADIO();
      ISFLUSHRX;
      ISFLUSHRX;
      DMA_ABORT_CHANNEL(dmaNumberRx);
      DMA_ARM_CHANNEL(dmaNumberRx);
      ISRXON;
   }
   else if(FSMSTATE == 56)
   {
      ISFLUSHTX;
   }

   INT_SETFLAG(INUM_RFERR,INT_CLR);

   INT_GLOBAL_ENABLE(INT_ON);
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩国产一二三区| 最新欧美精品一区二区三区| 丝袜诱惑制服诱惑色一区在线观看| www.日韩av| 亚洲精品美国一| 欧美日韩激情在线| 另类小说欧美激情| 国产亚洲1区2区3区| 99亚偷拍自图区亚洲| 亚洲高清在线精品| 日韩午夜中文字幕| 国产精品性做久久久久久| 久久精品男人的天堂| 99国产精品久久久| 午夜久久久久久久久| 精品国产乱码久久久久久牛牛| 国产黄人亚洲片| 一区二区三区四区不卡在线| 日韩亚洲欧美一区二区三区| 国产成人综合在线观看| 亚洲精品国产无套在线观| 欧美高清一级片在线| 国产精品一区二区久激情瑜伽 | 免费精品99久久国产综合精品| 欧美一区二区三区白人| 欧美喷水一区二区| 久久国产精品第一页| 国产精品色哟哟| 欧美性猛交xxxxxxxx| 国产在线视频一区二区三区| 自拍偷拍欧美精品| 日韩精品一区在线| 在线一区二区视频| 国产精品自拍在线| 亚洲动漫第一页| 欧美极品少妇xxxxⅹ高跟鞋 | 免费欧美高清视频| 亚洲天堂网中文字| 精品成人免费观看| 欧美日韩免费观看一区三区| 国产大陆精品国产| 美女视频黄久久| 亚洲自拍另类综合| 国产精品麻豆一区二区| 精品美女在线播放| 欧美日韩国产一区| 91麻豆国产精品久久| 国产一区二区主播在线| 婷婷综合另类小说色区| 国产精品成人一区二区艾草| 26uuu亚洲综合色欧美| 6080午夜不卡| 欧美性一级生活| 成人av免费在线观看| 国产主播一区二区| 日本网站在线观看一区二区三区| 伊人色综合久久天天人手人婷| 欧美激情在线观看视频免费| 3d动漫精品啪啪| 欧美无砖砖区免费| 91一区二区三区在线观看| 国产福利一区二区三区| 免费看日韩a级影片| 亚洲国产wwwccc36天堂| 久久99久久99精品免视看婷婷| 一级特黄大欧美久久久| 日韩一区日韩二区| 国产精品嫩草久久久久| 国产日韩在线不卡| 久久人人超碰精品| 亚洲精品一区在线观看| 欧美电视剧在线看免费| 日韩美一区二区三区| 日韩欧美二区三区| 日韩精品影音先锋| 久久日一线二线三线suv| 精品国产百合女同互慰| 久久夜色精品国产噜噜av | 成人国产免费视频| 国产激情视频一区二区在线观看 | 成人av在线看| 91亚洲精品久久久蜜桃| 97国产精品videossex| 99精品在线免费| 不卡的电影网站| 色诱视频网站一区| 欧美在线免费播放| 欧美久久久影院| 日韩网站在线看片你懂的| 日韩一区二区高清| 日韩欧美一级片| 久久久久亚洲蜜桃| 亚洲欧洲色图综合| 性久久久久久久久久久久| 日本va欧美va精品| 国产成人综合网站| 暴力调教一区二区三区| 欧美羞羞免费网站| 欧美xxxxx牲另类人与| 久久精品视频一区| 亚洲人成7777| 青娱乐精品视频在线| 国产乱码精品一区二区三| 99热国产精品| 3751色影院一区二区三区| 亚洲福利视频一区| 久久激情五月激情| 99视频热这里只有精品免费| 欧美私人免费视频| 亚洲精品一区二区三区在线观看| 中文字幕视频一区| 亚洲不卡在线观看| 国产福利精品导航| 91超碰这里只有精品国产| 国产午夜精品在线观看| 亚洲综合久久久久| 国产精品456露脸| 欧美网站一区二区| 久久精品一区二区三区不卡| 一区二区三区四区视频精品免费| 欧美aaa在线| 91浏览器打开| 精品精品国产高清a毛片牛牛| 日韩美女久久久| 精品中文av资源站在线观看| 色狠狠一区二区三区香蕉| 欧美精品一区二区精品网| 亚洲综合在线五月| 成人在线综合网| 91精品国产手机| 亚洲欧美一区二区三区极速播放 | 欧美大片免费久久精品三p| 日韩理论在线观看| 美国欧美日韩国产在线播放| 在线观看国产日韩| 国产午夜三级一区二区三| 蜜臀av在线播放一区二区三区| 91亚洲国产成人精品一区二区三| 欧美第一区第二区| 五月综合激情婷婷六月色窝| 不卡的电影网站| 国产喂奶挤奶一区二区三区| 首页国产丝袜综合| 欧美中文一区二区三区| 国产精品国产三级国产aⅴ原创| 蜜臀av性久久久久蜜臀aⅴ| 91福利在线看| 亚洲视频小说图片| 成人午夜视频在线观看| 久久久久久9999| 精品一区二区三区欧美| 91精品国产福利在线观看| 亚洲国产色一区| 欧美色图一区二区三区| 自拍偷拍亚洲激情| 92国产精品观看| 中文字幕在线一区二区三区| 国产精品一区二区三区四区| 欧美精品123区| 首页综合国产亚洲丝袜| 欧美三级韩国三级日本一级| 亚洲人成网站影音先锋播放| 成人动漫一区二区在线| 亚洲国产精品激情在线观看| 国产精品原创巨作av| 久久久精品人体av艺术| 寂寞少妇一区二区三区| 精品国免费一区二区三区| 久久不见久久见免费视频7| 日韩亚洲欧美成人一区| 捆绑调教美女网站视频一区| 日韩欧美在线综合网| 久久激情综合网| 国产色综合久久| 成人短视频下载| 亚洲欧美日韩人成在线播放| 91麻豆免费观看| 午夜国产不卡在线观看视频| 欧美理论在线播放| 另类中文字幕网| 国产亚洲欧洲一区高清在线观看| 国产91精品露脸国语对白| 国产精品国产精品国产专区不蜜| av亚洲精华国产精华精| 亚洲免费电影在线| 欧美日本在线看| 欧美性xxxxxx少妇| 麻豆国产91在线播放| 久久天堂av综合合色蜜桃网| 成人午夜视频免费看| 亚洲欧美偷拍另类a∨色屁股| 欧美私人免费视频| 久草这里只有精品视频| 欧美激情综合网| 在线免费一区三区| 久久激情综合网| 亚洲人成7777| 欧美精品日韩一区| 国产91清纯白嫩初高中在线观看| 一区二区三区中文字幕在线观看|