examples/mini/mini.c
changeset 1179 c0e6adec1aee
parent 1171 de880622f253
child 1209 8be462afb7f4
child 1685 399ef727bf62
equal deleted inserted replaced
1178:ca00393c8ca6 1179:c0e6adec1aee
    43 // Module parameters
    43 // Module parameters
    44 #define FREQUENCY 100
    44 #define FREQUENCY 100
    45 
    45 
    46 // Optional features
    46 // Optional features
    47 #define CONFIGURE_PDOS  1
    47 #define CONFIGURE_PDOS  1
    48 #define EL3162_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 
    51 
    52 #define PFX "ec_mini: "
    52 #define PFX "ec_mini: "
    53 
    53 
    71 
    71 
    72 // process data
    72 // process data
    73 static uint8_t *domain1_pd; // process data memory
    73 static uint8_t *domain1_pd; // process data memory
    74 
    74 
    75 #define AnaInSlavePos  0, 1
    75 #define AnaInSlavePos  0, 1
       
    76 #define AnaOutSlavePos 0, 2
    76 #define DigOutSlavePos 0, 3
    77 #define DigOutSlavePos 0, 3
    77 
    78 
    78 #define Beckhoff_EL2004 0x00000002, 0x07D43052
    79 #define Beckhoff_EL2004 0x00000002, 0x07D43052
    79 #define Beckhoff_EL3162 0x00000002, 0x0C5A3052
    80 #define Beckhoff_EL3152 0x00000002, 0x0c503052
    80 
    81 #define Beckhoff_EL4102 0x00000002, 0x10063052
    81 static unsigned int off_ana_in; // offsets for Pdo entries
    82 
       
    83 // offsets for Pdo entries
       
    84 static unsigned int off_ana_in;
       
    85 static unsigned int off_ana_out;
    82 static unsigned int off_dig_out;
    86 static unsigned int off_dig_out;
    83 
    87 
    84 const static ec_pdo_entry_reg_t domain1_regs[] = {
    88 const static ec_pdo_entry_reg_t domain1_regs[] = {
    85 #if EL3162_ALT_PDOS
    89 #if EL3152_ALT_PDOS
    86     {AnaInSlavePos,  Beckhoff_EL3162, 0x6401, 2, &off_ana_in},
    90     {AnaInSlavePos,  Beckhoff_EL3152, 0x6401, 1, &off_ana_in},
    87 #else
    91 #else
    88     {AnaInSlavePos,  Beckhoff_EL3162, 0x3101, 2, &off_ana_in},
    92     {AnaInSlavePos,  Beckhoff_EL3152, 0x3101, 2, &off_ana_in},
    89 #endif
    93 #endif
       
    94     {AnaOutSlavePos, Beckhoff_EL4102, 0x3001, 1, &off_ana_out},
    90     {DigOutSlavePos, Beckhoff_EL2004, 0x3001, 1, &off_dig_out},
    95     {DigOutSlavePos, Beckhoff_EL2004, 0x3001, 1, &off_dig_out},
    91     {}
    96     {}
    92 };
    97 };
    93 
    98 
    94 static unsigned int counter = 0;
    99 static unsigned int counter = 0;
    96 
   101 
    97 /*****************************************************************************/
   102 /*****************************************************************************/
    98 
   103 
    99 #if CONFIGURE_PDOS
   104 #if CONFIGURE_PDOS
   100 
   105 
   101 static ec_pdo_entry_info_t el3162_pdo_entries[] = {
   106 // Analog in --------------------------
       
   107 
       
   108 static ec_pdo_entry_info_t el3152_pdo_entries[] = {
   102     {0x3101, 1,  8}, // channel 1 status
   109     {0x3101, 1,  8}, // channel 1 status
   103     {0x3101, 2, 16}, // channel 1 value
   110     {0x3101, 2, 16}, // channel 1 value
   104     {0x3102, 1,  8}, // channel 2 status
   111     {0x3102, 1,  8}, // channel 2 status
   105     {0x3102, 2, 16}, // channel 2 value
   112     {0x3102, 2, 16}, // channel 2 value
   106     {0x6401, 1, 16}, // channel 1 value (alt.)
   113     {0x6401, 1, 16}, // channel 1 value (alt.)
   107     {0x6401, 2, 16}  // channel 2 value (alt.)
   114     {0x6401, 2, 16}  // channel 2 value (alt.)
   108 };
   115 };
   109 
   116 
   110 #if EL3162_ALT_PDOS
   117 #if EL3152_ALT_PDOS
   111 static ec_pdo_info_t el3162_pdos[] = {
   118 static ec_pdo_info_t el3152_pdos[] = {
   112     {0x1A10, 2, el3162_pdo_entries + 4},
   119     {0x1A10, 2, el3152_pdo_entries + 4},
   113 };
   120 };
   114 
   121 
   115 static ec_sync_info_t el3162_syncs[] = {
   122 static ec_sync_info_t el3152_syncs[] = {
   116     {2, EC_DIR_OUTPUT},
   123     {2, EC_DIR_OUTPUT},
   117     {3, EC_DIR_INPUT, 1, el3162_pdos},
   124     {3, EC_DIR_INPUT, 1, el3152_pdos},
   118     {0xff}
   125     {0xff}
   119 };
   126 };
   120 #else
   127 #else
   121 static ec_pdo_info_t el3162_pdos[] = {
   128 static ec_pdo_info_t el3152_pdos[] = {
   122     {0x1A00, 2, el3162_pdo_entries},
   129     {0x1A00, 2, el3152_pdo_entries},
   123     {0x1A01, 2, el3162_pdo_entries + 2}
   130     {0x1A01, 2, el3152_pdo_entries + 2}
   124 };
   131 };
   125 
   132 
   126 static ec_sync_info_t el3162_syncs[] = {
   133 static ec_sync_info_t el3152_syncs[] = {
   127     {2, EC_DIR_OUTPUT},
   134     {2, EC_DIR_OUTPUT},
   128     {3, EC_DIR_INPUT, 2, el3162_pdos},
   135     {3, EC_DIR_INPUT, 1, el3152_pdos},
   129     {0xff}
   136     {0xff}
   130 };
   137 };
   131 #endif
   138 #endif
       
   139 
       
   140 // Analog out -------------------------
       
   141 
       
   142 static ec_pdo_entry_info_t el4102_pdo_entries[] = {
       
   143     {0x3001, 1, 16}, // channel 1 value
       
   144     {0x3002, 1, 16}, // channel 2 value
       
   145 };
       
   146 
       
   147 static ec_pdo_info_t el4102_pdos[] = {
       
   148     {0x1600, 1, el4102_pdo_entries},
       
   149     {0x1601, 1, el4102_pdo_entries + 1}
       
   150 };
       
   151 
       
   152 static ec_sync_info_t el4102_syncs[] = {
       
   153     {2, EC_DIR_OUTPUT, 2, el4102_pdos},
       
   154     {3, EC_DIR_INPUT},
       
   155     {0xff}
       
   156 };
       
   157 
       
   158 // Digital out ------------------------
   132 
   159 
   133 static ec_pdo_entry_info_t el2004_channels[] = {
   160 static ec_pdo_entry_info_t el2004_channels[] = {
   134     {0x3001, 1, 1}, // Value 1
   161     {0x3001, 1, 1}, // Value 1
   135     {0x3001, 2, 1}, // Value 2
   162     {0x3001, 2, 1}, // Value 2
   136     {0x3001, 3, 1}, // Value 3
   163     {0x3001, 3, 1}, // Value 3
   328         printk(KERN_ERR PFX "Domain creation failed!\n");
   355         printk(KERN_ERR PFX "Domain creation failed!\n");
   329         goto out_release_master;
   356         goto out_release_master;
   330     }
   357     }
   331 
   358 
   332     if (!(sc_ana_in = ecrt_master_slave_config(
   359     if (!(sc_ana_in = ecrt_master_slave_config(
   333                     master, AnaInSlavePos, Beckhoff_EL3162))) {
   360                     master, AnaInSlavePos, Beckhoff_EL3152))) {
   334         printk(KERN_ERR PFX "Failed to get slave configuration.\n");
   361         printk(KERN_ERR PFX "Failed to get slave configuration.\n");
   335         goto out_release_master;
   362         goto out_release_master;
   336     }
   363     }
   337 
   364 
   338 #if CONFIGURE_PDOS
   365 #if CONFIGURE_PDOS
   339     printk(KERN_INFO PFX "Configuring Pdos...\n");
   366     printk(KERN_INFO PFX "Configuring Pdos...\n");
   340     if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3162_syncs)) {
   367     if (ecrt_slave_config_pdos(sc_ana_in, EC_END, el3152_syncs)) {
       
   368         printk(KERN_ERR PFX "Failed to configure Pdos.\n");
       
   369         goto out_release_master;
       
   370     }
       
   371 
       
   372     if (!(sc = ecrt_master_slave_config(
       
   373                     master, AnaOutSlavePos, Beckhoff_EL4102))) {
       
   374         printk(KERN_ERR PFX "Failed to get slave configuration.\n");
       
   375         goto out_release_master;
       
   376     }
       
   377 
       
   378     if (ecrt_slave_config_pdos(sc, EC_END, el4102_syncs)) {
   341         printk(KERN_ERR PFX "Failed to configure Pdos.\n");
   379         printk(KERN_ERR PFX "Failed to configure Pdos.\n");
   342         goto out_release_master;
   380         goto out_release_master;
   343     }
   381     }
   344 
   382 
   345     if (!(sc = ecrt_master_slave_config(
   383     if (!(sc = ecrt_master_slave_config(