wg_mailbox.h
Go to the documentation of this file.
00001 /*********************************************************************
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2008, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the Willow Garage nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *********************************************************************/
00034 
00035 #pragma once
00036 
00037 #include "ethercat_hardware/ethercat_com.h"
00038 #include <diagnostic_updater/DiagnosticStatusWrapper.h>
00039 
00040 namespace ethercat_hardware
00041 {
00042 
00043 
00044 struct MbxDiagnostics 
00045 {
00046   MbxDiagnostics();
00047   uint32_t write_errors_;
00048   uint32_t read_errors_;
00049   uint32_t lock_errors_;
00050   uint32_t retries_;
00051   uint32_t retry_errors_;
00052 };
00053 
00054 
00055 class WGMailbox
00056 {
00057 public:
00058   WGMailbox();
00059 
00060   bool initialize(EtherCAT_SlaveHandler *sh);
00061   int writeMailbox(EthercatCom *com, unsigned address, void const *data, unsigned length);
00062   int readMailbox(EthercatCom *com, unsigned address, void *data, unsigned length);
00063   void publishMailboxDiagnostics(diagnostic_updater::DiagnosticStatusWrapper &d);
00064 
00065   static const unsigned MBX_COMMAND_PHY_ADDR = 0x1400;
00066   static const unsigned MBX_COMMAND_SIZE = 512;
00067   static const unsigned MBX_STATUS_PHY_ADDR = 0x2400;
00068   static const unsigned MBX_STATUS_SIZE = 512;
00069 
00070   static const unsigned MBX_COMMAND_SYNCMAN_NUM = 2;
00071   static const unsigned MBX_STATUS_SYNCMAN_NUM  = 3;
00072 
00073 protected:
00074   // Each WG0X device can only support one mailbox operation at a time
00075   bool lockMailbox();
00076   void unlockMailbox();
00077   pthread_mutex_t mailbox_lock_;
00078   MbxDiagnostics mailbox_diagnostics_;
00079   MbxDiagnostics mailbox_publish_diagnostics_;
00080 
00081   // Mailbox helper functions
00082   int writeMailbox_(EthercatCom *com, unsigned address, void const *data, unsigned length);
00083   int readMailbox_(EthercatCom *com, unsigned address, void *data, unsigned length);  
00084   bool verifyDeviceStateForMailboxOperation();
00085   bool clearReadMailbox(EthercatCom *com);
00086   bool waitForReadMailboxReady(EthercatCom *com);
00087   bool waitForWriteMailboxReady(EthercatCom *com);
00088   bool readMailboxRepeatRequest(EthercatCom *com);
00089   bool _readMailboxRepeatRequest(EthercatCom *com);
00090   bool writeMailboxInternal(EthercatCom *com, void const *data, unsigned length);
00091   bool readMailboxInternal(EthercatCom *com, void *data, unsigned length);
00092   void diagnoseMailboxError(EthercatCom *com);
00093   
00094   EtherCAT_SlaveHandler *sh_;
00095 };
00096 
00097 
00098 }; //end namespace ethercat_hardware


ethercat_hardware
Author(s): Rob Wheeler (email: wheeler@willowgarage.com), Maintained by Derek King (email: dking@willowgarage.com)
autogenerated on Thu Apr 24 2014 15:43:45