1 /******************************************************************************
2 *  Filename:       chipinfo.c
3 *  Revised:        2020-02-17 10:51:36 +0100 (Mon, 17 Feb 2020)
4 *  Revision:       56781
5 *
6 *  Description:    Collection of functions returning chip information.
7 *
8 *  Copyright (c) 2015 - 2017, 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 "chipinfo.h"
40 
41 //*****************************************************************************
42 //
43 // Handle support for DriverLib in ROM:
44 // This section will undo prototype renaming made in the header file
45 //
46 //*****************************************************************************
47 #if !defined(DOXYGEN)
48     #undef  ChipInfo_GetSupportedProtocol_BV
49     #define ChipInfo_GetSupportedProtocol_BV NOROM_ChipInfo_GetSupportedProtocol_BV
50     #undef  ChipInfo_GetPackageType
51     #define ChipInfo_GetPackageType         NOROM_ChipInfo_GetPackageType
52     #undef  ChipInfo_GetChipType
53     #define ChipInfo_GetChipType            NOROM_ChipInfo_GetChipType
54     #undef  ChipInfo_GetChipFamily
55     #define ChipInfo_GetChipFamily          NOROM_ChipInfo_GetChipFamily
56     #undef  ChipInfo_GetHwRevision
57     #define ChipInfo_GetHwRevision          NOROM_ChipInfo_GetHwRevision
58     #undef  ThisLibraryIsFor_CC13x2_CC26x2_HwRev20AndLater_HaltIfViolated
59     #define ThisLibraryIsFor_CC13x2_CC26x2_HwRev20AndLater_HaltIfViolated NOROM_ThisLibraryIsFor_CC13x2_CC26x2_HwRev20AndLater_HaltIfViolated
60 #endif
61 
62 //*****************************************************************************
63 //
64 // ChipInfo_GetSupportedProtocol_BV()
65 //
66 //*****************************************************************************
67 ProtocolBitVector_t
ChipInfo_GetSupportedProtocol_BV(void)68 ChipInfo_GetSupportedProtocol_BV( void )
69 {
70    return ((ProtocolBitVector_t)( HWREG( PRCM_BASE + 0x1D4 ) & 0x0E ));
71 }
72 
73 //*****************************************************************************
74 //
75 // ChipInfo_GetPackageType()
76 //
77 //*****************************************************************************
78 PackageType_t
ChipInfo_GetPackageType(void)79 ChipInfo_GetPackageType( void )
80 {
81    PackageType_t packType = (PackageType_t)((
82       HWREG( FCFG1_BASE + FCFG1_O_USER_ID     ) &
83                           FCFG1_USER_ID_PKG_M ) >>
84                           FCFG1_USER_ID_PKG_S ) ;
85 
86    if (( packType < PACKAGE_4x4    ) ||
87        ( packType > PACKAGE_7x7_Q1 )    )
88    {
89       packType = PACKAGE_Unknown;
90    }
91 
92    return ( packType );
93 }
94 
95 //*****************************************************************************
96 //
97 // ChipInfo_GetChipFamily()
98 //
99 //*****************************************************************************
100 ChipFamily_t
ChipInfo_GetChipFamily(void)101 ChipInfo_GetChipFamily( void )
102 {
103    uint32_t       waferId                    ;
104    ChipFamily_t   chipFam = FAMILY_Unknown   ;
105 
106    waferId = (( HWREG( FCFG1_BASE + FCFG1_O_ICEPICK_DEVICE_ID ) &
107                                       FCFG1_ICEPICK_DEVICE_ID_WAFER_ID_M ) >>
108                                       FCFG1_ICEPICK_DEVICE_ID_WAFER_ID_S ) ;
109 
110    if ( waferId == 0xBB41 ) {
111       chipFam = FAMILY_CC13x2_CC26x2 ;
112    }
113 
114    return ( chipFam );
115 }
116 
117 //*****************************************************************************
118 //
119 // ChipInfo_GetChipType()
120 //
121 //*****************************************************************************
122 ChipType_t
ChipInfo_GetChipType(void)123 ChipInfo_GetChipType( void )
124 {
125    ChipType_t     chipType       = CHIP_TYPE_Unknown        ;
126    ChipFamily_t   chipFam        = ChipInfo_GetChipFamily() ;
127    uint32_t       fcfg1UserId    = ChipInfo_GetUserId()     ;
128    uint32_t       fcfg1Protocol  = (( fcfg1UserId & FCFG1_USER_ID_PROTOCOL_M ) >>
129                                                     FCFG1_USER_ID_PROTOCOL_S ) ;
130    uint32_t       fcfg1Cc13      = (( fcfg1UserId & FCFG1_USER_ID_CC13_M ) >>
131                                                     FCFG1_USER_ID_CC13_S ) ;
132    uint32_t       fcfg1Pa        = (( fcfg1UserId & FCFG1_USER_ID_PA_M ) >>
133                                                     FCFG1_USER_ID_PA_S ) ;
134 
135    if ( chipFam == FAMILY_CC13x2_CC26x2 ) {
136       switch ( fcfg1Protocol ) {
137       case 0xF :
138          if( fcfg1Cc13 ) {
139             if ( fcfg1Pa ) {
140                chipType = CHIP_TYPE_CC1352P  ;
141             } else {
142                chipType = CHIP_TYPE_CC1352   ;
143             }
144          } else {
145             if ( fcfg1Pa ) {
146                chipType = CHIP_TYPE_CC2652P  ;
147             } else {
148                chipType = CHIP_TYPE_CC2652   ;
149             }
150          }
151          break;
152       case 0x9 :
153          if( fcfg1Pa ) {
154             chipType = CHIP_TYPE_unused      ;
155          } else {
156             chipType = CHIP_TYPE_CC2642      ;
157          }
158          break;
159       case 0x8 :
160          chipType = CHIP_TYPE_CC1312         ;
161          break;
162       }
163    }
164 
165    return ( chipType );
166 }
167 
168 //*****************************************************************************
169 //
170 // ChipInfo_GetHwRevision()
171 //
172 //*****************************************************************************
173 HwRevision_t
ChipInfo_GetHwRevision(void)174 ChipInfo_GetHwRevision( void )
175 {
176    HwRevision_t   hwRev       = HWREV_Unknown                     ;
177    uint32_t       fcfg1Rev    = ChipInfo_GetDeviceIdHwRevCode()   ;
178    uint32_t       minorHwRev  = ChipInfo_GetMinorHwRev()          ;
179    ChipFamily_t   chipFam     = ChipInfo_GetChipFamily()          ;
180 
181    if ( chipFam == FAMILY_CC13x2_CC26x2 ) {
182       switch ( fcfg1Rev ) {
183       case 0 : // CC13x2, CC26x2 - PG1.0
184       case 1 : // CC13x2, CC26x2 - PG1.01 (will also show up as PG1.0)
185          hwRev = (HwRevision_t)((uint32_t)HWREV_1_0 );
186          break;
187       case 2 : // CC13x2, CC26x2 - PG1.1 (or later)
188          hwRev = (HwRevision_t)(((uint32_t)HWREV_1_1 ) + minorHwRev );
189          break;
190       case 3 : // CC13x2, CC26x2 - PG2.1 (or later)
191          hwRev = (HwRevision_t)(((uint32_t)HWREV_2_1 ) + minorHwRev );
192          break;
193       }
194    }
195 
196    return ( hwRev );
197 }
198 
199 //*****************************************************************************
200 // ThisLibraryIsFor_CC13x2_CC26x2_HwRev20AndLater_HaltIfViolated()
201 //*****************************************************************************
202 void
ThisLibraryIsFor_CC13x2_CC26x2_HwRev20AndLater_HaltIfViolated(void)203 ThisLibraryIsFor_CC13x2_CC26x2_HwRev20AndLater_HaltIfViolated( void )
204 {
205    if (( ! ChipInfo_ChipFamilyIs_CC13x2_CC26x2() ) ||
206        ( ! ChipInfo_HwRevisionIs_GTEQ_2_0()      )    )
207    {
208       while(1)
209       {
210          // This driverlib version is for the CC13x2/CC26x2 PG2.0 and later chips.
211          // Do nothing - stay here forever
212       }
213    }
214 }
215