📄 hamaro_iq.c
字号:
}
/* copy data from HAMARO_IQPAK to user buffer */
for (cnt = 0 ; cnt < iqcount ; cnt++)
{
ptr = (nim->iqpak->head+cnt)%nim->iqpak->max;
ivals[cnt] = nim->iqpak->I[ptr];
qvals[cnt] = nim->iqpak->Q[ptr];
}
return(True);
} /* HAMARO_ConstGetPoints() */
/*******************************************************************************************************/
/* HAMARO_ConstGetIQSample() */
/*******************************************************************************************************/
BOOL HAMARO_ConstGetIQSample( /* function to retrieve IQ sample from hardware */
HAMARO_NIM *nim, /* pointer to nim */
unsigned char *I, /* pointer to where I portion will be written */
unsigned char *Q) /* pointer to where Q portion will be written */
{
/* proposed API to retrieve data from HAMARO_IQ_SampleGetIq() */
/* test for valid IQ pointer */
if (HAMARO_DRIVER_ValidateNimIq(nim) == False) return(False);
/* test for valid buffers */
if (I == NULL || Q == NULL)
{
/* invalid pointer */
HAMARO_DRIVER_SET_ERROR(nim,HAMARO_CONST_IQBUF);
return(False);
}
/* retrieve I, Q samples directly from hardware via ser.bus */
return (HAMARO_IQ_SampleGetIq(nim,I,Q));
} /* HAMARO_ConstGetIQSample() */
/*******************************************************************************************************/
/* HAMARO_IQ_SampleGetIq() */
/*******************************************************************************************************/
BOOL HAMARO_IQ_SampleGetIq( /* function to retrieve I,Q sample data from hardware */
HAMARO_NIM *nim, /* pointer to nim */
unsigned char *ival, /* pointer to storage for I */
unsigned char *qval) /* pointer to storage for Q */
{
unsigned char temp1;
unsigned char temp2;
unsigned long ulRegVal;
int err = 0;
/* read the IQ register twice -- first s/b I or Q, 2nd s/b Q or I */
if (HAMARO_RegisterRead(nim,CX2430X_CONSTIQ,&ulRegVal, HAMARO_DEMOD_I2C_IO) != True) err++;
temp1 = (unsigned char)ulRegVal;
if (HAMARO_RegisterRead(nim,CX2430X_CONSTIQ,&ulRegVal, HAMARO_DEMOD_I2C_IO) != True) err++;
temp2 = (unsigned char)ulRegVal;
/* test that the bytes were read */
if (err == 0)
{
/* test that I, Q data are paired. If not, save 2nd read, try to get the next match */
if ((temp1&0x80) != (temp2&0x80))
{
/* pairs did not match, so more temp2 to temp1, then try to read again */
temp1 = temp2;
if (HAMARO_RegisterRead(nim,CX2430X_CONSTIQ,&ulRegVal, HAMARO_DEMOD_I2C_IO) != True) err++;
temp1 = (unsigned char)ulRegVal;
/* if bytes are NOT matched, then we got a hardware prob. report prob */
if ((temp1&0x80) != (temp2&0x80))
{
/* unable to match I, Q pair. report error */
HAMARO_DRIVER_SET_ERROR(nim,HAMARO_IQ_IO);
return(False);
}
}
/* pairs did match, place them in order, return values to caller */
if ((temp1&0x40) == 0x40)
{
*qval = (unsigned char)(temp1&0x3f);
*ival = (unsigned char)(temp2&0x3f);
}
else
{
*ival = (unsigned char)(temp1&0x3f);
*qval = (unsigned char)(temp2&0x3f);
}
return(True);
}
HAMARO_DRIVER_SET_ERROR(nim,HAMARO_IQ_IO);
return(False);
} /* HAMARO_IQ_SampleGetIq() */
/*******************************************************************************************************/
/* HAMARO_IQ_Sample() */
/*******************************************************************************************************/
BOOL HAMARO_IQ_Sample( /* function to retrieve I,Q data from demod, place into HAMARO_IQPAK */
HAMARO_NIM *nim) /* pointer to nim */
{
static unsigned char I = 0; /* static for testing only */
static unsigned char Q = 0;
/* test for valid HAMARO_NIM, IQ pointer */
HAMARO_DRIVER_VALIDATE_NIM(nim);
if (HAMARO_DRIVER_ValidateNimIq(nim) == False) return(False);
/* test for IQ busy -- don't save I,Q data if busy -- if busy, return TRUE (no error, just busy!) */
if (nim->iqpak->busy == True) return(True);
/* extract the I, Q values from the Demod */
if (HAMARO_IQ_SampleGetIq(nim,&I,&Q) == False) return(False);
/* determine where to place I,Q data */
nim->iqpak->tail++;
if (nim->iqpak->tail == nim->iqpak->head)
{
nim->iqpak->head++;
if (nim->iqpak->head >= nim->iqpak->max) nim->iqpak->head = 0;
}
if (nim->iqpak->tail >= nim->iqpak->max)
{
/* tail has wrapped around */
nim->iqpak->tail = 0;
nim->iqpak->head++;
if (nim->iqpak->head >= nim->iqpak->max)
{
nim->iqpak->head = 0;
}
}
/* place the I,Q values into the buffer */
nim->iqpak->I[nim->iqpak->tail] = I;
nim->iqpak->Q[nim->iqpak->tail] = Q;
return(True);
} /* HAMARO_IQ_Sample() */
/*******************************************************************************************************/
/* HAMARO_IQ_ConstCount() */
/*******************************************************************************************************/
int HAMARO_IQ_ConstCount( /* function to return the count of IQ samples in HAMARO_IQPAK */
HAMARO_NIM *nim) /* pointer to nim */
{
/* return count of I,Q values saved */
return( (nim->iqpak->head>nim->iqpak->tail?nim->iqpak->max-(nim->iqpak->head-nim->iqpak->tail-1)
:nim->iqpak->tail-nim->iqpak->head) );
} /* HAMARO_IQ_ConstCount() */
/*******************************************************************************************************/
/* HAMARO_ConstGetUnbufferredIQSample() */
/*******************************************************************************************************/
BOOL HAMARO_ConstGetUnbufferredIQSample( /* funct to return unbuffered i, q results from demod */
HAMARO_NIM *nim, /* pointer to nim */
signed char *I, /* pointer to storage where I value will be returned to caller */
signed char *Q) /* pointer to storage where Q value will be returned to caller */
{
unsigned char i;
unsigned char q;
/* grab raw I,Q data from demod, convert it into a pos/neg */
if (HAMARO_IQ_SampleGetIq(nim,&i,&q) == False) return(False);
*I = (signed char)HAMARO_DRIVER_convert_twos(i,6);
*Q = (signed char)HAMARO_DRIVER_convert_twos(q,6);
return(True);
} /* HAMARO_ConstGetUnbufferredIQSample() */
/*******************************************************************************************************/
/*******************************************************************************************************/
#endif /* #ifdef HAMARO_INCLUDE_CONSTELLATION */
/*******************************************************************************************************/
/*******************************************************************************************************/
/*******************************************************************************************************/
/* CR 9509 : Add an extra newline */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -