System Tick设置

[复制链接]
查看366 | 回复1 | 2022-4-6 17:13:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区

您需要 登录 才可以下载或查看,没有账号?立即注册

×
const static S_TICK_FUNC  cs_ScmFunc =
{
    .Init    = TickInit,
    .TimerMs = TickTimerMs,
    .DelayMs = TickDelayMs,
    .DelayUs = TickDelayUs,
    .Delay   = TickDelay,
};

/* Public variables ----------------------------------------------------------*/
S_TICK_HANDLE  Tick =
{
    .c_pScmFunc = &cs_ScmFunc,
};


/* Private functions ---------------------------------------------------------*/
/**
*  @brief    TickInit
*  @param    None
*  @return   None
*  @details  Interrupt for 50us.
**/
static void TickInit(void)
{
    if (SysTick_Config(SystemCoreClock / 20000))
    {
        while (1);
    }
    else{}
   
    NVIC_SetPriority(SysTick_IRQn, 0x00);
}

/**
*  @brief    TickTimerMs
*  @param    None
*  @return   None
*  @details  None
**/
static uint32_t TickTimerMs(uint32_t *pwTime, const uint32_t wMaskBit)
{
    if (*pwTime)
    {
        if (READ_BIT(Tick.ScmParam.wEvent, wMaskBit))
        {
            CLR_BIT(Tick.ScmParam.wEvent, wMaskBit);
            if (!(-- *pwTime))
            {
                return (true);
            }
            else{}
        }
        else{}
       }
    else{}

    return (false);
}

/**
*  @brief    TickDelayMs
*  @param    None
*  @return   None
*  @details  None
**/
static void TickDelayMs(uint32_t wTime)
{
    while (1)
    {
        if (TickTimerMs(&wTime, TICK_EVENT_PUBLIC))
        {
            return;
        }
        else{}
    }
}

/**
*  @brief    TickDelayUs
*  @param    None
*  @return   None
*  @details  None
**/
static void TickDelayUs(const uint32_t wTime)
{
    uint32_t  wStartCnt = SysTick->VAL;
    uint32_t  wStopCnt  = 0;
    uint32_t  wDeltaCnt = wTime * 72 - 1;
   
   
    while (1)
    {
        wStopCnt = SysTick->VAL;
        
        if ((wStartCnt - wStopCnt) > wDeltaCnt)
        {
            return;
        }
        else{}
    }
}

/**
*  @brief    TickDelay
*  @param    None
*  @return   None
*  @details  None
**/
static void TickDelay(volatile uint32_t wTime)
{
    while (wTime --);
}
回复

使用道具 举报

weiziushi | 2022-4-7 09:03:46 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则