gd32f10x_misc.h 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*!
  2. \file gd32f10x_misc.h
  3. \brief definitions for the MISC
  4. \version 2014-12-26, V1.0.0, firmware for GD32F10x
  5. \version 2017-06-20, V2.0.0, firmware for GD32F10x
  6. \version 2018-07-31, V2.1.0, firmware for GD32F10x
  7. \version 2020-09-30, V2.2.0, firmware for GD32F10x
  8. */
  9. /*
  10. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  11. Redistribution and use in source and binary forms, with or without modification,
  12. are permitted provided that the following conditions are met:
  13. 1. Redistributions of source code must retain the above copyright notice, this
  14. list of conditions and the following disclaimer.
  15. 2. Redistributions in binary form must reproduce the above copyright notice,
  16. this list of conditions and the following disclaimer in the documentation
  17. and/or other materials provided with the distribution.
  18. 3. Neither the name of the copyright holder nor the names of its contributors
  19. may be used to endorse or promote products derived from this software without
  20. specific prior written permission.
  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. #ifndef GD32F10X_MISC_H
  33. #define GD32F10X_MISC_H
  34. #include "gd32f10x.h"
  35. /* constants definitions */
  36. /* set the RAM and FLASH base address */
  37. #define NVIC_VECTTAB_RAM ((uint32_t)0x20000000) /*!< RAM base address */
  38. #define NVIC_VECTTAB_FLASH ((uint32_t)0x08000000) /*!< Flash base address */
  39. /* set the NVIC vector table offset mask */
  40. #define NVIC_VECTTAB_OFFSET_MASK ((uint32_t)0x1FFFFF80)
  41. /* the register key mask, if you want to do the write operation, you should write 0x5FA to VECTKEY bits */
  42. #define NVIC_AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
  43. /* priority group - define the pre-emption priority and the subpriority */
  44. #define NVIC_PRIGROUP_PRE0_SUB4 ((uint32_t)0x700) /*!< 0 bits for pre-emption priority 4 bits for subpriority */
  45. #define NVIC_PRIGROUP_PRE1_SUB3 ((uint32_t)0x600) /*!< 1 bits for pre-emption priority 3 bits for subpriority */
  46. #define NVIC_PRIGROUP_PRE2_SUB2 ((uint32_t)0x500) /*!< 2 bits for pre-emption priority 2 bits for subpriority */
  47. #define NVIC_PRIGROUP_PRE3_SUB1 ((uint32_t)0x400) /*!< 3 bits for pre-emption priority 1 bits for subpriority */
  48. #define NVIC_PRIGROUP_PRE4_SUB0 ((uint32_t)0x300) /*!< 4 bits for pre-emption priority 0 bits for subpriority */
  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. #define SCB_LPM_SLEEP_EXIT_ISR SCB_SCR_SLEEPONEXIT
  54. #define SCB_LPM_DEEPSLEEP SCB_SCR_SLEEPDEEP
  55. #define SCB_LPM_WAKE_BY_ALL_INT SCB_SCR_SEVONPEND
  56. /* choose the systick clock source */
  57. #define SYSTICK_CLKSOURCE_HCLK_DIV8 ((uint32_t)0xFFFFFFFBU) /*!< systick clock source is from HCLK/8 */
  58. #define SYSTICK_CLKSOURCE_HCLK ((uint32_t)0x00000004U) /*!< systick clock source is from HCLK */
  59. /* function declarations */
  60. /* set the priority group */
  61. void nvic_priority_group_set(uint32_t nvic_prigroup);
  62. /* enable NVIC request */
  63. void nvic_irq_enable(uint8_t nvic_irq, uint8_t nvic_irq_pre_priority, uint8_t nvic_irq_sub_priority);
  64. /* disable NVIC request */
  65. void nvic_irq_disable(uint8_t nvic_irq);
  66. /* set the NVIC vector table base address */
  67. void nvic_vector_table_set(uint32_t nvic_vict_tab, uint32_t offset);
  68. /* set the state of the low power mode */
  69. void system_lowpower_set(uint8_t lowpower_mode);
  70. /* reset the state of the low power mode */
  71. void system_lowpower_reset(uint8_t lowpower_mode);
  72. /* set the systick clock source */
  73. void systick_clksource_set(uint32_t systick_clksource);
  74. #endif /* GD32F10X_MISC_H */