]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - msp430-bsl/msp430-bsl.git/blob - F5xx_F6xx_Core_Lib/HAL_TLV.c
Adding IAR Embedded Workbench files for IAR EW 5.56.5.
[msp430-bsl/msp430-bsl.git] / F5xx_F6xx_Core_Lib / HAL_TLV.c
1 /*******************************************************************************
2  *
3  * HAL_TLV.c
4  * Provides Functions to Read the TLV Data Section of the MSP430 Devices
5  * 
6  *
7  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ 
8  * 
9  * 
10  *  Redistribution and use in source and binary forms, with or without 
11  *  modification, are permitted provided that the following conditions 
12  *  are met:
13  *
14  *    Redistributions of source code must retain the above copyright 
15  *    notice, this list of conditions and the following disclaimer.
16  *
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   
20  *    distribution.
21  *
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.
25  *
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.
37  * 
38  * Updated: Version 2.0 01/17/2011
39  *  
40  ******************************************************************************/
42 #include "msp430.h"
43 #include "HAL_TLV.h" 
45 void Get_TLV_Info(uint8_t tag, uint8_t instance, uint8_t *length, uint16_t **data_address)
46 {
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
52   {
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
55   }
56   
57   if (*TLV_address == tag)                       // Check if Tag match happened..
58   {
59     *length = *(TLV_address + 1);                  // Return length = Address + 1
60     *data_address = (uint16_t *)(TLV_address + 2); // Return address of first data/value info = Address + 2
61   }
62   else                                           // If there was no tag match and the end of TLV structure was reached..
63   {
64     *length = 0;                                 // Return 0 for TAG not found
65     *data_address = 0;                           // Return 0 for TAG not found
66   }
67 }
69 uint16_t Get_Device_Type(void)
70 {
71   uint16_t *pDeviceType = (uint16_t *)DEVICE_ID_0;
72   return pDeviceType[0];                         // Return Value from TLV Table
73 }
75 uint16_t Get_TLV_Memory(uint8_t instance)
76 {
77     uint8_t *pPDTAG;
78     uint8_t bPDTAG_bytes;
79     uint16_t count;
81     instance *= 2;                               // set tag for word access comparison
82     
83     // TLV access Function Call
84     Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (uint16_t **)&pPDTAG); // Get Peripheral data pointer
85     
86     for (count = 0;count <= instance; count += 2)
87     {
88       if (pPDTAG[count] == 0) return 0;          // Return 0 if end reached
89       if (count == instance) return (pPDTAG[count] | pPDTAG[count+1]<<8);
90     }
91     
92     return 0;                                    // Return 0: not found
93 }
95 uint16_t Get_TLV_Peripheral(uint8_t tag, uint8_t instance)
96 {
97     uint8_t *pPDTAG;
98     uint8_t bPDTAG_bytes;
99     uint16_t count = 0;
100     uint16_t pcount = 0;
102     Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (uint16_t **)&pPDTAG); // Get Peripheral data pointer
104     // read memory configuration from TLV to get offset for Peripherals
105     while (Get_TLV_Memory(count)) {
106       count++;
107     }
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
119           instance--;
120         }
121         else {
122           return (pPDTAG[count] | pPDTAG[count + 1] << 8); // Return found data
123         }
124       }
125     }
126     
127     return 0;                                    // Return 0: not found
130 uint8_t Get_TLV_Interrupt(uint8_t tag)
132     uint8_t *pPDTAG;
133     uint8_t bPDTAG_bytes;
134     uint16_t count = 0;
135     uint16_t pcount = 0;
137     Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (uint16_t **)&pPDTAG); // Get Peripheral data pointer
138     
139     // read memory configuration from TLV to get offset for Peripherals
140     while (Get_TLV_Memory(count))
141     {
142       count++;
143     }
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)
152     {
153       if (pPDTAG[count] == 0) return 0;          // Return 0: not found/end of table
154       if (count == tag) return (pPDTAG[count]);  // Return found data
155     }
156     
157     return 0;                                    // Return 0: not found