Example #1
0
/**********************************************************************
 *
 * Method:      remove()
 *
 * Description: Remove a timer from the timer list.
 *
 * Notes:       This routine disables interrupts.
 * 
 * Returns:     A pointer to the removed timer, NULL if it wasn't
 *              found in the timer list.
 *
 **********************************************************************/
Timer *
TimerList::remove(Timer * pTimer)
{
    Timer **  ppPrev = &this->pTop;


    enterCS();

    //
    // Walk down the linked list until the dead timer is found.
    //
    while (*ppPrev != NULL && *ppPrev != pTimer)
    {
        ppPrev = &(*ppPrev)->pNext;
    }

    //
    // Remove the dead timer from the linked list.
    //
    if (*ppPrev != NULL)
    {
        *ppPrev = pTimer->pNext;
        (*ppPrev)->count += pTimer->count;
    }

    exitCS();

    return (*ppPrev);

}   /* remove() */
Example #2
0
/**********************************************************************
 *
 * Method:      insert()
 *
 * Description: Insert a timer into an ordered linked list.
 *
 * Notes:       This routine disables interrupts.
 * 
 * Returns:     None defined.
 *
 **********************************************************************/
void
TimerList::insert(Timer * pTimer)
{
    Timer **  ppPrev = &this->pTop;


    enterCS();

    //
    // Initialize the new timer's tick count.
    //
    pTimer->count = pTimer->length;

    //
    // Walk down the timer list, subtracting ticks as we go.
    //
    while (*ppPrev != NULL && pTimer->count >= (*ppPrev)->count)
    {
        pTimer->count -= (*ppPrev)->count;
        ppPrev = &(*ppPrev)->pNext;
    }
    
    // 
    // Insert the new timer at this point in the timer list.
    //
    pTimer->pNext = *ppPrev;
    *ppPrev = pTimer;
  
    //
    // Adjust the tick count of the next timer (if any).
    //
    if (pTimer->pNext != NULL)
    {
        pTimer->pNext->count -= pTimer->count;
    } 

    exitCS();

}   /* insert() */
Example #3
0
File: stat.c Project: doniexun/rtos
main() {
    int i;
    int tid;

    /* for stat */
    int IdleMem; /* idle task memeory address pData */
    unsigned int maxCnt;
    int memIdle;
    unsigned int idleCnt;
    int zero=0;
    int usage;
    unsigned long sum= 0;

    unsigned int upTime = 0;

    /*int loopCnt = 4;*/
    int loopCnt = 2;
    
    cprintf("Initializing .... ");
    /* get absolute data memory address of TID */
    IdleMem = GetAbsMem(IdleTaskTID);

    tid = Receive(&memIdle,sizeof(int));

    Reply(tid,NULL,NULL);
    /* wait until system reaches the stable state */
    Delay(TICKS_PER_SEC * 2);

    for(i = 0; i < loopCnt ; i++ ) {
	enterCS();
	/* reset the counter */
	absZero(IdleMem + memIdle, sizeof(int));
	exitCS();

	Delay(TICKS_PER_SEC * 1);

	/* get the maximum counter */
	enterCS();
	absRead(IdleMem + memIdle, &maxCnt, sizeof(int));
	exitCS();
	sum += maxCnt;
    } /* for */

    maxCnt = (int) sum / loopCnt;

/* if you don't want stat just undef this */
#ifdef DO_STAT
	console_xy(118,4);
	cprintf("Max:%x",maxCnt);

/* delete the initialzing message */
	console_xy(0,0);
	cprintf("                      ");
	console_xy(90,5);
	cprintf("Uptime:");

    while(1){
	enterCS();
	/* reset the counter */
	absZero(IdleMem + memIdle, sizeof(int));
	exitCS();

	Delay(TICKS_PER_SEC * 1);

	enterCS();
	/* read the number */
	absRead(IdleMem + memIdle, &idleCnt, sizeof(int));
	exitCS();

	if(maxCnt > 100 ) {
	    usage = (int)(100L - 100L * idleCnt / maxCnt);
	    if (usage > 100) {
		usage = 100;
	    } else if (usage < 0) {
		usage =   0;
	    }
	}
	else {
	    usage = 0;
	}

	console_xy(101,4);
	cprintf("%2d %% Idl:%x",usage, idleCnt);

	upTime = UpTime();
	console_xy(116,3);
	cprintf("%d",upTime);
	/*WakeUp(INIT_TID);*/

	/* XXX this is repitittion but ... */
	console_xy(118,4);
	cprintf("Max:%x",maxCnt);
    }
#endif /* DO_STAT */

    Exit();
}