📄 tmc.c
字号:
TMD_Active_Timers_List = timer;
/* Setup the actual count-down timer structures. */
TMD_Timer_Start = time;
timer -> tm_remaining_time = time;
/* BUG FIX FOR NU_RESET WITH INITIAL TIME OF 0 */
/* Determine if there is any time remaining on the timer.
If so, enable the timer. Otherwise, the Timer HISR is
already pending, so skip starting the timer again. */
if (time != 0)
/* Start the actual count-down timer. */
TMT_Enable_Timer(TMD_Timer_Start);
else
TMD_Timer_State = TM_EXPIRED;
}
else
{
/* Place the new timer into the list. */
/* Pickup the head of the list. */
list_ptr = TMD_Active_Timers_List;
/* Determine if the timer is being added while the timer
expiration task is running. If so, don't attempt to adjust
the expiration list. If not, adjust the list. */
if (!TMD_Active_List_Busy)
{
/* Calculate the elapsed amount of time from the last timer
request. */
elapsed = TMD_Timer_Start - TMT_Read_Timer();
/* Adjust the first entry in the timer list and the timer
start value accordingly. */
TMD_Timer_Start = TMD_Timer_Start - elapsed;
/* Make sure the remaining time is never below zero. */
if (list_ptr -> tm_remaining_time > elapsed)
{
list_ptr -> tm_remaining_time = list_ptr -> tm_remaining_time
- elapsed;
}
else
{
list_ptr -> tm_remaining_time = 0;
}
}
/* At this point the timer list is accurate again. Find the
appropriate place on the timer list for the new timer. */
/* Determine where to place the timer in the list. */
done = NU_FALSE;
do
{
/* Determine if the timer belongs before the current timer
pointed to by list_ptr. */
if (time < list_ptr -> tm_remaining_time)
{
/* Update the time of the next timer. */
list_ptr -> tm_remaining_time =
list_ptr -> tm_remaining_time - time;
/* Determine if an insertion at the head of the list is
present. */
if (list_ptr == TMD_Active_Timers_List)
/* Move the list head to the new timer. */
TMD_Active_Timers_List = timer;
/* Set the done flag to end the search. */
done = NU_TRUE;
}
else
{
/* Decrement the time by the remaining value of each timer in
the list. In this way, the list never has to be searched
again. */
time = time - list_ptr -> tm_remaining_time;
/* Move the list pointer to the next timer in the list. */
list_ptr = list_ptr -> tm_next_timer;
/* Check to see if the list has wrapped around. */
if (list_ptr == TMD_Active_Timers_List)
/* Searching is done. */
done = NU_TRUE;
}
} while (!done);
/* Link the new timer into the list. */
timer -> tm_next_timer = list_ptr;
timer -> tm_previous_timer = list_ptr -> tm_previous_timer;
(list_ptr -> tm_previous_timer) -> tm_next_timer = timer;
list_ptr -> tm_previous_timer = timer;
/* Update the remaining time parameter. */
timer -> tm_remaining_time = time;
/* Determine if a new timer should be started. */
if (!TMD_Active_List_Busy)
{
/* Calculate the new timer expiration. */
time = TMD_Active_Timers_List -> tm_remaining_time;
/* Determine if the new expiration is less than the current
time, if any. If not, let already started time expire. */
if (time <= TMD_Timer_Start)
{
/* Setup for a smaller timer expiration. */
TMD_Timer_Start = time;
/* Determine if there is any time remaining on the timer in
the front of the list. If so, adjust the timer.
Otherwise, the Timer HISR is already pending, so skip
starting the timer again. */
if (TMD_Timer_Start)
/* Still some remaining time, adjust the timer. */
TMT_Adjust_Timer(TMD_Timer_Start);
else
/* Indicate that the task and application timer has
expired. */
TMD_Timer_State = TM_EXPIRED;
}
}
}
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* TMC_Stop_Timer */
/* */
/* DESCRIPTION */
/* */
/* This function is responsible for stopping both application and */
/* task timers. This routine must be called from Supervisor mode */
/* in a Supervisor/User mode switching kernel. */
/* */
/* CALLED BY */
/* */
/* TMC_Control_Timer Control application timer */
/* TMC_Stop_Task_Timer Start task timer */
/* */
/* CALLS */
/* */
/* TMT_Disable_Timer Disable the count-down timer */
/* */
/* INPUTS */
/* */
/* timer Timer control block pointer */
/* */
/* OUTPUTS */
/* */
/* None */
/* */
/*************************************************************************/
VOID TMC_Stop_Timer(TM_TCB *timer)
{
/* Note that the active timer list is already under protection. */
/* If the next neighbor of the timer that needs to be stopped is not the
head of the timer list, add the remaining time field to the remaining
time of the next neighbor. */
if ((timer -> tm_next_timer) != TMD_Active_Timers_List)
/* Adjust the next neighbor's remaining time field. */
(timer -> tm_next_timer) -> tm_remaining_time =
(timer -> tm_next_timer) -> tm_remaining_time +
timer -> tm_remaining_time;
/* Unlink the timer from the active list. */
if (timer -> tm_next_timer == timer)
{
/* Only timer on the list. */
TMD_Active_Timers_List = NU_NULL;
/* Disable the timer. */
TMT_Disable_Timer();
}
else
{
/* More than one timer on the list. */
(timer -> tm_previous_timer) -> tm_next_timer = timer -> tm_next_timer;
(timer -> tm_next_timer) -> tm_previous_timer =
timer -> tm_previous_timer;
/* Determine if the timer is at the head of the list. */
if (TMD_Active_Timers_List == timer)
/* Yes, move the head pointer to the next timer. */
TMD_Active_Timers_List = timer -> tm_next_timer;
}
/* Clear the timer's next and previous pointers. */
timer -> tm_next_timer = NU_NULL;
timer -> tm_previous_timer = NU_NULL;
}
/*************************************************************************/
/* */
/* FUNCTION */
/* */
/* TMC_Timer_HISR */
/* */
/* DESCRIPTION */
/* */
/* This function is responsible for High-Level interrupt processing */
/* of a timer expiration. If an application timer has expired, */
/* the timer expiration function is called. Otherwise, if the */
/* time-slice timer has expired, time-slice processing is invoked. */
/* */
/* CALLED BY */
/* */
/* None */
/* */
/* CALLS */
/* */
/* TCC_Time_Slice Task time-slice processing */
/* TMC_Timer_Expiration Timer expiration processing */
/* TMT_Retrieve_TS_Task Retrieve time-sliced task ptr*/
/* */
/* INPUTS */
/* */
/* None */
/* */
/* OUTPUTS */
/* */
/* None */
/* */
/*************************************************************************/
VOID TMC_Timer_HISR(VOID)
{
NU_TASK *task; /* Time slice task. */
/* Determine if the task timer has expired. */
if (TMD_Timer_State == TM_EXPIRED)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -