Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Tammo Jan Dijkema
dt_ctrl
Commits
e471d053
Commit
e471d053
authored
Jan 30, 2015
by
Jeroen Vreeken
Browse files
Optimization revisited.
parent
7b55edea
Changes
1
Hide whitespace changes
Inline
Side-by-side
controller/block/block_oneshot.c
View file @
e471d053
...
...
@@ -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"
,
fals
e
,
param_set_period
,
.
args
=
{
"double"
,
NULL
}
},
{
"force"
,
fals
e
,
param_set_force
,
.
args
=
{
"int"
,
NULL
}
},
{
"period"
,
tru
e
,
param_set_period
,
.
args
=
{
"double"
,
NULL
}
},
{
"force"
,
tru
e
,
param_set_force
,
.
args
=
{
"int"
,
NULL
}
},
{
NULL
},
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment