ecrt.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  *  $Id: ecrt.h 490 2006-08-02 12:25:25Z fp $
00004  *
00005  *  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
00006  *
00007  *  This file is part of the IgH EtherCAT Master.
00008  *
00009  *  The IgH EtherCAT Master is free software; you can redistribute it
00010  *  and/or modify it under the terms of the GNU General Public License
00011  *  as published by the Free Software Foundation; either version 2 of the
00012  *  License, or (at your option) any later version.
00013  *
00014  *  The IgH EtherCAT Master is distributed in the hope that it will be
00015  *  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *  GNU General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU General Public License
00020  *  along with the IgH EtherCAT Master; if not, write to the Free Software
00021  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022  *
00023  *  The right to use EtherCAT Technology is granted and comes free of
00024  *  charge under condition of compatibility of product made by
00025  *  Licensee. People intending to distribute/sell products based on the
00026  *  code, have to sign an agreement to guarantee that products using
00027  *  software based on IgH EtherCAT master stay compatible with the actual
00028  *  EtherCAT specification (which are released themselves as an open
00029  *  standard) as the (only) precondition to have the right to use EtherCAT
00030  *  Technology, IP and trade marks.
00031  *
00032  *****************************************************************************/
00033 
00047 /*****************************************************************************/
00048 
00049 #ifndef __ECRT_H__
00050 #define __ECRT_H__
00051 
00052 #include <asm/byteorder.h>
00053 
00054 #ifdef __KERNEL__
00055 #include <linux/types.h>
00056 #else
00057 #include <stdint.h>
00058 #endif
00059 
00060 /*****************************************************************************/
00061 
00062 struct ec_master;
00063 typedef struct ec_master ec_master_t; 
00065 struct ec_domain;
00066 typedef struct ec_domain ec_domain_t; 
00068 struct ec_slave;
00069 typedef struct ec_slave ec_slave_t; 
00077 typedef struct
00078 {
00079     void **data_ptr; 
00080     const char *slave_address; 
00082     const char *vendor_name; 
00083     const char *product_name; 
00084     const char *field_name; 
00085     unsigned int field_index; 
00086     unsigned int field_count; 
00087 }
00088 ec_field_init_t;
00089 
00090 /******************************************************************************
00091  *  Master request functions
00092  *****************************************************************************/
00093 
00094 ec_master_t *ecrt_request_master(unsigned int master_index);
00095 void ecrt_release_master(ec_master_t *master);
00096 
00097 /******************************************************************************
00098  *  Master methods
00099  *****************************************************************************/
00100 
00101 void ecrt_master_callbacks(ec_master_t *master, int (*request_cb)(void *),
00102                            void (*release_cb)(void *), void *cb_data);
00103 
00104 ec_domain_t *ecrt_master_create_domain(ec_master_t *master);
00105 
00106 int ecrt_master_activate(ec_master_t *master);
00107 void ecrt_master_deactivate(ec_master_t *master);
00108 
00109 int ecrt_master_fetch_sdo_lists(ec_master_t *master);
00110 
00111 void ecrt_master_sync_io(ec_master_t *master);
00112 void ecrt_master_async_send(ec_master_t *master);
00113 void ecrt_master_async_receive(ec_master_t *master);
00114 void ecrt_master_prepare_async_io(ec_master_t *master);
00115 
00116 void ecrt_master_run(ec_master_t *master);
00117 
00118 int ecrt_master_start_eoe(ec_master_t *master);
00119 
00120 void ecrt_master_debug(ec_master_t *master, int level);
00121 void ecrt_master_print(const ec_master_t *master, unsigned int verbosity);
00122 
00123 ec_slave_t *ecrt_master_get_slave(const ec_master_t *, const char *);
00124 
00125 /******************************************************************************
00126  *  Domain Methods
00127  *****************************************************************************/
00128 
00129 ec_slave_t *ecrt_domain_register_field(ec_domain_t *domain,
00130                                        const char *address,
00131                                        const char *vendor_name,
00132                                        const char *product_name,
00133                                        void **data_ptr, const char *field_name,
00134                                        unsigned int field_index,
00135                                        unsigned int field_count);
00136 int ecrt_domain_register_field_list(ec_domain_t *domain,
00137                                     const ec_field_init_t *fields);
00138 
00139 void ecrt_domain_queue(ec_domain_t *domain);
00140 void ecrt_domain_process(ec_domain_t *domain);
00141 
00142 int ecrt_domain_state(ec_domain_t *domain);
00143 
00144 /******************************************************************************
00145  *  Slave Methods
00146  *****************************************************************************/
00147 
00148 /* there SDO functions are deprecated! */
00149 
00150 int ecrt_slave_sdo_read_exp8(ec_slave_t *slave, uint16_t sdo_index,
00151                               uint8_t sdo_subindex, uint8_t *value);
00152 int ecrt_slave_sdo_read_exp16(ec_slave_t *slave, uint16_t sdo_index,
00153                               uint8_t sdo_subindex, uint16_t *value);
00154 int ecrt_slave_sdo_read_exp32(ec_slave_t *slave, uint16_t sdo_index,
00155                               uint8_t sdo_subindex, uint32_t *value);
00156 int ecrt_slave_sdo_write_exp8(ec_slave_t *slave, uint16_t sdo_index,
00157                               uint8_t sdo_subindex, uint8_t value);
00158 int ecrt_slave_sdo_write_exp16(ec_slave_t *slave, uint16_t sdo_index,
00159                                uint8_t sdo_subindex, uint16_t value);
00160 int ecrt_slave_sdo_write_exp32(ec_slave_t *slave, uint16_t sdo_index,
00161                                uint8_t sdo_subindex, uint32_t value);
00162 int ecrt_slave_sdo_read(ec_slave_t *slave, uint16_t sdo_index,
00163                         uint8_t sdo_subindex, uint8_t *data, size_t *size);
00164 
00165 int ecrt_slave_write_alias(ec_slave_t *slave, uint16_t alias); // deprecated!
00166 
00167 int ecrt_slave_field_size(ec_slave_t *slave, const char *field_name,
00168                           unsigned int field_index, size_t size);
00169 
00170 /******************************************************************************
00171  *  Bitwise read/write macros
00172  *****************************************************************************/
00173 
00180 #define EC_READ_BIT(DATA, POS) ((*((uint8_t *) (DATA)) >> (POS)) & 0x01)
00181 
00189 #define EC_WRITE_BIT(DATA, POS, VAL) \
00190     do { \
00191         if (VAL) *((uint8_t *) (DATA)) |=  (1 << (POS)); \
00192         else     *((uint8_t *) (DATA)) &= ~(1 << (POS)); \
00193     } while (0)
00194 
00195 /******************************************************************************
00196  *  Read macros
00197  *****************************************************************************/
00198 
00204 #define EC_READ_U8(DATA) \
00205     ((uint8_t) *((uint8_t *) (DATA)))
00206 
00213 #define EC_READ_S8(DATA) \
00214      ((int8_t) *((uint8_t *) (DATA)))
00215 
00222 #define EC_READ_U16(DATA) \
00223      ((uint16_t) le16_to_cpup((void *) (DATA)))
00224 
00231 #define EC_READ_S16(DATA) \
00232      ((int16_t) le16_to_cpup((void *) (DATA)))
00233 
00240 #define EC_READ_U32(DATA) \
00241      ((uint32_t) le32_to_cpup((void *) (DATA)))
00242 
00249 #define EC_READ_S32(DATA) \
00250      ((int32_t) le32_to_cpup((void *) (DATA)))
00251 
00252 
00253 /******************************************************************************
00254  *  Write macros
00255  *****************************************************************************/
00256 
00263 #define EC_WRITE_U8(DATA, VAL) \
00264     do { \
00265         *((uint8_t *)(DATA)) = ((uint8_t) (VAL)); \
00266     } while (0)
00267 
00274 #define EC_WRITE_S8(DATA, VAL) EC_WRITE_U8(DATA, VAL)
00275 
00282 #define EC_WRITE_U16(DATA, VAL) \
00283     do { \
00284         *((uint16_t *) (DATA)) = (uint16_t) (VAL); \
00285         cpu_to_le16s(DATA); \
00286     } while (0)
00287 
00294 #define EC_WRITE_S16(DATA, VAL) EC_WRITE_U16(DATA, VAL)
00295 
00302 #define EC_WRITE_U32(DATA, VAL) \
00303     do { \
00304         *((uint32_t *) (DATA)) = (uint32_t) (VAL); \
00305         cpu_to_le16s(DATA); \
00306     } while (0)
00307 
00314 #define EC_WRITE_S32(DATA, VAL) EC_WRITE_U32(DATA, VAL)
00315 
00316 /*****************************************************************************/
00317 
00318 #endif

Generated on Wed Aug 2 18:41:43 2006 for IgH EtherCAT master by  doxygen 1.4.6