master/master.c
changeset 130 69c2645300ee
parent 129 67b6e534db4b
child 133 b36d187ecc0b
equal deleted inserted replaced
129:67b6e534db4b 130:69c2645300ee
    99     }
    99     }
   100 
   100 
   101     master->command_index = 0;
   101     master->command_index = 0;
   102     master->debug_level = 0;
   102     master->debug_level = 0;
   103     master->timeout = 100; // us
   103     master->timeout = 100; // us
       
   104 
       
   105     master->slaves_responding = 0;
       
   106     master->slave_states = EC_SLAVE_STATE_UNKNOWN;
       
   107 
   104     master->stats.timeouts = 0;
   108     master->stats.timeouts = 0;
   105     master->stats.delayed = 0;
   109     master->stats.delayed = 0;
   106     master->stats.corrupted = 0;
   110     master->stats.corrupted = 0;
   107     master->stats.unmatched = 0;
   111     master->stats.unmatched = 0;
   108     master->stats.t_last = 0;
   112     master->stats.t_last = 0;
   387             EC_ERR("Simple-IO command error!\n");
   391             EC_ERR("Simple-IO command error!\n");
   388             return -1;
   392             return -1;
   389         }
   393         }
   390 
   394 
   391         // Keine direkte Antwort. Dem Slave Zeit lassen...
   395         // Keine direkte Antwort. Dem Slave Zeit lassen...
   392         udelay(10);
   396         udelay(100);
   393 
   397 
   394         if (unlikely(--response_tries_left)) {
   398         if (unlikely(--response_tries_left)) {
   395             EC_ERR("No response in simple-IO!\n");
   399             EC_ERR("No response in simple-IO!\n");
   396             return -1;
   400             return -1;
   397         }
   401         }
   677     EC_WRITE_U8 (data + 11, (fmmu->sync->control_byte & 0x04) ? 0x02 : 0x01);
   681     EC_WRITE_U8 (data + 11, (fmmu->sync->control_byte & 0x04) ? 0x02 : 0x01);
   678     EC_WRITE_U16(data + 12, 0x0001); // Enable
   682     EC_WRITE_U16(data + 12, 0x0001); // Enable
   679     EC_WRITE_U16(data + 14, 0x0000); // res.
   683     EC_WRITE_U16(data + 14, 0x0000); // res.
   680 }
   684 }
   681 
   685 
       
   686 /*****************************************************************************/
       
   687 
       
   688 /**
       
   689    Gibt Überwachungsinformationen aus.
       
   690 */
       
   691 
       
   692 void ec_master_process_watch_command(ec_master_t *master
       
   693                                      /**< EtherCAT-Master */
       
   694                                      )
       
   695 {
       
   696     unsigned int first;
       
   697 
       
   698     first = 1;
       
   699 
       
   700     if (master->watch_command.working_counter != master->slaves_responding ||
       
   701         master->watch_command.data[0] != master->slave_states)
       
   702     {
       
   703         master->slaves_responding = master->watch_command.working_counter;
       
   704         master->slave_states = master->watch_command.data[0];
       
   705 
       
   706         EC_INFO("%i slave%s responding (", master->slaves_responding,
       
   707                 master->slaves_responding == 1 ? "" : "s");
       
   708 
       
   709         if (master->slave_states & EC_SLAVE_STATE_INIT) {
       
   710             printk("INIT");
       
   711             first = 0;
       
   712         }
       
   713         if (master->slave_states & EC_SLAVE_STATE_PREOP) {
       
   714             if (!first) {
       
   715                 printk(", ");
       
   716                 first = 0;
       
   717             }
       
   718             printk("PREOP");
       
   719         }
       
   720         if (master->slave_states & EC_SLAVE_STATE_SAVEOP) {
       
   721             if (!first) {
       
   722                 printk(", ");
       
   723                 first = 0;
       
   724             }
       
   725             printk("SAVEOP");
       
   726         }
       
   727         if (master->slave_states & EC_SLAVE_STATE_OP) {
       
   728             if (!first) {
       
   729                 printk(", ");
       
   730                 first = 0;
       
   731             }
       
   732             printk("OP");
       
   733         }
       
   734         printk(")\n");
       
   735     }
       
   736 }
       
   737 
   682 /******************************************************************************
   738 /******************************************************************************
   683  *
   739  *
   684  * Echtzeitschnittstelle
   740  * Echtzeitschnittstelle
   685  *
   741  *
   686  *****************************************************************************/
   742  *****************************************************************************/
   833 
   889 
   834         // Change state to OP
   890         // Change state to OP
   835         if (unlikely(ec_slave_state_change(slave, EC_SLAVE_STATE_OP)))
   891         if (unlikely(ec_slave_state_change(slave, EC_SLAVE_STATE_OP)))
   836             return -1;
   892             return -1;
   837     }
   893     }
       
   894 
       
   895     master->slaves_responding = master->slave_count;
       
   896     master->slave_states = EC_SLAVE_STATE_OP;
   838 
   897 
   839     return 0;
   898     return 0;
   840 }
   899 }
   841 
   900 
   842 /*****************************************************************************/
   901 /*****************************************************************************/
   950         // Device-Zustand abfragen
  1009         // Device-Zustand abfragen
   951         ec_device_call_isr(master->device);
  1010         ec_device_call_isr(master->device);
   952         return;
  1011         return;
   953     }
  1012     }
   954 
  1013 
       
  1014     // Watch-Kommando hinzufügen
       
  1015     ec_command_init_brd(&master->watch_command, 0x130, 2);
       
  1016     ec_master_queue_command(master, &master->watch_command);
       
  1017 
   955     // Rahmen senden
  1018     // Rahmen senden
   956     ec_master_send_commands(master);
  1019     ec_master_send_commands(master);
   957 }
  1020 }
   958 
  1021 
   959 /*****************************************************************************/
  1022 /*****************************************************************************/
   963 */
  1026 */
   964 
  1027 
   965 void ecrt_master_async_receive(ec_master_t *master)
  1028 void ecrt_master_async_receive(ec_master_t *master)
   966 {
  1029 {
   967     ec_command_t *command, *next;
  1030     ec_command_t *command, *next;
   968 
       
   969     ec_master_output_stats(master);
       
   970 
  1031 
   971     ec_device_call_isr(master->device);
  1032     ec_device_call_isr(master->device);
   972 
  1033 
   973     // Alle empfangenen Kommandos aus der Liste entfernen
  1034     // Alle empfangenen Kommandos aus der Liste entfernen
   974     list_for_each_entry_safe(command, next, &master->commands, list)
  1035     list_for_each_entry_safe(command, next, &master->commands, list)
   987             default:
  1048             default:
   988                 break;
  1049                 break;
   989         }
  1050         }
   990         list_del_init(&command->list);
  1051         list_del_init(&command->list);
   991     }
  1052     }
       
  1053 
       
  1054     // Watch-Kommando verarbeiten
       
  1055     ec_master_process_watch_command(master);
       
  1056 
       
  1057     // Statistiken ausgeben
       
  1058     ec_master_output_stats(master);
   992 }
  1059 }
   993 
  1060 
   994 /*****************************************************************************/
  1061 /*****************************************************************************/
   995 
  1062 
   996 /**
  1063 /**