Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some quality of life changes around invalid parameters #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ extra cooling required above 40mhz).
This value is ONLY used to compute the sample rates entered for the tenxfsc parameters other than 0, 1, 2.


### `center_offset` (0 to 255, default 2)

### `center_offset` (0 to 63, default 0)

This option allows you to manually adjust DC centre offset or the centring of the RF signal you wish to capture.

Expand Down
49 changes: 32 additions & 17 deletions cxadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#define default_tenxfsc 0
#define default_sixdb 1
#define default_crystal 28636363
#define default_center_offset 8
#define default_center_offset 0

#define cx_read(reg) readl(ctd->mmio + ((reg) >> 2))
#define cx_write(reg, value) writel((value), ctd->mmio + ((reg) >> 2))
Expand All @@ -56,6 +56,8 @@
dev_err(&ctd->pci->dev, fmt, ##__VA_ARGS__)
#define cx_info(fmt, ...) \
dev_info(&ctd->pci->dev, fmt, ##__VA_ARGS__)
#define cx_notice(fmt, ...) \
dev_notice(&ctd->pci->dev, fmt, ##__VA_ARGS__)

/* 64 Mbytes VBI DMA BUFF */
#define VBI_DMA_BUFF_SIZE (1024*1024*64)
Expand Down Expand Up @@ -627,6 +629,31 @@ static int make_risc_instructions(struct cxadc *ctd)
return 0;
}

static void bound_parameters(struct cxadc *ctd)
{
if (ctd->level < 0) {
cx_notice("Negative 'level' value: %d, setting to 0\n",
ctd->level);
ctd->level = 0;
}
if (ctd->level > 31) {
cx_notice("Excessively large 'level' value: %d, setting to 31\n",
ctd->level);
ctd->level = 31;
}

if (ctd->center_offset < 0) {
cx_notice("Negative 'center_offset' value: %d, setting to 0\n",
ctd->center_offset);
ctd->center_offset = 0;
}
if (ctd->center_offset > 63) {
cx_notice("Excessively large 'center_offset' value: %d, setting to 63\n",
ctd->level);
ctd->center_offset = 63;
}
}

static int cxadc_char_open(struct inode *inode, struct file *file)
{
int minor = iminor(inode);
Expand Down Expand Up @@ -665,10 +692,7 @@ static int cxadc_char_open(struct inode *inode, struct file *file)

/* re-set the level, clock speed, and bit size */

if (ctd->level < 0)
ctd->level = 0;
if (ctd->level > 31)
ctd->level = 31;
bound_parameters(ctd);
/* control gain also bit 16 */
cx_write(MO_AGC_GAIN_ADJ4, (ctd->sixdb<<23)|(0<<22)|(0<<21)|(ctd->level<<16)|(0xff<<8)|(0x0<<0));
cx_write(MO_AGC_SYNC_TIP3, (0x1e48<<16)|(0xff<<8)|(ctd->center_offset));
Expand Down Expand Up @@ -799,10 +823,7 @@ static ssize_t cxadc_char_read(struct file *file, char __user *tgt,
* adding code to allow level change during read, have tested, works with CAV capture
* script i have been working on
*/
if (ctd->level < 0)
ctd->level = 0;
if (ctd->level > 31)
ctd->level = 31;
bound_parameters(ctd);
cx_write(MO_AGC_GAIN_ADJ4, (ctd->sixdb<<23)|(0<<22)|(0<<21)|(ctd->level<<16)|(0xff<<8)|(0x0<<0));
cx_write(MO_AGC_SYNC_TIP3, (0x1e48<<16)|(0xff<<8)|(ctd->center_offset));

Expand Down Expand Up @@ -1148,10 +1169,7 @@ static int cxadc_probe(struct pci_dev *pci_dev,
/* set vbi agc */
cx_write(MO_AGC_SYNC_SLICER, 0x0);

if (ctd->level < 0)
ctd->level = 0;
if (ctd->level > 31)
ctd->level = 31;
bound_parameters(ctd);

cx_write(MO_AGC_BACK_VBI, (0<<27)|(0<<26)|(1<<25)|(0x100<<16)|(0xfff<<0));
/* control gain also bit 16 */
Expand Down Expand Up @@ -1400,10 +1418,7 @@ static int cxadc_resume(struct pci_dev *pci_dev)
/* set vbi agc */
cx_write(MO_AGC_SYNC_SLICER, 0x0);

if (ctd->level < 0)
ctd->level = 0;
if (ctd->level > 31)
ctd->level = 31;
bound_parameters(ctd);

cx_write(MO_AGC_BACK_VBI, (0<<27)|(0<<26)|(1<<25)|(0x100<<16)|(0xfff<<0));
/* control gain also bit 16 */
Expand Down