examples/mini/mini.c
branchstable-1.0
changeset 1621 4bbe090553f7
parent 1619 0d4119024f55
equal deleted inserted replaced
1620:9d7453c16ade 1621:4bbe090553f7
    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, *r_kbus_out;
    60 
    61 
    61 // channels
    62 // channels
    62 uint32_t k_pos;
    63 uint32_t k_pos;
    63 uint8_t k_stat;
    64 uint8_t k_stat;
    64 
    65 
    65 ec_field_init_t domain1_fields[] = {
    66 ec_field_init_t domain1_fields[] = {
    66     {NULL, "3", "Beckhoff", "EL5001", "InputValue",   0},
    67     //{&r_kbus_out, "0", "Beckhoff", "BK1120", "Outputs", 0},
    67     {NULL, "2", "Beckhoff", "EL4132", "OutputValue",  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);
   131 
   134 
   132 /*****************************************************************************/
   135 /*****************************************************************************/
   133 
   136 
   134 int __init init_mini_module(void)
   137 int __init init_mini_module(void)
   135 {
   138 {
       
   139     ec_slave_t *slave;
       
   140 
   136     printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
   141     printk(KERN_INFO "=== Starting Minimal EtherCAT environment... ===\n");
   137 
   142 
   138     if ((master = ecrt_request_master(0)) == NULL) {
   143     if ((master = ecrt_request_master(0)) == NULL) {
   139         printk(KERN_ERR "Requesting master 0 failed!\n");
   144         printk(KERN_ERR "Requesting master 0 failed!\n");
   140         goto out_return;
   145         goto out_return;
   153     if (ecrt_domain_register_field_list(domain1, domain1_fields)) {
   158     if (ecrt_domain_register_field_list(domain1, domain1_fields)) {
   154         printk(KERN_ERR "Field registration failed!\n");
   159         printk(KERN_ERR "Field registration failed!\n");
   155         goto out_release_master;
   160         goto out_release_master;
   156     }
   161     }
   157 
   162 
       
   163 #if 1
       
   164     printk(KERN_INFO "Setting variable data field sizes...\n");
       
   165     if (!(slave = ecrt_master_get_slave(master, "0"))) {
       
   166         printk(KERN_ERR "Failed to get slave!\n");
       
   167         goto out_deactivate;
       
   168     }
       
   169     ecrt_slave_field_size(slave, "Outputs", 0, 0x16);
       
   170     ecrt_slave_field_size(slave, "Inputs", 0, 0x16);
       
   171 #endif
       
   172 
   158     printk(KERN_INFO "Activating master...\n");
   173     printk(KERN_INFO "Activating master...\n");
   159     if (ecrt_master_activate(master)) {
   174     if (ecrt_master_activate(master)) {
   160         printk(KERN_ERR "Failed to activate master!\n");
   175         printk(KERN_ERR "Failed to activate master!\n");
   161         goto out_release_master;
   176         goto out_release_master;
   162     }
   177     }
   163 
   178 
   164 #if 0
   179 #if 1
   165     if (ecrt_master_fetch_sdo_lists(master)) {
   180     if (ecrt_master_fetch_sdo_lists(master)) {
   166         printk(KERN_ERR "Failed to fetch SDO lists!\n");
   181         printk(KERN_ERR "Failed to fetch SDO lists!\n");
   167         goto out_deactivate;
   182         goto out_deactivate;
   168     }
   183     }
   169     ecrt_master_print(master, 2);
   184     ecrt_master_print(master, 2);
   189         printk(KERN_ERR "Failed to configure SSI slave!\n");
   204         printk(KERN_ERR "Failed to configure SSI slave!\n");
   190         goto out_deactivate;
   205         goto out_deactivate;
   191     }
   206     }
   192 #endif
   207 #endif
   193 
   208 
   194 #if 0
       
   195     printk(KERN_INFO "Writing alias...\n");
       
   196     if (ecrt_slave_sdo_write_exp16(slave, 0xBEEF)) {
       
   197         printk(KERN_ERR "Failed to write alias!\n");
       
   198         goto out_deactivate;
       
   199     }
       
   200 #endif
       
   201 
       
   202 #ifdef ASYNC
   209 #ifdef ASYNC
   203     // send once and wait...
   210     // send once and wait...
   204     ecrt_master_prepare_async_io(master);
   211     ecrt_master_prepare_async_io(master);
   205 #endif
   212 #endif
   206 
   213