Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

l1394_node.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           l1394node.cpp  -  description
00003                              -------------------
00004     begin                : Wed Jul 5 2000
00005     copyright            : (C) 2000-2004 by Michael Repplinger
00006     email                : repplix@studcs.uni-sb.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "l1394_node.h"
00019 #include "l1394_card.h"
00020 //#include <stdio.h>
00021 
00022 using std::hex;
00023 using std::dec;
00024 
00025 namespace L1394{
00026 using namespace internal;
00027 Node::Node(const u_int32_t node_id, const Card* parent)
00028 {
00029   __node_id           = node_id;
00030   __parent            = parent;
00031   __reference_counter = 0;
00032   __state             = ENABLED;
00033   __node_type         = _UnknownNode;
00034   __guid              = 0;
00035   __event             = new Event(this);
00036     message           = SMessage::getInstance();
00037 }
00038 
00039 
00040 Node::~Node() {
00041   delete __event;
00042 }
00043 
00044 
00045 void Node::readGuid() {
00046   Quadlet tmp;
00047   read(CSR_REGISTER_BASE+CSR_CONFIG_ROM+0x0c, &tmp);
00048 
00049   __guid = tmp.toInt();
00050   __guid = __guid << 32;
00051 
00052   read(CSR_REGISTER_BASE+CSR_CONFIG_ROM+0x10, &tmp);
00053 
00054   __guid = __guid | tmp.toInt();
00055 
00056     message->debugStream() << "Node > GUID from node " << __node_id << " : 0x" << hex << __guid << dec << endl;
00057 }
00058 
00059 
00060 int Node::read(const u_int64_t address, Quadlet* response) const
00061 {
00062   if (__state == DISABLED)  {
00063     message->warningStream() << "Node > Node object is not active " << endl;
00064     return L1394_FAILED;
00065   }
00066   int resp_code = __parent->requestTransaction()->read(address, response, __node_id);
00067   __parent->releaseTransaction();
00068   return resp_code;
00069 }
00070 
00071 
00072 int Node::write(const u_int64_t address,const Quadlet& data) const
00073 {
00074   if (__state == DISABLED)  {
00075     message->warningStream() << " Node > object is not active " << endl;
00076     return L1394_FAILED;
00077   }
00078 
00079   int resp_code = __parent->requestTransaction()->write(address, data, __node_id);
00080   __parent->releaseTransaction();
00081   return resp_code;
00082 }
00083 
00084 
00085 int Node::lock(const u_int64_t address,const Quadlet& data,const unsigned int extcode, const Quadlet& argument, Quadlet* result) const
00086 {
00087   if (__state == DISABLED)  {
00088     message->warningStream() << " Node > Node object is not active " << endl;
00089     return L1394_FAILED;
00090   }
00091 
00092   int resp_code = __parent->requestTransaction()->lock(address, data, extcode, argument, result, __node_id);
00093   __parent->releaseTransaction();
00094   return resp_code;
00095 }
00096 
00097 void Node::setEvent(Event* event) {
00098   __event = event;
00099 }
00100 
00101 void Node::setState(const NodeState s)
00102 {
00103   if(  __state != s )  {
00104     __state = s;
00105     switch(__state)  {
00106       case ENABLED  :
00107         __event->call(NODE_ENABLED);
00108         break;
00109 
00110       case DISABLED :
00111         __event->call(NODE_DISABLED);
00112         break;
00113       default:
00114         message->errorStream() << "Node > no valid state " << endl;
00115         break;
00116     }
00117   }
00118 }
00119 
00120 
00121 /*int Node::allocateIsoChannel(const int channel)
00122 {
00123   if (channel < 1 && channel > 64)
00124     return L1394_FAILED;
00125 
00126   if (channel<=32)
00127   {
00128     if (low_iso_channel.getBit(channel-1) == 1)
00129       return L1394_FAILED;
00130     else
00131     {
00132       low_iso_channel.setBit(channel-1, 1);
00133       return L1394_SUCCESS;
00134     }
00135   }
00136 
00137   if (channel >32)
00138   {
00139     if (high_iso_channel.getBit(channel-33) == 1)
00140       return L1394_FAILED;
00141     else
00142     {
00143       high_iso_channel.setBit(channel-33, 1);
00144       return L1394_SUCCESS;
00145     }
00146   }
00147   return L1394_FAILED;
00148 }
00149 
00150 int Node::releaseIsoChannel(const int channel)
00151 {
00152   if (channel < 1 && channel > 64)
00153     return L1394_FAILED;
00154 
00155   if (channel<=32)
00156     low_iso_channel.setBit(channel-1, 0);
00157 
00158   if (channel >32)
00159     high_iso_channel.setBit(channel-33, 0);
00160 
00161   return L1394_SUCCESS;
00162 
00163 }
00164 */
00165 int Node::increaseRefCount()
00166 {
00167   ++__reference_counter;
00168   if (__reference_counter > 0) {
00169     setState(ENABLED);
00170   }
00171   return __reference_counter;
00172 }
00173 
00174 
00175 int Node::decreaseRefCount()
00176 {
00177   --__reference_counter;
00178   if (__reference_counter <= 0)  {
00179     __reference_counter = 0;
00180     setState(DISABLED);
00181   }
00182   return __reference_counter;
00183 }
00184 
00185 
00186 u_int32_t Node::getCardID() const {
00187   return __parent->getCardID();
00188 }
00189 
00190 
00191 const char* Node::char_node_type[] =
00192     {"Unknown node", "IEEE-Card", "FCP-Node", "Dcc-Node", "SBP2-Node",
00193      "PHY-only Node"};
00194 
00195 u_int32_t* Node::reset_counter_array = new u_int32_t [16];
00196 
00197 
00198 }//namespace L1394
00199 
00200 

Generated on Wed Aug 24 00:36:40 2005 for L1394 by doxygen 1.4.2
L1394 library (NMM) grahics.cs.uni-sb.de/~repplix/l1394_home/