ecrt.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  *  $Id: ecrt.h 495 2006-08-03 12:59:01Z 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 
00089 /******************************************************************************
00090  *  Master request functions
00091  *****************************************************************************/
00092 
00093 ec_master_t *ecrt_request_master(unsigned int master_index);
00094 void ecrt_release_master(ec_master_t *master);
00095 
00096 /******************************************************************************
00097  *  Master methods
00098  *****************************************************************************/
00099 
00100 void ecrt_master_callbacks(ec_master_t *master, int (*request_cb)(void *),
00101                            void (*release_cb)(void *), void *cb_data);
00102 
00103 ec_domain_t *ecrt_master_create_domain(ec_master_t *master);
00104 
00105 int ecrt_master_activate(ec_master_t *master);
00106 void ecrt_master_deactivate(ec_master_t *master);
00107 
00108 void ecrt_master_prepare(ec_master_t *master);
00109 
00110 void ecrt_master_send(ec_master_t *master);
00111 void ecrt_master_receive(ec_master_t *master);
00112 
00113 void ecrt_master_run(ec_master_t *master);
00114 
00115 ec_slave_t *ecrt_master_get_slave(const ec_master_t *, const char *);
00116 
00117 int ecrt_master_state(const ec_master_t *master);
00118 
00119 /******************************************************************************
00120  *  Domain Methods
00121  *****************************************************************************/
00122 
00123 ec_slave_t *ecrt_domain_register_pdo(ec_domain_t *domain,
00124                                      const char *address,
00125                                      uint32_t vendor_id,
00126                                      uint32_t product_code,
00127                                      uint16_t pdo_index,
00128                                      uint8_t pdo_subindex,
00129                                      void **data_ptr);
00130 int ecrt_domain_register_pdo_list(ec_domain_t *domain,
00131                                   const ec_pdo_reg_t *pdos);
00132 
00133 void ecrt_domain_process(ec_domain_t *domain);
00134 int ecrt_domain_state(const ec_domain_t *domain);
00135 
00136 /******************************************************************************
00137  *  Slave Methods
00138  *****************************************************************************/
00139 
00140 int ecrt_slave_conf_sdo8(ec_slave_t *slave, uint16_t sdo_index,
00141                          uint8_t sdo_subindex, uint8_t value);
00142 int ecrt_slave_conf_sdo16(ec_slave_t *slave, uint16_t sdo_index,
00143                           uint8_t sdo_subindex, uint16_t value);
00144 int ecrt_slave_conf_sdo32(ec_slave_t *slave, uint16_t sdo_index,
00145                           uint8_t sdo_subindex, uint32_t value);
00146 
00147 int ecrt_slave_pdo_size(ec_slave_t *slave, uint16_t pdo_index,
00148                         uint8_t pdo_subindex, size_t size);
00149 
00150 /******************************************************************************
00151  *  Bitwise read/write macros
00152  *****************************************************************************/
00153 
00160 #define EC_READ_BIT(DATA, POS) ((*((uint8_t *) (DATA)) >> (POS)) & 0x01)
00161 
00169 #define EC_WRITE_BIT(DATA, POS, VAL) \
00170     do { \
00171         if (VAL) *((uint8_t *) (DATA)) |=  (1 << (POS)); \
00172         else     *((uint8_t *) (DATA)) &= ~(1 << (POS)); \
00173     } while (0)
00174 
00175 /******************************************************************************
00176  *  Read macros
00177  *****************************************************************************/
00178 
00184 #define EC_READ_U8(DATA) \
00185     ((uint8_t) *((uint8_t *) (DATA)))
00186 
00193 #define EC_READ_S8(DATA) \
00194      ((int8_t) *((uint8_t *) (DATA)))
00195 
00202 #define EC_READ_U16(DATA) \
00203      ((uint16_t) le16_to_cpup((void *) (DATA)))
00204 
00211 #define EC_READ_S16(DATA) \
00212      ((int16_t) le16_to_cpup((void *) (DATA)))
00213 
00220 #define EC_READ_U32(DATA) \
00221      ((uint32_t) le32_to_cpup((void *) (DATA)))
00222 
00229 #define EC_READ_S32(DATA) \
00230      ((int32_t) le32_to_cpup((void *) (DATA)))
00231 
00232 
00233 /******************************************************************************
00234  *  Write macros
00235  *****************************************************************************/
00236 
00243 #define EC_WRITE_U8(DATA, VAL) \
00244     do { \
00245         *((uint8_t *)(DATA)) = ((uint8_t) (VAL)); \
00246     } while (0)
00247 
00254 #define EC_WRITE_S8(DATA, VAL) EC_WRITE_U8(DATA, VAL)
00255 
00262 #define EC_WRITE_U16(DATA, VAL) \
00263     do { \
00264         *((uint16_t *) (DATA)) = (uint16_t) (VAL); \
00265         cpu_to_le16s(DATA); \
00266     } while (0)
00267 
00274 #define EC_WRITE_S16(DATA, VAL) EC_WRITE_U16(DATA, VAL)
00275 
00282 #define EC_WRITE_U32(DATA, VAL) \
00283     do { \
00284         *((uint32_t *) (DATA)) = (uint32_t) (VAL); \
00285         cpu_to_le16s(DATA); \
00286     } while (0)
00287 
00294 #define EC_WRITE_S32(DATA, VAL) EC_WRITE_U32(DATA, VAL)
00295 
00296 /*****************************************************************************/
00297 
00298 #endif

Generated on Fri Sep 1 14:56:56 2006 for IgH EtherCAT master by  doxygen 1.4.6