Skip to content

Commit

Permalink
support 8 channel si5351
Browse files Browse the repository at this point in the history
  • Loading branch information
paulh002 committed Dec 3, 2023
1 parent 48e96e7 commit c7e3bc9
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 22 deletions.
3 changes: 2 additions & 1 deletion SoapyHifiBerry-Release.vgdbsettings
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</CustomSourceDirectories>
<AutoProgramSPIFFSPartition>true</AutoProgramSPIFFSPartition>
<BuildHost>
<HostName>192.168.88.41</HostName>
<HostName>192.168.88.68</HostName>
<Transport>SSH</Transport>
<UserName>pi</UserName>
</BuildHost>
Expand Down Expand Up @@ -57,6 +57,7 @@
<ProjectFile>SoapyHifiBerry.vcxproj</ProjectFile>
<RemoteBuildEnvironment>
<Records />
<EnvironmentSetupFiles />
</RemoteBuildEnvironment>
<ParallelJobCount>1</ParallelJobCount>
<SuppressDirectoryChangeMessages>true</SuppressDirectoryChangeMessages>
Expand Down
4 changes: 3 additions & 1 deletion SoapyHifiBerry.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@

#define CLK_VFO_I SI5351_CLK0
#define CLK_VFO_Q SI5351_CLK1

#define CLK_VFO_TX_I SI5351_CLK4
#define CLK_VFO_TX_Q SI5351_CLK5

const int hifiBerry_BufferSize = 2048;

Expand All @@ -52,6 +53,7 @@ typedef enum vfoMode_
Single,
IQSingle,
IQMulti,
IQSingleMultiPort
} vfoMode;

class sdr_stream
Expand Down
2 changes: 1 addition & 1 deletion SoapyHifiBerry.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<TargetName>libSoapyHifiBerrySDR</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|VisualGDB'">
<RemoteBuildHost>192.168.88.41</RemoteBuildHost>
<RemoteBuildHost>192.168.88.68</RemoteBuildHost>
<ToolchainID>com.sysprogs.toolchain.default-gcc</ToolchainID>
<ToolchainVersion />
<GNUTargetType>DynamicLibrary</GNUTargetType>
Expand Down
25 changes: 23 additions & 2 deletions SoapyHifiBerrySettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,12 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args)
vfoIQMode = Single;
else if (IQMode == "IQSINGLE")
vfoIQMode = IQSingle;
else
else if (IQMode == "IQMulti")
vfoIQMode = IQMulti;
else
vfoIQMode = IQSingleMultiPort;

