examples/mini/mini.c
changeset 879 9b395c5646ab
parent 878 40c379697ebf
child 880 f6212c54a5e3
equal deleted inserted replaced
878:40c379697ebf 879:9b395c5646ab
    43 
    43 
    44 // Module parameters
    44 // Module parameters
    45 #define FREQUENCY 100
    45 #define FREQUENCY 100
    46 
    46 
    47 // Optional features
    47 // Optional features
    48 #define CONFIGURE_MAPPING
    48 #define CONFIGURE_PDOS
    49 #define EXTERNAL_MEMORY
    49 #define EXTERNAL_MEMORY
    50 #define SDO_ACCESS
    50 #define SDO_ACCESS
    51 
    51 
    52 #define PFX "ec_mini: "
    52 #define PFX "ec_mini: "
    53 
    53 
    80     {}
    80     {}
    81 };
    81 };
    82 
    82 
    83 /*****************************************************************************/
    83 /*****************************************************************************/
    84 
    84 
    85 #ifdef CONFIGURE_MAPPING
    85 #ifdef CONFIGURE_PDOS
    86 static ec_pdo_entry_info_t el3162_channel1[] = {
    86 static ec_pdo_entry_info_t el3162_channel1[] = {
    87     {0x3101, 1,  8}, // status
    87     {0x3101, 1,  8}, // status
    88     {0x3101, 2, 16}  // value
    88     {0x3101, 2, 16}  // value
    89 };
    89 };
    90 
    90 
    91 static ec_pdo_entry_info_t el3162_channel2[] = {
    91 static ec_pdo_entry_info_t el3162_channel2[] = {
    92     {0x3102, 1,  8}, // status
    92     {0x3102, 1,  8}, // status
    93     {0x3102, 2, 16}  // value
    93     {0x3102, 2, 16}  // value
    94 };
    94 };
    95 
    95 
    96 static ec_pdo_info_t el3162_mapping[] = {
    96 static ec_pdo_info_t el3162_pdos[] = {
    97     {EC_DIR_INPUT, 0x1A00, 2, el3162_channel1},
    97     {EC_DIR_INPUT, 0x1A00, 2, el3162_channel1},
    98     {EC_DIR_INPUT, 0x1A01, 2, el3162_channel2},
    98     {EC_DIR_INPUT, 0x1A01, 2, el3162_channel2},
    99     {EC_MAP_END}
    99     {EC_END}
   100 };
   100 };
   101 
   101 
   102 static ec_pdo_entry_info_t el2004_channels[] = {
   102 static ec_pdo_entry_info_t el2004_channels[] = {
   103     {0x3001, 1, 1}, // Value 1
   103     {0x3001, 1, 1}, // Value 1
   104     {0x3001, 2, 1}, // Value 2
   104     {0x3001, 2, 1}, // Value 2
   105     {0x3001, 3, 1}, // Value 3
   105     {0x3001, 3, 1}, // Value 3
   106     {0x3001, 4, 1}  // Value 4
   106     {0x3001, 4, 1}  // Value 4
   107 };
   107 };
   108 
   108 
   109 static ec_pdo_info_t el2004_mapping[] = {
   109 static ec_pdo_info_t el2004_pdos[] = {
   110     {EC_DIR_OUTPUT, 0x1600, 1, &el2004_channels[0]},
   110     {EC_DIR_OUTPUT, 0x1600, 1, &el2004_channels[0]},
   111     {EC_DIR_OUTPUT, 0x1601, 1, &el2004_channels[1]},
   111     {EC_DIR_OUTPUT, 0x1601, 1, &el2004_channels[1]},
   112     {EC_DIR_OUTPUT, 0x1602, 1, &el2004_channels[2]},
   112     {EC_DIR_OUTPUT, 0x1602, 1, &el2004_channels[2]},
   113     {EC_DIR_OUTPUT, 0x1603, 1, &el2004_channels[3]},
   113     {EC_DIR_OUTPUT, 0x1603, 1, &el2004_channels[3]},
   114 };
   114 };
   249 
   249 
   250 /*****************************************************************************/
   250 /*****************************************************************************/
   251 
   251 
   252 int __init init_mini_module(void)
   252 int __init init_mini_module(void)
   253 {
   253 {
   254 #ifdef CONFIGURE_MAPPING
   254 #ifdef CONFIGURE_PDOS
   255     ec_slave_config_t *sc;
   255     ec_slave_config_t *sc;
   256 #endif
   256 #endif
   257 #ifdef EXTERNAL_MEMORY
   257 #ifdef EXTERNAL_MEMORY
   258     unsigned int size;
   258     unsigned int size;
   259 #endif
   259 #endif
   271     if (!(domain1 = ecrt_master_create_domain(master))) {
   271     if (!(domain1 = ecrt_master_create_domain(master))) {
   272         printk(KERN_ERR PFX "Domain creation failed!\n");
   272         printk(KERN_ERR PFX "Domain creation failed!\n");
   273         goto out_release_master;
   273         goto out_release_master;
   274     }
   274     }
   275 
   275 
   276 #ifdef CONFIGURE_MAPPING
   276 #ifdef CONFIGURE_PDOS
   277     printk(KERN_INFO PFX "Configuring Pdo mapping...\n");
   277     printk(KERN_INFO PFX "Configuring Pdos...\n");
   278     if (!(sc = ecrt_master_slave_config(master, 0, 1, Beckhoff_EL3162))) {
   278     if (!(sc = ecrt_master_slave_config(master, 0, 1, Beckhoff_EL3162))) {
   279         printk(KERN_ERR PFX "Failed to get slave configuration.\n");
   279         printk(KERN_ERR PFX "Failed to get slave configuration.\n");
   280         goto out_release_master;
   280         goto out_release_master;
   281     }
   281     }
   282 
   282 
   283     if (ecrt_slave_config_mapping(sc, EC_MAP_END, el3162_mapping)) {
   283     if (ecrt_slave_config_pdos(sc, EC_END, el3162_pdos)) {
   284         printk(KERN_ERR PFX "Failed to configure Pdo mapping.\n");
   284         printk(KERN_ERR PFX "Failed to configure Pdos.\n");
   285         goto out_release_master;
   285         goto out_release_master;
   286     }
   286     }
   287 
   287 
   288     if (!(sc = ecrt_master_slave_config(master, 0, 3, Beckhoff_EL2004))) {
   288     if (!(sc = ecrt_master_slave_config(master, 0, 3, Beckhoff_EL2004))) {
   289         printk(KERN_ERR PFX "Failed to get slave configuration.\n");
   289         printk(KERN_ERR PFX "Failed to get slave configuration.\n");
   290         goto out_release_master;
   290         goto out_release_master;
   291     }
   291     }
   292 
   292 
   293     if (ecrt_slave_config_mapping(sc, 4, el2004_mapping)) {
   293     if (ecrt_slave_config_pdos(sc, 4, el2004_pdos)) {
   294         printk(KERN_ERR PFX "Failed to configure Pdo mapping.\n");
   294         printk(KERN_ERR PFX "Failed to configure Pdos.\n");
   295         goto out_release_master;
   295         goto out_release_master;
   296     }
   296     }
   297 #endif
   297 #endif
   298 
   298 
   299 #ifdef SDO_ACCESS
   299 #ifdef SDO_ACCESS