mbed

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Tue Nov 08 17:45:16 2016 +0000
Revision:
150:02e0a0aed4ec
Parent:
149:156823d33999
Child:
151:5eaa88a5bcc7
This updates the lib to the mbed lib v129

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 149:156823d33999 1 /**
<> 149:156823d33999 2 ***************************************************************************
<> 149:156823d33999 3 * @file ncs36510_init.c
<> 149:156823d33999 4 * @brief Initialization of Orion SoC
<> 149:156823d33999 5 * @internal
<> 149:156823d33999 6 * @author ON Semiconductor
<> 149:156823d33999 7 * $Rev:
<> 149:156823d33999 8 * $Date: $
<> 149:156823d33999 9 ******************************************************************************
<> 149:156823d33999 10 * Copyright 2016 Semiconductor Components Industries LLC (d/b/a “ON Semiconductor”).
<> 149:156823d33999 11 * All rights reserved. This software and/or documentation is licensed by ON Semiconductor
<> 149:156823d33999 12 * under limited terms and conditions. The terms and conditions pertaining to the software
<> 149:156823d33999 13 * and/or documentation are available at http://www.onsemi.com/site/pdf/ONSEMI_T&C.pdf
<> 149:156823d33999 14 * (“ON Semiconductor Standard Terms and Conditions of Sale, Section 8 Software”) and
<> 149:156823d33999 15 * if applicable the software license agreement. Do not use this software and/or
<> 149:156823d33999 16 * documentation unless you have carefully read and you agree to the limited terms and
<> 149:156823d33999 17 * conditions. By using this software and/or documentation, you agree to the limited
<> 149:156823d33999 18 * terms and conditions.
<> 149:156823d33999 19 *
<> 149:156823d33999 20 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
<> 149:156823d33999 21 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
<> 149:156823d33999 22 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
<> 149:156823d33999 23 * ON SEMICONDUCTOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
<> 149:156823d33999 24 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
<> 149:156823d33999 25 * @endinternal
<> 149:156823d33999 26 *
<> 149:156823d33999 27 * @ingroup main
<> 149:156823d33999 28 *
<> 149:156823d33999 29 * @details
<> 149:156823d33999 30 */
<> 149:156823d33999 31
<> 149:156823d33999 32 /*************************************************************************************************
<> 149:156823d33999 33 * *
<> 149:156823d33999 34 * Header files *
<> 149:156823d33999 35 * *
<> 149:156823d33999 36 *************************************************************************************************/
<> 149:156823d33999 37 #include "ncs36510Init.h"
<> 149:156823d33999 38
<> 149:156823d33999 39 void fPmuInit(void);
<> 149:156823d33999 40 /**
<> 149:156823d33999 41 * @brief
<> 149:156823d33999 42 * Hardware trimming function
<> 149:156823d33999 43 * This function copies trim codes from specific flash location
<> 149:156823d33999 44 * where they are stored to proper hw registers.
<> 149:156823d33999 45 */
<> 149:156823d33999 46 boolean fTrim()
<> 149:156823d33999 47 {
<> 149:156823d33999 48
<> 149:156823d33999 49 /**- Check if trim values are present */
<> 149:156823d33999 50 /**- If Trim data is present. Only trim if valid trim values are present. */
<> 149:156823d33999 51 /**- Copy trims in registers */
<> 149:156823d33999 52 if (TRIMREG->REVISION_CODE != 0xFFFFFFFF) {
<> 149:156823d33999 53
<> 149:156823d33999 54 /**- board specific clock trims may only be done when present, writing all 1's is not good */
<> 149:156823d33999 55 if ((TRIMREG->TRIM_32K_EXT & 0xFFFF0000) != 0xFFFF0000) {
<> 149:156823d33999 56 CLOCKREG->TRIM_32K_EXT = TRIMREG->TRIM_32K_EXT;
<> 149:156823d33999 57 }
<> 149:156823d33999 58
<> 149:156823d33999 59 if ((TRIMREG->TRIM_32M_EXT & 0xFFFF0000) != 0xFFFF0000) {
<> 149:156823d33999 60 CLOCKREG->TRIM_32M_EXT = TRIMREG->TRIM_32M_EXT;
<> 149:156823d33999 61 }
<> 149:156823d33999 62
<> 149:156823d33999 63 MACHWREG->TX_LENGTH.BITS.TX_PRE_CHIPS = TRIMREG->TX_PRE_CHIPS;
<> 149:156823d33999 64
<> 149:156823d33999 65 RFANATRIMREG->TX_CHAIN_TRIM = TRIMREG->TX_CHAIN_TRIM;
<> 149:156823d33999 66 RFANATRIMREG->PLL_VCO_TAP_LOCATION = TRIMREG->PLL_VCO_TAP_LOCATION;
<> 149:156823d33999 67 RFANATRIMREG->PLL_TRIM.WORD = TRIMREG->PLL_TRIM;
<> 149:156823d33999 68
<> 149:156823d33999 69 /**- board specific RSSI trims may only be done when present, writing all 1's is not good */
<> 149:156823d33999 70 if ((TRIMREG->RSSI_OFFSET & 0xFFFF0000) != 0xFFFF0000) {
<> 149:156823d33999 71 DMDREG->DMD_CONTROL2.BITS.RSSI_OFFSET = TRIMREG->RSSI_OFFSET;
<> 149:156823d33999 72 }
<> 149:156823d33999 73
<> 149:156823d33999 74 RFANATRIMREG->RX_CHAIN_TRIM = TRIMREG->RX_CHAIN_TRIM;
<> 149:156823d33999 75 RFANATRIMREG->PMU_TRIM = TRIMREG->PMU_TRIM;
<> 149:156823d33999 76 RANDREG->WR_SEED_RD_RAND = TRIMREG->WR_SEED_RD_RAND;
<> 149:156823d33999 77
<> 149:156823d33999 78 /** REVD boards are trimmed (in flash) with rx vco trims specific for high side injection,
<> 149:156823d33999 79 * */
<> 149:156823d33999 80 RFANATRIMREG->RX_VCO_TRIM_LUT1 = TRIMREG->RX_VCO_LUT1.WORD;;
<> 149:156823d33999 81 RFANATRIMREG->RX_VCO_TRIM_LUT2 = TRIMREG->RX_VCO_LUT2.WORD;;
<> 149:156823d33999 82
<> 149:156823d33999 83 RFANATRIMREG->TX_VCO_TRIM_LUT1 = TRIMREG->TX_VCO_LUT1.WORD;;
<> 149:156823d33999 84 RFANATRIMREG->TX_VCO_TRIM_LUT2 = TRIMREG->TX_VCO_LUT2.WORD;;
<> 149:156823d33999 85
<> 150:02e0a0aed4ec 86 if ( TRIMREG->MAC_ADDR_LOW != 0xFFFFFFFF ) {
<> 150:02e0a0aed4ec 87 MACHWREG->LONG_ADDRESS_LOW = TRIMREG->MAC_ADDR_LOW;
<> 150:02e0a0aed4ec 88 }
<> 150:02e0a0aed4ec 89
<> 150:02e0a0aed4ec 90 if ( TRIMREG->MAC_ADDR_HIGH != 0xFFFFFFFF ) {
<> 150:02e0a0aed4ec 91 MACHWREG->LONG_ADDRESS_HIGH = TRIMREG->MAC_ADDR_HIGH;
<> 150:02e0a0aed4ec 92 }
<> 149:156823d33999 93
<> 149:156823d33999 94 return True;
<> 149:156823d33999 95 } else {
<> 149:156823d33999 96 /**- If no trim values are present, update the global status variable. */
<> 149:156823d33999 97 return False;
<> 149:156823d33999 98 }
<> 149:156823d33999 99 }
<> 149:156823d33999 100
<> 149:156823d33999 101 /* See clock.h for documentation. */
<> 149:156823d33999 102 void fClockInit()
<> 149:156823d33999 103 {
<> 149:156823d33999 104
<> 149:156823d33999 105 /** Enable external 32MHz oscillator */
<> 149:156823d33999 106 CLOCKREG->CCR.BITS.OSC_SEL = 1;
<> 149:156823d33999 107
<> 149:156823d33999 108 /** - Wait external 32MHz oscillator to be ready */
<> 149:156823d33999 109 while(CLOCKREG->CSR.BITS.XTAL32M != 1) {} /* If you get stuck here, something is wrong with board or trim values */
<> 149:156823d33999 110
<> 149:156823d33999 111 /** Internal 32MHz calibration \n *//** - Enable internal 32MHz clock */
<> 149:156823d33999 112 PMUREG->CONTROL.BITS.INT32M = 0;
<> 149:156823d33999 113
<> 149:156823d33999 114 /** - Wait 5 uSec for clock to stabilize */
<> 149:156823d33999 115 volatile uint8_t Timer;
<> 149:156823d33999 116 for(Timer = 0; Timer < 10; Timer++);
<> 149:156823d33999 117
<> 149:156823d33999 118 /** - Enable calibration */
<> 149:156823d33999 119 CLOCKREG->CCR.BITS.CAL32M = True;
<> 149:156823d33999 120
<> 149:156823d33999 121 /** - Wait calibration to be completed */
<> 149:156823d33999 122 while(CLOCKREG->CSR.BITS.CAL32MDONE == False); /* If you stuck here, issue with internal 32M calibration */
<> 149:156823d33999 123
<> 149:156823d33999 124 /** - Check calibration status */
<> 149:156823d33999 125 while(CLOCKREG->CSR.BITS.CAL32MFAIL == True); /* If you stuck here, issue with internal 32M calibration */
<> 149:156823d33999 126
<> 149:156823d33999 127 /** - Power down internal 32MHz osc */
<> 149:156823d33999 128 PMUREG->CONTROL.BITS.INT32M = 1;
<> 149:156823d33999 129
<> 149:156823d33999 130 /** Internal 32KHz calibration \n */ /** - Enable internal 32KHz clock */
<> 149:156823d33999 131 PMUREG->CONTROL.BITS.INT32K = 0;
<> 149:156823d33999 132
<> 149:156823d33999 133 /** - Wait 5 uSec for clock to stabilize */
<> 149:156823d33999 134 for(Timer = 0; Timer < 10; Timer++);
<> 149:156823d33999 135
<> 149:156823d33999 136 /** - Enable calibration */
<> 149:156823d33999 137 CLOCKREG->CCR.BITS.CAL32K = True;
<> 149:156823d33999 138
<> 149:156823d33999 139 /** - Wait calibration to be completed */
<> 149:156823d33999 140 while(CLOCKREG->CSR.BITS.DONE32K == False); /* If you stuck here, issue with internal 32K calibration */
<> 149:156823d33999 141
<> 149:156823d33999 142 /** - Check calibration status */
<> 149:156823d33999 143 while(CLOCKREG->CSR.BITS.CAL32K == True); /* If you stuck here, issue with internal 32M calibration */
<> 149:156823d33999 144
<> 149:156823d33999 145 /** - Power down external 32KHz osc */
<> 149:156823d33999 146 PMUREG->CONTROL.BITS.EXT32K = 1;
<> 149:156823d33999 147
<> 149:156823d33999 148 /** Disable all peripheral clocks by default */
<> 149:156823d33999 149 CLOCKREG->PDIS.WORD = 0xFFFFFFFF;
<> 149:156823d33999 150
<> 149:156823d33999 151 /** Set core frequency */
<> 149:156823d33999 152 CLOCKREG->FDIV = CPU_CLOCK_DIV - 1;
<> 149:156823d33999 153 }
<> 149:156823d33999 154
<> 149:156823d33999 155 /* Initializes PMU module */
<> 149:156823d33999 156 void fPmuInit()
<> 149:156823d33999 157 {
<> 149:156823d33999 158 /** Enable the clock for PMU peripheral device */
<> 149:156823d33999 159 CLOCK_ENABLE(CLOCK_PMU);
<> 149:156823d33999 160
<> 149:156823d33999 161 /** Unset wakeup on pending (only enabled irq can wakeup) */
<> 149:156823d33999 162 SCB->SCR &= ~SCB_SCR_SEVONPEND_Msk;
<> 149:156823d33999 163
<> 149:156823d33999 164 /** Unset auto sleep when returning from wakeup irq */
<> 149:156823d33999 165 SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk;
<> 149:156823d33999 166
<> 149:156823d33999 167 /** Set regulator timings */
<> 150:02e0a0aed4ec 168 PMUREG->FVDD_TSETTLE = 160;
<> 150:02e0a0aed4ec 169 PMUREG->FVDD_TSTARTUP = 400;
<> 150:02e0a0aed4ec 170
<> 149:156823d33999 171
<> 149:156823d33999 172 /** Keep SRAMA & SRAMB powered in coma mode */
<> 149:156823d33999 173 PMUREG->CONTROL.BITS.SRAMA = False;
<> 149:156823d33999 174 PMUREG->CONTROL.BITS.SRAMB = False;
<> 149:156823d33999 175
<> 150:02e0a0aed4ec 176 PMUREG->CONTROL.BITS.N1V1 = True; /* Enable ACTIVE mode switching regulator */
<> 150:02e0a0aed4ec 177 PMUREG->CONTROL.BITS.C1V1 = True; /* Enable COMA mode switching regulator */
<> 149:156823d33999 178
<> 149:156823d33999 179 /** Disable the clock for PMU peripheral device, all settings are done */
<> 149:156823d33999 180 CLOCK_DISABLE(CLOCK_PMU);
<> 149:156823d33999 181 }
<> 149:156823d33999 182
<> 149:156823d33999 183 /* See clock.h for documentation. */
<> 149:156823d33999 184 uint32_t fClockGetPeriphClockfrequency()
<> 149:156823d33999 185 {
<> 149:156823d33999 186 return (CPU_CLOCK_ROOT_HZ / CPU_CLOCK_DIV);
<> 149:156823d33999 187 }
<> 149:156823d33999 188
<> 149:156823d33999 189
<> 149:156823d33999 190 /**
<> 149:156823d33999 191 * @brief
<> 149:156823d33999 192 * Hardware initialization function
<> 149:156823d33999 193 * This function initializes hardware at application start up prior
<> 149:156823d33999 194 * to other initializations or OS operations.
<> 149:156823d33999 195 */
<> 149:156823d33999 196 static void fHwInit(void)
<> 149:156823d33999 197 {
<> 149:156823d33999 198
<> 149:156823d33999 199 /* Trim register settings */
<> 149:156823d33999 200 fTrim();
<> 149:156823d33999 201
<> 149:156823d33999 202 /* Clock setting */
<> 149:156823d33999 203 /** - Initialize clock */
<> 149:156823d33999 204 fClockInit();
<> 149:156823d33999 205
<> 149:156823d33999 206 /** - Initialize pmu */
<> 149:156823d33999 207 fPmuInit();
<> 149:156823d33999 208
<> 149:156823d33999 209 /** Orion has 4 interrupt bits in interrupt priority register
<> 149:156823d33999 210 * The lowest 4 bits are not used.
<> 149:156823d33999 211 *
<> 149:156823d33999 212 @verbatim
<> 149:156823d33999 213 +-----+-----+-----+-----+-----+-----+-----+-----+
<> 149:156823d33999 214 |bit 7|bit 6|bit 5|bit 4|bit 3|bit 2|bit 1|bit 0|
<> 149:156823d33999 215 | | | | | 0 | 0 | 0 | 0 |
<> 149:156823d33999 216 +-----+-----+-----+-----+-----+-----+-----+-----+
<> 149:156823d33999 217 |
<> 149:156823d33999 218 INTERRUPT PRIORITY | NOT IMPLEMENTED,
<> 149:156823d33999 219 | read as 0
<> 149:156823d33999 220 Valid priorities are 0x00, 0x10, 0x20, 0x30
<> 149:156823d33999 221 0x40, 0x50, 0x60, 0x70
<> 149:156823d33999 222 0x80, 0x90, 0xA0, 0xB0
<> 149:156823d33999 223 0xC0, 0xD0, 0xE0, 0xF0
<> 149:156823d33999 224 @endverbatim
<> 149:156823d33999 225 * Lowest number is highest priority
<> 149:156823d33999 226 *
<> 149:156823d33999 227 *
<> 149:156823d33999 228 * This range is defined by
<> 149:156823d33999 229 * configKERNEL_INTERRUPT_PRIORITY (lowest)
<> 149:156823d33999 230 * and configMAX_SYSCALL_INTERRUPT_PRIORITY (highest). All interrupt
<> 149:156823d33999 231 * priorities need to fall in that range.
<> 149:156823d33999 232 *
<> 149:156823d33999 233 * To be future safe, the LSbits of the priority are set to 0xF.
<> 149:156823d33999 234 * This wil lmake sure that if more interrupt bits are used, the
<> 149:156823d33999 235 * priority is maintained.
<> 149:156823d33999 236 */
<> 149:156823d33999 237
<> 149:156823d33999 238 /** - Set IRQs priorities */
<> 149:156823d33999 239 NVIC_SetPriority(Tim0_IRQn, 14);
<> 149:156823d33999 240 NVIC_SetPriority(Tim1_IRQn, 14);
<> 149:156823d33999 241 NVIC_SetPriority(Tim2_IRQn, 14);
<> 149:156823d33999 242 NVIC_SetPriority(Uart1_IRQn,14);
<> 149:156823d33999 243 NVIC_SetPriority(Spi_IRQn, 14);
<> 149:156823d33999 244 NVIC_SetPriority(I2C_IRQn, 14);
<> 149:156823d33999 245 NVIC_SetPriority(Gpio_IRQn, 14);
<> 149:156823d33999 246 NVIC_SetPriority(Rtc_IRQn, 14);
<> 149:156823d33999 247 NVIC_SetPriority(MacHw_IRQn, 13);
<> 149:156823d33999 248 NVIC_SetPriority(Aes_IRQn, 13);
<> 149:156823d33999 249 NVIC_SetPriority(Adc_IRQn, 14);
<> 149:156823d33999 250 NVIC_SetPriority(ClockCal_IRQn, 14);
<> 149:156823d33999 251 NVIC_SetPriority(Uart2_IRQn, 14);
<> 149:156823d33999 252 NVIC_SetPriority(Dma_IRQn, 14);
<> 149:156823d33999 253 NVIC_SetPriority(Uvi_IRQn, 14);
<> 149:156823d33999 254 NVIC_SetPriority(DbgPwrUp_IRQn, 14);
<> 149:156823d33999 255 NVIC_SetPriority(Spi2_IRQn, 14);
<> 149:156823d33999 256 NVIC_SetPriority(I2C2_IRQn, 14);
<> 149:156823d33999 257 }
<> 149:156823d33999 258
<> 149:156823d33999 259 extern void __Vectors;
<> 149:156823d33999 260
<> 149:156823d33999 261 void fNcs36510Init(void)
<> 149:156823d33999 262 {
<> 149:156823d33999 263 /** Setting this register is helping to debug imprecise bus access faults
<> 149:156823d33999 264 * making them precise bus access faults. It has an impact on application
<> 149:156823d33999 265 * performance. */
<> 149:156823d33999 266 // SCnSCB->ACTLR |= SCnSCB_ACTLR_DISDEFWBUF_Msk;
<> 149:156823d33999 267
<> 149:156823d33999 268 /** This main function implements: */
<> 149:156823d33999 269 /**- Disable all interrupts */
<> 149:156823d33999 270 NVIC->ICER[0] = 0x1F;
<> 149:156823d33999 271
<> 149:156823d33999 272 /**- Clear all Pending interrupts */
<> 149:156823d33999 273 NVIC->ICPR[0] = 0x1F;
<> 149:156823d33999 274
<> 149:156823d33999 275 /**- Clear all pending SV and systick */
<> 149:156823d33999 276 SCB->ICSR = (uint32_t)0x0A000000;
<> 149:156823d33999 277 SCB->VTOR = (uint32_t) (&__Vectors);
<> 149:156823d33999 278
<> 149:156823d33999 279 /**- Initialize hardware */
<> 149:156823d33999 280 fHwInit();
<> 149:156823d33999 281 }