📄 ar_timer.c
字号:
/*----------------------------------------------------------------------------
* A R T X - K e r n e l
*----------------------------------------------------------------------------
* Name: AR_TIMER.C
* Purpose: User timer functions
* Rev.: V2.00 / 19-oct-2005
*----------------------------------------------------------------------------
* This code is part of the ARTX-ARM kernel package of Keil Software.
* Copyright (c) 2004-2005 Keil Software. All rights reserved.
*---------------------------------------------------------------------------*/
#include "Kernel\ARTX_Config.h"
/* ARTX_Config.c */
extern struct OS_XTMR os_tmr;
/* Mapping of API-type to internal type */
#define p_TMR ((P_TMR)timer)
/*----------------------------------------------------------------------------
* Functions
*---------------------------------------------------------------------------*/
/*--------------------------- os_tmr_tick -----------------------------------*/
void os_tmr_tick (void) {
/* Decrement delta count of timer list head. Timers having the value of */
/* zero are removed from the list and the callback function is called. */
P_TMR p;
if (os_tmr.next == NULL) {
return;
}
os_tmr.tcnt--;
while (os_tmr.tcnt == 0 && (p = os_tmr.next) != NULL) {
/* Call a user provided function to handle an ellapsed timer */
os_tmr_call (p->info);
os_tmr.tcnt = p->tcnt;
os_tmr.next = p->next;
os_free_TMR (p);
}
} /* end of os_tmr_tick */
/*--------------------------- os_tmr_create ---------------------------------*/
OS_ID os_tmr_create (U16 tcnt, U16 info) {
/* Create an user timer and put it into the chained timer list using */
/* a timeout count value of "tcnt". User parameter "info" is used as a */
/* parameter for the user provided callback function "os_tmr_call ()". */
P_TMR p_tmr, p;
U32 delta,itcnt = tcnt;
if (!tcnt) {
return (NULL);
}
p_tmr = os_alloc_TMR ();
if (!p_tmr) {
return (NULL);
}
p_tmr->info = info;
p = (P_TMR)&os_tmr;
tsk_lock ();
delta = p->tcnt;
while (delta < itcnt && p->next != NULL) {
p = p->next;
delta += p->tcnt;
}
/* Right place found, insert timer into the list */
p_tmr->next = p->next;
p_tmr->tcnt = (U16)(delta - itcnt);
p->next = p_tmr;
p->tcnt -= p_tmr->tcnt;
tsk_unlock ();
return (p_tmr);
} /* end of os_tmr_create */
/*--------------------------- os_tmr_kill -----------------------------------*/
OS_ID os_tmr_kill (OS_ID timer) {
/* Remove user timer from the chained timer list. */
P_TMR p;
p = (P_TMR)&os_tmr;
tsk_lock ();
/* Search timer list for requested timer */
while (p->next != timer) {
if (p->next == NULL) {
/* Failed, "timer" is not in the timer list */
tsk_unlock ();
return (timer);
}
p = p->next;
}
/* Timer was found, remove it from the list */
p->next = p_TMR->next;
p->tcnt += p_TMR->tcnt;
os_free_TMR (timer);
/* Timer killed */
tsk_unlock ();
return (NULL);
} /* end of os_tmr_kill */
/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -