2 **************************************************************************
3 * @file at32f435_437_misc.c
6 * @brief contains all the functions for the misc firmware library
7 **************************************************************************
8 * Copyright notice & Disclaimer
10 * The software Board Support Package (BSP) that is made available to
11 * download from Artery official website is the copyrighted work of Artery.
12 * Artery authorizes customers to use, copy, and distribute the BSP
13 * software and its related documentation for the purpose of design and
14 * development in conjunction with Artery microcontrollers. Use of the
15 * software is governed by this copyright notice and the following disclaimer.
17 * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
18 * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
19 * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
20 * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
21 * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
24 **************************************************************************
27 /* includes ------------------------------------------------------------------*/
28 #include "at32f435_437_conf.h"
30 /** @addtogroup AT32F435_437_periph_driver
35 * @brief MISC driver modules
39 #ifdef MISC_MODULE_ENABLED
41 /** @defgroup MISC_private_functions
45 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
52 void nvic_system_reset(void)
58 * @brief enable nvic irq
59 * @param irqn (IRQn_Type number)
60 * @param preempt_priority: preemptive priority value (starting from 0)
61 * @param sub_priority: subpriority value (starting from 0)
64 void nvic_irq_enable(IRQn_Type irqn
, uint32_t preempt_priority
, uint32_t sub_priority
)
66 uint32_t temp_priority
= 0;
69 temp_priority
= NVIC_EncodePriority(NVIC_GetPriorityGrouping(), preempt_priority
, sub_priority
);
71 NVIC_SetPriority(irqn
, temp_priority
);
77 * @brief disable nvic irq number
78 * @param irqn (IRQn_Type number)
81 void nvic_irq_disable(IRQn_Type irqn
)
83 NVIC_DisableIRQ(irqn
);
87 * @brief config nvic priority group
88 * @param priority_group
89 * this parameter can be one of the following values:
90 * - NVIC_PRIORITY_GROUP_0
91 * - NVIC_PRIORITY_GROUP_1
92 * - NVIC_PRIORITY_GROUP_2
93 * - NVIC_PRIORITY_GROUP_3
94 * - NVIC_PRIORITY_GROUP_4
97 void nvic_priority_group_config(nvic_priority_group_type priority_group
)
99 /* set the prigroup[10:8] bits according to nvic_prioritygroup value */
100 NVIC_SetPriorityGrouping(priority_group
);
104 * @brief set the vector table location and offset.
106 * this parameter can be one of the following values:
108 * - NVIC_VECTTAB_FLASH
109 * @param offset (vector table base offset field. this value must be a multiple of 0x200)
112 void nvic_vector_table_set(uint32_t base
, uint32_t offset
)
114 SCB
->VTOR
= base
| (offset
& (uint32_t)0x1FFFFF80);
118 * @brief config nvic lowpower mode
120 * this parameter can be one of the following values:
121 * - NVIC_LP_SEVONPEND
122 * - NVIC_LP_SLEEPDEEP
123 * - NVIC_LP_SLEEPONEXIT
124 * @param new_state (new state of lp condition. ENABLE or DISABLE)
127 void nvic_lowpower_mode_config(nvic_lowpower_mode_type lp_mode
, confirm_state new_state
)
129 if(new_state
!= FALSE
)
135 SCB
->SCR
&= (uint32_t)(~(uint32_t)lp_mode
);
140 * @brief config systick clock source
142 * this parameter can be one of the following values:
143 * - SYSTICK_CLOCK_SOURCE_AHBCLK_DIV8
144 * - SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV
147 void systick_clock_source_config(systick_clock_source_type source
)
149 if(source
== SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV
)
151 SysTick
->CTRL
|= SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV
;
155 SysTick
->CTRL
&= ~(uint32_t)SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV
;