BA
/
BaBoRo_test2
Backup 1
mbed-os/platform/mbed_application.c@0:02dd72d1d465, 2018-04-24 (annotated)
- Committer:
- borlanic
- Date:
- Tue Apr 24 11:45:18 2018 +0000
- Revision:
- 0:02dd72d1d465
BaBoRo_test2 - backup 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
borlanic | 0:02dd72d1d465 | 1 | /* mbed Microcontroller Library |
borlanic | 0:02dd72d1d465 | 2 | * Copyright (c) 2017-2017 ARM Limited |
borlanic | 0:02dd72d1d465 | 3 | * |
borlanic | 0:02dd72d1d465 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
borlanic | 0:02dd72d1d465 | 5 | * you may not use this file except in compliance with the License. |
borlanic | 0:02dd72d1d465 | 6 | * You may obtain a copy of the License at |
borlanic | 0:02dd72d1d465 | 7 | * |
borlanic | 0:02dd72d1d465 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
borlanic | 0:02dd72d1d465 | 9 | * |
borlanic | 0:02dd72d1d465 | 10 | * Unless required by applicable law or agreed to in writing, software |
borlanic | 0:02dd72d1d465 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
borlanic | 0:02dd72d1d465 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
borlanic | 0:02dd72d1d465 | 13 | * See the License for the specific language governing permissions and |
borlanic | 0:02dd72d1d465 | 14 | * limitations under the License. |
borlanic | 0:02dd72d1d465 | 15 | */ |
borlanic | 0:02dd72d1d465 | 16 | |
borlanic | 0:02dd72d1d465 | 17 | #include <stdlib.h> |
borlanic | 0:02dd72d1d465 | 18 | #include <stdarg.h> |
borlanic | 0:02dd72d1d465 | 19 | #include "device.h" |
borlanic | 0:02dd72d1d465 | 20 | #include "platform/mbed_application.h" |
borlanic | 0:02dd72d1d465 | 21 | |
borlanic | 0:02dd72d1d465 | 22 | #if MBED_APPLICATION_SUPPORT |
borlanic | 0:02dd72d1d465 | 23 | |
borlanic | 0:02dd72d1d465 | 24 | static void powerdown_nvic(void); |
borlanic | 0:02dd72d1d465 | 25 | static void powerdown_scb(uint32_t vtor); |
borlanic | 0:02dd72d1d465 | 26 | static void start_new_application(void *sp, void *pc); |
borlanic | 0:02dd72d1d465 | 27 | |
borlanic | 0:02dd72d1d465 | 28 | void mbed_start_application(uintptr_t address) |
borlanic | 0:02dd72d1d465 | 29 | { |
borlanic | 0:02dd72d1d465 | 30 | void *sp; |
borlanic | 0:02dd72d1d465 | 31 | void *pc; |
borlanic | 0:02dd72d1d465 | 32 | |
borlanic | 0:02dd72d1d465 | 33 | // Interrupts are re-enabled in start_new_application |
borlanic | 0:02dd72d1d465 | 34 | __disable_irq(); |
borlanic | 0:02dd72d1d465 | 35 | |
borlanic | 0:02dd72d1d465 | 36 | SysTick->CTRL = 0x00000000; |
borlanic | 0:02dd72d1d465 | 37 | powerdown_nvic(); |
borlanic | 0:02dd72d1d465 | 38 | powerdown_scb(address); |
borlanic | 0:02dd72d1d465 | 39 | |
borlanic | 0:02dd72d1d465 | 40 | sp = *((void**)address + 0); |
borlanic | 0:02dd72d1d465 | 41 | pc = *((void**)address + 1); |
borlanic | 0:02dd72d1d465 | 42 | start_new_application(sp, pc); |
borlanic | 0:02dd72d1d465 | 43 | } |
borlanic | 0:02dd72d1d465 | 44 | |
borlanic | 0:02dd72d1d465 | 45 | static void powerdown_nvic() |
borlanic | 0:02dd72d1d465 | 46 | { |
borlanic | 0:02dd72d1d465 | 47 | int isr_groups_32; |
borlanic | 0:02dd72d1d465 | 48 | int i; |
borlanic | 0:02dd72d1d465 | 49 | int j; |
borlanic | 0:02dd72d1d465 | 50 | |
borlanic | 0:02dd72d1d465 | 51 | isr_groups_32 = ((SCnSCB->ICTR & SCnSCB_ICTR_INTLINESNUM_Msk) >> SCnSCB_ICTR_INTLINESNUM_Pos) + 1; |
borlanic | 0:02dd72d1d465 | 52 | for (i = 0; i < isr_groups_32; i++) { |
borlanic | 0:02dd72d1d465 | 53 | NVIC->ICER[i] = 0xFFFFFFFF; |
borlanic | 0:02dd72d1d465 | 54 | NVIC->ICPR[i] = 0xFFFFFFFF; |
borlanic | 0:02dd72d1d465 | 55 | for (j = 0; j < 8; j++) { |
borlanic | 0:02dd72d1d465 | 56 | NVIC->IP[i * 8 + j] = 0x00000000; |
borlanic | 0:02dd72d1d465 | 57 | } |
borlanic | 0:02dd72d1d465 | 58 | } |
borlanic | 0:02dd72d1d465 | 59 | } |
borlanic | 0:02dd72d1d465 | 60 | |
borlanic | 0:02dd72d1d465 | 61 | static void powerdown_scb(uint32_t vtor) |
borlanic | 0:02dd72d1d465 | 62 | { |
borlanic | 0:02dd72d1d465 | 63 | int i; |
borlanic | 0:02dd72d1d465 | 64 | |
borlanic | 0:02dd72d1d465 | 65 | // SCB->CPUID - Read only CPU ID register |
borlanic | 0:02dd72d1d465 | 66 | SCB->ICSR = SCB_ICSR_PENDSVCLR_Msk | SCB_ICSR_PENDSTCLR_Msk; |
borlanic | 0:02dd72d1d465 | 67 | SCB->VTOR = vtor; |
borlanic | 0:02dd72d1d465 | 68 | SCB->AIRCR = 0x05FA | 0x0000; |
borlanic | 0:02dd72d1d465 | 69 | SCB->SCR = 0x00000000; |
borlanic | 0:02dd72d1d465 | 70 | // SCB->CCR - Implementation defined value |
borlanic | 0:02dd72d1d465 | 71 | for (i = 0; i < 12; i++) { |
borlanic | 0:02dd72d1d465 | 72 | #if defined(__CORTEX_M7) |
borlanic | 0:02dd72d1d465 | 73 | SCB->SHPR[i] = 0x00; |
borlanic | 0:02dd72d1d465 | 74 | #else |
borlanic | 0:02dd72d1d465 | 75 | SCB->SHP[i] = 0x00; |
borlanic | 0:02dd72d1d465 | 76 | #endif |
borlanic | 0:02dd72d1d465 | 77 | } |
borlanic | 0:02dd72d1d465 | 78 | SCB->SHCSR = 0x00000000; |
borlanic | 0:02dd72d1d465 | 79 | SCB->CFSR = 0xFFFFFFFF; |
borlanic | 0:02dd72d1d465 | 80 | SCB->HFSR = SCB_HFSR_DEBUGEVT_Msk | SCB_HFSR_FORCED_Msk | SCB_HFSR_VECTTBL_Msk; |
borlanic | 0:02dd72d1d465 | 81 | SCB->DFSR = SCB_DFSR_EXTERNAL_Msk | SCB_DFSR_VCATCH_Msk | |
borlanic | 0:02dd72d1d465 | 82 | SCB_DFSR_DWTTRAP_Msk | SCB_DFSR_BKPT_Msk | SCB_DFSR_HALTED_Msk; |
borlanic | 0:02dd72d1d465 | 83 | // SCB->MMFAR - Implementation defined value |
borlanic | 0:02dd72d1d465 | 84 | // SCB->BFAR - Implementation defined value |
borlanic | 0:02dd72d1d465 | 85 | // SCB->AFSR - Implementation defined value |
borlanic | 0:02dd72d1d465 | 86 | // SCB->PFR - Read only processor feature register |
borlanic | 0:02dd72d1d465 | 87 | // SCB->DFR - Read only debug feature registers |
borlanic | 0:02dd72d1d465 | 88 | // SCB->ADR - Read only auxiliary feature registers |
borlanic | 0:02dd72d1d465 | 89 | // SCB->MMFR - Read only memory model feature registers |
borlanic | 0:02dd72d1d465 | 90 | // SCB->ISAR - Read only instruction set attribute registers |
borlanic | 0:02dd72d1d465 | 91 | // SCB->CPACR - Implementation defined value |
borlanic | 0:02dd72d1d465 | 92 | } |
borlanic | 0:02dd72d1d465 | 93 | |
borlanic | 0:02dd72d1d465 | 94 | #if defined (__CC_ARM) |
borlanic | 0:02dd72d1d465 | 95 | |
borlanic | 0:02dd72d1d465 | 96 | __asm static void start_new_application(void *sp, void *pc) |
borlanic | 0:02dd72d1d465 | 97 | { |
borlanic | 0:02dd72d1d465 | 98 | MOV R2, #0 |
borlanic | 0:02dd72d1d465 | 99 | MSR CONTROL, R2 // Switch to main stack |
borlanic | 0:02dd72d1d465 | 100 | MOV SP, R0 |
borlanic | 0:02dd72d1d465 | 101 | MSR PRIMASK, R2 // Enable interrupts |
borlanic | 0:02dd72d1d465 | 102 | BX R1 |
borlanic | 0:02dd72d1d465 | 103 | } |
borlanic | 0:02dd72d1d465 | 104 | |
borlanic | 0:02dd72d1d465 | 105 | #elif defined (__GNUC__) || defined (__ICCARM__) |
borlanic | 0:02dd72d1d465 | 106 | |
borlanic | 0:02dd72d1d465 | 107 | void start_new_application(void *sp, void *pc) |
borlanic | 0:02dd72d1d465 | 108 | { |
borlanic | 0:02dd72d1d465 | 109 | __asm volatile ( |
borlanic | 0:02dd72d1d465 | 110 | "mov r2, #0 \n" |
borlanic | 0:02dd72d1d465 | 111 | "msr control, r2 \n" // Switch to main stack |
borlanic | 0:02dd72d1d465 | 112 | "mov sp, %0 \n" |
borlanic | 0:02dd72d1d465 | 113 | "msr primask, r2 \n" // Enable interrupts |
borlanic | 0:02dd72d1d465 | 114 | "bx %1 \n" |
borlanic | 0:02dd72d1d465 | 115 | : |
borlanic | 0:02dd72d1d465 | 116 | : "l" (sp), "l" (pc) |
borlanic | 0:02dd72d1d465 | 117 | : "r2", "cc", "memory" |
borlanic | 0:02dd72d1d465 | 118 | ); |
borlanic | 0:02dd72d1d465 | 119 | } |
borlanic | 0:02dd72d1d465 | 120 | |
borlanic | 0:02dd72d1d465 | 121 | #else |
borlanic | 0:02dd72d1d465 | 122 | |
borlanic | 0:02dd72d1d465 | 123 | #error "Unsupported toolchain" |
borlanic | 0:02dd72d1d465 | 124 | |
borlanic | 0:02dd72d1d465 | 125 | #endif |
borlanic | 0:02dd72d1d465 | 126 | |
borlanic | 0:02dd72d1d465 | 127 | #endif /* MBED_APPLICATION_SUPPORT */ |