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_Cmd.h File Reference

EVE's command read/write. More...

#include "EVE_HalDefs.h"

Go to the source code of this file.

Macros

#define EVE_CMD_STRING_MAX   511
 

Functions

EVE_HAL_EXPORT uint16_t EVE_Cmd_rp (EVE_HalContext *phost)
 Read from Coprocessor.
 
EVE_HAL_EXPORT uint16_t EVE_Cmd_wp (EVE_HalContext *phost)
 Write to Coprocessor.
 
EVE_HAL_EXPORT uint16_t EVE_Cmd_space (EVE_HalContext *phost)
 Get free space of Coprocessor's command buffer.
 
EVE_HAL_EXPORT void EVE_Cmd_startFunc (EVE_HalContext *phost)
 Begin writing a function, keeps the transfer open.
 
EVE_HAL_EXPORT void EVE_Cmd_endFunc (EVE_HalContext *phost)
 End writing a function, closes the transfer.
 
EVE_HAL_EXPORT bool EVE_Cmd_wrMem (EVE_HalContext *phost, const uint8_t *buffer, uint32_t size)
 Write buffer to Coprocessor's comand fifo.
 
EVE_HAL_EXPORT bool EVE_Cmd_wrProgMem (EVE_HalContext *phost, eve_progmem_const uint8_t *buffer, uint32_t size)
 Write buffer in ProgMem to Coprocessor's comand fifo.
 
EVE_HAL_EXPORT uint32_t EVE_Cmd_wrString (EVE_HalContext *phost, const char *str, uint32_t maxLength)
 Write a string into Coprocessor's command fifo.
 
EVE_HAL_EXPORT bool EVE_Cmd_wr8 (EVE_HalContext *phost, uint8_t value)
 Write a byte to Coprocessor's command fifo.
 
EVE_HAL_EXPORT bool EVE_Cmd_wr16 (EVE_HalContext *phost, uint16_t value)
 Write 2 bytes to Coprocessor's command fifo.
 
EVE_HAL_EXPORT bool EVE_Cmd_wr32 (EVE_HalContext *phost, uint32_t value)
 Write 4 bytes to Coprocessor's command fifo.
 
EVE_HAL_EXPORT uint16_t EVE_Cmd_moveWp (EVE_HalContext *phost, uint16_t bytes)
 Move the write pointer forward by the specified number of bytes. Returns the previous write pointer.
 
EVE_HAL_EXPORT bool EVE_Cmd_waitFlush (EVE_HalContext *phost)
 Wait till Command FIFO buffer empty.
 
EVE_HAL_EXPORT uint32_t EVE_Cmd_waitSpace (EVE_HalContext *phost, uint32_t size)
 
EVE_HAL_EXPORT bool EVE_Cmd_waitLogo (EVE_HalContext *phost)
 Wait until Coprocessor finished logo animation.
 
EVE_HAL_EXPORT bool EVE_Cmd_waitRead32 (EVE_HalContext *phost, uint32_t ptr, uint32_t value)
 
EVE_HAL_EXPORT void EVE_Cmd_restore (EVE_HalContext *phost)
 

Detailed Description

EVE's command read/write.

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_Cmd.h.

Macro Definition Documentation

◆ EVE_CMD_STRING_MAX

#define EVE_CMD_STRING_MAX   511

Definition at line 44 of file EVE_Cmd.h.

Function Documentation

◆ EVE_Cmd_endFunc()

EVE_HAL_EXPORT void EVE_Cmd_endFunc ( EVE_HalContext phost)

End writing a function, closes the transfer.

Parameters
phostPointer to Hal context

Definition at line 274 of file EVE_Cmd.c.

275{
276 eve_assert(!phost->CmdWaiting);
277 eve_assert(phost->CmdBufferIndex == 0);
278 endFunc(phost);
279 phost->CmdFunc = false;
280}
static void endFunc(EVE_HalContext *phost)
End read/write to Coprocessor.
Definition EVE_Cmd.c:44
#define eve_assert(cond)
uint8_t CmdBufferIndex

◆ EVE_Cmd_moveWp()

EVE_HAL_EXPORT uint16_t EVE_Cmd_moveWp ( EVE_HalContext phost,
uint16_t  bytes 
)

Move the write pointer forward by the specified number of bytes. Returns the previous write pointer.

Parameters
phostPointer to Hal context
bytesNumber of bytes to move
Returns
uint16_t Previous write pointer

Definition at line 446 of file EVE_Cmd.c.

