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

📄 rf_test.c

📁 ti-Chipcon CC2430 zigbee Soc应用开发源码实例。包括rf,powermodes,clockmodes底层驱动源码。有了这些实例,包括误码率测试等。对你更好的理解和应用这颗芯片
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
*                                                                             *
*        **********                                                           *
*       ************                                                          *
*      ***        ***                                                         *
*     ***    ++    ***                                                        *
*     ***   +  +   ***                      CHIPCON                           *
*     ***   +                                                                 *
*     ***   +  +   ***                                                        *
*     ***    ++    ***                                                        *
*      ***        ***                                                         *
*       ************                                                          *
*        **********                                                           *
*                                                                             *
*******************************************************************************

Filename:     rf_test.c
Target:       cc2430
Author:       efu
Revised:      30/5-2007
Revision:     1.2

Description:
    This file provides 4 small tests which demonstrates use of the radio.

******************************************************************************/

/******************************************************************************
 * INCLUDES
 */
#include "app_ex.h"
#include "cul.h"
#include "pingPong.h"

/******************************************************************************
 * CONSTANTS
 */
#define ADDRESS_0                     0x01
#define ADDRESS_1                     0x02

#define SEND                             0
#define RECEIVE                          1

#define SINGLE                           0
#define CONTINUOUS                       1
#define PING_PONG                        2
#define PER_TEST                         3
#define EXIT                             4

#define RECEIVE_TIMEOUT               1200

#define PING_PONG_TIMEOUT             1200
#define PING_PONG_REQUEST             0x80
#define PING_PONG_RESPONSE            0x40

#define PER_RECEIVE_TIMEOUT            100
#define PER_TOTAL_PACKET_NUMBER       1000
#define PER_TEST_REQUEST              0x20

/******************************************************************************
 * TYPEDEFS
 */

/******************************************************************************
 * GLOBAL VARIABLES
 */

/******************************************************************************
 * LOCAL VARIABLES
 */
uint8  RxTxState;
uint8  myAddr;
uint8  remoteAddr;
bool   remoteAddressSet;
bool   myAddressSet;
uint32 frequency;

/******************************************************************************
 * LOCAL FUNCTIONS
 */
void initRfTest(void);
void rf_test_main(void);
void receivePacket(uint8 *receiveByte);
void sendPacket(uint8 sendByte);
void printAddress(uint8 address);
void printRSSI(int8 rssi);
uint32 getFrequency(void);
uint8 getAddress(uint8 a);
void receiveMode(void);
void singleMode(void);
void contionuousMode(void);
void pingPongMode(void);
void perTestMode(void);
void showState(void);
void conductPerTest(void);
void pingPongResponse(void);



