1 /******************************************************************************
2 *  Filename:       chipinfo.c
3 *  Revised:        2015-10-28 11:48:13 +0100 (Wed, 28 Oct 2015)
4 *  Revision:       44860
5 *
6 *  Description:    Collection of functions returning chip information.
7 *
8 *  Copyright (c) 2015, Texas Instruments Incorporated
9 *  All rights reserved.
10 *
11 *  Redistribution and use in source and binary forms, with or without
12 *  modification, are permitted provided that the following conditions are met:
13 *
14 *  1) Redistributions of source code must retain the above copyright notice,
15 *     this list of conditions and the following disclaimer.
16 *
17 *  2) Redistributions in binary form must reproduce the above copyright notice,
18 *     this list of conditions and the following disclaimer in the documentation
19 *     and/or other materials provided with the distribution.
20 *
21 *  3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 *     be used to endorse or promote products derived from this software without
23 *     specific prior written permission.
24 *
25 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 *  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 *  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 *  POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 #include <driverlib/chipinfo.h>
40 
41 //*****************************************************************************
42 //
43 // Internal macros
44 //
45 //*****************************************************************************
46 
47 #define BV( x )   ( 1 << ( x ))
48 
49 
50 //*****************************************************************************
51 //
52 // ChipInfo_GetSupportedProtocol_BV()
53 //
54 //*****************************************************************************
55 ProtocolBitVector_t
ChipInfo_GetSupportedProtocol_BV(void)56 ChipInfo_GetSupportedProtocol_BV( void )
57 {
58    return ((ProtocolBitVector_t)( HWREG( PRCM_BASE + 0x1D4 ) & 0x0E ));
59 }
60 
61 
62 //*****************************************************************************
63 //
64 // ChipInfo_GetPackageType()
65 //
66 //*****************************************************************************
67 PackageType_t
ChipInfo_GetPackageType(void)68 ChipInfo_GetPackageType( void )
69 {
70    PackageType_t packType = (PackageType_t)((
71       HWREG( FCFG1_BASE + FCFG1_O_USER_ID     ) &
72                           FCFG1_USER_ID_PKG_M ) >>
73                           FCFG1_USER_ID_PKG_S ) ;
74 
75    if (( packType < PACKAGE_4x4 ) ||
76        ( packType > PACKAGE_7x7 )    )
77    {
78       packType = PACKAGE_Unknown;
79    }
80 
81    return ( packType );
82 }
83 
84 
85 //*****************************************************************************
86 //
87 // ChipInfo_GetChipFamily()
88 //
89 //*****************************************************************************
90 ChipFamily_t
ChipInfo_GetChipFamily(void)91 ChipInfo_GetChipFamily( void )
92 {
93    ChipFamily_t   chipFam  = FAMILY_Unknown  ;
94    uint32_t       waferId                    ;
95 
96    waferId = (( HWREG( FCFG1_BASE + FCFG1_O_ICEPICK_DEVICE_ID ) &
97                            FCFG1_ICEPICK_DEVICE_ID_WAFER_ID_M ) >>
98                            FCFG1_ICEPICK_DEVICE_ID_WAFER_ID_S ) ;
99 
100    if (      waferId == 0xB99A )  chipFam = FAMILY_CC26xx       ;
101    else if ( waferId == 0xB9BE )  chipFam = FAMILY_CC13xx       ;
102    else if ( waferId == 0xBB20 )  chipFam = FAMILY_CC26xxLizard ;
103    else if ( waferId == 0xBB41 )  chipFam = FAMILY_CC26xxAgama  ;
104 
105    return ( chipFam );
106 }
107 
108 
109 //*****************************************************************************
110 //
111 // ChipInfo_GetHwRevision()
112 //
113 //*****************************************************************************
114 HwRevision_t
ChipInfo_GetHwRevision(void)115 ChipInfo_GetHwRevision( void )
116 {
117    HwRevision_t   hwRev       = HWREV_Unknown                     ;
118    uint32_t       fcfg1Rev    = ChipInfo_GetDeviceIdHwRevCode()   ;
119    uint32_t       minorHwRev  = ChipInfo_GetMinorHwRev()          ;
120 
121    switch( ChipInfo_GetChipFamily() ) {
122    case FAMILY_CC26xx :
123       switch ( fcfg1Rev ) {
124       case 1 : // CC26xx PG1.0
125          hwRev = HWREV_1_0;
126          break;
127       case 3 : // CC26xx PG2.0
128          hwRev = HWREV_2_0;
129          break;
130       case 7 : // CC26xx PG2.1
131          hwRev = HWREV_2_1;
132          break;
133       case 8 : // CC26xx PG2.2 (or later)
134          hwRev = (HwRevision_t)(((uint32_t)HWREV_2_2 ) + minorHwRev );
135          break;
136       }
137       break;
138    case FAMILY_CC13xx :
139       switch ( fcfg1Rev ) {
140       case 0 : // CC13xx PG1.0
141          hwRev = HWREV_1_0;
142          break;
143       case 2 : // CC13xx PG2.0 (or later)
144          hwRev = (HwRevision_t)(((uint32_t)HWREV_2_0 ) + minorHwRev );
145          break;
146       }
147       break;
148    case FAMILY_CC26xxLizard :
149    case FAMILY_CC26xxAgama  :
150       switch ( fcfg1Rev ) {
151       case 0 : // CC26xxLizard or CC26xxAgama PG1.0 (or later)
152          hwRev = (HwRevision_t)(((uint32_t)HWREV_1_0 ) + minorHwRev );
153          break;
154       }
155       break;
156    default :
157       // GCC gives warning if not handling all options explicitly in a "switch" on a variable of type "enum"
158       break;
159    }
160 
161    return ( hwRev );
162 }
163 
164 
165 
166 //*****************************************************************************
167 // ThisCodeIsBuiltForCC13xxHwRev20AndLater_HaltIfViolated()
168 //*****************************************************************************
169 void
ThisCodeIsBuiltForCC13xxHwRev20AndLater_HaltIfViolated(void)170 ThisCodeIsBuiltForCC13xxHwRev20AndLater_HaltIfViolated( void )
171 {
172    if (( ! ChipInfo_ChipFamilyIsCC13xx()     ) ||
173        ( ! ChipInfo_HwRevisionIs_GTEQ_2_0()  )    )
174    {
175       while(1)
176       {
177          //
178          // This driverlib version is for CC13xx PG2.0 and later.
179          // Do nothing - stay here forever
180          //
181       }
182    }
183 }
184