dol: initial dol commit
[jump.git] / dol / src / dol / visitor / cell / lib / spu / WindowedFifo.h
1 #ifndef _WINDOWEDFIFO_H_
2 #define _WINDOWEDFIFO_H_
3
4 #include <stdio.h>
5 #include <string.h>
6
7 #include "../constant.h"
8
9 #include "../lib/malloc_align.h"
10 #include "../lib/free_align.h"
11
12 class WindowedFifo {
13     public:
14         WindowedFifo(unsigned size);
15         virtual ~WindowedFifo();
16
17         // Write
18                 virtual unsigned reserve(char** destination, unsigned len);
19         virtual void release();
20
21                 // Read
22         virtual unsigned capture(char** destination, unsigned len);
23         virtual void consume();
24
25                 // General functions
26         virtual unsigned used() const;
27         virtual unsigned unused() const;
28         virtual unsigned size() const;
29
30                 // DMA functions
31         virtual char *getQueuePointer();
32         virtual void dmaRead(unsigned len);
33         virtual unsigned dmaStart();
34         virtual bool dmaAllowed();
35                 virtual unsigned dmaWrite(const void *source, unsigned len);
36
37                 // Global variables
38                 unsigned _inTail;
39
40     protected:
41         char *_buffer;          // Pointer to the buffer
42         
43                 unsigned _head;         // Current position of the head
44         unsigned _tail;         // Current position of the tail
45         unsigned _headRoom;     // HeadRoom pointer 
46         unsigned _tailRoom;     // Tailroom pointer
47         
48                 unsigned _size;         // Total space of the buffer
49         unsigned _use;          // How many data are used in the buffer
50         unsigned _writeReserve; // Number of tokens one is writing
51         unsigned _readReserve;  // Number of tokens one is reading
52         
53                 bool _isHeadReserved;   // Head reserved?
54         bool _isTailReserved;   // Tail reserved?
55
56                 unsigned _blocked;      // Blocked number the request has to wait
57         bool _activeDMA;        // Is there an active DMA on this buffer
58 };
59
60 #endif