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