447{
448 uint16_t wp;
449 uint16_t prevWp;
450 eve_assert(!phost->CmdWaiting);
451 eve_assert(phost->CmdBufferIndex == 0);
452
453 if (!EVE_Cmd_waitSpace(phost, bytes))
454 return -1;
455
456 prevWp = EVE_Cmd_wp(phost);
457 wp = (prevWp + bytes) & EVE_CMD_FIFO_MASK;
458#if !defined(EVE_SUPPORT_CMDB) || defined(EVE_MULTI_GRAPHICS_TARGET)
459 if (!EVE_Hal_supportCmdB(phost))
460 {
461 phost->CmdWp = wp;
462 }
463#endif
464 EVE_Hal_wr16(phost, REG_CMD_WRITE, wp);
465
466 return prevWp;
467}
EVE_HAL_EXPORT uint32_t EVE_Cmd_waitSpace(EVE_HalContext *phost, uint32_t size)
Definition EVE_Cmd.c:580
EVE_HAL_EXPORT uint16_t EVE_Cmd_wp(EVE_HalContext *phost)
Write to Coprocessor.
Definition EVE_Cmd.c:80
#define REG_CMD_WRITE
#define EVE_CMD_FIFO_MASK
Definition EVE_GpuDefs.h:60
EVE_HAL_EXPORT void EVE_Hal_wr16(EVE_HalContext *phost, uint32_t addr, uint16_t v)
Write 2 bytes to Coprocessor's memory.
Definition EVE_Hal.c:234
static bool EVE_Hal_supportCmdB(EVE_HalContext *phost)
unsigned short uint16_t

◆ EVE_Cmd_restore()

EVE_HAL_EXPORT void EVE_Cmd_restore ( EVE_HalContext phost)

Restore the internal state of EVE_Cmd. Call this after manually writing to the coprocessor buffer

Definition at line 682 of file EVE_Cmd.c.

683{
684 EVE_Cmd_rp(phost);
685 EVE_Cmd_wp(phost);
686 EVE_Cmd_space(phost);
687}
EVE_HAL_EXPORT uint16_t EVE_Cmd_space(EVE_HalContext *phost)
Get free space of Coprocessor's command buffer.
Definition EVE_Cmd.c:105
EVE_HAL_EXPORT uint16_t EVE_Cmd_rp(EVE_HalContext *phost)
Read from Coprocessor.
Definition EVE_Cmd.c:64

◆ EVE_Cmd_rp()

EVE_HAL_EXPORT uint16_t EVE_Cmd_rp ( EVE_HalContext phost)

Read from Coprocessor.

Get the current read pointer. Safe to use during ongoing command transaction

Parameters
phostPointer to Hal context
Returns
uint16_t Read pointer

Definition at line 64 of file EVE_Cmd.c.

65{
66 uint16_t rp;
67 endFunc(phost);
69 if (EVE_CMD_FAULT(rp))
70 phost->CmdFault = true;
71 return rp;
72}
#define EVE_CMD_FAULT(rp)
Definition EVE_GpuDefs.h:63
#define REG_CMD_READ
EVE_HAL_EXPORT uint16_t EVE_Hal_rd16(EVE_HalContext *phost, uint32_t addr)
Read 2 bytes from Coprocessor's memory.
Definition EVE_Hal.c:173

◆ EVE_Cmd_space()

EVE_HAL_EXPORT uint16_t EVE_Cmd_space ( EVE_HalContext phost)

Get free space of Coprocessor's command buffer.

Get the currently available space. Updates cached available space. Safe to use during ongoing command transaction

Parameters
phostPointer to Hal context
Returns
uint16_t Free space in Bytes

Definition at line 105 of file EVE_Cmd.c.

106{
107 uint16_t space;
108 uint16_t wp;
109 uint16_t rp;
110 endFunc(phost);
111 if (EVE_Hal_supportCmdB(phost))
112 {
114 if (EVE_CMD_FAULT(space))
115 phost->CmdFault = true;
116 phost->CmdSpace = space;
117 return space;
118 }
119 else
120 {
121 wp = EVE_Cmd_wp(phost);
122 rp = EVE_Cmd_rp(phost);
123 space = (rp - wp - 4) & EVE_CMD_FIFO_MASK;
124 phost->CmdSpace = space;
125 return space;
126 }
127}
#define REG_CMDB_SPACE
uint16_t CmdSpace

◆ EVE_Cmd_startFunc()

EVE_HAL_EXPORT void EVE_Cmd_startFunc ( EVE_HalContext phost)

Begin writing a function, keeps the transfer open.

Note
While a command transaction is ongoing, HAL functions outside of EVE_Cmd_* must not be used.
Parameters
phostPointer to Hal context

Definition at line 262 of file EVE_Cmd.c.

