Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

ecrt.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  *  $Id: ecrt.h 686 2006-11-07 13:47:50Z 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     const char *slave_address; 
00081     uint32_t vendor_id; 
00082     uint32_t product_code; 
00083     uint16_t pdo_index; 
00084     uint8_t pdo_subindex; 
00085     void **data_ptr; 
00086 }
00087 ec_pdo_reg_t;
00088 
00093 typedef enum {EC_DIR_INPUT, EC_DIR_OUTPUT} ec_direction_t;
00094 
00095 /******************************************************************************
00096  *  Master request functions
00097  *****************************************************************************/
00098 
00099 ec_master_t *ecrt_request_master(unsigned int master_index);
00100 void ecrt_release_master(ec_master_t *master);
00101 
00102 /******************************************************************************
00103  *  Master methods
00104  *****************************************************************************/
00105 
00106 void ecrt_master_callbacks(ec_master_t *master, int (*request_cb)(void *),
00107                            void (*release_cb)(void *), void *cb_data);
00108 
00109 ec_domain_t *ecrt_master_create_domain(ec_master_t *master);
00110 
00111 int ecrt_master_activate(ec_master_t *master);
00112 void ecrt_master_deactivate(ec_master_t *master); // deprecated!
00113 
00114 void ecrt_master_prepare(ec_master_t *master);
00115 
00116 void ecrt_master_send(ec_master_t *master);
00117 void ecrt_master_receive(ec_master_t *master);
00118 
00119 void ecrt_master_run(ec_master_t *master);
00120 
00121 ec_slave_t *ecrt_master_get_slave(const ec_master_t *, const char *);
00122 
00124 int ecrt_master_state(const ec_master_t *master);
00127 /******************************************************************************
00128  *  Domain Methods
00129  *****************************************************************************/
00130 
00131 ec_slave_t *ecrt_domain_register_pdo(ec_domain_t *domain,
00132                                      const char *address,
00133                                      uint32_t vendor_id,
00134                                      uint32_t product_code,
00135                                      uint16_t pdo_index,
00136                                      uint8_t pdo_subindex,
00137                                      void **data_ptr);
00138 
00139 int ecrt_domain_register_pdo_list(ec_domain_t *domain,
00140                                   const ec_pdo_reg_t *pdos);
00141 
00142 ec_slave_t *ecrt_domain_register_pdo_range(ec_domain_t *domain,
00143                                            const char *address,
00144                                            uint32_t vendor_id,
00145                                            uint32_t product_code,
00146                                            ec_direction_t direction,
00147                                            uint16_t offset,
00148                                            uint16_t length,
00149                                            void **data_ptr);
00150 
00151 void ecrt_domain_process(ec_domain_t *domain);
00152 int ecrt_domain_state(const ec_domain_t *domain);
00153 
00154 /******************************************************************************
00155  *  Slave Methods
00156  *****************************************************************************/
00157 
00158 int ecrt_slave_conf_sdo8(ec_slave_t *slave, uint16_t sdo_index,
00159                          uint8_t sdo_subindex, uint8_t value);
00160 int ecrt_slave_conf_sdo16(ec_slave_t *slave, uint16_t sdo_index,
00161                           uint8_t sdo_subindex, uint16_t value);
00162 int ecrt_slave_conf_sdo32(ec_slave_t *slave, uint16_t sdo_index,
00163                           uint8_t sdo_subindex, uint32_t value);
00164 
00165 int ecrt_slave_pdo_size(ec_slave_t *slave, uint16_t pdo_index,
00166                         uint8_t pdo_subindex, size_t size); // deprecated
00167 
00168 /******************************************************************************
00169  *  Bitwise read/write macros
00170  *****************************************************************************/
00171 
00178 #define EC_READ_BIT(DATA, POS) ((*((uint8_t *) (DATA)) >> (POS)) & 0x01)
00179 
00187 #define EC_WRITE_BIT(DATA, POS, VAL) \
00188     do { \
00189         if (VAL) *((uint8_t *) (DATA)) |=  (1 << (POS)); \
00190         else     *((uint8_t *) (DATA)) &= ~(1 << (POS)); \
00191     } while (0)
00192 
00193 /******************************************************************************
00194  *  Read macros
00195  *****************************************************************************/
00196 
00202 #define EC_READ_U8(DATA) \
00203     ((uint8_t) *((uint8_t *) (DATA)))
00204 
00211 #define EC_READ_S8(DATA) \
00212      ((int8_t) *((uint8_t *) (DATA)))
00213 
00220 #define EC_READ_U16(DATA) \
00221      ((uint16_t) le16_to_cpup((void *) (DATA)))
00222 
00229 #define EC_READ_S16(DATA) \
00230      ((int16_t) le16_to_cpup((void *) (DATA)))
00231 
00238 #define EC_READ_U32(DATA) \
00239      ((uint32_t) le32_to_cpup((void *) (DATA)))
00240 
00247 #define EC_READ_S32(DATA) \
00248      ((int32_t) le32_to_cpup((void *) (DATA)))
00249 
00250 
00251 /******************************************************************************
00252  *  Write macros
00253  *****************************************************************************/
00254 
00261 #define EC_WRITE_U8(DATA, VAL) \
00262     do { \
00263         *((uint8_t *)(DATA)) = ((uint8_t) (VAL)); \
00264     } while (0)
00265 
00272 #define EC_WRITE_S8(DATA, VAL) EC_WRITE_U8(DATA, VAL)
00273 
00280 #define EC_WRITE_U16(DATA, VAL) \
00281     do { \
00282         *((uint16_t *) (DATA)) = (uint16_t) (VAL); \
00283         cpu_to_le16s(DATA); \
00284     } while (0)
00285 
00292 #define EC_WRITE_S16(DATA, VAL) EC_WRITE_U16(DATA, VAL)
00293 
00300 #define EC_WRITE_U32(DATA, VAL) \
00301     do { \
00302         *((uint32_t *) (DATA)) = (uint32_t) (VAL); \
00303         cpu_to_le16s(DATA); \
00304     } while (0)
00305 
00312 #define EC_WRITE_S32(DATA, VAL) EC_WRITE_U32(DATA, VAL)
00313 
00314 /*****************************************************************************/
00315 
00316 #endif

Generated on Tue Nov 7 15:03:35 2006 for IgH EtherCAT master by  doxygen 1.4.4