fp@0: /**************************************************************** fp@0: * fp@0: * e c _ m a s t e r . h fp@0: * fp@0: * Struktur für einen EtherCAT-Master. fp@0: * fp@0: * $Date$ fp@0: * $Author$ fp@0: * fp@0: ***************************************************************/ fp@0: fp@0: #ifndef _EC_MASTER_H_ fp@0: #define _EC_MASTER_H_ fp@0: fp@0: #include "ec_device.h" fp@0: #include "ec_slave.h" fp@0: #include "ec_command.h" fp@0: fp@0: /***************************************************************/ fp@0: fp@0: /** fp@0: EtherCAT-Master fp@0: fp@0: Verwaltet die EtherCAT-Slaves und kommuniziert mit fp@0: dem zugewiesenen EtherCAT-Gerät. fp@0: */ fp@0: fp@0: typedef struct fp@0: { fp@0: EtherCAT_slave_t *slaves; /**< Zeiger auf statischen Speicher fp@0: mit Slave-Informationen */ fp@0: unsigned int slave_count; /**< Anzahl der Slaves in slaves */ fp@0: fp@0: EtherCAT_command_t *first_command; /**< Zeiger auf das erste fp@0: Kommando in der Liste */ fp@0: EtherCAT_command_t *process_data_command; /**< Zeiger Auf das Kommando fp@0: zum Senden und Empfangen fp@0: der Prozessdaten */ fp@0: fp@0: EtherCAT_device_t *dev; /**< Zeiger auf das zugewiesene EtherCAT-Gerät */ fp@0: fp@0: unsigned char command_index; /**< Aktueller Kommando-Index */ fp@0: fp@0: unsigned char tx_data[ECAT_FRAME_BUFFER_SIZE]; /**< Statischer Speicher fp@0: für zu sendende Daten */ fp@0: unsigned int tx_data_length; /**< Länge der Daten im Sendespeicher */ fp@0: unsigned char rx_data[ECAT_FRAME_BUFFER_SIZE]; /**< Statische Speicher für fp@0: eine Kopie des Rx-Buffers fp@0: im EtherCAT-Gerät */ fp@0: fp@0: unsigned char *process_data; /**< Zeiger auf Speicher mit Prozessdaten */ fp@0: unsigned int process_data_length; /**< Länge der Prozessdaten */ fp@0: fp@2: EtherCAT_command_t cmd_ring[ECAT_COMMAND_RING_SIZE]; /**< Statischer Kommandoring */ fp@2: int cmd_reserved[ECAT_COMMAND_RING_SIZE]; /**< Reservierungsflags für die Kommandos */ fp@0: unsigned int cmd_ring_index; /**< Index des nächsten Kommandos im Ring */ fp@2: fp@2: int debug_level; /**< Debug-Level im Master-Code */ 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 *, EtherCAT_device_t *); fp@0: void EtherCAT_master_clear(EtherCAT_master_t *); fp@0: fp@0: // Slave management 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: int EtherCAT_activate_slave(EtherCAT_master_t *, EtherCAT_slave_t *); fp@0: int EtherCAT_deactivate_slave(EtherCAT_master_t *, EtherCAT_slave_t *); fp@0: int EtherCAT_activate_all_slaves(EtherCAT_master_t *); fp@0: int EtherCAT_deactivate_all_slaves(EtherCAT_master_t *); fp@0: fp@0: // Sending and receiving fp@0: int EtherCAT_async_send_receive(EtherCAT_master_t *); fp@0: int EtherCAT_send(EtherCAT_master_t *); fp@0: int EtherCAT_receive(EtherCAT_master_t *); fp@0: int EtherCAT_write_process_data(EtherCAT_master_t *); fp@0: int EtherCAT_read_process_data(EtherCAT_master_t *); fp@2: void EtherCAT_clear_process_data(EtherCAT_master_t *); fp@0: fp@0: /***************************************************************/ 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: fp@0: /***************************************************************/ fp@0: fp@0: // Private functions fp@0: EtherCAT_command_t *alloc_cmd(EtherCAT_master_t *); fp@2: int 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: fp@0: /***************************************************************/ fp@0: fp@0: #endif