263{
264 eve_assert(!phost->CmdWaiting);
265 eve_assert(phost->CmdBufferIndex == 0);
266 phost->CmdFunc = true;
267}

◆ EVE_Cmd_waitFlush()

EVE_HAL_EXPORT bool EVE_Cmd_waitFlush ( EVE_HalContext phost)

Wait till Command FIFO buffer empty.

Wait for the command buffer to fully empty. Returns false in case a coprocessor fault occurred

Parameters
phostPointer to Hal context
Returns
true True if ok
false False if error

Definition at line 775 of file Gpu_Hal.cpp.

776{
778
779 host->cmd_fifo_wp = Gpu_Hal_Rd16(host,REG_CMD_WRITE);
780}
#define Gpu_Hal_Rd16
Definition Gpu_Hal.h:205

◆ EVE_Cmd_waitLogo()

EVE_HAL_EXPORT bool EVE_Cmd_waitLogo ( EVE_HalContext phost)

Wait until Coprocessor finished logo animation.

Wait for logo to finish displaying. (Waits for both the read and write pointer to go to 0)

Parameters
phostPointer to Hal context
Returns
true True if ok
false False if error

Definition at line 625 of file EVE_Cmd.c.

626{
627 uint16_t rp;
628 uint16_t wp;
629
630 eve_assert(!phost->CmdWaiting);
631 phost->CmdWaiting = true;
632
633 do
634 {
635 rp = EVE_Cmd_rp(phost);
636 wp = EVE_Cmd_wp(phost);
637 if (!handleWait(phost, rp))
638 return false;
639
640 } while ((wp != 0) || (rp != 0));
641
642 phost->CmdWaiting = false;
643 return true;
644}
static bool handleWait(EVE_HalContext *phost, uint16_t rpOrSpace)
Wait handler.
Definition EVE_Cmd.c:528

◆ EVE_Cmd_waitRead32()

EVE_HAL_EXPORT bool EVE_Cmd_waitRead32 ( EVE_HalContext phost,
uint32_t  ptr,
uint32_t  value 
)

Wait for a 32-bit value that was set by EVE_CoCmd_memWrite32(phost, ptr, value).

Returns
true when the value is found.
false otherwise when the coprocessor has flushed, or a coprocessor fault occured.

Definition at line 651 of file EVE_Cmd.c.

652{
653 uint16_t rp;
654 uint16_t wp;
655
656 eve_assert(!phost->CmdWaiting);
657 phost->CmdWaiting = true;
658 while ((rp = EVE_Cmd_rp(phost)) != (wp = EVE_Cmd_wp(phost)))
659 {
660 if (EVE_Hal_rd32(phost, ptr) == value)
661 {
662 /* Expected value has been read */
663 phost->CmdWaiting = false;
664 return true;
665 }
666 if (!handleWait(phost, rp))
667 {
668 phost->CmdSpace = (rp - wp - 4) & EVE_CMD_FIFO_MASK;
669 return false;
670 }
671 }
672
673 /* Command buffer empty */
674 phost->CmdSpace = EVE_CMD_FIFO_SIZE - 4;
675 phost->CmdWaiting = false;
676 return EVE_Hal_rd32(phost, ptr) == value;
677}
#define EVE_CMD_FIFO_SIZE
Definition EVE_GpuDefs.h:58
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_Cmd_waitSpace()

EVE_HAL_EXPORT uint32_t EVE_Cmd_waitSpace ( EVE_HalContext phost,
uint32_t  size 
)

Wait for the command buffer to have at least the requested amount of free space.

Returns
0 in case a coprocessor fault occurred

Definition at line 580 of file EVE_Cmd.c.

581{
582 uint16_t space;
583
584 if (size > (EVE_CMD_FIFO_SIZE - 4))
585 {
586 eve_printf_debug("Requested free space exceeds coprocessor FIFO\n");
587 return 0;
588 }
589
590 eve_assert(!phost->CmdWaiting);
591 phost->CmdWaiting = true;
592
593 space = phost->CmdSpace;
594
595#if 1
596 /* Optimization.
597 Only update space if more space is needed than already known available,
598 or when not actually waiting for any space */
599 if (space < size || !size)
600 space = EVE_Cmd_space(phost);
601 if (!checkWait(phost, space))
602 return 0;
603#endif
604
605 /* Wait until there's sufficient space */
606 while (space < size)
607 {
608 space = EVE_Cmd_space(phost);
609 if (!handleWait(phost, space))
610 return 0;
611 }
612
613 /* Sufficient space */
614 phost->CmdWaiting = false;
615 return space;
616}
static bool checkWait(EVE_HalContext *phost, uint16_t rpOrSpace)
Check for coprocessor fault.
Definition EVE_Cmd.c:481
#define eve_printf_debug(fmt,...)

