examples/mini/mini.c
changeset 280 35c99cdda518
parent 275 ba51285d4ef6
child 325 7833cf70c4f2
equal deleted inserted replaced
279:12f48c1cb143 280:35c99cdda518
    55 ec_domain_t *domain1 = NULL;
    55 ec_domain_t *domain1 = NULL;
    56 spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
    56 spinlock_t master_lock = SPIN_LOCK_UNLOCKED;
    57 
    57 
    58 // data fields
    58 // data fields
    59 //void *r_ssi_input, *r_ssi_status, *r_4102[3];
    59 //void *r_ssi_input, *r_ssi_status, *r_4102[3];
    60 void *r_kbus_in;
    60 void *r_kbus_in, *r_kbus_out;
    61 
    61 
    62 // channels
    62 // channels
    63 uint32_t k_pos;
    63 uint32_t k_pos;
    64 uint8_t k_stat;
    64 uint8_t k_stat;
    65 
    65 
    66 ec_field_init_t domain1_fields[] = {
    66 ec_field_init_t domain1_fields[] = {
    67     {&r_kbus_in, "0", "Beckhoff", "BK1120", "Inputs", 0},
    67     //{&r_kbus_out, "0", "Beckhoff", "BK1120", "Outputs", 0},
       
    68     //{&r_kbus_in,  "0", "Beckhoff", "BK1120", "Inputs",  0},
    68     {}
    69     {}
    69 };
    70 };
    70 
    71 
    71 /*****************************************************************************/
    72 /*****************************************************************************/
    72 
    73 
    73 void run(unsigned long data)
    74 void run(unsigned long data)
    74 {
    75 {
    75     static unsigned int counter = 0;
    76     static unsigned int counter = 0;
       
    77     unsigned int i;
    76 
    78 
    77     spin_lock(&master_lock);
    79     spin_lock(&master_lock);
    78 
    80 
    79 #ifdef ASYNC
    81 #ifdef ASYNC
    80     // receive
    82     // receive
   103     if (counter) {
   105     if (counter) {
   104         counter--;
   106         counter--;
   105     }
   107     }
   106     else {
   108     else {
   107         counter = FREQUENCY;
   109         counter = FREQUENCY;
   108         //printk(KERN_INFO "k_pos    = %i\n", k_pos);
   110         printk(KERN_INFO "input = ");
   109         //printk(KERN_INFO "k_stat   = 0x%02X\n", k_stat);
   111         for (i = 0; i < 22; i++) printk("%02X ", *((uint8_t *) r_kbus_in + i));
       
   112         printk("\n");
   110     }
   113     }
   111 
   114 
   112     // restart timer
   115     // restart timer
   113     timer.expires += HZ / FREQUENCY;
   116     timer.expires += HZ / FREQUENCY;
   114     add_timer(&timer);
   117     add_timer(&timer);
   161     printk(KERN_INFO "Setting variable data field sizes...\n");
   164     printk(KERN_INFO "Setting variable data field sizes...\n");
   162     if (!(slave = ecrt_master_get_slave(master, "0"))) {
   165     if (!(slave = ecrt_master_get_slave(master, "0"))) {
   163         printk(KERN_ERR "Failed to get slave!\n");
   166         printk(KERN_ERR "Failed to get slave!\n");
   164         goto out_deactivate;
   167         goto out_deactivate;
   165     }
   168     }
   166     ecrt_slave_field_size(slave, "Inputs", 0, 1);
   169     ecrt_slave_field_size(slave, "Outputs", 0, 0x16);
       
   170     ecrt_slave_field_size(slave, "Inputs", 0, 0x16);
   167 #endif
   171 #endif
   168 
   172 
   169     printk(KERN_INFO "Activating master...\n");
   173     printk(KERN_INFO "Activating master...\n");
   170     if (ecrt_master_activate(master)) {
   174     if (ecrt_master_activate(master)) {
   171         printk(KERN_ERR "Failed to activate master!\n");
   175         printk(KERN_ERR "Failed to activate master!\n");
   172         goto out_release_master;
   176         goto out_release_master;
   173     }
   177     }
   174 
   178 
   175 #if 0
   179 #if 1
   176     if (ecrt_master_fetch_sdo_lists(master)) {
   180     if (ecrt_master_fetch_sdo_lists(master)) {
   177         printk(KERN_ERR "Failed to fetch SDO lists!\n");
   181         printk(KERN_ERR "Failed to fetch SDO lists!\n");
   178         goto out_deactivate;
   182         goto out_deactivate;
   179     }
   183     }
   180     ecrt_master_print(master, 2);
   184     ecrt_master_print(master, 2);