📄 hopp.c
字号:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 *
* *** + + *** FREQUENCY HOPPING *
* *** +++ *** *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* This file contains the implementations of all the functions from the *
* Frequency Hopping Basic library, which is found in Cul.h, as well as *
* some internal utility functions. *
*****************************************************************************
* Author: OGR *
*****************************************************************************
* Revision history: *
* *
* $Log: Hopp.c,v $
* Revision 1.1 2003/07/29 11:24:49 tos
* Initial version in CVS.
*
*
* *
****************************************************************************/
#include <chipcon/cul.h>
#include <chipcon/CC1010EB.h>
data byte currentFreq = 0;
xdata bool usingOverrides = FALSE;
// Variables that are used to override baudrate and PA output power
extern byte xdata hal_dataformat_override,
hal_baudrate_override,
hal_pa_pow_override,
hal_modem0_original,
hal_pa_pow_original;
//----------------------------------------------------------------------------
// void fhpRFCalib(...)
//
// Description:
// This function is almost identical to halRFCalib.
// The main difference is that the rf_settings is in the form
// of FHP_RXTXPAIR_SETTINGS, which is a smaller structure.
// See halRFCalib for details.
//----------------------------------------------------------------------------
void fhpRFCalib(FHP_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
} // end fhpRFCalib
//----------------------------------------------------------------------------
// bool fhpRFSetRxTxOff(...)
//
// Description:
// Function used to set a specific RX/TX channel pair as the current
// RF configuration. The _mode_ parameter is used to select between
// activating RF in RX or TX or turning off RF.
// This function is mainly identical to halRFSetRxTxOff. The main
// differences are that the rf_settings is in the form of
// FHP_RXTXPAIR_SETTINGS, which is a smaller structure, and that it
// is not necessary to update the settings that are common for all
// the frequencies.
//
// Arguments:
// byte mode
// Options given below. Turn off, turn on in RX, or on in TX. If
// RF_OFF is supplied the two pointers can be NULL.
// FHP_RXTXPAIR_SETTINGS* rf_settings
// Pointer to a FHP_RXTXPAIR_SETTINGS data structure containing the
// settings for an RX/TX channel pair (obtained 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.
// bool full
// specifies whether or not to perform a full update of the settings.
// The alternative is to only change settings that are specific to
// each frequency.
//
// Return value:
// bool
// Returns TRUE if the PLL locked.
// Otherwise, recalibration is necessary.
//----------------------------------------------------------------------------
bool fhpRFSetRxTxOff(byte mode, FHP_RXTXPAIR_SETTINGS code* rf_settings, RF_RXTXPAIR_CALDATA xdata* rf_caldata, bool full) {
int i;
if (mode==RF_OFF) {
RFMAIN=0x38; // RX, TX, FS powered down
return TRUE;
}
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;
if (mode==RF_RX) {
PLL=rf_settings->pll_rx;
RFMAIN=0x30;
TEST5=0x10 | rf_caldata->vco_ao_rx;
TEST6=0x20 | rf_caldata->chp_co_rx;
CURRENT = RF_SETTINGS.current_rx;
} else {
PLL=rf_settings->pll_tx;
RFMAIN=0xF0;
TEST5=0x10 | rf_caldata->vco_ao_tx;
TEST6=0x3B;
CURRENT = RF_SETTINGS.current_tx;
}
if (full) {
MODEM0=hal_modem0_original=RF_SETTINGS.modem0;
if (hal_baudrate_override&0x01)
MODEM0=(MODEM0&0x1F)|(hal_baudrate_override&0xE0);
if (hal_dataformat_override&0x01)
MODEM0=(MODEM0&0xE7)|(hal_dataformat_override&0x18);
MODEM1=RF_SETTINGS.modem1;
MODEM2=RF_SETTINGS.modem2;
FSEP1=RF_SETTINGS.fsep1;
FSEP0=RF_SETTINGS.fsep0;
PA_POW=hal_pa_pow_original=RF_SETTINGS.pa_pow;
if (hal_pa_pow_override)
PA_POW=hal_pa_pow_override;
MATCH=RF_SETTINGS.match;
PRESCALER=RF_SETTINGS.prescaler;
FREND=RF_SETTINGS.frend;
}
// Wait 200 usec before monitoring LOCK
for(i=LOCK_MONITOR_DELAY; i>0; i--);
// Wait for lock
for(i=LOCK_TIMEOUT; !(LOCK&0x01) && (i>0); i--);
return LOCK&0x01;
} // end fhpRFSetRxTxOff
//----------------------------------------------------------------------------
// void initializeFrequencies()
//
// Description:
// Calibrates all the frequencies that are to be used.
// This function must be called before transmitting or receiving.
//
// Arguments:
// None.
//
// Return value:
// void
//----------------------------------------------------------------------------
void initializeFrequencies() {
byte i;
// 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;
for (i=0; i<numberOfFrequencies; ++i) {
fhpRFCalib(&rxtxpair_settings[i], &rxtxpair_caldata[i]); //FHP
frequencyPermutation[i] = i;
}
fhpRFSetRxTxOff(RF_RX,rxtxpair_settings,rxtxpair_caldata,TRUE); // gives warning because of multiple call, but is not a problem
} // end initializeFrequencies
//----------------------------------------------------------------------------
// void changeFreq(...)
//
// Description:
// Used to change the current frequency and/or mode.
//
// Arguments:
// byte mode
// One of RF_OFF, RF_RX and RF_TX.
// byte increment
// The amount by which the position in the frequency
// hopping sequence will be advanced.
//
// Return value:
// void
//----------------------------------------------------------------------------
void changeFreq(byte mode, byte increment) {
byte number;
currentFreq += increment;
while (currentFreq >= numberOfFrequencies) currentFreq-=numberOfFrequencies;
number = frequencyPermutation[currentFreq];
while (!fhpRFSetRxTxOff(mode, &rxtxpair_settings[number],&rxtxpair_caldata[number],usingOverrides)) {
fhpRFCalib(&rxtxpair_settings[number],&rxtxpair_caldata[number]);
}
} // end changeFreq
//----------------------------------------------------------------------------
// byte getFrequencyPosition()
//
// Description:
// Reads the current position in the frequency hopping sequence.
//
// Arguments:
// None.
//
// Return value:
// byte
// The current position.
//----------------------------------------------------------------------------
byte getFrequencyPosition() {
return currentFreq;
} // end getFrequencyPosition
//----------------------------------------------------------------------------
// void setFrequencyPosition(...)
//
// Description:
// Sets the current position in the frequency hopping sequence.
//
// Arguments:
// byte pos
// The new position in the sequence.
//
// Return value:
// void
//----------------------------------------------------------------------------
void setFrequencyPosition(byte pos) {
currentFreq = pos;
} // end setFrequencyPosition
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -