Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

cosyfifo.h

Go to the documentation of this file.
00001 /*--------------------------------------------------------------------
00002  *
00003  * (C) Copyright Koninklijke Philips Electronics NV 2006. 
00004  * All rights reserved. This software is licensed under the terms of
00005  * version 2.1 of the GNU Lesser General Public License as published 
00006  * by the Free Software Foundation. For licensing and warranty
00007  * information, see the file COPYING in the main directory.
00008  *
00009  *------------------------------------------------------------------*/
00010 
00011 #ifndef COSYFIFO_H
00012 #define COSYFIFO_H
00013 
00014 #include "rte.h"
00015 #include "rtefifo.h"
00016 #include "bqueue.h"
00017 #include "semaphoreapi.h"
00018 #ifdef PREEMPTIVE
00019 #include "mutexapi.h"
00020 #endif
00021 
00022 enum FifoMetric
00023 {
00024         MinSize, MaxSize,
00025         Size, Data, Room,
00026         TokensWritten, TokensRead,
00027         WriteCalls, ReadCalls,
00028         TokensPerWrite, TokensPerRead,
00029         TokenSize,
00030         BytesWritten, BytesRead,
00031         PendingWriteTokens, PendingReadTokens,
00032   NeededWriteTokens, NeededReadTokens
00033 };
00034 
00035 class cosySelect;
00036 
00037 class cosyFifo : public rteFifo
00038 {
00039 
00040 public:
00041   cosyFifo(FifoImpl& f, cosyRte& r);
00042 
00043   void read(void* p, unsigned int nitems);
00044   void write(const void* p, unsigned int nitems);
00045   
00046   unsigned int size() const;
00047   unsigned int data() const;
00048   unsigned int room() const;
00049 
00050 private:  
00051   cosyRte* rte;
00052 
00053   unsigned int minSize;   // minimum size
00054   unsigned int maxSize;   // maximum size
00055 
00056   unsigned int countw;    // number of tokens written
00057   unsigned int countr;    // number of tokens read
00058   unsigned int wcount;    // number of write calls
00059   unsigned int rcount;    // number of read calls
00060 
00061   static unsigned int defaultMinSize;
00062   static unsigned int defaultMaxSize;
00063   static unsigned int defaultBytes;
00064 
00065   static const char* getMetricName(FifoMetric m);
00066   unsigned int getMetricValue(FifoMetric m);
00067 
00068   unsigned int calcSize(unsigned int lo, unsigned int hi, unsigned int s);
00069 
00070   bool grow();
00071 
00072   bqueue q;
00073   char* wp;
00074   char* rp;
00075   
00076   unsigned int    wn;     // pending write tokens
00077   unsigned int    rn;     // pending read tokens
00078 
00079   unsigned int  ws; // select tokens
00080   unsigned int  rs; // select tokens
00081   
00082   bool    block;  // writer blocked
00083   Semaphore   sema; // binary semaphore
00084 
00085   friend class cosySelect;
00086   cosySelect* sel;
00087 
00088 #ifdef PREEMPTIVE
00089   Mutex mutex;
00090   void lock();
00091   void unlock();
00092 #endif
00093 
00094   friend class cosyNetwork;
00095 };
00096 
00097 #endif

Generated on Wed Feb 15 14:52:38 2006 for yapi by doxygen 1.3.2