Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
167:1657b442184c
project opencv 3.1 on GR PEACH board, no use SD card.

Who changed what in which revision?

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