mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_ONSEMI/TARGET_NCS36510/ncs36510Init.c@149:156823d33999, 2016-10-28 (annotated)
- Committer:
- <>
- Date:
- Fri Oct 28 11:17:30 2016 +0100
- Revision:
- 149:156823d33999
- Child:
- 150:02e0a0aed4ec
This updates the lib to the mbed lib v128
NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.
Who changed what in which revision?
User | Revision | Line number | New 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 | |
<> | 149:156823d33999 | 86 | |
<> | 149:156823d33999 | 87 | return True; |
<> | 149:156823d33999 | 88 | } else { |
<> | 149:156823d33999 | 89 | /**- If no trim values are present, update the global status variable. */ |
<> | 149:156823d33999 | 90 | return False; |
<> | 149:156823d33999 | 91 | } |
<> | 149:156823d33999 | 92 | } |
<> | 149:156823d33999 | 93 | |
<> | 149:156823d33999 | 94 | /* See clock.h for documentation. */ |
<> | 149:156823d33999 | 95 | void fClockInit() |
<> | 149:156823d33999 | 96 | { |
<> | 149:156823d33999 | 97 | |
<> | 149:156823d33999 | 98 | /** Enable external 32MHz oscillator */ |
<> | 149:156823d33999 | 99 | CLOCKREG->CCR.BITS.OSC_SEL = 1; |
<> | 149:156823d33999 | 100 | |
<> | 149:156823d33999 | 101 | /** - Wait external 32MHz oscillator to be ready */ |
<> | 149:156823d33999 | 102 | while(CLOCKREG->CSR.BITS.XTAL32M != 1) {} /* If you get stuck here, something is wrong with board or trim values */ |
<> | 149:156823d33999 | 103 | |
<> | 149:156823d33999 | 104 | /** Internal 32MHz calibration \n *//** - Enable internal 32MHz clock */ |
<> | 149:156823d33999 | 105 | PMUREG->CONTROL.BITS.INT32M = 0; |
<> | 149:156823d33999 | 106 | |
<> | 149:156823d33999 | 107 | /** - Wait 5 uSec for clock to stabilize */ |
<> | 149:156823d33999 | 108 | volatile uint8_t Timer; |
<> | 149:156823d33999 | 109 | for(Timer = 0; Timer < 10; Timer++); |
<> | 149:156823d33999 | 110 | |
<> | 149:156823d33999 | 111 | /** - Enable calibration */ |
<> | 149:156823d33999 | 112 | CLOCKREG->CCR.BITS.CAL32M = True; |
<> | 149:156823d33999 | 113 | |
<> | 149:156823d33999 | 114 | /** - Wait calibration to be completed */ |
<> | 149:156823d33999 | 115 | while(CLOCKREG->CSR.BITS.CAL32MDONE == False); /* If you stuck here, issue with internal 32M calibration */ |
<> | 149:156823d33999 | 116 | |
<> | 149:156823d33999 | 117 | /** - Check calibration status */ |
<> | 149:156823d33999 | 118 | while(CLOCKREG->CSR.BITS.CAL32MFAIL == True); /* If you stuck here, issue with internal 32M calibration */ |
<> | 149:156823d33999 | 119 | |
<> | 149:156823d33999 | 120 | /** - Power down internal 32MHz osc */ |
<> | 149:156823d33999 | 121 | PMUREG->CONTROL.BITS.INT32M = 1; |
<> | 149:156823d33999 | 122 | |
<> | 149:156823d33999 | 123 | /** Internal 32KHz calibration \n */ /** - Enable internal 32KHz clock */ |
<> | 149:156823d33999 | 124 | PMUREG->CONTROL.BITS.INT32K = 0; |
<> | 149:156823d33999 | 125 | |
<> | 149:156823d33999 | 126 | /** - Wait 5 uSec for clock to stabilize */ |
<> | 149:156823d33999 | 127 | for(Timer = 0; Timer < 10; Timer++); |
<> | 149:156823d33999 | 128 | |
<> | 149:156823d33999 | 129 | /** - Enable calibration */ |
<> | 149:156823d33999 | 130 | CLOCKREG->CCR.BITS.CAL32K = True; |
<> | 149:156823d33999 | 131 | |
<> | 149:156823d33999 | 132 | /** - Wait calibration to be completed */ |
<> | 149:156823d33999 | 133 | while(CLOCKREG->CSR.BITS.DONE32K == False); /* If you stuck here, issue with internal 32K calibration */ |
<> | 149:156823d33999 | 134 | |
<> | 149:156823d33999 | 135 | /** - Check calibration status */ |
<> | 149:156823d33999 | 136 | while(CLOCKREG->CSR.BITS.CAL32K == True); /* If you stuck here, issue with internal 32M calibration */ |
<> | 149:156823d33999 | 137 | |
<> | 149:156823d33999 | 138 | /** - Power down external 32KHz osc */ |
<> | 149:156823d33999 | 139 | PMUREG->CONTROL.BITS.EXT32K = 1; |
<> | 149:156823d33999 | 140 | |
<> | 149:156823d33999 | 141 | /** Disable all peripheral clocks by default */ |
<> | 149:156823d33999 | 142 | CLOCKREG->PDIS.WORD = 0xFFFFFFFF; |
<> | 149:156823d33999 | 143 | |
<> | 149:156823d33999 | 144 | /** Set core frequency */ |
<> | 149:156823d33999 | 145 | CLOCKREG->FDIV = CPU_CLOCK_DIV - 1; |
<> | 149:156823d33999 | 146 | } |
<> | 149:156823d33999 | 147 | |
<> | 149:156823d33999 | 148 | /* Initializes PMU module */ |
<> | 149:156823d33999 | 149 | void fPmuInit() |
<> | 149:156823d33999 | 150 | { |
<> | 149:156823d33999 | 151 | /** Enable the clock for PMU peripheral device */ |
<> | 149:156823d33999 | 152 | CLOCK_ENABLE(CLOCK_PMU); |
<> | 149:156823d33999 | 153 | |
<> | 149:156823d33999 | 154 | /** Unset wakeup on pending (only enabled irq can wakeup) */ |
<> | 149:156823d33999 | 155 | SCB->SCR &= ~SCB_SCR_SEVONPEND_Msk; |
<> | 149:156823d33999 | 156 | |
<> | 149:156823d33999 | 157 | /** Unset auto sleep when returning from wakeup irq */ |
<> | 149:156823d33999 | 158 | SCB->SCR &= ~SCB_SCR_SLEEPONEXIT_Msk; |
<> | 149:156823d33999 | 159 | |
<> | 149:156823d33999 | 160 | /** Set regulator timings */ |
<> | 149:156823d33999 | 161 | PMUREG->FVDD_TSETTLE = 160; |
<> | 149:156823d33999 | 162 | PMUREG->FVDD_TSTARTUP = 400; |
<> | 149:156823d33999 | 163 | |
<> | 149:156823d33999 | 164 | /** Keep SRAMA & SRAMB powered in coma mode */ |
<> | 149:156823d33999 | 165 | PMUREG->CONTROL.BITS.SRAMA = False; |
<> | 149:156823d33999 | 166 | PMUREG->CONTROL.BITS.SRAMB = False; |
<> | 149:156823d33999 | 167 | |
<> | 149:156823d33999 | 168 | PMUREG->CONTROL.BITS.N1V1 = True; /* Enable ACTIVE mode switching regulator */ |
<> | 149:156823d33999 | 169 | PMUREG->CONTROL.BITS.C1V1 = True; /* Enable COMA mode switching regulator */ |
<> | 149:156823d33999 | 170 | |
<> | 149:156823d33999 | 171 | /** Disable the clock for PMU peripheral device, all settings are done */ |
<> | 149:156823d33999 | 172 | CLOCK_DISABLE(CLOCK_PMU); |
<> | 149:156823d33999 | 173 | } |
<> | 149:156823d33999 | 174 | |
<> | 149:156823d33999 | 175 | /* See clock.h for documentation. */ |
<> | 149:156823d33999 | 176 | uint32_t fClockGetPeriphClockfrequency() |
<> | 149:156823d33999 | 177 | { |
<> | 149:156823d33999 | 178 | return (CPU_CLOCK_ROOT_HZ / CPU_CLOCK_DIV); |
<> | 149:156823d33999 | 179 | } |
<> | 149:156823d33999 | 180 | |
<> | 149:156823d33999 | 181 | |
<> | 149:156823d33999 | 182 | /** |
<> | 149:156823d33999 | 183 | * @brief |
<> | 149:156823d33999 | 184 | * Hardware initialization function |
<> | 149:156823d33999 | 185 | * This function initializes hardware at application start up prior |
<> | 149:156823d33999 | 186 | * to other initializations or OS operations. |
<> | 149:156823d33999 | 187 | */ |
<> | 149:156823d33999 | 188 | static void fHwInit(void) |
<> | 149:156823d33999 | 189 | { |
<> | 149:156823d33999 | 190 | |
<> | 149:156823d33999 | 191 | /* Trim register settings */ |
<> | 149:156823d33999 | 192 | fTrim(); |
<> | 149:156823d33999 | 193 | |
<> | 149:156823d33999 | 194 | /* Clock setting */ |
<> | 149:156823d33999 | 195 | /** - Initialize clock */ |
<> | 149:156823d33999 | 196 | fClockInit(); |
<> | 149:156823d33999 | 197 | |
<> | 149:156823d33999 | 198 | /** - Initialize pmu */ |
<> | 149:156823d33999 | 199 | fPmuInit(); |
<> | 149:156823d33999 | 200 | |
<> | 149:156823d33999 | 201 | /** Orion has 4 interrupt bits in interrupt priority register |
<> | 149:156823d33999 | 202 | * The lowest 4 bits are not used. |
<> | 149:156823d33999 | 203 | * |
<> | 149:156823d33999 | 204 | @verbatim |
<> | 149:156823d33999 | 205 | +-----+-----+-----+-----+-----+-----+-----+-----+ |
<> | 149:156823d33999 | 206 | |bit 7|bit 6|bit 5|bit 4|bit 3|bit 2|bit 1|bit 0| |
<> | 149:156823d33999 | 207 | | | | | | 0 | 0 | 0 | 0 | |
<> | 149:156823d33999 | 208 | +-----+-----+-----+-----+-----+-----+-----+-----+ |
<> | 149:156823d33999 | 209 | | |
<> | 149:156823d33999 | 210 | INTERRUPT PRIORITY | NOT IMPLEMENTED, |
<> | 149:156823d33999 | 211 | | read as 0 |
<> | 149:156823d33999 | 212 | Valid priorities are 0x00, 0x10, 0x20, 0x30 |
<> | 149:156823d33999 | 213 | 0x40, 0x50, 0x60, 0x70 |
<> | 149:156823d33999 | 214 | 0x80, 0x90, 0xA0, 0xB0 |
<> | 149:156823d33999 | 215 | 0xC0, 0xD0, 0xE0, 0xF0 |
<> | 149:156823d33999 | 216 | @endverbatim |
<> | 149:156823d33999 | 217 | * Lowest number is highest priority |
<> | 149:156823d33999 | 218 | * |
<> | 149:156823d33999 | 219 | * |
<> | 149:156823d33999 | 220 | * This range is defined by |
<> | 149:156823d33999 | 221 | * configKERNEL_INTERRUPT_PRIORITY (lowest) |
<> | 149:156823d33999 | 222 | * and configMAX_SYSCALL_INTERRUPT_PRIORITY (highest). All interrupt |
<> | 149:156823d33999 | 223 | * priorities need to fall in that range. |
<> | 149:156823d33999 | 224 | * |
<> | 149:156823d33999 | 225 | * To be future safe, the LSbits of the priority are set to 0xF. |
<> | 149:156823d33999 | 226 | * This wil lmake sure that if more interrupt bits are used, the |
<> | 149:156823d33999 | 227 | * priority is maintained. |
<> | 149:156823d33999 | 228 | */ |
<> | 149:156823d33999 | 229 | |
<> | 149:156823d33999 | 230 | /** - Set IRQs priorities */ |
<> | 149:156823d33999 | 231 | NVIC_SetPriority(Tim0_IRQn, 14); |
<> | 149:156823d33999 | 232 | NVIC_SetPriority(Tim1_IRQn, 14); |
<> | 149:156823d33999 | 233 | NVIC_SetPriority(Tim2_IRQn, 14); |
<> | 149:156823d33999 | 234 | NVIC_SetPriority(Uart1_IRQn,14); |
<> | 149:156823d33999 | 235 | NVIC_SetPriority(Spi_IRQn, 14); |
<> | 149:156823d33999 | 236 | NVIC_SetPriority(I2C_IRQn, 14); |
<> | 149:156823d33999 | 237 | NVIC_SetPriority(Gpio_IRQn, 14); |
<> | 149:156823d33999 | 238 | NVIC_SetPriority(Rtc_IRQn, 14); |
<> | 149:156823d33999 | 239 | NVIC_SetPriority(MacHw_IRQn, 13); |
<> | 149:156823d33999 | 240 | NVIC_SetPriority(Aes_IRQn, 13); |
<> | 149:156823d33999 | 241 | NVIC_SetPriority(Adc_IRQn, 14); |
<> | 149:156823d33999 | 242 | NVIC_SetPriority(ClockCal_IRQn, 14); |
<> | 149:156823d33999 | 243 | NVIC_SetPriority(Uart2_IRQn, 14); |
<> | 149:156823d33999 | 244 | NVIC_SetPriority(Dma_IRQn, 14); |
<> | 149:156823d33999 | 245 | NVIC_SetPriority(Uvi_IRQn, 14); |
<> | 149:156823d33999 | 246 | NVIC_SetPriority(DbgPwrUp_IRQn, 14); |
<> | 149:156823d33999 | 247 | NVIC_SetPriority(Spi2_IRQn, 14); |
<> | 149:156823d33999 | 248 | NVIC_SetPriority(I2C2_IRQn, 14); |
<> | 149:156823d33999 | 249 | } |
<> | 149:156823d33999 | 250 | |
<> | 149:156823d33999 | 251 | extern void __Vectors; |
<> | 149:156823d33999 | 252 | |
<> | 149:156823d33999 | 253 | void fNcs36510Init(void) |
<> | 149:156823d33999 | 254 | { |
<> | 149:156823d33999 | 255 | /** Setting this register is helping to debug imprecise bus access faults |
<> | 149:156823d33999 | 256 | * making them precise bus access faults. It has an impact on application |
<> | 149:156823d33999 | 257 | * performance. */ |
<> | 149:156823d33999 | 258 | // SCnSCB->ACTLR |= SCnSCB_ACTLR_DISDEFWBUF_Msk; |
<> | 149:156823d33999 | 259 | |
<> | 149:156823d33999 | 260 | /** This main function implements: */ |
<> | 149:156823d33999 | 261 | /**- Disable all interrupts */ |
<> | 149:156823d33999 | 262 | NVIC->ICER[0] = 0x1F; |
<> | 149:156823d33999 | 263 | |
<> | 149:156823d33999 | 264 | /**- Clear all Pending interrupts */ |
<> | 149:156823d33999 | 265 | NVIC->ICPR[0] = 0x1F; |
<> | 149:156823d33999 | 266 | |
<> | 149:156823d33999 | 267 | /**- Clear all pending SV and systick */ |
<> | 149:156823d33999 | 268 | SCB->ICSR = (uint32_t)0x0A000000; |
<> | 149:156823d33999 | 269 | SCB->VTOR = (uint32_t) (&__Vectors); |
<> | 149:156823d33999 | 270 | |
<> | 149:156823d33999 | 271 | /**- Initialize hardware */ |
<> | 149:156823d33999 | 272 | fHwInit(); |
<> | 149:156823d33999 | 273 | } |