1
|
|
2
|
#include <stdint.h>
|
3
|
#include <stdio.h>
|
4
|
#include <unistd.h>
|
5
|
#include <stdlib.h>
|
6
|
#include <errno.h>
|
7
|
#include <string.h>
|
8
|
#include <stdarg.h>
|
9
|
|
10
|
#include <common.h>
|
11
|
#include <tuner_e4k.h>
|
12
|
|
13
|
|
14
|
void logp2(int subsys, unsigned int level, char *file,
|
15
|
int line, int cont, const char *format, ...)
|
16
|
{
|
17
|
va_list ap;
|
18
|
fprintf(stderr, "%u/%u/%s:%u: ", subsys, level, file, line);
|
19
|
|
20
|
va_start(ap, format);
|
21
|
vfprintf(stderr, format, ap);
|
22
|
va_end(ap);
|
23
|
}
|
24
|
|
25
|
|
26
|
static uint8_t regs[0x7f];
|
27
|
|
28
|
/* stub functions for register read/write */
|
29
|
int e4k_reg_write(struct e4k_state *e4k, uint8_t reg, uint8_t val)
|
30
|
{
|
31
|
printf("REG WRITE: [0x%02x] = 0x%02x\n", reg, val);
|
32
|
|
33
|
if (reg > ARRAY_SIZE(regs))
|
34
|
return -ERANGE;
|
35
|
|
36
|
regs[reg] = val;
|
37
|
|
38
|
return 0;
|
39
|
}
|
40
|
|
41
|
int e4k_reg_read(struct e4k_state *e4k, uint8_t reg)
|
42
|
{
|
43
|
if (reg > ARRAY_SIZE(regs))
|
44
|
return -ERANGE;
|
45
|
|
46
|
printf("REG READ: [0x%02x] = 0x%02x\n", reg, regs[reg]);
|
47
|
|
48
|
return regs[reg];
|
49
|
}
|
50
|
|
51
|
static struct e4k_state g_e4k;
|
52
|
|
53
|
#define FOSC 26000000
|
54
|
|
55
|
static void dump_params(struct e4k_pll_params *p)
|
56
|
{
|
57
|
int32_t delta = p->intended_flo - p->flo;
|
58
|
|
59
|
printf("Flo_int = %u: R=%u, X=%u, Z=%u, Flo = %u, delta=%d\n",
|
60
|
p->intended_flo, p->r, p->x, p->z, p->flo, delta);
|
61
|
}
|
62
|
|
63
|
static void compute_and_dump(uint32_t flo)
|
64
|
{
|
65
|
struct e4k_pll_params params;
|
66
|
int rc;
|
67
|
|
68
|
memset(¶ms, 0, sizeof(params));
|
69
|
rc = e4k_compute_pll_params(¶ms, FOSC, flo);
|
70
|
if (rc < 0) {
|
71
|
fprintf(stderr, "something went wrong!\n");
|
72
|
exit(1);
|
73
|
}
|
74
|
|
75
|
dump_params(¶ms);
|
76
|
e4k_tune_params(&g_e4k, ¶ms);
|
77
|
}
|
78
|
|
79
|
static const uint32_t test_freqs[] = {
|
80
|
888000000, 66666666, 425000000
|
81
|
};
|
82
|
//1234567890
|
83
|
|
84
|
int main(int argc, char **argv)
|
85
|
{
|
86
|
int i;
|
87
|
|
88
|
printf("Initializing....\n");
|
89
|
e4k_init(&g_e4k);
|
90
|
|
91
|
for (i = 0; i < ARRAY_SIZE(test_freqs); i++) {
|
92
|
compute_and_dump(test_freqs[i]);
|
93
|
}
|
94
|
}
|