4 * Created on: Mar 3, 2009
8 #ifndef FASTCOMMUNICATION_H_
9 #define FASTCOMMUNICATION_H_
12 #include <spu_intrinsics.h>
13 #include <spu_mfcio.h>
25 #include "WindowedFifo.h"
26 #include "../common.h"
28 // For external Mailbox Communication
29 #include "../spu_mfcio_ext.h"
31 // Include to allocate/free using for DMA transfers
32 #include "../lib/malloc_align.h"
33 #include "../lib/free_align.h"
36 #define waittag(tag_id) mfc_write_tag_mask(1<<tag_id); mfc_read_tag_status_all();
40 // This is a full Request
41 typedef struct _comRequest {
42 bool valid; // If the request is valid
43 uint32_t status; // Status of the request (read_..., ...)
45 uint32_t tag_id; // Tag ID
46 uint32_t queue; // The queue which is used by the request
48 bool iswfifo; // True if it is a WFIFO
49 Fifo* fifo; // Pointer to the used FIFO
50 WindowedFifo* wfifo; // Pointer to the WFIFO
52 uint32_t len; // The len of the data
53 char* data; // Point to the data which are stored
54 uint32_t offset; // Offset generated by alignment
57 // Struct to store a FIFO
58 typedef struct _fifoCollection {
59 int type; // local, in or out
60 int queue; // Corresponding queue number
62 bool iswfifo; // True if it is a WFIFO
63 WindowedFifo* wfifo; // Pointer to the WFIFO
64 Fifo* fifo; // Pointer to the FIFO
68 * The Communication Class
70 class FastCommunication {
72 FastCommunication(int nrOfQueues, uint64_t ea_base, uint64_t *ea_base_all, int32_t * queueFromSPE, int32_t * queueOnSPE, uint64_t * fifoTails);
73 virtual ~FastCommunication();
75 bool addFifo(int fifoNr, Fifo* fifo, int type, int queue);
76 bool addWFifo(int fifoNr, WindowedFifo* fifo, int type, int queue);
81 static int const local = 0;
82 static int const in = 1;
83 static int const out = 2;
85 static int const comIn = 0;
86 static int const comOut = 1;
88 static int const read_request_sent = 0;
89 static int const read_started = 1;
90 static int const read_pending = 2;
94 void sendMessage(uint32_t message, int32_t process);
95 int testMessage(int32_t process);
98 comRequest* newRequest();
99 void deleteRequest(comRequest* request);
100 comRequest* getRequest(uint8_t status, uint32_t queue);
104 fifoCollection * _fifos;
107 int _nrOfRequest; // Need only 2 requests per queue (others are blocked...)
108 comRequest _request[MAXNOREQ]; // Stores at maximum 12 requests
109 uint8_t _currentRequest; // The current request (so that we can start in the next iteration by the next one)
111 // Pointers for communication
112 uint64_t _ea_base; // This is my base address
113 uint64_t * _ea_base_all; // All base addresses of the control blocks of the other SPEs (for sending message to)
114 int32_t * queueFromSPE; // Array which tells us from which processor a queue comes
115 int32_t * queueOnSPE; // Array which tells us to which processor a queue goes
116 uint64_t * _fifoTails; // Pointers to the tail of the other queues
119 #endif /* FASTCOMMUNICATION_H_ */