Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
etherlabmaster
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue 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
ICS Control System Infrastructure
etherlabmaster
Commits
7e403e80
Commit
7e403e80
authored
17 years ago
by
Florian Pose
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned up mini module.
parent
78d27a08
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/mini/mini.c
+33
-25
33 additions, 25 deletions
examples/mini/mini.c
with
33 additions
and
25 deletions
examples/mini/mini.c
+
33
−
25
View file @
7e403e80
...
@@ -39,16 +39,16 @@
...
@@ -39,16 +39,16 @@
#include
"../../include/ecrt.h"
// EtherCAT realtime interface
#include
"../../include/ecrt.h"
// EtherCAT realtime interface
#include
"../../include/ecdb.h"
// EtherCAT slave database
#include
"../../include/ecdb.h"
// EtherCAT slave database
#define PFX "ec_mini: "
/*****************************************************************************/
// module parameters
#define FREQUENCY 100
#define FREQUENCY 100
#define CONFIGURE_MAPPING
#define CONFIGURE_MAPPING
#define EXTERNAL_MEMORY
#define EXTERNAL_MEMORY
/*****************************************************************************/
#define PFX "ec_mini: "
static
struct
timer_list
timer
;
/*****************************************************************************/
// EtherCAT
// EtherCAT
static
ec_master_t
*
master
=
NULL
;
static
ec_master_t
*
master
=
NULL
;
...
@@ -58,6 +58,27 @@ spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
...
@@ -58,6 +58,27 @@ spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
static
ec_domain_t
*
domain1
=
NULL
;
static
ec_domain_t
*
domain1
=
NULL
;
static
ec_domain_state_t
domain1_state
=
{};
static
ec_domain_state_t
domain1_state
=
{};
static
struct
timer_list
timer
;
static
unsigned
int
counter
=
0
;
/*****************************************************************************/
// process data
static
uint8_t
*
domain1_pd
;
// process data memory
static
unsigned
int
off_ana_in
;
// offsets for Pdo entries
static
unsigned
int
off_dig_out
;
static
unsigned
int
blink
=
0
;
const
static
ec_pdo_entry_reg_t
domain1_regs
[]
=
{
{
0
,
1
,
Beckhoff_EL3162
,
0x3101
,
2
,
&
off_ana_in
},
{
0
,
3
,
Beckhoff_EL2004
,
0x3001
,
1
,
&
off_dig_out
},
{}
};
/*****************************************************************************/
#ifdef CONFIGURE_MAPPING
#ifdef CONFIGURE_MAPPING
const
ec_pdo_entry_info_t
el3162_channel1
[]
=
{
const
ec_pdo_entry_info_t
el3162_channel1
[]
=
{
{
0x3101
,
1
,
8
},
// status
{
0x3101
,
1
,
8
},
// status
...
@@ -89,16 +110,6 @@ const ec_pdo_info_t el2004_mapping[] = {
...
@@ -89,16 +110,6 @@ const ec_pdo_info_t el2004_mapping[] = {
};
};
#endif
#endif
static
uint8_t
*
pd
;
/**< Process data. */
static
unsigned
int
off_ana_in
;
static
unsigned
int
off_dig_out
;
const
static
ec_pdo_entry_reg_t
domain1_regs
[]
=
{
{
0
,
1
,
Beckhoff_EL3162
,
0x3101
,
2
,
&
off_ana_in
},
{
0
,
3
,
Beckhoff_EL2004
,
0x3001
,
1
,
&
off_dig_out
},
{}
};
/*****************************************************************************/
/*****************************************************************************/
void
check_domain1_state
(
void
)
void
check_domain1_state
(
void
)
...
@@ -144,11 +155,8 @@ void check_master_state(void)
...
@@ -144,11 +155,8 @@ void check_master_state(void)
/*****************************************************************************/
/*****************************************************************************/
void
run
(
unsigned
long
data
)
void
cyclic_task
(
unsigned
long
data
)
{
{
static
unsigned
int
counter
=
0
;
static
unsigned
int
blink
=
0
;
// receive process data
// receive process data
spin_lock
(
&
master_lock
);
spin_lock
(
&
master_lock
);
ecrt_master_receive
(
master
);
ecrt_master_receive
(
master
);
...
@@ -171,7 +179,7 @@ void run(unsigned long data)
...
@@ -171,7 +179,7 @@ void run(unsigned long data)
}
}
// write process data
// write process data
EC_WRITE_U8
(
pd
+
off_dig_out
,
blink
?
0x0F
:
0x00
);
EC_WRITE_U8
(
domain1_
pd
+
off_dig_out
,
blink
?
0x0F
:
0x00
);
// send process data
// send process data
spin_lock
(
&
master_lock
);
spin_lock
(
&
master_lock
);
...
@@ -256,12 +264,12 @@ int __init init_mini_module(void)
...
@@ -256,12 +264,12 @@ int __init init_mini_module(void)
#ifdef EXTERNAL_MEMORY
#ifdef EXTERNAL_MEMORY
if
((
size
=
ecrt_domain_size
(
domain1
)))
{
if
((
size
=
ecrt_domain_size
(
domain1
)))
{
if
(
!
(
pd
=
(
uint8_t
*
)
kmalloc
(
size
,
GFP_KERNEL
)))
{
if
(
!
(
domain1_
pd
=
(
uint8_t
*
)
kmalloc
(
size
,
GFP_KERNEL
)))
{
printk
(
KERN_ERR
PFX
"Failed to allocate %u bytes of process data"
printk
(
KERN_ERR
PFX
"Failed to allocate %u bytes of process data"
" memory!
\n
"
,
size
);
" memory!
\n
"
,
size
);
goto
out_release_master
;
goto
out_release_master
;
}
}
ecrt_domain_external_memory
(
domain1
,
pd
);
ecrt_domain_external_memory
(
domain1
,
domain1_
pd
);
}
}
#endif
#endif
...
@@ -277,12 +285,12 @@ int __init init_mini_module(void)
...
@@ -277,12 +285,12 @@ int __init init_mini_module(void)
#ifndef EXTERNAL_MEMORY
#ifndef EXTERNAL_MEMORY
// Get internal process data for domain
// Get internal process data for domain
pd
=
ecrt_domain_data
(
domain1
);
domain1_
pd
=
ecrt_domain_data
(
domain1
);
#endif
#endif
printk
(
KERN_INFO
PFX
"Starting cyclic sample thread.
\n
"
);
printk
(
KERN_INFO
PFX
"Starting cyclic sample thread.
\n
"
);
init_timer
(
&
timer
);
init_timer
(
&
timer
);
timer
.
function
=
run
;
timer
.
function
=
cyclic_task
;
timer
.
expires
=
jiffies
+
10
;
timer
.
expires
=
jiffies
+
10
;
add_timer
(
&
timer
);
add_timer
(
&
timer
);
...
@@ -291,7 +299,7 @@ int __init init_mini_module(void)
...
@@ -291,7 +299,7 @@ int __init init_mini_module(void)
#ifdef EXTERNAL_MEMORY
#ifdef EXTERNAL_MEMORY
out_free_process_data:
out_free_process_data:
kfree
(
pd
);
kfree
(
domain1_
pd
);
#endif
#endif
out_release_master:
out_release_master:
printk
(
KERN_ERR
PFX
"Releasing master...
\n
"
);
printk
(
KERN_ERR
PFX
"Releasing master...
\n
"
);
...
@@ -310,7 +318,7 @@ void __exit cleanup_mini_module(void)
...
@@ -310,7 +318,7 @@ void __exit cleanup_mini_module(void)
del_timer_sync
(
&
timer
);
del_timer_sync
(
&
timer
);
#ifdef EXTERNAL_MEMORY
#ifdef EXTERNAL_MEMORY
kfree
(
pd
);
kfree
(
domain1_
pd
);
#endif
#endif
printk
(
KERN_INFO
PFX
"Releasing master...
\n
"
);
printk
(
KERN_INFO
PFX
"Releasing master...
\n
"
);
...
...
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