image/svg+xml
Brteve's API for EveApps
Version 0.0.1
The reference document for common folder of EveApps project.
 
Loading...
Searching...
No Matches
EVE_MediaFifo.h File Reference

EVE's mediafifo controller. More...

#include "EVE_HalDefs.h"

Go to the source code of this file.

Functions

EVE_HAL_EXPORT bool EVE_MediaFifo_set (EVE_HalContext *phost, uint32_t address, uint32_t size)
 Set the media FIFO.
 
EVE_HAL_EXPORT void EVE_MediaFifo_close (EVE_HalContext *phost)
 
EVE_HAL_EXPORT uint32_t EVE_MediaFifo_rp (EVE_HalContext *phost)
 Get the current read pointer.
 
EVE_HAL_EXPORT uint32_t EVE_MediaFifo_wp (EVE_HalContext *phost)
 Get the current write pointer.
 
EVE_HAL_EXPORT uint32_t EVE_MediaFifo_space (EVE_HalContext *phost)
 Get the currently available space.
 
EVE_HAL_EXPORT bool EVE_MediaFifo_wrMem (EVE_HalContext *phost, const uint8_t *buffer, uint32_t size, uint32_t *transfered)
 Write a buffer to the media FIFO. Waits if there is not enough space in the media FIFO.
 
EVE_HAL_EXPORT bool EVE_MediaFifo_waitFlush (EVE_HalContext *phost, bool orCmdFlush)
 Wait for the media FIFO to fully empty.
 
EVE_HAL_EXPORT uint32_t EVE_MediaFifo_waitSpace (EVE_HalContext *phost, uint32_t size, bool orCmdFlush)
 Wait for the media FIFO to have at least the requested amount of free space.
 

Detailed Description

EVE's mediafifo controller.

This file defines the generic APIs of phost access layer for the FT800 or EVE compatible silicon. Application shall access FT800 or EVE resources over these APIs,regardless of I2C or SPI protocol. In addition, there are some helper functions defined for FT800 coprocessor engine as well as phost commands.

Author
Bridgetek
Date
2018

MIT License

Copyright (c) [2019] [Bridgetek Pte Ltd (BRTChip)]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Definition in file EVE_MediaFifo.h.

Function Documentation

◆ EVE_MediaFifo_close()

EVE_HAL_EXPORT void EVE_MediaFifo_close ( EVE_HalContext phost)

Closes the current media FIFO. Indication for HAL only

Definition at line 87 of file EVE_MediaFifo.c.

88{
89 phost->MediaFifoAddress = 0;
90 phost->MediaFifoSize = 0;
91}
uint32_t MediaFifoAddress
uint32_t MediaFifoSize

◆ EVE_MediaFifo_rp()

EVE_HAL_EXPORT uint32_t EVE_MediaFifo_rp ( EVE_HalContext phost)

Get the current read pointer.

Get the current read pointer.

Parameters
phostPointer to Hal context
Returns
uint32_t read pointer

Definition at line 99 of file EVE_MediaFifo.c.

100{
101 return EVE_Hal_rd32(phost, REG_MEDIAFIFO_READ);
102}
#define REG_MEDIAFIFO_READ
EVE_HAL_EXPORT uint32_t EVE_Hal_rd32(EVE_HalContext *phost, uint32_t addr)
Read 4 bytes from Coprocessor's memory.
Definition EVE_Hal.c:189

◆ EVE_MediaFifo_set()

EVE_HAL_EXPORT bool EVE_MediaFifo_set ( EVE_HalContext phost,
uint32_t  address,
uint32_t  size 
)

Set the media FIFO.

Set the media FIFO. Returns false in case a coprocessor fault occurred

Parameters
phostPointer to Hal context
address
size
Returns
false in case a coprocessor fault occurred

Definition at line 45 of file EVE_MediaFifo.c.

