]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4XX/cmsis_nvic.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_STM / TARGET_STM32F4XX / cmsis_nvic.c
1 /* mbed Microcontroller Library - cmsis_nvic for STM32F4
2  * Copyright (c) 2009-2011 ARM Limited. All rights reserved.
3  *
4  * CMSIS-style functionality to support dynamic vectors
5  */ 
6 #include "cmsis_nvic.h"
7
8 #define NVIC_RAM_VECTOR_ADDRESS   (0x20000000)  // Location of vectors in RAM
9
10 static unsigned char vtor_relocated;
11
12 void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
13     uint32_t *vectors = (uint32_t*)SCB->VTOR;
14     uint32_t i;
15
16     // Copy and switch to dynamic vectors if the first time called
17     if (!vtor_relocated) {
18         uint32_t *old_vectors = vectors;
19         vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS;
20         for (i=0; i<NVIC_NUM_VECTORS; i++) {
21             vectors[i] = old_vectors[i];
22         }
23         SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS;
24         vtor_relocated = 1;
25     }
26     vectors[IRQn + 16] = vector;
27 }
28
29 uint32_t NVIC_GetVector(IRQn_Type IRQn) {
30     uint32_t *vectors = (uint32_t*)SCB->VTOR;
31     return vectors[IRQn + 16];
32 }
33