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

📄 rx_int.c

📁 基于cc1010的设计实例
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                    CHIPCON CC1010 EXAMPLE PROGRAM            *
 *      ***   + +   ***        SIMPLE RF RX test based on RF interrupt       *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 *                                                                           *
 * This program simply receives RF data based on RF interrupt (bytemode) and *
 * then sends it to a PC terminal through the UART0 interface. It requires   *
 * that a remote unit sends valid RF packets according to the RF setup and   *
 * protocol specified in Chipcons "halRFtest".                               *
 *                                                                           *
 * Status indication:                                                        *
 *   Green LED indicates packet reception.                                   *
 *   Red   LED indicates packet error.                                       *
 *   Blue  LED indicates main loop is runnning ok.                           *
 *                                                                           *
 * Setup:                                                                    *
 *   Connect a standard Hyperterminal to CC1010EB serial port 0 for          *
 *   diagnostic monitoring. Apply the following Hyperterminal settings:      *
 *   57600 bit/sec, 8 data bit, No parity, 1 stop bit, No flow control       *
 *****************************************************************************
 * Author:              TOS                                                  *
 *****************************************************************************
 * Revision history:                                                         *
 *                                                                           *
 * $Log: rx_int.c,v $
 * Revision 1.1  2004/01/09 14:54:07  tos
 * Initial version in CVS.
 *
 *
 *                                                                           *
 ****************************************************************************/

#include <chipcon/reg1010.h>
#include <chipcon/cc1010eb.h>
#include <chipcon/hal.h>
#include <stdio.h>


#define  RF_RX_BUF_SIZE       50
#define  TEST_STRING_LENGTH   10

//Define ASCII codes / terminal commands
#define ASCII_LF   0x0A
#define ASCII_CR   0x0D
#define ASCII_NUL  0x00
#define ASCII_ESC  0x1B

// Define RSSI limit for response
#define RSSI_LIM  -75

// Define monitor timeouts
#define RSSI_MONITOR_TIMEOUT  0x0110
#define MAIN_MONITOR_TIMEOUT  0x00FF

void RFSetupReceive(void);

int main_monitor = 0;
int rssi_monitor = 0;
char rssi_val;
int i = 0;

byte rf_rx_string[TEST_STRING_LENGTH];
byte rf_rx_buf[RF_RX_BUF_SIZE];
byte rf_rx_index = 0;

byte rf_rx_display = FALSE;
int packet_error_cnt = 0;
byte packet_error = FALSE;


