1 /*!
2 \file systick.c
3 \brief the systick configuration file
4
5 \version 2016-08-15, V1.0.0, demo for GD32F4xx
6 \version 2018-12-12, V2.0.0, demo for GD32F4xx
7 */
8
9 /*
10 Copyright (c) 2018 GigaDevice Semiconductor Inc.
11
12 Redistribution and use in source and binary forms, with or without modification,
13 are permitted provided that the following conditions are met:
14
15 1. Redistributions of source code must retain the above copyright notice, this
16 list of conditions and the following disclaimer.
17 2. Redistributions in binary form must reproduce the above copyright notice,
18 this list of conditions and the following disclaimer in the documentation
19 and/or other materials provided with the distribution.
20 3. Neither the name of the copyright holder nor the names of its contributors
21 may be used to endorse or promote products derived from this software without
22 specific prior written permission.
23
24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
28 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33 OF SUCH DAMAGE.
34 */
35
36 #include "gd32f4xx.h"
37 #include "gd32f4xx_systick.h"
38
39 #define TICK_FOR_1000_HZ 1000U
40 volatile static uint32_t delay = 1;
41
42 /*!
43 \brief configure systick
44 \param[in] none
45 \param[out] none
46 \retval none
47 */
Gd32f4xxSystickConfig(void)48 void Gd32f4xxSystickConfig(void)
49 {
50 /* setup systick timer for 1000Hz interrupts */
51 if (SysTick_Config(SystemCoreClock / TICK_FOR_1000_HZ)) {
52 /* capture error */
53 while (1) { }
54 }
55 /* configure the systick handler priority */
56 NVIC_SetPriority(SysTick_IRQn, 0x00U);
57 }
58
59 /*!
60 \brief delay a time in milliseconds
61 \param[in] count: count in milliseconds
62 \param[out] none
63 \retval none
64 */
Gd32f4xxDelay1ms(uint32_t count)65 void Gd32f4xxDelay1ms(uint32_t count)
66 {
67 delay = count;
68
69 while (delay != 0U) { }
70 }
71
72 /*!
73 \brief delay decrement
74 \param[in] none
75 \param[out] none
76 \retval none
77 */
Gd32f4xxDelayDecrement(void)78 void Gd32f4xxDelayDecrement(void)
79 {
80 if (delay != 0U) {
81 delay--;
82 }
83 }
84