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

📄 rfcalib.c

📁 ti-Chipcon CC1010 1G以下Soc源码库。包括rf,powermodes,clockmodes,flashRW,interrupts,timer,pwm,uart...所有底层驱动源码
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                            CHIPCON CC1010                    *
 *      ***   + +   ***                     HAL - RFCalib                    *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 *                                                                           *
 *****************************************************************************
 * Author:              ROH                                                  *
 *****************************************************************************
 * Revision history:                                                         *
 *                                                                           *
 * $Log: RFCalib.c,v $
 * Revision 1.2  2003/05/12 09:56:49  tos
 * Corrections according to Errata Note 01: recalibrate if unable to lock PLL.
 *
 * Revision 1.1.2.1  2003/05/12 07:24:50  tos
 * Corrections according to Errata Note 01: recalibrate if unable to lock PLL.
 *
 * Revision 1.1  2002/10/14 13:04:33  tos
 * Initial version in CVS.
 *
 *                                                                           *
 ****************************************************************************/

#include <chipcon/hal.h>


// Variables that are used to override baudrate and PA output power
byte xdata   hal_dataformat_override, 
             hal_baudrate_override, 
             hal_pa_pow_override,
             hal_modem0_original,
             hal_pa_pow_original;

//----------------------------------------------------------------------------
//  void halRFCalib(...)
//
//  Description:
//      Performs the necessary RF-calibration for an RX/TX channel pair with
//      the settings specified by the RF_RXTXPAIR_SETTINGS data structure
//      pointed to by _rf_settings_. The results of the calibration are stored
//      in the RF_RXTXPAIR_CALDATA data structure pointed to by _rf_caldata_.
//      Call this function once for each RX/TX channel pair that will be used
//      by the program before they are used and whenever the supply voltage or
//      temperature has changed significantly.
//      The application Chipcon SmartRF Studio should be used to generate this
//      data structure.
//
//  Arguments:
//      RF_RXTXPAIR_SETTINGS* rf_settings
//          Pointer to a RF_RXTXPAIR_SETTINGS data structure containing the
//          settings for an RX/TX channel pair (exported from SmartRF Studio.)
//      RF_RXTXPAIR_CALDATA xdata* rf_caldata
//          A pointer to a RF_RXTXPAIR_CALDATA data structure which will be
//          filled with the results from the calibration.
//
//  Return value:
//      void
//----------------------------------------------------------------------------
void halRFCalib(RF_RXTXPAIR_SETTINGS code* rf_settings, RF_RXTXPAIR_CALDATA xdata* rf_caldata) {
    int i;

    // Write required registers for calibration
    FREQ_2A=rf_settings->freq_2a;
    FREQ_1A=rf_settings->freq_1a;
    FREQ_0A=rf_settings->freq_0a;
    FREQ_2B=rf_settings->freq_2b;
    FREQ_1B=rf_settings->freq_1b;
    FREQ_0B=rf_settings->freq_0b;
    PLL=rf_settings->pll_rx;
    CAL=0x26;                           // CAL_DUAL=0, CAL_WAIT=1, CAL_CURRENT=0
    TEST5=0x00;                         // Zero previous calibration results,
    TEST6=0x00;                         // so that override is no longer in effect    
    
    // Turn on frequency synthesiser and RX chain, set VCO current
    //RFMAIN=0x10;                        // RXTX=RX, F_REG=A, RX_PD=0, FS_PD=0    
    F_REG=0;
    FS_PD=0;
    CURRENT=rf_settings->current_rx;

    // Start RX calibration, wait for completion
    CAL |= 0x80;                        // Start calibration
    for(i=CAL_TIMEOUT; !(CAL&0x08) && (i>0); i--); // Wait until finished (max 34 ms)
    CAL &= ~0x80;                       // Stop calibration

    // Wait for lock
    for(i=LOCK_TIMEOUT; !(LOCK&0x01) && (i>0); i--);

    // Save RX calibration results
    rf_caldata->vco_ao_rx=TEST0;
    rf_caldata->chp_co_rx=TEST2;

    // Setup for TX calibration
    //RFMAIN=0xE0;                        // RXTX=TX, F_REG=B, TX_PD=0, FS_PD=0    
    PLL=rf_settings->pll_tx;
    F_REG=1;
    CURRENT=rf_settings->current_tx;
    PA_POW=0x00;                        // Turn off PA to avoid spurious emmisions
    TEST6=0x3B;                         // In TX, always use chp_current = 0x1B
        
    // Start TX calibration, wait for completion
    CAL |= 0x80;                        // Start calibration
    for(i=CAL_TIMEOUT; !(CAL&0x08) && (i>0); i--); // Wait until finished (max 34 ms)
    CAL &= ~0x80;                       // Stop calibration

    // Wait for lock
    for(i=LOCK_TIMEOUT; !(LOCK&0x01) && (i>0); i--);

    // Save TX calibration results
    rf_caldata->vco_ao_tx=TEST0;
    
    // Turn off all RF
    RFMAIN=0x38;                        // RX, TX, FS powered down
    
    // Make sure the override variables are properly initialized
    hal_dataformat_override=0;
    hal_baudrate_override=0;
    hal_pa_pow_override=0;
    hal_modem0_original=0;
    hal_pa_pow_original=0;
}

⌨️ 快捷键说明

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