/* cblsrv is covered by the LGPL: This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. Copyright (c) 2006 Zoltan Csizmadia All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef _CABLE_H_INCLUDED_ #define _CABLE_H_INCLUDED_ #include "bits.h" #include "long_bits.h" // TAP states #define TAPSTATE_RESET 0x00 #define TAPSTATE_IDLE 0x01 #define TAPSTATE_SELECTDR 0x02 #define TAPSTATE_CAPTUREDR 0x03 #define TAPSTATE_SHIFTDR 0x04 #define TAPSTATE_EXIT1DR 0x05 #define TAPSTATE_PAUSEDR 0x06 #define TAPSTATE_EXIT2DR 0x07 #define TAPSTATE_UPDATEDR 0x08 #define TAPSTATE_IRSTATES 0x09 #define TAPSTATE_SELECTIR 0x09 #define TAPSTATE_CAPTUREIR 0x0A #define TAPSTATE_SHIFTIR 0x0B #define TAPSTATE_EXIT1IR 0x0C #define TAPSTATE_PAUSEIR 0x0D #define TAPSTATE_EXIT2IR 0x0E #define TAPSTATE_UPDATEIR 0x0F class cable{ public: enum res_t { res_success = 0, res_fail = -1 }; int previous_shift_mode; typedef LongBits longbits_t; longbits_t wbuf_cache; cable(); virtual ~cable(); public: virtual res_t open() = 0; virtual res_t close() = 0; virtual int get_desc(char* desc, int len) = 0; virtual res_t set_option(const char* name, const char* value); virtual res_t get_option(const char* name, char* value, int len); virtual res_t set_tms(int) = 0; virtual res_t set_tck(int) = 0; virtual res_t pulse_tck(int) = 0; virtual res_t state_transit(int state_from, int state_to) = 0; virtual res_t shift(int num_bits, const void* wbuff, void* rbuff, bool exit_shift_state) = 0; public: static int tms_transition(int state_from, int state_to, u32* tms_seq); public: virtual res_t write(int mode, bits& wbuff, bits& wmask, bits& cmp_rbuff, bits& cmp_rmask); public: bits& get_last_rbuff(); protected: bits hir; bits hdr; bits tir; bits tdr; bits last_rbuff; }; class tms_manual_controlled_cable : public cable{ public: tms_manual_controlled_cable() : cable() {} virtual ~tms_manual_controlled_cable() {} virtual cable::res_t shift_tms(u32 tms_seq, int count) = 0; cable::res_t state_transit(int state_from, int state_to){ u32 pre_tms = 0; int pre_tms_count = 0; pre_tms_count = cable::tms_transition(state_from, state_to, &pre_tms); if(pre_tms_count > 0){ return shift_tms(pre_tms, pre_tms_count); } return pre_tms_count < 0 ? cable::res_fail : cable::res_success; } }; #endif