/*******************************************************************************
* Project:      Amped'RF Bluetooth
* File name:    GKI_nvic.c
* Description:  NVIC abstraction layer
*
* Copyright (c) 2013 Amped'RF Inc., AR Technology  All rights reserved.
*******************************************************************************/
#include "SDK_Common.h"
#include "GKI_lib.h"



#if defined(STR32F10x)

u32 UART_Channel[2];

#elif defined(STR32F2xx)

u8  USART_Channel_IRQn[2] = {USART1_IRQn, USART2_IRQn};

#endif


/*******************************************************************************
* Function Name  : GKI_nvic_InitStruct
* Description    : Init NVIC structure
*******************************************************************************/
void GKI_nvic_InitStruct(tGKI_nvic_Init *s)
{
    memset(s, 0, sizeof(tGKI_nvic_Init));
}




/*******************************************************************************
* Function Name  : GKI_nvic_Init
* Description    : Init NVIC
*******************************************************************************/
void GKI_nvic_Init(tGKI_nvic_Init *s)
{
    NVIC_InitTypeDef NVIC_InitStruct;
    NVIC_InitStruct.NVIC_IRQChannel                     = s->NVIC_IRQChannel;
    NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority   = s->NVIC_IRQChannelPreemptionPriority;
    NVIC_InitStruct.NVIC_IRQChannelSubPriority          = s->NVIC_IRQChannelSubPriority;
    NVIC_InitStruct.NVIC_IRQChannelCmd                  = s->NVIC_IRQChannelCmd;
    NVIC_Init(&NVIC_InitStruct);
}


/*******************************************************************************
* Function Name  : Reset_NVIC
* Description    : Reset NVIC, Vectors, Priority group
*******************************************************************************/
void GKI_nvic_Reset(void)
{
#if defined(STR32F10x)
    NVIC_SETPRIMASK();
    NVIC_DeInit();                                      // Deinitialize NVIC
    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0);         // Vector = 0x08000000
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);     // Grp Priorities = 4
#endif
}





/*******************************************************************************
* Function Name  : Reset_NVIC
* Description    : Reset NVIC, Vectors, Priority group
*******************************************************************************/
void GKI_nvic_SetUartIsr(u16 u, u8 pri)
{
#if defined(STR32F10x)

    NVIC_InitTypeDef NVIC_InitStruct;
    NVIC_InitStruct.NVIC_IRQChannel = pUart->IRQChannel;
    NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = pUart->IRQPriority;
    NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStruct);

#elif defined(STR32F2xx)

    NVIC_InitTypeDef NVIC_InitStruct;
    NVIC_InitStruct.NVIC_IRQChannel = USART_Channel_IRQn[u];
    NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = pUart->IRQPriority;
    NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
    NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStruct);

    USART_ITConfig(UART[u], USART_IT_IDLE, ENABLE);

#endif
}


//--------------------------------------------------------------
//