123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- #include "gd32f30x_misc.h"
- void nvic_priority_group_set(uint32_t nvic_prigroup)
- {
-
- SCB->AIRCR = NVIC_AIRCR_VECTKEY_MASK | nvic_prigroup;
- }
- void nvic_irq_enable(uint8_t nvic_irq, uint8_t nvic_irq_pre_priority,
- uint8_t nvic_irq_sub_priority)
- {
- uint32_t temp_priority = 0x00U, temp_pre = 0x00U, temp_sub = 0x00U;
-
- if(((SCB->AIRCR) & (uint32_t)0x700U)==NVIC_PRIGROUP_PRE0_SUB4){
- temp_pre=0U;
- temp_sub=0x4U;
- }else if(((SCB->AIRCR) & (uint32_t)0x700U)==NVIC_PRIGROUP_PRE1_SUB3){
- temp_pre=1U;
- temp_sub=0x3U;
- }else if(((SCB->AIRCR) & (uint32_t)0x700U)==NVIC_PRIGROUP_PRE2_SUB2){
- temp_pre=2U;
- temp_sub=0x2U;
- }else if(((SCB->AIRCR) & (uint32_t)0x700U)==NVIC_PRIGROUP_PRE3_SUB1){
- temp_pre=3U;
- temp_sub=0x1U;
- }else if(((SCB->AIRCR) & (uint32_t)0x700U)==NVIC_PRIGROUP_PRE4_SUB0){
- temp_pre=4U;
- temp_sub=0x0U;
- }else{
- nvic_priority_group_set(NVIC_PRIGROUP_PRE2_SUB2);
- temp_pre=2U;
- temp_sub=0x2U;
- }
-
- temp_priority = (uint32_t)nvic_irq_pre_priority << (0x4U - temp_pre);
- temp_priority |= nvic_irq_sub_priority &(0x0FU >> (0x4U - temp_sub));
- temp_priority = temp_priority << 0x04U;
- NVIC->IP[nvic_irq] = (uint8_t)temp_priority;
-
- NVIC->ISER[nvic_irq >> 0x05U] = (uint32_t)0x01U << (nvic_irq & (uint8_t)0x1FU);
- }
- void nvic_irq_disable(uint8_t nvic_irq)
- {
-
- NVIC->ICER[nvic_irq >> 0x05] = (uint32_t)0x01 << (nvic_irq & (uint8_t)0x1F);
- }
- void nvic_vector_table_set(uint32_t nvic_vict_tab, uint32_t offset)
- {
- SCB->VTOR = nvic_vict_tab | (offset & NVIC_VECTTAB_OFFSET_MASK);
- __DSB();
- }
- void system_lowpower_set(uint8_t lowpower_mode)
- {
- SCB->SCR |= (uint32_t)lowpower_mode;
- }
- void system_lowpower_reset(uint8_t lowpower_mode)
- {
- SCB->SCR &= (~(uint32_t)lowpower_mode);
- }
- void systick_clksource_set(uint32_t systick_clksource)
- {
- if(SYSTICK_CLKSOURCE_HCLK == systick_clksource ){
-
- SysTick->CTRL |= SYSTICK_CLKSOURCE_HCLK;
- }else{
-
- SysTick->CTRL &= SYSTICK_CLKSOURCE_HCLK_DIV8;
- }
- }
|