1 /*!
2     \file    gd32l23x_misc.h
3     \brief   definitions for the MISC
4 
5     \version 2021-08-04, V1.0.0, firmware for GD32L23x
6 */
7 
8 /*
9     Redistribution and use in source and binary forms, with or without modification,
10 are permitted provided that the following conditions are met:
11 
12     1. Redistributions of source code must retain the above copyright notice, this
13        list of conditions and the following disclaimer.
14     2. Redistributions in binary form must reproduce the above copyright notice,
15        this list of conditions and the following disclaimer in the documentation
16        and/or other materials provided with the distribution.
17     3. Neither the name of the copyright holder nor the names of its contributors
18        may be used to endorse or promote products derived from this software without
19        specific prior written permission.
20 
21     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 OF SUCH DAMAGE.
31 */
32 
33 #ifndef GD32L23X_MISC_H
34 #define GD32L23X_MISC_H
35 
36 #include "gd32l23x.h"
37 
38 /* constants definitions */
39 /* set the RAM and FLASH base address */
40 #define NVIC_VECTTAB_RAM            ((uint32_t)0x20000000)                      /*!< RAM base address */
41 #define NVIC_VECTTAB_FLASH          ((uint32_t)0x08000000)                      /*!< Flash base address */
42 
43 /* set the NVIC vector table offset mask */
44 #define NVIC_VECTTAB_OFFSET_MASK    ((uint32_t)0x1FFFFF80)                      /*!< NVIC vector table offset mask */
45 
46 /* the register key mask, if you want to do the write operation, you should write 0x5FA to VECTKEY bits */
47 #define NVIC_AIRCR_VECTKEY_MASK     ((uint32_t)0x05FA0000)                      /*!< NVIC VECTKEY mask */
48 
49 /* choose the method to enter or exit the lowpower mode */
50 #define SCB_SCR_SLEEPONEXIT         ((uint8_t)0x02)                             /*!< choose the the system whether enter low power mode by exiting from ISR */
51 #define SCB_SCR_SLEEPDEEP           ((uint8_t)0x04)                             /*!< choose the the system enter the DEEPSLEEP mode or SLEEP mode */
52 #define SCB_SCR_SEVONPEND           ((uint8_t)0x10)                             /*!< choose the interrupt source that can wake up the lowpower mode */
53 
54 #define SCB_LPM_SLEEP_EXIT_ISR      SCB_SCR_SLEEPONEXIT                         /*!< low power mode by exiting from ISR */
55 #define SCB_LPM_DEEPSLEEP           SCB_SCR_SLEEPDEEP                           /*!< DEEPSLEEP mode or SLEEP mode */
56 #define SCB_LPM_WAKE_BY_ALL_INT     SCB_SCR_SEVONPEND                           /*!< wakeup by all interrupt */
57 
58 /* choose the systick clock source */
59 #define SYSTICK_CLKSOURCE_HCLK_DIV8 ((uint32_t)0xFFFFFFFBU)                     /*!< systick clock source is from HCLK/8 */
60 #define SYSTICK_CLKSOURCE_HCLK      ((uint32_t)0x00000004U)                     /*!< systick clock source is from HCLK */
61 
62 /* function declarations */
63 /* enable NVIC request */
64 void nvic_irq_enable(uint8_t nvic_irq, uint8_t nvic_irq_priority);
65 /* disable NVIC request */
66 void nvic_irq_disable(uint8_t nvic_irq);
67 /* initiates a system reset request to reset the MCU */
68 void nvic_system_reset(void);
69 
70 /* set the NVIC vector table base address */
71 void nvic_vector_table_set(uint32_t nvic_vict_tab, uint32_t offset);
72 
73 /* set the state of the low power mode */
74 void system_lowpower_set(uint8_t lowpower_mode);
75 /* reset the state of the low power mode */
76 void system_lowpower_reset(uint8_t lowpower_mode);
77 
78 /* set the systick clock source */
79 void systick_clksource_set(uint32_t systick_clksource);
80 
81 #endif /* gd32l23x_MISC_H */
82