if (vfoIQMode == Single || vfoIQMode == IQSingle)
if (vfoIQMode == Single || vfoIQMode == IQSingle || vfoIQMode == IQSingleMultiPort)
{
cout << "IQ mode single multiplier = " << multiplier << endl;

Expand Down Expand Up @@ -184,6 +186,20 @@ SoapyHifiBerry::SoapyHifiBerry(const SoapySDR::Kwargs &args)
pSI5351->output_enable(CLK_NA, 0);
pSI5351->update_status();
}
if (vfoIQMode == IQSingleMultiPort)
{
cout << "si5351 found" << endl;
pSI5351->set_correction((long)corr, SI5351_PLL_INPUT_XO);
pSI5351->drive_strength(CLK_VFO_I, rxDrive);
pSI5351->drive_strength(CLK_VFO_Q, rxDrive);
pSI5351->output_enable(CLK_VFO_I, 1);
pSI5351->output_enable(CLK_VFO_Q, 1);
pSI5351->drive_strength(CLK_VFO_TX_I, rxDrive);
pSI5351->drive_strength(CLK_VFO_TX_Q, rxDrive);
pSI5351->output_enable(CLK_VFO_TX_I, 1);
pSI5351->output_enable(CLK_VFO_TX_Q, 1);
pSI5351->update_status();
}
if (vfoIQMode == IQMulti)
{
cout << "IQMulti mode multiplier = " << multiplier << endl;
Expand Down Expand Up @@ -404,6 +420,7 @@ void SoapyHifiBerry::setFrequency(const int direction, const size_t channel, con
pSI5351->set_freq((uint64_t)frequency * SI5351_FREQ_MULT * multiplier, CLK_VFO_RX);
break;
case IQSingle:
case IQSingleMultiPort:
if (pSI5351)
pSI5351->setIQFrequency((long)frequency * (long)multiplier);
break;
Expand Down Expand Up @@ -431,6 +448,10 @@ void SoapyHifiBerry::setFrequency(const int direction, const size_t channel, con
if (pSI5351)
pSI5351->setIQFrequency((long)frequency * (long)multiplier);
break;
case IQSingleMultiPort:
if (pSI5351)
pSI5351->setIQFrequency((long)frequency * (long)multiplier, true);
break;
case IQMulti:
if (pSI5351tx)
{
Expand Down
37 changes: 24 additions & 13 deletions si5351.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ extern "C" {
/* Public functions */
/********************/

Si5351::Si5351(const char *i2c_device_filepath, uint8_t i2c_addr, si5351_clock i_clock, si5351_clock q_clock)
: i2c_bus_addr(i2c_addr), i2c_file(0), i2c_filepath(i2c_device_filepath), iclock(i_clock), qclock(q_clock)
Si5351::Si5351(const char *i2c_device_filepath, uint8_t i2c_addr, si5351_clock i_clock, si5351_clock q_clock, si5351_clock i_clockTx, si5351_clock q_clockTx)
: i2c_bus_addr(i2c_addr), i2c_file(0), i2c_filepath(i2c_device_filepath), iclock(i_clock), qclock(q_clock), iclockTx(i_clockTx), qclockTx(q_clockTx)


{
Expand All @@ -52,7 +52,7 @@ Si5351::Si5351(const char *i2c_device_filepath, uint8_t i2c_addr, si5351_clock i
pllb_ref_osc = SI5351_PLL_INPUT_XO;
clkin_div = SI5351_CLKIN_DIV_1;
i2c_file = 0;
lastMult = -1;
lastMultRx = lastMultTx = -1;
}

Si5351::~Si5351()
Expand Down Expand Up @@ -162,17 +162,17 @@ void Si5351::reset(void)
pll_assignment[1] = SI5351_PLLA;
pll_assignment[2] = SI5351_PLLA;
pll_assignment[3] = SI5351_PLLA;
pll_assignment[4] = SI5351_PLLA;
pll_assignment[5] = SI5351_PLLA;
pll_assignment[4] = SI5351_PLLB;
pll_assignment[5] = SI5351_PLLB;
pll_assignment[6] = SI5351_PLLB;
pll_assignment[7] = SI5351_PLLB;

set_ms_source(SI5351_CLK0, SI5351_PLLA);
set_ms_source(SI5351_CLK1, SI5351_PLLA);
set_ms_source(SI5351_CLK2, SI5351_PLLA);
set_ms_source(SI5351_CLK3, SI5351_PLLA);
set_ms_source(SI5351_CLK4, SI5351_PLLA);
set_ms_source(SI5351_CLK5, SI5351_PLLA);
set_ms_source(SI5351_CLK4, SI5351_PLLB);
set_ms_source(SI5351_CLK5, SI5351_PLLB);
set_ms_source(SI5351_CLK6, SI5351_PLLB);
set_ms_source(SI5351_CLK7, SI5351_PLLB);

Expand Down Expand Up @@ -1868,7 +1868,7 @@ int Si5351::getEvenDivisor(uint64_t freq)
return 2;
}

void Si5351::setIQFrequency(uint64_t freq)
void Si5351::setIQFrequency(uint64_t freq, bool highClockPorts)
{
int mult = 0;

Expand All @@ -1877,16 +1877,27 @@ void Si5351::setIQFrequency(uint64_t freq)
uint64_t pllFreq = freq * mult * 100ULL;

printf("mult = %d pll = %ld Mhz freq %ld\n", mult, pllFreq / 100L, freq);
set_iq_freq_manual(f, pllFreq, iclock, qclock);

if (mult != lastMult)
if (!highClockPorts)
set_iq_freq_manual(f, pllFreq, iclock, qclock);
else
set_iq_freq_manual(f, pllFreq, iclockTx, qclockTx);

if (mult != lastMultRx && !highClockPorts)
{
set_phase(iclock, 0);
set_phase(qclock, mult);
pll_reset(SI5351_PLLA);
update_status();
lastMult = mult;
pll_reset(pll_assignment[iclock]);
lastMultRx = mult;
}
if (mult != lastMultTx && highClockPorts)
{
set_phase(iclockTx, 0);
set_phase(qclockTx, mult);
pll_reset(pll_assignment[iclockTx]);
lastMultTx = mult;
}
update_status();
}

uint8_t Si5351::set_iq_freq_manual(uint64_t freq, uint64_t pll_freq, enum si5351_clock iclk, enum si5351_clock qclk)
Expand Down
8 changes: 4 additions & 4 deletions si5351.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,14 @@ struct Si5351IntStatus
class Si5351
{
public:
Si5351(const char *i2c_device_filepath, uint8_t i2c_addr = SI5351_BUS_BASE_ADDR, si5351_clock iclock = SI5351_CLK0, si5351_clock qclock = SI5351_CLK1);
Si5351(const char *i2c_device_filepath, uint8_t i2c_addr = SI5351_BUS_BASE_ADDR, si5351_clock iclock = SI5351_CLK0, si5351_clock qclock = SI5351_CLK1, si5351_clock iclockTx = SI5351_CLK6, si5351_clock qclockTx = SI5351_CLK7);
~Si5351();
bool init(uint8_t, uint32_t, int32_t, int fileHandle = 0);
void reset(void);
uint8_t set_freq(uint64_t, enum si5351_clock);
uint8_t set_freq_manual(uint64_t, uint64_t, enum si5351_clock);
uint8_t set_iq_freq_manual(uint64_t freq, uint64_t pll_freq, enum si5351_clock iclk, enum si5351_clock qclk);
void setIQFrequency(uint64_t freq);
void setIQFrequency(uint64_t freq, bool highClockPorts = false);
int getEvenDivisor(uint64_t freq);
void set_pll(uint64_t, enum si5351_pll);
void set_ms(enum si5351_clock, struct Si5351RegSet, uint8_t, uint8_t, uint8_t);
Expand Down Expand Up @@ -376,8 +376,8 @@ class Si5351

int i2c_file;
std::string i2c_filepath;
int lastMult;
si5351_clock iclock, qclock;
int lastMultRx, lastMultTx;
si5351_clock iclock, qclock, iclockTx, qclockTx;
};

#endif /* SI5351_H_ */

0 comments on commit c7e3bc9

Please sign in to comment.