-
Notifications
You must be signed in to change notification settings - Fork 145
/
eeprom.h
130 lines (102 loc) · 3.23 KB
/
eeprom.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*
* XCOMM on-board calibration EEPROM definitions.
*
* Copyright 2012-2014 Analog Devices Inc.
*
* Licensed under the GPL-2.
*/
#ifndef XCOMM_EEPROM_H_
#define XCOMM_EEPROM_H_
#define FAB_SIZE_FRU_EEPROM 256
#define CURRENT_VERSION 1
#define MAX_SIZE_CAL_EEPROM 254
#define FAB_SIZE_CAL_EEPROM 256
#define NEXT_TERMINATION 0
#define ADI_MAGIC_0 'A'
#define ADI_MAGIC_1 'D'
#define ADI_VERSION(v) ('0' + (v))
const char *find_eeprom(const char *path);
/* Version 0 */
struct fmcomms1_calib_data {
char adi_magic0;
char adi_magic1;
char version;
unsigned char next;
unsigned short cal_frequency_MHz;
/* DAC Calibration Data */
short i_phase_adj; /* 10-bit */
short q_phase_adj; /* 10-bit */
unsigned short i_dac_offset; /* 16-bit */
unsigned short q_dac_offset; /* 16-bit */
unsigned short i_dac_fs_adj; /* 10-bit */
unsigned short q_dac_fs_adj; /* 10-bit */
/* ADC Calibration Data */
short i_adc_offset_adj; /* 16-bit signed */
unsigned short i_adc_gain_adj; /* 16-bit fract 1.15 */
short q_adc_offset_adj; /* 16-bit signed */
unsigned short q_adc_gain_adj; /* 16-bit fract 1.15 */
} __attribute__((packed));
/* Version 1 */
struct fmcomms1_calib_header_v1 {
char adi_magic0;
char adi_magic1;
char version;
unsigned char num_entries;
unsigned short temp_calibbias;
} __attribute__((packed));
struct fmcomms1_calib_data_v1 {
unsigned short cal_frequency_MHz;
/* DAC Calibration Data */
short i_phase_adj; /* 10-bit */
short q_phase_adj; /* 10-bit */
short i_dac_offset; /* 16-bit */
short q_dac_offset; /* 16-bit */
unsigned short i_dac_fs_adj; /* 10-bit */
unsigned short q_dac_fs_adj; /* 10-bit */
/* ADC Calibration Data */
short i_adc_offset_adj; /* 16-bit signed */
unsigned short i_adc_gain_adj; /* 16-bit fract 1.1.14 */
unsigned short i_adc_phase_adj; /* 16-bit fract 1.1.14 */
short q_adc_offset_adj; /* 16-bit signed */
unsigned short q_adc_gain_adj; /* 16-bit fract 1.1.14 */
} __attribute__((packed));
static inline unsigned short float_to_fract1_15(double val)
{
unsigned long long llval;
if (val < 0.0)
val = 0.0;
else if (val >= 2.0)
val = 1.999999;
val *= 1000000;
llval = (unsigned long long)val * 0x8000UL;
return (llval / 1000000);
}
static inline double fract1_15_to_float(unsigned short val)
{
return (double)val / 0x8000;
}
static inline unsigned short float_to_fract1_1_14(double val)
{
unsigned short fract;
unsigned long long llval;
if (val < 0.000000) {
fract = 0x8000;
val *= -1.0;
} else {
fract = 0;
}
if (val >= 2.0)
val = 1.999999;
val *= 1000000;
llval = (unsigned long long)val * 0x4000UL;
fract |= (llval / 1000000);
return fract;
}
static inline double fract1_1_14_to_float(unsigned short val)
{
double ret = (double)(val & 0x7FFF) / 0x4000UL;
if (val & 0x8000)
return -ret;
return ret;
}
#endif /* XCOMM_EEPROM_H_ */