examples/mini/mini.c
changeset 2068 3001f6523e63
parent 2024 96e2ae6cce95
child 2089 adbf7900b848
equal deleted inserted replaced
2067:19732da2cf86 2068:3001f6523e63
   344 
   344 
   345     // write process data
   345     // write process data
   346     EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x06 : 0x09);
   346     EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x06 : 0x09);
   347 
   347 
   348     // send process data
   348     // send process data
   349     down(&master_sem);
       
   350     ecrt_domain_queue(domain1);
   349     ecrt_domain_queue(domain1);
       
   350     up(&master_sem);
   351     ecrt_master_send(master);
   351     ecrt_master_send(master);
   352     up(&master_sem);
       
   353 
   352 
   354     // restart timer
   353     // restart timer
   355     timer.expires += HZ / FREQUENCY;
   354     timer.expires += HZ / FREQUENCY;
   356     add_timer(&timer);
   355     add_timer(&timer);
   357 }
   356 }
   358 
   357 
   359 /*****************************************************************************/
   358 /*****************************************************************************/
   360 
   359 
   361 void send_callback(void *cb_data)
   360 void request_lock_callback(void *cb_data)
   362 {
   361 {
   363     ec_master_t *m = (ec_master_t *) cb_data;
   362     ec_master_t *m = (ec_master_t *) cb_data;
   364     down(&master_sem);
   363     down(&master_sem);
   365     ecrt_master_send_ext(m);
   364 }
   366     up(&master_sem);
   365 
   367 }
   366 /*****************************************************************************/
   368 
   367 
   369 /*****************************************************************************/
   368 void release_lock_callback(void *cb_data)
   370 
       
   371 void receive_callback(void *cb_data)
       
   372 {
   369 {
   373     ec_master_t *m = (ec_master_t *) cb_data;
   370     ec_master_t *m = (ec_master_t *) cb_data;
   374     down(&master_sem);
       
   375     ecrt_master_receive(m);
       
   376     up(&master_sem);
   371     up(&master_sem);
   377 }
   372 }
   378 
   373 
   379 /*****************************************************************************/
   374 /*****************************************************************************/
   380 
   375 
   396         printk(KERN_ERR PFX "Requesting master 0 failed.\n");
   391         printk(KERN_ERR PFX "Requesting master 0 failed.\n");
   397         goto out_return;
   392         goto out_return;
   398     }
   393     }
   399 
   394 
   400     sema_init(&master_sem, 1);
   395     sema_init(&master_sem, 1);
   401     ecrt_master_callbacks(master, send_callback, receive_callback, master);
   396     ecrt_master_callbacks(master, request_lock_callback, release_lock_callback, master);
   402 
   397 
   403     printk(KERN_INFO PFX "Registering domain...\n");
   398     printk(KERN_INFO PFX "Registering domain...\n");
   404     if (!(domain1 = ecrt_master_create_domain(master))) {
   399     if (!(domain1 = ecrt_master_create_domain(master))) {
   405         printk(KERN_ERR PFX "Domain creation failed!\n");
   400         printk(KERN_ERR PFX "Domain creation failed!\n");
   406         goto out_release_master;
   401         goto out_release_master;