46{
47 bool res;
48
49 if (!EVE_Hal_supportMediaFifo(phost))
50 {
51 eve_assert_ex(false, "EVE_MediaFifo_set is not available on the current graphics platform\n");
52 return false;
53 }
54
55 if (phost->MediaFifoAddress != address || phost->MediaFifoSize != size)
56 {
57 EVE_Cmd_startFunc(phost);
59 EVE_Cmd_wr32(phost, address);
60 EVE_Cmd_wr32(phost, size);
61 EVE_Cmd_endFunc(phost);
62
63 /* Must flush for fifo pointers to be ready. */
64 res = EVE_Cmd_waitFlush(phost);
65 }
66 else
67 {
68 res = true;
69 }
70
71 if (res)
72 {
75 phost->MediaFifoAddress = address;
76 phost->MediaFifoSize = size;
77 }
78 else
79 {
80 phost->MediaFifoAddress = 0;
81 phost->MediaFifoSize = 0;
82 }
83
84 return res;
85}
EVE_HAL_EXPORT void EVE_Cmd_startFunc(EVE_HalContext *phost)
Begin writing a function, keeps the transfer open.
Definition EVE_Cmd.c:262
EVE_HAL_EXPORT void EVE_Cmd_endFunc(EVE_HalContext *phost)
End writing a function, closes the transfer.
Definition EVE_Cmd.c:274
EVE_HAL_EXPORT bool EVE_Cmd_wr32(EVE_HalContext *phost, uint32_t value)
Write 4 bytes to Coprocessor's command fifo.
Definition EVE_Cmd.c:394
#define CMD_MEDIAFIFO
#define REG_MEDIAFIFO_WRITE
static bool EVE_Hal_supportMediaFifo(EVE_HalContext *phost)
#define eve_assert(cond)
#define eve_assert_ex(cond, ex)
void EVE_Cmd_waitFlush(EVE_HalContext *host)
Definition Gpu_Hal.cpp:775

◆ EVE_MediaFifo_space()

EVE_HAL_EXPORT uint32_t EVE_MediaFifo_space ( EVE_HalContext phost)

Get the currently available space.

Get the currently available space.

Parameters
phostPointer to Hal context
Returns
uint32_t available space

Definition at line 121 of file EVE_MediaFifo.c.

122{
123 if (!phost->MediaFifoSize)
124 return 0;
125
128#if 1
129 return rp > wp
130 ? (rp - wp - 4)
131 : (rp + phost->MediaFifoSize - wp - 4);
132#else
133 int32_t diff = wp - rp;
134 if (diff < 0)
135 diff += phost->MediaFifoSize;
136 eve_assert(diff >= 0 && diff < phost->MediaFifoSize);
137 return phost->MediaFifoSize - diff - 4;
138#endif
139}
int int32_t

◆ EVE_MediaFifo_waitFlush()

EVE_HAL_EXPORT bool EVE_MediaFifo_waitFlush ( EVE_HalContext phost,
bool  orCmdFlush 
)

Wait for the media FIFO to fully empty.

Wait for the media FIFO to fully empty. When checking if a file is fully processed, EVE_Cmd_waitFlush must be called. Returns false in case a coprocessor fault occurred, or in case the coprocessor is done processing

Parameters
phostPointer to Hal context
orCmdFlush
Returns
false in case a coprocessor fault occurred

Definition at line 365 of file EVE_MediaFifo.c.

366{
367 return EVE_MediaFifo_waitSpace(phost, phost->MediaFifoSize - 4, orCmdFlush);
368}
uint32_t EVE_MediaFifo_waitSpace(EVE_HalContext *phost, uint32_t size, bool orCmdFlush)
Wait for the media FIFO to have at least the requested amount of free space.

◆ EVE_MediaFifo_waitSpace()

EVE_HAL_EXPORT uint32_t EVE_MediaFifo_waitSpace ( EVE_HalContext phost,
uint32_t  size,
bool  orCmdFlush 
)

Wait for the media FIFO to have at least the requested amount of free space.

Wait for the media FIFO to have at least the requested amount of free space. Returns 0 in case a coprocessor fault occurred, or in case the coprocessor is done processing

Parameters
phostPointer to Hal context
size
orCmdFlush
Returns
0 in case a coprocessor fault occurred

Definition at line 378 of file EVE_MediaFifo.c.