◆ EVE_Cmd_wp()

EVE_HAL_EXPORT uint16_t EVE_Cmd_wp ( EVE_HalContext phost)

Write to Coprocessor.

Get the current write pointer. Updates cached write pointer when CMDB is not supported. Safe to use during ongoing command transaction

Parameters
phostPointer to Hal context
Returns
uint16_t Write pointer

Definition at line 80 of file EVE_Cmd.c.

81{
82 endFunc(phost);
83 if (EVE_Hal_supportCmdB(phost))
84 {
86 }
87 else
88 {
89#if !defined(EVE_SUPPORT_CMDB) || defined(EVE_MULTI_GRAPHICS_TARGET)
90 phost->CmdWp = EVE_Hal_rd16(phost, REG_CMD_WRITE) & EVE_CMD_FIFO_MASK;
91 return phost->CmdWp;
92#else
93 eve_assert(false);
94 return 0xffff;
95#endif
96 }
97}

◆ EVE_Cmd_wr16()

EVE_HAL_EXPORT bool EVE_Cmd_wr16 ( EVE_HalContext phost,
uint16_t  value 
)

Write 2 bytes to Coprocessor's command fifo.

Write a 16-bit value to the command buffer. Uses a cache to write 4 bytes at once. Wire endianness is handled by the transfer. Waits if there is not enough space in the command buffer. Returns false in case a coprocessor fault occurred

Parameters
phostPointer to Hal context
valueData to write
Returns
true True if ok
false False if error

Definition at line 366 of file EVE_Cmd.c.

367{
368 eve_assert(!phost->CmdWaiting);
369 eve_assert(phost->CmdBufferIndex < 3);
370
371 if (phost->CmdBufferIndex < 3)
372 {
373 phost->CmdBuffer[phost->CmdBufferIndex++] = value & 0xFF;
374 phost->CmdBuffer[phost->CmdBufferIndex++] = value >> 8;
375 }
376
377 if (phost->CmdBufferIndex == 4)
378 {
379 phost->CmdBufferIndex = 0;
380 return EVE_Cmd_wrMem(phost, phost->CmdBuffer, 4);
381 }
382
383 return true;
384}
EVE_HAL_EXPORT bool EVE_Cmd_wrMem(EVE_HalContext *phost, const uint8_t *buffer, uint32_t size)
Write buffer to Coprocessor's comand fifo.
Definition EVE_Cmd.c:291
uint8_t CmdBuffer[4]

◆ EVE_Cmd_wr32()

EVE_HAL_EXPORT bool EVE_Cmd_wr32 ( EVE_HalContext phost,
uint32_t  value 
)

Write 4 bytes to Coprocessor's command fifo.

Write a value to the command buffer. Wire endianness is handled by the transfer. Waits if there is not enough space in the command buffer. Returns false in case a coprocessor fault occurred

Parameters
phostPointer to Hal context
valueData to write
Returns
true True if ok
false False if error

Definition at line 394 of file EVE_Cmd.c.

395{
396 eve_assert(!phost->CmdWaiting);
397 eve_assert(phost->CmdBufferIndex == 0);
398
399 if (phost->CmdSpace < 4 && !EVE_Cmd_waitSpace(phost, 4))
400 return false;
401
402 if (phost->Status != EVE_STATUS_WRITING)
403 {
404 if (EVE_Hal_supportCmdB(phost))
405 {
407 }
408 else
409 {
410#if !defined(EVE_SUPPORT_CMDB) || defined(EVE_MULTI_GRAPHICS_TARGET)
411 EVE_Hal_startTransfer(phost, EVE_TRANSFER_WRITE, RAM_CMD + phost->CmdWp);
412#else
413 eve_assert(false);
414#endif
415 }
416 }
417 EVE_Hal_transfer32(phost, value);
418 if (!phost->CmdFunc) /* Keep alive while writing function */
419 {
420 EVE_Hal_endTransfer(phost);
421 }
422 eve_assert(phost->CmdSpace >= 4);
423 phost->CmdSpace -= 4;
424#if !defined(EVE_SUPPORT_CMDB) || defined(EVE_MULTI_GRAPHICS_TARGET)
425 if (!EVE_Hal_supportCmdB(phost))
426 {
427 phost->CmdWp += 4;
428 phost->CmdWp &= EVE_CMD_FIFO_MASK;
429 if (!phost->CmdFunc) /* Defer write pointer */
430 {
431 EVE_Hal_wr16(phost, REG_CMD_WRITE, phost->CmdWp);
432 }
433 }
434#endif
435
436 return true;
437}
#define RAM_CMD
#define REG_CMDB_WRITE
@ EVE_STATUS_WRITING
Definition EVE_HalDefs.h:60
EVE_HAL_EXPORT void EVE_Hal_startTransfer(EVE_HalContext *phost, EVE_TRANSFER_T rw, uint32_t addr)
Start data transfer to Coprocessor.
@ EVE_TRANSFER_WRITE
Definition EVE_HalDefs.h:68
EVE_HAL_EXPORT void EVE_Hal_endTransfer(EVE_HalContext *phost)
End data transfer.
EVE_HAL_EXPORT uint32_t EVE_Hal_transfer32(EVE_HalContext *phost, uint32_t value)
Write 4 bytes to Coprocessor.
EVE_STATUS_T Status

