wg_util.h
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2008, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 #pragma once
36 
37 #include <stdint.h>
40 
41 namespace ethercat_hardware
42 {
43 
44 // Syncmanger control register 0x804+N*8
45 struct SyncManControl {
46  union {
47  uint8_t raw;
48  struct {
49  uint8_t mode : 2;
50  uint8_t direction : 2;
51  uint8_t ecat_irq_enable : 1;
52  uint8_t pdi_irq_enable : 1;
53  uint8_t watchdog_enable : 1;
54  uint8_t res1 : 1;
55  } __attribute__ ((__packed__));
56  } __attribute__ ((__packed__));
57  //static const unsigned BASE_ADDR=0x804;
58  //static unsigned base_addr(unsigned num);
59  //void print(std::ostream &os=std::cout) const;
60 } __attribute__ ((__packed__));
61 
62 // Syncmanger status register 0x805+N*8
63 struct SyncManStatus {
64  union {
65  uint8_t raw;
66  struct {
67  uint8_t interrupt_write : 1;
68  uint8_t interrupt_read : 1;
69  uint8_t res1 : 1;
70  uint8_t mailbox_status : 1;
71  uint8_t buffer_status : 2;
72  uint8_t res2 : 2;
73  } __attribute__ ((__packed__));
74  } __attribute__ ((__packed__));
75  //static const unsigned BASE_ADDR=0x805;
76  //static unsigned base_addr(unsigned num);
77  //void print(std::ostream &os=std::cout) const;
78 } __attribute__ ((__packed__));
79 
80 // Syncmanger activation register 0x806+N*8
81 struct SyncManActivate {
82  union {
83  uint8_t raw;
84  struct {
85  uint8_t enable : 1;
86  uint8_t repeat_request : 1;
87  uint8_t res4 : 4;
88  uint8_t ecat_latch_event : 1;
89  uint8_t pdi_latch_event : 1;
90  } __attribute__ ((__packed__));
91  } __attribute__ ((__packed__));
92  static const unsigned BASE_ADDR=0x806;
93  static unsigned baseAddress(unsigned num);
94  //void print(std::ostream &os=std::cout) const;
95  bool writeData(EthercatCom *com, EtherCAT_SlaveHandler *sh, EthercatDevice::AddrMode addrMode, unsigned num) const;
96 } __attribute__ ((__packed__));
97 
98 // Syncmanger PDI control register 0x807+N*8
99 struct SyncManPDIControl {
100  union {
101  uint8_t raw;
102  struct {
103  uint8_t deactivate : 1;
104  uint8_t repeat_ack : 1;
105  uint8_t res6 : 6;
106  } __attribute__ ((__packed__));
107  } __attribute__ ((__packed__));
108  //static const unsigned BASE_ADDR=0x807;
109  //static unsigned base_addr(unsigned num);
110  //void print(std::ostream &os=std::cout) const;
111 } __attribute__ ((__packed__));
112 
113 
114 // For SyncManager settings REG 0x800+8*N
115 struct SyncMan {
116  union {
117  uint8_t raw[8];
118  struct {
119  uint16_t start_addr;
120  uint16_t length;
125  } __attribute__ ((__packed__));
126  } __attribute__ ((__packed__));
127 
128  // Base address for first syncmanager
129  static const unsigned BASE_ADDR=0x800;
130  // Base address of Nth syncmanager for N=0-7
131  static unsigned baseAddress(unsigned num);
132 
133  bool readData(EthercatCom *com, EtherCAT_SlaveHandler *sh, EthercatDevice::AddrMode addrMode, unsigned num);
134  //void print(unsigned num, std::ostream &os=std::cout) const;
135 } __attribute__ ((__packed__));
136 
137 namespace wg_util
138 {
139 unsigned computeChecksum(void const *data, unsigned length);
140 unsigned int rotateRight8(unsigned in);
141 };
142 
143 }; // end namespace ethercat_hardware
EthercatCom
Definition: ethercat_com.h:44
ethercat_hardware::SyncManActivate::baseAddress
static unsigned baseAddress(unsigned num)
Definition: wg_util.cpp:118
ethercat_hardware::SyncManControl::watchdog_enable
uint8_t watchdog_enable
Definition: wg_util.h:149
ethercat_hardware::SyncManStatus::res2
uint8_t res2
Definition: wg_util.h:104
ethercat_hardware::SyncManStatus::__attribute__
union ethercat_hardware::SyncManStatus::@28 __attribute__((__packed__))
ethercat_hardware::SyncManStatus::buffer_status
uint8_t buffer_status
Definition: wg_util.h:103
ethercat_hardware::SyncMan
Definition: wg_util.h:147
ethercat_hardware::SyncManActivate::pdi_latch_event
uint8_t pdi_latch_event
Definition: wg_util.h:121
ethercat_hardware::SyncMan::status
SyncManStatus status
Definition: wg_util.h:154
ethercat_hardware::SyncManActivate::BASE_ADDR
static const unsigned BASE_ADDR
Definition: wg_util.h:124
EthercatDevice::AddrMode
AddrMode
Definition: ethercat_device.h:189
ethercat_hardware::SyncManStatus
Definition: wg_util.h:95
ethercat_hardware::SyncManActivate
Definition: wg_util.h:113
ethercat_hardware::SyncManControl::res1
uint8_t res1
Definition: wg_util.h:150
ethercat_hardware
Definition: motor_heating_model.h:53
ethercat_hardware::SyncMan::raw
uint8_t raw[8]
Definition: wg_util.h:149
ethercat_hardware::SyncManControl::direction
uint8_t direction
Definition: wg_util.h:146
ethercat_hardware::SyncMan::control
SyncManControl control
Definition: wg_util.h:153
ethercat_hardware::SyncManActivate::ecat_latch_event
uint8_t ecat_latch_event
Definition: wg_util.h:120
data
data
ethercat_hardware::SyncManPDIControl::__attribute__
union ethercat_hardware::SyncManPDIControl::@40 __attribute__((__packed__))
ethercat_hardware::SyncManControl
Definition: wg_util.h:77
ethercat_com.h
ethercat_hardware::SyncManStatus::interrupt_write
uint8_t interrupt_write
Definition: wg_util.h:99
ethercat_hardware::SyncManActivate::__attribute__
union ethercat_hardware::SyncManActivate::@34 __attribute__((__packed__))
ethercat_hardware::SyncManPDIControl
Definition: wg_util.h:131
ethercat_hardware::wg_util::computeChecksum
unsigned computeChecksum(void const *data, unsigned length)
Definition: wg_util.cpp:81
ethercat_hardware::SyncMan::BASE_ADDR
static const unsigned BASE_ADDR
Definition: wg_util.h:161
ethercat_hardware::SyncManControl::ecat_irq_enable
uint8_t ecat_irq_enable
Definition: wg_util.h:147
ethercat_hardware::SyncManControl::pdi_irq_enable
uint8_t pdi_irq_enable
Definition: wg_util.h:148
ethercat_hardware::SyncMan::start_addr
uint16_t start_addr
Definition: wg_util.h:151
ethercat_hardware::SyncManActivate::res4
uint8_t res4
Definition: wg_util.h:119
ethercat_hardware::SyncManPDIControl::deactivate
uint8_t deactivate
Definition: wg_util.h:135
ethercat_hardware::SyncManControl::mode
uint8_t mode
Definition: wg_util.h:145
ethercat_hardware::SyncMan::readData
bool readData(EthercatCom *com, EtherCAT_SlaveHandler *sh, EthercatDevice::AddrMode addrMode, unsigned num)
Read data from Sync Manager.
Definition: wg_util.cpp:112
ethercat_hardware::SyncManPDIControl::res6
uint8_t res6
Definition: wg_util.h:137
ethercat_device.h
ethercat_hardware::SyncMan::__attribute__
union ethercat_hardware::SyncMan::@46 __attribute__((__packed__))
ethercat_hardware::__attribute__
ethercat_hardware::MotorHeatingModelCommon __attribute__
ethercat_hardware::SyncManPDIControl::raw
uint8_t raw
Definition: wg_util.h:133
ethercat_hardware::SyncManStatus::raw
uint8_t raw
Definition: wg_util.h:97
ethercat_hardware::SyncManPDIControl::repeat_ack
uint8_t repeat_ack
Definition: wg_util.h:136
ethercat_hardware::SyncManStatus::res1
uint8_t res1
Definition: wg_util.h:101
length
uint16_t length
Definition: wg_util.h:151
ethercat_hardware::SyncManStatus::interrupt_read
uint8_t interrupt_read
Definition: wg_util.h:100
ethercat_hardware::SyncMan::pdi_control
SyncManPDIControl pdi_control
Definition: wg_util.h:156
ethercat_hardware::SyncMan::length
uint16_t length
Definition: wg_util.h:152
ethercat_hardware::SyncMan::activate
SyncManActivate activate
Definition: wg_util.h:155
ethercat_hardware::SyncManActivate::writeData
bool writeData(EthercatCom *com, EtherCAT_SlaveHandler *sh, EthercatDevice::AddrMode addrMode, unsigned num) const
Write data to Sync Manager Activation register.
Definition: wg_util.cpp:133
ethercat_hardware::SyncManActivate::raw
uint8_t raw
Definition: wg_util.h:115
ethercat_hardware::SyncManActivate::enable
uint8_t enable
Definition: wg_util.h:117
ethercat_hardware::SyncManControl::raw
uint8_t raw
Definition: wg_util.h:143
ethercat_hardware::SyncManStatus::mailbox_status
uint8_t mailbox_status
Definition: wg_util.h:102
ethercat_hardware::SyncMan::baseAddress
static unsigned baseAddress(unsigned num)
Definition: wg_util.cpp:96
ethercat_hardware::SyncManControl::__attribute__
union ethercat_hardware::SyncManControl::@22 __attribute__((__packed__))
ethercat_hardware::wg_util::rotateRight8
unsigned int rotateRight8(unsigned in)
Definition: wg_util.cpp:73
ethercat_hardware::SyncManActivate::repeat_request
uint8_t repeat_request
Definition: wg_util.h:118


ethercat_hardware
Author(s): Rob Wheeler , Derek King
autogenerated on Sun Apr 2 2023 02:44:04