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

📄 rfcom.c

📁 RF tranceiver MSP430F1611+CC2420 with FreeRTOS
💻 C
字号:
/*******************************************************************************************************
 *                                                                                                     *
 *        **********                                                                                   *
 *       ************                                                                                  *
 *      ***        ***                                                                                 *
 *      ***   +++   ***                                                                                *
 *      ***   + +   ***                                                                                *
 *      ***   +                                   CHIPCON CC2420DBK EXAMPLES                           *
 *      ***   + +   ***                  RF Blinking LED Demo - Application Note 033                   *
 *      ***   +++   ***                                                                                *
 *      ***        ***                                                                                 *
 *       ************                                                                                  *
 *        **********                                                                                   *
 *                                                                                                     *
 *******************************************************************************************************
 * This program demonstrates the use of the CC2420DB library, including the basic RF library. The      *
 * packet protocol being used is a small subset of the IEEE 802.15.4 standard. It uses an 802.15.4 MAC *
 * compatible frame format, but does not implement any other MAC functions/mechanisms (e.g. CSMA-CA).  *
 * The basic RF library can thus not be used to communicate with compliant 802.15.4 networks.          *
 *                                                                                                     *
 * A MSP430F1611 running this program will establish a point-to-point RF link on channel 26 with       *
 * a CC2420DB using the following node addresses:                                                      *
 * - PAN ID: 0x2420 (both nodes)                                                                       *
 * - Short address:                                                                                    *
 *		0x5678                                                                  	       *
 * Destination address: 0x1234                                                                         *
 *                                                                                                     *
 * This application is intended to work with the blinking LED application on a CC2420DB.               *
 * The pot-meter on the CC2420DB can be used to change the blinking frequency of the diode on          *
 * the MSP-FET430P140 board.                                                                           *
 * Please note that there is no so-called (PAN) coordinator.                                           *
 *                                                                                                     *
 * INSTRUCTIONS:                                                                                       *
 * Outgoing data packets containing a 10-byte payload will be transmitted each 50th cycle of the       *
 * main program loop. Byte 0 contains the LED dimmer value to the CC2420DBB, byte 1 contains the       *
 * status byte from CC2420 and bytes 2/3 the number of packets received from the CC2420DB.             *
 * This application uses the value of byte 0 FROM the CC2420DB to regulate the blinking frequency of   *
 * the LED on the MSP-FET430P140.                                                                      *                                                                                                     *
 * This example is based on the blinking LED example for the CC2420DB board.                           *
 *******************************************************************************************************
 * Compiler: MSP430 IAR C/C++ compiler  or msp430-gcc GNU C compiler                                   *
 * Target platform: MSP-FET430P140 (can easily be ported to other platforms)                           *
 *******************************************************************************************************
 * Revision history:                                                                                   *
 *                                                                                                     *
 *                                                                                                     *
 *******************************************************************************************************/

#include <stdlib.h>

/* Scheduler include files. */
#include "..\..\..\Os\include\FreeRTOS.h"
#include "..\..\..\Os\include\task.h"

/* Demo task include files. */
#include "..\include\rfcom.h"

//-------------------------------------------------------------------------------------------------------
// Defintions used locally in this file.
//-------------------------------------------------------------------------------------------------------
#define PAYLOAD_SIZE	   2         // If Need for small RF exchanged
#define RF_CHANNEL	   26
#define NUMBER_OF_BYTES    8         // Number of bytes in packet
#define rfcomSTACK_SIZE		configMINIMAL_STACK_SIZE

volatile BYTE bytesCount = 0;        // Bytes Counter



//-------------------------------------------------------------------------------------------------------
// Basic RF transmission and reception structures
//-------------------------------------------------------------------------------------------------------
BASIC_RF_RX_INFO rfRxInfo;
BASIC_RF_TX_INFO rfTxInfo;
BYTE pTxBuffer[BASIC_RF_MAX_PAYLOAD_SIZE];
BYTE pRxBuffer[BASIC_RF_MAX_PAYLOAD_SIZE];
//BYTE pTxBuffer[PAYLOAD_SIZE];
//BYTE pRxBuffer[PAYLOAD_SIZE];