◆ EVE_Cmd_wr8()

EVE_HAL_EXPORT bool EVE_Cmd_wr8 ( EVE_HalContext phost,
uint8_t  value 
)

Write a byte to Coprocessor's command fifo.

Write a 8-bit value to the command buffer. Uses a cache to write 4 bytes at once. Waits if there is not enough space in the command buffer. Returns false in case a coprocessor fault occurred

Parameters
phostPointer to Hal context
valueByte to write
Returns
true True if ok
false False if error

Definition at line 339 of file EVE_Cmd.c.

340{
341 eve_assert(!phost->CmdWaiting);
342 eve_assert(phost->CmdBufferIndex < 4);
343
344 if (phost->CmdBufferIndex < 4)
345 {
346 phost->CmdBuffer[phost->CmdBufferIndex++] = value;
347 }
348
349 if (phost->CmdBufferIndex == 4)
350 {
351 phost->CmdBufferIndex = 0;
352 return EVE_Cmd_wrMem(phost, phost->CmdBuffer, 4);
353 }
354
355 return true;
356}

◆ EVE_Cmd_wrMem()

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

Write buffer to Coprocessor's comand fifo.

Write a buffer to the command buffer. Waits if there is not enough space in the command buffer. Returns false in case a coprocessor fault occurred

Parameters
phostPointer to Hal context
bufferData pointer
sizeSize to write
Returns
true Write ok
false Write error

Definition at line 291 of file EVE_Cmd.c.

292{
293 eve_assert(!phost->CmdWaiting);
294 eve_assert(phost->CmdBufferIndex == 0);
295 return wrBuffer(phost, buffer, size, false, false) == size;
296}
static uint32_t wrBuffer(EVE_HalContext *phost, const void *buffer, uint32_t size, bool progmem, bool string)
Write buffer to Coprocessor's comand fifo.
Definition EVE_Cmd.c:191
static ft_uint32_t ft_uint8_t * buffer
Definition FT_Gpu_Hal.h:139

◆ EVE_Cmd_wrProgMem()

EVE_HAL_EXPORT bool EVE_Cmd_wrProgMem ( EVE_HalContext phost,
eve_progmem_const uint8_t buffer,
uint32_t  size 
)

Write buffer in ProgMem to Coprocessor's comand fifo.

Write a progmem buffer to the command buffer. Waits if there is not enough space in the command buffer. Returns false in case a coprocessor fault occurred

Parameters
phostPointer to Hal context
bufferData buffer
sizeSize to write
Returns
true True if ok
false False if error

Definition at line 307 of file EVE_Cmd.c.

308{
309 eve_assert(!phost->CmdWaiting);
310 eve_assert(phost->CmdBufferIndex == 0);
311 return wrBuffer(phost, (void *)(uintptr_t)buffer, size, true, false) == size;
312}

◆ EVE_Cmd_wrString()

EVE_HAL_EXPORT uint32_t EVE_Cmd_wrString ( EVE_HalContext phost,
const char *  str,
uint32_t  maxLength 
)

Write a string into Coprocessor's command fifo.

Write a string to the command buffer, padded to 4 bytes. Waits if there is not enough space in the command buffer. Parameter maxLength can be set up to EVE_CMD_STRING_MAX. Returns false in case a coprocessor fault occurred

Parameters
phostPointer to Hal context
strString to write
maxLengthLength to write, up to EVE_CMD_STRING_MAX
Returns
uint32_t Number of bytes transfered

Definition at line 322 of file EVE_Cmd.c.

323{
324 uint32_t transfered;
325 eve_assert(!phost->CmdWaiting);
326 eve_assert(phost->CmdBufferIndex == 0);
327 transfered = wrBuffer(phost, str, maxLength, false, true);
328 return transfered;
329}
unsigned int uint32_t