379{
380 uint32_t space;
381
382 if (!EVE_Hal_supportMediaFifo(phost))
383 {
384 eve_assert_ex(false, "EVE_MediaFifo_waitSpace is not available on the current graphics platform\n");
385 return 0;
386 }
387
388 if (!phost->MediaFifoSize)
389 {
390 eve_printf_debug("EVE Media FIFO has not been set, cannot wait for space\n");
391 return 0;
392 }
393
394 if (size > (phost->MediaFifoSize - 4))
395 {
396 eve_printf_debug("Requested free space exceeds media FIFO\n");
397 return 0;
398 }
399
400 eve_assert(!phost->CmdWaiting);
401 phost->CmdWaiting = true;
402
403#if 1
404 space = EVE_MediaFifo_space(phost);
405 if (!checkWait(phost, space))
406 return 0;
407#endif
408
409 do
410 {
411 space = EVE_MediaFifo_space(phost);
412 if (!handleWait(phost, (uint16_t)space))
413 return 0;
414 phost->CmdWaiting = false;
415 uint32_t cmdSpace = EVE_Cmd_waitSpace(phost, 0);
416 if (!cmdSpace)
417 return 0; /* Check for coprocessor error */
418 if (orCmdFlush && cmdSpace == (EVE_CMD_FIFO_SIZE - 4))
419 return 0; /* Processed */
420 phost->CmdWaiting = true;
421 } while (space < size);
422
423 phost->CmdWaiting = false;
424 return space;
425}
EVE_HAL_EXPORT uint32_t EVE_Cmd_waitSpace(EVE_HalContext *phost, uint32_t size)
Definition EVE_Cmd.c:580
#define EVE_CMD_FIFO_SIZE
Definition EVE_GpuDefs.h:58
unsigned short uint16_t
unsigned int uint32_t
static bool checkWait(EVE_HalContext *phost, uint32_t rpOrSpace)
uint32_t EVE_MediaFifo_space(EVE_HalContext *phost)
Get the currently available space.
static bool handleWait(EVE_HalContext *phost, uint16_t rpOrSpace)
#define eve_printf_debug(fmt,...)

◆ EVE_MediaFifo_wp()

EVE_HAL_EXPORT uint32_t EVE_MediaFifo_wp ( EVE_HalContext phost)

Get the current write pointer.

Get the current write pointer.

Parameters
phostPointer to Hal context
Returns
uint32_t write pointer

Definition at line 110 of file EVE_MediaFifo.c.

111{
112 return EVE_Hal_rd32(phost, REG_MEDIAFIFO_WRITE);
113}

◆ EVE_MediaFifo_wrMem()

EVE_HAL_EXPORT bool EVE_MediaFifo_wrMem ( EVE_HalContext phost,
const uint8_t buffer,
uint32_t  size,
uint32_t transfered 
)

Write a buffer to the media FIFO. Waits if there is not enough space in the media FIFO.

Write a buffer to the media FIFO. Waits if there is not enough space in the media FIFO. Returns false in case a coprocessor fault occurred. If the transfered pointer is set, the write may exit early if the coprocessor function has finished, and the transfered amount will be set.

Parameters
phostPointer to Hal context
buffer
size
transfered
Returns
false in case a coprocessor fault occurred

Definition at line 151 of file EVE_MediaFifo.c.

