ch32v20x_misc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : ch32v20x_misc.c
  3. * Author : WCH
  4. * Version : V1.0.0
  5. * Date : 2021/06/06
  6. * Description : This file provides all the miscellaneous firmware functions .
  7. *********************************************************************************
  8. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  9. * Attention: This software (modified or not) and binary are used for
  10. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  11. *******************************************************************************/
  12. #include "ch32v20x_misc.h"
  13. __IO uint32_t NVIC_Priority_Group = 0;
  14. /*********************************************************************
  15. * @fn NVIC_PriorityGroupConfig
  16. *
  17. * @brief Configures the priority grouping - pre-emption priority and subpriority.
  18. *
  19. * @param NVIC_PriorityGroup - specifies the priority grouping bits length.
  20. * NVIC_PriorityGroup_0 - 0 bits for pre-emption priority
  21. * 3 bits for subpriority
  22. * NVIC_PriorityGroup_1 - 1 bits for pre-emption priority
  23. * 2 bits for subpriority
  24. *
  25. * @return none
  26. */
  27. void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
  28. {
  29. NVIC_Priority_Group = NVIC_PriorityGroup;
  30. }
  31. /*********************************************************************
  32. * @fn NVIC_Init
  33. *
  34. * @brief Initializes the NVIC peripheral according to the specified parameters in
  35. * the NVIC_InitStruct.
  36. *
  37. * @param NVIC_InitStruct - pointer to a NVIC_InitTypeDef structure that contains the
  38. * configuration information for the specified NVIC peripheral.
  39. * interrupt nesting enable(CSR-0x804 bit1 = 1)
  40. * NVIC_IRQChannelPreemptionPriority - range from 0 to 1.
  41. * NVIC_IRQChannelSubPriority - range from 0 to 3.
  42. *
  43. * interrupt nesting disable(CSR-0x804 bit1 = 0)
  44. * NVIC_IRQChannelPreemptionPriority - range is 0.
  45. * NVIC_IRQChannelSubPriority - range from 0 to 7.
  46. *
  47. * @return none
  48. */
  49. void NVIC_Init(NVIC_InitTypeDef *NVIC_InitStruct)
  50. {
  51. #if (INTSYSCR_INEST == INTSYSCR_INEST_NoEN)
  52. if(NVIC_Priority_Group == NVIC_PriorityGroup_0)
  53. {
  54. NVIC_SetPriority(NVIC_InitStruct->NVIC_IRQChannel, NVIC_InitStruct->NVIC_IRQChannelSubPriority << 4);
  55. }
  56. #else
  57. if(NVIC_Priority_Group == NVIC_PriorityGroup_1)
  58. {
  59. if(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority == 1)
  60. {
  61. NVIC_SetPriority(NVIC_InitStruct->NVIC_IRQChannel, (1 << 7) | (NVIC_InitStruct->NVIC_IRQChannelSubPriority << 5));
  62. }
  63. else if(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority == 0)
  64. {
  65. NVIC_SetPriority(NVIC_InitStruct->NVIC_IRQChannel, (0 << 7) | (NVIC_InitStruct->NVIC_IRQChannelSubPriority << 5));
  66. }
  67. }
  68. #endif
  69. if(NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
  70. {
  71. NVIC_EnableIRQ(NVIC_InitStruct->NVIC_IRQChannel);
  72. }
  73. else
  74. {
  75. NVIC_DisableIRQ(NVIC_InitStruct->NVIC_IRQChannel);
  76. }
  77. }