1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
inline byte modeblockhi(byte mode) //Mode blocks when hi input?
{
return (mode==0)?1:0; //Only block with mode 0!
}
//Assume mode 2=6 and 3=7, mode 2/6 is equal to 3/7 except 3/7 decrements by 2 only when gate is high, none else.
HW82C54_STATUS status_82C54_handler[0x10000]; //All status handlers (word size)
inline byte getOperatingMode(byte channel) //Get a operating mode!
{
return ((Timer82C54.operatingmode[channel]&(0x3<<1))>>1); //What operating mode?
}
/*
Start of Status Handlers (Timer)
*/
void status_init(byte channel)
{
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_WAITFORRELOADSET; //All channels wait for the reload to be set!
}
void status_waitforreloadsetorcommandset(byte channel) //Wait for reload or command to be set!
{
if ((Timer82C54.channelstatus[channel]&CHANNELSTATUS_RELOADSET) || (Timer82C54.channelstatus[channel]&CHANNELSTATUS_COMMANDSET)) //Reload or command set?
{
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_WAITFORRELOADSETORCOMMANDSET; //Turn of reload/command wait!
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_RELOADSET; //Turn off reload set!
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_COMMANDSET; //Turn off command set!
}
}
/*
for waitforreloadset!
*/
void reloadset0(byte channel)
{
if (Timer82C54.signalrising==0) //Dropped?
{
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_RELOADSET; //Turn off reload set!
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_RUNNING; //Start running: we're loaded, so run!
Timer82C54.channelcount[channel] = Timer82C54.channelreloadvalue[channel]; //Load the reload value!
setOutput(channel,0); //Set output low!
}
else
{
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_WAITFORRELOADSET; //Try again later!
}
}
void reloadset1(byte channel)
{
if (Timer82C54.signalrising==0) //Dropped?
{
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_RELOADSET; //Turn off reload set!
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_RUNNING; //Start running: we're loaded, so run!
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_WAITFORGATEHIGH; //Wait for rising edge of gate!
setOutput(channel,0); //Set output low!
}
else
{
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_WAITFORRELOADSET; //Try again later!
}
}
void reloadset26(byte channel)
{
if (Timer82C54.signalrising==0) //Dropped?
{
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_RELOADSET; //Turn off reload set!
Timer82C54.channelcount[channel] = Timer82C54.channelreloadvalue[channel]; //Load the reload value!
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_RUNNING; //Start running: we're loaded, so run!
}
else
{
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_WAITFORRELOADSET; //Try again later!
}
}
void reloadset37(byte channel)
{
if (Timer82C54.signalrising==0) //Dropped?
{
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_RELOADSET; //Turn off reload set!
Timer82C54.channelcount[channel] = Timer82C54.channelreloadvalue[channel]; //Load the reload value!
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_RUNNING; //Start running: we're loaded, so run!
}
else
{
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_WAITFORRELOADSET; //Try again later!
}
}
void reloadset4(byte channel)
{
if (Timer82C54.signalrising==0) //Dropped?
{
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_RELOADSET; //Turn off reload set!
Timer82C54.channelcount[channel] = Timer82C54.channelreloadvalue[channel]; //Load the reload value!
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_RUNNING; //Start running: we're loaded, so run!
}
else
{
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_WAITFORRELOADSET; //Try again later!
}
}
void reloadset5(byte channel)
{
if (gatestatus(channel)==1) //Rised?
{
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_RELOADSET; //Turn off reload set!
Timer82C54.channelcount[channel] = Timer82C54.channelreloadvalue[channel]; //Load the reload value!
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_RUNNING; //Start running: we're loaded, so run!
}
else
{
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_WAITFORRELOADSET; //Try again later!
}
}
HW82C54_STATUS status_waitforreloadset_handlers[8] = {
reloadset0,
reloadset1,
reloadset26,
reloadset37,
reloadset4,
reloadset5,
reloadset26,
reloadset37
}; //All handlers for WAITFORRELOADSET!
void status_waitforreloadset(byte channel) //Wait for reload to be set!
{
//Waiting for load/reset!
if (Timer82C54.channelstatus[channel]&CHANNELSTATUS_RELOADSET) //Reload set?
{
Timer82C54.readbackstatus[channel] &= ~0x40; //We're loading the reload register!
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_WAITFORRELOADSET; //Turn of reload wait!
status_waitforreloadset_handlers[getOperatingMode(channel)](channel); //Execute handler for the reload!
}
}
/*
Rest of the handlers!
*/
void status_waitforgatehigh(byte channel) //Wait for gate to become high!
{
if (gatestatus(channel)==1) //Gotten high?
{
//Do something!
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_WAITFORGATEHIGH; //We've gotten high, turn option off!
switch (getOperatingMode(channel)) //What operating mode?
{
case 1:
setOutput(channel,0); //Set output low!
Timer82C54.channelcount[channel] = Timer82C54.channelreloadvalue[channel]; //Load the reload value!
break;
case 2:
case 6:
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_RUNNING; //Start running!
Timer82C54.channelcount[channel] = Timer82C54.channelreloadvalue[channel]; //Load the reload value!
break;
case 3:
case 7:
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_RUNNING; //Start running!
Timer82C54.channelcount[channel] = Timer82C54.channelreloadvalue[channel]; //Load the reload value!
break;
default: //Unknown?
break; //Do nothing!
}
}
}
void status_waitforgatelow(byte channel) //Wait for gate to become low!
{
if (!gatestatus(channel)) //Gotten low?
{
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_WAITFORGATELOW; //We've gotten low, turn option off!
}
}
void status_skipcycle(byte channel) //Skip a cycle!
{
if (getOperatingMode(channel)==4 || getOperatingMode(channel)==5) //Mode 4/5?
{
if (Timer82C54.signalrising==Timer82C54.skipcycle_last) //Skipped a cycle?
{
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_SKIPCYCLE; //We've skipped a cycle, turn option off!
setOutput(channel,1); //Set the output to high!
Timer82C54.channelstatus[channel] |= CHANNELSTATUS_DISABLED; //Disable the channel!
}
}
else //Invalid mode for this?
{
Timer82C54.channelstatus[channel] &= ~CHANNELSTATUS_SKIPCYCLE; //Turn option off!
status_82C54_handler[Timer82C54.channelstatus[channel]](channel); //Disabled skip cycle: run like a normal cycle!
}
}
|