systick.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*!
  2. \file systick.c
  3. \brief the systick configuration file
  4. \version 2014-12-26, V1.0.0, demo for GD32F10x
  5. \version 2017-06-30, V2.0.0, demo for GD32F10x
  6. \version 2021-04-30, V2.1.0, demo for GD32F10x
  7. */
  8. /*
  9. Copyright (c) 2021, GigaDevice Semiconductor Inc.
  10. Redistribution and use in source and binary forms, with or without modification,
  11. are permitted provided that the following conditions are met:
  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. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  29. OF SUCH DAMAGE.
  30. */
  31. #include "gd32f10x.h"
  32. #include "systick.h"
  33. volatile static uint32_t delay;
  34. /*!
  35. \brief configure systick
  36. \param[in] none
  37. \param[out] none
  38. \retval none
  39. */
  40. void systick_config(void)
  41. {
  42. /* setup systick timer for 1000Hz interrupts */
  43. if (SysTick_Config(SystemCoreClock / 1000U)){
  44. /* capture error */
  45. while(1){
  46. }
  47. }
  48. /* configure the systick handler priority */
  49. NVIC_SetPriority(SysTick_IRQn, 0x00U);
  50. //__ASM volatile("cpsie i");
  51. __set_PRIMASK(0);
  52. }
  53. /*!
  54. \brief delay a time in milliseconds
  55. \param[in] count: count in milliseconds
  56. \param[out] none
  57. \retval none
  58. */
  59. void delay_1ms(uint32_t count)
  60. {
  61. delay = count;
  62. while(0U != delay){
  63. }
  64. }
  65. /*!
  66. \brief delay decrement
  67. \param[in] none
  68. \param[out] none
  69. \retval none
  70. */
  71. void delay_decrement(void)
  72. {
  73. if(0U != delay){
  74. delay--;
  75. }
  76. }