Commit e471d053 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Optimization revisited.

parent 7b55edea
......@@ -79,30 +79,32 @@ static void calculate(struct controller_block *block)
{
struct controller_block_private *priv;
priv = block->private;
bool out;
bool set = INPUT(set);
bool reset = INPUT(reset);
uint32_t period = priv->period;
uint32_t ticks_left = priv->ticks_left;
uint32_t setmask = (uint32_t)0 - set;
uint32_t resetmask = (uint32_t)0 - reset;
/* set counter to period if set true */
ticks_left += (period - ticks_left) & setmask;
/* reset counter if reset true */
ticks_left -= ticks_left & resetmask;
/* if counter not zero output is true */
out = ticks_left;
/* decrement, but not below zero */
ticks_left -= ticks_left != 0;
if (INPUT(reset)) {
priv->ticks_left = 0;
OUTPUT(out) = false;
} else {
if (INPUT(set)) {
priv->ticks_left = priv->period;
OUTPUT(out) = true;
#ifdef DEBUG
if (OUTPUT(out) != out)
log_send(LOG_T_DEBUG, "%s: turned %s", block->name,
out ? "on" : "off");
log_send(LOG_T_DEBUG, "%s: turned on", block->name);
#endif
priv->ticks_left = ticks_left;
OUTPUT(out) = out;
} else {
uint32_t ticks_left;
ticks_left = priv->ticks_left;
if (ticks_left) {
ticks_left--;
priv->ticks_left = ticks_left;
OUTPUT(out) = ticks_left;
} else {
OUTPUT(out) = false;
}
}
}
}
static struct controller_block_interm_list interms[] = {
......@@ -180,8 +182,8 @@ static int param_set_force(struct controller_block *block, char *param,
}
static struct controller_block_param_list params[] = {
{ "period", false, param_set_period, .args = { "double", NULL } },
{ "force", false, param_set_force, .args = { "int", NULL } },
{ "period", true, param_set_period, .args = { "double", NULL } },
{ "force", true, param_set_force, .args = { "int", NULL } },
{ NULL },
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment