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.c File Reference

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

#include "EVE_Cmd.h"
#include "EVE_Platform.h"

Go to the source code of this file.

Functions

static void endFunc (EVE_HalContext *phost)
 End read/write to Coprocessor.
 
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.
 
static void startBufferTransfer (EVE_HalContext *phost)
 Start transfer data to EVE.
 
static uint32_t wrString (EVE_HalContext *phost, const void *buffer, uint32_t *size, uint32_t transfered, uint32_t transfer)
 Write string to Coprocessor's comand fifo.
 
static uint32_t wrBuffer (EVE_HalContext *phost, const void *buffer, uint32_t size, bool progmem, bool string)
 Write buffer to Coprocessor's comand fifo.
 
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.
 
void debugBackupRamG (EVE_HalContext *phost)
 Backup the last 128 bytes of RAM_G, which may be used for an error message.
 
static bool checkWait (EVE_HalContext *phost, uint16_t rpOrSpace)
 Check for coprocessor fault.
 
static bool handleWait (EVE_HalContext *phost, uint16_t rpOrSpace)
 Wait handler.
 
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.c.

Function Documentation

◆ checkWait()

static bool checkWait ( EVE_HalContext phost,
uint16_t  rpOrSpace 
)
static

Check for coprocessor fault.

Parameters
phostPointer to Hal context
rpOrSpaceRead pointer or space
Returns
true True if ok
false False if coprocessor fault

Definition at line 481 of file EVE_Cmd.c.

482{
483 /* Check for coprocessor fault */
484 if (EVE_CMD_FAULT(rpOrSpace))
485 {
486 char err[128];
487 err[0] = '\0';
488 /* Coprocessor fault */
489 phost->CmdWaiting = false;
490#if defined(_DEBUG)
491 if (!phost->DebugMessageVisible)
492 {
493 eve_printf_debug("Coprocessor fault\n");
494 debugBackupRamG(phost);
495 if (EVE_CHIPID >= EVE_BT815)
496 {
497 EVE_Hal_rdMem(phost, (uint8_t *)err, RAM_ERR_REPORT, 128);
498 eve_printf_debug("%s\n", err);
499 EVE_Hal_displayMessage(phost, err, 128);
500 }
501 else
502 {
503 EVE_Hal_displayMessage(phost, "Coprocessor fault ", sizeof("Coprocessor fault "));
504 }
505 }
506#endif
507 return false;
508 }
509
510 if (phost->Status == EVE_STATUS_ERROR || phost->Status == EVE_STATUS_CLOSED)
511 {
512 phost->CmdWaiting = false;
513 eve_printf_debug("Host error\n");
514 return false;
515 }
516
517 return true;
518}
void debugBackupRamG(EVE_HalContext *phost)
Backup the last 128 bytes of RAM_G, which may be used for an error message.
Definition EVE_Util.c:1722
#define EVE_BT815
Definition EVE_Config.h:66
#define EVE_CHIPID
#define RAM_ERR_REPORT
Definition EVE_GpuDefs.h:79
#define EVE_CMD_FAULT(rp)
Definition EVE_GpuDefs.h:63
EVE_HAL_EXPORT void EVE_Hal_rdMem(EVE_HalContext *phost, uint8_t *result, uint32_t addr, uint32_t size)
Read a block data from Coprocessor's memory.
Definition EVE_Hal.c:206
void EVE_Hal_displayMessage(EVE_HalContext *phost, const char *str, uint16_t size)
Display a fullscreen debug message using TEXT8X8. Uses the back of RAM_G.
Definition EVE_Hal.c:486
@ EVE_STATUS_CLOSED
Definition EVE_HalDefs.h:57
@ EVE_STATUS_ERROR
Definition EVE_HalDefs.h:61
unsigned char uint8_t
#define eve_printf_debug(fmt,...)
bool DebugMessageVisible
EVE_STATUS_T Status

◆ debugBackupRamG()

void debugBackupRamG ( EVE_HalContext phost)

Backup the last 128 bytes of RAM_G, which may be used for an error message.

Parameters
phostPointer to Hal context

Definition at line 1722 of file EVE_Util.c.

1723{
1724 if (!phost->DebugMessageVisible)
1725 {
1726 EVE_Hal_rdMem(phost, phost->DebugBackup, RAM_G + RAM_G_SIZE - sizeof(phost->DebugBackup), sizeof(phost->DebugBackup));
1727 phost->DebugMessageVisible = true;
1728 }
1729}
#define RAM_G_SIZE
Definition EVE_GpuDefs.h:98
#define RAM_G
Definition EVE_GpuDefs.h:77
uint8_t DebugBackup[RAM_ERR_REPORT_MAX]

◆ endFunc()

static void endFunc ( EVE_HalContext phost)
inlinestatic

End read/write to Coprocessor.

Parameters
phostPointer to Hal context

Definition at line 44 of file EVE_Cmd.c.

45{
46 if (phost->Status == EVE_STATUS_WRITING)
47 {
49#if !defined(EVE_SUPPORT_CMDB) || defined(EVE_MULTI_GRAPHICS_TARGET)
50 if (!EVE_Hal_supportCmdB(phost))
51 {
52 EVE_Hal_wr16(phost, REG_CMD_WRITE, phost->CmdWp);
53 }
54#endif
55 }
56}
#define REG_CMD_WRITE
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
@ EVE_STATUS_WRITING
Definition EVE_HalDefs.h:60
static bool EVE_Hal_supportCmdB(EVE_HalContext *phost)
EVE_HAL_EXPORT void EVE_Hal_endTransfer(EVE_HalContext *phost)
End data transfer.

◆ 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 EVE_CMD_FIFO_MASK
Definition EVE_GpuDefs.h:60
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.

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

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.

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.

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

Definition at line 555 of file EVE_Cmd.c.

556{
557 uint16_t rp;
558 uint16_t wp;
559
560 eve_assert(!phost->CmdWaiting);
561 phost->CmdWaiting = true;
562 while ((rp = EVE_Cmd_rp(phost)) != (wp = EVE_Cmd_wp(phost)))
563 {
564 if (!handleWait(phost, rp))
565 {
566 phost->CmdSpace = (rp - wp - 4) & EVE_CMD_FIFO_MASK;
567 return false;
568 }
569 }
570
571 /* Command buffer empty */
572 phost->CmdSpace = EVE_CMD_FIFO_SIZE - 4;
573 phost->CmdWaiting = false;
574 return true;
575}
static bool handleWait(EVE_HalContext *phost, uint16_t rpOrSpace)
Wait handler.
Definition EVE_Cmd.c:528
#define EVE_CMD_FIFO_SIZE
Definition EVE_GpuDefs.h:58

◆ EVE_Cmd_waitLogo()

EVE_HAL_EXPORT bool EVE_Cmd_waitLogo ( EVE_HalContext phost)

Wait until Coprocessor finished logo animation.

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}

◆ 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}
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

◆ EVE_Cmd_wp()

EVE_HAL_EXPORT uint16_t EVE_Cmd_wp ( EVE_HalContext phost)

Write to Coprocessor.

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.

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.

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_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 uint32_t EVE_Hal_transfer32(EVE_HalContext *phost, uint32_t value)
Write 4 bytes to Coprocessor.

◆ EVE_Cmd_wr8()

EVE_HAL_EXPORT bool EVE_Cmd_wr8 ( EVE_HalContext phost,
uint8_t  value 
)

Write a byte to Coprocessor's command fifo.

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.

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.

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.

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

◆ handleWait()

static bool handleWait ( EVE_HalContext phost,
uint16_t  rpOrSpace 
)
static

Wait handler.

Parameters
phostPointer to Hal context
rpOrSpaceRead pointer or space
Returns
true True if ok
false False if error

Definition at line 528 of file EVE_Cmd.c.

529{
530 /* Check for coprocessor fault */
531 if (!checkWait(phost, rpOrSpace))
532 return false;
533
534 /* Process any idling */
535 EVE_Hal_idle(phost);
536
537 /* Process user idling */
538 if (phost->CbCmdWait && !phost->CbCmdWait(phost))
539 {
540 /* Wait aborted */
541 phost->CmdWaiting = false;
542 eve_printf_debug("Wait for coprocessor aborted\n");
543 return false;
544 }
545 return true;
546}
EVE_HAL_EXPORT void EVE_Hal_idle(EVE_HalContext *phost)
Idle handler for Eve_Hal framework.
Definition EVE_Hal.c:136
EVE_Callback CbCmdWait

◆ startBufferTransfer()

static void startBufferTransfer ( EVE_HalContext phost)
static

Start transfer data to EVE.

Parameters
phostPointer to Hal context

Definition at line 134 of file EVE_Cmd.c.

135{
136 if (phost->Status != EVE_STATUS_WRITING)
137 {
138 if (EVE_Hal_supportCmdB(phost))
139 {
141 }
142 else
143 {
144#if !defined(EVE_SUPPORT_CMDB) || defined(EVE_MULTI_GRAPHICS_TARGET)
145 EVE_Hal_startTransfer(phost, EVE_TRANSFER_WRITE, RAM_CMD + phost->CmdWp);
146#else
147 eve_assert(false);
148#endif
149 }
150 }
151}

◆ wrBuffer()

static uint32_t wrBuffer ( EVE_HalContext phost,
const void *  buffer,
uint32_t  size,
bool  progmem,
bool  string 
)
static

Write buffer to Coprocessor's comand fifo.

