-
Notifications
You must be signed in to change notification settings - Fork 0
/
tlv.c
89 lines (80 loc) · 2.6 KB
/
tlv.c
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
/*
* tlv.c -- MSP430Framework for LaunchPad
* by yasunoxx
* ### Use mspgcc(4.6.3 or later) only !!! ###
*/
/* original source by Paul Haddad
http://e2e.ti.com/support/microcontrollers/msp430/f/166/t/89118.aspx?pi24337=1
*/
#ifdef GCC_VERSION_463
#include <legacymsp430.h>
#else
#include <msp430g2553.h>
#endif
#include <string.h>
#include "tlv.h"
unsigned short Var_CAL_ADC_GAIN_FACTOR;
unsigned short Var_CAL_ADC_OFFSET;
unsigned short Var_CAL_ADC_15VREF_FACTOR;
unsigned short Var_CAL_ADC_15T30, Var_CAL_ADC_15T85;
unsigned short Var_CAL_ADC_25VREF_FACTOR;
unsigned short Var_CAL_ADC_25T30, Var_CAL_ADC_25T85;
unsigned char Var_CALDCO_16MHz, Var_CALBC1_16MHz;
unsigned char Var_CALDCO_12MHz, Var_CALBC1_12MHz;
unsigned char Var_CALDCO_8MHz, Var_CALBC1_8MHz;
unsigned char Var_CALDCO_1MHz, Var_CALBC1_1MHz;
void GetTLV( void )
{
unsigned char data[ TLV_SIZE ];
unsigned char count = 0;
unsigned short checksum;
memcpy( data, (void *)TLV_START, TLV_SIZE ); // Read TLV
// FIXME: add here CHECKSUM VALIDATION
checksum = data[ count++ ];
checksum += data[ count ++ ] << 8;
while( 1 )
{
if( data[ count ] == TAG_EMPTY )
{
count++;
count += data[ count ];
count++;
}
else if( data[ count ] == TAG_ADC10_1 )
// else if( data[ count ] == TAG_ADC10_1 || data[ count ] == TAG_ADC12_1 )
{
count++;
count++; // size
Var_CAL_ADC_GAIN_FACTOR = data[ count++ ];
Var_CAL_ADC_GAIN_FACTOR += data[ count++ ] << 8;
Var_CAL_ADC_OFFSET = data[ count++ ];
Var_CAL_ADC_OFFSET += data[ count++ ] << 8;
Var_CAL_ADC_15VREF_FACTOR = data[ count++ ];
Var_CAL_ADC_15VREF_FACTOR += data[ count++ ] << 8;
Var_CAL_ADC_15T30 = data[ count++ ];
Var_CAL_ADC_15T30 += data[ count++ ] << 8;
Var_CAL_ADC_15T85 = data[ count++ ];
Var_CAL_ADC_15T85 += data[ count++ ] << 8;
Var_CAL_ADC_25VREF_FACTOR = data[ count++ ];
Var_CAL_ADC_25VREF_FACTOR += data[ count++ ] << 8;
Var_CAL_ADC_25T30 = data[ count++ ];
Var_CAL_ADC_25T30 += data[ count++ ] << 8;
Var_CAL_ADC_25T85 = data[ count++ ];
Var_CAL_ADC_25T85 += data[ count++ ] << 8;
}
else if( data[ count ] == TAG_DCO_30 )
{
count++;
count++; // size
Var_CALDCO_16MHz = data[ count++ ];
Var_CALBC1_16MHz = data[ count++ ];
Var_CALDCO_12MHz = data[ count++ ];
Var_CALBC1_12MHz = data[ count++ ];
Var_CALDCO_8MHz = data[ count++ ];
Var_CALBC1_8MHz = data[ count++ ];
Var_CALDCO_1MHz = data[ count++ ];
Var_CALBC1_1MHz = data[ count++ ];
}
if( count >= TLV_SIZE ) break;
} // endwhile
}