1 /******************************************************************************
2 *  Filename:       chipinfo.c
3 *  Revised:        2020-10-08 13:53:12 +0200 (Thu, 08 Oct 2020)
4 *  Revision:       58979
5 *
6 *  Description:    Collection of functions returning chip information.
7 *
8 *  Copyright (c) 2015 - 2020, 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_SIP )    )
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    uint32_t       fcfg1Hposc     = (( fcfg1UserId & 0x01000000 ) >> 24 ) ;
135 
136    if ( chipFam == FAMILY_CC13x2_CC26x2 ) {
137       switch ( fcfg1Protocol ) {
138       case 0xF :
139          if ( fcfg1Cc13 ) {
140             if ( fcfg1Pa ) {
141                chipType = CHIP_TYPE_CC1352P  ;
142             } else {
143                chipType = CHIP_TYPE_CC1352   ;
144             }
145          } else {
146             // ! fcfg1Cc13
147             if ( fcfg1Pa && fcfg1Hposc ) {
148                chipType = CHIP_TYPE_CC2652PB ;
149             }
150             // ! fcfg1Hposc
151             else if ( fcfg1Pa ) {
152                chipType = CHIP_TYPE_CC2652P  ;
153             }
154             // ! fcfg1Pa
155             else if ( fcfg1Hposc ) {
156                chipType = CHIP_TYPE_CC2652RB;
157             }
158             else {
159                chipType = CHIP_TYPE_CC2652   ;
160             }
161          }
162          break;
163       case 0x9 :
164          if ( fcfg1Pa ) {
165             chipType = CHIP_TYPE_unused      ;
166          } else {
167             chipType = CHIP_TYPE_CC2642      ;
168          }
169          break;
170       case 0x8 :
171          chipType = CHIP_TYPE_CC1312         ;
172          break;
173       }
174    }
175 
176    return ( chipType );
177 }
178 
179 //*****************************************************************************
180 //
181 // ChipInfo_GetHwRevision()
182 //
183 //*****************************************************************************
184 HwRevision_t
ChipInfo_GetHwRevision(void)185 ChipInfo_GetHwRevision( void )
186 {
187    HwRevision_t   hwRev       = HWREV_Unknown                     ;
188    uint32_t       fcfg1Rev    = ChipInfo_GetDeviceIdHwRevCode()   ;
189    uint32_t       minorHwRev  = ChipInfo_GetMinorHwRev()          ;
190    ChipFamily_t   chipFam     = ChipInfo_GetChipFamily()          ;
191 
192    if ( chipFam == FAMILY_CC13x2_CC26x2 ) {
193       switch ( fcfg1Rev ) {
194       case 0 : // CC13x2, CC26x2 - PG1.0
195       case 1 : // CC13x2, CC26x2 - PG1.01 (will also show up as PG1.0)
196          hwRev = (HwRevision_t)((uint32_t)HWREV_1_0 );
197          break;
198       case 2 : // CC13x2, CC26x2 - PG1.1 (or later)
199          hwRev = (HwRevision_t)(((uint32_t)HWREV_1_1 ) + minorHwRev );
200          break;
201       case 3 : // CC13x2, CC26x2 - PG2.1 (or later)
202          hwRev = (HwRevision_t)(((uint32_t)HWREV_2_1 ) + minorHwRev );
203          break;
204       }
205    }
206 
207    return ( hwRev );
208 }
209 
210 //*****************************************************************************
211 // ThisLibraryIsFor_CC13x2_CC26x2_HwRev20AndLater_HaltIfViolated()
212 //*****************************************************************************
213 void
ThisLibraryIsFor_CC13x2_CC26x2_HwRev20AndLater_HaltIfViolated(void)214 ThisLibraryIsFor_CC13x2_CC26x2_HwRev20AndLater_HaltIfViolated( void )
215 {
216    if (( ! ChipInfo_ChipFamilyIs_CC13x2_CC26x2() ) ||
217        ( ! ChipInfo_HwRevisionIs_GTEQ_2_0()      )    )
218    {
219       while(1)
220       {
221          // This driverlib version is for the CC13x2/CC26x2 PG2.0 and later chips.
222          // Do nothing - stay here forever
223       }
224    }
225 }
226