Parameters
phostPointer to Hal context
bufferData pointer
sizeSize to write
progmemTrue if ProgMem
stringTrue is string
Returns
uint32_t Byte transfered

Definition at line 191 of file EVE_Cmd.c.

192{
193 uint32_t transfered = 0;
194
195 do
196 {
197 uint32_t transfer = (size - transfered);
198 uint32_t space = phost->CmdSpace;
199 uint32_t req = min((string ? (transfer + 1) : transfer), (EVE_CMD_FIFO_SIZE >> 1));
200 eve_assert(!string || (req == (transfer + 1)));
201 if (space < req)
202 {
203 if (!EVE_Cmd_waitSpace(phost, req))
204 return transfered; /* Coprocessor fault */
205 space = phost->CmdSpace;
206 }
207 if (transfer > space)
208 transfer = space;
209 eve_assert(transfer <= EVE_CMD_FIFO_SIZE - 4);
210 if (transfer)
211 {
212 startBufferTransfer(phost);
213 if (string)
214 {
215 transfer = wrString(phost, buffer, &size, transfered, transfer);
216 }
217 else if (progmem)
218 {
219 EVE_Hal_transferProgMem(phost, NULL, (eve_progmem_const uint8_t *)(uintptr_t)(&((uint8_t *)buffer)[transfered]), transfer);
220 }
221 else
222 {
223 EVE_Hal_transferMem(phost, NULL, &((uint8_t *)buffer)[transfered], transfer);
224 }
225 if (!string && (transfer & 0x3))
226 {
227 uint32_t pad = 4 - (transfer & 0x3);
228 uint8_t padding[4] = { 0 };
229 eve_assert((transfered + transfer) == size);
230 EVE_Hal_transferMem(phost, NULL, padding, pad);
231 transfer += pad;
232 eve_assert(!(transfer & 0x3));
233 }
234 transfered += transfer;
235 if (!phost->CmdFunc) /* Keep alive while writing function */
236 {
237 EVE_Hal_endTransfer(phost);
238 }
239 eve_assert(phost->CmdSpace >= transfer);
240 phost->CmdSpace -= (uint16_t)transfer;
241#if !defined(EVE_SUPPORT_CMDB) || defined(EVE_MULTI_GRAPHICS_TARGET)
242 if (!EVE_Hal_supportCmdB(phost))
243 {
244 phost->CmdWp += (uint16_t)transfer;
245 phost->CmdWp &= EVE_CMD_FIFO_MASK;
246 if (!phost->CmdFunc) /* Defer write pointer */
247 {
248 EVE_Hal_wr16(phost, REG_CMD_WRITE, phost->CmdWp);
249 }
250 }
251#endif
252 }
253 } while (transfered < size);
254 return transfered;
255}
static uint32_t wrString(EVE_HalContext *phost, const void *buffer, uint32_t *size, uint32_t transfered, uint32_t transfer)
Write string to Coprocessor's comand fifo.
Definition EVE_Cmd.c:163
static void startBufferTransfer(EVE_HalContext *phost)
Start transfer data to EVE.
Definition EVE_Cmd.c:134
#define eve_progmem_const
EVE_HAL_EXPORT void EVE_Hal_transferMem(EVE_HalContext *phost, uint8_t *result, const uint8_t *buffer, uint32_t size)
Transfer (read/write) a block data to Coprocessor.
EVE_HAL_EXPORT void EVE_Hal_transferProgMem(EVE_HalContext *phost, uint8_t *result, eve_progmem_const uint8_t *buffer, uint32_t size)
Transfer a block data from program memory.

◆ wrString()

static uint32_t wrString ( EVE_HalContext phost,
const void *  buffer,
uint32_t size,
uint32_t  transfered,
uint32_t  transfer 
)
static

Write string to Coprocessor's comand fifo.

Parameters
phostPointer to Hal context
bufferData pointer
sizeSize to write
transferByte to transfer
transferedByte transfered
Returns
transfer Byte to transfer

Definition at line 163 of file EVE_Cmd.c.

164{
165 uint32_t t;
166 eve_assert(transfered == 0);
167 eve_assert(transfer == *size); /* Cannot split string transfers */
168 eve_assert(transfer <= phost->CmdSpace);
169 t = EVE_Hal_transferString(phost, (const char *)buffer, transfered, transfer, 0x3);
170 if (t != transfer) /* End of string */
171 {
172 eve_assert(t <= phost->CmdSpace);
173 transfer = t;
174 *size = (transfered + transfer);
175 }
176 eve_assert((transfered + transfer) == *size);
177
178 return transfer;
179}
EVE_HAL_EXPORT uint32_t EVE_Hal_transferString(EVE_HalContext *phost, const char *str, uint32_t index, uint32_t size, uint32_t padMask)
Transfer a string to EVE platform.