void main() {

#ifdef FREQ868

// X-tal frequency: 14.745600 MHz
// RF frequency A: 868.277200 MHz	Rx
// RF frequency B: 868.277200 MHz	Tx
// RX Mode: Low side LO
// Frequency separation: 64 kHz
// Data rate: 2.4 kBaud
// Data Format: Manchester
// RF output power: 4 dBm
// IF/RSSI: RSSI Enabled

RF_RXTXPAIR_SETTINGS code RF_SETTINGS = {
    0x4B, 0x2F, 0x15,    // Modem 0, 1 and 2: Manchester, 2.4 kBaud
    //0x43, 0x2F, 0x15,    // Modem 0, 1 and 2: NRZ, 2.4 kBaud
    //0xA1, 0x2F, 0x29,    // Modem 0, 1 and 2: NRZ, 38.4 kBaud
    //0xA0, 0x2F, 0x52,    // Modem 0, 1 and 2: NRZ, 76.8 kBaud
    0x75, 0xA0, 0x00,    // Freq A
    0x58, 0x32, 0x8D,    // Freq B
    0x01, 0xAB,          // FSEP 1 and 0
    0x40,                // PLL_RX
    0x30,                // PLL_TX
    0x6C,                // CURRENT_RX
    0xF3,                // CURRENT_TX
    0x32,                // FREND
    0xFF,                // PA_POW
    0x00,                // MATCH
    0x00,                // PRESCALER
    };

#endif

#ifdef FREQ915

// X-tal frequency: 14.745600 MHz
// RF frequency A: 915.027455 MHz	Rx
// RF frequency B: 915.027455 MHz	Tx
// RX Mode: Low side LO
// Frequency separation: 64 kHz
// Data rate: 2.4 kBaud
// Data Format: Manchester
// RF output power: 4 dBm
// IF/RSSI: RSSI Enabled

RF_RXTXPAIR_SETTINGS code RF_SETTINGS = {
    0x4B, 0x2F, 0x15,    // Modem 0, 1 and 2
    0xAA, 0x80, 0x00,    // Freq A
    0x5C, 0xF4, 0x02,    // Freq B
    0x01, 0xAB,          // FSEP 1 and 0
    0x58,                // PLL_RX
    0x30,                // PLL_TX
    0x6C,                // CURRENT_RX
    0xF3,                // CURRENT_TX
    0x32,                // FREND
    0xFF,                // PA_POW
    0x00,                // MATCH
    0x00,                // PRESCALER
    };


#endif

#ifdef FREQ433

// X-tal frequency: 14.745600 MHz
// RF frequency A: 433.302000 MHz	Rx
// RF frequency B: 433.302000 MHz	Tx
// RX Mode: Low side LO
// Frequency separation: 64 kHz
// Data rate: 2.4 kBaud
// Data Format: Manchester
// RF output power: 10 dBm
// IF/RSSI: RSSI Enabled

RF_RXTXPAIR_SETTINGS code RF_SETTINGS = {
    0x4B, 0x2F, 0x0E,    // Modem 0, 1 and 2
    0x58, 0x00, 0x00,    // Freq A
    0x41, 0xFC, 0x9C,    // Freq B
    0x02, 0x80,          // FSEP 1 and 0
    0x60,                // PLL_RX
    0x48,                // PLL_TX
    0x44,                // CURRENT_RX
    0x81,                // CURRENT_TX
    0x0A,                // FREND
    0xFF,                // PA_POW
    0xC0,                // MATCH
    0x00,                // PRESCALER
    };

#endif


    // Calibration data
    RF_RXTXPAIR_CALDATA xdata RF_CALDATA;

    // Fill up reference string
    for(i = 0; i < TEST_STRING_LENGTH; i++){
        rf_rx_string[i]=i;
    }

    // Disable watchdog timer
    WDT_ENABLE(FALSE);

    // Set optimum settings for speed and low power consumption
    MEM_NO_WAIT_STATES();
    FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS);

    // Calibrate
    halRFCalib(&RF_SETTINGS, &RF_CALDATA);

    // Turn on RF for RX
    halRFSetRxTxOff(RF_RX, &RF_SETTINGS, &RF_CALDATA);

    // Initialise RSSI reading
    halRFReadRSSIlevel(RSSI_MODE_INIT);

    // Setup UART0 with polled I/O
    UART0_SETUP(57600, CC1010EB_CLKFREQ, UART_NO_PARITY | UART_RX_TX | UART_POLLED);

    // Enable the LEDs
    RLED_OE(TRUE);
    YLED_OE(TRUE);
    GLED_OE(TRUE);
    BLED_OE(TRUE);

    RLED = LED_OFF;
    YLED = LED_OFF;
    GLED = LED_OFF;
    BLED = LED_OFF;

    // Setup RF receive
    RFSetupReceive();

    // Reset main loop monitor
    main_monitor = MAIN_MONITOR_TIMEOUT;

    // Reset RSSI monitor
    rssi_monitor = RSSI_MONITOR_TIMEOUT;

    // Clear screen
    printf("%c[2J", ASCII_ESC);

    // Place cursor at upper left corner
    printf("%c[H", ASCII_ESC);

    // Display RF packet data + RSSI level:
    while (TRUE) {

        // Display RSSI level info:
        if((rssi_val = halRFReadRSSIlevel(RSSI_MODE_RUN)) > RSSI_LIM){
            printf("RSSI = %4d dBm, Packet error count = %d\n", (int)rssi_val, packet_error_cnt);
        } else {
            if (rssi_monitor-- < 0x0000) {
                printf("RSSI = %4d dBm, Packet error count = %d\n", (int)rssi_val, packet_error_cnt);
                rssi_monitor = RSSI_MONITOR_TIMEOUT;
            }
        }

        // Detect RF packet error and display RF packet data:
        if(rf_rx_display == TRUE){
            rf_rx_display = FALSE;
            for(i = 2; i < TEST_STRING_LENGTH+2; i++){
                if(rf_rx_buf[i] != i-2){
                    packet_error = TRUE;
                    RLED = LED_ON;
                }
                printf("RXD%d=%d ", i-2, (int)rf_rx_buf[i]);
            }

            if(packet_error == TRUE){
                packet_error_cnt++;
            }
            packet_error = FALSE;

            printf("\n");
        }else{
        }

        // Indicate main loop is running ok:
        if (main_monitor-- < 0x0000) {
            BLED = !BLED;
            main_monitor = MAIN_MONITOR_TIMEOUT;
        }

    }


    // Power down ADC:
    // In this application example this instruction does not have
    // any effect, since it is placed outside the infinite loop above.
    // However, if the "real" application needs to, for instance,
    // enter a power save mode, then it might be important power down
    // the ADC to save as much power as possible.
    ADC_POWER(FALSE);
}