152{
153 if (!EVE_Hal_supportMediaFifo(phost))
154 {
155 eve_assert_ex(false, "EVE_MediaFifo_wrMem is not available on the current graphics platform\n");
156 return false;
157 }
158
159 if (!phost->MediaFifoSize)
160 {
161 eve_printf_debug("EVE Media FIFO has not been set, cannot write\n");
162 return false;
163 }
164
165#if 1
166 /* Two strategies.
167 - Wait for entire space and write the entire buffer.
168 - Wait for half the fifo to be available, and write in parts. */
169
170 /* If the size is within the media fifo size, write the entire buffer at once */
171 if (size <= phost->MediaFifoSize - 4)
172 {
173 uint32_t wp;
174 int32_t overflow;
175
176 if (!EVE_MediaFifo_waitSpace(phost, size, transfered))
177 return false;
178
180 overflow = (int32_t)(wp + size) - (int32_t)(phost->MediaFifoSize);
181 if (overflow > 0)
182 {
183 eve_assert(phost->MediaFifoAddress + wp + size - overflow <= RAM_G_SIZE);
184 eve_assert(phost->MediaFifoAddress + overflow <= RAM_G_SIZE);
185 EVE_Hal_wrMem(phost, phost->MediaFifoAddress + wp, buffer, size - overflow);
186 EVE_Hal_wrMem(phost, phost->MediaFifoAddress, &buffer[size - overflow], overflow);
187 }
188 else
189 {
190 eve_assert(phost->MediaFifoAddress + wp + size <= RAM_G_SIZE);
191 EVE_Hal_wrMem(phost, phost->MediaFifoAddress + wp, buffer, size);
192 }
193 wp += size;
194 if (wp >= phost->MediaFifoSize)
195 wp -= phost->MediaFifoSize;
196 eve_assert(wp < phost->MediaFifoSize);
198 if (transfered)
199 *transfered = size;
200 return true;
201 }
202 else
203 {
204 /* Otherwise, write in parts. */
205 uint32_t halfSize = ((phost->MediaFifoSize >> 3) << 2) - 4;
206 uint32_t remaining = size;
207 uint32_t done = 0;
208 uint32_t wp;
209
211 while (remaining)
212 {
213 uint32_t transfer = min(halfSize, remaining);
214 int32_t overflow;
215 if (!EVE_MediaFifo_waitSpace(phost, transfer, transfered))
216 return false;
217
218 overflow = (int32_t)(wp + transfer) - (int32_t)(phost->MediaFifoSize);
219 if (overflow > 0)
220 {
221 eve_assert(phost->MediaFifoAddress + wp + transfer - overflow <= RAM_G_SIZE);
222 eve_assert(phost->MediaFifoAddress + overflow <= RAM_G_SIZE);
223 EVE_Hal_wrMem(phost, phost->MediaFifoAddress + wp, &buffer[done], transfer - overflow);
224 EVE_Hal_wrMem(phost, phost->MediaFifoAddress, &buffer[done + transfer - overflow], overflow);
225 }
226 else
227 {
228 eve_assert(phost->MediaFifoAddress + wp + transfer <= RAM_G_SIZE);
229 EVE_Hal_wrMem(phost, phost->MediaFifoAddress + wp, &buffer[done], transfer);
230 }
231 wp += transfer;
232 done += transfer;
233 remaining -= transfer;
234 if (wp >= phost->MediaFifoSize)
235 wp -= phost->MediaFifoSize;
236 eve_assert(wp < phost->MediaFifoSize);
238
239 if (transfered)
240 {
241 *transfered = done;
242 if (EVE_Cmd_rp(phost) == EVE_Cmd_wp(phost))
243 return true; /* Early exit, finished processing. */
244 }
245 }
246
247 return true;
248 }
249#else
250 eve_scope()
251 {
252 uint32_t halfSize = ((phost->MediaFifoSize >> 3) << 2) - 4;
253 uint32_t remaining = size;
254 uint32_t done = 0;
255 uint32_t wp;
256
257 /* Write to media FIFO as soon as space is available */
259 while (remaining)
260 {
261 uint32_t transfer = min(
262 EVE_MediaFifo_waitSpace(phost, 4),
263 min(halfSize, remaining));
264 if (!transfer)
265 return false; // !phost->CmdFault;
266 int32_t overflow = (int32_t)(wp + transfer) - (int32_t)(phost->MediaFifoSize);
267 if (overflow > 0)
268 {
269 EVE_Hal_wrMem(phost, phost->MediaFifoAddress + wp, &buffer[done], transfer - overflow);
270 EVE_Hal_wrMem(phost, phost->MediaFifoAddress, &buffer[done + transfer - overflow], overflow);
271 }
272 else
273 {
274 EVE_Hal_wrMem(phost, phost->MediaFifoAddress + wp, &buffer[done], transfer);
275 }
276 wp += transfer;
277 done += transfer;
278 remaining -= transfer;
279 if (wp >= phost->MediaFifoSize)
280 wp -= phost->MediaFifoSize;
281 eve_assert(wp < phost->MediaFifoSize);
283
284 if (transfered)
285 {
286 *transfered = done;
287 if (EVE_Cmd_rp(phost) == EVE_Cmd_wp(phost))
288 return true; /* Early exit, finished processing. */
289 }
290 }
291
292 return true;
293 }
294#endif
295}
EVE_HAL_EXPORT uint16_t EVE_Cmd_rp(EVE_HalContext *phost)
Read from Coprocessor.
Definition EVE_Cmd.c:64
EVE_HAL_EXPORT uint16_t EVE_Cmd_wp(EVE_HalContext *phost)
Write to Coprocessor.
Definition EVE_Cmd.c:80
#define RAM_G_SIZE
Definition EVE_GpuDefs.h:98
EVE_HAL_EXPORT void EVE_Hal_wr32(EVE_HalContext *phost, uint32_t addr, uint32_t v)
Write 4 bytes to Coprocessor's memory.
Definition EVE_Hal.c:248
EVE_HAL_EXPORT void EVE_Hal_wrMem(EVE_HalContext *phost, uint32_t addr, const uint8_t *buffer, uint32_t size)
Write a buffer to Coprocessor's memory.
Definition EVE_Hal.c:263
static ft_uint32_t ft_uint8_t * buffer
Definition FT_Gpu_Hal.h:139