📄 si47xxamrx.c
字号:
PoweredUp = 0;
// Perform a hardware reset, power up the device, and then perform the
// initial configuration.
si47xx_reset();
si47xxAMRX_powerup();
si47xxAMRX_configure();
}
void si47xxAMSWLWRX_initialize(void)
{
// Zero status registers.
PoweredUp = 0;
// Perform a hardware reset, power up the device, and then perform the
// initial configuration.
si47xx_reset();
si47xxAMRX_powerup();
si47xxAMSWLWRX_configure();
}
//-----------------------------------------------------------------------------
// Set the volume and mute/unmute status
//
// Inputs:
// volume: a 6-bit volume value
//
// Note: It is assumed that if the volume is being adjusted, the device should
// not be muted.
//-----------------------------------------------------------------------------
void si47xxAMRX_set_volume(u8 volume)
{
// Turn off the mute
si47xx_set_property(RX_HARD_MUTE, 0);
// Set the volume to the passed value
si47xx_set_property(RX_VOLUME, (u16)volume & RX_VOLUME_MASK);
}
//-----------------------------------------------------------------------------
// Mute/unmute audio
//
// Inputs:
// mute: 0 = output enabled (mute disabled)
// 1 = output muted
//-----------------------------------------------------------------------------
void si47xxAMRX_mute(u8 mute)
{
if(mute)
si47xx_set_property(RX_HARD_MUTE,
RX_HARD_MUTE_RMUTE_MASK | RX_HARD_MUTE_LMUTE_MASK);
else
si47xx_set_property(RX_HARD_MUTE, 0);
}
//-----------------------------------------------------------------------------
// Tunes to a station number using the current band and spacing settings.
//
// Inputs:
// frequency: frequency in 1kHz steps
//
// Returns:
// The RSSI level found during the tune.
//-----------------------------------------------------------------------------
u8 si47xxAMRX_tune(u16 frequency)
{
// Enable the bit used for the interrupt of STC.
SeekTuneInProc = 1;
// Call the tune command to start the tune.
WaitSTCInterrupt = 1;
amTuneFreq(frequency);
// wait for the interrupt before continuing
// If you do not wish to use interrupts but wish to poll the part
// then comment out this line.
while (WaitSTCInterrupt); // Wait for interrupt to clear the bit
// Wait for stc bit to be set
while (!(getIntStatus() & STCINT));
// Clear the STC bit and get the results of the tune.
amTuneStatus(0, 1);
// Disable the bit used for the interrupt of STC.
SeekTuneInProc = 0;
// Return the RSSI level
return RSSI;
}
//-----------------------------------------------------------------------------
// Inputs:
// seekup: 0 = seek down
// 1 = seek up
// seekmode: 0 = wrap at band limits
// 1 = stop at band limits
// Outputs:
// zero = seek found a station
// nonzero = seek did not find a station
//-----------------------------------------------------------------------------
u8 si47xxAMRX_seek(u8 seekup, u8 seekmode)
{
// Enable the bit used for the interrupt of STC.
SeekTuneInProc = 1;
// Call the tune command to start the seek.
WaitSTCInterrupt = 1;
amSeekStart(seekup, !seekmode);
// wait for the interrupt before continuing
// If you do not wish to use interrupts but wish to poll the part
// then comment out these two lines.
while (WaitSTCInterrupt); // Wait for interrupt to clear the bit
// Wait for stc bit to be set
// If there is a display to update seek progress, then you could
// call fmTuneStatus in this loop to get the current frequency.
// When calling fmTuneStatus here make sure intack is zero.
while (!(getIntStatus() & STCINT));
// Clear the STC bit and get the results of the tune.
amTuneStatus(0, 1);
// Disable the bit used for the interrupt of STC.
SeekTuneInProc = 0;
// The tuner is now set to the newly found channel if one was available
// as indicated by the seek-fail bit.
return BLTF; //return seek fail indicator
}
//-----------------------------------------------------------------------------
// Returns the current tuned frequency of the part
//
// Returns:
// frequency in 1kHz steps
//-----------------------------------------------------------------------------
u16 si47xxAMRX_get_frequency()
{
// Get the tune status which contains the current frequency
amTuneStatus(0, 0);
// Return the frequency
return Freq;
}
//-----------------------------------------------------------------------------
// Returns the current tuned frequency of the part
//
// Returns:
// frequency in 10kHz steps
//-----------------------------------------------------------------------------
u8 si47xxAMRX_get_rssi()
{
// Get the tune status which contains the current frequency
amTuneStatus(0,0); // This should be changed to Rsq status when working.
// Return the RSSI level
return RSSI;
}
//-----------------------------------------------------------------------------
// Helper function that sends the AM_TUNE_FREQ command to the part
//
// Inputs:
// frequency in 1kHz steps
//-----------------------------------------------------------------------------
static void amTuneFreq(u16 frequency)
{
// Put the ID for the command in the first byte.
cmd[0] = AM_TUNE_FREQ;
// Initialize the reserved section to 0
cmd[1] = 0;
// Put the frequency in the second and third bytes.
cmd[2] = (u8)(frequency >> 8);
cmd[3] = (u8)(frequency & 0x00FF);
// Set the antenna calibration value.
cmd[4] = (u8)0; // Auto
cmd[5] = (u8)0;
// Invoke the command
si47xx_command(6, cmd, 1, rsp);
}
//-----------------------------------------------------------------------------
// Helper function that sends the AM_SEEK_START command to the part
//
// Inputs:
// seekUp: If non-zero seek will increment otherwise decrement
// wrap: If non-zero seek will wrap around band limits when hitting the end
// of the band limit.
//-----------------------------------------------------------------------------
static void amSeekStart(u8 seekUp, u8 wrap)
{
// Put the ID for the command in the first byte.
cmd[0] = AM_SEEK_START;
// Put the flags if the bit was set for the input parameters.
cmd[1] = 0;
if(seekUp) cmd[1] |= AM_SEEK_START_IN_SEEKUP;
if(wrap) cmd[1] |= AM_SEEK_START_IN_WRAP;
// Invoke the command
si47xx_command(2, cmd, 1, rsp);
}
//-----------------------------------------------------------------------------
// Helper function that sends the AM_TUNE_STATUS command to the part
//
// Inputs:
// cancel: If non-zero the current seek will be cancelled.
// intack: If non-zero the interrupt for STCINT will be cleared.
//
// Outputs: // These are global variables and are set by this method
// STC: The seek/tune is complete
// BLTF: The seek reached the band limit or original start frequency
// AFCRL: The AFC is railed if this is non-zero
// Valid: The station is valid if this is non-zero
// Freq: The current frequency
// RSSI: The RSSI level read at tune.
// ASNR: The audio SNR level read at tune.
// AntCap: The current level of the tuning capacitor.
//-----------------------------------------------------------------------------
static void amTuneStatus(u8 cancel, u8 intack)
{
// Put the ID for the command in the first byte.
cmd[0] = AM_TUNE_STATUS;
// Put the flags if the bit was set for the input parameters.
cmd[1] = 0;
if(cancel) cmd[1] |= AM_TUNE_STATUS_IN_CANCEL;
if(intack) cmd[1] |= AM_TUNE_STATUS_IN_INTACK;
// Invoke the command
si47xx_command(2, cmd, 8, rsp);
// Parse the results
STC = !!(rsp[0] & STCINT);
BLTF = !!(rsp[1] & AM_TUNE_STATUS_OUT_BTLF);
AFCRL = !!(rsp[1] & AM_TUNE_STATUS_OUT_AFCRL);
Valid = !!(rsp[1] & AM_TUNE_STATUS_OUT_VALID);
Freq = ((u16)rsp[2] << 8) | (u16)rsp[3];
RSSI = rsp[4];
ASNR = rsp[5];
AntCap = ((u16)rsp[6] << 8) | (u16)rsp[7];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -