1 /*******************************************************************************
4 * Provides Functions to Read the TLV Data Section of the MSP430 Devices
7 * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the
22 * Neither the name of Texas Instruments Incorporated nor the names of
23 * its contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Updated: Version 2.0 01/17/2011
40 ******************************************************************************/
45 void Get_TLV_Info(unsigned char tag, unsigned char instance, unsigned char *length, unsigned int **data_address)
47 char *TLV_address = (char *)TLV_START; // TLV Structure Start Address
49 while((TLV_address < (char *)TLV_END)
50 && ((*TLV_address != tag) || instance) // check for tag and instance
51 && (*TLV_address != TLV_TAGEND)) // do range check first
53 if (*TLV_address == tag) instance--; // repeat till requested instance is reached
54 TLV_address += *(TLV_address + 1) + 2; // add (Current TAG address + LENGTH) + 2
57 if (*TLV_address == tag) // Check if Tag match happened..
59 *length = *(TLV_address + 1); // Return length = Address + 1
60 *data_address = (unsigned int *)(TLV_address + 2); // Return address of first data/value info = Address + 2
62 else // If there was no tag match and the end of TLV structure was reached..
64 *length = 0; // Return 0 for TAG not found
65 *data_address = 0; // Return 0 for TAG not found
69 unsigned int Get_Device_Type(void)
71 unsigned int *pDeviceType = (unsigned int *)DEVICE_ID_0;
72 return pDeviceType[0]; // Return Value from TLV Table
75 unsigned int Get_TLV_Memory(unsigned char instance)
77 unsigned char *pPDTAG;
78 unsigned char bPDTAG_bytes;
81 instance *= 2; // set tag for word access comparison
83 // TLV access Function Call
84 Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (unsigned int **)&pPDTAG); // Get Peripheral data pointer
86 for (count = 0;count <= instance; count += 2)
88 if (pPDTAG[count] == 0) return 0; // Return 0 if end reached
89 if (count == instance) return (pPDTAG[count] | pPDTAG[count+1]<<8);
92 return 0; // Return 0: not found
95 unsigned int Get_TLV_Peripheral(unsigned char tag, unsigned char instance)
97 unsigned char *pPDTAG;
98 unsigned char bPDTAG_bytes;
99 unsigned int count = 0;
100 unsigned int pcount = 0;
102 Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (unsigned int **)&pPDTAG); // Get Peripheral data pointer
104 // read memory configuration from TLV to get offset for Peripherals
105 while (Get_TLV_Memory(count)) {
109 pcount = pPDTAG[count * 2 + 1]; // get number of Peripheral entries
110 count++; // inc count to first Periperal
111 pPDTAG += count*2; // adjust point to first address of Peripheral
112 count = 0; // set counter back to 0
113 pcount *= 2; // align pcount for work comparision
115 // TLV access Function Call
116 for (count = 0; count <= pcount; count += 2) {
117 if (pPDTAG[count+1] == tag) { // test if required Peripheral is found
118 if (instance > 0) { // test if required instance is found
122 return (pPDTAG[count] | pPDTAG[count + 1] << 8); // Return found data
127 return 0; // Return 0: not found
130 unsigned char Get_TLV_Interrupt(unsigned char tag)
132 unsigned char *pPDTAG;
133 unsigned char bPDTAG_bytes;
134 unsigned int count = 0;
135 unsigned int pcount = 0;
137 Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (unsigned int **)&pPDTAG); // Get Peripheral data pointer
139 // read memory configuration from TLV to get offset for Peripherals
140 while (Get_TLV_Memory(count))
145 pcount = pPDTAG[count * 2 + 1];
146 count++; // inc count to first Periperal
147 pPDTAG += (pcount + count) * 2; // adjust point to first address of Peripheral
148 count = 0; // set counter back to 0
150 // TLV access Function Call
151 for (count = 0; count <= tag; count += 2)
153 if (pPDTAG[count] == 0) return 0; // Return 0: not found/end of table
154 if (count == tag) return (pPDTAG[count]); // Return found data
157 return 0; // Return 0: not found