1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,158 @@ |
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 |
+ ******************************************************************************/ |
|
41 |
+ |
|
42 |
+#include "msp430.h" |
|
43 |
+#include "HAL_TLV.h" |
|
44 |
+ |
|
45 |
+void Get_TLV_Info(unsigned char tag, unsigned char instance, unsigned char *length, unsigned int **data_address) |
|
46 |
+{ |
|
47 |
+ char *TLV_address = (char *)TLV_START; // TLV Structure Start Address |
|
48 |
+ |
|
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 = (unsigned int *)(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 |
+} |
|
68 |
+ |
|
69 |
+unsigned int Get_Device_Type(void) |
|
70 |
+{ |
|
71 |
+ unsigned int *pDeviceType = (unsigned int *)DEVICE_ID_0; |
|
72 |
+ return pDeviceType[0]; // Return Value from TLV Table |
|
73 |
+} |
|
74 |
+ |
|
75 |
+unsigned int Get_TLV_Memory(unsigned char instance) |
|
76 |
+{ |
|
77 |
+ unsigned char *pPDTAG; |
|
78 |
+ unsigned char bPDTAG_bytes; |
|
79 |
+ unsigned int count; |
|
80 |
+ |
|
81 |
+ instance *= 2; // set tag for word access comparison |
|
82 |
+ |
|
83 |
+ // TLV access Function Call |
|
84 |
+ Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (unsigned int **)&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 |
+} |
|
94 |
+ |
|
95 |
+unsigned int Get_TLV_Peripheral(unsigned char tag, unsigned char instance) |
|
96 |
+{ |
|
97 |
+ unsigned char *pPDTAG; |
|
98 |
+ unsigned char bPDTAG_bytes; |
|
99 |
+ unsigned int count = 0; |
|
100 |
+ unsigned int pcount = 0; |
|
101 |
+ |
|
102 |
+ Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (unsigned int **)&pPDTAG); // Get Peripheral data pointer |
|
103 |
+ |
|
104 |
+ // read memory configuration from TLV to get offset for Peripherals |
|
105 |
+ while (Get_TLV_Memory(count)) { |
|
106 |
+ count++; |
|
107 |
+ } |
|
108 |
+ |
|
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 |
|
114 |
+ |
|
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 |
|
128 |
+} |
|
129 |
+ |
|
130 |
+unsigned char Get_TLV_Interrupt(unsigned char tag) |
|
131 |
+{ |
|
132 |
+ unsigned char *pPDTAG; |
|
133 |
+ unsigned char bPDTAG_bytes; |
|
134 |
+ unsigned int count = 0; |
|
135 |
+ unsigned int pcount = 0; |
|
136 |
+ |
|
137 |
+ Get_TLV_Info(TLV_PDTAG, 0, &bPDTAG_bytes, (unsigned int **)&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 |
+ } |
|
144 |
+ |
|
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 |
|
149 |
+ |
|
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 |
|
158 |
+} |