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_Hal.c
Go to the documentation of this file.
1
32#include "EVE_HalDefs.h"
33#include "EVE_Platform.h"
34
35#include "EVE_HalImpl.h"
36
37#include <string.h>
38
39/*********
40** INIT **
41*********/
42
46
59
65{
66 eve_assert_ex(g_HalPlatform.OpenedDevices == 0, "HAL context still open\n");
70 memset(&g_HalPlatform, 0, sizeof(EVE_HalPlatform));
71}
72
79{
80 EVE_Hal_defaultsEx(parameters, -1);
81}
82
89EVE_HAL_EXPORT void EVE_Hal_defaultsEx(EVE_HalParameters *parameters, size_t deviceIdx)
90{
91 memset(parameters, 0, sizeof(EVE_HalParameters));
92 eve_assert_do(EVE_HalImpl_defaults(parameters, deviceIdx));
93}
94
104{
105 memset(phost, 0, sizeof(EVE_HalContext));
106 phost->UserContext = parameters->UserContext;
107 phost->CbCmdWait = parameters->CbCmdWait;
108 return EVE_HalImpl_open(phost, parameters);
109}
110
117{
118 if (phost->Status == EVE_STATUS_CLOSED)
119 {
120 eve_printf_debug("Attempt to close HAL context that is already closed\n");
121 return;
122 }
123
124#ifdef EVE_SUPPORT_MEDIAFIFO
125 EVE_Util_closeFile(phost);
126#endif
127 EVE_HalImpl_close(phost);
128 memset(phost, 0, sizeof(EVE_HalContext));
129}
130
140
142
143/*********************
144** TRANSFER HELPERS **
145*********************/
146
149
158{
159 uint8_t value;
161 value = EVE_Hal_transfer8(phost, 0);
162 EVE_Hal_endTransfer(phost);
163 return value;
164}
165
174{
175 uint16_t value;
177 value = EVE_Hal_transfer16(phost, 0);
178 EVE_Hal_endTransfer(phost);
179 return value;
180}
181
190{
191 uint32_t value;
193 value = EVE_Hal_transfer32(phost, 0);
194 EVE_Hal_endTransfer(phost);
195 return value;
196}
197
207{
209 EVE_Hal_transferMem(phost, result, NULL, size);
210 EVE_Hal_endTransfer(phost);
211}
212
226
240
254
269
284
295EVE_HAL_EXPORT void EVE_Hal_wrString(EVE_HalContext *phost, uint32_t addr, const char *str, uint32_t index, uint32_t size, uint32_t padMask)
296{
298 EVE_Hal_transferString(phost, str, index, size, padMask);
299 EVE_Hal_endTransfer(phost);
300}
302
303/************
304** UTILITY **
305************/
306
309
318{
319 uint32_t f;
320
321 /* Trim the internal clock by increase the REG_TRIM register till the measured frequency is within the acceptable range.*/
323 for (uint8_t i = 0; i < 31 && f < lowFreq; i++)
324 {
325 EVE_Hal_wr8(phost, REG_TRIM, i); /* increase the REG_TRIM register value automatically increases the internal clock */
327 }
328 EVE_Hal_wr32(phost, REG_FREQUENCY, f); /* Set the final frequency to be used for internal operations */
329
330 return f;
331}
333
334/*********
335** HOST **
336*********/
337
340
348{
349 EVE_Hal_hostCommand(phost, (uint8_t)pllsource);
350}
351
362
373
383
391{
392#if (EVE_SUPPORT_CHIPID >= EVE_FT810)
393 if (EVE_CHIPID >= EVE_FT810)
394 {
395#if (EVE_SUPPORT_CHIPID >= EVE_BT815)
396 if (EVE_SYSCLK_84M == freq)
397 EVE_Hal_hostCommandExt3(phost, (uint32_t)0x61 | (0x80 << 8) | (0x07 << 8));
398 else
399#endif
400 if (EVE_SYSCLK_72M == freq)
401 EVE_Hal_hostCommandExt3(phost, (uint32_t)0x61 | (0x40 << 8) | (0x06 << 8));
402 else if (EVE_SYSCLK_60M == freq)
403 EVE_Hal_hostCommandExt3(phost, (uint32_t)0x61 | (0x40 << 8) | (0x05 << 8));
404 else if (EVE_SYSCLK_48M == freq)
405 EVE_Hal_hostCommandExt3(phost, (uint32_t)0x61 | (0x40 << 8) | (0x04 << 8));
406 else if (EVE_SYSCLK_36M == freq)
407 EVE_Hal_hostCommandExt3(phost, (uint32_t)0x61 | (0x03 << 8));
408 else if (EVE_SYSCLK_24M == freq)
409 EVE_Hal_hostCommandExt3(phost, (uint32_t)0x61 | (0x02 << 8));
410 else if (EVE_SYSCLK_DEFAULT == freq) //default clock
411 EVE_Hal_hostCommandExt3(phost, 0x61);
412 }
413 else
414#endif
415 {
416 switch (freq)
417 {
418 case EVE_SYSCLK_24M:
420 break;
421 case EVE_SYSCLK_36M:
423 break;
424 default:
425 eve_printf_debug("Invalid sys clk frequency selected (%i)\n", (int)freq);
426 /* no break */
427 case EVE_SYSCLK_48M:
429 break;
430 }
431 }
432}
433
434#if (EVE_SUPPORT_CHIPID >= EVE_FT810)
442{
443 EVE_Hal_hostCommandExt3(phost, (uint32_t)0x49 | (val << 8));
444}
445
454{
455 EVE_Hal_hostCommandExt3(phost, (uint32_t)0x70 | (group << 8) | (strength << 8));
456}
457
467
477#endif
478
486void EVE_Hal_displayMessage(EVE_HalContext *phost, const char *str, uint16_t size)
487{
488 uint32_t round = ((size + 31U) & ~31U);
489 uint32_t addr = RAM_G + RAM_G_SIZE - round;
490 uint32_t dl = 0;
491
492 /* Abuse back of RAM_G to store error */
493 /* May invalidate user data... */
494 EVE_Hal_wrMem(phost, addr, (uint8_t *)str, size);
495
496 /* Empty remaining space after text */
498 for (uint32_t i = size; i < round; ++i)
499 EVE_Hal_transfer8(phost, 0);
500 EVE_Hal_endTransfer(phost);
501
502 /* Generate bluescreen */
503 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), CLEAR_COLOR_RGB(0x00, 0x20, 0x40));
504 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), CLEAR(1, 1, 1));
505 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), BITMAP_HANDLE(15)); /* Scratch handle will reset anyway after reset */
506 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), BITMAP_SOURCE(addr));
507 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), BITMAP_SIZE_H(0, 0));
508 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), BITMAP_SIZE(NEAREST, BORDER, BORDER, 256, (round >> 2)));
509 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), BITMAP_LAYOUT_H(0, 0));
510 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), BITMAP_LAYOUT(TEXT8X8, 32, (round >> 2)));
511 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), BEGIN(BITMAPS));
512 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), VERTEX2II(32, 32, 15, 0));
513#if ENABLE_ERR_REPORT
514 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), BITMAP_SOURCE(RAM_ERR_REPORT));
515 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), VERTEX2II(32, 96, 15, 0));
516#endif
517 EVE_Hal_wr32(phost, RAM_DL + ((dl++) << 2), DISPLAY());
519}
521
522/* end of file */
static uint32_t f
Definition Common.c:41
#define EVE_HAL_EXPORT
#define EVE_CHIPID
#define eve_progmem_const
#define EVE_FT810
Definition EVE_Config.h:58
#define TEXT8X8
#define RAM_ERR_REPORT
Definition EVE_GpuDefs.h:79
#define NEAREST
#define CLEAR(c, s, t)
#define BITMAP_LAYOUT(format, linestride, height)
#define REG_DLSWAP
#define BEGIN(prim)
#define BITMAPS
#define BITMAP_HANDLE(handle)
#define BITMAP_SIZE_H(width, height)
#define DISPLAY()
#define REG_TRIM
#define BITMAP_SOURCE(addr)
#define BORDER
#define REG_FREQUENCY
#define RAM_DL
Definition EVE_GpuDefs.h:95
#define DLSWAP_FRAME
#define BITMAP_LAYOUT_H(linestride, height)
#define RAM_G_SIZE
Definition EVE_GpuDefs.h:98
#define BITMAP_SIZE(filter, wrapx, wrapy, width, height)
#define RAM_G
Definition EVE_GpuDefs.h:77
#define CLEAR_COLOR_RGB(red, green, blue)
#define VERTEX2II(x, y, handle, cell)
EVE_81X_GPIO_DRIVE_STRENGTH_T
EVE_PLL_FREQ_T
@ EVE_PLL_36M
@ EVE_PLL_24M
@ EVE_PLL_48M
#define EVE_CORE_RESET
EVE_POWER_MODE_T
#define EVE_81X_RESET_ACTIVE
EVE_PLL_SOURCE_T
EVE_81X_PLL_FREQ_T
@ EVE_SYSCLK_84M
@ EVE_SYSCLK_36M
@ EVE_SYSCLK_60M
@ EVE_SYSCLK_DEFAULT
@ EVE_SYSCLK_48M
@ EVE_SYSCLK_24M
@ EVE_SYSCLK_72M
EVE_81X_GPIO_GROUP_T
#define EVE_81X_RESET_REMOVAL
EVE_HalPlatform g_HalPlatform
Definition EVE_Hal.c:43
EVE_HAL_EXPORT void EVE_Host_powerModeSwitch(EVE_HalContext *phost, EVE_POWER_MODE_T pwrmode)
Switch power mode for Coprocessor.
Definition EVE_Hal.c:369
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_HAL_EXPORT void EVE_Host_padDriveStrength(EVE_HalContext *phost, EVE_81X_GPIO_DRIVE_STRENGTH_T strength, EVE_81X_GPIO_GROUP_T group)
Set the drive strength for various pins.
Definition EVE_Hal.c:453
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
EVE_HAL_EXPORT void EVE_Hal_wrProgMem(EVE_HalContext *phost, uint32_t addr, eve_progmem_const uint8_t *buffer, uint32_t size)
Write a buffer in ProgMem to Coprocessor's memory.
Definition EVE_Hal.c:278
EVE_HAL_EXPORT void EVE_Hal_defaultsEx(EVE_HalParameters *parameters, size_t deviceIdx)
Setup default parameters for Eve_Hal framework.
Definition EVE_Hal.c:89
EVE_HAL_EXPORT void EVE_Host_pllFreqSelect(EVE_HalContext *phost, EVE_PLL_FREQ_T freq)
Select system clock for Coprocessor.
Definition EVE_Hal.c:358
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
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_HAL_EXPORT void EVE_Host_powerOffComponents(EVE_HalContext *phost, uint8_t val)
Power off a component.
Definition EVE_Hal.c:441
EVE_HAL_EXPORT int32_t EVE_Hal_clockTrimming(EVE_HalContext *phost, uint32_t lowFreq)
Trim the internal clock till the measured frequency is within the acceptable range.
Definition EVE_Hal.c:317
EVE_HAL_EXPORT void EVE_Host_selectSysClk(EVE_HalContext *phost, EVE_81X_PLL_FREQ_T freq)
Set system clock for Coprocessor.
Definition EVE_Hal.c:390
EVE_HAL_EXPORT bool EVE_Hal_open(EVE_HalContext *phost, const EVE_HalParameters *parameters)
Open the Eve_Hal framework.
Definition EVE_Hal.c:103
EVE_HAL_EXPORT void EVE_Hal_idle(EVE_HalContext *phost)
Idle handler for Eve_Hal framework.
Definition EVE_Hal.c:136
EVE_HAL_EXPORT void EVE_Host_resetActive(EVE_HalContext *phost)
Hold the device in reset state.
Definition EVE_Hal.c:463
EVE_HAL_EXPORT void EVE_Host_clockSelect(EVE_HalContext *phost, EVE_PLL_SOURCE_T pllsource)
Select clock source for Coprocessor.
Definition EVE_Hal.c:347
EVE_HAL_EXPORT void EVE_Hal_wr8(EVE_HalContext *phost, uint32_t addr, uint8_t v)
Write 8 bits to Coprocessor's memory.
Definition EVE_Hal.c:220
EVE_HAL_EXPORT void EVE_Host_resetRemoval(EVE_HalContext *phost)
Exit reset state, Eve will power on and enter into its default state.
Definition EVE_Hal.c:473
EVE_HAL_EXPORT void EVE_Host_coreReset(EVE_HalContext *phost)
Send reset signal to Coprocessor.
Definition EVE_Hal.c:379
EVE_HAL_EXPORT void EVE_Hal_close(EVE_HalContext *phost)
Close the Eve_Hal framework.
Definition EVE_Hal.c:116
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_HAL_EXPORT void EVE_Hal_wrString(EVE_HalContext *phost, uint32_t addr, const char *str, uint32_t index, uint32_t size, uint32_t padMask)
Write a string to Coprocessor's memory.
Definition EVE_Hal.c:295
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
EVE_HAL_EXPORT uint8_t EVE_Hal_rd8(EVE_HalContext *phost, uint32_t addr)
Read 8 bits from Coprocessor's memory.
Definition EVE_Hal.c:157
EVE_HAL_EXPORT void EVE_Hal_defaults(EVE_HalParameters *parameters)
Setup default parameters for Eve_Hal framework.
Definition EVE_Hal.c:78
EVE_HAL_EXPORT EVE_HalPlatform * EVE_Hal_initialize()
Eve_Hal framework initialization.
Definition EVE_Hal.c:52
EVE_HAL_EXPORT void EVE_Hal_release()
Close Eve_Hal framework.
Definition EVE_Hal.c:64
Eve_Hal framework APIs.
@ EVE_STATUS_CLOSED
Definition EVE_HalDefs.h:57
EVE_HAL_EXPORT uint8_t EVE_Hal_transfer8(EVE_HalContext *phost, uint8_t value)
Write 8 bits to Coprocessor.
EVE_HAL_EXPORT uint16_t EVE_Hal_transfer16(EVE_HalContext *phost, uint16_t value)
Write 2 bytes to Coprocessor.
EVE_HAL_EXPORT void EVE_Hal_startTransfer(EVE_HalContext *phost, EVE_TRANSFER_T rw, uint32_t addr)
Start data transfer to Coprocessor.
EVE_HAL_EXPORT void EVE_Hal_hostCommand(EVE_HalContext *phost, uint8_t cmd)
Send a host command to Coprocessor.
@ EVE_TRANSFER_WRITE
Definition EVE_HalDefs.h:68
@ EVE_TRANSFER_READ
Definition EVE_HalDefs.h:67
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.
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.
EVE_HAL_EXPORT void EVE_Hal_endTransfer(EVE_HalContext *phost)
End data transfer.
EVE_HAL_EXPORT uint32_t EVE_Hal_currentFrequency(EVE_HalContext *phost)
Get current system clock of Coprocessor.
EVE_HAL_EXPORT void EVE_Hal_hostCommandExt3(EVE_HalContext *phost, uint32_t cmd)
This API sends a 3byte command to the phost.
EVE_HAL_EXPORT uint32_t EVE_Hal_transfer32(EVE_HalContext *phost, uint32_t value)
Write 4 bytes to Coprocessor.
Eve_Hal framework APIs.
bool EVE_HalImpl_open(EVE_HalContext *phost, const EVE_HalParameters *parameters)
Opens a new HAL context using the specified parameters.
void EVE_Mcu_initialize()
Init FT9x host MCU.
bool EVE_HalImpl_defaults(EVE_HalParameters *parameters, size_t deviceIdx)
Get the default configuration parameters.
void EVE_Millis_release()
Release FT9x timer.
void EVE_HalImpl_close(EVE_HalContext *phost)
Close a HAL context.
void EVE_Mcu_release()
Release FT9x host MCU.
void EVE_HalImpl_initialize()
Initialize HAL platform.
void EVE_Millis_initialize()
Init FT9x timer.
void EVE_HalImpl_idle(EVE_HalContext *phost)
Idle. Call regularly to update frequently changing internal state.
void EVE_HalImpl_release()
Release HAL platform.
unsigned short uint16_t
int int32_t
unsigned int uint32_t
unsigned char uint8_t
EVE_HAL_EXPORT void EVE_Util_closeFile(EVE_HalContext *phost)
Platform selector.
#define eve_printf_debug(fmt,...)
#define eve_assert_ex(cond, ex)
#define eve_assert_do(cond)
static ft_uint32_t ft_uint8_t * buffer
Definition FT_Gpu_Hal.h:139
static ft_uint32_t addr
Definition FT_Gpu_Hal.h:139
EVE_Callback CbCmdWait
EVE_STATUS_T Status
EVE_Callback CbCmdWait
uint32_t OpenedDevices