]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - sub1ghz-sensor-to-cloud/tida01476.git/blob - sensor_cc1310lp/Application/MAC/StartUp/icall_startup.c
Initial Commit
[sub1ghz-sensor-to-cloud/tida01476.git] / sensor_cc1310lp / Application / MAC / StartUp / icall_startup.c
1 /******************************************************************************
3  @file  icall_startup.c
5  @brief Startup code for CC13xx/CC26xx devices
7  Group: WCS LPC
8  Target Device: CC13xx
10  ******************************************************************************
11  
12  Copyright (c) 2014-2017, Texas Instruments Incorporated
13  All rights reserved.
15  Redistribution and use in source and binary forms, with or without
16  modification, are permitted provided that the following conditions
17  are met:
19  *  Redistributions of source code must retain the above copyright
20     notice, this list of conditions and the following disclaimer.
22  *  Redistributions in binary form must reproduce the above copyright
23     notice, this list of conditions and the following disclaimer in the
24     documentation and/or other materials provided with the distribution.
26  *  Neither the name of Texas Instruments Incorporated nor the names of
27     its contributors may be used to endorse or promote products derived
28     from this software without specific prior written permission.
30  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
32  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
37  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
38  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
39  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
40  EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  ******************************************************************************
43  Release Name: simplelink_cc13x0_sdk_1_30_00_06"
44  Release Date: 2017-03-08 14:43:30
45  *****************************************************************************/
47 /* Check for IAR or TI compiler */
48 #if !(defined(__IAR_SYSTEMS_ICC__) || \
49       defined(__TI_COMPILER_VERSION) || \
50       defined(__TI_COMPILER_VERSION__))
51 #error "startup.c: Unsupported compiler!"
52 #endif
54 /*******************************************************************************
55  * INCLUDES
56  */
58 #include "hal_types.h"
59 #include <icall.h>
61 #if defined(FLASH_ROM_BUILD)
62 #include "ROM_Init.h"
63 #include "CommonROM_Init.h"
64 #endif /* FLASH_ROM_BUILD */
66 /*******************************************************************************
67  * EXTERNS
68  */
70 /*******************************************************************************
71  * PROTOTYPES
72  */
74 /*******************************************************************************
75  * MACROS
76  */
78 /*******************************************************************************
79  * CONSTANTS
80  */
82 #define CRC16_POLYNOMIAL  0x1021
84 /*******************************************************************************
85  * TYPEDEFS
86  */
88 /*******************************************************************************
89  * LOCAL VARIABLES
90  */
92 /*******************************************************************************
93  * GLOBAL VARIABLES
94  */
95 #if !defined(STACK_LIBRARY)
96 ICall_Dispatcher ICall_dispatcher;
97 ICall_EnterCS    ICall_enterCriticalSection;
98 ICall_LeaveCS    ICall_leaveCriticalSection;
99 #endif /* STACK_LIBRARY */
101 /*******************************************************************************
102  * @fn          checkCRC16
103  *
104  * @brief       A simple implementation of the crc-16 checksum algorithm,
105  *              courtesy of IAR (circa 2007).
106  *
107  *              Note:  If you use this function, you need to call it with an
108  *                     extra number of zero bytes equal to the size of the
109  *                     checksum (in this case 2), to "rotate out the answer".
110  *
111  * input parameters
112  *
113  * @param       crc   - The CRC value to start with.
114  * @param       pAddr - Pointer to an array of bytes to run the CRC over.
115  * @param       len   - The number of bytes to process.
116  *
117  * output parameters
118  *
119  * @param       None.
120  *
121  * @return      CRC-16 result.
122  */
123 uint16 slow_crc16(uint16 crc, uint8 *pAddr, uint32 len)
125   while(len--)
126   {
127     uint8 i;
128     uint8 byte = *(pAddr++);
130     for(i=0; i<8; ++i)
131     {
132       uint32 temp = crc;
134       crc <<= 1;
136       if(byte & 0x80)
137       {
138         crc |= 1;
139       }
141       if(temp & 0x8000)
142       {
143         crc ^= CRC16_POLYNOMIAL;
144       }
146       byte <<= 1;
147     }
148   }
150   return(crc);
153 /*******************************************************************************
154  * @fn          validChecksum
155  *
156  * @brief       Check if the ROM checksum is valid.
157  *
158  *              Note: This routine assumes the CRC directly follows the end
159  *                    address!
160  *
161  * input parameters
162  *
163  * @param       None.
164  *
165  * output parameters
166  *
167  * @param       None.
168  *
169  * @return      TRUE=Valid Checksum; FALSE=Invalid Checksum.
170  */
171 uint8 validChecksum(const uint32 *beginAddr, const uint32 *endAddr)
173   uint16 crc      = 0;
174   uint16 romCRC   = *((uint16 *)(((uint8 *)endAddr)+1));
175   uint8  zeros[2] = {0, 0};
177   // calculate the ROM checksum
178   crc = slow_crc16(crc, (uint8 *)beginAddr,
179                    ((uint32)endAddr - (uint32)beginAddr + 1));
181   // needed to rotate out the answer
182   crc = slow_crc16(crc, zeros, 2);
184   // Compare the calculated checksum with the stored
185   return((crc==romCRC)? TRUE : FALSE);
188 /*******************************************************************************
189  * @fn          startup_entry
190  *
191  * @brief       This is the TI-15.4 stack entry point.
192  *
193  * input parameters
194  *
195  * @param       arg0   argument containing remote dispatch function pointers
196  * @param       arg1   custom initialization parameter
197  *
198  * output parameters
199  *
200  * @param       None.
201  *
202  * @return      None.
203  */
204 #if !defined(STACK_LIBRARY)
205 #if defined __TI_COMPILER_VERSION || defined __TI_COMPILER_VERSION__
206 #pragma CODE_SECTION(startup_entry,"EntrySection")
207 #elif defined(__IAR_SYSTEMS_ICC__)
208 #pragma location="EntrySection"
209 #endif
210 #endif /* STACK_LIBRARY */
212 void startup_entry(const ICall_RemoteTaskArg *arg0, void *arg1)
214   extern int stack_main( void *arg );
215 #if !defined(STACK_LIBRARY)
216 #if defined(__IAR_SYSTEMS_ICC__)
217   extern void __iar_data_init3(void);
218   __iar_data_init3();
219 #elif defined __TI_COMPILER_VERSION || defined __TI_COMPILER_VERSION__
220   extern void __TI_auto_init(void);
221   __TI_auto_init();
222 #else
223 #error "Error: Must specify a compiler!"
224 #endif
225 #endif /* STACK_LIBRARY */
227   ICall_dispatcher = arg0->dispatch;
228   ICall_enterCriticalSection = arg0->entercs;
229   ICall_leaveCriticalSection = arg0->leavecs;
231 #if defined(FLASH_ROM_BUILD)
232   // initialize the Common ROM
233   CommonROM_Init();
235   // initialize the TIMAC ROM
236   ROM_Init();
237 #endif /* FLASH_ROM_BUILD */
239   stack_main(arg1);