/* The task that is created three times. */
static portTASK_FUNCTION_PROTO( vRfComTask, pvParameters );

void vStartRfComTask( unsigned portBASE_TYPE uxPriority )
{
    xTaskCreate( vRfComTask, ( const signed portCHAR * const ) "RFCOM", rfcomSTACK_SIZE, NULL, uxPriority, ( xTaskHandle * ) NULL );
}
//-------------------------------------------------------------------------------------------------------
//  BASIC_RF_RX_INFO* basicRfReceivePacket(BASIC_RF_RX_INFO *pRRI)
//
//  DESCRIPTION:
//      This function is a part of the basic RF library, but must be declared by the application. Once
//		the application has turned on the receiver, using basicRfReceiveOn(), all incoming packets will
//		be received by the FIFOP interrupt service routine. When finished, the ISR will call the
//		basicRfReceivePacket() function. Please note that this function must return quickly, since the
//		next received packet will overwrite the active BASIC_RF_RX_INFO structure (pointed to by pRRI).
//
//  ARGUMENTS:
//		BASIC_RF_RX_INFO *pRRI
//	      	The reception structure, which contains all relevant info about the received packet.
//
//  RETURN VALUE:
//     BASIC_RF_RX_INFO*
//			The pointer to the next BASIC_RF_RX_INFO structure to be used by the FIFOP ISR. If there is
//			only one buffer, then return pRRI.
//-------------------------------------------------------------------------------------------------------
BASIC_RF_RX_INFO* basicRfReceivePacket(BASIC_RF_RX_INFO *pRRI)
{
// Continue using the (one and only) reception structure
    TOGGLE_YLED();


    for (bytesCount = 0; bytesCount < NUMBER_OF_BYTES; bytesCount++)
    {
        while (!(IFG1 & UTXIFG0));                     // USART0 TX buffer ready?
        TXBUF0 = pRxBuffer[bytesCount];
    }

    return pRRI;
} // basicRfReceivePacket




static portTASK_FUNCTION( vRfComTask, pvParameters )
{

    ( void ) pvParameters;

//-------------------------------------------------------------------------------------------------------
// initialise UART0
//-------------------------------------------------------------------------------------------------------
    P3SEL  |= 0x30;
    ME1    |= UTXE0 + URXE0;
    UCTL0  |= CHAR + SPB;
    UTCTL0 |= SSEL1;
    UBR00   = 0x08;                                   // 8MHz 115200
    UBR10   = 0x00;                                   // 8MHz 115200
    UMCTL0  = 0x6B;                                   // 8MHz 115200 modulation
    UCTL0  &= ~SWRST;

//-------------------------------------------------------------------------------------------------------
// Initalize ports for communication with CC2420 and other peripheral units
//-------------------------------------------------------------------------------------------------------
    PORT_INIT();
    SPI_INIT();


// Wait for the user to select node address, and initialize for basic RF operation

    halWait(1000);
    basicRfInit(&rfRxInfo, RF_CHANNEL, 0x2420, 0x1234);

// Initalize common protocol parameters
    rfTxInfo.destAddr   = 0x5678;
    rfTxInfo.length     = PAYLOAD_SIZE;
    rfTxInfo.ackRequest = FALSE;
    rfTxInfo.pPayload   = pTxBuffer;

    rfRxInfo.pPayload   = pRxBuffer;

    basicRfReceiveOn();

    portENABLE_INTERRUPTS();

    for (;;)
    {

//        pTxBuffer[0] = 0xDE;
//        pTxBuffer[1] = 0xAD;

//        basicRfSendPacket(&rfTxInfo);

//        for (int i=1; i<=50; i++){
//        halWait(200);
//        }
//        TOGGLE_RLED();

    } //for (;;)
} // RfCom

⌨️ 快捷键说明

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