📄 clp.c
字号:
/************************************************************************/
/* */
/* Copyright 1990 by Accelerated Technology */
/* */
/* PROPRIETARY RIGHTS of Accelerated Technology are involved in the */
/* subject matter of this material. All manufacturing, reproduction, */
/* use, and sales rights pertaining to this subject matter are */
/* governed by the license agreement. The buyer or recipient of this */
/* package, implicitly accepts the terms of the license. */
/* */
/************************************************************************/
/************************************************************************/
/* */
/* FILE DESCRIPTION */
/* */
/* This file contains routines that provide timer services to the */
/* executive and to application tasks. */
/* */
/* ROUTINES */
/* */
/* CLP_Initialize Clock Initialization */
/* CLP_Start_Timer Setup a task timer */
/* CLP_Stop_Timer Stop a task timer */
/* CLP_Timer_Expiration Timer expired */
/* */
/* NOTES */
/* */
/* None */
/* */
/************************************************************************/
/* Define necessary include files. */
#include "nu_defs.h" /* General constants */
#include "in_extr.h" /* Alloc and error routines */
#include "cl_defs.h" /* Data structure defns */
#include "cl_extr.h" /* Clock routine defns */
#include "sk_extr.h" /* Scheduler external refs */
/* Define global data structures to the clock routines. */
/* The pointer "CLP_TR_List" is used to point to the list of
sequentially allocated timer request structures. */
struct CL_TIMER_REQUEST_STRUCT *CLP_TR_List;
/* The pointer "CLP_Active_List_Ptr" is used to point to the chain of active
timer requests. If this pointer is NULL, there are no timers active. */
struct CL_TIMER_REQUEST_STRUCT *CLP_Active_List_Ptr;
/* The unsigned int "CLP_Timer_Request" contains a copy of the last value
entered into the timer. */
unsigned int CLP_Timer_Request;
/* The unsigned int "CLP_Total_Timers" contains the maximum number of timers
in the system. */
unsigned int CLP_Total_Timers;
/************************************************************************/
/* */
/* FUNCTION "CLP_Initialize" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function is used to allocate and initialize all of the */
/* timer request blocks necessary for the clock routines. */
/* Note that the scheduler initialization must run prior to */
/* this routine since the number of timers is based on the */
/* number of application tasks. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* INP_Initialize High level initialization */
/* */
/* ROUTINES CALLED */
/* */
/* INP_Memory_Alloc Allocate initial memory */
/* SKP_Maximum_Tasks Number of tasks in system */
/* CLD_Load_Clock Load system clock */
/* CLD_Load_Timer Load the timer */
/* CLD_Stop_System_Timer Stop the system timer */
/* */
/* INPUTS */
/* */
/* None */
/* */
/* OUTPUTS */
/* */
/* CLP_TR_List[] Timer request list */
/* CLP_Active_List_Ptr Active timer list pointer */
/* */
/************************************************************************/
void CLP_Initialize()
{
unsigned int bytes; /* Number of bytes required */
int i; /* Working variable */
/* Initialize the pointers to the active and inactive timer lists. */
CLP_Active_List_Ptr = NU_NULL;
/* Calculate the number of system timers. */
CLP_Total_Timers = SKP_Maximum_Tasks();
/* Allocate memory for all of the timer request structures. */
bytes = sizeof(struct CL_TIMER_REQUEST_STRUCT) * CLP_Total_Timers;
CLP_TR_List = (struct CL_TIMER_REQUEST_STRUCT *) INP_Memory_Alloc(bytes);
/* Set up the active list pointer. */
CLP_Active_List_Ptr = NU_NULL;
/* Loop through the list to initialize each timer request entry. */
for (i = 0; i < CLP_Total_Timers; i++)
{
/* Set up the timer ID for easy access later. */
CLP_TR_List[i].cl_timer_id = i;
/* Set up the timer request value. */
CLP_TR_List[i].cl_remaining = 0;
/* Set up pointers to other active entries. */
CLP_TR_List[i].cl_next = NU_NULL;
CLP_TR_List[i].cl_previous = NU_NULL;
}
/* Initialize the system clock. */
CLD_Load_Clock(0);
/* Initialize the timer clock. */
CLP_Timer_Request = 0;
/* Call the "CLD_Load_Timer" routine to setup the timer. */
CLD_Load_Timer(CLP_Timer_Request);
/* Call the "CLD_Stop_System_Timer" routine to insure the system timer
is not active. */
CLD_Stop_System_Timer();
} /* end of CLP_Initialize */
/************************************************************************/
/* */
/* FUNCTION "CLP_Start_Timer" */
/* */
/* */
/* DESCRIPTION */
/* */
/* This function places the selected timer on the ready list if */
/* it is not there already. If it is, the requested value is */
/* simply re-adjusted. It is assumed that interrupts are already */
/* locked out. */
/* */
/* AUTHOR */
/* */
/* William E. Lamie, Accelerated Technology */
/* */
/* CALLED FROM */
/* */
/* Task timeout suspension routines */
/* */
/* ROUTINES CALLED */
/* */
/* CLD_Read_Timer Read the timer */
/* CLD_Load_Timer Load the timer */
/* */
/* INPUTS */
/* */
/* timer_id Timer identification */
/* time Request time */
/* */
/* OUTPUTS */
/* */
/* Active timer list */
/* CLP_Timer_Request Copy of CLP_Timer */
/* */
/************************************************************************/
void CLP_Start_Timer(unsigned int timer_id, unsigned int time)
{
struct CL_TIMER_REQUEST_STRUCT *timer_ptr; /* Timer pointer */
unsigned int current_timer; /* Current timer */
/* Point to the timer id request structure. */
timer_ptr = &CLP_TR_List[timer_id];
/* Determine if this new pointer is already active. */
if ((timer_ptr -> cl_previous == NU_NULL) &&
(timer_ptr -> cl_next == NU_NULL) &&
(CLP_Active_List_Ptr != timer_ptr))
{
/* Place at the head. */
timer_ptr -> cl_next = CLP_Active_List_Ptr;
timer_ptr -> cl_previous = NU_NULL;
/* Check to see if any adjacent node needs to be updated. */
if (CLP_Active_List_Ptr)
CLP_Active_List_Ptr -> cl_previous = timer_ptr;
/* Update the active list pointer. */
CLP_Active_List_Ptr = timer_ptr;
}
/* Check for an active timer request. */
if (CLP_Timer_Request > 0)
{
/* Get the current value of the count down timer. */
current_timer = CLD_Read_Timer();
/* Update the time remaining field of this timer with the
difference between the last request and the actual timer
value. */
timer_ptr -> cl_remaining = time;
timer_ptr -> cl_ignore = CLP_Timer_Request - current_timer;
/* Check for the new timer being less than the current remaining
timer. */
if (current_timer > time)
{
/* Load a new value into the actual timer and update our
saved timer request to the amount of time that has
elapsed so far and the current time request. */
CLP_Timer_Request = (CLP_Timer_Request - current_timer) + time;
/* Load the new timer value. */
CLD_Load_Timer(time);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -