home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
programs
/
system
/
idleled
/
idle_led.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-02-27
|
3KB
|
99 lines
/*
Program: Idle Led
Version: 1.0a 7/7/93
Author: Lindsay Meek (meek@fizzy.csu.murdoch.edu.au)
Description: Whenever the CPU is busy, the power led goes on else it is off.
It operates using timerA on CIAB. This is continuosly reset
by the idle task running at low priority (-127). When the
idle task is preempted by anything, the timer is allowed to
underflow causing the interrupt server to run which turns on
the power light. Next time the idle task runs, it immediately
turns off the power light.
Modifying the timer reload value below will change the
responsiveness of the led to the changes in CPU load.
*/
/* I think this is about 10 ms */
#define TIMER_DELAY 7000
#include <exec/nodes.h>
#include <exec/tasks.h>
#include <exec/interrupts.h>
#include <hardware/cia.h>
#include <libraries/dos.h>
#include <resources/cia.h>
struct Task *FindTask(char *);
/* CIA resource calls */
struct MiscResource;
long AbleICR(struct MiscResource *resource, long mask);
struct Interrupt *AddICRVector(struct MiscResource *resource, long iCRBit, struct Interrupt *interrupt);
void RemICRVector(struct MiscResource *resource, long iCRBit, struct Interrupt *interrupt);
long SetICR(struct MiscResource *resource, long mask);
struct MiscResource *OpenResource(char *);
struct MiscResource *ciabase=NULL;
IdleIrq(void)
{
/* Turn on power light */
ciaa.ciapra &= -1-CIAF_LED;
return 0; /* Set Z flag so other servers will execute */
}
/* Run this as a process. It aborts when it detects a CTRL_C signal */
main(int argc,char **argv)
{
struct Task *met;
BYTE oldpri;
struct Interrupt mei;
if(NULL==(ciabase=OpenResource(CIABNAME)))
{ printf("Couldn't aquire %s\n",CIABNAME); exit(1); }
mei.is_Node.ln_Type = NT_INTERRUPT;
mei.is_Node.ln_Pri = 127;
mei.is_Node.ln_Name = "Idle-Led-Off";
mei.is_Data = NULL;
mei.is_Code = IdleIrq;
AddICRVector(ciabase,CIAICRB_TA,&mei); /* Install IRQ server */
met=FindTask(NULL); /* Fetch this tcb */
oldpri=met->tc_Node.ln_Pri; /* Save old priority */
met->tc_Node.ln_Pri=-127; /* Make priority VERY low for idle */
ciab.ciacra = 0; /* Stop timer */
ciab.ciatalo = TIMER_DELAY & 0xff;
ciab.ciatahi = TIMER_DELAY >> 8; /* Load up timer delay */
SetICR(ciabase,CIAICRF_TA | CIAICRF_SETCLR); /* Enable IRQ */
/* Busy loop for eating idle cpu cycles */
while((met->tc_SigRecvd & SIGBREAKF_CTRL_C)==0) /* Abort on CTRL_C */
{
/* Reset timer. Started with force load and one-shot */
ciab.ciacra = CIACRAF_START | CIACRAF_LOAD | CIACRAF_RUNMODE;
/* Turn off power light */
ciaa.ciapra |= CIAF_LED;
}
ciab.ciacra = 0; /* Stop timer */
SetICR(ciabase,CIAICRF_TA); /* Disable interrupt */
RemICRVector(ciabase,CIAICRB_TA,&mei); /* Remove IRQ server */
met->tc_Node.ln_Pri=oldpri; /* Change priority back */
return 0;
}