fp@0: //--------------------------------------------------------------- fp@0: // fp@0: // e c _ m a s t e r . h fp@0: // fp@0: // $LastChangedDate$ fp@0: // $Author$ fp@0: // fp@0: //--------------------------------------------------------------- fp@0: fp@0: #include fp@0: #include fp@0: #include fp@0: fp@0: #include "ec_slave.h" fp@0: #include "ec_command.h" fp@0: fp@0: //--------------------------------------------------------------- fp@0: fp@0: typedef struct fp@0: { fp@0: EtherCAT_slave_t *slaves; // Slaves array fp@0: unsigned int slave_count; // Number of slaves fp@0: fp@0: EtherCAT_command_t *first_command; // List of commands fp@0: fp@0: pcap_t *pcap_handle; // Handle for libpcap fp@0: libnet_t *net_handle; // Handle for libnet fp@0: fp@0: unsigned char command_index; // Current command index fp@0: fp@0: unsigned char *process_data; fp@0: unsigned int process_data_length; fp@0: void (*pre_cb)(unsigned char *); fp@0: void (*post_cb)(unsigned char *); fp@0: pthread_t thread; fp@0: int thread_continue; fp@0: unsigned int cycle_time; fp@0: fp@0: double bus_time; fp@0: fp@0: double last_jitter; fp@0: double last_cycle_time; fp@0: double last_cycle_work_time; fp@0: double last_cycle_busy_rate; fp@0: } fp@0: EtherCAT_master_t; fp@0: fp@0: //--------------------------------------------------------------- fp@0: fp@0: // Master creation and deletion fp@0: int EtherCAT_master_init(EtherCAT_master_t *, char *); fp@0: void EtherCAT_master_clear(EtherCAT_master_t *); fp@0: fp@0: // Checking for slaves fp@0: int EtherCAT_check_slaves(EtherCAT_master_t *, EtherCAT_slave_t *, unsigned int); fp@0: void EtherCAT_clear_slaves(EtherCAT_master_t *); fp@0: fp@0: // Slave information interface fp@0: int EtherCAT_read_slave_information(EtherCAT_master_t *, fp@0: unsigned short int, fp@0: unsigned short int, fp@0: unsigned int *); fp@0: fp@0: // EtherCAT commands fp@0: EtherCAT_command_t *EtherCAT_read(EtherCAT_master_t *, fp@0: unsigned short, fp@0: unsigned short, fp@0: unsigned int); fp@0: EtherCAT_command_t *EtherCAT_write(EtherCAT_master_t *, fp@0: unsigned short, fp@0: unsigned short, fp@0: unsigned int, fp@0: const unsigned char *); fp@0: EtherCAT_command_t *EtherCAT_position_read(EtherCAT_master_t *, fp@0: short, fp@0: unsigned short, fp@0: unsigned int); fp@0: EtherCAT_command_t *EtherCAT_position_write(EtherCAT_master_t *, fp@0: short, fp@0: unsigned short, fp@0: unsigned int, fp@0: const unsigned char *); fp@0: EtherCAT_command_t *EtherCAT_broadcast_read(EtherCAT_master_t *, fp@0: unsigned short, fp@0: unsigned int); fp@0: EtherCAT_command_t *EtherCAT_broadcast_write(EtherCAT_master_t *, fp@0: unsigned short, fp@0: unsigned int, fp@0: const unsigned char *); fp@0: EtherCAT_command_t *EtherCAT_logical_read_write(EtherCAT_master_t *, fp@0: unsigned int, fp@0: unsigned int, fp@0: unsigned char *); fp@0: fp@0: void EtherCAT_remove_command(EtherCAT_master_t *, EtherCAT_command_t *); fp@0: fp@0: // Slave states fp@0: int EtherCAT_state_change(EtherCAT_master_t *, EtherCAT_slave_t *, unsigned char); fp@0: int EtherCAT_broadcast_state_change(EtherCAT_master_t *, unsigned char); fp@0: fp@0: int EtherCAT_activate_slave(EtherCAT_master_t *, EtherCAT_slave_t *); fp@0: int EtherCAT_deactivate_slave(EtherCAT_master_t *, EtherCAT_slave_t *); fp@0: fp@0: // Sending and receiving fp@0: int EtherCAT_send_receive(EtherCAT_master_t *); fp@0: fp@0: int EtherCAT_start(EtherCAT_master_t *, fp@0: unsigned int, fp@0: void (*)(unsigned char *), fp@0: void (*)(unsigned char *), fp@0: unsigned int); fp@0: int EtherCAT_stop(EtherCAT_master_t *); fp@0: fp@0: // Private functions fp@0: void add_command(EtherCAT_master_t *, EtherCAT_command_t *); fp@0: void set_byte(unsigned char *, unsigned int, unsigned char); fp@0: void set_word(unsigned char *, unsigned int, unsigned int); fp@0: void *thread_function(void *); fp@0: fp@0: //---------------------------------------------------------------