元驭机器人元驭机器人Hall 传感器教学下载原文件
1/*!2    \file    systick.c3    \brief   the systick configuration file45    \version 2026-02-04, V2.5.0, firmware for GD32E23x6*/78/*9    Copyright (c) 2026, GigaDevice Semiconductor Inc.1011    Redistribution and use in source and binary forms, with or without modification,12are permitted provided that the following conditions are met:1314    1. Redistributions of source code must retain the above copyright notice, this15       list of conditions and the following disclaimer.16    2. Redistributions in binary form must reproduce the above copyright notice,17       this list of conditions and the following disclaimer in the documentation18       and/or other materials provided with the distribution.19    3. Neither the name of the copyright holder nor the names of its contributors20       may be used to endorse or promote products derived from this software without21       specific prior written permission.2223    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"24AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED25WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.26IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,27INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT28NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR29PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,30WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)31ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY32OF SUCH DAMAGE.33*/3435#include "gd32e23x.h"36#include "systick.h"3738volatile static uint32_t delay;39static volatile uint32_t s_tick_ms;4041/*!42    \brief      configure systick43    \param[in]  none44    \param[out] none45    \retval     none46*/47void systick_config(void)48{49    /* setup systick timer for 1000Hz interrupts */50    if(SysTick_Config(SystemCoreClock / 1000U)) {51        /* capture error */52        while(1) {53        }54    }55    /* configure the systick handler priority */56    NVIC_SetPriority(SysTick_IRQn, 0x00U);57}5859/*!60    \brief      delay a time in milliseconds61    \param[in]  count: count in milliseconds62    \param[out] none63    \retval     none64*/65void delay_1ms(uint32_t count)66{67    delay = count;6869    while(0U != delay) {70    }71}7273/*!74    \brief      delay decrement75    \param[in]  none76    \param[out] none77    \retval     none78*/79void delay_decrement(void)80{81    s_tick_ms++;82    if(0U != delay) {83        delay--;84    }85}8687/*!88    \brief      读毫秒计数89    \param[in]  none90    \param[out] none91    \retval     systick_config 之后经过的毫秒92*/93uint32_t systick_get_ms(void)94{95    return s_tick_ms;96}