Added squelch system to MD3x0 rtx driver
This commit is contained in:
parent
2c0b75b221
commit
bb53b5ccef
|
|
@ -18,12 +18,14 @@
|
||||||
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
* along with this program; if not, see <http://www.gnu.org/licenses/> *
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include <toneGenerator_MDx.h>
|
||||||
#include <calibInfo_MDx.h>
|
#include <calibInfo_MDx.h>
|
||||||
#include <calibUtils.h>
|
#include <calibUtils.h>
|
||||||
#include <datatypes.h>
|
#include <datatypes.h>
|
||||||
#include <hwconfig.h>
|
#include <hwconfig.h>
|
||||||
#include <platform.h>
|
#include <platform.h>
|
||||||
#include <ADC1_MDx.h>
|
#include <ADC1_MDx.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <gpio.h>
|
#include <gpio.h>
|
||||||
|
|
@ -32,7 +34,6 @@
|
||||||
#include "HR-C5000_MD3x0.h"
|
#include "HR-C5000_MD3x0.h"
|
||||||
#include "pll_MD3x0.h"
|
#include "pll_MD3x0.h"
|
||||||
|
|
||||||
#include "toneGenerator_MDx.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
struct rtxStatus_t
|
struct rtxStatus_t
|
||||||
|
|
@ -53,9 +54,12 @@ struct rtxStatus_t
|
||||||
}
|
}
|
||||||
rtxStatus;
|
rtxStatus;
|
||||||
|
|
||||||
OS_Q cfgMailbox;
|
OS_Q cfgMailbox; /* Queue for incoming config messages */
|
||||||
const md3x0Calib_t *calData;
|
const md3x0Calib_t *calData; /* Pointer to calibration data */
|
||||||
const freq_t IF_FREQ = 49950000; /* Intermediate frequency: 49.95MHz */
|
const freq_t IF_FREQ = 49950000; /* Intermediate frequency: 49.95MHz */
|
||||||
|
|
||||||
|
uint8_t sqlOpenTsh; /* Squelch opening threshold */
|
||||||
|
uint8_t sqlCloseTsh; /* Squelch closing threshold */
|
||||||
|
|
||||||
static void printUnsignedInt(unsigned int x)
|
static void printUnsignedInt(unsigned int x)
|
||||||
{
|
{
|
||||||
|
|
@ -124,7 +128,7 @@ void _setOpMode()
|
||||||
|
|
||||||
void _enableTxStage()
|
void _enableTxStage()
|
||||||
{
|
{
|
||||||
// if(rtxStatus.txDisable == 1) return;
|
if(rtxStatus.txDisable == 1) return;
|
||||||
|
|
||||||
gpio_clearPin(RX_STG_EN);
|
gpio_clearPin(RX_STG_EN);
|
||||||
|
|
||||||
|
|
@ -198,6 +202,34 @@ void _setCTCSS()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _updateSqlThresholds()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* TODO:
|
||||||
|
* - check why openSql9 is less than openSql1, maybe parameters are swapped
|
||||||
|
* - squelch levels 1 - 9
|
||||||
|
*/
|
||||||
|
uint8_t sql1OpenTsh = interpCalParameter(rtxStatus.rxFrequency, calData->rxFreq,
|
||||||
|
calData->openSql9, 9);
|
||||||
|
|
||||||
|
uint8_t sql1CloseTsh = interpCalParameter(rtxStatus.rxFrequency, calData->rxFreq,
|
||||||
|
calData->closeSql9, 9);
|
||||||
|
|
||||||
|
sqlOpenTsh = sql1OpenTsh;
|
||||||
|
sqlCloseTsh = sql1CloseTsh;
|
||||||
|
|
||||||
|
/* uint8_t sql9OpenTsh = interpCalParameter(rtxStatus.rxFrequency, calData->rxFreq,
|
||||||
|
calData->openSql1, 9);
|
||||||
|
|
||||||
|
uint8_t sql9CloseTsh = interpCalParameter(rtxStatus.rxFrequency, calData->rxFreq,
|
||||||
|
calData->closeSql1, 9);
|
||||||
|
|
||||||
|
sqlOpenTsh = sql1OpenTsh + ((rtxStatus.sqlLevel - 1) *
|
||||||
|
(sql9OpenTsh - sql1OpenTsh))/8;
|
||||||
|
|
||||||
|
sqlCloseTsh = sql1CloseTsh + ((rtxStatus.sqlLevel - 1) *
|
||||||
|
(sql9CloseTsh - sql1CloseTsh))/8; */
|
||||||
|
}
|
||||||
|
|
||||||
void rtx_init()
|
void rtx_init()
|
||||||
{
|
{
|
||||||
|
|
@ -240,7 +272,7 @@ void rtx_init()
|
||||||
gpio_setPin(MIC_PWR); /* Turn on microphone */
|
gpio_setPin(MIC_PWR); /* Turn on microphone */
|
||||||
gpio_setPin(AMP_EN); /* Turn on audio amplifier */
|
gpio_setPin(AMP_EN); /* Turn on audio amplifier */
|
||||||
gpio_setPin(FM_MUTE); /* Unmute path from AF_out to amplifier */
|
gpio_setPin(FM_MUTE); /* Unmute path from AF_out to amplifier */
|
||||||
gpio_clearPin(SPK_MUTE); /* Mute speaker */
|
gpio_setPin(SPK_MUTE); /* Mute speaker */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Configure and enble DAC
|
* Configure and enble DAC
|
||||||
|
|
@ -359,11 +391,31 @@ void rtx_taskFunc()
|
||||||
_setBandwidth();
|
_setBandwidth();
|
||||||
_updateC5000IQparams();
|
_updateC5000IQparams();
|
||||||
_setCTCSS();
|
_setCTCSS();
|
||||||
|
_updateSqlThresholds();
|
||||||
|
|
||||||
/* TODO: temporarily force to RX mode if rtx is off. */
|
/* TODO: temporarily force to RX mode if rtx is off. */
|
||||||
if(rtxStatus.opStatus == OFF) _enableRxStage();
|
if(rtxStatus.opStatus == OFF) _enableRxStage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(rtxStatus.opStatus == RX)
|
||||||
|
{
|
||||||
|
/* Convert back voltage to ADC counts */
|
||||||
|
float sqlValue = (adc1_getMeasurement(1) * 4096.0f)/3300.0f;
|
||||||
|
uint16_t sqlLevel = ((uint16_t) sqlValue) >> 6;
|
||||||
|
|
||||||
|
if((gpio_readPin(SPK_MUTE) == 1) && (sqlLevel > sqlOpenTsh))
|
||||||
|
{
|
||||||
|
gpio_clearPin(SPK_MUTE);
|
||||||
|
platform_ledOn(GREEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
if((gpio_readPin(SPK_MUTE) == 0) && (sqlLevel < sqlCloseTsh))
|
||||||
|
{
|
||||||
|
gpio_setPin(SPK_MUTE);
|
||||||
|
platform_ledOff(GREEN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(platform_getPttStatus() && (rtxStatus.opStatus != TX))
|
if(platform_getPttStatus() && (rtxStatus.opStatus != TX))
|
||||||
{
|
{
|
||||||
_disableRtxStages();
|
_disableRtxStages();
|
||||||
|
|
@ -387,5 +439,5 @@ void rtx_taskFunc()
|
||||||
|
|
||||||
float rtx_getRssi()
|
float rtx_getRssi()
|
||||||
{
|
{
|
||||||
return 0;
|
return adc1_getMeasurement(1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,68 +21,47 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <os.h>
|
#include <os.h>
|
||||||
#include "gpio.h"
|
#include "gpio.h"
|
||||||
#include "delays.h"
|
#include "delays.h"
|
||||||
#include "rtx.h"
|
#include "rtx.h"
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
#include "hwconfig.h"
|
#include "hwconfig.h"
|
||||||
#include "HR-C5000_MD3x0.h"
|
#include "toneGenerator_MDx.h"
|
||||||
#include "toneGenerator_MDxx380.h"
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
platform_init();
|
platform_init();
|
||||||
// toneGen_init();
|
toneGen_init();
|
||||||
// toneGen_setToneFreq(77.0f);
|
|
||||||
|
|
||||||
gpio_setMode(SPK_MUTE, OUTPUT);
|
|
||||||
gpio_setMode(AMP_EN, OUTPUT);
|
|
||||||
gpio_setMode(FM_MUTE, OUTPUT);
|
|
||||||
|
|
||||||
gpio_setPin(AMP_EN); /* Turn on audio amplifier */
|
|
||||||
gpio_setPin(FM_MUTE); /* Unmute path from AF_out to amplifier */
|
|
||||||
gpio_clearPin(SPK_MUTE); /* Unmute speaker */
|
|
||||||
|
|
||||||
rtx_init();
|
rtx_init();
|
||||||
rtx_setTxFreq(430100000.0f);
|
|
||||||
rtx_setRxFreq(430100000.0f);
|
|
||||||
rtx_setBandwidth(BW_25);
|
|
||||||
rtx_setOpmode(FM);
|
|
||||||
rtx_setFuncmode(RX);
|
|
||||||
|
|
||||||
gpio_setMode(GPIOA, 14, OUTPUT); /* Micpwr_sw */
|
freq_t rptFreq = 430100000;
|
||||||
gpio_setPin(GPIOA, 14);
|
freq_t rptShift = 1600000;
|
||||||
|
tone_t ctcss = 719;
|
||||||
|
|
||||||
bool txActive = false;
|
/*
|
||||||
uint8_t count = 0;
|
* Allocate a configuration message for RTX.
|
||||||
|
* This memory chunk is then freed inside the driver, so you must not call
|
||||||
|
* free() in this pointer!
|
||||||
|
*/
|
||||||
|
rtxConfig_t *cfg = ((rtxConfig_t *) malloc(sizeof(rtxConfig_t)));
|
||||||
|
|
||||||
|
cfg->opMode = FM;
|
||||||
|
cfg->bandwidth = BW_25;
|
||||||
|
cfg->rxFrequency = rptFreq;
|
||||||
|
cfg->txFrequency = rptFreq + rptShift;
|
||||||
|
cfg->txPower = 1.0f;
|
||||||
|
cfg->sqlLevel = 3;
|
||||||
|
cfg->rxTone = 0;
|
||||||
|
cfg->txTone = ctcss;
|
||||||
|
rtx_configure(cfg);
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if(platform_getPttStatus() && (txActive == false))
|
|
||||||
{
|
|
||||||
rtx_setFuncmode(OFF);
|
|
||||||
rtx_setFuncmode(TX);
|
|
||||||
C5000_startAnalogTx();
|
|
||||||
platform_ledOn(RED);
|
|
||||||
txActive = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!platform_getPttStatus() && (txActive == true))
|
rtx_taskFunc();
|
||||||
{
|
|
||||||
rtx_setFuncmode(OFF);
|
|
||||||
C5000_stopAnalogTx();
|
|
||||||
platform_ledOff(RED);
|
|
||||||
rtx_setFuncmode(RX);
|
|
||||||
txActive = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
count++;
|
|
||||||
if(count == 50)
|
|
||||||
{
|
|
||||||
printf("RSSI: %f\r\n", rtx_getRssi());
|
|
||||||
count = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
OS_ERR err;
|
OS_ERR err;
|
||||||
OSTimeDlyHMSM(0u, 0u, 0u, 10u, OS_OPT_TIME_HMSM_STRICT, &err);
|
OSTimeDlyHMSM(0u, 0u, 0u, 10u, OS_OPT_TIME_HMSM_STRICT, &err);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue