home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
progmisc
/
ad12.zip
/
ANLGOUT.AD
< prev
next >
Wrap
Text File
|
1990-03-07
|
3KB
|
92 lines
┌ * Analog output to flight simulator
│
│ * Outputs to analog channels are placed on output queue as
│ * they occur. Periodically, pending outputs are removed from
│ * the queue by analogOut and sent to the appropriate channel.
│ * Calls to enqueue and output are asynconronous.
│
│ * Operations supported
│ * analogOut data to analog channels
│ * aOut output value v to analog channel c
│ * enQueAnalogOut put output on queue
│ * deQueAnalogOut get output from queue
│ * initQueAnalogOut initialize output que
│
│ ┌ * Data structures and other declarations
│ │
│ │ #include "defines.h"
│ │ #include "declars.h"
│ │
│ │ * MaxQue MUST BE AN EXACT POWER OF 2
│ │ #define MaxQue 512
│ │ #define Wrap MaxQue - 1
│ │
│ │ /* queue of output control structure pointers */
│ │ static struct analogOutCtrl *aOutQueue[MaxQue];
│ │
│ │ static int nextTail = 0; /* next queue input location */
│ │ static int nextHead = 0; /* next queue output location */
│ │
│ │ extern int outputPending;
│ │ extern int timeOut;
│ │ extern struct analogOutCtrl anlgOutTable[NumAnalogOut];
│ └
│
│ ┌ * Functions
│ │
│ │ * Loop over pending transactions and output them
│ │ ┌ int analogOut() {
│ │ │ struct analogOutCtrl *oc;
│ │ │
│ │ │ ╔ For (i = 0; i< 1; i++)
│ │ │ ║ initAnalog(i);
│ │ │ ╚
│ │ │
│ │ │ * loop over all data in the aOutQueue structure
│ │ │ ╔ While ((oc = deQueAnalogOut()) !- (struct outCtrl *) Empty)
│ │ │ ║ dtoa(oc->channel, oc->word, oc->board);
│ │ │ ╚
│ │ │
│ │ │ return (timeOut ? Pending : !Pending);
│ │ └ }
│ │
│ │ * Output value v to analog channel c
│ │ ┌ aOut(int c, int v) {
│ │ │ anlgOutTable[c].word = v;
│ │ │ enQueAnalogOut(&anlgOutTable[c]);
│ │ └ }
│ │
│ │ * Put output on queue
│ │ ┌ int enQueAnalogOut(struct analogOutCtrl *obj) {
│ │ │ * return if queue full
│ │ │ ╒ If (((nextTail + 1) & Wrap) == nextHead)
│ │ │ │ return (Full);
│ │ │ └
│ │ │ * not full, add item to queue
│ │ │ aOutQueue[nextTail++] = obj;
│ │ │ nextTail &= Wrap;
│ │ │ return (NotFull);
│ │ └ }
│ │
│ │ * Get output from queue
│ │ ┌ struct analogOutCtrl * deQueAnalogOut() {
│ │ │
│ │ │ ╒ if (nextTail == nextHead)
│ │ │ │ * return if queue empty
│ │ │ │ return ((struct analogOutCtrl *) Empty);
│ │ │ └
│ │ │ obj = aOutQueue[nextHead++]; * fnx to execute
│ │ │ nextHead &= Wrap;
│ │ │ return (obj);
│ │ └ }
│ │
│ │ * initialize output queue
│ │ ┌ void initQueAnalogOut() {
│ │ │ nextTail = 0;
│ │ │ nextHead = 0;
│ │ └ }
│ │
│ └
│
└