BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
tlv.h
Go to the documentation of this file.
1 /* Copyright 2012-2014, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
54 #ifndef BSP430_UTILITY_TLV_H
55 #define BSP430_UTILITY_TLV_H
56 
57 #include <bsp430/core.h>
58 
65 #ifndef configBSP430_TLV
66 #define configBSP430_TLV 0
67 #endif /* configBSP430_TLV */
68 
77 #if defined(BSP430_DOXYGEN) || defined(configBSP430_TLV)
78 #define BSP430_TLV (configBSP430_TLV - 0)
79 #endif /* BSP430_TLV */
80 
83 typedef struct sBSP430tlvEntry {
85  unsigned char tag;
88  unsigned char len;
90 
94 typedef struct sBSP430tlvTable2xx {
96  unsigned int crc;
97  union {
99  unsigned int words[1];
102  };
104 
109 typedef struct sBSP430tlvTable5xx {
113  unsigned char info_len_lg2;
116  unsigned char crc_len_lg2;
119  unsigned int crc;
121  unsigned int device_id;
123  unsigned char firmware_revision;
125  unsigned char hardware_revision;
126  union {
128  unsigned int words[1];
131  };
133 
144 #define BSP430_TLV_IS_5XX defined(__MSP430_HAS_MSP430XV2_CPU__)
145 
149 #if defined(BSP430_DOXYGEN) || (BSP430_TLV_IS_5XX - 0)
151 #else /* BSP430_TLV_IS_5XX */
153 #endif /* BSP430_TLV_IS_5XX */
154 
161 #define BSP430_TLV_NEXT_ENTRY(ep_) ((sBSP430tlvEntry *)(sizeof(sBSP430tlvEntry) + (ep_)->len + (unsigned char *)(ep_)))
162 
170 #if defined(BSP430_DOXYGEN) || (BSP430_TLV_IS_5XX - 0)
171 #define BSP430_TLV_ENTRY_IS_ADC(ep_) ((TLV_ADC10CAL == (ep_)->tag) || (TLV_ADC12CAL == (ep_)->tag))
172 #else /* BSP430_TLV_IS_5XX */
173 #define BSP430_TLV_ENTRY_IS_ADC(ep_) ((TAG_DCO_30 != (ep_)->tag) && (TAG_EMPTY != (ep_)->tag))
174 #endif /* BSP430_TLV_IS_5XX */
175 
176 #if defined(BSP430_DOXYGEN) || (BSP430_TLV_IS_5XX - 0)
177 
178 /* Standard definitions when missing from header */
179 #ifndef TLV_LDTAG
180 #define TLV_LDTAG (0x01)
181 #endif /* TLV_LDTAG */
182 #ifndef TLV_PDTAG
183 #define TLV_PDTAG (0x02)
184 #endif /* TLV_PDTAG */
185 #ifndef TLV_BLANK
186 #define TLV_BLANK (0x05)
187 #endif /* TLV_BLANK */
188 #ifndef TLV_DIERECORD
189 #define TLV_DIERECORD (0x08)
190 #endif /* TLV_DIERECORD */
191 #ifndef TLV_ADC12CAL
192 #define TLV_ADC12CAL (0x11)
193 #endif /* TLV_ADC12CAL */
194 #ifndef TLV_REFCAL
195 #define TLV_REFCAL (0x12)
196 #endif /* TLV_REFCAL */
197 #ifndef TLV_ADC10CAL
198 #define TLV_ADC10CAL (0x13)
199 #endif /* TLV_ADC10CAL */
200 #ifndef TLV_TAGEXT
201 #define TLV_TAGEXT (0xFE)
202 #endif /* TLV_TAGEXT */
203 
209 typedef struct sBSP430tlvDIERECORD {
211  unsigned long lot_id;
212  unsigned int die_x_position;
213  unsigned int die_y_position;
214  unsigned int test_results;
216 
221 typedef struct sBSP430tlvREFCAL {
223  unsigned int cal_adc_15vref_factor;
224  unsigned int cal_adc_20vref_factor;
225  unsigned int cal_adc_25vref_factor;
227 
237 typedef struct sBPS430tlvADCCAL {
239  unsigned int cal_adc_gain_factor;
240  unsigned int cal_adc_offset;
241  unsigned int cal_adc_15t30;
242  unsigned int cal_adc_15t85;
243  unsigned int cal_adc_20t30;
244  unsigned int cal_adc_20t85;
245  unsigned int cal_adc_25t30;
246  unsigned int cal_adc_25t85;
248 
249 #if 0
250 /* Documented in FR5XX user guide, but no examples available. This
251  * structure may need to be packed to correctly locate
252  * bsl_cif_config. */
253 typedef struct sBSP430tlvBSL {
254  sBSP430tlvEntry hdr;
255  unsigned char bsl_com_if;
256  unsigned char bsl_cif_config[1];
257 } sBSP430tlvBSL;
258 #endif /* 0 */
259 
260 #endif /* BSP430_TLV_IS_5XX */
261 
262 #if defined(BSP430_DOXYGEN) || ! (BSP430_TLV_IS_5XX - 0)
263 
264 /* Standard definitions when missing from header */
265 #ifndef TAG_DCO_30
266 #define TAG_DCO_30 (0x01)
267 #endif /* TAG_DCO_30 */
268 #ifndef TAG_EMPTY
269 #define TAG_EMPTY (0xFE)
270 #endif /* TAG_EMPTY */
271 
278 typedef struct sBSP430tlvDCO {
280  unsigned char caldco_16MHz;
281  unsigned char calbc1_16MHz;
282  unsigned char caldco_12MHz;
283  unsigned char calbc1_12MHz;
284  unsigned char caldco_8MHz;
285  unsigned char calbc1_8MHz;
286  unsigned char caldco_1MHz;
287  unsigned char calbc1_1MHz;
288 } sBSP430tlvDCO;
289 
301 typedef struct sBPS430tlvADC {
303  unsigned int cal_adc_gain_factor;
304  unsigned int cal_adc_offset;
305  unsigned int cal_adc_15vref_factor;
306  unsigned int cal_adc_15t30;
307  unsigned int cal_adc_15t85;
308  unsigned int cal_adc_25vref_factor;
309  unsigned int cal_adc_25t30;
310  unsigned int cal_adc_25t85;
311 } sBSP430tlvADC;
312 
313 #endif /* ! BSP430_TLV_IS_5XX */
314 
315 #if defined(BSP430_DOXYGEN) || (BSP430_TLV_IS_5XX - 0)
316 
317 #define BSP430_TLV_TABLE_DATA_OFFSET 4
318 
320 #define BSP430_TLV_TABLE_PREFIX_LENGTH 8
321 #ifndef TLV_START
322 
330 #define TLV_START (BSP430_TLV_TABLE_PREFIX_LENGTH + *(const unsigned int *)0x0FF4)
331 
338 #define TLV_END (TLV_START - BSP430_TLV_TABLE_PREFIX_LENGTH + (4 << ((const sBSP430tlvTable *)BSP430_TLV_TABLE_START)->info_len_lg2) - 1)
339 #endif /* TLV_START */
340 #else /* BSP430_TLV_IS_5XX */
341 #define BSP430_TLV_TABLE_DATA_OFFSET 2
342 #define BSP430_TLV_TABLE_PREFIX_LENGTH 2
343 #define TLV_START 0x10C2
344 #define TLV_END 0x10FF
345 #endif /* BSP430_TLV_IS_5XX */
346 
352 #define BSP430_TLV_TABLE_START ((const unsigned char *)TLV_START - BSP430_TLV_TABLE_PREFIX_LENGTH)
353 
359 #define BSP430_TLV_TABLE_IS_VALID() \
360  (((const sBSP430tlvTable *)BSP430_TLV_TABLE_START)->crc \
361  == uiBSP430tlvChecksum(BSP430_TLV_TABLE_START + BSP430_TLV_TABLE_DATA_OFFSET, \
362  (1 + (const unsigned char *)TLV_END) - (BSP430_TLV_TABLE_START + BSP430_TLV_TABLE_DATA_OFFSET)))
363 
393 unsigned int uiBSP430tlvChecksum (const unsigned char * data,
394  size_t len);
395 
396 #endif /* BSP430_UTILITY_TLV_H */
unsigned char caldco_8MHz
Definition: tlv.h:284
unsigned char len
Definition: tlv.h:88
struct sBSP430tlvDIERECORD sBSP430tlvDIERECORD
Definition: tlv.h:278
unsigned int cal_adc_15t30
Definition: tlv.h:306
unsigned int die_x_position
Definition: tlv.h:212
unsigned int words[1]
Definition: tlv.h:128
Definition: tlv.h:83
sBSP430tlvEntry hdr
Definition: tlv.h:302
unsigned int cal_adc_20vref_factor
Definition: tlv.h:224
Definition: tlv.h:237
struct sBSP430tlvDCO sBSP430tlvDCO
unsigned int cal_adc_20t85
Definition: tlv.h:244
unsigned int device_id
Definition: tlv.h:121
unsigned int crc
Definition: tlv.h:119
struct sBPS430tlvADC sBSP430tlvADC
Common header included by all BSP430 leaf headers.
sBSP430tlvEntry hdr
Definition: tlv.h:279
unsigned int crc
Definition: tlv.h:96
unsigned char calbc1_16MHz
Definition: tlv.h:281
unsigned char info_len_lg2
Definition: tlv.h:113
unsigned int cal_adc_gain_factor
Definition: tlv.h:303
unsigned int words[1]
Definition: tlv.h:99
unsigned int cal_adc_15vref_factor
Definition: tlv.h:223
struct sBSP430tlvTable2xx sBSP430tlvTable2xx
unsigned int die_y_position
Definition: tlv.h:213
unsigned char calbc1_1MHz
Definition: tlv.h:287
struct sBSP430tlvREFCAL sBSP430tlvREFCAL
unsigned char caldco_16MHz
Definition: tlv.h:280
unsigned char caldco_12MHz
Definition: tlv.h:282
unsigned int test_results
Definition: tlv.h:214
unsigned int cal_adc_25t30
Definition: tlv.h:309
unsigned char hardware_revision
Definition: tlv.h:125
unsigned int cal_adc_25t85
Definition: tlv.h:246
unsigned int cal_adc_25t85
Definition: tlv.h:310
sBSP430tlvEntry hdr
Definition: tlv.h:222
unsigned int cal_adc_gain_factor
Definition: tlv.h:239
unsigned char crc_len_lg2
Definition: tlv.h:116
Definition: tlv.h:209
Definition: tlv.h:94
Definition: tlv.h:109
sBSP430tlvEntry entry
Definition: tlv.h:130
unsigned char firmware_revision
Definition: tlv.h:123
Definition: tlv.h:221
unsigned char tag
Definition: tlv.h:85
struct sBSP430tlvEntry sBSP430tlvEntry
unsigned int cal_adc_offset
Definition: tlv.h:304
unsigned int uiBSP430tlvChecksum(const unsigned char *data, size_t len)
unsigned int cal_adc_20t30
Definition: tlv.h:243
unsigned int cal_adc_15t85
Definition: tlv.h:307
unsigned int cal_adc_15t30
Definition: tlv.h:241
unsigned long lot_id
Definition: tlv.h:211
sBSP430tlvEntry entry
Definition: tlv.h:101
struct sBPS430tlvADCCAL sBSP430tlvADCCAL
unsigned char calbc1_12MHz
Definition: tlv.h:283
sBSP430tlvEntry hdr
Definition: tlv.h:238
unsigned int cal_adc_15t85
Definition: tlv.h:242
struct sBSP430tlvTable5xx sBSP430tlvTable5xx
unsigned int cal_adc_offset
Definition: tlv.h:240
unsigned int cal_adc_25t30
Definition: tlv.h:245
unsigned int cal_adc_15vref_factor
Definition: tlv.h:305
Definition: tlv.h:301
unsigned int cal_adc_25vref_factor
Definition: tlv.h:225
unsigned int cal_adc_25vref_factor
Definition: tlv.h:308
unsigned char caldco_1MHz
Definition: tlv.h:286
sBSP430tlvTable5xx sBSP430tlvTable
Definition: tlv.h:150
sBSP430tlvEntry hdr
Definition: tlv.h:210
unsigned char calbc1_8MHz
Definition: tlv.h:285