/******************************************************************************
* @fn  initRfTest
*
* @brief
*      Initializes components for the RF test application example.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void initRfTest(void)
{
   char *menuText[] = {(char *)" Sender?", (char *)" Receiver?", (char *)" Set Freq?", (char *)" Set MyAddr?", (char *)" Set RemoteAddr?"};

   byte result;
   frequency = 2405000;


   initLcd();

   INIT_JOYSTICK();
   INIT_BUTTON();
   INIT_GLED();
   INIT_YLED();

   SET_MAIN_CLOCK_SOURCE(CRYSTAL);

   remoteAddressSet = FALSE;
   myAddressSet = FALSE;


   while((result = lcdMenu(menuText, 5)) > 1)
   {
      if(result == 2)
      {
         frequency = getFrequency();
      }
      else if(result == 3)
      {
         lcdUpdate((char *)"Set myAddress",(char *)"");
         myAddr = getAddress(myAddr);
         myAddressSet = TRUE;
      }
      else if(result == 4)
      {
         lcdUpdate((char *)"Set remoteAddr",(char *)"");
         remoteAddr = getAddress(remoteAddr);
         remoteAddressSet = TRUE;
      }
      else
      { // ABORT_MENU
         return;
      }
   }

   if(result == 1) // Receiver
   {
      RxTxState = RECEIVE;
      if(myAddressSet == FALSE)
      {
         myAddr = ADDRESS_1;
      }
      if(remoteAddressSet == FALSE)
      {
         remoteAddr = ADDRESS_0;
      }
   }
   else // Sender
   {
      RxTxState = SEND;
      if(myAddressSet == FALSE)
      {
         myAddr = ADDRESS_0;
      }
      if(remoteAddressSet == FALSE)
      {
         remoteAddr = ADDRESS_1;
      }
      lcdUpdate((char *)"Sender",(char *)"");
      waitVisible(CLEARLY_VISIBLE);
   }
   radioInit(frequency, myAddr);
}


/******************************************************************************
* @fn  rf_test_main
*
* @brief
*      Main function.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
#ifdef COMPLETE_APPLICATION
void rf_test_main(void){
#else
void main(void){
#endif
   uint8 mode = 0;
   char *menuText[] = {(char *)" Single?", (char *)" Continuous?", (char *)" PingPong?", (char *)" PER Test?"};

   while(getJoystickDirection() != CENTRED);
   initRfTest();

   // Turning on interrupts
   INT_GLOBAL_ENABLE(INT_ON);

   while( !stopApplication() )
   {
      // If set up as slave, the unit will only be in receive
      if(RxTxState == RECEIVE)
      {
         lcdUpdate((char *)"Receive",(char *)"Node");
         waitVisible(CLEARLY_VISIBLE);
         receiveMode();
         return;
      }
      else
      {
         mode = lcdMenu(menuText, 4);

         switch (mode){
         case SINGLE:
            lcdUpdate((char *)"Single mode", (char *)"");
            waitVisible(CLEARLY_VISIBLE);
            singleMode();
            break;

         case CONTINUOUS:
            lcdUpdate((char *)"Continuous Mode", (char *)"");
            waitVisible(CLEARLY_VISIBLE);
            contionuousMode();
            break;

         case PING_PONG:
            lcdUpdate((char *)"Ping Pong Mode", (char *)"");
            waitVisible(CLEARLY_VISIBLE);
            pingPongMode();
            break;

         case PER_TEST:
            lcdUpdate((char *)"PER Mode", (char *)"");
            waitVisible(CLEARLY_VISIBLE);
            perTestMode();
            break;

         case ABORT_MENU:
            return;
         }
      }
      while(getJoystickDirection() != CENTRED);
      GLED = YLED = LED_OFF;
   }

   STOP_RADIO();
   return;
}


/******************************************************************************
* @fn  singleMode
*
* @brief
*      Function for transferring one packet
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void singleMode(void)
{
   char *singleMenu[] = {(char *)" Send?"};
   byte sendBuffer[] = {0x01, 0x02, 0x03, 0x04, 0x05};
   bool res;

   while( lcdMenu(singleMenu, 1) == 0 )
   {
     YLED = LED_ON;
     res = radioSend(sendBuffer, sizeof(sendBuffer), remoteAddr, DO_ACK);
     YLED = LED_OFF;

     if(res == TRUE)
     {
       lcdUpdateLine(LINE1, (char *)"OK!");
     }
     else
     {
       lcdUpdateLine(LINE1, (char *)"Failed...");
     }
     waitVisible(CLEARLY_VISIBLE);
   }
}


/******************************************************************************
* @fn  contionuousMode
*
* @brief
*      Function for transferring packets until stopped by user.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void contionuousMode(void)
{
   bool res;
   byte sendBuffer[] = {0x01, 0x02, 0x03, 0x04, 0x05};
   showState();

   while( !stopApplication() )
   {
      YLED = LED_ON;
      res = radioSend(sendBuffer, sizeof(sendBuffer), remoteAddr, DO_ACK);
      YLED = LED_OFF;

      if(res == TRUE)
      {
         lcdUpdateLine(LINE1, (char *)"OK!");
      }
      else
      {
         lcdUpdateLine(LINE1, (char *)"Failed...");
      }
      waitVisible(CLEARLY_VISIBLE);
   }
}


/******************************************************************************
* @fn  pingPongMode
*
* @brief
*      Function for sending packets between two nodes.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
void pingPongMode(void)
{
  bool res;
  byte sendBuffer = PING_PONG_REQUEST;
  byte* buffer;
  byte length;
  byte sender;

  pingPongInit();

  while( !stopApplication() )
  {
    YLED = LED_ON;

⌨️ 快捷键说明

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