examples/mini/mini.c
changeset 1209 8be462afb7f4
parent 1179 c0e6adec1aee
child 1212 d634ed3a9b94
equal deleted inserted replaced
1208:026e35646ab4 1209:8be462afb7f4
    46 // Optional features
    46 // Optional features
    47 #define CONFIGURE_PDOS  1
    47 #define CONFIGURE_PDOS  1
    48 #define EL3152_ALT_PDOS 0
    48 #define EL3152_ALT_PDOS 0
    49 #define EXTERNAL_MEMORY 1
    49 #define EXTERNAL_MEMORY 1
    50 #define SDO_ACCESS      0
    50 #define SDO_ACCESS      0
       
    51 #define VOE_ACCESS      0
    51 
    52 
    52 #define PFX "ec_mini: "
    53 #define PFX "ec_mini: "
    53 
    54 
    54 /*****************************************************************************/
    55 /*****************************************************************************/
    55 
    56 
   182 
   183 
   183 #if SDO_ACCESS
   184 #if SDO_ACCESS
   184 static ec_sdo_request_t *sdo;
   185 static ec_sdo_request_t *sdo;
   185 #endif
   186 #endif
   186 
   187 
       
   188 #if VOE_ACCESS
       
   189 static ec_voe_handler_t *voe;
       
   190 #endif
       
   191 
   187 /*****************************************************************************/
   192 /*****************************************************************************/
   188 
   193 
   189 void check_domain1_state(void)
   194 void check_domain1_state(void)
   190 {
   195 {
   191     ec_domain_state_t ds;
   196     ec_domain_state_t ds;
   247 
   252 
   248 #if SDO_ACCESS
   253 #if SDO_ACCESS
   249 void read_sdo(void)
   254 void read_sdo(void)
   250 {
   255 {
   251     switch (ecrt_sdo_request_state(sdo)) {
   256     switch (ecrt_sdo_request_state(sdo)) {
   252         case EC_SDO_REQUEST_UNUSED: // request was not used yet
   257         case EC_REQUEST_UNUSED: // request was not used yet
   253             ecrt_sdo_request_read(sdo); // trigger first read
   258             ecrt_sdo_request_read(sdo); // trigger first read
   254             break;
   259             break;
   255         case EC_SDO_REQUEST_BUSY:
   260         case EC_REQUEST_BUSY:
   256             printk(KERN_INFO PFX "Still busy...\n");
   261             printk(KERN_INFO PFX "Still busy...\n");
   257             break;
   262             break;
   258         case EC_SDO_REQUEST_SUCCESS:
   263         case EC_REQUEST_SUCCESS:
   259             printk(KERN_INFO PFX "Sdo value: 0x%04X\n",
   264             printk(KERN_INFO PFX "Sdo value: 0x%04X\n",
   260                     EC_READ_U16(ecrt_sdo_request_data(sdo)));
   265                     EC_READ_U16(ecrt_sdo_request_data(sdo)));
   261             ecrt_sdo_request_read(sdo); // trigger next read
   266             ecrt_sdo_request_read(sdo); // trigger next read
   262             break;
   267             break;
   263         case EC_SDO_REQUEST_ERROR:
   268         case EC_REQUEST_ERROR:
   264             printk(KERN_INFO PFX "Failed to read Sdo!\n");
   269             printk(KERN_INFO PFX "Failed to read Sdo!\n");
   265             ecrt_sdo_request_read(sdo); // retry reading
   270             ecrt_sdo_request_read(sdo); // retry reading
       
   271             break;
       
   272     }
       
   273 }
       
   274 #endif
       
   275 
       
   276 /*****************************************************************************/
       
   277 
       
   278 #if VOE_ACCESS
       
   279 void read_voe(void)
       
   280 {
       
   281     switch (ecrt_voe_handler_execute(voe)) {
       
   282         case EC_REQUEST_UNUSED:
       
   283             ecrt_voe_handler_read(voe); // trigger first read
       
   284             break;
       
   285         case EC_REQUEST_BUSY:
       
   286             printk(KERN_INFO PFX "VoE read still busy...\n");
       
   287             break;
       
   288         case EC_REQUEST_SUCCESS:
       
   289             printk(KERN_INFO PFX "VoE received.\n");
       
   290             // get data via ecrt_voe_handler_data(voe)
       
   291             ecrt_voe_handler_read(voe); // trigger next read
       
   292             break;
       
   293         case EC_REQUEST_ERROR:
       
   294             printk(KERN_INFO PFX "Failed to read VoE data!\n");
       
   295             ecrt_voe_handler_read(voe); // retry reading
   266             break;
   296             break;
   267     }
   297     }
   268 }
   298 }
   269 #endif
   299 #endif
   270 
   300 
   297         
   327         
   298 #if SDO_ACCESS
   328 #if SDO_ACCESS
   299         // read process data Sdo
   329         // read process data Sdo
   300         read_sdo();
   330         read_sdo();
   301 #endif
   331 #endif
       
   332 
       
   333 #if VOE_ACCESS
       
   334         read_voe();
       
   335 #endif
   302     }
   336     }
   303 
   337 
   304     // write process data
   338     // write process data
   305     EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x06 : 0x09);
   339     EC_WRITE_U8(domain1_pd + off_dig_out, blink ? 0x06 : 0x09);
   306 
   340 
   397     if (!(sdo = ecrt_slave_config_create_sdo_request(sc_ana_in, 0x3102, 2, 2))) {
   431     if (!(sdo = ecrt_slave_config_create_sdo_request(sc_ana_in, 0x3102, 2, 2))) {
   398         printk(KERN_ERR PFX "Failed to create Sdo request.\n");
   432         printk(KERN_ERR PFX "Failed to create Sdo request.\n");
   399         goto out_release_master;
   433         goto out_release_master;
   400     }
   434     }
   401     ecrt_sdo_request_timeout(sdo, 500); // ms
   435     ecrt_sdo_request_timeout(sdo, 500); // ms
       
   436 #endif
       
   437 
       
   438 #if VOE_ACCESS
       
   439     printk(KERN_INFO PFX "Creating VoE handlers...\n");
       
   440     if (!(voe = ecrt_slave_config_create_voe_handler(sc_ana_in, 1000))) {
       
   441         printk(KERN_ERR PFX "Failed to create VoE handler.\n");
       
   442         goto out_release_master;
       
   443     }
   402 #endif
   444 #endif
   403 
   445 
   404     printk(KERN_INFO PFX "Registering Pdo entries...\n");
   446     printk(KERN_INFO PFX "Registering Pdo entries...\n");
   405     if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
   447     if (ecrt_domain_reg_pdo_entry_list(domain1, domain1_regs)) {
   406         printk(KERN_ERR PFX "Pdo entry registration failed!\n");
   448         printk(KERN_ERR PFX "Pdo entry registration failed!\n");