Morpheus / target-mcu-k64f

Fork of target-mcu-k64f by -deleted-

Committer:
screamer
Date:
Wed Mar 23 21:24:48 2016 +0000
Revision:
0:c5e2f793b59a
Initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
screamer 0:c5e2f793b59a 1 /* mbed Microcontroller Library
screamer 0:c5e2f793b59a 2 * CMSIS-style functionality to support dynamic vectors
screamer 0:c5e2f793b59a 3 *******************************************************************************
screamer 0:c5e2f793b59a 4 * Copyright (c) 2011 ARM Limited. All rights reserved.
screamer 0:c5e2f793b59a 5 * All rights reserved.
screamer 0:c5e2f793b59a 6 *
screamer 0:c5e2f793b59a 7 * Redistribution and use in source and binary forms, with or without
screamer 0:c5e2f793b59a 8 * modification, are permitted provided that the following conditions are met:
screamer 0:c5e2f793b59a 9 *
screamer 0:c5e2f793b59a 10 * 1. Redistributions of source code must retain the above copyright notice,
screamer 0:c5e2f793b59a 11 * this list of conditions and the following disclaimer.
screamer 0:c5e2f793b59a 12 * 2. Redistributions in binary form must reproduce the above copyright notice,
screamer 0:c5e2f793b59a 13 * this list of conditions and the following disclaimer in the documentation
screamer 0:c5e2f793b59a 14 * and/or other materials provided with the distribution.
screamer 0:c5e2f793b59a 15 * 3. Neither the name of ARM Limited nor the names of its contributors
screamer 0:c5e2f793b59a 16 * may be used to endorse or promote products derived from this software
screamer 0:c5e2f793b59a 17 * without specific prior written permission.
screamer 0:c5e2f793b59a 18 *
screamer 0:c5e2f793b59a 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
screamer 0:c5e2f793b59a 20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
screamer 0:c5e2f793b59a 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
screamer 0:c5e2f793b59a 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
screamer 0:c5e2f793b59a 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
screamer 0:c5e2f793b59a 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
screamer 0:c5e2f793b59a 25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
screamer 0:c5e2f793b59a 26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
screamer 0:c5e2f793b59a 27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
screamer 0:c5e2f793b59a 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
screamer 0:c5e2f793b59a 29 *******************************************************************************
screamer 0:c5e2f793b59a 30 */
screamer 0:c5e2f793b59a 31 #include "cmsis_nvic.h"
screamer 0:c5e2f793b59a 32
screamer 0:c5e2f793b59a 33 #define NVIC_RAM_VECTOR_ADDRESS (0x1FFF0000) // Vectors positioned at start of RAM
screamer 0:c5e2f793b59a 34 #define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash
screamer 0:c5e2f793b59a 35
screamer 0:c5e2f793b59a 36 void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
screamer 0:c5e2f793b59a 37 uint32_t *vectors = (uint32_t*)SCB->VTOR;
screamer 0:c5e2f793b59a 38 uint32_t i;
screamer 0:c5e2f793b59a 39
screamer 0:c5e2f793b59a 40 // Copy and switch to dynamic vectors if the first time called
screamer 0:c5e2f793b59a 41 if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) {
screamer 0:c5e2f793b59a 42 uint32_t *old_vectors = vectors;
screamer 0:c5e2f793b59a 43 vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS;
screamer 0:c5e2f793b59a 44 for (i=0; i<NVIC_NUM_VECTORS; i++) {
screamer 0:c5e2f793b59a 45 vectors[i] = old_vectors[i];
screamer 0:c5e2f793b59a 46 }
screamer 0:c5e2f793b59a 47 SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS;
screamer 0:c5e2f793b59a 48 }
screamer 0:c5e2f793b59a 49 vectors[IRQn + 16] = vector;
screamer 0:c5e2f793b59a 50 }
screamer 0:c5e2f793b59a 51
screamer 0:c5e2f793b59a 52 uint32_t NVIC_GetVector(IRQn_Type IRQn) {
screamer 0:c5e2f793b59a 53 uint32_t *vectors = (uint32_t*)SCB->VTOR;
screamer 0:c5e2f793b59a 54 return vectors[IRQn + 16];
screamer 0:c5e2f793b59a 55 }