Shorter critical sections in examples.
This commit is contained in:
parent
03c3e13bf9
commit
09a843f8a0
|
|
@ -32,7 +32,6 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/timer.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/interrupt.h>
|
||||
|
|
@ -73,35 +72,36 @@ ec_pdo_reg_t domain1_pdos[] = {
|
|||
void run(unsigned long data)
|
||||
{
|
||||
static unsigned int counter = 0;
|
||||
static unsigned int einaus = 0;
|
||||
|
||||
spin_lock(&master_lock);
|
||||
static unsigned int blink = 0;
|
||||
|
||||
// receive
|
||||
spin_lock(&master_lock);
|
||||
ecrt_master_receive(master);
|
||||
ecrt_domain_process(domain1);
|
||||
spin_unlock(&master_lock);
|
||||
|
||||
// process data
|
||||
//k_pos = EC_READ_U32(r_ssi);
|
||||
#ifdef KBUS
|
||||
EC_WRITE_U8(r_outputs + 2, einaus ? 0xFF : 0x00);
|
||||
#endif
|
||||
|
||||
// send
|
||||
ecrt_domain_queue(domain1);
|
||||
ecrt_master_run(master);
|
||||
ecrt_master_send(master);
|
||||
|
||||
spin_unlock(&master_lock);
|
||||
// k_pos = EC_READ_U32(r_ssi);
|
||||
|
||||
if (counter) {
|
||||
counter--;
|
||||
}
|
||||
else {
|
||||
counter = FREQUENCY;
|
||||
einaus = !einaus;
|
||||
blink = !blink;
|
||||
}
|
||||
|
||||
#ifdef KBUS
|
||||
EC_WRITE_U8(r_outputs + 2, blink ? 0xFF : 0x00);
|
||||
#endif
|
||||
|
||||
// send
|
||||
spin_lock(&master_lock);
|
||||
ecrt_domain_queue(domain1);
|
||||
ecrt_master_run(master);
|
||||
ecrt_master_send(master);
|
||||
spin_unlock(&master_lock);
|
||||
|
||||
// restart timer
|
||||
timer.expires += HZ / FREQUENCY;
|
||||
add_timer(&timer);
|
||||
|
|
@ -211,8 +211,8 @@ void __exit cleanup_mini_module(void)
|
|||
/*****************************************************************************/
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>");
|
||||
MODULE_DESCRIPTION ("EtherCAT minimal test environment");
|
||||
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
|
||||
MODULE_DESCRIPTION("EtherCAT minimal test environment");
|
||||
|
||||
module_init(init_mini_module);
|
||||
module_exit(cleanup_mini_module);
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ ec_domain_t *domain1 = NULL;
|
|||
// raw process data
|
||||
void *r_ana_out;
|
||||
|
||||
// Channels
|
||||
// channels
|
||||
double k_ana_out;
|
||||
|
||||
ec_pdo_reg_t domain1_pdos[] = {
|
||||
|
|
@ -78,20 +78,20 @@ ec_pdo_reg_t domain1_pdos[] = {
|
|||
|
||||
void msr_controller_run(void)
|
||||
{
|
||||
rt_sem_wait(&master_sem);
|
||||
|
||||
// receive
|
||||
rt_sem_wait(&master_sem);
|
||||
ecrt_master_receive(master);
|
||||
ecrt_domain_process(domain1);
|
||||
rt_sem_signal(&master_sem);
|
||||
|
||||
// Process data
|
||||
EC_WRITE_S16(r_ana_out, k_ana_out / 10.0 * 0x7FFF);
|
||||
|
||||
// Send
|
||||
rt_sem_wait(&master_sem);
|
||||
ecrt_domain_queue(domain1);
|
||||
ecrt_master_run(master);
|
||||
ecrt_master_send(master);
|
||||
|
||||
rt_sem_signal(&master_sem);
|
||||
|
||||
msr_write_kanal_list();
|
||||
|
|
@ -221,8 +221,8 @@ void __exit cleanup_mod(void)
|
|||
/*****************************************************************************/
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR ("Florian Pose <fp@igh-essen.com>");
|
||||
MODULE_DESCRIPTION ("EtherCAT RTAI MSR sample module");
|
||||
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
|
||||
MODULE_DESCRIPTION("EtherCAT RTAI MSR sample module");
|
||||
|
||||
module_init(init_mod);
|
||||
module_exit(cleanup_mod);
|
||||
|
|
|
|||
|
|
@ -46,12 +46,6 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
|
||||
MODULE_DESCRIPTION("EtherCAT RTAI sample module");
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
// RTAI task frequency in Hz
|
||||
#define FREQUENCY 10000
|
||||
#define INHIBIT_TIME 20
|
||||
|
|
@ -84,22 +78,23 @@ ec_pdo_reg_t domain1_pdos[] = {
|
|||
|
||||
void run(long data)
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
while (1) {
|
||||
t_last_cycle = get_cycles();
|
||||
rt_sem_wait(&master_sem);
|
||||
|
||||
rt_sem_wait(&master_sem);
|
||||
ecrt_master_receive(master);
|
||||
ecrt_domain_process(domain1);
|
||||
rt_sem_signal(&master_sem);
|
||||
|
||||
// process data
|
||||
//k_pos = EC_READ_U32(r_ssi_input);
|
||||
|
||||
rt_sem_wait(&master_sem);
|
||||
ecrt_domain_queue(domain1);
|
||||
ecrt_master_run(master);
|
||||
ecrt_master_send(master);
|
||||
|
||||
rt_sem_signal(&master_sem);
|
||||
|
||||
rt_task_wait_period();
|
||||
}
|
||||
}
|
||||
|
|
@ -108,7 +103,7 @@ void run(long data)
|
|||
|
||||
int request_lock(void *data)
|
||||
{
|
||||
// too close to the next RT cycle: deny access...
|
||||
// too close to the next real time cycle: deny access...
|
||||
if (get_cycles() - t_last_cycle > t_critical) return -1;
|
||||
|
||||
// allow access
|
||||
|
|
@ -142,7 +137,7 @@ int __init init_mod(void)
|
|||
|
||||
ecrt_master_callbacks(master, request_lock, release_lock, NULL);
|
||||
|
||||
printk(KERN_INFO "Registering domain...\n");
|
||||
printk(KERN_INFO "Creating domain...\n");
|
||||
if (!(domain1 = ecrt_master_create_domain(master))) {
|
||||
printk(KERN_ERR "Domain creation failed!\n");
|
||||
goto out_release_master;
|
||||
|
|
@ -207,8 +202,11 @@ void __exit cleanup_mod(void)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>");
|
||||
MODULE_DESCRIPTION("EtherCAT RTAI sample module");
|
||||
|
||||
module_init(init_mod);
|
||||
module_exit(cleanup_mod);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue