BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Data Structures | Macros | Typedefs | Functions
tlv.h File Reference

Basic support for MSP430 Tag-Length-Value device descriptors. More...

#include <bsp430/core.h>

Go to the source code of this file.

Data Structures

struct  sBSP430tlvEntry
 
struct  sBSP430tlvTable2xx
 
struct  sBSP430tlvTable5xx
 
struct  sBSP430tlvDIERECORD
 
struct  sBSP430tlvREFCAL
 
struct  sBPS430tlvADCCAL
 
struct  sBSP430tlvDCO
 
struct  sBPS430tlvADC
 

Macros

#define configBSP430_TLV   0
 
#define BSP430_TLV   (configBSP430_TLV - 0)
 
#define BSP430_TLV_IS_5XX   defined(__MSP430_HAS_MSP430XV2_CPU__)
 
#define BSP430_TLV_NEXT_ENTRY(ep_)   ((sBSP430tlvEntry *)(sizeof(sBSP430tlvEntry) + (ep_)->len + (unsigned char *)(ep_)))
 
#define BSP430_TLV_ENTRY_IS_ADC(ep_)   ((TLV_ADC10CAL == (ep_)->tag) || (TLV_ADC12CAL == (ep_)->tag))
 
#define TLV_LDTAG   (0x01)
 
#define TLV_PDTAG   (0x02)
 
#define TLV_BLANK   (0x05)
 
#define TLV_DIERECORD   (0x08)
 
#define TLV_ADC12CAL   (0x11)
 
#define TLV_REFCAL   (0x12)
 
#define TLV_ADC10CAL   (0x13)
 
#define TLV_TAGEXT   (0xFE)
 
#define TAG_DCO_30   (0x01)
 
#define TAG_EMPTY   (0xFE)
 
#define BSP430_TLV_TABLE_DATA_OFFSET   4
 
#define BSP430_TLV_TABLE_PREFIX_LENGTH   8
 
#define TLV_START   (BSP430_TLV_TABLE_PREFIX_LENGTH + *(const unsigned int *)0x0FF4)
 
#define TLV_END   (TLV_START - BSP430_TLV_TABLE_PREFIX_LENGTH + (4 << ((const sBSP430tlvTable *)BSP430_TLV_TABLE_START)->info_len_lg2) - 1)
 
#define BSP430_TLV_TABLE_START   ((const unsigned char *)TLV_START - BSP430_TLV_TABLE_PREFIX_LENGTH)
 
#define BSP430_TLV_TABLE_IS_VALID()
 

Typedefs

typedef struct sBSP430tlvEntry sBSP430tlvEntry
 
typedef struct sBSP430tlvTable2xx sBSP430tlvTable2xx
 
typedef struct sBSP430tlvTable5xx sBSP430tlvTable5xx
 
typedef sBSP430tlvTable5xx sBSP430tlvTable
 
typedef struct sBSP430tlvDIERECORD sBSP430tlvDIERECORD
 
typedef struct sBSP430tlvREFCAL sBSP430tlvREFCAL
 
typedef struct sBPS430tlvADCCAL sBSP430tlvADCCAL
 
typedef struct sBSP430tlvDCO sBSP430tlvDCO
 
typedef struct sBPS430tlvADC sBSP430tlvADC
 

Functions

unsigned int uiBSP430tlvChecksum (const unsigned char *data, size_t len)
 

Detailed Description

Basic support for MSP430 Tag-Length-Value device descriptors.

Two families of MSP430 use TLV descriptors for various purposes:

The layout of the device descriptor table and the algorithm used for checksum on them differ between these two implementations. The C preprocessor symbol BSP430_TLV_IS_5XX may be used to identify the supported implementation in user code.

Homepage
http://github.com/pabigot/bsp430

Macro Definition Documentation

#define BSP430_TLV   (configBSP430_TLV - 0)

Indicate that the TLV interface is available on the platform. The value is true iff configBSP430_TLV is true.

This flag is defined only if configBSP430_TLV is true.

C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Dependency:
configBSP430_TLV
Platform-Based Value:
Undefined here; include <bsp430/platform.h> to obtain the correct value of this macro.
#define BSP430_TLV_ENTRY_IS_ADC (   ep_)    ((TLV_ADC10CAL == (ep_)->tag) || (TLV_ADC12CAL == (ep_)->tag))

Check whether a TLV entry corresponds to an ADC.

On 5xx/6xx MCUs this may be either TLV_ADC10CAL or TLV_ADC12CAL. No MCU has both.

On 2xx MCUs, the tag value is not constant across the family for either peripheral type, so an ADC is detected by a tag that is neither TAG_DCO_30 nor TAG_EMPTY.

#define BSP430_TLV_IS_5XX   defined(__MSP430_HAS_MSP430XV2_CPU__)

Flag used to determine which variant of TLV structure is used.

The functional presence symbol __MSP430_HAS_TLV__ is missing from certain headers that support TLV. For the purposes of this module, the standard BSP430 approach of using the MCU header functional presence symbol __MSP430_HAS_MSP430XV2_CPU__ is used to identify MCUs that follow the 5xx/6xx/FR5xx interface; the 2xx interface is assumed for all other MCUs.

C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
#define BSP430_TLV_NEXT_ENTRY (   ep_)    ((sBSP430tlvEntry *)(sizeof(sBSP430tlvEntry) + (ep_)->len + (unsigned char *)(ep_)))

Return a pointer to the next entry in the table.

Warning
This routine does not account for the possibility of an extended tag. Extended tags are only used on 5xx/6xx device descriptor tables, and are not adequately documented in the user's guide.
#define BSP430_TLV_TABLE_DATA_OFFSET   4

Offset from start of TLV table to skip past the CRC value

#define BSP430_TLV_TABLE_IS_VALID ( )
Value:
(1 + (const unsigned char *)TLV_END) - (BSP430_TLV_TABLE_START + BSP430_TLV_TABLE_DATA_OFFSET)))
#define BSP430_TLV_TABLE_DATA_OFFSET
Definition: tlv.h:317
#define BSP430_TLV_TABLE_START
Definition: tlv.h:352
#define TLV_END
Definition: tlv.h:338
Definition: tlv.h:109
unsigned int uiBSP430tlvChecksum(const unsigned char *data, size_t len)

Check whether the table is valid.

This references BSP430_TLV_TABLE_START and TLV_END and other constants to verify that the stored checksum matches the checksum calculated over the data area of the descriptor table.

#define BSP430_TLV_TABLE_PREFIX_LENGTH   8

Offset from start of TLV table to the first sBSP430tlvEntry entry in the table.

#define BSP430_TLV_TABLE_START   ((const unsigned char *)TLV_START - BSP430_TLV_TABLE_PREFIX_LENGTH)

The offset of the device descriptor table.

This begins with the CRC and any other family-specific prefix information. The value has type const unsigned char *, and may be cast to sBSP430tlvTable to access relevant information.

#define configBSP430_TLV   0

Define to a true value to indicate intent to use the TLV interface.

C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Affects:
BSP430_TLV
Defaulted:
The value here is superseded by previously encountered definitions.
#define TAG_DCO_30   (0x01)

(2xx) Tag for DCO30 Calibration Data

#define TAG_EMPTY   (0xFE)

(2xx) Tag for Empty Data Field in Calibration Data

#define TLV_ADC10CAL   (0x13)

ADC10 calibration

#define TLV_ADC12CAL   (0x11)

ADC12 calibration

#define TLV_BLANK   (0x05)

Blank descriptor

#define TLV_DIERECORD   (0x08)

Die Record

#define TLV_END   (TLV_START - BSP430_TLV_TABLE_PREFIX_LENGTH + (4 << ((const sBSP430tlvTable *)BSP430_TLV_TABLE_START)->info_len_lg2) - 1)

Integer corresponding to the address of the last byte in the TLV table.

It is normally part of the MCU header, but is missing in some cases. It can be reconstructed from the encoded table length.

Platform-Specific Value:
The value here is an example, and may differ from the actual value used depending on platform information.
#define TLV_LDTAG   (0x01)

Legacy descriptor (1xx, 2xx, 4xx families)

#define TLV_PDTAG   (0x02)

Peripheral discovery descriptor

#define TLV_REFCAL   (0x12)

REF calibration

#define TLV_START   (BSP430_TLV_TABLE_PREFIX_LENGTH + *(const unsigned int *)0x0FF4)

Integer corresponding to address of first TLV table entry.

This constant is normally part of the MCU header, but is missing in some cases. It can be reconstructed from the address stored in 0xFF4 on 5xx-family MCUs. It is normally 0x1A08.

Platform-Specific Value:
The value here is an example, and may differ from the actual value used depending on platform information.
#define TLV_TAGEXT   (0xFE)

Tag extender

Typedef Documentation

typedef struct sBPS430tlvADC sBSP430tlvADC

TLV entry for TAG_ADC10_1 and TAG_ADC12_1 on 2xx MCUs

These are ADC gain and offset calibration constants, as well as constants for the internal temperature sensor. The tag values are not defined on all MCUs, and the observed value is 8 on some and 0x10 on others. The address of sBSP430tlvADC::cal_adc_gain_factor is fixed at 0x10DC.

When processing a 2xx descriptor table, it is reasonable to assume that any tag that is not TAG_DCO_30 nor TAG_EMPTY corresponds to an ADC structure.

TLV entry for TLV_ADCCAL, TLV_ADC12CAL, and TLV_ADC10CAL on 5xx MCUs

These are ADC gain and offset calibration constants, as well as constants for the internal temperature sensor. See the family user guide for details.

Warning
: On FR4xx/2xx ADC_10 variants the structure stops after 10 bytes, at the cal_adc_20t30 field, since that variant supports only a 1.5V reference.
typedef struct sBSP430tlvDCO sBSP430tlvDCO

TLV entry for TAG_DCO_30 on 2xx MCUs.

These are BC2 calibration constants for fixed frequencies of MCLK. The TAG_DCO_30 is not defined on all MCUs, but all observed MCUs have used a tag value 1 for this when a tag is present. The address of sBSP430tlvDCO::caldco_16mhz is fixed at 0x10F8.

TLV entry for TLV_DIERECORD on 5xx MCUs.

This structure is not described in the users' guide, but can be found in certain MCU data sheets, including the one for the MSP430F5438a

Fixed header for all TLV entries. This is immediately followed by entry-specific data.

TLV entry for TLV_REFCAL on 5xx MCUs.

These are the constants for ADC adjustment based on the internal reference voltage. See the family user guide for details.

Typedef for the family-specific TLV table structure for this MCU.

Platform-Specific Value:
The value here is an example, and may differ from the actual value used depending on platform information.

The complete device descriptor table including the header, as supported on 2xx devices. The address of the table is 0x10C0.

The complete device descriptor table including the header, as supported on 5xx/6xx/FR5xx devices. The address of sBSP430tlvTable5::entry is available as TLV_START in the MCU header, and can be read from memory at address 0x0FF4.

Function Documentation

unsigned int uiBSP430tlvChecksum ( const unsigned char *  data,
size_t  len 
)

Calculate the TLV-compatible checksum for a region of memory.

The algorithm that is used is family-specific.

  • For 2xx it is the negative of the 16-bit XOR of the data.
  • For 5xx/6xx it is the value computed by the CRC16 peripheral module, which uses the CRC-CCITT polynomial but reverses the bit order. Currently the implementation uses that module on these MCUs.

Other families do not explicitly support the TLV infrastructure, though it may be used for application purposes.

Warning
Reversed CRC support is not present in certain NRND MCUs like the MSP430F5438; all such MCUs have been superseded by newer ones such as the MSP430F5438A. Because the implementation in the 5xx/6xx family depends on the CRC module, this function will not compile on those MCUs.
Note
5xx/6xx MCU headers provide TLV_START and TLV_END, which provide the addresses of the first and last byte of the TLV entry region. The CRC should be calculated starting at data = TLV_START-4, and the length of the region is len = 5+TLV_END-TLV_START.
Parameters
dataThe address of the data over which the checksum is calculated.
lenThe number of octets in the data that contribute to the checksum.
Returns
the 16-bit checksum