Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
moberg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Blomdell
moberg
Commits
a5def94f
Commit
a5def94f
authored
6 years ago
by
Anders Blomdell
Browse files
Options
Downloads
Patches
Plain Diff
Clean up unused devices after channel install
parent
25d5b846
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
moberg.c
+19
-13
19 additions, 13 deletions
moberg.c
moberg_channel.h
+67
-0
67 additions, 0 deletions
moberg_channel.h
moberg_config.c
+15
-0
15 additions, 0 deletions
moberg_config.c
moberg_device.c
+8
-0
8 additions, 0 deletions
moberg_device.c
moberg_device.h
+2
-0
2 additions, 0 deletions
moberg_device.h
with
111 additions
and
13 deletions
moberg.c
+
19
−
13
View file @
a5def94f
...
...
@@ -14,12 +14,6 @@
#include
<moberg_config.h>
#include
<moberg_parser.h>
static
struct
deferred_action
{
struct
deferred_action
*
next
;
int
(
*
action
)(
void
*
param
);
void
*
param
;
}
*
deferred_action
=
NULL
;
struct
moberg
{
struct
moberg_config
*
config
;
struct
channel_list
{
...
...
@@ -28,6 +22,23 @@ struct moberg {
}
analog_in
,
analog_out
,
digital_in
,
digital_out
,
encoder_in
;
};
static
struct
deferred_action
{
struct
deferred_action
*
next
;
int
(
*
action
)(
void
*
param
);
void
*
param
;
}
*
deferred_action
=
NULL
;
static
void
run_deferred_actions
()
{
while
(
deferred_action
)
{
fprintf
(
stderr
,
"RUNNING deferred
\n
"
);
struct
deferred_action
*
deferred
=
deferred_action
;
deferred_action
=
deferred_action
->
next
;
deferred
->
action
(
deferred
->
param
);
free
(
deferred
);
}
}
static
int
channel_list_set
(
struct
channel_list
*
list
,
int
index
,
struct
moberg_channel
*
value
)
...
...
@@ -253,6 +264,7 @@ struct moberg *moberg_new(
/* Parse environment overrides */
}
install_config
(
result
);
run_deferred_actions
();
err:
return
result
;
...
...
@@ -269,13 +281,7 @@ void moberg_free(struct moberg *moberg)
channel_list_free
(
&
moberg
->
encoder_in
);
free
(
moberg
);
}
while
(
deferred_action
)
{
fprintf
(
stderr
,
"RUNNING deferred
\n
"
);
struct
deferred_action
*
deferred
=
deferred_action
;
deferred_action
=
deferred_action
->
next
;
deferred
->
action
(
deferred
->
param
);
free
(
deferred
);
}
run_deferred_actions
();
}
enum
moberg_status
moberg_start
(
...
...
This diff is collapsed.
Click to expand it.
moberg_channel.h
0 → 100644
+
67
−
0
View file @
a5def94f
#ifndef __MOBERG_CHANNEL_H__
#define __MOBERG_CHANNEL_H__
#include
<moberg.h>
enum
moberg_channel_kind
{
chan_ANALOGIN
,
chan_ANALOGOUT
,
chan_DIGITALIN
,
chan_DIGITALOUT
,
chan_ENCODERIN
};
struct
moberg_channel
{
struct
moberg_channel_context
*
context
;
/* Use-count of channel, when it reaches zero, channel will be free'd */
int
(
*
up
)(
struct
moberg_channel
*
channel
);
int
(
*
down
)(
struct
moberg_channel
*
channel
);
/* Channel open and close */
int
(
*
open
)(
struct
moberg_channel
*
channel
);
int
(
*
close
)(
struct
moberg_channel
*
channel
);
/* I/O operations */
enum
moberg_channel_kind
kind
;
union
moberg_channel_action
{
struct
{
struct
moberg_channel_analog_in
*
context
;
int
(
*
read
)(
struct
moberg_channel_analog_in
*
,
double
*
value
);
}
analog_in
;
struct
{
struct
moberg_channel_analog_out
*
context
;
int
(
*
write
)(
struct
moberg_channel_context
*
,
double
value
);
}
analog_out
;
struct
{
struct
moberg_channel_digital_in
*
context
;
int
(
*
read
)(
struct
moberg_channel_context
*
,
int
*
value
);
}
digital_in
;
struct
{
struct
moberg_channel_digital_out
*
context
;
int
(
*
write
)(
struct
moberg_channel_context
*
,
int
value
);
}
digital_out
;
struct
{
struct
moberg_channel_encoder_in
*
context
;
int
(
*
read
)(
struct
moberg_channel_context
*
,
long
*
value
);
}
encoder_in
;
}
action
;
};
struct
moberg_channel_map
{
struct
moberg_device
*
device
;
int
(
*
map
)(
struct
moberg_device
*
device
,
struct
moberg_channel
*
channel
);
};
struct
moberg_channel_install
{
struct
moberg
*
context
;
int
(
*
channel
)(
struct
moberg
*
context
,
int
index
,
struct
moberg_device
*
device
,
struct
moberg_channel
*
channel
);
};
#endif
This diff is collapsed.
Click to expand it.
moberg_config.c
+
15
−
0
View file @
a5def94f
...
...
@@ -76,6 +76,21 @@ int moberg_config_install_channels(struct moberg_config *config,
for
(
struct
device_entry
*
d
=
config
->
device_head
;
d
;
d
=
d
->
next
)
{
result
&=
moberg_device_install_channels
(
d
->
device
,
install
);
}
struct
device_entry
*
device
=
config
->
device_head
;
struct
device_entry
**
previous
=
&
config
->
device_head
;
while
(
device
)
{
struct
device_entry
*
next
=
device
->
next
;
if
(
moberg_device_in_use
(
device
->
device
))
{
previous
=
&
device
->
next
;
}
else
{
fprintf
(
stderr
,
"FREE
\n
"
);
moberg_device_free
(
device
->
device
);
free
(
device
);
*
previous
=
next
;
}
device
=
next
;
}
return
result
;
}
...
...
This diff is collapsed.
Click to expand it.
moberg_device.c
+
8
−
0
View file @
a5def94f
...
...
@@ -90,6 +90,14 @@ void moberg_device_free(struct moberg_device *device)
free
(
device
);
}
int
moberg_device_in_use
(
struct
moberg_device
*
device
)
{
device
->
driver
.
up
(
device
->
device_context
);
int
use
=
device
->
driver
.
down
(
device
->
device_context
);
fprintf
(
stderr
,
"IN_USE: %d
\n
"
,
use
);
return
use
>
1
;
}
int
moberg_device_parse_config
(
struct
moberg_device
*
device
,
struct
moberg_parser_context
*
parser
)
{
...
...
This diff is collapsed.
Click to expand it.
moberg_device.h
+
2
−
0
View file @
a5def94f
...
...
@@ -35,6 +35,8 @@ struct moberg_device *moberg_device_new(const char *driver);
void
moberg_device_free
(
struct
moberg_device
*
device
);
int
moberg_device_in_use
(
struct
moberg_device
*
device
);
int
moberg_device_parse_config
(
struct
moberg_device
*
device
,
struct
moberg_parser_context
*
context
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment