tao_z
2022-05-29 a7c0d42a6590c26d37c17b082aef52925b466569
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
  ******************************************************************************
  * @file     xl_uart.c
  * @author   Kirk
  * @version  4.5.2
  * @date     Fri Mar 26 17:29:12 2021
  * @brief    This file provide function about NVIC firmware progreamme 
  ******************************************************************************
  * @attention
  *
  * 2019 by Chipways Communications,Inc. All Rights Reserved.
  * This software is supplied under the terms of a license
  * agreement or non-disclosure agreement with Chipways.
  * Passing on and copying of this document,and communication
  * of its contents is not permitted without prior written
  * authorization.
  *
  * <h2><center>&copy; COPYRIGHT 2019 Chipways</center></h2>
  ******************************************************************************
  */
 
#if defined(__cplusplus)
extern "C" {
#endif /* __cplusplus */
 
/* Includes ---------------------------------------------------------------*/
#include "xl_nvic.h"
 
 
/** @addtogroup XL6600_StdPeriph_Driver
  * @{
  */
 
/** @defgroup NVIC NVIC Module 
  * @brief NVIC Driver Modules Library
  * @{
  */
 
/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/    
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
 
/** @defgroup NVIC_Private_Functions
  * @{
 */ 
 
 /**
 * @brief  ÅäÖÃÓÅÏȼ¶·Ö×é:ÏÈÕ¼ÓÅÏȼ¶ºÍ×ÓÓÅÏȼ¶.
 * @param  NVIC_PriorityGroup: Ö¸¶¨ÓÅÏȼ¶·Ö×é볤¶È.
 *        Õâ¸ö²ÎÊý¿ÉÒÔΪÒÔÏÂÖµ:
 *     @arg NVIC_PriorityGroup_0: ÇÀÕ¼ÓÅÏȼ¶0λ
 *                                ×ÓÓÅÏȼ¶2λ
 *     @arg NVIC_PriorityGroup_1: ÏÈÕ¼ÓÅÏȼ¶1λ
 *                                ÇÀÓÅÏȼ¶1λ
 *     @arg NVIC_PriorityGroup_2: ÏÈÕ¼ÓÅÏȼ¶2λ
 *                                ÇÀÓÅÏȼ¶0λ
 * @retval None
 */
void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
{
    /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
    SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
}
 
/**
 * @brief  ¸ù¾ÝÔÚ NVIC_InitStructÖÐÖ¸¶¨²ÎÊý³õʼ»¯NVICÍâÉè.
 * @param  NVIC_InitStruct: Ö¸Ïò°üº¬Ö¸¶¨NVICÍâÉèÅäÖÃÐÅÏ¢µÄNVIC_InitTypeDef½á¹¹.
 * @retval None
 */
void NVIC_Init(const NVIC_InitTypeDef* NVIC_InitStruct)
{
    uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
 
    if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
    {
        /* Compute the Corresponding IRQ Priority --------------------------------*/    
        tmppriority = ((uint32_t)0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> (uint8_t)0x08;
        tmppre = ((uint32_t)0x4 - tmppriority);
        tmpsub = tmpsub >> tmppriority;
 
        tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
        tmppriority |=  NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
        tmppriority = tmppriority << 0x04;
            
        NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = (uint8_t)tmppriority;
 
        /* Enable the Selected IRQ Channels --------------------------------------*/
        NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
          (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
    }
    else
    {
        /* Disable the Selected IRQ Channels -------------------------------------*/
        NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
          (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
    }
}
 
/**
 * @brief  ÉèÖÃʸÁ¿±íµÄλÖÃºÍÆ«ÒÆ.
 * @param  NVIC_VectTab: Ö¸¶¨Ê¸Á¿±íÊÇ·ñÔÚROM»òÉÁ´æÖÐ.
 *        Õâ¸ö²ÎÊý¿ÉÒÔΪÒÔÏÂÖµ:
 *     @arg NVIC_VectTab_RAM
 *     @arg NVIC_VectTab_FLASH
 * @param  Offset: Ê¸Á¿±í»ùÓÚÆ«ÒÆ×Ö¶Î,¸ÃÖµ±ØÐëÊÇ 0x200µÄ±¶Êý.
 * @retval None
 */
void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
    SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
}
 
/**
 * @brief  Ñ¡Ôñϵͳ½øÈëµÍ¹¦ÂÊģʽµÄÌõ¼þ.
 * @param  LowPowerMode: ÎªÏµÍ³Ö¸¶¨½øÈëµÍ¹¦ÂÊģʽµÄеÄģʽ.
 *        Õâ¸ö²ÎÊý¿ÉÒÔΪÒÔÏÂÖµ:
 *     @arg NVIC_LP_SEVONPEND
 *     @arg NVIC_LP_SLEEPDEEP
 *     @arg NVIC_LP_SLEEPONEXIT
 * @param  NewState: µÍѹ״̬µÄÐÂ״̬.
 *        Õâ¸ö²ÎÊý¿ÉÒÔΪÒÔÏÂÖµ:
 *     @arg ENABLE
 *     @arg DISABLE    
 * @retval None
 */
void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
{
    if (NewState != DISABLE)
    {
        SCB->SCR |= LowPowerMode;
    }
    else
    {
        SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
    }
}
 
/**
 * @brief  ÅäÖÃSysTickʱÖÓÔ´.
 * @param  SysTick_CLKSource: Ö¸¶¨SysTickʱÖÓÔ´.
 *        Õâ¸ö²ÎÊý¿ÉÒÔΪÒÔÏÂÖµ:
 *     @arg SysTick_CLKSource_HCLK_Div8: Ñ¡ÔñAHBʱÖÓ³ýÒÔ8×÷ΪϵͳʱÖÓÔ´.
 *     @arg SysTick_CLKSource_HCLK: Ñ¡ÔñAHBʱÖÓ×÷ΪϵͳʱÖÓÔ´.
 * @retval None
 */
void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
{
    if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
    {
        SysTick->CTRL |= (uint32_t)SysTick_CLKSource_HCLK;
    }
    else
    {
        SysTick->CTRL &= (uint32_t)SysTick_CLKSource_HCLK_Div8;
    }
}
 
 
 
 
 
/**
  * @}
  */
 
/**
  * @}
  */
 
/**
  * @}
  */
#ifdef __cplusplus
}
#endif /* __cplusplus */