// RF interrupt service rotine:
void RF_ISR (void) interrupt INUM_RF {

    INT_ENABLE(INUM_RF, INT_OFF);
	INT_SETFLAG (INUM_RF, INT_CLR);

    // Get RF receive data
    rf_rx_buf[rf_rx_index] = RF_RECEIVE_BYTE();

    RLED = LED_OFF;

    // Verify packet contents:
    switch(rf_rx_index){
        case 0:
            RF_LOCK_AVERAGE_FILTER(TRUE);
            if(rf_rx_buf[rf_rx_index] != RF_SUITABLE_SYNC_BYTE){
                RLED = LED_ON;
            }else{
            }
            rf_rx_index++;
            break;

        case 1:
            if(rf_rx_buf[rf_rx_index] != TEST_STRING_LENGTH){
                RLED = LED_ON;
            }else{
            }
            rf_rx_index++;
            break;

        case TEST_STRING_LENGTH+3:
            rf_rx_index = 0;
            rf_rx_display = TRUE;
            PDET &= ~0x80;
            PDET |= 0x80;
            break;

        default:
            if((rf_rx_buf[rf_rx_index] != rf_rx_string[rf_rx_index-2]) && (rf_rx_index < TEST_STRING_LENGTH+2)){
                RLED = LED_ON;
            }else{
            }
            rf_rx_index++;
            break;
    }

    // Indicate packet reception
    GLED = !GLED;

    INT_ENABLE(INUM_RF, INT_ON);

	return;
}




// Setup RF for RX
void RFSetupReceive (void) {

    // Disable global interrupt
    INT_GLOBAL_ENABLE (INT_OFF);

    // Setup RF interrupt
    INT_SETFLAG (INUM_RF, INT_CLR);
    INT_PRIORITY (INUM_RF, INT_HIGH);
    INT_ENABLE (INUM_RF, INT_ON);

    // Enable RF interrupt based on bytemode
    RF_SET_BYTEMODE();

    // Setup preamble configuration
    RF_SET_PREAMBLE_COUNT(16);
    RF_SET_SYNC_BYTE(RF_SUITABLE_SYNC_BYTE);

    // Make sure avg filter is free-running + 22 baud settling time
    MODEM1=(MODEM1&0x03)|0x24;

    // Reset preamble detection
    PDET &= ~0x80;
    PDET |= 0x80;

    // Start RX
    RF_START_RX();

    // Enable global interrupt
    INT_GLOBAL_ENABLE (INT_ON);

}



⌨️ 快捷键说明

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