From: SnickerSun Date: Tue, 27 Aug 2024 01:01:03 +0000 (+0800) Subject: patch_0626_to_0720 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~425 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=08ee4ff2e4aed8d48185534cf37a821d317dc297;p=mirrors%2FFD230.git patch_0626_to_0720 --- diff --git a/code/sdk/application/brandy/brandy_standard/kernel_init.c b/code/sdk/application/brandy/brandy_standard/kernel_init.c index 2180c636f..9c344734a 100644 --- a/code/sdk/application/brandy/brandy_standard/kernel_init.c +++ b/code/sdk/application/brandy/brandy_standard/kernel_init.c @@ -174,8 +174,13 @@ static void OsCacheInit(void) static void chip_watchdog_init(void) { watchdog_turnon_clk(); +#ifdef CONFIG_SYSTEM_VIEW + watchdog_func_adapt(CHIP_WDT_TIMEOUT_128S); + uapi_watchdog_init(CHIP_WDT_TIMEOUT_128S); +#else watchdog_func_adapt(CHIP_WDT_TIMEOUT_32S); uapi_watchdog_init(CHIP_WDT_TIMEOUT_32S); +#endif uapi_watchdog_enable(WDT_MODE_INTERRUPT); } diff --git a/code/sdk/application/brandy/brandy_standard/thread_init.c b/code/sdk/application/brandy/brandy_standard/thread_init.c index 1fa120900..99894d65d 100644 --- a/code/sdk/application/brandy/brandy_standard/thread_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_init.c @@ -24,6 +24,7 @@ #include "pm_control.h" #include "dfx_system_init.h" #include "cpu_load.h" +#include "exception_dump.h" #ifdef SUPPORT_AT_CMD #include "at_cmd_api.h" @@ -194,6 +195,9 @@ osSemaphoreId_t get_save_file_semaphore(void) void save_file_main(void) { + if (osKernelGetState() == osKernelRunning) { + dump_norflash_trace_to_file(); + } g_semaphore_save = osSemaphoreNew(1, 0, NULL); if (!g_semaphore_save) { panic(PANIC_LOG, LOG_PANIC_MUTEX_NOT_READY); diff --git a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c index 93c7f41df..c527654f8 100644 --- a/code/sdk/application/brandy/brandy_standard/thread_pri_init.c +++ b/code/sdk/application/brandy/brandy_standard/thread_pri_init.c @@ -119,6 +119,14 @@ static void emmc_init(void) } #endif +#ifdef CFG_SDIO_EMMC_COEXIST +static void sdio_init(void) +{ + init_sdio_pinmux(); + sdio_drv_context_init(); +} +#endif + #ifdef CFG_DRIVERS_NANDFLASH static void nandflash_init(void) { @@ -304,6 +312,9 @@ static void thread_main(const void *unused) g_store_init_select = STORE_CLASS_EMMC; sdiom_internal_freq_handler_register(mmc_set_internal_clk); #endif +#ifdef CFG_SDIO_EMMC_COEXIST + sdio_init(); +#endif #ifdef CFG_DRIVERS_NANDFLASH yaffs_nand_drv_checkptset(YAFFS_CHECKPT_SKIPED); nandflash_init(); @@ -333,6 +344,10 @@ static void thread_main(const void *unused) uapi_calendar_init(); #ifdef SUPPORT_AT_OHOSFWK ohos_startup(); +#endif +#ifdef CONFIG_SYSTEM_VIEW + SEGGER_SYSVIEW_Conf(); + // 请在抓取systemview开始的地方调用SEGGER_SYSVIEW_Start接口 #endif uapi_pm_remove_sleep_veto(PM_ID_DEBUG); set_startup_finish_flag(); diff --git a/code/sdk/application/wearable/CMakeLists.txt b/code/sdk/application/wearable/CMakeLists.txt index 0e54ea283..364c3478d 100644 --- a/code/sdk/application/wearable/CMakeLists.txt +++ b/code/sdk/application/wearable/CMakeLists.txt @@ -12,4 +12,5 @@ add_subdirectory_if_exist(xts_adapt) add_subdirectory_if_exist(alipay) if("SUPPORT_AUTO_OTA" IN_LIST DEFINES) add_subdirectory_if_exist(auto_ota) -endif() \ No newline at end of file +endif() +add_subdirectory_with_alias_if_exist(SystemView ${PROJECT_BINARY_DIR}/systemview) \ No newline at end of file diff --git a/code/sdk/application/wearable/SystemView/CMakeLists.txt b/code/sdk/application/wearable/SystemView/CMakeLists.txt new file mode 100644 index 000000000..5993c99ba --- /dev/null +++ b/code/sdk/application/wearable/SystemView/CMakeLists.txt @@ -0,0 +1,50 @@ +#=============================================================================== +# @brief cmake file +# Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. +#=============================================================================== +set(COMPONENT_NAME "systemview") + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/Src/SEGGER/SEGGER_RTT.c + ${CMAKE_CURRENT_SOURCE_DIR}/Src/SEGGER/SEGGER_SYSVIEW.c + ${CMAKE_CURRENT_SOURCE_DIR}/Src/Sample/LiteOS/SEGGER_SYSVIEW_LiteOS.c + ${CMAKE_CURRENT_SOURCE_DIR}/Src/Sample/LiteOS/Config/SEGGER_SYSVIEW_Config_LiteOS.c +) + +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/Src/SEGGER + ${CMAKE_CURRENT_SOURCE_DIR}/Src/Config + ${CMAKE_CURRENT_SOURCE_DIR}/Src/Sample/LiteOS +) + +set(PRIVATE_HEADER +) + +set(PRIVATE_DEFINES +) + +set(PUBLIC_DEFINES + CONFIG_SYSTEM_VIEW +) + +# use this when you want to add ccflags like -include xxx +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS +-Wno-pointer-arith +-Wno-strict-prototypes +-Wno-implicit-function-declaration +-Wno-unused-function +-Wno-int-conversion +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +build_component() \ No newline at end of file diff --git a/code/sdk/application/wearable/SystemView/Readme.txt b/code/sdk/application/wearable/SystemView/Readme.txt new file mode 100644 index 000000000..8b05d5ec9 --- /dev/null +++ b/code/sdk/application/wearable/SystemView/Readme.txt @@ -0,0 +1,13 @@ +启用systemview调试。 注意:当前仅适配liteos版本。源代码需要用户获取,SDK仅发布litesos适配部分,建议使用v3.42版本。 +1)在config.py对应target增加systemview组件。 +2)在kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/tools/build/config/brandy.config将LOSCFG_SYSTEM_VIEW配置为y +3)将systemview源代码放置application/wearable/SystemView/Src下,其中Sample中sdk已发布了LiteOS适配。 +4)SystemView/Src/Sample/LiteOS/Tooladapt下SYSVIEW_LiteOS.txt放置在PC端SYSTEMVIEW工具的Description文件夹下。 + + +在线模式。 +1.在SEGGER_SYSVIEW_ConfDefaults.h中将SEGGER_SYSVIEW_POST_MORTEM_MODE配置为0 +2.在SEGGER_SYSVIEW_ConfDefaults.h中将SEGGER_SYSVIEW_RTT_BUFFER_SIZE修改为(16 * 1024) +3.通过application.lst中获取_SEGGER_RTT 变量地址。 +4.通过工具的recorder configuration配置RTT的Detection地址,然后启动采集。 + diff --git a/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/Config/SEGGER_SYSVIEW_Config_LiteOS.c b/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/Config/SEGGER_SYSVIEW_Config_LiteOS.c new file mode 100644 index 000000000..c6d323856 --- /dev/null +++ b/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/Config/SEGGER_SYSVIEW_Config_LiteOS.c @@ -0,0 +1,127 @@ +/********************************************************************* +* SEGGER Microcontroller GmbH & Co. KG * +* The Embedded Experts * +********************************************************************** +* * +* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the RTT protocol and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* conditions are met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this list of conditions and the following disclaimer. * +* * +* o Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the following * +* disclaimer in the documentation and/or other materials provided * +* with the distribution. * +* * +* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * +* nor the names of its contributors may be used to endorse or * +* promote products derived from this software without specific * +* prior written permission. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: V2.52a * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_Config_FreeRTOS.c +Purpose : Sample setup configuration of SystemView with FreeRTOS. +Revision: $Rev: 7745 $ +*/ +#include "los_base.h" +#include "los_config.h" +#include "los_hwi_pri.h" +#include "tcxo.h" +#include "SEGGER_SYSVIEW.h" + +#define configCPU_CLOCK_HZ ( OS_SYS_CLOCK ) + +extern const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI; + +/********************************************************************* +* +* Defines, configurable +* +********************************************************************** +*/ +// The application name to be displayed in SystemViewer +#define SYSVIEW_APP_NAME "LiteOS Demo Application" + +// The target device name +#define SYSVIEW_DEVICE_NAME "RISCV" + +// Frequency of the timestamp. Must match SEGGER_SYSVIEW_GET_TIMESTAMP in SEGGER_SYSVIEW_Conf.h +#define SYSVIEW_TIMESTAMP_FREQ (configCPU_CLOCK_HZ) + +// System Frequency. SystemcoreClock is used in most CMSIS compatible projects. +#define SYSVIEW_CPU_FREQ configCPU_CLOCK_HZ + +// The lowest RAM address used for IDs (pointers) +#define SYSVIEW_RAM_BASE (0x20000000) + +/********************************************************************* +* +* _cbSendSystemDesc() +* +* Function description +* Sends SystemView description strings. +*/ +static void _cbSendSystemDesc(void) { + SEGGER_SYSVIEW_SendSysDesc("N="SYSVIEW_APP_NAME",D="SYSVIEW_DEVICE_NAME",O=LiteOS"); + SEGGER_SYSVIEW_SendSysDesc("I#15=SysTick"); +} + +/********************************************************************* +* +* Global functions +* +********************************************************************** +*/ +void SEGGER_SYSVIEW_Conf(void) { + SEGGER_SYSVIEW_Init(SYSVIEW_TIMESTAMP_FREQ, SYSVIEW_CPU_FREQ, + &SYSVIEW_X_OS_TraceAPI, _cbSendSystemDesc); + SEGGER_SYSVIEW_SetRAMBase(SYSVIEW_RAM_BASE); +} + +U32 SEGGER_SYSVIEW_X_GetTimestamp(void) { + return uapi_tcxo_get_count(); +} + +U32 SEGGER_SYSVIEW_X_GetInterruptId(void) { + return OsIntNumGet(); +} + +/*************************** End of file ****************************/ diff --git a/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/SEGGER_SYSVIEW_LiteOS.c b/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/SEGGER_SYSVIEW_LiteOS.c new file mode 100644 index 000000000..a65aa1e27 --- /dev/null +++ b/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/SEGGER_SYSVIEW_LiteOS.c @@ -0,0 +1,681 @@ +/* ******************************************************************** +* SEGGER Microcontroller GmbH & Co. KG * +* The Embedded Experts * +********************************************************************** +* * +* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the RTT protocol and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* conditions are met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this list of conditions and the following disclaimer. * +* * +* o Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the following * +* disclaimer in the documentation and/or other materials provided * +* with the distribution. * +* * +* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * +* nor the names of its contributors may be used to endorse or * +* promote products derived from this software without specific * +* prior written permission. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: V2.52a * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_FreeRTOS.c +Purpose : Interface between FreeRTOS and SystemView. +Revision: $Rev: 7947 $ +*/ +#include "los_base.h" +#include "los_task.h" +#include "los_config.h" +#include "los_task_pri.h" +#include "SEGGER_SYSVIEW.h" +#include "SEGGER_SYSVIEW_LiteOS.h" +#include "string.h" // Required for memset + +#define PRODUCT_TSK_MAX_SUPPORT_NUM 32 /* max num task */ +typedef UINT32 TickType_t; +#define configTICK_RATE_HZ ((TickType_t)1000) +#define portTICK_PERIOD_MS ((TickType_t)1000 / configTICK_RATE_HZ) +typedef struct SYSVIEW_FREERTOS_TASK_STATUS SYSVIEW_FREERTOS_TASK_STATUS; + +struct SYSVIEW_FREERTOS_TASK_STATUS { + U32 xHandle; + const char *pcTaskName; + unsigned uxCurrentPriority; + U32 pxStack; + unsigned uStackHighWaterMark; +}; + +static SYSVIEW_FREERTOS_TASK_STATUS _aTasks[SYSVIEW_LITEOS_MAX_NOF_TASKS]; +static unsigned _NumTasks; + +static inline U64 MC_GetTick(void) +{ + return uapi_tcxo_get_ms(); +} +/* ******************************************************************** + * + * _cbSendTaskList() + * + * Function description + * This function is part of the link between FreeRTOS and SYSVIEW. + * Called from SystemView when asked by the host, it uses SYSVIEW + * functions to send the entire task list to the host. + */ +static void _cbSendTaskList(void) +{ + unsigned n; + + for (n = 0; n < _NumTasks; n++) { +#if INCLUDE_uxTaskGetStackHighWaterMark // Report Task Stack High Watermark + _aTasks[n].uStackHighWaterMark = uxTaskGetStackHighWaterMark((TaskHandle_t)_aTasks[n].xHandle); +#endif + SYSVIEW_SendTaskInfo((U32)_aTasks[n].xHandle, _aTasks[n].pcTaskName, (unsigned)_aTasks[n].uxCurrentPriority, + (U32)_aTasks[n].pxStack, (unsigned)_aTasks[n].uStackHighWaterMark); + } +} + +/* ******************************************************************** + * + * _cbGetTime() + * + * Function description + * This function is part of the link between FreeRTOS and SYSVIEW. + * Called from SystemView when asked by the host, returns the + * current system time in micro seconds. + */ +static U64 _cbGetTime(void) +{ + U64 Time; + + Time = MC_GetTick(); + Time *= portTICK_PERIOD_MS; + Time *= 1000; + return Time; +} + +/* ******************************************************************** + * + * Global functions + * + * ********************************************************************* + */ +/* ******************************************************************** + * + * SYSVIEW_AddTask() + * + * Function description + * Add a task to the internal list and record its information. + */ +void SYSVIEW_AddTask(U32 xHandle, const char *pcTaskName, unsigned uxCurrentPriority, U32 pxStack, + unsigned uStackHighWaterMark) +{ + if (memcmp(pcTaskName, "IdleCore000", 11) == 0) { + return; + } + + if (_NumTasks >= SYSVIEW_LITEOS_MAX_NOF_TASKS) { + SEGGER_SYSVIEW_Warn("SYSTEMVIEW: Could not record task information. Maximum number of tasks reached."); + return; + } + + _aTasks[_NumTasks].xHandle = xHandle; + _aTasks[_NumTasks].pcTaskName = pcTaskName; + _aTasks[_NumTasks].uxCurrentPriority = uxCurrentPriority; + _aTasks[_NumTasks].pxStack = pxStack; + _aTasks[_NumTasks].uStackHighWaterMark = uStackHighWaterMark; + + _NumTasks++; + + SYSVIEW_SendTaskInfo(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark); +} + +/* ******************************************************************** + * + * SYSVIEW_UpdateTask() + * + * Function description + * Update a task in the internal list and record its information. + */ +void SYSVIEW_UpdateTask(U32 xHandle, const char *pcTaskName, unsigned uxCurrentPriority, U32 pxStack, + unsigned uStackHighWaterMark) +{ + unsigned n; + + if (memcmp(pcTaskName, "IdleCore000", 11) == 0) { + return; + } + + for (n = 0; n < _NumTasks; n++) { + if (_aTasks[n].xHandle == xHandle) { + break; + } + } + if (n < _NumTasks) { + _aTasks[n].pcTaskName = pcTaskName; + _aTasks[n].uxCurrentPriority = uxCurrentPriority; + _aTasks[n].pxStack = pxStack; + _aTasks[n].uStackHighWaterMark = uStackHighWaterMark; + + SYSVIEW_SendTaskInfo(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark); + } else { + SYSVIEW_AddTask(xHandle, pcTaskName, uxCurrentPriority, pxStack, uStackHighWaterMark); + } +} + +/* ******************************************************************** + * + * SYSVIEW_DeleteTask() + * + * Function description + * Delete a task from the internal list. + */ +void SYSVIEW_DeleteTask(U32 xHandle) +{ + unsigned n; + + if (_NumTasks == 0) { + return; // Early out + } + for (n = 0; n < _NumTasks; n++) { + if (_aTasks[n].xHandle == xHandle) { + break; + } + } + if (n == (_NumTasks - 1)) { + // + // Task is last item in list. + // Simply zero the item and decrement number of tasks. + // + memset(&_aTasks[n], 0, sizeof(_aTasks[n])); + _NumTasks--; + } else if (n < _NumTasks) { + // + // Task is in the middle of the list. + // Move last item to current position and decrement number of tasks. + // Order of tasks does not really matter, so no need to move all following items. + // + _aTasks[n].xHandle = _aTasks[_NumTasks - 1].xHandle; + _aTasks[n].pcTaskName = _aTasks[_NumTasks - 1].pcTaskName; + _aTasks[n].uxCurrentPriority = _aTasks[_NumTasks - 1].uxCurrentPriority; + _aTasks[n].pxStack = _aTasks[_NumTasks - 1].pxStack; + _aTasks[n].uStackHighWaterMark = _aTasks[_NumTasks - 1].uStackHighWaterMark; + memset(&_aTasks[_NumTasks - 1], 0, sizeof(_aTasks[_NumTasks - 1])); + _NumTasks--; + } +} + +/* ******************************************************************** + * + * SYSVIEW_SendTaskInfo() + * + * Function description + * Record task information. + */ +void SYSVIEW_SendTaskInfo(U32 TaskID, const char *sName, unsigned Prio, U32 StackBase, unsigned StackSize) +{ + SEGGER_SYSVIEW_TASKINFO TaskInfo; + + memset(&TaskInfo, 0, sizeof(TaskInfo)); // Fill all elements with 0 to allow extending the structure in future + // version without breaking the code + TaskInfo.TaskID = TaskID; + TaskInfo.sName = sName; + TaskInfo.Prio = Prio; + TaskInfo.StackBase = StackBase; + TaskInfo.StackSize = StackSize; + SEGGER_SYSVIEW_SendTaskInfo(&TaskInfo); +} + +/* ******************************************************************** + * + * SYSVIEW_RecordU32x4() + * + * Function description + * Record an event with 4 parameters + */ +void SYSVIEW_RecordU32x4(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3) +{ + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 4 * SEGGER_SYSVIEW_QUANTA_U32]; + U8 *pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} + +/* ******************************************************************** + * + * SYSVIEW_RecordU32x5() + * + * Function description + * Record an event with 5 parameters + */ +void SYSVIEW_RecordU32x5(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4) +{ + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + 5 * SEGGER_SYSVIEW_QUANTA_U32]; + U8 *pPayload; + // + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); // Prepare the packet for SystemView + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); // Add the first parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); // Add the second parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); // Add the third parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para3); // Add the fourth parameter to the packet + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para4); // Add the fifth parameter to the packet + // + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, Id); // Send the packet +} + +/* ****************************************************************** + * + * SEGGER_SYSVIEW_RecordU32_String + * + * Function description + * Record an event with 1 parameter and one description string + */ +void SEGGER_SYSVIEW_RecordU32_String(U32 EventID, U32 Para0, const char *sDescription) +{ + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN + 1]; + U8 *pPayload; + + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); + pPayload = SEGGER_SYSVIEW_EncodeString(pPayload, sDescription, SEGGER_SYSVIEW_MAX_STRING_LEN); + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, EventID); +} + +/* ****************************************************************** + * + * SEGGER_SYSVIEW_RecordU32x2_String + * + * Function description + * Record an event with 2 parameter and one description string + */ +void SEGGER_SYSVIEW_RecordU32x2_String(U32 EventID, U32 Para0, U32 Para1, const char *sDescription) +{ + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN + 1]; + U8 *pPayload; + + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); + pPayload = SEGGER_SYSVIEW_EncodeString(pPayload, sDescription, SEGGER_SYSVIEW_MAX_STRING_LEN); + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, EventID); +} + +/* ****************************************************************** + * + * SEGGER_SYSVIEW_RecordU32x3_String + * + * Function description + * Record an event with 3 parameter and one description string + */ +void SEGGER_SYSVIEW_RecordU32x3_String(U32 EventID, U32 Para0, U32 Para1, U32 Para2, const char *sDescription) +{ + U8 aPacket[SEGGER_SYSVIEW_INFO_SIZE + SEGGER_SYSVIEW_QUANTA_U32 + SEGGER_SYSVIEW_MAX_STRING_LEN + 1]; + U8 *pPayload; + + pPayload = SEGGER_SYSVIEW_PREPARE_PACKET(aPacket); + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para0); + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para1); + pPayload = SEGGER_SYSVIEW_EncodeU32(pPayload, Para2); + pPayload = SEGGER_SYSVIEW_EncodeString(pPayload, sDescription, SEGGER_SYSVIEW_MAX_STRING_LEN); + SEGGER_SYSVIEW_SendPacket(&aPacket[0], pPayload, EventID); +} + + +/** + * queue trace. + */ +#if (ENABLE_QUEUE_TRACE == 1) +void LOS_TRACE_QUEUE_CREATE(UINT32 queueId, UINT16 len, UINT16 msgSize, UINTPTR queue, UINT8 queueMemType) +{ + SEGGER_SYSVIEW_RecordU32x4(ID_OFFSET + ID_LOS_QUEUECREATE, queueId, (UINT32)len, (UINT32)queue, + (UINT32)queueMemType); +} +void LOS_TRACE_QUEUE_DELETE(UINT32 queueId, UINT8 queueState, UINT16 readWriteableCnt) +{ + SEGGER_SYSVIEW_RecordU32x3(ID_OFFSET + ID_LOS_QUEUEDELETE, queueId, (UINT32)queueState, (UINT32)readWriteableCnt); +} +void LOS_TRACE_QUEUE_RW(UINT32 queueId, UINT16 queueSize, UINT32 bufferSize, UINT32 operateType, UINT16 readableCnt, + UINT16 writeableCnt, UINT32 timeout) +{ + SEGGER_SYSVIEW_RecordU32x5(ID_OFFSET + ID_LOS_QUEUERW, queueId, operateType, (UINT32)readableCnt, + (UINT32)writeableCnt, timeout); +} +#endif + +/** + * event trace. + */ +#if (ENABLE_EVENT_TRACE == 1) +void LOS_TRACE_EVENT_CREATE(UINTPTR eventCB) +{ + SEGGER_SYSVIEW_RecordString(ID_OFFSET + ID_LOS_EVENTINIT, "EventCreate."); +} +void LOS_TRACE_EVENT_READ(UINTPTR eventCB, UINT32 uwEventID, UINT32 eventMask, UINT32 mode, UINT32 timeout) +{ + if (mode == LOS_WAITMODE_OR) { + SEGGER_SYSVIEW_RecordU32x2_String(ID_OFFSET + ID_LOS_EVENTREAD, uwEventID, eventMask, "OR"); + } else if (mode == LOS_WAITMODE_AND) { + SEGGER_SYSVIEW_RecordU32x2_String(ID_OFFSET + ID_LOS_EVENTREAD, uwEventID, eventMask, "AND"); + } +} +void LOS_TRACE_EVENT_WRITE(UINTPTR eventCB, UINT32 uwEventID, UINT32 events) +{ + SEGGER_SYSVIEW_RecordU32x2(ID_OFFSET + ID_LOS_EVENTWRITE, uwEventID, events); +} +void LOS_TRACE_EVENT_CLEAR(UINTPTR eventCB, UINT32 uwEventID, UINT32 events) +{ + SEGGER_SYSVIEW_RecordU32x2(ID_OFFSET + ID_LOS_EVENTCLEAR, uwEventID, events); +} +void LOS_TRACE_EVENT_DELETE(UINTPTR eventCB, UINT32 ret) +{ + SEGGER_SYSVIEW_RecordU32_String(ID_OFFSET + ID_LOS_EVENTDESTROY, ret, "EventDestroy"); +} + +void LOS_TRACE_EVENT_COND_READ(UINTPTR eventCB, UINT32 uwEventID) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_CON_READ, uwEventID); +} +void LOS_TRACE_EVENT_COND_WRITE(UINTPTR eventCB, UINT32 uwEventID) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_CON_WRITE, uwEventID); +} +#endif + +/** + * mutex trace. + */ +#if (ENABLE_EVENT_TRACE == 1) +void LOS_TRACE_MUX_CREATE(UINT32 muxId) +{ + SEGGER_SYSVIEW_RecordU32_String(ID_OFFSET + ID_LOS_MUXCREATE, muxId, "muxStat = mux_used"); +} +void LOS_TRACE_MUX_POST(UINT32 muxHandle, UINT16 muxCount, UINT32 taskId) +{ + SEGGER_SYSVIEW_RecordU32x3(ID_OFFSET + ID_LOS_MUXPOST, muxHandle, (UINT32)muxCount, taskId); +} +void LOS_TRACE_MUX_PEND(UINT32 muxHandle, UINT16 muxCount, UINT32 taskId, UINT32 timeout) +{ + SEGGER_SYSVIEW_RecordU32x4(ID_OFFSET + ID_LOS_MUXPEND, muxHandle, (UINT32)muxCount, taskId, timeout); +} +void LOS_TRACE_MUX_DELETE(UINT32 muxHandle, UINT8 muxStat, UINT16 muxCount, UINT32 taskId) +{ + SEGGER_SYSVIEW_RecordU32x4(ID_OFFSET + ID_LOS_MUXDELETE, muxHandle, (UINT32)muxStat, (UINT32)muxCount, taskId); +} +#endif + +/** + * semphore trace. + */ +#if (ENABLE_SEM_TRACE == 1) +void LOS_TRACE_SEM_CREATE(UINT32 semId, UINT8 type, UINT16 count) +{ + SEGGER_SYSVIEW_RecordU32x3(ID_OFFSET + ID_LOS_SEMCREATE, semId, (UINT32)type, (UINT32)count); +} +void LOS_TRACE_SEM_DELETE(UINT32 semHandle, UINT32 ret) +{ + SEGGER_SYSVIEW_RecordU32x2_String(ID_OFFSET + ID_LOS_SEMDELETE, semHandle, ret, "semStat = OS_SEM_UNUSED"); +} +void LOS_TRACE_SEM_PEND(UINT32 semHandle, UINT16 semCount, UINT32 timeout) +{ + SEGGER_SYSVIEW_RecordU32x3(ID_OFFSET + ID_LOS_SEMPEND, semHandle, (UINT32)semCount, timeout); +} +void LOS_TRACE_SEM_POST(UINT32 semHandle, UINT8 semType, UINT16 semCount) +{ + SEGGER_SYSVIEW_RecordU32x3(ID_OFFSET + ID_LOS_SEMPOST, semHandle, (UINT32)semType, (UINT32)semCount); +} +#endif + +/** + * memory alloc&free trace. + */ +#if (ENABLE_MEM_TRACE == 1) +void LOS_TRACE_MEM_INFO_REQ(VOID *pool) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_MEMINIT, (UINT32)pool); +} +void LOS_TRACE_MEM_ALLOC(VOID *pool, UINTPTR ptr, UINT32 size) +{ + SEGGER_SYSVIEW_RecordU32x3(ID_OFFSET + ID_LOS_MEMALLOC, (UINT32)pool, (UINT32)ptr, size); +} +void LOS_TRACE_MEM_FREE(VOID *pool, UINTPTR ptr) +{ + SEGGER_SYSVIEW_RecordU32x2(ID_OFFSET + ID_LOS_MEMFREE, (UINT32)pool, (UINT32)ptr); +} +void LOS_TRACE_MEM_REALLOC(VOID *pool, UINTPTR ptr, UINT32 size) +{ + SEGGER_SYSVIEW_RecordU32x3(ID_OFFSET + ID_LOS_MEMREALLOC, (UINT32)pool, (UINT32)ptr, size); +} +void LOS_TRACE_MEM_ALLOC_ALIGN(VOID *pool, UINTPTR ptr, UINT32 size, UINT32 boundary) +{ + SEGGER_SYSVIEW_RecordU32x4(ID_OFFSET + ID_LOS_MEMALLOCALIGN, (UINT32)pool, (UINT32)ptr, (UINT32)size, + (UINT32)boundary); +} +#endif + +/** + * task trace. + */ +#if (ENABLE_TASK_TRACE == 1) +#ifdef LOSCFG_KERNEL_SMP +void LOS_TRACE_TASK_SIGNAL(UINT32 taskId, UINT32 mpSignal) +{ + ; +} +#endif +// void LOS_TRACE_TASK_DELAY(UINT32 tick); +void LOS_TRACE_TASK_RESUME(UINT32 taskId, UINT16 taskStatus, UINT16 priority) +{ + LosTaskCB *newTask = OS_TCB_FROM_TID(taskId); + SEGGER_SYSVIEW_OnTaskStartReady((UINT32)newTask); +} +void LOS_TRACE_TASK_DELETE(UINT32 taskId, UINT16 taskStatus, UINT32 usrStack) +{ + LosTaskCB *newTask = OS_TCB_FROM_TID(taskId); + SEGGER_SYSVIEW_RecordU32_String(ID_OFFSET + ID_LOS_TASK_DELETE, taskId, newTask->taskName); + SYSVIEW_DeleteTask((UINT32)newTask); +} +void LOS_TRACE_TASK_PRIOSET(UINT32 taskId, UINT16 taskStatus, UINT16 priority, UINT16 taskPrio) +{ + LosTaskCB *newTask = OS_TCB_FROM_TID(taskId); + SEGGER_SYSVIEW_RecordU32x2(ID_OFFSET + ID_LOS_TASK_PRIOSET, SEGGER_SYSVIEW_ShrinkId((U32)newTask), priority); + SYSVIEW_UpdateTask((UINT32)newTask, &(newTask->taskName[0]), (UINT32)priority, (UINT32)newTask->stackPointer, 0); +} + +// sched trace +void LOS_TRACE_TASK_SWITCH(UINT32 taskId, UINT16 runPriority, UINT16 curTaskStatus, UINT16 newPriority, + UINT16 newTaskStatus) +{ + LosTaskCB *newTask = OS_TCB_FROM_TID(taskId); + if (memcmp(newTask->taskName, "IdleCore000", 11) == 0) { + SEGGER_SYSVIEW_OnIdle(); + } else { + SEGGER_SYSVIEW_OnTaskStartExec((UINT32)newTask); + } +} +#ifndef LOSCFG_SCHED_LATENCY +void LOS_TRACE_TASK_SIGNAL(UINT32 taskId, UINT32 schedFlag) {} +#endif +void LOS_TRACE_TASK_SUSPEND(UINT32 taskId, UINT16 taskStatus, UINT32 currTaskId) +{ + LosTaskCB *newTask = OS_TCB_FROM_TID(taskId); + SEGGER_SYSVIEW_OnTaskStopReady((UINT32)newTask, ((3u << 3) | 3)); +} + +void LOS_TRACE_MOVED_TASK_TO_READY_STATE(const LosTaskCB *pstTaskCB) +{ + SEGGER_SYSVIEW_OnTaskStartReady((UINT32)pstTaskCB); +} +void LOS_TRACE_MOVED_TASK_TO_DELAYED_LIST(const LosTaskCB *pstTaskCB) +{ + ; +} +void LOS_TRACE_MOVED_TASK_TO_SUSPENDED_LIST(const LosTaskCB *pstTaskCB) +{ + ; +} + +void LOS_TRACE_ISR_EXIT_TO_SCHEDULER(void) +{ + ; +} +void LOS_TRACE_ISR_ENTER(U32 hwiIndex) +{ + ; +} +void LOS_TRACE_ISR_EXIT(U32 hwiIndex) +{ + ; +} +#endif + +/** + * swtmr trace. + */ +#if (ENABLE_SWTMR_TRACE == 1) +void LOS_TRACE_SWTMR_EXPIRED(UINT16 timerId) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_SWTMR_EXPIRED, (UINT32)timerId); +} +void LOS_TRACE_SWTMR_CREATE(UINT16 timerId) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_SWTMR_CREATE, (UINT32)timerId); +} +void LOS_TRACE_SWTMR_START(UINT16 timerId, UINT8 mode, UINT8 overrun, UINT32 interval, UINT32 expiry) +{ + SEGGER_SYSVIEW_RecordU32x5(ID_OFFSET + ID_LOS_SWTMR_START, (UINT32)timerId, (UINT32)mode, (UINT32)overrun, + (UINT32)interval, (UINT32)expiry); +} +void LOS_TRACE_SWTMR_STOP(UINT16 timerId) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_SWTMR_STOP, (UINT32)timerId); +} +void LOS_TRACE_SWTMR_DELETE(UINT16 timerId) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_SWTMR_DELETE, (UINT32)timerId); +} +#endif + +/** + * hwi trace. + */ +// Machine timer interrupt too frequency +#define OS_TICK_INT_NUM_SYSTEM_VIEW 7 +void LOS_TRACE_HWI_RESPONSE_IN(UINT32 hwiNum) +{ + if (hwiNum == OS_TICK_INT_NUM_SYSTEM_VIEW) { + return; + } + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + LOS_TRACE_HWI_RESPONSE_IN, hwiNum); + SEGGER_SYSVIEW_RecordEnterISR(); +} +void LOS_TRACE_HWI_RESPONSE_OUT(UINT32 hwiNum) +{ + if (hwiNum == OS_TICK_INT_NUM_SYSTEM_VIEW) { + return; + } + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_HWI_RESPONSE_OUT, hwiNum); + SEGGER_SYSVIEW_RecordExitISR(); +} +#if (ENABLE_HWI_TRACE == 1) +void LOS_TRACE_HWI_CREATE(UINT32 hwiNum, HWI_PRIOR_T hwiPrio, HWI_MODE_T hwiMode, UINTPTR hwiHandler) +{ + SEGGER_SYSVIEW_RecordU32x4(ID_OFFSET + ID_LOS_HWI_CREATE, hwiNum, (UINT32)hwiPrio, (UINT32)hwiMode, + (UINT32)hwiHandler); +} +void LOS_TRACE_HWI_CREATE_NODE(UINT32 hwiNum, UINTPTR pDevId, UINT32 ret) +{ + SEGGER_SYSVIEW_RecordU32x2(ID_OFFSET + ID_LOS_HWI_CREATE_NODE, (UINT32)pDevId, ret); +} +void LOS_TRACE_HWI_DELETE(UINT32 hwiNum) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_HWI_DELETE, hwiNum); +} +void LOS_TRACE_HWI_DELETE_NODE(UINT32 hwiNum, UINTPTR pDevId, UINT32 ret) +{ + SEGGER_SYSVIEW_RecordU32x3(ID_OFFSET + ID_LOS_HWI_DELETE_NODE, hwiNum, (UINT32)pDevId, ret); +} +void LOS_TRACE_HWI_TRIGGER(UINT32 hwiNum) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_HWI_TRIGGER, hwiNum); +} +void LOS_TRACE_HWI_ENABLE(UINT32 hwiNum) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_HWI_ENABLE, hwiNum); +} +void LOS_TRACE_HWI_DISABLE(UINT32 hwiNum) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_HWI_DISABLE, hwiNum); +} +void LOS_TRACE_HWI_CLEAR(UINT32 hwiNum) +{ + SEGGER_SYSVIEW_RecordU32(ID_OFFSET + ID_LOS_HWI_CLEAR, hwiNum); +} +void LOS_TRACE_HWI_SETPRI(UINT32 hwiNum, HWI_PRIOR_T priority) +{ + SEGGER_SYSVIEW_RecordU32x2(ID_OFFSET + ID_LOS_HWI_SETPRI, hwiNum, (UINT32)priority); +} +void LOS_TRACE_HWI_SETAFFINITY(UINT32 hwiNum, UINT32 cpuMask) +{ + SEGGER_SYSVIEW_RecordU32x2(ID_OFFSET + ID_LOS_HWI_SETAFFINITY, hwiNum, cpuMask); +} +void LOS_TRACE_HWI_SENDIPI(UINT32 hwiNum, UINT32 cpuMask) +{ + SEGGER_SYSVIEW_RecordU32x2(ID_OFFSET + ID_LOS_HWI_SENDIPI, hwiNum, cpuMask); +} +#endif +/* ******************************************************************** + * + * Public API structures + * + * ********************************************************************* + */ +// Callbacks provided to SYSTEMVIEW by FreeRTOS +const SEGGER_SYSVIEW_OS_API SYSVIEW_X_OS_TraceAPI = { + _cbGetTime, + _cbSendTaskList, +}; + +/* ************************** End of file *************************** */ diff --git a/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/SEGGER_SYSVIEW_LiteOS.h b/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/SEGGER_SYSVIEW_LiteOS.h new file mode 100644 index 000000000..c4bb15b7a --- /dev/null +++ b/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/SEGGER_SYSVIEW_LiteOS.h @@ -0,0 +1,374 @@ +/* ******************************************************************** +* SEGGER Microcontroller GmbH & Co. KG * +* The Embedded Experts * +********************************************************************** +* * +* (c) 2015 - 2017 SEGGER Microcontroller GmbH & Co. KG * +* * +* www.segger.com Support: support@segger.com * +* * +********************************************************************** +* * +* SEGGER SystemView * Real-time application analysis * +* * +********************************************************************** +* * +* All rights reserved. * +* * +* SEGGER strongly recommends to not make any changes * +* to or modify the source code of this software in order to stay * +* compatible with the RTT protocol and J-Link. * +* * +* Redistribution and use in source and binary forms, with or * +* without modification, are permitted provided that the following * +* conditions are met: * +* * +* o Redistributions of source code must retain the above copyright * +* notice, this list of conditions and the following disclaimer. * +* * +* o Redistributions in binary form must reproduce the above * +* copyright notice, this list of conditions and the following * +* disclaimer in the documentation and/or other materials provided * +* with the distribution. * +* * +* o Neither the name of SEGGER Microcontroller GmbH & Co. KG * +* nor the names of its contributors may be used to endorse or * +* promote products derived from this software without specific * +* prior written permission. * +* * +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * +* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * +* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * +* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * +* DISCLAIMED. IN NO EVENT SHALL SEGGER Microcontroller BE LIABLE FOR * +* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * +* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT * +* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * +* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * +* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * +* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * +* DAMAGE. * +* * +********************************************************************** +* * +* SystemView version: V2.52a * +* * +********************************************************************** +-------------------------- END-OF-HEADER ----------------------------- + +File : SEGGER_SYSVIEW_LiteOS.h +Purpose : Interface between FreeRTOS and SystemView. +Revision: $Rev: 7745 $ + +Notes: + (1) Include this file at the end of FreeRTOSConfig.h +*/ + +#ifndef SYSVIEW_LITEOS_H +#define SYSVIEW_LITEOS_H + +#include "SEGGER_SYSVIEW.h" +#include "los_event.h" +#include "los_mux.h" +#include "los_queue.h" +#include "los_sem.h" +#include "los_task.h" +#include "los_task_base.h" + +/** + * Configure the modules to be traced. + */ +#define ENABLE_TASK_TRACE 1 +#define ENABLE_QUEUE_TRACE 0 +#define ENABLE_EVENT_TRACE 0 +#define ENABLE_MUX_TRACE 0 +#define ENABLE_SEM_TRACE 0 +#define ENABLE_MEM_TRACE 0 +#define ENABLE_HWI_TRACE 0 +#define ENABLE_SWTMR_TRACE 0 + +/* + * Several functions take an TaskHandle_t parameter that can optionally be NULL, + * where NULL is used to indicate that the handle of the currently executing + * task should be used in place of the parameter. This macro simply checks to + * see if the parameter is NULL and returns a pointer to the appropriate TCB. + */ + +#define SYSVIEW_LITEOS_MAX_NOF_TASKS PRODUCT_TSK_MAX_SUPPORT_NUM +#define traceMOVED_TASK_TO_READY_STATE(pstTaskCB) SEGGER_SYSVIEW_OnTaskStartReady((U32)pstTaskCB) +#define traceREADDED_TASK_TO_READY_STATE(pxTCB) +#define traceMOVED_TASK_TO_DELAYED_LIST(pstTaskCB) SEGGER_SYSVIEW_OnTaskStopReady((U32)pstTaskCB, (1u << 2)) +#define traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(pstTaskCB) SEGGER_SYSVIEW_OnTaskStopReady((U32)pstTaskCB, (1u << 2)) +#define traceMOVED_TASK_TO_SUSPENDED_LIST(pstTaskCB) SEGGER_SYSVIEW_OnTaskStopReady((U32)pstTaskCB, ((3u << 3) | 3)) +#define traceISR_EXIT_TO_SCHEDULER() SEGGER_SYSVIEW_RecordExitISRToScheduler() +#define traceISR_EXIT() SEGGER_SYSVIEW_RecordExitISR() +#define traceISR_ENTER() SEGGER_SYSVIEW_RecordEnterISR() +#if (portSTACK_GROWTH < 0) +#define traceTASK_CREATE(pstTaskCB) \ + if (pstTaskCB != NULL) { \ + SEGGER_SYSVIEW_OnTaskCreate((U32)pstTaskCB); \ + SYSVIEW_AddTask((U32)pstTaskCB, (pstTaskCB->taskName), pstTaskCB->priority, \ + (U32)(pstTaskCB->topOfStack - pstTaskCB->stackSize), ((U32)pstTaskCB->stackSize)); \ + } +#else +#define traceTASK_CREATE(pstTaskCB) \ + if (pstTaskCB != NULL) { \ + SEGGER_SYSVIEW_OnTaskCreate((U32)pstTaskCB); \ + SYSVIEW_AddTask((U32)pstTaskCB, (pstTaskCB->taskName), pstTaskCB->priority, \ + (U32)(pstTaskCB->topOfStack + pstTaskCB->stackSize), (U32)(pstTaskCB->stackSize)); \ + } +#endif + +/* ******************************************************************** + * + * Defines, fixed + * + * ********************************************************************* + */ +#define ID_OFFSET (32u) + +#define ID_LOS_TASK_SIGNAL (1u) +#define ID_LOS_TASK_DELETE (2u) +#define ID_LOS_TASK_RESUME (3u) +#define ID_LOS_TASK_PRIOSET (4u) + +#define ID_LOS_TASK_SWITCH (5u) +#define ID_LOS_TASK_SUSPEND (6u) + +#define ID_LOS_QUEUECREATE (20u) +#define ID_LOS_QUEUEDELETE (21u) +#define ID_LOS_QUEUEREAD (22u) +#define ID_LOS_QUEUEWRITE (23u) +#define ID_LOS_QUEUERW (24u) + +#define ID_LOS_EVENTINIT (30u) +#define ID_LOS_EVENTDESTROY (31u) +#define ID_LOS_EVENTREAD (32u) +#define ID_LOS_EVENTWRITE (33u) +#define ID_LOS_EVENTCLEAR (34u) +#define ID_LOS_CON_READ (35u) +#define ID_LOS_CON_WRITE (36u) + +#define ID_LOS_MUXCREATE (40u) +#define ID_LOS_MUXDELETE (41u) +#define ID_LOS_MUXPEND (42u) +#define ID_LOS_MUXPOST (43u) + +#define ID_LOS_SEMCREATE (50u) +#define ID_LOS_SEMDELETE (51u) +#define ID_LOS_SEMPEND (52u) +#define ID_LOS_SEMPOST (53u) + +#define ID_LOS_MEMINIT (60u) +#define ID_LOS_MEMDEINIT (61u) +#define ID_LOS_MEMALLOC (62u) +#define ID_LOS_MEMFREE (63u) +#define ID_LOS_MEMREALLOC (64u) +#define ID_LOS_MEMALLOCALIGN (65u) + +#define ID_LOS_SWTMR_CREATE (70u) +#define ID_LOS_SWTMR_START (71u) +#define ID_LOS_SWTMR_STOP (72u) +#define ID_LOS_SWTMR_EXPIRED (73u) +#define ID_LOS_SWTMR_DELETE (74u) + +#define ID_LOS_HWI_CREATE (80u) +#define ID_LOS_HWI_DELETE (81u) +#define ID_LOS_HWI_CREATE_NODE (82u) +#define ID_LOS_HWI_DELETE_NODE (83u) +#define ID_LOS_HWI_TRIGGER (84u) +#define ID_LOS_HWI_ENABLE (85u) +#define ID_LOS_HWI_DISABLE (86u) +#define ID_LOS_HWI_CLEAR (87u) +#define ID_LOS_HWI_SETPRI (88u) +#define ID_LOS_HWI_HWI_RESPONSE_IN (89u) +#define ID_LOS_HWI_RESPONSE_OUT (90u) +#define ID_LOS_HWI_SETAFFINITY (91u) +#define ID_LOS_HWI_SENDIPI (92u) + +/* ******************************************************************** + * + * API functions + * + * ********************************************************************* + */ +#ifdef __cplusplus +extern "C" { +#endif +void SYSVIEW_AddTask(U32 xHandle, const char *pcTaskName, unsigned uxCurrentPriority, U32 pxStack, + unsigned uStackHighWaterMark); +void SYSVIEW_UpdateTask(U32 xHandle, const char *pcTaskName, unsigned uxCurrentPriority, U32 pxStack, + unsigned uStackHighWaterMark); +void SYSVIEW_DeleteTask(U32 xHandle); +void SYSVIEW_SendTaskInfo(U32 TaskID, const char *sName, unsigned Prio, U32 StackBase, unsigned StackSize); +void SYSVIEW_RecordU32x4(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3); +void SYSVIEW_RecordU32x5(unsigned Id, U32 Para0, U32 Para1, U32 Para2, U32 Para3, U32 Para4); + +/** + * queue trace. + */ +#if (ENABLE_QUEUE_TRACE == 1) +void LOS_TRACE_QUEUE_CREATE(UINT32 queueId, UINT16 len, UINT16 msgSize, UINTPTR queue, UINT8 queueMemType); +void LOS_TRACE_QUEUE_DELETE(UINT32 queueId, UINT8 queueState, UINT16 readWriteableCnt); +void LOS_TRACE_QUEUE_RW(UINT32 queueId, UINT16 queueSize, UINT32 bufferSize, UINT32 operateType, UINT16 readableCnt, + UINT16 writeableCnt, UINT32 timeout); +#else +#define LOS_TRACE_QUEUE_CREATE(...) +#define LOS_TRACE_QUEUE_DELETE(...) +#define LOS_TRACE_QUEUE_RW(...) +#endif + +/** + * event trace. + */ +#if (ENABLE_EVENT_TRACE == 1) +void LOS_TRACE_EVENT_CREATE(UINTPTR eventCB); +void LOS_TRACE_EVENT_READ(UINTPTR eventCB, UINT32 uwEventID, UINT32 eventMask, UINT32 mode, UINT32 timeout); +void LOS_TRACE_EVENT_WRITE(UINTPTR eventCB, UINT32 uwEventID, UINT32 events); +void LOS_TRACE_EVENT_CLEAR(UINTPTR eventCB, UINT32 uwEventID, UINT32 events); +void LOS_TRACE_EVENT_DELETE(UINTPTR eventCB, UINT32 ret); +void LOS_TRACE_EVENT_COND_READ(UINTPTR eventCB, UINT32 uwEventID); +void LOS_TRACE_EVENT_COND_WRITE(UINTPTR eventCB, UINT32 uwEventID); +#else +#define LOS_TRACE_EVENT_CREATE(...) +#define LOS_TRACE_EVENT_READ(...) +#define LOS_TRACE_EVENT_WRITE(...) +#define LOS_TRACE_EVENT_CLEAR(...) +#define LOS_TRACE_EVENT_DELETE(...) +#define LOS_TRACE_EVENT_COND_READ(...) +#define LOS_TRACE_EVENT_COND_WRITE(...) +#endif +/** + * mutex trace. + */ +#if (ENABLE_MUX_TRACE == 1) +void LOS_TRACE_MUX_CREATE(UINT32 muxId); +void LOS_TRACE_MUX_POST(UINT32 muxHandle, UINT16 muxCount, UINT32 taskId); +void LOS_TRACE_MUX_PEND(UINT32 muxHandle, UINT16 muxCount, UINT32 taskId, UINT32 timeout); +void LOS_TRACE_MUX_DELETE(UINT32 muxHandle, UINT8 muxStat, UINT16 muxCount, UINT32 taskId); +#else +#define LOS_TRACE_MUX_CREATE(...) +#define LOS_TRACE_MUX_POST(...) +#define LOS_TRACE_MUX_PEND(...) +#define LOS_TRACE_MUX_DELETE(...) +#endif +/** + * semphore trace. + */ +#if (ENABLE_SEM_TRACE == 1) +void LOS_TRACE_SEM_CREATE(UINT32 semId, UINT8 type, UINT16 count); +void LOS_TRACE_SEM_DELETE(UINT32 semHandle, UINT32 ret); +void LOS_TRACE_SEM_PEND(UINT32 semHandle, UINT16 semCount, UINT32 timeout); +void LOS_TRACE_SEM_POST(UINT32 semHandle, UINT8 semType, UINT16 semCount); +#else +#define LOS_TRACE_SEM_CREATE(...) +#define LOS_TRACE_SEM_DELETE(...) +#define LOS_TRACE_SEM_PEND(...) +#define LOS_TRACE_SEM_POST(...) +#endif + +/** + * memory alloc&free trace. + */ +#if (ENABLE_MEM_TRACE == 1) +void LOS_TRACE_MEM_INFO_REQ(VOID *pool); +void LOS_TRACE_MEM_ALLOC(VOID *pool, UINTPTR ptr, UINT32 size); +void LOS_TRACE_MEM_FREE(VOID *pool, UINTPTR ptr); +void LOS_TRACE_MEM_REALLOC(VOID *pool, UINTPTR ptr, UINT32 size); +void LOS_TRACE_MEM_ALLOC_ALIGN(VOID *pool, UINTPTR ptr, UINT32 size, UINT32 boundary); +#else +#define LOS_TRACE_MEM_INFO_REQ(...) +#define LOS_TRACE_MEM_ALLOC(...) +#define LOS_TRACE_MEM_FREE(...) +#define LOS_TRACE_MEM_REALLOC(...) +#define LOS_TRACE_MEM_ALLOC_ALIGN(...) +#endif +/** + * task trace. + */ +#if (ENABLE_TASK_TRACE == 1) +#ifdef LOSCFG_KERNEL_SMP +void LOS_TRACE_TASK_SIGNAL(UINT32 taskId, UINT32 mpSignal); +#endif +// void LOS_TRACE_TASK_DELAY(UINT32 tick); +void LOS_TRACE_TASK_RESUME(UINT32 taskId, UINT16 taskStatus, UINT16 priority); +void LOS_TRACE_TASK_DELETE(UINT32 taskId, UINT16 taskStatus, UINT32 usrStack); +void LOS_TRACE_TASK_PRIOSET(UINT32 taskId, UINT16 taskStatus, UINT16 priority, UINT16 taskPrio); +// sched trace +void LOS_TRACE_TASK_SWITCH(UINT32 taskId, UINT16 runPriority, UINT16 curTaskStatus, UINT16 newPriority, + UINT16 newTaskStatus); +#ifndef LOSCFG_SCHED_LATENCY +void LOS_TRACE_TASK_SIGNAL(UINT32 taskId, UINT32 schedFlag); +#endif +void LOS_TRACE_TASK_SUSPEND(UINT32 taskId, UINT16 taskStatus, UINT32 currTaskId); +void LOS_TRACE_TASK_SWITCHED_IN(void); +void LOS_TRACE_MOVED_TASK_TO_READY_STATE(const LosTaskCB *pstTaskCB); +void LOS_TRACE_MOVED_TASK_TO_DELAYED_LIST(const LosTaskCB *pstTaskCB); +void LOS_TRACE_MOVED_TASK_TO_SUSPENDED_LIST(const LosTaskCB *pstTaskCB); +void LOS_TRACE_ISR_EXIT_TO_SCHEDULER(void); +void LOS_TRACE_ISR_ENTER(U32 hwiIndex); +void LOS_TRACE_ISR_EXIT(U32 hwiIndex); +#else +#define LOS_TRACE_TASK_SIGNAL(...) +#define LOS_TRACE_TASK_RESUME(...) +#define LOS_TRACE_TASK_DELETE(...) +#define LOS_TRACE_TASK_PRIOSET(...) +#define LOS_TRACE_TASK_SWITCH(...) +#define LOS_TRACE_TASK_SUSPEND(...) +#endif +/** + * swtmr trace. + */ +#if (ENABLE_SWTMR_TRACE == 1) +void LOS_TRACE_SWTMR_EXPIRED(UINT16 timerId); +void LOS_TRACE_SWTMR_CREATE(UINT16 timerId); +void LOS_TRACE_SWTMR_START(UINT16 timerId, UINT8 mode, UINT8 overrun, UINT32 interval, UINT32 expiry); +void LOS_TRACE_SWTMR_STOP(UINT16 timerId); +void LOS_TRACE_SWTMR_DELETE(UINT16 timerId); +#else +#define LOS_TRACE_SWTMR_EXPIRED(...) +#define LOS_TRACE_SWTMR_CREATE(...) +#define LOS_TRACE_SWTMR_START(...) +#define LOS_TRACE_SWTMR_STOP(...) +#define LOS_TRACE_SWTMR_DELETE(...) +#endif + +/** + * hwi trace. + */ +void LOS_TRACE_HWI_RESPONSE_IN(UINT32 hwiNum); +void LOS_TRACE_HWI_RESPONSE_OUT(UINT32 hwiNum); +#if (ENABLE_HWI_TRACE == 1) +void LOS_TRACE_HWI_CREATE(UINT32 hwiNum, HWI_PRIOR_T hwiPrio, HWI_MODE_T hwiMode, UINTPTR hwiHandler); +void LOS_TRACE_HWI_CREATE_NODE(UINT32 hwiNum, UINTPTR pDevId, UINT32 ret); +void LOS_TRACE_HWI_DELETE(UINT32 hwiNum); +void LOS_TRACE_HWI_DELETE_NODE(UINT32 hwiNum, UINTPTR pDevId, UINT32 ret); +void LOS_TRACE_HWI_TRIGGER(UINT32 hwiNum); +void LOS_TRACE_HWI_ENABLE(UINT32 hwiNum); +void LOS_TRACE_HWI_DISABLE(UINT32 hwiNum); +void LOS_TRACE_HWI_CLEAR(UINT32 hwiNum); +void LOS_TRACE_HWI_SETPRI(UINT32 hwiNum, HWI_PRIOR_T priority); +void LOS_TRACE_HWI_SETAFFINITY(UINT32 hwiNum, UINT32 cpuMask); +void LOS_TRACE_HWI_SENDIPI(UINT32 hwiNum, UINT32 cpuMask); +#else +#define LOS_TRACE_HWI_CREATE(...) +#define LOS_TRACE_HWI_CREATE_NODE(...) +#define LOS_TRACE_HWI_DELETE(...) +#define LOS_TRACE_HWI_DELETE_NODE(...) +#define LOS_TRACE_HWI_TRIGGER(...) +#define LOS_TRACE_HWI_ENABLE(...) +#define LOS_TRACE_HWI_DISABLE(...) +#define LOS_TRACE_HWI_CLEAR(...) +#define LOS_TRACE_HWI_SETPRI(...) +#define LOS_TRACE_HWI_SETAFFINITY(...) +#define LOS_TRACE_HWI_SENDIPI(...) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* SYSVIEW_LITEOS_H */ + +/* ************************** End of file *************************** */ diff --git a/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/Tooladapt/Readme.txt b/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/Tooladapt/Readme.txt new file mode 100644 index 000000000..53abb3b2b --- /dev/null +++ b/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/Tooladapt/Readme.txt @@ -0,0 +1 @@ +将SYSVIEW_LiteOS.txt放置在PC端SYSTEMVIEW工具的Description文件夹下。 \ No newline at end of file diff --git a/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/Tooladapt/SYSVIEW_LiteOS.txt b/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/Tooladapt/SYSVIEW_LiteOS.txt new file mode 100644 index 000000000..cd7d76220 --- /dev/null +++ b/code/sdk/application/wearable/SystemView/Src/Sample/LiteOS/Tooladapt/SYSVIEW_LiteOS.txt @@ -0,0 +1,43 @@ +34 LOS_TaskDelete taskId = %u, taskName = %s. +36 OsSchedPrioModify taskId = %u, priority = %u. +52 OsQueueCreateInternal queueId = %u, len = %u, queue = %u, queueMemType = %u. +53 LOS_QueueDelete queueId = %u, queueState = %u, readWriteableCnt = %u. +56 OsQueueOperate queueId = %u,, operateType = %u, readableCnt = %u, writeableCnt = %u, timeout = %u. +62 LOS_EventInit %s +63 LOS_EventDestroy ret = %u, %s. +64 LOS_EventRead uwEventID = %u, eventMask = %u, %s. +65 OsEventWrite uwEventID = %u, events = %u. +66 LOS_EventClear uwEventID = %u, events = %u. +67 EventCondRead uwEventID = %u +68 LOS_EventCondWrite uwEventID = %u +72 LOS_MuxCreate muxId = %u, %s. +73 LOS_MuxDelete muxHandle = %u, muxStat = %u, muxCount = %u, taskId = %u. +74 LOS_MuxPend muxHandle = %u, muxCount = %u, taskId = %u, timeout = %u. +75 LOS_MuxPost muxHandle = %u, muxCount = %u, taskId = %u. +82 OsSemCreate semId = %u, type = %u, count = %u. +83 LOS_SemDelete semHandle = %u, ret = %u, %s. +84 LOS_SemPend semHandle = %u, semCount = %u, timeout = %u. +85 LOS_SemPost semHandle = %u, semType = %u, semCount = %u. +92 LOS_MemPoolInit pool = %x. +94 LOS_MemAlloc pool = %x, ptr = %x, size = %u. +95 LOS_MemFree pool = %x, ptr = %x. +96 LOS_MemRealloc pool = %x, ptr = %x, size = %u. +97 LOS_MemAllocAlign pool = %x, ptr = %x, size = %u, boundary = %u. +102 LOS_SwtmrCreate timerId = %u. +103 LOS_SwtmrStart timerId = %u, mode = %u, overrun = %u, interval = %u, expiry = %u. +104 LOS_SwtmrStop timerId = %u. +105 OsSwtmrScan timerId = %u. +106 OsSwtmrDeleteOption timerId = %u. +112 LOS_HwiCreate hwiNum = %u, hwiPrio = %u, hwiMode = %u, hwiHandler = %u. +113 LOS_HwiDelete hwiNum = %u +114 LOS_HwiCreate pDevId = %u, ret = %u. +115 LOS_HwiDelete hwiNum = %u, pDevId = %u, ret = %u. +116 LOS_HwiTrigger hwiNum = %u. +117 LOS_HwiEnable hwiNum = %u. +118 LOS_HwiDisable hwiNum = %u. +119 LOS_HwiClear hwiNum = %u. +120 LOS_HwiSetPriority hwiNum = %u, priority = %u. +121 OsIntHandle hwiNum = %u. +122 OsIntHandle hwiNum = %u. +123 LOS_HwiSetAffinity hwiNum = %u, cpuMask = %u. +124 LOS_HwiSendIpi hwiNum = %u, cpuMask = %u. diff --git a/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h b/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h index 986ca7f45..93a608cfc 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h +++ b/code/sdk/application/wearable/nativeabilityfwk/include/Ability.h @@ -87,7 +87,7 @@ protected: SliceStruct curSlice_; SliceStruct prevSlice_; - + uint16_t targetSliceIdFromJS_ = 0; uint16_t defaultSliceId_ = gSliceInvalid; uint16_t curSlicePriority_ = gSliceDefaultPriority; SliceTransition sliceTransition_; @@ -95,7 +95,6 @@ protected: void ResumeSlice(const uint16_t priority = gSliceDefaultPriority); void StartSlice(const uint16_t sliceId, const uint16_t priority); - void StopSlice(); void PostChangeSlice(const uint16_t targetSliceId, TransitionType type, const uint16_t priority); diff --git a/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp b/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp index 6e46de0bd..ceafc7308 100644 --- a/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp +++ b/code/sdk/application/wearable/nativeabilityfwk/src/Ability.cpp @@ -14,6 +14,7 @@ */ #include "Ability.h" + #include "graphic_service.h" #include "abilityms_slite_client.h" #include "common/input_device_manager.h" @@ -68,6 +69,7 @@ void Ability::StartSlice(const uint16_t sliceId, const uint16_t priority) nextSlice->OnStart(); nextSlice->OnResume(); + } ListsNode* Ability::Find(const uint16_t sliceId) @@ -93,9 +95,6 @@ ListsNode* Ability::Find(const uint16_t sliceId) void Ability::ChangeSlice(const uint16_t targetSliceId, TransitionType type, const uint16_t priority) { - if (GetCurSliceId() == targetSliceId) { - return; - } if (osal_atomic_read(&transitionCount_) <= 0) { osal_atomic_inc(&transitionCount_); GraphicService::GetInstance()->PostGraphicEvent(std::bind(&Ability::PostChangeSlice, this, targetSliceId, @@ -120,9 +119,12 @@ void Ability::PostChangeSlice(const uint16_t targetSliceId, TransitionType type, // slice页面跳转,先onstop,再onstart.在一个线程同步执行绘制,不会出现闪屏现象 #ifdef JS_ENABLE ElementName *elementName = OHOS::AbilityMsClient::GetInstance().GetTopAbility(); - if (strcmp(elementName->bundleName, "com.huawei.launcher") != 0) { + if (elementName != nullptr && strcmp(elementName->bundleName, "com.huawei.launcher") != 0) { OHOS::AbilityMsClient::GetInstance().ForceStop(elementName->bundleName); - } + targetSliceIdFromJS_ = targetSliceId; + osal_atomic_dec(&transitionCount_); + return; + } #endif StartSlice(targetSliceId, priority); @@ -156,8 +158,10 @@ void Ability::OnTransitionEnd() void Ability::ResumeSlice(const uint16_t priority) { uint16_t targetSliceId = gSliceInvalid; - - if (allSlices_.empty()) { + if (targetSliceIdFromJS_ != 0) { + targetSliceId = targetSliceIdFromJS_; + targetSliceIdFromJS_ = 0; + } else if (allSlices_.empty()) { targetSliceId = defaultSliceId_; } else { targetSliceId = GetCurSliceId(); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp index fd9dd57f0..22e85a984 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp @@ -201,6 +201,7 @@ void wrapper_gatts_start_service_callback(uint8_t server_id, uint16_t handle, er callback.start_service_cb(server_id, handle, status); } } + g_uuid_list.pop_front(); wrapper_gatts_service_start(); } } @@ -307,7 +308,6 @@ void wrapper_gatts_service_start(void) bt_uuid_t &uuid = g_uuid_list.front(); // 服务异步添加,需要保证当前服务start后,再添加下一个服务 (void)gatts_add_service(gatts_server_id, &uuid, true); - g_uuid_list.pop_front(); } else { g_svr_handle_list.clear(); } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialVideoView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialVideoView.cpp index c3cbafba4..f8182fd92 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialVideoView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialVideoView.cpp @@ -3,9 +3,6 @@ */ #include "DialVideoView.h" -#ifdef SUPPORT_AT_OHOSFWK -#include "ui_screennotify.h" -#endif namespace OHOS { static constexpr int16_t JPEG_HEIGHT_DIVISOR = 2; @@ -14,26 +11,6 @@ static constexpr int16_t JPEG_HEIGHT_BYTE_ALIGNMENT = 16; static constexpr int16_t BUFFER_QUEUE_SIZE = 2; static constexpr int16_t STRIDE_ALIGNMENT_VALUE = 128; -#ifdef SUPPORT_AT_OHOSFWK -static MediaVideoPlay *g_videoPlay = nullptr; -static void ScreenStatusNotify(ScreenStatus status) -{ - if (g_videoPlay == nullptr) { - return; - } - - if (status == SCREEN_STATUS_OFF && g_videoPlay->isPlayed_) { - g_videoPlay->PauseVideoPlay(); - } else if (status == SCREEN_STATUS_ON) { - if (g_videoPlay->isPause_) { - g_videoPlay->ResumeVideoPlay(); - } else if (g_videoPlay->isExited_) { - g_videoPlay->StartVideoPlay(); - } - } -} -#endif - static inline int32_t MediaByteAlign(int16_t value, int16_t align) { return (((value) + (align) - 1) & (~((align) - 1))); @@ -45,10 +22,6 @@ DialVideoView::DialVideoView() DialVideoView::~DialVideoView() { -#ifdef SUPPORT_AT_OHOSFWK - g_videoPlay = nullptr; - deregisterNotifyScreenStatus(ScreenStatusNotify); -#endif if (videoPlayer_ != nullptr) { delete videoPlayer_; } @@ -87,10 +60,6 @@ bool DialVideoView::SetVideoRes(FILE* fp, uint32_t offset) videoPlayer_ = new MediaVideoPlay(surface, fd, offset_, true); videoPlayer_->SetSyncExitMode(true); -#ifdef SUPPORT_AT_OHOSFWK - g_videoPlay = videoPlayer_; - registerNotifyScreenStatus(ScreenStatusNotify); -#endif return true; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp index a8866df8a..b32dc39cd 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/dial/DialViewGroup.cpp @@ -7,8 +7,32 @@ #include "DialBinParser.h" #include "ModelDialDataFactory.h" #include "common/low_power_manager.h" +#include "common/image_cache_manager.h" +#ifdef SUPPORT_AT_OHOSFWK +#include "ui_screennotify.h" +#endif namespace OHOS { +static DialVideoView* g_video = nullptr; + +#ifdef SUPPORT_AT_OHOSFWK +static void ScreenStatusNotify(ScreenStatus status) +{ + if (g_video == nullptr) { + return; + } + if (status == SCREEN_STATUS_OFF && g_video->IsPlayed()) { + g_video->PausePlay(); + } else if (status == SCREEN_STATUS_ON) { + if (g_video->IsPaused()) { + g_video->ResumePlay(); + } else if (!g_video->IsPlayed()) { + g_video->StartPlay(); + } + } +} +#endif + DialViewGroup::DialViewGroup(void) { SetTouchable(true); @@ -18,6 +42,12 @@ DialViewGroup::DialViewGroup(void) DialViewGroup::~DialViewGroup(void) { + if (video_ != nullptr) { +#ifdef SUPPORT_AT_OHOSFWK + deregisterNotifyScreenStatus(ScreenStatusNotify); +#endif + g_video = nullptr; + } if (kaleidoscope_ != nullptr) { kaleidoscope_->ClearFocus(); kaleidoscope_ = nullptr; @@ -27,6 +57,7 @@ DialViewGroup::~DialViewGroup(void) void DialViewGroup::ClearDial() { + ImageCacheManager::GetInstance().UnloadAllInMultiRes(filePath_); ListNode* passiveNode = passiveUpdateTypes_.Head(); while (passiveNode != passiveUpdateTypes_.End()) { DialDataType type = passiveNode->data_; @@ -83,14 +114,6 @@ void DialViewGroup::PreLoad(void) return; } DialBinParser::GetInstance()->UpdateDial(filePath_, fp_, this); - if (video_ != nullptr) { - video_->StartPlay(); - } - - if (kaleidoscope_ != nullptr) { - kaleidoscope_->RequestFocus(); - kaleidoscope_->StartRotateAnimator(); - } resPreloaded_ = true; } } @@ -134,6 +157,10 @@ void DialViewGroup::AddView(UIView* view, bool isDialVideoView) return; } video_ = reinterpret_cast(view); + g_video = video_; +#ifdef SUPPORT_AT_OHOSFWK + registerNotifyScreenStatus(ScreenStatusNotify); +#endif } } @@ -299,14 +326,16 @@ void DialViewGroup::ScrollEnd(bool isActive) if (isActive) { if (video_->IsPaused()) { video_->ResumePlay(); - } else if (video_->IsStopped()) { + } else if (!video_->IsPlayed()) { video_->StartPlay(); } + g_video = video_; } else { if (video_->IsPaused() || video_->IsPlayed()) { video_->StopPlay(); } ClearCache(); + g_video = nullptr; } } @@ -341,12 +370,15 @@ void DialViewGroup::CoverEnd(bool isCovered) if (video_ == nullptr) { return; } - if (!isCovered) { + if (isCovered) { + g_video = nullptr; + } else { if (video_->IsPaused()) { video_->ResumePlay(); - } else if (video_->IsStopped()) { + } else if (!video_->IsPlayed()) { video_->StartPlay(); } + g_video = video_; } } @@ -355,9 +387,10 @@ void DialViewGroup::OnActive(void) if (video_ != nullptr) { if (video_->IsPaused()) { video_->ResumePlay(); - } else if (video_->IsStopped()) { + } else if (!video_->IsPlayed()) { video_->StartPlay(); } + g_video = video_; } else if (kaleidoscope_ != nullptr) { kaleidoscope_->RequestFocus(); kaleidoscope_->StartRotateAnimator(); @@ -370,6 +403,7 @@ void DialViewGroup::OnInactive(void) if (!video_->IsStopped()) { video_->StopPlay(); } + g_video = nullptr; } else if (kaleidoscope_ != nullptr) { kaleidoscope_->StopRotateAnimator(); kaleidoscope_->ClearFocus(); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp b/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp index c9374ea13..2d3f6ffa5 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/phoneservice/src/PhoneService.cpp @@ -670,8 +670,6 @@ static void ScoStateChanged(const bd_addr_t *bdAddr, hfp_sco_connect_state_t sta } break; case HFP_SCO_STATE_CONNECTED: - CopyBdAddr(bdAddr); - ScoConnectPro(); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ScoStateChanged] SCO connected!"); break; diff --git a/code/sdk/application/wearable/service/broadcast/src/broadcast_feature.c b/code/sdk/application/wearable/service/broadcast/src/broadcast_feature.c index 32e9496c7..fa08cb9fc 100644 --- a/code/sdk/application/wearable/service/broadcast/src/broadcast_feature.c +++ b/code/sdk/application/wearable/service/broadcast/src/broadcast_feature.c @@ -22,7 +22,7 @@ typedef struct BroadcastFeature { static const char *GetFeatureName(Feature *feature_); static void OnInitialize(Feature *feature_, Service *parent, Identity id); static void OnStop(Feature *feature_, Identity id); -static BOOL OnMessage(Feature *feature_, Request **req); +static BOOL OnMessage(Feature *feature_, Request *req); static int32 SubscribeTopic(IUnknown *broadcastApi, const Topic topic, const Subscriber* subscriber); static int32 UnsubscribeTopic(IUnknown *broadcastApi, const Topic topic, const Subscriber* subscriber); @@ -84,12 +84,11 @@ static void OnStop(Feature *feature, Identity identity) (void)identity; } -static BOOL OnMessage(Feature *feature, Request **req) +static BOOL OnMessage(Feature *feature, Request *req) { - Request *r = (*req); WEARABLE_LOGI(WEARABLE_LOG_MODULE_BROADCASE_SERVICE, "BroadcastFeature req=0x%p, msgId=%u, len=%u, data=0x%p", - r, r->msgId, r->len, r->data); - HandleTopicMessage((BroadcastFeature *)feature, *req); + req, req->msgId, req->len, req->data); + HandleTopicMessage((BroadcastFeature *)feature, req); return TRUE; } diff --git a/code/sdk/application/wearable/service/msg_center/CMakeLists.txt b/code/sdk/application/wearable/service/msg_center/CMakeLists.txt index 69d64a4da..1b778a285 100644 --- a/code/sdk/application/wearable/service/msg_center/CMakeLists.txt +++ b/code/sdk/application/wearable/service/msg_center/CMakeLists.txt @@ -135,7 +135,6 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/msg_center_cmd.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/alarm_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/makephone_notification.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/notification_manager_customer.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/vendor_app/baidu/baidu_app.cpp ) else() @@ -144,7 +143,6 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/msg_center_cmd.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/alarm_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/makephone_notification.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/notification_manager_customer.cpp ) endif() diff --git a/code/sdk/application/wearable/service/msg_center/brandy-native-js/libmsg_center.a b/code/sdk/application/wearable/service/msg_center/brandy-native-js/libmsg_center.a index 5ee51f2c9..bddcbf682 100644 Binary files a/code/sdk/application/wearable/service/msg_center/brandy-native-js/libmsg_center.a and b/code/sdk/application/wearable/service/msg_center/brandy-native-js/libmsg_center.a differ diff --git a/code/sdk/application/wearable/service/msg_center/brandy-xts/libmsg_center.a b/code/sdk/application/wearable/service/msg_center/brandy-xts/libmsg_center.a index bba3ff9a8..6dfee5571 100644 Binary files a/code/sdk/application/wearable/service/msg_center/brandy-xts/libmsg_center.a and b/code/sdk/application/wearable/service/msg_center/brandy-xts/libmsg_center.a differ diff --git a/code/sdk/application/wearable/service/msg_center/include/msg_center_protocol.h b/code/sdk/application/wearable/service/msg_center/include/msg_center_protocol.h index 7b5a2fda3..484a1eb10 100644 --- a/code/sdk/application/wearable/service/msg_center/include/msg_center_protocol.h +++ b/code/sdk/application/wearable/service/msg_center/include/msg_center_protocol.h @@ -127,6 +127,9 @@ typedef enum msg_center_vector_navi_type_id { MSGCENTER_TYPE_ID_VECTOR_NAVI_REQ_DESTROY_PAGE, MSGCENTER_TYPE_ID_VECTOR_NAVI_BT_DISCONNECTED, MSGCENTER_TYPE_ID_VECTOR_NAVI_BT_CONNECTED, + MSGCENTER_TYPE_ID_VECTOR_NAVI_REC_FIRST_BATCH, + MSGCENTER_TYPE_ID_VECTOR_NAVI_REQ_DESTROY_FROM_WATCH, + MSGCENTER_TYPE_ID_VECTOR_NAVI_REC_DESTROY_FROM_WATCH } msg_center_vector_navi_type_id_t; typedef enum msg_center_alipay_type_id { @@ -300,6 +303,11 @@ static const char *g_vector_navi_str_tb[] = { "req_regeocode_search", "rec_regeocode_search", "req_destroy_page", + "null", + "null", + "null", + "req_destroy_from_watch", + "rec_destroy_from_watch", }; static inline const char* vector_navi_get_str(uint8_t type) diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/alarm_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/alarm_notification.h index 4393f7845..986be0075 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/alarm_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/alarm_notification.h @@ -8,11 +8,11 @@ #ifndef ALARM_NOTIFICATION_H #define ALARM_NOTIFICATION_H -constexpr char* ALARM_IMAGE_DELETE = "alarm_delete"; -constexpr char* ALARM_IMAGE_CLOCK = "alarm_clock"; -constexpr char* ALARM_VIEW_CLOSE = "alarm_close"; -constexpr char* ALARM_VIEW_DELAY = "alarm_delay"; -constexpr char* ALARM_VIEW_POPUP = "alarm_popup"; +static constexpr const char* ALARM_IMAGE_DELETE = "alarm_delete"; +static constexpr const char* ALARM_IMAGE_CLOCK = "alarm_clock"; +static constexpr const char* ALARM_VIEW_CLOSE = "alarm_close"; +static constexpr const char* ALARM_VIEW_DELAY = "alarm_delay"; +static constexpr const char* ALARM_VIEW_POPUP = "alarm_popup"; enum class AlarmTimerType { NOTIFY_ALARM_CLOSE = 0, diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/notification_manager.h b/code/sdk/application/wearable/service/msg_center/include/notify/notification_manager.h index f71205649..532f1c11d 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/notification_manager.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/notification_manager.h @@ -16,6 +16,7 @@ #ifndef NOTIFICATION_MANAGER_H #define NOTIFICATION_MANAGER_H #include +#include #include "common/task.h" #include "common/screen.h" @@ -30,7 +31,7 @@ constexpr int16_t NOTIFY_PRIORITY_DEFAULT = 4; namespace OHOS { using NewNotify = std::function; using RefreshNotifyContent = std::function; - +typedef void (*FreeNotifyfunc)(); class NotificationManager : public Task { public: static NotificationManager* GetInstance() @@ -71,7 +72,7 @@ public: void SetVolumeScreenStatus(bool status); bool GetWatchCallStatus(); void SetWatchCallStatus(bool status); - + void RegisterNotifyCleanupFunction(FreeNotifyfunc); void Callback() override; UIViewGroup* screenContainer_ = nullptr; @@ -97,6 +98,7 @@ private: bool hasNewNotifyNeedShow_ = false; bool hasNotifyNeedRefresh_ = false; bool hasNewNotifyNeedStop_ = false; + std::vector notifyCleanupFunctions_; uint16_t notifyPri = NOTIFY_PRIORITY_DEFAULT; uint16_t notifyId = -1; diff --git a/code/sdk/application/wearable/service/msg_center/include/vendor_app/baidu_app.h b/code/sdk/application/wearable/service/msg_center/include/vendor_app/baidu_app.h index 678a202b0..2588d0ec4 100644 --- a/code/sdk/application/wearable/service/msg_center/include/vendor_app/baidu_app.h +++ b/code/sdk/application/wearable/service/msg_center/include/vendor_app/baidu_app.h @@ -117,6 +117,11 @@ errcode_t msg_center_vector_navi_rec_geocode_search(uint8_t cmd_id, uint8_t type errcode_t msg_center_vector_navi_req_regeocode_search(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); errcode_t msg_center_vector_navi_rec_regeocode_search(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); errcode_t msg_center_vector_navi_req_destroy_page(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_vector_navi_rec_first_batch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_vector_navi_req_destroy_from_watch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); +errcode_t msg_center_vector_navi_rec_destroy_from_watch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len); + +bool is_vector_navi_long_distance(uint8_t type); #ifdef __cplusplus #if __cplusplus diff --git a/code/sdk/application/wearable/service/msg_center/include/vendor_app/baidumap_msg_center.h b/code/sdk/application/wearable/service/msg_center/include/vendor_app/baidumap_msg_center.h index e20f08a55..e35eeb8d7 100644 --- a/code/sdk/application/wearable/service/msg_center/include/vendor_app/baidumap_msg_center.h +++ b/code/sdk/application/wearable/service/msg_center/include/vendor_app/baidumap_msg_center.h @@ -44,6 +44,11 @@ uint8_t duer_msg_center_recv_map_info(uint8_t command_id, uint8_t type, struct C */ uint8_t duer_msg_center_send_map_info(uint8_t duer_type, void *usr_data, uint16_t usr_len); +/** + * 接收APP下发的缓存第一次批量请求 + */ +uint8_t duer_msg_center_map_to_title(void *data, uint16_t len); + #ifdef __cplusplus #if __cplusplus } diff --git a/code/sdk/application/wearable/service/msg_center/libs/libbaidumapsdk.a b/code/sdk/application/wearable/service/msg_center/libs/libbaidumapsdk.a index 468970f03..65fccf470 100644 Binary files a/code/sdk/application/wearable/service/msg_center/libs/libbaidumapsdk.a and b/code/sdk/application/wearable/service/msg_center/libs/libbaidumapsdk.a differ diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_cmd.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_cmd.cpp index d5503ab0a..945a33005 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_cmd.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_cmd.cpp @@ -89,10 +89,13 @@ msg_center_cmd_map_t g_msg_center_type_tbl[] = { { MSGCENTER_CMD_VECTOR_NAVI, MSGCENTER_TYPE_ID_VECTOR_NAVI_REC_GEOCODE_SEARCH, msg_center_vector_navi_rec_geocode_search}, { MSGCENTER_CMD_VECTOR_NAVI, MSGCENTER_TYPE_ID_VECTOR_NAVI_REQ_REGEOCODE_SEARCH, msg_center_vector_navi_req_regeocode_search}, { MSGCENTER_CMD_VECTOR_NAVI, MSGCENTER_TYPE_ID_VECTOR_NAVI_REC_REGEOCODE_SEARCH, msg_center_vector_navi_rec_regeocode_search}, - /* µØÍ¼Ë½ÓÐЭÒé */ + /* 地图私有协议 */ { MSGCENTER_CMD_VECTOR_NAVI, MSGCENTER_TYPE_ID_VECTOR_NAVI_REQ_DESTROY_PAGE, msg_center_vector_navi_req_destroy_page}, - { MSGCENTER_CMD_VECTOR_NAVI, MSGCENTER_TYPE_ID_VECTOR_NAVI_BT_DISCONNECTED, NULL}, - { MSGCENTER_CMD_VECTOR_NAVI, MSGCENTER_TYPE_ID_VECTOR_NAVI_BT_CONNECTED, NULL}, + { MSGCENTER_CMD_VECTOR_NAVI, MSGCENTER_TYPE_ID_VECTOR_NAVI_BT_DISCONNECTED, NULL}, + { MSGCENTER_CMD_VECTOR_NAVI, MSGCENTER_TYPE_ID_VECTOR_NAVI_BT_CONNECTED, NULL}, + { MSGCENTER_CMD_VECTOR_NAVI, MSGCENTER_TYPE_ID_VECTOR_NAVI_REC_FIRST_BATCH, msg_center_vector_navi_rec_first_batch}, + { MSGCENTER_CMD_VECTOR_NAVI, MSGCENTER_TYPE_ID_VECTOR_NAVI_REQ_DESTROY_FROM_WATCH, msg_center_vector_navi_req_destroy_from_watch}, + { MSGCENTER_CMD_VECTOR_NAVI, MSGCENTER_TYPE_ID_VECTOR_NAVI_REC_DESTROY_FROM_WATCH, msg_center_vector_navi_rec_destroy_from_watch}, #endif #ifdef SUPPORT_ALIPAY_SEC { MSGCENTER_CMD_ALIPAY, MSGCENTER_TYPE_ID_ALIPAY_NETWORK_STATUS, msg_center_alipay_network_status}, @@ -127,7 +130,7 @@ char *msg_center_get_bundle_name(uint8_t cmd_id) case MSGCENTER_CMD_NAVIGATION: return "cn.navigate"; case MSGCENTER_CMD_VECTOR_NAVI: - return "com.baidu.baiduMap"; + return "com.baidu.BaiduMap"; default: WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER,"msg_center_get_bundle_name: wrong cmd_id[%d]", cmd_id); break; diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/alarm_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/alarm_notification.cpp index 417c99a5d..db0420092 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/alarm_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/alarm_notification.cpp @@ -13,7 +13,7 @@ #include "components/ui_label.h" namespace OHOS { -constexpr char* RING_AGAIN = "响铃将在十分钟后再次响起"; +static constexpr const char* RING_AGAIN = "响铃将在十分钟后再次响起"; constexpr int32_t NOTIFY_THREE_SECONDS = 3000; constexpr int32_t NOTIFY_ONE_SECOND = 1000; constexpr int32_t NOTIFY_THIRTY_SECONDS = 30000; @@ -199,6 +199,7 @@ UIViewGroup *CreateAlarmCloseView() g_closeView->SetOnDragListener(listener); g_closeView->SetDraggable(true); g_closeView->SetTouchable(true); + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeAlarmCloseView); return g_closeView; } @@ -256,6 +257,7 @@ UIViewGroup *CreateAlarmRingView() g_ringView->SetOnDragListener(listener); g_ringView->SetDraggable(true); g_ringView->SetTouchable(true); + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeAlarmRingView); return g_ringView; } @@ -397,6 +399,7 @@ UIViewGroup* CreateAlarmView(void) UIView::OnDragListener *listener = static_cast(AlarmViewEventListener::GetInstance()); g_alarmView->SetOnDragListener(listener); StartAlarmTimer(AlarmTimerType::NOTIFY_ALARM_RING, NOTOFY_NO_OPERATE_TIME); + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeAlarmView); return g_alarmView; } void FreeAlarmView(void) diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp index f16103f3e..29c369a94 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/makephone_notification.cpp @@ -486,6 +486,7 @@ UIViewGroup* CreatePhoneCallView(void) g_phoneView->Add(g_comingTimes); g_phoneView->SetDraggable(true); g_phoneView->SetTouchable(true); + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreePhoneCallView); return g_phoneView; } @@ -540,7 +541,7 @@ UIViewGroup* CreateMultiplePhoneView(void) g_imageHorns->SetOnClickListener(clickListener); StartCallTimer(CallTimerType::NOTIFY_PHONE_CURTIME_DISPLAY, NOTIFY_THIRTY_SECONDS); NotificationManager::GetInstance()->SetVolumeScreenStatus(false); - + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeMultiplePhoneCallView); return g_multiPhoneView; } @@ -599,6 +600,7 @@ UIViewGroup* CreateCallingView(void) StartCallTimer(CallTimerType::NOTIFY_PHONE_CALLING_DISPLAY, NOTIFY_ONE_SECOND); StartCallTimer(CallTimerType::NOTIFY_PHONE_CURTIME_DISPLAY, NOTIFY_THIRTY_SECONDS); NotificationManager::GetInstance()->SetVolumeScreenStatus(false); + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeCallingView); return g_callingView; } @@ -650,6 +652,7 @@ UIViewGroup* CreateWaitingHintsView(void) UIView::OnClickListener *clickListener = static_cast\ (OHOS::CallViewEventListener::GetInstance()); g_imageDissgreeNew->SetOnClickListener(clickListener); + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeWaitingHintsView); return g_waitingHintsView; } diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/notification_manager_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/notification_manager_customer.cpp deleted file mode 100644 index 4feb730c9..000000000 --- a/code/sdk/application/wearable/service/msg_center/src/notify/notification_manager_customer.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) CompanyNameMagicTag. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "notification_manager.h" - -namespace OHOS { - -/* 只有在新增Topic时,需要添加对应的Free操作 */ -void NotificationManager::FreeNotifyViews() -{ - FreeAlarmView(); - FreeAlarmCloseView(); - FreeAlarmRingView(); - FreePhoneCallView(); - FreeCallingView(); - FreeMultiplePhoneCallView(); - FreeWaitingHintsView(); -} -} diff --git a/code/sdk/application/wearable/service/msg_center/src/vendor_app/baidu/baidu_app.cpp b/code/sdk/application/wearable/service/msg_center/src/vendor_app/baidu/baidu_app.cpp index 375838d33..96008a187 100644 --- a/code/sdk/application/wearable/service/msg_center/src/vendor_app/baidu/baidu_app.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/vendor_app/baidu/baidu_app.cpp @@ -31,6 +31,7 @@ extern "C" { #define TTS_MEDIA_PARAM_OFFSET 2 #define TASK_PRIORITY_PCM_STREAM (osPriority_t)(40) #define PCM_STREAM_MSG_STACK_SIZE 0xC00 +#define ROUTE_TRANS_MAX_SIZE (60 * 1024) /* 60K大小的导航路线规划,距离大概是15KM */ osMessageQueueId_t g_pcm_stream_msg_queue_id = nullptr; @@ -149,6 +150,7 @@ static errcode_t pcm_stream_task_body(void *data) } else if (msg.msg_id == MSGCENTER_TYPE_ID_XIAODU_END_RECORD) { res = msg_center_xiaodu_send_end_record(MSGCENTER_CMD_XIAODU, MSGCENTER_TYPE_ID_XIAODU_END_RECORD, msg.data, msg.len); + free(msg.data); if (res != ERRCODE_SUCC) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "send pcm stream failed"); return ERRCODE_FAIL; @@ -470,9 +472,14 @@ static void msg_center_transfer_longbuf(char *data, uint8_t type) WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "file_len = %d.\r\n", file_len); /* send to JSI */ - BaidumapSendMsgToJS(file_content, type); - free(file_content); - file_content = nullptr; + if (file_len <= ROUTE_TRANS_MAX_SIZE) { + BaidumapSendMsgToJS(file_content, type); + free(file_content); + file_content = nullptr; + } else { + BaidumapFailSendMsgToJS("long distance", type); + } + } errcode_t msg_center_vector_navi_pull_up(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) @@ -764,6 +771,17 @@ static bool is_vector_navi_longbuf(uint8_t type) } } +bool is_vector_navi_long_distance(uint8_t type) +{ + if (type == MSGCENTER_TYPE_ID_VECTOR_NAVI_REC_ROUTE_RIDING_SEARCH || + type == MSGCENTER_TYPE_ID_VECTOR_NAVI_REC_ROUTE_WALKING_SEARCH || + type == MSGCENTER_TYPE_ID_VECTOR_NAVI_REC_ROUTE_TRANSIT_SEARCH) { + return true; + } else { + return false; + } +} + static bool has_two_callback(uint8_t type) { if (type == MSGCENTER_TYPE_ID_VECTOR_NAVI_REC_GEOCODE_SEARCH || @@ -1088,6 +1106,49 @@ errcode_t msg_center_vector_navi_req_destroy_page(uint8_t cmd_id, uint8_t type, return msg_center_vector_navi_req_common_proc(cmd_id, type, usr_data, usr_len); } +errcode_t msg_center_vector_navi_rec_first_batch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + uint8_t tl_len = msg_center_get_tlv_tl_len(usr_data); + uint16_t payload_len = usr_len - tl_len; + uint8_t *tlv_payload = (uint8_t *)msg_center_get_tlv_payload(usr_data); + uint8_t ack = 1; + errcode_t ret = ERRCODE_SUCC; + uint8_t res; + + /* ack */ + ret = msg_center_send_data(cmd_id, type, &ack, sizeof(ack)); + if (ret != ERRCODE_SUCC) { + return ERRCODE_FAIL; + } + + /* BD09坐标系json */ + char *json = (char *)malloc(payload_len + 1); + if (json == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_MSG_CENTER, "rec_first_batch_json: malloc failed.\r\n"); + return ERRCODE_FAIL; + } + + (void)memcpy_s(json, payload_len, tlv_payload, payload_len); + json[payload_len] = '\0'; + WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "rec_first_batch_json: %s\r\n", json); + + duer_msg_center_map_to_title(json, payload_len); + free(json); + json = NULL; + + return ERRCODE_SUCC; +} + +errcode_t msg_center_vector_navi_req_destroy_from_watch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + return msg_center_vector_navi_req_common_proc(cmd_id, type, usr_data, usr_len); +} + +errcode_t msg_center_vector_navi_rec_destroy_from_watch(uint8_t cmd_id, uint8_t type, void *usr_data, uint16_t usr_len) +{ + return msg_center_vector_navi_rec_common_proc(cmd_id, type, usr_data, usr_len); +} + #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wstp/at_service/app/app_at_process.c b/code/sdk/application/wstp/at_service/app/app_at_process.c index d69fb55ef..02492f115 100644 --- a/code/sdk/application/wstp/at_service/app/app_at_process.c +++ b/code/sdk/application/wstp/at_service/app/app_at_process.c @@ -528,8 +528,7 @@ static uint32_t mcu_fs_format(uint8_t *para, uint32_t para_len) #ifdef CFG_DRIVERS_NANDFLASH wstp_print("\r\nnandflash format,wait a moment!\r\n"); - struct nand_driver_struct* driver = get_nand_flash(); - erase_all(driver); + nandflash_yaffs_format(); ret = ERRCODE_SUCC; #endif @@ -1793,11 +1792,12 @@ uint32_t at_nand_write_erase(uint8_t *data, uint32_t data_len) #ifdef CFG_DRIVERS_NANDFLASH char *ptr = (char *)data; uint32_t block = strtoul(ptr, NULL, 10); - wstp_print("block = %d \r\n", block); struct nand_driver_struct *freertos_nandflash_driver = get_nand_flash(); + wstp_print("block = %d total_block = %d\r\n", block, freertos_nandflash_driver->total_block); if (block >= freertos_nandflash_driver->total_block) { - wstp_print("exceed max block = %d \r\n", block); - return ERRCODE_FAIL; + erase_all(freertos_nandflash_driver); + wstp_print("erase all block\r\n"); + return ERRCODE_SUCC; } freertos_nandflash_driver->erase_block(block); #endif diff --git a/code/sdk/application/wstp/at_service/app/app_common_api.c b/code/sdk/application/wstp/at_service/app/app_common_api.c index 26a28dff0..b5e1c37f8 100644 --- a/code/sdk/application/wstp/at_service/app/app_common_api.c +++ b/code/sdk/application/wstp/at_service/app/app_common_api.c @@ -229,7 +229,7 @@ void nand_read_test(struct nand_driver_struct* driver, uint32_t nand_test_blocks uint8_t status; for (uint32_t i = 0; i < nand_test_blocks * driver->pages_per_block; i++) { ret = driver->read_page(i, rbuf, driver->bytes_per_page, rbuf + driver->bytes_per_page, - driver->bytes_per_oob, &status); + driver->bytes_per_oob, &status, TRANS_DEFAULT); if (ret != MC_SUCCESS) { PRINT("nand aging test read failed %d \r\n", ret); continue; @@ -263,7 +263,7 @@ void nand_write_test(struct nand_driver_struct* driver, uint32_t nand_test_block } ret = driver->read_page(i, rbuf, driver->bytes_per_page, rbuf + driver->bytes_per_page, - driver->bytes_per_oob, &status); + driver->bytes_per_oob, &status, TRANS_DEFAULT); if (ret != MC_SUCCESS) { PRINT("nand aging test read failed %d \r\n", ret); continue; diff --git a/code/sdk/application/wstp/at_service/ohosfwk/CMakeLists.txt b/code/sdk/application/wstp/at_service/ohosfwk/CMakeLists.txt index 2b97afce0..d036b0a2c 100644 --- a/code/sdk/application/wstp/at_service/ohosfwk/CMakeLists.txt +++ b/code/sdk/application/wstp/at_service/ohosfwk/CMakeLists.txt @@ -17,6 +17,8 @@ set(PRIVATE_HEADER ${ROOT_DIR}/application/wearable/ohos_deps ${ROOT_DIR}/application/wearable/nativeapp/nativeui/uiservice/include ${ROOT_DIR}/open_source/openharmony/third_party/cJSON + ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/kits + ${ROOT_DIR}/middleware/services/gui/uikit/utils/interfaces/innerkits ) set(PRIVATE_DEFINES diff --git a/code/sdk/application/wstp/at_service/ohosfwk/ohosfwk_at_process.cpp b/code/sdk/application/wstp/at_service/ohosfwk/ohosfwk_at_process.cpp index 7a36219b8..bbba86e0f 100644 --- a/code/sdk/application/wstp/at_service/ohosfwk/ohosfwk_at_process.cpp +++ b/code/sdk/application/wstp/at_service/ohosfwk/ohosfwk_at_process.cpp @@ -15,6 +15,8 @@ #include "gt_bundle_manager_service.h" #include "ui_service.h" #include "sign_mode.h" +#include "NativeAbility.h" +#include "ability_manager.h" #define ARRAY_COUNT(array) (sizeof(array) / sizeof(array[0])) #define OHOSFWK_MAX_ARGC 8 @@ -172,11 +174,62 @@ static uint32_t OhosfwkATCmdBmSet(uint8_t *para, uint32_t paraLen, char *strComm return ERRCODE_SUCC; } +static uint32_t OhosfwkATCmdAmChangeNativeSlice(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + unused(strCommonCmd); + uint8_t argv[OHOSFWK_MAX_ARGC][OHOSFWK_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != OHOSFWK_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OHOSFWK ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + if (argc != 1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OHOSFWK ATCMD Set Parameter Failed\n"); + return ERRCODE_FAIL; + } + char *stringAppViewId = (char *)argv[0]; + uint16_t AppViewId = static_cast(std::stoi(stringAppViewId)); + OHOS::NativeAbility::GetInstance().ChangeSlice(AppViewId); + return ERRCODE_SUCC; +} + +static uint32_t OhosfwkATCmdAmStartJsApp(uint8_t *para, uint32_t paraLen, char *strCommonCmd) +{ + unused(strCommonCmd); + uint8_t argv[OHOSFWK_MAX_ARGC][OHOSFWK_MAX_ARGV_LEN] = { 0 }; + uint32_t argc = 0; + + int ret = ConvertCmdToParam(para, paraLen, argv, &argc); + if (ret != OHOSFWK_SUCCESS) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OHOSFWK ATCMD Convert Command Failed\n"); + return ERRCODE_FAIL; + } + + if (argc != 1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OHOSFWK ATCMD Set Parameter Failed\n"); + return ERRCODE_FAIL; + } + Want *want = new Want(); + memset_s(want, sizeof(Want), 0, sizeof(Want)); + + ElementName startElement = {}; + startElement.abilityName = (char *)"default"; + startElement.bundleName = (char *)argv[0]; + startElement.deviceId = nullptr; + SetWantElement(want, startElement); + StartAbility(want); + delete want; + return ERRCODE_SUCC; +} + static const at_cmd_table_t g_ohosfwk_cmd[] = { { (char *)"AT^OHOSFWK_AM_EXIT_JSAPP", OhosfwkATCmdAmExitJsApp, (char *)"00 00 00 00" }, { (char *)"AT^OHOSFWK_BM_INSTALL", OhosfwkATCmdBmInstall, (char *)"00 00 00 01" }, { (char *)"AT^OHOSFWK_BM_SET", OhosfwkATCmdBmSet, (char *)"00 00 00 02" }, { (char *)"AT^OHOSFWK_BM_UNINSTALL", OhosfwkATCmdBmUninstall, (char *)"00 00 00 03" }, + { (char *)"AT^OHOSFWK_AM_CHANGENATIVESLICE", OhosfwkATCmdAmChangeNativeSlice, (char *)"00 00 00 04" }, + { (char *)"AT^OHOSFWK_AM_START_JS_APP", OhosfwkATCmdAmStartJsApp, (char *)"00 00 00 05" }, }; at_cmd_table_t *get_ohosfwk_cmd_table(uint32_t *cmd_count) diff --git a/code/sdk/bootloader/flashboot/brandy/CMakeLists.txt b/code/sdk/bootloader/flashboot/brandy/CMakeLists.txt index bfe51e417..5724dfd9b 100644 --- a/code/sdk/bootloader/flashboot/brandy/CMakeLists.txt +++ b/code/sdk/bootloader/flashboot/brandy/CMakeLists.txt @@ -2,6 +2,7 @@ # @brief cmake file # Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. #=============================================================================== +add_subdirectory_if_exist(emmc) add_subdirectory_if_exist(nandflash) add_subdirectory_if_exist(boot_ulp) set(COMPONENT_NAME "flash_boot_brandy") diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/CMakeLists.txt b/code/sdk/bootloader/flashboot/brandy/emmc/CMakeLists.txt new file mode 100644 index 000000000..db6616dce --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/CMakeLists.txt @@ -0,0 +1,49 @@ +#=============================================================================== +# @brief cmake file +# Copyright (c) @CompanyNameMagicTag 2022-2022. All rights reserved. +#=============================================================================== +set(COMPONENT_NAME "boot_emmc") + +set(SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/hal_mmc_common.c + ${CMAKE_CURRENT_SOURCE_DIR}/drv_mmc_adapter.c + ${CMAKE_CURRENT_SOURCE_DIR}/mmc_block.c + ${CMAKE_CURRENT_SOURCE_DIR}/mmcsd_core.c + ${CMAKE_CURRENT_SOURCE_DIR}/mmc.c + ${CMAKE_CURRENT_SOURCE_DIR}/sd.c + ${CMAKE_CURRENT_SOURCE_DIR}/sdio.c +) + +set(PUBLIC_HEADER + ${CMAKE_CURRENT_SOURCE_DIR}/ +) + +set(PRIVATE_HEADER +) + +set(PRIVATE_DEFINES +) + +set(PUBLIC_DEFINES +) + +# use this when you want to add ccflags like -include xxx +set(COMPONENT_PUBLIC_CCFLAGS +) + +set(COMPONENT_CCFLAGS + -Wno-incompatible-function-pointer-types + -Wno-incompatible-pointer-types + -Wno-implicit-function-declaration + -Wno-int-conversion +) + +set(WHOLE_LINK + true +) + +set(MAIN_COMPONENT + false +) + +build_component() \ No newline at end of file diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/drv_mmc_adapter.c b/code/sdk/bootloader/flashboot/brandy/emmc/drv_mmc_adapter.c new file mode 100644 index 000000000..3a339f6d1 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/drv_mmc_adapter.c @@ -0,0 +1,1418 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: MMC DRIVER ADAPTER. + * Author: + * Create: 2020-04 + */ + +#include "mshc_reg.h" +#include "hal_mmc_common.h" +#include "mmcsd_core.h" +#include "mmc.h" +#include "oal_interface.h" +#include "chip_core_irq.h" +#include "debug_print.h" +#include "mmc_block.h" +#include "panic.h" +#include "pinctrl_porting.h" +#include "chip_io.h" +#include "drv_mmc_adapter.h" + +#define ADMA2_16BIT_LEN_MAX_VAL 65536UL +#define ADMA2_FLAG_VALID_BIT_AND_TRAN_DATA_STAT 0x21 +#define STOP_CMD_RETRY_TIMES 500 +#define TRY_TIMES 3 +#define DCACHE_LINE_ALIGN 32 +#define MPU_DTCM_ADDR_BASE 0x20000000 +#define MPU_DTCM_LEN 0x00040000 +#define EMMC_PINMUX_NUM 10 +#define EMMC_PAD_PINMUX_NUM 9 +#define EMMC_BASE_ADDR 0x52062000 +#define EMMC_STAB_MAX_LEN 1024 + +#define hi_mmc_judge_buf_in_dtcm(addr) ((MPU_DTCM_ADDR_BASE <= (uint32_t)(addr)) && \ + ((uint32_t)(addr) <= MPU_DTCM_ADDR_BASE + MPU_DTCM_LEN)) + +struct hi_mmc_drv *g_mmc_ptr[MAX_MMC_NUM] = { 0 }; +static uint32_t g_mmc_int_status = 0; +volatile int g_mmc_init_process = 1; +static mmc_err_info_type_t g_mmc_err_info = { 0 }; +struct rt_mmcsd_host* g_mmc = NULL; +char g_adma_buf[128]__attribute__((__aligned__(64))) = { 0 }; + +static void hi_mmc_request(struct rt_mmcsd_host *mmc, struct rt_mmcsd_req *req); +static void hi_mmc_set_iocfg(struct rt_mmcsd_host *mmc, struct rt_mmcsd_io_cfg *io_cfg); +static void hi_mmc_enable_sdio_irq(struct rt_mmcsd_host *mmc, rt_int32_t enable); +static void hi_send_cmd(struct hi_mmc_drv *mmc_drv, struct rt_mmcsd_cmd *cmd, const struct rt_mmcsd_data *data); +static void hi_mmc_set_power(struct rt_mmcsd_host *mmc, uint8_t mode); +static void hi_mmc_set_bus_mode(const struct rt_mmcsd_host *mmc, int mode); +static void hi_mmc_poll_handler_all(struct hi_mmc_drv *mmc_drv); + +uintptr_t mmc_align(uintptr_t addr, uint32_t boundary) +{ + return (addr + boundary - 1) & ~((uintptr_t)(boundary - 1)); +} + +void hi_mmc_set_clock(struct rt_mmcsd_host *mmc, unsigned int clocknum) +{ + if (mmc == NULL) { + return; + } + struct hi_mmc_drv *mmc_drv = mmc->private_data; + + if (clocknum >= mmc_drv->freq_max) { + clocknum = mmc_drv->freq_max; + } + hal_mmc_set_clock(mmc_drv, clocknum); + // when the clock freq greater 16mhz, for performance, don't wait the int status register. + if (clocknum >= 16000000) { // 16000000 means clock freq 16MHz + g_mmc_init_process = 0; + LOG_E("MODIFY THE CLOKNUM=%d", clocknum); + } +} + +static void hi_mmc_set_tsf_irqs(struct hi_mmc_drv *mmc) +{ + unsigned int pio_irqs = MSHC_INT_DATA_AVAIL | MSHC_INT_SPACE_AVAIL; + unsigned int dma_irqs = MSHC_INT_DMA_END | MSHC_INT_ADMA_ERROR; + + if ((mmc->flags & MMC_FLAG_REQ_USE_DMA) != 0) { + mmc->irq_enable = (mmc->irq_enable & ~pio_irqs) | dma_irqs; + } else { + mmc->irq_enable = (mmc->irq_enable & ~dma_irqs) | pio_irqs; + } + hal_mmc_enable_plug_irq(mmc, mmc->irq_enable); +} + +static void hi_mmc_adma_set_desc_line(const struct hi_mmc_drv *mmc_drv, const char *desc, + unsigned long addr, uint32_t len, unsigned cmd) +{ + unsigned short* cmdlen = (unsigned short *)desc; + + cmdlen[0] = (unsigned short)(cmd); + cmdlen[1] = (unsigned short)(len); + + if ((mmc_drv->flags & MMC_FLAG_USE_ADMA_64BIT) != 0) { + unsigned long *dataddr = (unsigned long*)(desc + ADMA_EVERY_ITEM_LEN); + dataddr[0] = (addr); + } else { + unsigned int *dataddr = (unsigned int*)(desc + ADMA_EVERY_ITEM_LEN); + dataddr[0] = (addr); + } +} + +static void hi_mmc_adma_set_end(char *desc) +{ + unsigned short *d = (unsigned short *)desc; + d[0] |= ADMA2_TRANS_END; +} + +static int hi_mmc_adma_set_desc_table(struct hi_mmc_drv *mmc_drv, struct rt_mmcsd_data *data) +{ + char *adma_desc = NULL; + unsigned long addr; + uint32_t len; + + adma_desc = mmc_drv->adma_desc; + (void)memset_s(mmc_drv->adma_desc, mmc_align(mmc_drv->adma_desc_sz, CACHE_ALIGNED_SIZE), + 0, mmc_align(mmc_drv->adma_desc_sz, CACHE_ALIGNED_SIZE)); + addr = (uintptr_t)data->buf; + len = data->blks * data->blksize; + LOG_I("DMA addr:%x, len:%d dma_malloc_len=%d", addr, len, mmc_align(mmc_drv->adma_desc_sz, CACHE_ALIGNED_SIZE)); + + do { + if (len > ADMA2_16BIT_LEN_MAX_VAL) { + hi_mmc_adma_set_desc_line(mmc_drv, adma_desc, addr, ADMA2_16BIT_LEN_MAX_VAL, + ADMA2_FLAG_VALID_BIT_AND_TRAN_DATA_STAT); + len -= ADMA2_16BIT_LEN_MAX_VAL; + addr += ADMA2_16BIT_LEN_MAX_VAL; + } else { + hi_mmc_adma_set_desc_line(mmc_drv, adma_desc, addr, len, ADMA2_FLAG_VALID_BIT_AND_TRAN_DATA_STAT); + len = 0; + } + adma_desc += mmc_drv->adma_desc_line_sz; + } while (len != 0); + + if ((unsigned int)(adma_desc - mmc_drv->adma_desc) > mmc_drv->adma_desc_sz) { + LOG_E("check dma wrong! adma_desc:%d, desc:%d, sz:%d", + adma_desc, mmc_drv->adma_desc, mmc_drv->adma_desc_sz); + return -1; + } + /* Mark the last descriptor as the terminating descriptor */ + if (adma_desc != mmc_drv->adma_desc) { + adma_desc -= mmc_drv->adma_desc_line_sz; + hi_mmc_adma_set_end(adma_desc); + } + return 0; +} + +struct rt_mmcsd_host* hi_mmc_get_host(uint32_t id) +{ + return g_mmc_ptr[id]->host; +} + +static void hi_mmc_non_os_req(void) +{ + uint32_t times = NON_OS_WAIT_SUM_TIMES; + while (g_mmc_int_status == 0) { + uapi_tcxo_delay_ms(NON_OS_WAIT_INT_PER_MSEC); + times--; + if (times == 0) { + LOG_I("non-os mode the req timeout failed"); + break; + } + } + g_mmc_int_status = 0; +} + +void hal_mmc_reset(struct hi_mmc_drv *mmc_drv) +{ + if (mmc_drv == NULL) { + return; + } + hal_mmc_clr_reg(mmc_drv, MSHC_RESET_ALL); +} + +void hi_mmc_set_power(struct rt_mmcsd_host *mmc, uint8_t mode) +{ + if ((mmc == NULL) || (mmc->private_data == NULL)) { return; } + struct hi_mmc_drv *mmc_drv = mmc->private_data; + unsigned int pwr = MSHC_POWER_330; + + LOG_D("host->pwr = 0x%x, vdd value =%d, version=%d", mmc_drv->pwr, mmc->valid_ocr, mmc_drv->version); + + if (mode == POWER_OFF) { + mmc_writew(mmc_drv, 0, MSHC_NOR_SIGNAL_ENABLE); + mmc_writew(mmc_drv, 0, MSHC_ERR_SIGNAL_ENABLE); + hal_mmc_reset(mmc_drv); + } else { + if (mmc_drv->version >= MSHC_SPEC_300) { + hal_mmc_set_preset_val(mmc_drv, false); + } + + if (mmc_drv->pwr == MSHC_POWER_330) { + return; + } + + mmc_drv->pwr = pwr; + + mmc_writeb(mmc_drv, 0, MSHC_POWER_CONTROL); + mmc_writeb(mmc_drv, (uint8_t)pwr, MSHC_POWER_CONTROL); + pwr |= MSHC_POWER_ON; + mmc_writeb(mmc_drv, (uint8_t)pwr, MSHC_POWER_CONTROL); + uapi_tcxo_delay_ms(NON_OS_WAIT_INT_PER_MSEC); + } +} + +void hi_mmc_set_bus_mode(const struct rt_mmcsd_host *mmc, int mode) +{ + UNUSED(mmc); + UNUSED(mode); +} + +void hi_mmc_set_bus_width(struct rt_mmcsd_host *mmc, int width) +{ + if (mmc == NULL) { + return; + } + unsigned char ctrl_val; + struct hi_mmc_drv *mmc_drv = mmc->private_data; + + ctrl_val = mmc_readb(mmc_drv, MSHC_HOST_CONTROL); + if (width == BUS_WIDTH_8) { + ctrl_val &= ~MSHC_CTRL_4BITBUS; + if (mmc_drv->version >= MSHC_SPEC_300) { + ctrl_val |= MSHC_CTRL_8BITBUS; + } + } else { + if (mmc_drv->version >= MSHC_SPEC_300) { + ctrl_val &= ~MSHC_CTRL_8BITBUS; + } + if (width == BUS_WIDTH_4) { + ctrl_val |= MSHC_CTRL_4BITBUS; + } else { + ctrl_val &= ~MSHC_CTRL_4BITBUS; + } + } + mmc_writeb(mmc_drv, ctrl_val, MSHC_HOST_CONTROL); +} + +static void hi_mmc_set_voltage(const struct rt_mmcsd_host *mmc, uint16_t vdd) +{ + UNUSED(mmc); + UNUSED(vdd); +} + +void hi_mmc_set_timing(struct rt_mmcsd_host *mmc, int timing) +{ + hal_mmc_set_timing(mmc->private_data, timing); +} + +void hi_mmc_set_iocfg(struct rt_mmcsd_host *mmc, struct rt_mmcsd_io_cfg *io_cfg) +{ + LOG_D("hisi emmc powr_mode=%d clock=%d, bus_mode=%d, bus_width=%d, vdd=%d", + io_cfg->power_mode, io_cfg->clock, io_cfg->bus_mode, io_cfg->bus_width, io_cfg->vdd); + hi_mmc_set_power(mmc, io_cfg->power_mode); + hi_mmc_set_clock(mmc, io_cfg->clock); + hi_mmc_set_bus_mode(mmc, io_cfg->bus_mode); + hi_mmc_set_bus_width(mmc, io_cfg->bus_width); + hi_mmc_set_voltage(mmc, io_cfg->vdd); +} + +void hi_mmc_enable_sdio_irq(struct rt_mmcsd_host *mmc, rt_int32_t enable) +{ + UNUSED(mmc); + UNUSED(enable); +} + +static void hi_mmc_prepare_data(struct hi_mmc_drv *mmc_drv) +{ + unsigned char ctrl; + struct rt_mmcsd_data *data = mmc_drv->data; + int retval = 0; + + if (data == NULL) { + return; + } + LOG_D("data blocksz = %d, blocks = %d, max_request_size = %d", + data->blksize, data->blks, mmc_drv->host->max_dma_segs); + mmc_assert(((data->blksize * data->blks) < (mmc_drv->host->max_dma_segs))); + mmc_assert(data->blksize <= mmc_drv->host->max_blk_size); + mmc_assert(data->blks < MMC_HOST_MAX_BLKS); + /* set timeout value , use default value. */ + mmc_writeb(mmc_drv, MSHC_DEFINE_TIMEOUT, MSHC_TIMEOUT_CONTROL); + + mmc_drv->data->bytes_xfered = 0; + // just only consider the ADMA2, default is ADMA2 + ctrl = mmc_readb(mmc_drv, MSHC_HOST_CONTROL); + ctrl &= ~MSHC_CTRL_DMA_MASK; + if ((mmc_drv->flags & MMC_FLAG_REQ_USE_DMA) != 0) { + if ((mmc_drv->flags & MMC_FLAG_USE_ADMA) != 0) { + /* ADMA config */ + retval = hi_mmc_adma_set_desc_table(mmc_drv, data); + if (retval != 0) { + mmc_drv->flags &= ~MMC_FLAG_REQ_USE_DMA; + } else { + mmc_writel(mmc_drv, 0, MSHC_DMA_ADDRESS); + hal_mmc_adma_config(mmc_drv); + } + ctrl |= ((mmc_drv->flags & MMC_FLAG_USE_ADMA_64BIT) != 0 ? MSHC_CTRL_ADMA64 : MSHC_CTRL_ADMA32); + } + } + + mmc_writeb(mmc_drv, ctrl, MSHC_HOST_CONTROL); + hi_mmc_set_tsf_irqs(mmc_drv); + mmc_writew(mmc_drv, MSHC_MAKE_BLKSZ(SDMA_BUF_BOUNDARY_512K, data->blksize), MSHC_BLOCK_SIZE); + mmc_writew(mmc_drv, (unsigned short)data->blks, MSHC_BLOCK_COUNT); +} + +static void hi_mmc_set_tsf_mode(struct hi_mmc_drv *mmc_drv, const struct rt_mmcsd_cmd *cmd) +{ + uint16_t mode; + struct rt_mmcsd_data *data = mmc_drv->data; + struct rt_mmcsd_card *card = mmc_drv->host->card; + if (data == NULL) { + mode = mmc_readw(mmc_drv, MSHC_TRANSFER_MODE); + mmc_writew(mmc_drv, mode & ~(MSHC_TRNS_AUTO_CMD12 | + MSHC_TRNS_AUTO_CMD23), MSHC_TRANSFER_MODE); + return; + } + mode = MSHC_TRNS_BLK_CNT_EN; + if (cmd->cmd_code == WRITE_MULTIPLE_BLOCK || + cmd->cmd_code == READ_MULTIPLE_BLOCK || data->blks > 1) { + mode |= MSHC_TRNS_MULTI; + // delete sd, just consider emmc + if ((card->card_type == CARD_TYPE_MMC) && (data->flags & DATA_CMD_AUTO_STOP)) { + if ((is_mmc_cmd23_support(card)) == 0) { + mode |= MSHC_TRNS_AUTO_CMD12; + } else { + mode |= MSHC_TRNS_AUTO_CMD23; + } + } + } + + if ((data->flags & DATA_DIR_READ) != 0) { + mode |= MSHC_TRNS_READ; + } + if ((mmc_drv->flags & MMC_FLAG_REQ_USE_DMA) != 0) { + mode |= MSHC_TRNS_DMA; + } + mmc_writew(mmc_drv, mode, MSHC_TRANSFER_MODE); +} + +static void hi_mmc_bottom_finish(struct hi_mmc_drv *mmc_drv) +{ + if (mmc_drv == NULL) { + return; + } + struct rt_mmcsd_req *mrq = NULL; + + mmc_assert(mmc_drv); + if (mmc_drv->req == NULL) { + return; + } + mrq = mmc_drv->req; + mmc_assert(mrq); + + if ((mmc_drv->flags & MMC_FLAG_DEVICE_DEAD) == 0 && ((mrq->cmd != NULL && mrq->cmd->err != 0) || + (mrq->data != NULL && mrq->data->err != 0))) { + g_mmc_err_info.mmc_cmd_err = mrq->cmd->err; + g_mmc_err_info.mmc_cmd_data_err = mrq->data->err; + hal_mmc_clr_reg(mmc_drv, MSHC_RESET_CMD); + hal_mmc_clr_reg(mmc_drv, MSHC_RESET_DATA); + hi_mmc_err_recovery(); + } + mmc_drv->req = NULL; + mmc_drv->cmd = NULL; + mmc_drv->data = NULL; + + if ((mmc_drv->flags & MMC_FLAG_NON_OS_HANDLE) != 0) { + if ((mmc_drv->flags & MMC_FLAG_NON_INT_HANDLE) == 0) { + g_mmc_int_status = 1; + } + } +} + +static void hi_mmc_make_cmd_flags(const struct rt_mmcsd_cmd *cmd, unsigned int *flags) +{ + switch (resp_type(cmd)) { + case RESP_NONE: + break; + case RESP_R1: + case RESP_R5: + case RESP_R6: + case RESP_R7: + *flags |= (MSHC_CMD_RESP_SHORT | MSHC_CMD_CRC | MSHC_CMD_INDEX); + break; + case RESP_R1B: + *flags |= (MSHC_CMD_RESP_SHORT_BUSY | MSHC_CMD_CRC | MSHC_CMD_INDEX); + break; + case RESP_R2: + *flags |= (MSHC_CMD_RESP_LONG | MSHC_CMD_CRC); + break; + case RESP_R3: + case RESP_R4: + *flags |= MSHC_CMD_RESP_SHORT; + break; + default: + LOG_E("ERROR: %s, unknown cmd type %x", __func__, resp_type(cmd)); + return; + } +} + +static void hi_mmc_set_cmd_type(uint32_t code, unsigned int *flags) +{ + if ((code == STOP_TRANSMISSION) || (code == SD_IO_RW_DIRECT)) { + *flags |= MSHC_CMD_ABORTCMD; + } +} + +void hi_send_cmd(struct hi_mmc_drv *mmc_drv, + struct rt_mmcsd_cmd *cmd, const struct rt_mmcsd_data *data) +{ + unsigned int flags = 0; + unsigned int mask; + unsigned long timeout_val = NON_OS_WAIT_SUM_TIMES; // the longest time 5s + + LOG_D(">> Exec CMD%3d, Arg:%#x", cmd->cmd_code, cmd->arg); + + mask = MSHC_CMD_INHIBIT; + if ((data != NULL) || (resp_type(cmd) == RESP_R1B)) { mask |= MSHC_DATA_INHIBIT; } + + if (data != NULL && data->stop != NULL) { mask &= ~MSHC_DATA_INHIBIT; } + /* wait host ready */ + while ((mmc_readl(mmc_drv, MSHC_PRESENT_STATE) & mask) != 0) { + if (timeout_val == 0) { + LOG_E("exec cmd %d timeout!", cmd->cmd_code); + hi_mmc_dumpregs(mmc_drv); + cmd->err = -EIO; + hi_mmc_bottom_finish(mmc_drv); + return; + } + timeout_val--; + uapi_tcxo_delay_us((uint64_t)WAIT_RSP_PER_USEC); + } + + mmc_drv->cmd = cmd; + hi_mmc_prepare_data(mmc_drv); + mmc_writel(mmc_drv, cmd->arg, MSHC_ARGUMENT); + hi_mmc_set_tsf_mode(mmc_drv, cmd); + hi_mmc_make_cmd_flags(cmd, &flags); + /* CMD19 is special in that the Data Present Select should be set */ + if (data != NULL || cmd->cmd_code == SEND_TUNING_BLOCK || + cmd->cmd_code == SEND_TUNING_BLOCK_HS200) { + flags |= MSHC_CMD_DATA; + } + hi_mmc_set_cmd_type(cmd->cmd_code, &flags); + mmc_writew(mmc_drv, MSHC_MAKE_CMD(cmd->cmd_code, flags), MSHC_COMMAND); +#ifdef SDIO_SLAVE_TEST_SUIT + uapi_tcxo_delay_us(100); // wait 100us for sdio loop test. +#endif +} + +static bool hi_mmc_check_data_aligned(struct rt_mmcsd_req *req) +{ + uint32_t *buf = (uint32_t *)req->data->buf; + + if (req->data == NULL) { + return true; + } + if ((uint32_t)buf % EMMC_DMA_ALIGN != 0) { + req->data->err = -ENODMAALIGN; + LOG_E("check data dma aligned err buf=%d!", (uint32_t)req->data->buf); + return false; + } + if (hi_mmc_judge_buf_in_dtcm(req->data->buf)) { + return true; + } + if (non_os_is_dcache_enabled() && ((uint32_t)buf % DCACHE_LINE_ALIGN != 0)) { + req->data->err = ENOCACHEALIGN; + LOG_E("check data cacheline aligned err buf=%d!", (uint32_t)req->data->buf); + return false; + } + return true; +} + +static void hi_mmc_refresh_dcache_by_addr_in_write(struct rt_mmcsd_req *req) +{ + UNUSED(req); +} + +static void hi_mmc_refresh_dcache_by_addr_in_read(struct rt_mmcsd_req *req) +{ + UNUSED(req); +} + +void hi_mmc_request(struct rt_mmcsd_host *mmc, struct rt_mmcsd_req *req) +{ + struct hi_mmc_drv *mmc_drv = NULL; + int present; + uint32_t timeout = MMC_CMD_DATA_REQ_TIMEOUT; + uint32_t ret = 0; + + if (mmc == NULL || req == NULL) { + panic(0, __LINE__); + return ; //lint !e527 unreachable code + } + mmc_drv = mmc->private_data; + if (mmc_drv == NULL) { + panic(0, __LINE__); + return ; //lint !e527 unreachable code + } + hal_mmc_set_card_clk(mmc_drv, true); + + mmc_drv->req = req; + mmc_drv->data = req->data; + present = SDHCI_PLUG_STATE(mmc_drv); + if (!hi_mmc_check_data_aligned(req)) { return; } + hi_mmc_refresh_dcache_by_addr_in_write(req); + if (present == 0 && (mmc_drv->flags & MMC_FLAG_NO_DETECT_INSERT) == 0) { + req->cmd->err = -EIO; + LOG_E("card is not present!"); + panic(0, __LINE__); + return ; //lint !e527 unreachable code + } else { + hi_send_cmd(mmc_drv, req->cmd, req->data); + } + + if (req->data == NULL) { timeout = MMC_CMD_REQ_TIMEOUT; } + g_mmc_err_info.mmc_cmd_code = (uint8_t)req->cmd->cmd_code; + + if ((mmc_drv->flags & MMC_FLAG_NON_INT_HANDLE) != 0) { + hi_mmc_poll_handler_all(mmc_drv); + } else { + hi_mmc_non_os_req(); + } + + hi_mmc_refresh_dcache_by_addr_in_read(req); + hal_mmc_set_card_clk(mmc_drv, false); + UNUSED(ret); +} + +static rt_int32_t hi_mmc_get_card_status(struct rt_mmcsd_host *mmc) +{ + UNUSED(mmc); + return 0; +} + +static const struct rt_mmcsd_host_ops g_hi_ops = { + .request = hi_mmc_request, + .set_iocfg = hi_mmc_set_iocfg, + .get_card_status = hi_mmc_get_card_status, + .enable_sdio_irq = hi_mmc_enable_sdio_irq, +}; + +static void hi_mmc_get_resp_r2(struct hi_mmc_drv *mmc_drv, struct rt_mmcsd_cmd *cmd) +{ + int i; + for (i = 0; i < 4; i++) { // R2 len 32*4 bytes + cmd->resp[i] = mmc_readl(mmc_drv, (uint32_t)(MSHC_RESPONSE + (3 - i) * 4)) << 8; // 3 4 8 + if (i != 3) { // 3 + // exclude bit135~bit128 with 3, 4, 24 and 0xff to get useful resp + cmd->resp[i] |= (mmc_readl(mmc_drv, (uint32_t)(MSHC_RESPONSE + (3 - i) * 4 - 4)) >> 24) & 0xFF; + } + LOG_I("Resp %#x %#x %#x %#x", cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]); // Resp 0 1 2 3 + } +} + +/* + * Interrupt handling + */ +static void hi_mmc_finish_cmd(struct hi_mmc_drv *mmc_drv) +{ + struct rt_mmcsd_cmd *cmd = mmc_drv->cmd; + int32_t ret; + mmc_assert(mmc_drv->cmd); + if (cmd == NULL) { + return; + } + if ((cmd->flags & RESP_MASK) != 0) { + if (resp_type(cmd) == RESP_R2) { + hi_mmc_get_resp_r2(mmc_drv, cmd); + } else { + mmc_drv->cmd->resp[0] = mmc_readl(mmc_drv, MSHC_RESPONSE); + LOG_I("Resp = %#x", mmc_drv->cmd->resp[0]); + } + } + ret = memcpy_s(g_mmc_err_info.mmc_cmd_resp, sizeof(g_mmc_err_info.mmc_cmd_resp), + mmc_drv->cmd->resp, sizeof(g_mmc_err_info.mmc_cmd_resp)); + if (ret != 0) { return; } + if (mmc_drv->data == NULL || cmd->cmd_code == STOP_TRANSMISSION) { + hi_mmc_bottom_finish(mmc_drv); + } +} + +static void hi_mmc_cmd_irq(struct hi_mmc_drv *mmc_drv, uint32_t intmask, const unsigned int *mask) +{ + UNUSED(mask); + + mmc_assert(intmask); + + if (mmc_drv->cmd == NULL) { return; } + if ((intmask & MSHC_ERR_INT_MASK) != 0) { + mmc_drv->cmd->err = (int)(intmask & MSHC_ERR_INT_MASK); + } else { + mmc_drv->cmd->err = 0; + } + + if (mmc_drv->data == NULL && mmc_drv->cmd->err != 0) { + hi_mmc_bottom_finish(mmc_drv); + return; + } + + if (resp_type(mmc_drv->cmd) == RESP_R1B) { + return; + } + if ((intmask & MSHC_INT_RESPONSE) != 0) { + hi_mmc_finish_cmd(mmc_drv); + } +} + +void hi_mmc_set_interrup_status(bool en) +{ + struct rt_mmcsd_host *mmc = NULL; + struct hi_mmc_drv *mmc_drv; + mmc = hi_mmc_get_host(SDIO_EMMC_ID); + if (mmc == NULL) { + panic(0, __LINE__); + return; //lint !e527 unreachable code + } + mmc_drv = mmc->private_data; + + bool cur_int_status = (mmc_drv->flags & MMC_FLAG_NON_INT_HANDLE) != 0 ? false : true; + if (cur_int_status != en) { + if (en) { + mmc_drv->flags &= ~MMC_FLAG_NON_OS_HANDLE; + mmc_drv->flags &= ~MMC_FLAG_NON_INT_HANDLE; + int_enable_irq((int)mmc_drv->irq_num); + } else { + mmc_drv->flags |= MMC_FLAG_NON_OS_HANDLE; + mmc_drv->flags |= MMC_FLAG_NON_INT_HANDLE; + int_disable_irq((int)mmc_drv->irq_num); + } + } +} + +static void hi_mmc_finish_data(struct hi_mmc_drv *mmc_drv) +{ + struct rt_mmcsd_data *data = NULL; + + mmc_assert(mmc_drv->data); + + data = mmc_drv->data; + + if (data->err == 0) { + data->bytes_xfered = data->blks * data->blksize; + } else { + data->bytes_xfered = 0; + } + + if (DATA_CMD_STOP_ENABLE(data) != 0) { + if (data->err != 0) { + hal_mmc_clr_reg(mmc_drv, MSHC_RESET_CMD); + hal_mmc_clr_reg(mmc_drv, MSHC_RESET_DATA); + } + hi_send_cmd(mmc_drv, data->stop, NULL); + } else { + hi_mmc_bottom_finish(mmc_drv); + } +} + +static void hi_mmc_get_dat_irq_err(uint32_t intmask, int *err) +{ + if ((intmask & MSHC_ERR_INT_MASK) != 0) { + *err = (int)(intmask & MSHC_ERR_INT_MASK); + } else { + *err = 0; + } +} + +static void hi_mmc_data_irq(struct hi_mmc_drv *mmc_drv, uint32_t intmask) +{ + unsigned int command; + + mmc_assert(intmask); + + if (mmc_drv->data == NULL || (mmc_drv->cmd != NULL && mmc_drv->cmd->cmd_code == STOP_TRANSMISSION)) { + if (mmc_drv->cmd != NULL && (mmc_drv->cmd->flags & RESP_R1B) != 0) { + if ((intmask & MSHC_INT_DATA_TIMEOUT) != 0) { + mmc_drv->cmd->err = -ETIMEDOUT; + hi_mmc_bottom_finish(mmc_drv); + return; + } + if ((intmask & MSHC_INT_DATA_END) != 0) { + hi_mmc_finish_cmd(mmc_drv); + return; + } + } + } + if (mmc_drv->data == NULL) { + return; + } + hi_mmc_get_dat_irq_err(intmask, &(mmc_drv->data->err)); + if ((mmc_drv->data->err) != 0) { + command = MSHC_GET_CMD(mmc_readw(mmc_drv, MSHC_COMMAND)); + if (command != SEND_TUNING_BLOCK && command != SEND_TUNING_BLOCK_HS200) { + LOG_E("err = 0x%x, cmd = %d, interrupt = 0x%x", mmc_drv->data->err, command, intmask); + hi_mmc_dumpregs(mmc_drv); + } + hi_mmc_finish_data(mmc_drv); + } else { + if ((intmask & MSHC_INT_DATA_END) != 0) { + hi_mmc_finish_data(mmc_drv); + } + } +} + +void hi_mmc_poll_handler_all(struct hi_mmc_drv *mmc_drv) +{ + uint16_t int_nor_mask = 0; + uint16_t int_err_mask = 0; + unsigned int intmask; + uint32_t times = NON_OS_WAIT_SUM_TIMES; + + while ((mmc_readl(mmc_drv, MSHC_PRESENT_STATE) & MSHC_CMD_INHIBIT) != 0) { + if (times == 0) { + LOG_D("exec cmd %d timeout!", mmc_drv->cmd->cmd_code); + hi_mmc_dumpregs(mmc_drv); + mmc_drv->cmd->err = -EIO; + g_mmc_err_info.mmc_present_stat = mmc_readl(mmc_drv, MSHC_PRESENT_STATE); + g_mmc_err_info.mmc_cmd_err = mmc_drv->cmd->err; + return; + } + times--; + uapi_tcxo_delay_us((uint64_t)WAIT_RSP_PER_USEC); + } + + // in initial, clock freq is 400k, need more time to wait int status. + if (g_mmc_init_process == 1) { uapi_tcxo_delay_ms(1ULL); } + + times = NON_OS_WAIT_SUM_TIMES; + while (times != 0) { + int_nor_mask = mmc_readw(mmc_drv, MSHC_NOR_INT_STATUS); + int_err_mask = mmc_readw(mmc_drv, MSHC_ERR_INT_STATUS); + if (int_err_mask != 0) { g_mmc_err_info.mmc_err_int_stat = int_err_mask; } + mmc_writew(mmc_drv, int_nor_mask, MSHC_NOR_INT_STATUS); + mmc_writew(mmc_drv, int_err_mask, MSHC_ERR_INT_STATUS); + intmask = (int_nor_mask | ((uint32_t)int_err_mask << MSHC_ERR_INT_OFFSET)); + + LOG_D("poll status %#x", intmask); + if ((intmask & MSHC_INT_CMD_MASK) != 0) { + hi_mmc_cmd_irq(mmc_drv, (intmask & MSHC_INT_CMD_MASK), &intmask); + if (mmc_drv->data == NULL) { break; } + } + + if ((intmask & MSHC_INT_DATA_MASK) != 0) { + hi_mmc_data_irq(mmc_drv, (intmask & MSHC_INT_DATA_MASK)); + LOG_I("data poll status %#x", intmask); + break; + } + if ((intmask & MSHC_INT_BUS_POWER) != 0) { PRINT("host%d:card is consuming too much power!", mmc_drv->id); } + intmask &= ~(CART_PLUG_STATE | MSHC_INT_CMD_MASK | MSHC_INT_DATA_MASK | + MSHC_INT_ERROR | MSHC_INT_BUS_POWER | MSHC_INT_CARD_INT); + if (intmask != 0) { mmc_drv->err_int_count++; } + + uapi_tcxo_delay_us((uint64_t)WAIT_RSP_PER_USEC); + times--; + } + if (times == 0) { + hi_mmc_err_recovery(); + LOG_E("timeout, need check"); + } +} + +static void hi_mmc_irq(struct hi_mmc_drv *mmc_drv) +{ + uint16_t int_nor_mask = 0; + uint16_t int_err_mask = 0; + unsigned int intmask; + + while ((int_nor_mask = mmc_readw(mmc_drv, MSHC_NOR_INT_STATUS)) != 0) { + int_err_mask = mmc_readw(mmc_drv, MSHC_ERR_INT_STATUS); + + mmc_writew(mmc_drv, int_nor_mask, MSHC_NOR_INT_STATUS); + mmc_writew(mmc_drv, int_err_mask, MSHC_ERR_INT_STATUS); + + intmask = int_nor_mask; + intmask |= ((uint32_t)int_err_mask << MSHC_ERR_INT_OFFSET); + LOG_I("OS IRQ %#x", intmask); + if ((intmask & MSHC_INT_CMD_MASK) != 0) { + hi_mmc_cmd_irq(mmc_drv, (intmask & MSHC_INT_CMD_MASK), &intmask); + } + + if ((intmask & MSHC_INT_DATA_MASK) != 0) { + hi_mmc_data_irq(mmc_drv, (intmask & MSHC_INT_DATA_MASK)); + } + if ((intmask & MSHC_INT_BUS_POWER) != 0) { + LOG_E("host%d:card is consuming too much power!", mmc_drv->id); + } + intmask &= ~(CART_PLUG_STATE | MSHC_INT_CMD_MASK | MSHC_INT_DATA_MASK | + MSHC_INT_ERROR | MSHC_INT_BUS_POWER | MSHC_INT_CARD_INT); + if (intmask != 0) { + mmc_drv->err_int_count++; + } + } +} + +static uint32_t mmc_erase_param_align(struct rt_mmcsd_card *card, uint32_t *start, uint32_t *end, uint32_t nums) +{ + uint32_t from_new = *start; + uint32_t nr_new = nums; + uint32_t rem; + LOG_I("erase form %#x to %#x, nr is %d, size is %d", *start, *end, nums, card->erase_size); + rem = from_new % card->erase_size; + if (rem != 0) { + rem = card->erase_size - rem; + from_new += rem; + if (nr_new > rem) { + nr_new -= rem; + } else { + return 0; + } + } + + rem = nr_new % card->erase_size; + if (rem != 0) { + nr_new -= rem; + } + if (nr_new == 0) { + return 0; + } + *end = from_new + nr_new; + *start = from_new; + return nr_new; +} + +static int hi_mmc_send_erase_cmd(struct rt_mmcsd_card *card, struct rt_mmcsd_cmd *cmd, uint32_t arg, uint32_t cmd_code) +{ + int err; + (void)memset_s(cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + cmd->cmd_code = cmd_code; + cmd->arg = arg; + cmd->flags = RESP_R1 | CMD_AC; + err = mmcsd_send_cmd(card->host, cmd, MMC_ERASE_CMD_RETRIES_TIMES); + if (err != 0) { + LOG_E("erase cmd_code=%d req failed ret=%d", cmd_code, err); + err = -EIO; + } + return err; +} + +static int hi_mmc_do_erase(struct rt_mmcsd_card *card, uint32_t start, uint32_t end, uint32_t type) +{ + struct rt_mmcsd_cmd cmd = { 0 }; + uint32_t busy_timeout = MMC_ERASE_MAX_TIME_MS; + uint64_t timeout; + int err; + + if (type == MMC_ERASE_TYPE_ERASE) { // erase type is group erase + if (end - start + 1 < card->erase_size) { + err = EOPNOTSUPP; + goto out; + } + } + + err = hi_mmc_send_erase_cmd(card, &cmd, start, ERASE_GROUP_START); + if (err != 0) { + goto out; /*lint !e801*/ + } + err = hi_mmc_send_erase_cmd(card, &cmd, end, ERASE_GROUP_END); + if (err != 0) { + goto out; /*lint !e801*/ + } + err = hi_mmc_send_erase_cmd(card, &cmd, type, ERASE); + if (err != 0) { + goto out; /*lint !e801*/ + } + + timeout = uapi_tcxo_get_ms() + busy_timeout; + do { + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + cmd.cmd_code = SEND_STATUS; + cmd.arg = card->rca << MMC_RCA_OFFSET_VAL; + cmd.flags = RESP_R1 | CMD_AC; + err = mmcsd_send_cmd(card->host, &cmd, MMC_ERASE_CMD_RETRIES_TIMES); + if (err != 0 || (cmd.resp[0] & R1_RSP_ERASE_STATE_ALL_ERR) != 0) { + LOG_E("erase: err = %d ,status = 0x%x", err, cmd.resp[0]); + err = -EIO; + goto out; /*lint !e801*/ + } + if (uapi_tcxo_get_ms() >= timeout) { + err = -EIO; + goto out; /*lint !e801*/ + } + } while ((cmd.resp[0] & R1_READY_FOR_DATA) == 0 || (R1_CURRENT_STATE(cmd.resp[0]) == R1_STATE_PRG)); + return 0; +out: + LOG_E("do erase error ret=%d", err); + return err; +} + +int mmc_erase_arae(struct rt_mmcsd_card *card, const struct rt_mmcsd_req *req) +{ + uint32_t start = (uint32_t)req->erase->start_addr; + uint32_t end = (uint32_t)(req->erase->start_addr + req->erase->len); + uint32_t nums = (uint32_t)req->erase->len; + uint32_t type = (uint32_t)req->erase->type; + if ((card->csd.card_cmd_class & CCC_ERASE) == 0) { + LOG_E("cmd_class=%x is not support CCC_ERASE", card->csd.card_cmd_class); + return -EOPNOTSUPP; + } + if (card->erase_size == 0) { + LOG_E("erase_size=%x error", card->erase_size); + return -EOPNOTSUPP; + } + if (type == MMC_ERASE_TYPE_ERASE) { + nums = mmc_erase_param_align(card, &start, &end, nums); + if (nums == 0) { + LOG_E("nums=%x 0 err", nums); + return -EINVAL; + } + } + if (end <= start) { + LOG_E("end lower than start", end, start); + return -EINVAL; + } + return hi_mmc_do_erase(card, start, end, type); +} + +static void hi_mmc_irq_mmc0(void) +{ + hi_mmc_irq(g_mmc_ptr[SDIO_EMMC_ID]); +} + +static void hi_mmc_irq_mmc1(void) +{ + hi_mmc_irq(g_mmc_ptr[SDIO_HOST_ID]); +} + +static HWI_PROC_FUNC hi_mmc_get_int_func(uint32_t irq_num) +{ + if (irq_num == EMMC_IRQn) { + return hi_mmc_irq_mmc0; + } else { + return hi_mmc_irq_mmc1; + } +} + +int hi_mmc_card_busy(struct rt_mmcsd_host *mmc) +{ + struct hi_mmc_drv *mmc_drv = (struct hi_mmc_drv *)mmc->private_data; + uint32_t present_state; + + // Check whether DAT[0] is 0 + present_state = mmc_readl(mmc_drv, MSHC_PRESENT_STATE); + + return !(present_state & MSHC_DATA_0_LVL_MASK); +} + +void hi_mmc_set_drv_bus_width_features(struct hi_mmc_drv *mmc_drv) +{ + if ((mmc_drv->host->flags & MMCSD_BUSWIDTH_1) != 0) { + mmc_drv->bus_width = MMCSD_BUS_WIDTH_1; + } else if ((mmc_drv->host->flags & MMCSD_BUSWIDTH_8) != 0) { + mmc_drv->bus_width = MMCSD_BUS_WIDTH_8; + } else { // default bus width is 4bit + mmc_drv->bus_width = MMCSD_BUS_WIDTH_4; + } +} + +void hi_mmc_set_drv_features(struct hi_mmc_drv *mmc_drv, uint8_t id) +{ + mmc_drv->id = id; + g_mmc_ptr[id] = mmc_drv; + switch (id) { + case SDIO_EMMC_ID: + mmc_drv->hw_base_addr = SDIO_EMMC_BASE_ADDR; + mmc_drv->irq_num = EMMC_IRQn; + mmc_drv->type = MMC_TYPE_MMC; + mmc_drv->freq_max = CONFIG_MMC0_CCLK_MAX; + mmc_drv->freq_min = CONFIG_MMC0_CCLK_MIN; + mmc_drv->flags |= MMC_FLAG_AUTO_CMD23; + break; +#if (WITH_SDIO_HOST == YES) + case SDIO_HOST_ID: + mmc_drv->hw_base_addr = SDIO_HOST_BASE_ADDR; + mmc_drv->irq_num = SDIO_HOST_IRQn; + mmc_drv->type = MMC_TYPE_SDIO; + mmc_drv->freq_max = CONFIG_MMC1_CCLK_MAX; + mmc_drv->freq_min = CONFIG_MMC1_CCLK_MIN; + break; +#endif + default: + break; + } + + mmc_drv->phy_driver_cap = mmc_drv->host->driver_cap; + hi_mmc_set_drv_bus_width_features(mmc_drv); + hal_mmc_deassert_status(mmc_drv); // power on and dereset + mmc_drv->version = (mmc_readw(mmc_drv, MSHC_HOST_VERSION) & MSHC_SPEC_VER_MASK); + // in 1135, the eMMC and SDIO are unpluggable cards, chip is not supportted. + mmc_drv->flags |= (MMC_FLAG_USE_ADMA | MMC_FLAG_REQ_USE_DMA | MMC_FLAG_NO_DETECT_INSERT); + mmc_drv->adma_max_desc = MMC_ADMA_MAX_DESC; + mmc_drv->adma_desc_line_sz = MMC_AMDA_32BIT_DESC_LINE_SIZE; + mmc_drv->adma_desc_sz = mmc_drv->adma_max_desc * mmc_drv->adma_desc_line_sz; + mmc_drv->adma_desc = (void *)g_adma_buf; + + if ((mmc_drv->host->flags & MMCSD_NON_OS_ENABLE) != 0) { + mmc_drv->flags |= (MMC_FLAG_NON_OS_HANDLE | MMC_FLAG_NON_INT_HANDLE); + } + + if (id == SDIO_EMMC_ID) { + hal_mmc_set_emmc_ctrl(mmc_drv, (uint32_t)MSHC_EMMC_CTRL, (uint32_t)MSHC_CARD_IS_EMMC_START, + (uint32_t)MSHC_CARD_IS_EMMC_BITS, (uint32_t)MSHC_CARD_IS_EMMC); + // set MBIU_CTRL_R 8burst + uint32_t pvendor_spc_area = mmc_reg32_getbits(mmc_drv, SD_BUS_PVSA1, SD_BUS_PVSA1_POS, SD_BUS_PVSA1_LEN); + // Offset: P_VENDOR_SPECIFIC_AREA[11:0] + 0x10 + mmc_reg32_setbits(mmc_drv, pvendor_spc_area + 0x10, SD_BUS_MBURST_POS, SD_BUS_MBURST_LEN, SD_BUS_MBURST_VAL); + } +} + +void hi_mmc_set_host_features(struct rt_mmcsd_host *mmc) +{ + struct hi_mmc_drv *mmc_drv = mmc->private_data; + + mmc_drv->irq_enable = MSHC_INT_BUS_POWER | MSHC_INT_DATA_END_ERR | MSHC_INT_DATA_CRC | MSHC_INT_DATA_TIMEOUT | + MSHC_INT_INDEX | MSHC_INT_END_BIT | MSHC_INT_CRC | MSHC_INT_TIMEOUT | MSHC_INT_DATA_END | + MSHC_INT_RESPONSE | MSHC_INT_AUTO_CMD_ERR; + mmc_drv->pwr = 0; + hal_mmc_enable_plug_irq(mmc_drv, mmc_drv->irq_enable); + + mmc->freq_max = mmc_drv->freq_max; + mmc->freq_min = mmc_drv->freq_min; +// In the standard, the value is calculated based on the CAPABILITIES1_R field. +// in Hi1135 apply the fixed value. + mmc->valid_ocr = VDD_29_30 | VDD_30_31 | VDD_32_33 | VDD_33_34 | VDD_165_195; + mmc->max_blk_size = MAX_BLOCK_SIZE; + mmc->max_blk_count = MAX_BLOCK_COUNT; + mmc->max_seg_size = MAX_SEG_SIZE; + mmc->max_dma_segs = mmc_drv->adma_max_desc * mmc->max_seg_size; + if (mmc_drv->bus_width == MMCSD_BUS_WIDTH_4) { + mmc->flags |= MMCSD_BUSWIDTH_4; + } else if (mmc_drv->bus_width == MMCSD_BUS_WIDTH_8) { + mmc->flags |= MMCSD_BUSWIDTH_8; + } else { + mmc->flags |= MMCSD_BUSWIDTH_1; + } + mmc->ops = &g_hi_ops; +} + +int hi_mmc_set_int_info(struct rt_mmcsd_host *mmc, struct hi_mmc_drv *mmc_drv) +{ + HWI_PROC_FUNC irq_func; + int ret; + irq_func = (HWI_PROC_FUNC)hi_mmc_get_int_func(mmc_drv->irq_num); + ret = (int)oal_int_create(mmc_drv->irq_num, irq_prio(mmc_drv->irq_num), (HWI_PROC_FUNC)irq_func, 0); + if (ret != 0) { + LOG_E("set irq for mmmc host err %d", ret); + ret = -EACCES; + return ret; + } + if ((mmc_drv->flags & MMC_FLAG_NON_INT_HANDLE) != 0) { + ret = (int)oal_int_delete(mmc_drv->irq_num); + } + if (ret != 0) { + LOG_E("unset irq for mmmc host err %d", ret); + ret = -EACCES; + return ret; + } + + return ret; +} + +#define PHASE_SCALE 16 +#define NOT_FOUND (-1) +#define MAX_TUNING_NUM 1 +#define SAMP_PHASE_DEF 7 + +#define SAMP_PHASE_ENDPOINT 15 // Soc only support 16 phase + +/* Tuning Block Pattern UHS-I */ +static const uint8_t g_tuning_blk_4bit[] = { + 0xFF, 0x0F, 0xFF, 0x00, 0xFF, 0xCC, 0xC3, 0xCC, + 0xC3, 0x3C, 0xCC, 0xFF, 0xFE, 0xFF, 0xFE, 0xEF, + 0xFF, 0xDF, 0xFF, 0xDD, 0xFF, 0xFB, 0xFF, 0xFB, + 0xBF, 0xFF, 0x7F, 0xFF, 0x77, 0xF7, 0xBD, 0xEF, + 0xFF, 0xF0, 0xFF, 0xF0, 0x0F, 0xFC, 0xCC, 0x3C, + 0xCC, 0x33, 0xCC, 0xCF, 0xFF, 0xEF, 0xFF, 0xEE, + 0xFF, 0xFD, 0xFF, 0xFD, 0xDF, 0xFF, 0xBF, 0xFF, + 0xBB, 0xFF, 0xF7, 0xFF, 0xF7, 0x7f, 0x7B, 0xDE, +}; + +/* Tuning block pattern for 8 bit mode for HS200 */ +static const uint8_t g_tuning_blk_8bit[] = { + 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, + 0xFF, 0xFF, 0xCC, 0xCC, 0xCC, 0x33, 0xCC, 0xCC, + 0xCC, 0x33, 0x33, 0xCC, 0xCC, 0xCC, 0xFF, 0xFF, + 0xFF, 0xEE, 0xFF, 0xFF, 0xFF, 0xEE, 0xEE, 0xFF, + 0xFF, 0xFF, 0xDD, 0xFF, 0xFF, 0xFF, 0xDD, 0xDD, + 0xFF, 0xFF, 0xFF, 0xBB, 0xFF, 0xFF, 0xFF, 0xBB, + 0xBB, 0xFF, 0xFF, 0xFF, 0x77, 0xFF, 0xFF, 0xFF, + 0x77, 0x77, 0xFF, 0x77, 0xBB, 0xDD, 0xEE, 0xFF, + 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0x00, + 0x00, 0xFF, 0xFF, 0xCC, 0xCC, 0xCC, 0x33, 0xCC, + 0xCC, 0xCC, 0x33, 0x33, 0xCC, 0xCC, 0xCC, 0xFF, + 0xFF, 0xFF, 0xEE, 0xFF, 0xFF, 0xFF, 0xEE, 0xEE, + 0xFF, 0xFF, 0xFF, 0xDD, 0xFF, 0xFF, 0xFF, 0xDD, + 0xDD, 0xFF, 0xFF, 0xFF, 0xBB, 0xFF, 0xFF, 0xFF, + 0xBB, 0xBB, 0xFF, 0xFF, 0xFF, 0x77, 0xFF, 0xFF, + 0xFF, 0x77, 0x77, 0xFF, 0x77, 0xBB, 0xDD, 0xEE, +}; + +struct tuning_blk_info { + uint8_t *blk; + unsigned int blk_size; +}; + +static void hi_mmc_tune_out(struct hi_mmc_drv *mmc_drv, uint32_t start, + uint32_t top, uint32_t bottom, uint32_t end) +{ + int phase; + unsigned short val; + + if (top == (uint32_t)NOT_FOUND) { + top = start; + } + + if (bottom == (uint32_t)NOT_FOUND) { + bottom = end; + } + if (bottom < top) { + phase = (top + bottom) >> 1; + phase = phase - (PHASE_SCALE >> 1); + phase = (phase < 0) ? (PHASE_SCALE + phase) : phase; + } else { + phase = (uint32_t)((top + bottom) >> 1); + } + hal_mmc_set_sample_phase(mmc_drv, (uint32_t)phase); + + val = mmc_readw(mmc_drv, MSHC_HOST_CONTROL2); + val |= MSHC_CTRL_TUNED_CLK; + mmc_writew(mmc_drv, val, MSHC_HOST_CONTROL2); + hal_mmc_enable_plug_irq(mmc_drv, mmc_drv->irq_enable); + LOG_I("tuning valid phase shift [%d, %d] Final Phase %d", top, bottom, phase); +} + +static void mmc_tuning_config(struct rt_mmcsd_req *tuning_mrq, struct rt_mmcsd_cmd *tuning_cmd, + struct rt_mmcsd_data *tuning_data, struct tuning_blk_info *tuning_info, struct rt_mmcsd_host *mmc) +{ + struct hi_mmc_drv *mmc_drv = mmc->private_data; + + if (mmc->io_cfg.bus_width == MMCSD_BUS_WIDTH_8) { + tuning_info->blk = (uint8_t *)g_tuning_blk_8bit; + tuning_info->blk_size = sizeof(g_tuning_blk_8bit); + } else if (mmc->io_cfg.bus_width == MMCSD_BUS_WIDTH_4) { + tuning_info->blk = (uint8_t *)g_tuning_blk_4bit; + tuning_info->blk_size = sizeof(g_tuning_blk_4bit); + } else { + LOG_E("MMC tuning config error"); + return; + } + + tuning_mrq->cmd = tuning_cmd; + tuning_mrq->data = tuning_data; + tuning_cmd->arg = 0; + tuning_cmd->retries = 0; + tuning_cmd->flags = RESP_R1 | CMD_ADTC; + tuning_cmd->err = 0; + tuning_data->err = 0; + tuning_mrq->data->blksize = tuning_info->blk_size; + tuning_mrq->data->blks = 1; + tuning_mrq->data->flags = DATA_DIR_READ; + + mmc_drv->req = tuning_mrq; + mmc_drv->cmd = tuning_cmd; + mmc_drv->data = tuning_data; +} + +static int mmc_send_tuning(struct rt_mmcsd_host *mmc, uint32_t opcode, int32_t *cmd_error) +{ + struct rt_mmcsd_req tuning_mrq = {0}; + struct rt_mmcsd_cmd tuning_cmd = {0}; + struct rt_mmcsd_data tuning_data = {0}; + struct tuning_blk_info tuning_info = {NULL, 0}; + struct hi_mmc_drv *mmc_drv = mmc->private_data; + void *data_buf = NULL; + int err = 0; + + mmc_tuning_config(&tuning_mrq, &tuning_cmd, &tuning_data, &tuning_info, mmc); + data_buf = (void *)irmalloc(mmc_align(tuning_info.blk_size, CACHE_ALIGNED_SIZE)); + if (data_buf == NULL) { + return -ENOMEM; + } + (void)memset_s(data_buf, tuning_info.blk_size, 0, tuning_info.blk_size); + tuning_cmd.cmd_code = opcode; + tuning_mrq.data->buf = (rt_uint32_t *)data_buf; + hal_mmc_set_card_clk(mmc_drv, true); + + hi_send_cmd(mmc_drv, &tuning_cmd, &tuning_data); + + if ((mmc_drv->flags & MMC_FLAG_NON_INT_HANDLE) != 0) { + hi_mmc_poll_handler_all(mmc_drv); + } else { + hi_mmc_non_os_req(); + } + + hal_mmc_set_card_clk(mmc_drv, false); + if (cmd_error != NULL) { + *cmd_error = tuning_cmd.err; + err = tuning_cmd.err; + goto out; /*lint !e801*/ + } + if (tuning_cmd.err != 0) { + err = tuning_cmd.err; + goto out; /*lint !e801*/ + } + + if (tuning_data.err != 0) { + err = tuning_data.err; + goto out; /*lint !e801*/ + } + if (memcmp(tuning_info.blk, data_buf, tuning_info.blk_size) != 0) { + err = -EIO; + } +out: + irfree(data_buf); + return err; +} + +int hi_mmc_exec_tuning(struct rt_mmcsd_host *mmc, uint32_t opcode) +{ + uint32_t hindex, val; + uint32_t error = 0; + uint32_t found = 0; + uint32_t startPoint = 0; + uint32_t endPoint = SAMP_PHASE_ENDPOINT; + uint32_t prevError = (uint32_t)NOT_FOUND; + uint32_t raisePoint = (uint32_t)NOT_FOUND; + uint32_t fallPoint = (uint32_t)NOT_FOUND; + struct hi_mmc_drv *drv = mmc->private_data; + + LOG_I("MMC_ExeTuning"); + + val = mmc_readl(drv, MSHC_AUTO_TUNING_CTRL); + val |= MSHC_SW_TUNING_EN; + mmc_writel(drv, val, MSHC_AUTO_TUNING_CTRL); + + val = drv->irq_enable | MSHC_INT_DATA_AVAIL; + hal_mmc_enable_plug_irq(drv, val); + + for (hindex = startPoint; hindex <= endPoint; hindex++) { + hal_mmc_set_sample_phase(drv, hindex); + if (mmc_send_tuning(drv->host, opcode, NULL) == 0) { + found = 1; /* found a valid phase */ + } else { + error = 1; + } + + if (hindex > startPoint) { + if (error != 0 && prevError == 0) { + fallPoint = hindex - 1; + } + if (error == 0 && prevError != 0) { + raisePoint = hindex; + } + } + + if ((raisePoint != (uint32_t)NOT_FOUND) && + (fallPoint != (uint32_t)NOT_FOUND)) { + break; + } + prevError = error; + error = 0; + } + + if (found == 0) { + LOG_E("no valid phase shift! use default"); + hal_mmc_set_sample_phase(drv, (uint32_t)SAMP_PHASE_DEF); + } else { + LOG_I("Tuning finished!!"); + hi_mmc_tune_out(drv, startPoint, raisePoint, fallPoint, endPoint); + } + return 0; +} + +void mmc_set_sdiom_clk_mode(int clk_type) +{ + hal_mmc_set_sdiom_clk_mode(g_mmc_ptr, clk_type); +} + +void mmc_set_driver_capability(struct rt_mmcsd_host* mmc, uint32_t cap) +{ + mmc->driver_cap = cap; +} + +bool mmc_detect_bus_error(struct rt_mmcsd_host* host) +{ + if ((host == NULL) || (host->private_data == NULL)) { return false; } + struct hi_mmc_drv *mmc_drv = host->private_data; + uint32_t cur_pstate = mmc_readl(mmc_drv, MSHC_PRESENT_STATE); + if ((g_mmc_err_info.mmc_err_int_stat != 0) || (g_mmc_err_info.mmc_present_stat & MSHC_CMD_INHIBIT) != 0 || + (cur_pstate & MSHC_CMD_INHIBIT) != 0) { + return true; + } + return false; +} + +int hi_mmc_send_stop_cmd(struct rt_mmcsd_host *mmc, uint32_t *status) +{ + int err = 0; + struct rt_mmcsd_card *card = mmc->card; + struct rt_mmcsd_cmd cmd = { 0 }; + + memset_s(&cmd, sizeof(cmd), 0, sizeof(cmd)); + cmd.cmd_code = STOP_TRANSMISSION; + cmd.arg = 0; + cmd.flags = RESP_R1B | CMD_AC; + + err = mmcsd_send_cmd(card->host, &cmd, TRY_TIMES); + // if the status of emmc device is ok, it will not response to the cmd12. + if (err != 0) { LOG_E("cmd12 err %x \n", err); } + err = mmc_send_status(card, ((rt_uint32_t *)status)); + if (err != 0) { LOG_E("cmd13 after cmd12 err %x \n", err); } + return err; +} + +void hi_mmc_set_magic_to_aon_area(void) +{ +#if ((defined EMMC_ABNORMAL_SAVE_TO_AON_AREA) && (EMMC_ABNORMAL_SAVE_TO_AON_AREA == YES)) + uint8_t *ptr = (uint8_t*)(uintptr_t)EMMC_ERROR_INFO; + *ptr = EMMC_NORMAL_MAGIC_VAL; +#else // Add different items as required. +#endif +} + +// sum 8 byte: 1 magic + 1 cmd_code + 2 err_int_stat + 4 present_stat +void hi_mmc_set_err_to_aon_area(void) +{ +#if ((defined EMMC_ABNORMAL_SAVE_TO_AON_AREA) && (EMMC_ABNORMAL_SAVE_TO_AON_AREA == YES)) + uint8_t *ptr = (uint8_t*)(uintptr_t)EMMC_ERROR_INFO; + int32_t ret = 0; + *ptr = EMMC_ERROR_MAGIC_VAL; + ptr++; + ret = memcpy_s((void *)ptr, sizeof(g_mmc_err_info.mmc_cmd_code), &(g_mmc_err_info.mmc_cmd_code), + sizeof(g_mmc_err_info.mmc_cmd_code)); + ptr += sizeof(g_mmc_err_info.mmc_cmd_code); + ret = memcpy_s((void *)ptr, sizeof(g_mmc_err_info.mmc_err_int_stat), &(g_mmc_err_info.mmc_err_int_stat), + sizeof(g_mmc_err_info.mmc_err_int_stat)); + ptr += sizeof(g_mmc_err_info.mmc_err_int_stat); + ret = memcpy_s((void *)ptr, sizeof(g_mmc_err_info.mmc_present_stat), &(g_mmc_err_info.mmc_present_stat), + sizeof(g_mmc_err_info.mmc_present_stat)); +#else // Add different items as required. +#endif +} + +mmc_err_info_type_t *hi_mmc_get_err_from_aon_area(void) +{ +#if ((defined EMMC_ABNORMAL_SAVE_TO_AON_AREA) && (EMMC_ABNORMAL_SAVE_TO_AON_AREA == YES)) + mmc_err_info_type_t *ptr = (mmc_err_info_type_t *)(uintptr_t)EMMC_ERROR_INFO; + return ptr; +#else // Add different items as required. + return &g_mmc_err_info; +#endif +} + +void hi_mmc_reset_cmd_data(struct rt_mmcsd_host* host) +{ + if ((host == NULL) || (host->private_data == NULL)) { return; } + struct hi_mmc_drv *mmc_drv = host->private_data; + hal_mmc_clr_reg(mmc_drv, MSHC_RESET_CMD); + hal_mmc_clr_reg(mmc_drv, MSHC_RESET_DATA); +} + + +void init_emmc_pinmux(void) +{ + int n; + + for (n = 0; n < EMMC_PINMUX_NUM; n++) { + writew(S_HGPIO + S_HGPIO6_OFFSET + n * 0x4, FUNC_EMMC); + } + + for (n = 0; n < EMMC_PAD_PINMUX_NUM; n++) { + writew(S_HGPIO_PAD + S_HGPIO6_PAD_OFFSET + n * 0x4, IE_PINMUX_EN); + } + + // 配置EMMC时钟源为32M + writew(SDIOM_CR_REG, SDIOM_CR_CTRL_XO_32M_CLK_EN); +} + +int ssb_emmc_init(void) +{ + g_mmc = (struct rt_mmcsd_host *)irmalloc(sizeof(struct rt_mmcsd_host)); + if (g_mmc == NULL) { + LOG_E("malloc failed, check\r\n"); + return -1; // -1 system error + } + memset_s(g_mmc, sizeof(struct rt_mmcsd_host), 0, sizeof(struct rt_mmcsd_host)); + g_mmc->id = 0; // 0 -- MMC0 + g_mmc->flags |= MMCSD_NON_OS_ENABLE; + g_mmc->flags |= MMCSD_BUSWIDTH_8; + writew(EMMC_BASE_ADDR + 0x508, 0); + init_emmc_pinmux(); + int ret = hi_mmc_init(g_mmc); + PRINT("emmc init ret=%d\r\n", ret); + PRINT("emmc msg:blksize=%d,card capacity=%dKB,earse size=%d\n", g_mmc->card->card_blksize, + g_mmc->card->card_capacity, g_mmc->card->erase_size); + return ret; +} + +struct rt_mmcsd_host* get_ssb_emmc(void) +{ + return g_mmc; +} + +int32_t ssb_emmc_read(const char *buffer, uint32_t start_sector, uint32_t nsectors) +{ + return hi_mmc_read(buffer, start_sector, nsectors); +} + +int32_t ssb_emmc_write(const char *buffer, uint32_t start_sector, uint32_t nsectors) +{ + return hi_mmc_write(buffer, start_sector, nsectors); +} + +int32_t ssb_emmc_erase(uint32_t start_sector, uint32_t nsectors) +{ + return hi_mmc_erase(start_sector, nsectors, ERASE_TYPE_ERASE_GROUP); +} \ No newline at end of file diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/drv_mmc_adapter.h b/code/sdk/bootloader/flashboot/brandy/emmc/drv_mmc_adapter.h new file mode 100644 index 000000000..683b736b8 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/drv_mmc_adapter.h @@ -0,0 +1,143 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: DRV MMC DRIVER HEADER FILE + * Author: + * Create: 2020-04 + */ +#ifndef DRV_MMC_ADAPTER_H +#define DRV_MMC_ADAPTER_H + +#include "mmcsd_host.h" +#include "mmcsd_card.h" +#include "hal_mmc_common.h" +/* + * Card Command Classes (CCC) + */ +#define CCC_BASIC (1 << 0) +#define CCC_BLOCK_READ (1 << 2) +#define CCC_BLOCK_WRITE (1 << 4) +#define CCC_ERASE (1 << 5) +#define CCC_WRITE_PROT (1 << 6) +#define CCC_LOCK_CARD (1 << 7) +#define CCC_APP_SPEC (1 << 8) +#define CCC_IO_MODE (1 << 9) +#define CCC_SWITCH (1 << 10) +#define MMC_CMD_DATA_REQ_TIMEOUT (1000 * 10) // 30s +#define MMC_CMD_REQ_TIMEOUT (1000 * 3) // 3s +#define MMC_TUNINT_REQ_TIMEOUT (1000 / 5) // 200ms + +#define is_sd_cmd23_support(card) ((card)->scr.cmds & SD_SCR_CMD23_SUPPORT) +#define is_mmc_cmd23_support(card) \ + (((card)->csd.card_cmd_class & CCC_BLOCK_READ) || ((card)->csd.card_cmd_class & CCC_BLOCK_WRITE)) +#define CART_PLUG_STATE (MSHC_INT_CARD_INSERT | MSHC_INT_CARD_REMOVE) +#define CONFIG_ERASE_MAX_SECTOR 0x100000 // 512M +#define ADMA2_TRANS_END 0x2 +#define NON_OS_WAIT_INT_PER_MSEC 1 +#define WAIT_RSP_PER_USEC 1 +#define NON_OS_WAIT_SUM_TIMES 1000000 +#define MMC_ERASE_CMD_RETRIES_TIMES 5 +#define MMC_ERASE_MAX_TIME_MS 6000 +#define ADMA_EVERY_ITEM_LEN 4 +#define MMC_HOST_MAX_BLKS 65535 +#define MMC_RCA_OFFSET_VAL 16 +#define EMMC_DMA_ALIGN 4 + +#ifndef LOSCFG_LIB_LIBC +#define ENODMAALIGN 1 +#define ENOCACHEALIGN 2 +#define EPARAMERR 3 +#define EIO 5 +#define ENOMEM 12 +#define EACCES 13 +#define EBUSY 16 +#define ETIME 62 +#define EOPNOTSUPP 95 /* Operation not supported on socket */ + +#endif + +#define DATA_CMD_AUTO_STOP (0x1 << 6) // for struct rt_mmcsd_data.flags + +typedef enum { + MMC_ERASE_TYPE_ERASE = 0x0, + MMC_ERASE_TYPE_TRIM = 0x1, + MMC_ERASE_TYPE_DISCARD = 0x3, + MMC_ERASE_TYPE_MAX +} mmc_erase_type_t; + +typedef struct { + uint8_t magic; + uint8_t mmc_cmd_code; + uint16_t mmc_err_int_stat; + uint32_t mmc_present_stat; + int32_t mmc_cmd_err; + int32_t mmc_cmd_data_err; + uint32_t mmc_cmd_resp[4]; +} mmc_err_info_type_t; + +typedef enum { + EMMC_NORMAL_MAGIC_VAL = 0xAC, + EMMC_ERROR_MAGIC_VAL = 0xDE, +} mmc_err_flag_t; + +int test_emmc_init(void); +struct rt_mmcsd_host* get_ssb_emmc(void); +int32_t ssb_emmc_read(const char *buffer, uint32_t start_sector, uint32_t nsectors); +int32_t ssb_emmc_write(const char *buffer, uint32_t start_sector, uint32_t nsectors); +int32_t ssb_emmc_erase(uint32_t start_sector, uint32_t nsectors); + +struct rt_mmcsd_host *hi_mmc_get_host(uint32_t id); + +int hi_mmc_exec_tuning(struct rt_mmcsd_host *mmc, uint32_t opcode); + +void hi_mmc_set_timing(struct rt_mmcsd_host *mmc, int timing); + +uint32_t hi_mmc_write(const void *buffer, uint32_t pos, uint32_t size); + +uint32_t hi_mmc_read(void *buffer, uint32_t pos, uint32_t size); + +uint32_t hi_mmc_pio_write(const void *buffer, uint32_t pos, uint32_t size); + +uint32_t hi_mmc_pio_read(void *buffer, uint32_t pos, uint32_t size); + +int hi_mmc_card_busy(struct rt_mmcsd_host *mmc); + +void hi_mmc_handle_non_os_xfer(struct rt_mmcsd_host *mmc, struct rt_mmcsd_req *req); + +void hi_mmc_set_clock(struct rt_mmcsd_host *mmc, unsigned int clocknum); + +void hi_mmc_set_os_interrupt(struct rt_mmcsd_host *mmc, bool en); + +void hi_mmc_set_interrup_status(bool en); + +void mmc_set_bus_width(void); + +void hi_mmc_set_bus_width(struct rt_mmcsd_host *mmc, int width); + +int mmc_switch(struct rt_mmcsd_card *card, rt_uint8_t set, rt_uint8_t index, rt_uint8_t value); + +void mmc_set_sdiom_clk_mode(int clk_type); + +void hi_mmc_set_drv_features(struct hi_mmc_drv *mmc_drv, uint8_t id); + +int hi_mmc_set_int_info(struct rt_mmcsd_host *mmc, struct hi_mmc_drv *mmc_drv); + +void hi_mmc_set_host_features(struct rt_mmcsd_host *mmc); + +void hi_mmc_set_drv_bus_width_features(struct hi_mmc_drv *mmc_drv); + +void mmc_set_driver_capability(struct rt_mmcsd_host* mmc, uint32_t cap); + +bool mmc_detect_bus_error(struct rt_mmcsd_host* host); + +void hi_mmc_set_err_to_aon_area(void); + +void hi_mmc_reset_cmd_data(struct rt_mmcsd_host* host); + +uint32_t hi_mmc_get_present_state(struct rt_mmcsd_host *host); + +int hi_mmc_send_stop_cmd(struct rt_mmcsd_host *mmc, uint32_t *status); + +mmc_err_info_type_t *hi_mmc_get_err_from_aon_area(void); + +void hi_mmc_set_magic_to_aon_area(void); +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/hal_mmc_common.c b/code/sdk/bootloader/flashboot/brandy/emmc/hal_mmc_common.c new file mode 100644 index 000000000..3d4cdd032 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/hal_mmc_common.c @@ -0,0 +1,605 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: HAL MMC DRIVER. + * Author: + * Create: 2020-04 + */ +#include "hal_mmc_common.h" +#include "mshc_reg.h" +#include "tcxo.h" +#include "hal_pmu_peripheral_application.h" +#include "non_os.h" +#include "clocks_core.h" +#include "platform_core.h" + +#define SDIOM_SRC_CLK_LOW_FREQ_VAL 32000000 // 32MHz +#define SDIOM_SRC_CLK_FREQ_LEVEL_50M_VAL 50000000 // 50MHz +#define SDIOM_SRC_CLK_FREQ_LEVEL_64M_VAL 64000000 // 64MHz +#define SDIOM_SRC_CLK_HIGH_FREQ_VAL 196000000 // 196MHz +#define SDIOM_WITH_SET_TM_AND_FIRST_FREQ_DIV 1 +#define SDIOM_WITHOUT_SET_TM_AND_SECOND_FREQ_DIV 2 + +hal_sdiom_clk_mode_t g_sdiom_clk_cfg[HAL_SDIOM_CLK_MODE_MAX_NUM] = { + { 0, 50000000, SD_HOST_CCLK_REG, 4 }, // sdio host clk 50MHz, emmc clk 50MHz 50000000 + { 1, 50000000, EMMC_CCLK_DIV_REG, 6 }, // sdio host clk 50MHz, emmc clk 32MHz 50000000 + { 0, 50000000, SD_HOST_CCLK_REG, 6 }, // sdio host clk 32MHz, emmc clk 50Mhz 50000000 + { 1, 32000000, EMMC_CCLK_DIV_REG, 1 }, // sdio host clk 50MHz, emmc clk 32MHz 50000000 +}; + +#if (SUPPORT_HI_EMMC_PHY == YES) +static void hi_mmc_set_phy_ioctl(struct hi_mmc_drv *mmc_drv) +{ + mmc_writel(mmc_drv, PHY_IOCTL_PUPD_VAL, MSHC_PHY_IOCTL_PUPD); + mmc_writel(mmc_drv, PHY_IOCTL_IOE_VAL, MSHC_PHY_IOCTL_IOE); +} + +void hi_mmc_set_phy_driver_capability(struct hi_mmc_drv *mmc_drv, uint32_t val) +{ + uint32_t ronsel = 0; + uint32_t ronsel2 = 0; + if (val & PHY_IOCTL_RONSEL_BIT0) { ronsel = PHY_IOCTL_RONSEL_BIT0_VAL_1; } + if (val & PHY_IOCTL_RONSEL_BIT1) { ronsel |= PHY_IOCTL_RONSEL_BIT1_VAL_1; } + if (val & PHY_IOCTL_RONSEL_BIT2) { ronsel2 = PHY_IOCTL_RONSEL_BIT2_VAL_1; } + + mmc_writel(mmc_drv, ronsel, MSHC_PHY_IOCTL_RONSEL_1_0); + mmc_writel(mmc_drv, ronsel2, MSHC_PHY_IOCTL_OD_RONSEL_2); +} + +static void hi_mmc_set_phy_invert_phase(struct hi_mmc_drv *mmc_drv) +{ + mmc_writel(mmc_drv, PHY_INV_CLK, DLY_CTL1); +} + +static void hi_mmc_set_phy_delay_by_measurement(struct hi_mmc_drv *mmc_drv) +{ + uint32_t val; + mmc_writel(mmc_drv, PHYINITCTRL_DISABLE, PHYINITCTRL); + mmc_writel(mmc_drv, PHY_SET_DLY_MEAS_EN, PHYCTRL2); + mmc_writel(mmc_drv, PHYINITCTRL_ENABLE, PHYINITCTRL); + while (mmc_readl(mmc_drv, PHYINITCTRL) & PHY_INIT_EN_MASK) {} + val = mmc_reg32_getbits(mmc_drv, DLY_CTL, PHY_DLY_CODE_R_POS, PHY_DLY_CODE_R_LEN); + // set the 1/4 T delay (meas val) to DLY_CLT1.dly1_code and DLY_CTL1.dly3.code + mmc_reg32_setbits(mmc_drv, DLY_CTL1, PHY_DLAY1_CODE_POS, PHY_DLAY1_CODE_LEN, val / 4); // 4 + mmc_reg32_setbits(mmc_drv, DLY_CTL1, PHY_DLAY3_CODE_POS, PHY_DLAY3_CODE_LEN, val / 4); // 4 + mmc_writel(mmc_drv, PHY_SET_DLY_MEAS_DIS, PHYCTRL2); +} +#endif + +uint32_t hal_mmc_get_cap1(struct hi_mmc_drv *mmc_drv) +{ + return mmc_readl(mmc_drv, MSHC_CAPABILITIES_1); +} + +uint32_t hal_mmc_get_cap2(struct hi_mmc_drv *mmc_drv) +{ + return mmc_readl(mmc_drv, MSHC_CAPABILITIES_2); +} + +void hal_mmc_enable_plug_irq(struct hi_mmc_drv* mmc_drv, uint32_t irq) +{ + mmc_writew(mmc_drv, irq & MSHC_NOR_INT_MASK, MSHC_NOR_INT_ENABLE); + mmc_writew(mmc_drv, (irq & MSHC_ERR_INT_MASK) >> MSHC_ERR_INT_OFFSET, MSHC_ERR_INT_ENABLE); + + mmc_writew(mmc_drv, irq & MSHC_NOR_INT_MASK, MSHC_NOR_SIGNAL_ENABLE); + mmc_writew(mmc_drv, (irq & MSHC_ERR_INT_MASK) >> MSHC_ERR_INT_OFFSET, MSHC_ERR_SIGNAL_ENABLE); +} + +void hal_mmc_set_sample_phase(struct hi_mmc_drv *mmc_drv, uint32_t phase) +{ + uint32_t fields; + fields = mmc_readl(mmc_drv, MSHC_AUTO_TUNING_STATUS); + fields &= ~MSHC_CENTER_PH_CODE_MASK; + fields |= (uint32_t)phase; + mmc_writel(mmc_drv, fields, MSHC_AUTO_TUNING_STATUS); +} + +static void hi_mmc_set_sdio_clk_in_cs(uint32_t fields, uint8_t div_num) +{ + uint16_t value; + + value = readw(fields); + value &= ~SDIO_EMMC_ORI_LOAD_DIV_EN; + writew(fields, value); + value &= SDIO_EMMC_DIV_NUM_MASK; + value |= (div_num << SDIO_EMMC_DIV_NUM_POST_SHIFT); + writew(fields, value); + value |= SDIO_EMMC_ORI_LOAD_DIV_EN; + writew(fields, value); + value |= SDIO_EMMC_ORI_DIV_EN; + writew(fields, value); + value |= SDIO_EMMC_CCLK_EN; + writew(fields, value); +} + +#if (USE_SDIOM_CLK_CONFIG_WAY == SDIOM_WITH_SET_TM_AND_FIRST_FREQ_DIV) +static void hal_mmc_adapte_clock(unsigned int cfg_clock, unsigned int *div_num, + unsigned int *tm_div_num, unsigned int *clock) +{ + if (cfg_clock >= MMC_FREQ_100M) { + *div_num = MMC_100M_DIV_NUM; + *tm_div_num = MMC_SRC_200M_TM_DIV_NUM; + *clock = MMC_FREQ_100M; + } else if (cfg_clock >= MMC_FREQ_50M) { + *div_num = MMC_50M_DIV_NUM; + *tm_div_num = MMC_SRC_200M_TM_DIV_NUM; + *clock = MMC_FREQ_50M; + } else if (cfg_clock >= MMC_FREQ_32M) { + *div_num = MMC_32M_DIV_NUM; + *tm_div_num = MMC_SRC_32M_TM_DIV_NUM; + *clock = MMC_FREQ_32M; + } else if (cfg_clock >= MMC_FREQ_16M) { + *div_num = MMC_16M_DIV_NUM; + *tm_div_num = MMC_SRC_32M_TM_DIV_NUM; + *clock = MMC_FREQ_16M; + } else if (cfg_clock >= MMC_FREQ_400K) { + *div_num = MMC_400K_DIV_NUM; + *tm_div_num = MMC_SRC_32M_TM_DIV_NUM; + *clock = MMC_FREQ_400K; + } else if (cfg_clock >= MMC_FREQ_100K) { + *div_num = MMC_100K_DIV_NUM; + *tm_div_num = MMC_SRC_32M_TM_DIV_NUM; + *clock = MMC_FREQ_100K; + } else { + *div_num = MMC_32M_DIV_NUM; + *tm_div_num = MMC_SRC_32M_TM_DIV_NUM; + *clock = 0; + } +} + +unsigned int hi_mmc_set_clock_with_way1(struct hi_mmc_drv *mmc_drv, unsigned int cfg_clock) +{ + unsigned int div_num = 0; + unsigned int tm_div_num = 0; + unsigned int real_clock; + unsigned int clk_div[MAX_MMC_NUM] = {EMMC_CCLK_DIV_REG, SD_HOST_CCLK_REG}; + unsigned int sdio_tm_div = SDIO_TM_DIV_REG; + unsigned int sdio_emmc_reg; + system_sdio_freq_t sdiom_clk = CLOCKS_SDIO_FREQ_32M; + uint16_t value; + non_os_enter_critical(); + hal_mmc_adapte_clock(cfg_clock, &div_num, &tm_div_num, &real_clock); + if (cfg_clock > MMC_FREQ_32M) { sdiom_clk = CLOCKS_SDIO_FREQ_H; } // high freq is 193.3MHz in suxun chip. + sdio_emmc_reg = clk_div[mmc_drv->id]; // 0--emmc, 1--sdio host + value = readw(sdio_emmc_reg); + value &= ~SDIO_EMMC_CCLK_EN; + value &= ~SDIO_EMMC_ORI_DIV_EN; + writew(sdio_emmc_reg, value); + value = readw(sdio_tm_div); + value &= ~SDIO_TM_DIV_EN; + writew(sdio_tm_div, value); + // Sets the eMMC source clock. + clocks_set_sdio_freq(sdiom_clk); + // Sets emmc or sdio host frequency divider number. + hi_mmc_set_sdio_clk_in_cs(sdio_emmc_reg, (uint8_t)div_num); + // Sets sdio host and emmc TMCLK(about 1MHz). + value = readw(sdio_tm_div); + value &= ~SDIO_TM_DIV_LOAD_EN; + writew(sdio_tm_div, value); + value &= ~SDIO_TM_DIV_MASK; + value |= (uint16_t)(tm_div_num << SDIO_TM_DIV_NUM_POST_SHIFT); + writew(sdio_tm_div, value); + value |= SDIO_TM_DIV_LOAD_EN; + writew(sdio_tm_div, value); + value |= SDIO_TM_DIV_EN; + writew(sdio_tm_div, value); + non_os_exit_critical(); + PRINT("Clock cfg:%#x div:%#x %#x real_clock %d\n", cfg_clock, div_num, sdio_tm_div, real_clock); + return real_clock; +} + +#elif (USE_SDIOM_CLK_CONFIG_WAY == SDIOM_WITHOUT_SET_TM_AND_SECOND_FREQ_DIV) +static void hi_mmc_set_sd_bus_clk_div(uint32_t div_reg, uint32_t freq_div) +{ + uint16_t value; + value = readw(div_reg); + value &= ~SD_BUS_LOAD_DIV_EN; + writew(div_reg, value); + value &= ~SD_BUS_DIV_NUM_MASK; + value |= (uint16_t)(freq_div << SD_BUS_DIV_NUM_POST_SHIFT); + writew(div_reg, value); + value |= SD_BUS_LOAD_DIV_EN; + writew(div_reg, value); +} + +static void hi_mmc_set_second_level_clk_div(uint32_t div_reg, uint32_t freq_div) +{ + uint16_t value; + value = readw(div_reg); + value &= ~SDIO_EMMC_CCLK_EN; + value &= ~SDIO_EMMC_ORI_DIV_EN; + writew(div_reg, value); + if (div_reg == EMMC_DIV_REG) { + value &= ~EMMC_DIV_NUM_MASK; + value |= (uint16_t)(freq_div << SDIO_EMMC_DIV_NUM_POST_SHIFT); + } else { + value &= ~SDIO_DIV_NUM_MASK; + value |= (uint16_t)(freq_div << SDIO_DIV_NUM_POST_SHIFT); + } + writew(div_reg, value); + value |= EMMC_CCLK_LOAD_DIV_EN; + writew(div_reg, value); + value |= EMMC_EMMC_CCLK_EN; + writew(div_reg, value); +} + +static void hi_mmc_set_first_level_clk_div(uint32_t div_reg, uint32_t freq_div) +{ + uint16_t value; + value = readw(div_reg); + value &= ~SDIO_EMMC_CCLK_EN; + value &= ~SDIO_EMMC_ORI_DIV_EN; + writew(div_reg, value); + value &= ~SDIO_EMMC_DIV_NUM_MASK; + value |= (uint16_t)(freq_div << SDIO_EMMC_DIV_NUM_POST_SHIFT); + writew(div_reg, value); + value |= EMMC_CCLK_LOAD_DIV_EN; + writew(div_reg, value); + value |= EMMC_EMMC_CCLK_EN; + writew(div_reg, value); + value |= BIT(14); // 14 + writew(div_reg, value); +} + +static void hi_mmc_set_sdiom_src_clk(uint32_t cfg_clock, uint32_t *freq_div, uint32_t *clk_level) +{ + system_sdio_freq_t sdiom_freq_level; + if (cfg_clock <= SDIOM_SRC_CLK_LOW_FREQ_VAL) { + sdiom_freq_level = CLOCKS_SDIO_FREQ_32M; + *clk_level = SDIOM_SRC_CLK_LOW_FREQ_VAL; + *freq_div = SDIOM_SRC_CLK_LOW_FREQ_VAL / cfg_clock; + if (SDIOM_SRC_CLK_LOW_FREQ_VAL % cfg_clock != 0) { *freq_div += 1; } + } else if (cfg_clock == SDIOM_SRC_CLK_FREQ_LEVEL_50M_VAL) { + sdiom_freq_level = CLOCKS_SDIO_FREQ_50M; + *clk_level = SDIOM_SRC_CLK_FREQ_LEVEL_50M_VAL; + *freq_div = 1; + } else if (cfg_clock == SDIOM_SRC_CLK_FREQ_LEVEL_64M_VAL) { + sdiom_freq_level = CLOCKS_SDIO_FREQ_64M; + *clk_level = SDIOM_SRC_CLK_FREQ_LEVEL_64M_VAL; + *freq_div = 1; + } else if (cfg_clock <= SDIOM_SRC_CLK_HIGH_FREQ_VAL) { + sdiom_freq_level = CLOCKS_SDIO_FREQ_H; + *clk_level = SDIOM_SRC_CLK_HIGH_FREQ_VAL; + *freq_div = SDIOM_SRC_CLK_HIGH_FREQ_VAL / cfg_clock; + if (SDIOM_SRC_CLK_HIGH_FREQ_VAL % cfg_clock != 0) { *freq_div += 1; } + } else { + sdiom_freq_level = CLOCKS_SDIO_FREQ_32M; + *clk_level = SDIOM_SRC_CLK_FREQ_LEVEL_64M_VAL; + *freq_div = 1; + } +} + +unsigned int hi_mmc_set_clock_with_way2(struct hi_mmc_drv *mmc_drv, unsigned int cfg_clock) +{ + uint32_t clock_level; + uint32_t first_freq_div = 0; + uint32_t freq_div = 0; + uint32_t second_freq_div = 0; + uint32_t sec_freq_div = 1; // Reserved for future expansion + + if (mmc_drv == NULL || mmc_drv->id >= MAX_MMC_NUM) { + return 0; + } + + hi_mmc_set_sdiom_src_clk(cfg_clock, &freq_div, &clock_level); + + if (mmc_drv->id == SDIO_EMMC_ID) { + first_freq_div = EMMC_CCLK_DIV_REG; + second_freq_div = EMMC_DIV_REG; + } else { + first_freq_div = SD_HOST_CCLK_REG; + second_freq_div = SDIO_DIV_REG; + } + hi_mmc_set_first_level_clk_div(first_freq_div, freq_div); + hi_mmc_set_second_level_clk_div(second_freq_div, sec_freq_div); + return (clock_level / freq_div); +} + +bool hi_mmc_set_clock_switch(uint32_t fisrt_div, uint32_t second_div, uint32_t sd_bus_div) +{ + hi_mmc_set_first_level_clk_div(EMMC_CCLK_DIV_REG, fisrt_div); // 198M 4div 49M + hi_mmc_set_second_level_clk_div(EMMC_DIV_REG, second_div); // 1div 49M + hi_mmc_set_sd_bus_clk_div(SDIO_DIV_REG, sd_bus_div); // sdbus 1div, 196M + return true; +} +#endif + +static unsigned int hal_mmc_set_soc_clock(struct hi_mmc_drv *mmc_drv, unsigned int cfg_clock) +{ + UNUSED(mmc_drv); + UNUSED(cfg_clock); +#if (USE_SDIOM_CLK_CONFIG_WAY == SDIOM_WITH_SET_TM_AND_FIRST_FREQ_DIV) + return hi_mmc_set_clock_with_way1(mmc_drv, cfg_clock); +#elif (USE_SDIOM_CLK_CONFIG_WAY == SDIOM_WITHOUT_SET_TM_AND_SECOND_FREQ_DIV) + return hi_mmc_set_clock_with_way2(mmc_drv, cfg_clock); +#else + return 0; // for the further extending +#endif +} /*lint +e550 +e574*/ + +void hal_mmc_set_card_clk(struct hi_mmc_drv *mmc_drv, bool en) +{ + uint16_t clk; + non_os_enter_critical(); + clk = mmc_readw(mmc_drv, MSHC_CLOCK_CONTROL); + if (en) { + clk |= MSHC_CLOCK_CARD_EN; + } else { + clk &= ~MSHC_CLOCK_CARD_EN; + } + mmc_writew(mmc_drv, clk, MSHC_CLOCK_CONTROL); + non_os_exit_critical(); +} + +void hal_mmc_set_clock(struct hi_mmc_drv *mmc_drv, unsigned int clocknum) +{ + unsigned short clk; + unsigned long timeout_val; + unsigned int ret; + + non_os_enter_critical(); + // turn off clk2card_on + clk = mmc_readw(mmc_drv, MSHC_CLOCK_CONTROL); + clk &= ~(MSHC_CLOCK_CARD_EN); + mmc_writew(mmc_drv, clk, MSHC_CLOCK_CONTROL); + + // turn off card_clk_en + clk &= ~(MSHC_CLOCK_INT_EN | MSHC_CLOCK_PLL_EN); + mmc_writew(mmc_drv, clk, MSHC_CLOCK_CONTROL); + + if (clocknum == 0) { + non_os_exit_critical(); + return; + } + if (clocknum >= mmc_drv->freq_max) { + clocknum = mmc_drv->freq_max; + } + + ret = hal_mmc_set_soc_clock(mmc_drv, clocknum); + if (!ret) { + LOG_E("Set clock fail!\n"); + non_os_exit_critical(); + return; + } + mmc_drv->clock = ret; + // turn on card_clk_en + clk |= MSHC_CLOCK_INT_EN | MSHC_CLOCK_PLL_EN; + mmc_writew(mmc_drv, clk, MSHC_CLOCK_CONTROL); + + timeout_val = 20; // max wait clock stable 20ms + while (timeout_val) { + clk = mmc_readw(mmc_drv, MSHC_CLOCK_CONTROL); + if (clk & (unsigned short)MSHC_CLOCK_INT_STABLE) { break; } + if (timeout_val == 1) { + LOG_E("Internal clock never stabilized.\n"); + non_os_exit_critical(); + return; + } + timeout_val--; + uapi_tcxo_delay_ms((uint64_t)1); + } + + // turn on clk2card_on + clk |= MSHC_CLOCK_CARD_EN; + mmc_writew(mmc_drv, clk, MSHC_CLOCK_CONTROL); + non_os_exit_critical(); +} + +void hal_mmc_clr_reg(struct hi_mmc_drv *mmc_drv, unsigned int mask) +{ + unsigned long timeout_val; + + mmc_writeb(mmc_drv, (uint8_t)mask, MSHC_SOFTWARE_RESET); + if (mask & MSHC_RESET_ALL) { + mmc_drv->clock = 0; + } + + timeout_val = 100; // timeout 100ms + + /* hw clears the bit when it's done */ + while (mmc_readb(mmc_drv, MSHC_SOFTWARE_RESET) & mask) { + if (timeout_val == 0) { + LOG_E("host%d: Reset 0x%x never completed.\n", + mmc_drv->id, (int)mask); + hi_mmc_dumpregs(mmc_drv); + return; + } + timeout_val--; + uapi_tcxo_delay_ms((uint64_t)1); + } + + if (mask & MSHC_RESET_ALL) { mmc_drv->preset_enabled = false; } +} + +void hal_mmc_deassert_status(struct hi_mmc_drv *mmc_drv) +{ + unsigned int value; + non_os_enter_critical(); + pmu_sdio_glb_common_reset(true); + if (mmc_drv->id == SDIO_EMMC_ID) { + hal_pmu_mcpu_perip_reset(HAL_PMU_MCPU_PERIP_EMMC, HAL_PMU_PERIP_REQUEST_RESET); + hal_pmu_mcpu_perip_reset(HAL_PMU_MCPU_PERIP_EMMC, HAL_PMU_PERIP_REQUEST_DERESET); + } else { + hal_pmu_mcpu_perip_reset(HAL_PMU_MCPU_PERIP_SDIO_HOST, HAL_PMU_PERIP_REQUEST_RESET); + hal_pmu_mcpu_perip_reset(HAL_PMU_MCPU_PERIP_SDIO_HOST, HAL_PMU_PERIP_REQUEST_DERESET); + } + non_os_exit_critical(); + // open the clk of card: + value = mmc_readl(mmc_drv, MSHC_CLK_CTRL); + value |= MSHC_CLK_CTRL_INT_CLK; + mmc_writel(mmc_drv, value, MSHC_CLK_CTRL); + + /* clock config with 400khz */ + (void)hal_mmc_set_clock(mmc_drv, MMC_FREQ_400K); +#if (SUPPORT_HI_EMMC_PHY == YES) + if (mmc_drv->id == SDIO_EMMC_ID) { + hi_mmc_set_phy_ioctl(mmc_drv); // config emmc PHY mode + hi_mmc_set_phy_driver_capability(mmc_drv, mmc_drv->phy_driver_cap); + hi_mmc_set_phy_invert_phase(mmc_drv); + hi_mmc_set_phy_delay_by_measurement(mmc_drv); + } +#endif +} + +static void hal_mmc_set_uhs_signal(struct hi_mmc_drv *mmc_drv, enum mmc_bus_timing timing) +{ + unsigned short ctrl_2; + + ctrl_2 = mmc_readw(mmc_drv, MSHC_HOST_CONTROL2); + + /* Select Bus Speed Mode for host */ + ctrl_2 &= ~MSHC_CTRL_UHS_MASK; + if ((timing == TIMING_UHS_SDR104) || (timing == TIMING_MMC_HS200)) { + ctrl_2 |= MSHC_CTRL_UHS_SDR104; + } else if (timing == TIMING_UHS_SDR12) { + ctrl_2 |= MSHC_CTRL_UHS_SDR12; + } else if ((timing == TIMING_UHS_SDR25) || (timing == TIMING_MMC_HS)) { + ctrl_2 |= MSHC_CTRL_UHS_SDR25; + } else if (timing == TIMING_UHS_SDR50) { + ctrl_2 |= MSHC_CTRL_UHS_SDR50; + } else if ((timing == TIMING_UHS_DDR50) || (timing == TIMING_UHS_DDR52)) { + ctrl_2 |= MSHC_CTRL_UHS_DDR50; + } else if (timing == TIMING_MMC_HS400) { + ctrl_2 |= MSHC_CTRL_HS400; + } + ctrl_2 |= MSHC_CTRL_VDD_180; + mmc_writew(mmc_drv, ctrl_2, MSHC_HOST_CONTROL2); +} + +void hal_mmc_set_preset_val(struct hi_mmc_drv *mmc_drv, bool en) +{ + unsigned short ctrl_val = 0; + if (mmc_drv->version < MSHC_SPEC_300) { return; } + + if (mmc_drv->preset_enabled != (uint32_t)en) { + ctrl_val = mmc_readw(mmc_drv, MSHC_HOST_CONTROL2); + if (en) { + ctrl_val |= MSHC_CTRL_PRESET_VAL_ENABLE; + } else { + ctrl_val &= ~MSHC_CTRL_PRESET_VAL_ENABLE; + } + + mmc_writew(mmc_drv, ctrl_val, MSHC_HOST_CONTROL2); + mmc_drv->preset_enabled = en; + } +} + +void hal_mmc_set_timing(struct hi_mmc_drv *mmc_drv, int timing) +{ + unsigned short clockval = 0; + unsigned short ctrl_2 = 0; + uint8_t ctrl; + + ctrl = mmc_readb(mmc_drv, MSHC_HOST_CONTROL); + + if (timing >= TIMING_MMC_HS) { + ctrl |= MSHC_CTRL_HISPD; + } + if (mmc_drv->version < MSHC_SPEC_300) { + mmc_writeb(mmc_drv, ctrl, MSHC_HOST_CONTROL); + return; + } + if (!mmc_drv->preset_enabled) { + mmc_writeb(mmc_drv, ctrl, MSHC_HOST_CONTROL); + ctrl_2 = mmc_readw(mmc_drv, MSHC_HOST_CONTROL2); + ctrl_2 &= ~MSHC_CTRL_DRV_TYPE_MASK; + + mmc_writew(mmc_drv, ctrl_2, MSHC_HOST_CONTROL2); + } else { + clockval = mmc_readw(mmc_drv, MSHC_CLOCK_CONTROL); + clockval &= ~MSHC_CLOCK_CARD_EN; + mmc_writew(mmc_drv, clockval, MSHC_CLOCK_CONTROL); + + mmc_writeb(mmc_drv, ctrl, MSHC_HOST_CONTROL); + hal_mmc_set_clock(mmc_drv, mmc_drv->clock); + } + clockval = mmc_readw(mmc_drv, MSHC_CLOCK_CONTROL); + clockval &= ~MSHC_CLOCK_CARD_EN; + mmc_writew(mmc_drv, clockval, MSHC_CLOCK_CONTROL); + + hal_mmc_set_uhs_signal(mmc_drv, (enum mmc_bus_timing)timing); + mmc_drv->timing = (uint32_t)timing; + if (mmc_drv->preset_enabled) { + hal_mmc_set_preset_val(mmc_drv, true); + } + hal_mmc_set_clock(mmc_drv, mmc_drv->clock); +} + +void hal_mmc_adma_config(struct hi_mmc_drv *mmc_drv) +{ + mmc_writel(mmc_drv, (uintptr_t)mmc_drv->adma_desc, MSHC_ADMA_ADDRESS_LOW); +} + +void hal_mmc_set_sdiom_clk_mode(struct hi_mmc_drv** drv, int mode) +{ + int id = g_sdiom_clk_cfg[mode].id; + uint32_t clock = g_sdiom_clk_cfg[mode].clock; + uint32_t fields = g_sdiom_clk_cfg[mode].amend_div_reg; + uint32_t div_num = g_sdiom_clk_cfg[mode].amend_div_num; + non_os_enter_critical(); + hal_mmc_set_clock(drv[id], clock); + hi_mmc_set_sdio_clk_in_cs(fields, (uint8_t)div_num); + non_os_exit_critical(); +} + +void hal_mmc_set_emmc_ctrl(struct hi_mmc_drv *mmc_drv, uint32_t offset, uint32_t pos, uint32_t bits, uint32_t val) +{ + reg_setbits(mmc_drv->hw_base_addr, offset, pos, bits, val); +} + +void hal_mmc_set_clk_en(hal_mmc_bus_num_t mmc_bus, bool en) +{ + if (mmc_bus >= MAX_MMC_NUM) { return; } + + uint32_t clk_reg[MAX_MMC_NUM] = { EMMC_CCLK_DIV_REG, SD_HOST_CCLK_REG }; + uint32_t reg_addr = clk_reg[mmc_bus]; + non_os_enter_critical(); + if (en) { + reg16_setbit((void *)((uintptr_t)reg_addr), SDIO_EMMC_CCLK_EN_POS); + } else { + reg16_clrbit((void *)((uintptr_t)reg_addr), SDIO_EMMC_CCLK_EN_POS); + } + non_os_exit_critical(); +} + +void hi_mmc_dumpregs(struct hi_mmc_drv *mmc_drv) +{ + LOG_E(": =========== DUMP (host%d) REGISTER===========\n", mmc_drv->id); + + LOG_E(": Sys addr[00]: 0x%08x | Version[FE]: 0x%04x\n", mmc_readl(mmc_drv, MSHC_DMA_ADDRESS), + mmc_readw(mmc_drv, MSHC_HOST_VERSION)); + LOG_E(": Blk size[04]: 0x%04x | Blk cnt[06]: 0x%04x\n", mmc_readw(mmc_drv, MSHC_BLOCK_SIZE), + mmc_readw(mmc_drv, MSHC_BLOCK_COUNT)); + LOG_E(": Argument[08]: 0x%08x | Trn mode[0C]: 0x%04x\n", mmc_readl(mmc_drv, MSHC_ARGUMENT), + mmc_readw(mmc_drv, MSHC_TRANSFER_MODE)); + LOG_E(": Present[24]: 0x%08x | Host ctl[28]: 0x%02x\n", mmc_readl(mmc_drv, MSHC_PRESENT_STATE), + mmc_readb(mmc_drv, MSHC_HOST_CONTROL)); + LOG_E(": Power[29]: 0x%02x | Blk gap[2A]: 0x%02x\n", mmc_readb(mmc_drv, MSHC_POWER_CONTROL), + mmc_readb(mmc_drv, MSHC_BLOCK_GAP_CONTROL)); + LOG_E(": Wake-up[2B]: 0x%02x | Clock[2C]: 0x%04x\n", mmc_readb(mmc_drv, MSHC_WAKE_UP_CONTROL), + mmc_readw(mmc_drv, MSHC_CLOCK_CONTROL)); + LOG_E(": Timeout[2E]: 0x%08x | Int stat[30]: 0x%08x\n", mmc_readb(mmc_drv, MSHC_TIMEOUT_CONTROL), + ((mmc_readw(mmc_drv, MSHC_ERR_INT_STATUS) << MSHC_ERR_INT_OFFSET) | + mmc_readw(mmc_drv, MSHC_NOR_INT_STATUS))); + LOG_E(": Int enab[34]: 0x%08x | Sig enab[38]: 0x%08x\n", + ((mmc_readw(mmc_drv, MSHC_ERR_INT_ENABLE) << MSHC_ERR_INT_OFFSET) | + mmc_readw(mmc_drv, MSHC_NOR_INT_ENABLE)), + ((mmc_readw(mmc_drv, MSHC_ERR_SIGNAL_ENABLE) << MSHC_ERR_INT_OFFSET) | + mmc_readw(mmc_drv, MSHC_NOR_SIGNAL_ENABLE))); + LOG_E(": ACMD err[3C]: 0x%04x | Slot int[FC]: 0x%04x\n", mmc_readw(mmc_drv, MSHC_AUTO_CMD_ERR), + mmc_readw(mmc_drv, MSHC_SLOT_INT_STATUS)); + LOG_E(": Caps_1[40]: 0x%08x | Caps_2][44]: 0x%08x\n", mmc_readl(mmc_drv, MSHC_CAPABILITIES_1), + mmc_readl(mmc_drv, MSHC_CAPABILITIES_2)); + LOG_E(": Cmd[0E]: 0x%04x | Max curr[48]: 0x%08x | opcode = %d\n", + mmc_readw(mmc_drv, MSHC_COMMAND), mmc_readl(mmc_drv, MSHC_MAX_CURRENT), + (mmc_readw(mmc_drv, MSHC_COMMAND) >> 8) & 0x3f); // 8 0x3f for get opcode what is bit13--bit8 + LOG_E(": Resp:0x%08x 0x%08x 0x%08x 0x%08x\n", + mmc_readl(mmc_drv, MSHC_RESPONSE), mmc_readl(mmc_drv, MSHC_RESPONSE + 0x4), + mmc_readl(mmc_drv, MSHC_RESPONSE + 0x8), mmc_readl(mmc_drv, MSHC_RESPONSE + 0xC)); + LOG_E(": Host ctl2[3E]: 0x%04x\n", mmc_readw(mmc_drv, MSHC_HOST_CONTROL2)); + LOG_E(": Emmc ctrl[52C]: 0x%04x\n", mmc_readw(mmc_drv, MSHC_EMMC_CTRL)); + if (mmc_drv->flags & MMC_FLAG_USE_ADMA) { + LOG_E(": ADMA Err[54]: 0x%02x | ADMA Ptr[58]: 0x%08x\n", mmc_readb(mmc_drv, MSHC_ADMA_ERROR), + mmc_readl(mmc_drv, MSHC_ADMA_ADDRESS_LOW)); + } + LOG_E(": ===========================================\n"); +} diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/hal_mmc_common.h b/code/sdk/bootloader/flashboot/brandy/emmc/hal_mmc_common.h new file mode 100644 index 000000000..c73c6c9e5 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/hal_mmc_common.h @@ -0,0 +1,426 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: HAL MMC COMMON DRIVER HEADER FILE + * Author: + * Create: 2020-04 + */ +#ifndef HAL_MMC_COMMON_H +#define HAL_MMC_COMMON_H + +#include "mmcsd_host.h" +#include "chip_io.h" +#include "platform_core.h" + +#define MMC_ADMA_MAX_DESC 8 +#define MMC_AMDA_32BIT_DESC_LINE_SIZE 8 +#define CACHE_ALIGNED_SIZE 64 +#define MAX_BLOCK_SIZE 512 +#define MAX_BLOCK_COUNT 4096 +#define MAX_SEG_SIZE 65536 +#define OFF_CLK2CARD_ON_DELAY 25 +#define SDIO_REG_CCCR_IO_ABORT 0x06 /* function abort/card reset */ + +#define CONFIG_MMC0_CCLK_MIN 400000 // 400KHz +#define CONFIG_MMC1_CCLK_MIN 100000 // 100KHz + +// sdio host & mmc base addr +#define SDIO_HOST_BASE_ADDR 0x52061000 // SDIO HOST base address +#define SDIO_EMMC_BASE_ADDR 0x52062000 // SDIO EMMC base address + +// clock config +#define M_CTL_RB_BASE_ADDR 0x52000000 + +#define SDIO_32M_CLKDIV_NUM_MASK 0x7F +#define SDIO_32M_CLKDIV_NUM_SHIFT 2 +#define SDIO_32M_DIV_EN BIT(1) +#define SDIO_32M_CLKSEL BIT(0) + +#define SDIO_CLKDIV_NUM_MASK 0xF +#define SDIO_CLKDIV_NUM_POST_SHIFT 6 +#define SDIO_CLKDIV_NUM_PRE_SHIFT 1 +#define SDIO_CLKDIV_SEL_SOC BIT(10) +#define SDIO_CLKDIV_POST_ENABLE BIT(5) +#define SDIO_CLKDIV_PRE_ENABLE BIT(0) +#define SDIO_CLKDIV_NUM_MAX 4 + +// emmc/sdio host clock crg in suxun CS +#define GLB_CLKEN_REG (M_CTL_RB_BASE_ADDR + 0x0548) +#if CHIP == TARGET_CHIP_SUSONG +#define SDIOM_CR_CLK_REG (M_CTL_RB_BASE_ADDR + 0x0568) +#else +#define SDIOM_CR_CLK_REG (M_CTL_RB_BASE_ADDR + 0x0564) +#endif +#define EMMC_CCLK_DIV_REG (M_CTL_RB_BASE_ADDR + 0x0100) +#define EMMC_DIV_REG (M_CTL_RB_BASE_ADDR + 0x0120) +#define SDIO_DIV_REG (M_CTL_RB_BASE_ADDR + 0x0124) +#define SD_HOST_CCLK_REG (M_CTL_RB_BASE_ADDR + 0x0110) +#define SDIO_CRG_HOST_100M_REG (M_CTL_RB_BASE_ADDR + 0x120) +#define SDIO_TM_DIV_REG (M_CTL_RB_BASE_ADDR + 0x0124) +#define SDIO_CRG_EMMC_32M_REG (M_CTL_RB_BASE_ADDR + 0x128) +#define SDIO_CRG_HOST_32M_REG (M_CTL_RB_BASE_ADDR + 0x124) +#define SDIO_CRG_EMMC_100M_REG (M_CTL_RB_BASE_ADDR + 0x12C) + +#define SDIO_EMMC_CCLK_EN BIT(0) +#define SDIO_EMMC_CCLK_EN_POS 0 +#define SDIO_EMMC_ORI_DIV_EN BIT(1) +#define SDIO_EMMC_ORI_LOAD_DIV_EN BIT(2) +#define SDIO_DIV_NUM_MASK 0xF8 // bit3---bit7 +#define EMMC_DIV_NUM_MASK 0x70 // bit4---bit6 +#define SDIO_DIV_NUM_POST_SHIFT 3 +#define EMMC_CCLK_DIV_NUM_MASK 0x70 +#define EMMC_CCLK_LOAD_DIV_EN BIT(1) +#define EMMC_EMMC_CCLK_EN BIT(0) +#define SDIO_EMMC_DIV_NUM_POST_SHIFT 4 +#define SDIO_TM_DIV_EN BIT(0) +#define SDIO_TM_DIV_LOAD_EN BIT(1) +#define SDIO_TM_DIV_MASK 0x1FF0 +#define SDIO_TM_DIV_NUM_POST_SHIFT 4 +#define GLB_CLKEN_SDIOM_EN BIT(4) +#define SDIOM_CR_EN BIT(0) +#define SDIOM_CR_CLK_SEL_32M 0x2 +#define SDIOM_CR_CLK_SEL_400M 0x4 +#define SDIOM_CR_CLK_SEL_POST_SHIFT 1 +#define SDIOM_CR_CLK_MASK 0xF + +#define SDIO_LGC_EN_CS BIT(1) +#define SDIO_CRG_EN_CS BIT(0) +#define SDIO_HOST_RESET_EMMC_CS BIT(0) +#define SDIO_HOST_RESET_SDIO_CS BIT(1) + +#define SD_BUS_LOAD_DIV_EN BIT(8) +#define SD_BUS_DIV_NUM_MASK 0xF8 // bit3---bit7 +#define SD_BUS_DIV_NUM_POST_SHIFT 3 +#define SD_EMMC_CCLK_DIV_4 4 +#define SD_BUS_DIV_1 1 +#define SD_BUS_DIV_2 2 +#define SD_BUS_PVSA1 0xE8 +#define SD_BUS_PVSA1_POS 0 +#define SD_BUS_PVSA1_LEN 12 +#define SD_BUS_MBURST_POS 0 +#define SD_BUS_MBURST_LEN 4 +#define SD_BUS_MBURST_VAL 8 + +#define MMC_100M_DIV_NUM 2 // clock source is 193.3MHz +#define MMC_50M_DIV_NUM 4 // clock source is 193.3MHz + +// When the clock is less than 32 MHz, the clock source is TCXO(32MHz). +#define MMC_32M_DIV_NUM 1 +#define MMC_16M_DIV_NUM 2 +#define MMC_400K_DIV_NUM 80 +#define MMC_100K_DIV_NUM 320 +#define MMC_SRC_32M_TM_DIV_NUM 32 +#define MMC_SRC_200M_TM_DIV_NUM 200 +#define MMC_FREQ_100K 100000 +#define MMC_FREQ_400K 400000 +#define MMC_FREQ_16M 16000000 // For FPGA Only +#define MMC_FREQ_32M 32000000 +#define MMC_FREQ_50M 50000000 +#define MMC_FREQ_100M 100000000 + +// reset config +#define MCPU_SOFT_RST (M_CTL_RB_BASE_ADDR + 0x0054) +#define SOFT_RST_MCU2DIS_H2H_N BIT(7) +#define SOFT_RST_MDMA_H2X_N BIT(6) +#define SOFT_RST_MEM_SUB_BUS_N BIT(5) +#define SOFT_RST_MDIAG_N BIT(4) +#define SOFT_RST_SEC_N BIT(3) +#define SOFT_RST_AUX_ADC_N BIT(2) +#define SOFT_RST_SDIO_BUS_N BIT(1) +#define SOFT_RST_IR_N BIT(0) + +#define SDIO_CRG_SOFT_RST (M_CTL_RB_BASE_ADDR + 0x0104) +#define SOFT_RST_DEVICE_SD_N BIT(7) +#define SOFT_RST_DEVICE_BUS_N BIT(6) +#define SOFT_RST_HOST_M_B_TM_N BIT(5) +#define SOFT_RST_HOST_H_N BIT(4) +#define SOFT_RST_HOST_TX_RX_N BIT(3) +#define SOFT_RST_EMMC_M_B_TM_N BIT(2) +#define SOFT_RST_EMMC_H_N BIT(1) +#define SOFT_RST_EMMC_TX_RX_N BIT(0) + +#define PMU_EMMC_POWER_ON 0xFFFF + +#define SDHCI_PLUG_STATE(h) (mmc_readl(h, MSHC_PRESENT_STATE) & MSHC_CARD_PRESENT) + +// sdio slave reg +#define HISDIO_REG_FUNC1_FIFO 0x00 /* Read Write FIFO */ +#define HISDIO_REG_FUNC1_INT_STATUS 0x08 /* interrupt mask and clear reg */ +#define HISDIO_REG_FUNC1_INT_ENABLE 0x09 /* interrupt */ +#define HISDIO_REG_FUNC1_XFER_COUNT 0x0c /* notify number of bytes to be read */ +#define HISDIO_REG_FUNC1_WRITE_MSG 0x24 /* write msg to device */ +#define HISDIO_REG_FUNC1_MSG_FROM_DEV 0x28 /* notify Host that device has got the msg */ +#define HISDIO_REG_FUNC1_MSG_HIGH_FROM_DEV 0x2b /* Host receive the msg ack */ +/* sdio extend function, add 64B register for hcc */ +#define HISDIO_FUNC1_EXTEND_REG_BASE 0x3c +#define HISDIO_FUNC1_EXTEND_REG_LEN 64 +#define HISDIO_FUNC1_INT_DREADY (1 << 0) /* data ready interrupt */ +#define HISDIO_FUNC1_INT_RERROR (1 << 1) /* data read error interrupt */ +#define HISDIO_FUNC1_INT_MFARM (1 << 2) /* ARM Msg interrupt */ +#define HISDIO_FUNC1_INT_ACK (1 << 3) /* ACK interrupt */ +#define HISDIO_FUNC1_INT_MASK (HISDIO_FUNC1_INT_DREADY | HISDIO_FUNC1_INT_RERROR | HISDIO_FUNC1_INT_MFARM) +#define HAL_SDIOM_CLK_MODE_MAX_NUM 4 + +#define BRANDY_INTERRUPT_SDIO 76 +#define BRANDY_INTERRUPT_EMMC 78 + +#define S_HGPIO 0x52065800 +#define S_HGPIO_PAD 0x5700d000 + +#define S_HGPIO0_OFFSET 0 +#define S_HGPIO0_PAD_OFFSET 0x200 + +#define S_HGPIO6_OFFSET 0x18 +#define S_HGPIO6_PAD_OFFSET 0x218 +#define FUNC_SDIO 0x01 +#define FUNC_EMMC 0x02 +#ifdef PRE_FPGA +#define IE_PINMUX_EN 0x02 +#else +#define IE_PINMUX_EN 0xC7 +#endif + +#define COM_CTL_RB_BASE 0x55000000 +#define SDIOM_CR_REG (COM_CTL_RB_BASE + 0x0628) +#define SDIOM_CR_CTRL_CH_ENABLE BIT(0) +#define SDIOM_CR_CTRL_DIV_EN BIT(4) + +#define SDIOM_CR_CTRL_DIV_OFFSET 5 +#define SDIOM_CR_CTRL_MIN_DIV 2 + +#define SDIOM_CR_CTRL_CLK_RESOURCE_RC 0 +#define SDIOM_CR_CTRL_CLK_RESOURCE_XO 1 +#define SDIOM_CR_CTRL_CLK_RESOURCE_XO_DLL2 2 +#define SDIOM_CR_CTRL_CLK_RESOURCE_PLL 3 + +#define SDIOM_CR_CTRL_CLK_RESOURCE_PLL_EN (SDIOM_CR_CTRL_CH_ENABLE | (SDIOM_CR_CTRL_CLK_RESOURCE_PLL << 1)) +#define SDIOM_CR_CTRL_XO_32M_CLK_EN (SDIOM_CR_CTRL_CH_ENABLE | (SDIOM_CR_CTRL_CLK_RESOURCE_XO << 1)) + +typedef enum { + SDIO_EMMC_ID, + SDIO_HOST_ID, + MAX_MMC_NUM +} hal_mmc_bus_num_t; + +typedef struct { + int id; + uint32_t clock; + uint32_t amend_div_reg; // Registers that need to be adjusted + uint32_t amend_div_num; // The frequency division coefficient of one side needs to be adjusted. +} hal_sdiom_clk_mode_t; + +enum dma_data_direction { + DMA_BIDIRECTIONAL = 0, + DMA_TO_DEVICE = 1, + DMA_FROM_DEVICE = 2, + DMA_NONE = 3, +}; + +enum hi_mmc_power_mode { + POWER_OFF = 0, + POWER_UP, + POWER_ON, +}; + +enum mmc_chip_select { + CS_DONTCARE = 0, + CS_HIGH, + CS_LOW, +}; + +enum hi_mmc_bus_width { + BUS_WIDTH_1 = 0, + BUS_WIDTH_4 = 2, + BUS_WIDTH_8 = 3, +}; + +enum hi_mmc_bus_mode { + MMC_BUSMODE_OPENDRAIN, + MMC_BUSMODE_PUSHPULL, +}; + +enum mmc_bus_timing { + TIMING_MMC_DS = 0, + TIMING_MMC_HS, + TIMING_SD_HS, + TIMING_UHS_SDR12, + TIMING_UHS_SDR25, + TIMING_UHS_SDR50, + TIMING_UHS_SDR104, + TIMING_UHS_DDR50, + TIMING_UHS_DDR52, + TIMING_MMC_HS200, /* for emmc */ + TIMING_MMC_HS400, /* for emmc */ +}; + +struct hi_mmc_drv { + struct rt_mmcsd_host *host; + struct rt_mmcsd_req *req; + struct rt_mmcsd_cmd *cmd; + struct rt_mmcsd_data *data; + + uint8_t id; + uint32_t hw_base_addr; + uint32_t msc_clock; + uint32_t irq_num; + uint32_t irq_enable; + uint32_t version; + uint32_t freq_min; + uint32_t freq_max; + uint32_t freq_default; + uint32_t preset_enabled; + uint32_t timing; + uint32_t flags; +#define MMC_FLAG_USE_SDMA (1 << 0) +#define MMC_FLAG_USE_ADMA (1 << 1) +#define MMC_FLAG_REQ_USE_DMA (1 << 2) +#define MMC_FLAG_DEVICE_DEAD (1 << 3) +#define MMC_FLAG_SDR50_NEEDS_TUNING (1 << 4) // +#define MMC_FLAG_NEEDS_RETUNING (1 << 5) // +#define MMC_FLAG_AUTO_CMD12 (1 << 6) // +#define MMC_FLAG_AUTO_CMD23 (1 << 7) +#define MMC_FLAG_PV_ENABLED (1 << 8) // +#define MMC_FLAG_SDIO_IRQ_ENABLED (1 << 9) +#define MMC_FLAG_SDR104_NEEDS_TUNING (1 << 10) // +#define MMC_FLAG_USING_RETUNING_TIMER (1 << 11) +#define MMC_FLAG_USE_ADMA_64BIT (1 << 12) +#define MMC_FLAG_NON_INT_HANDLE (1 << 13) +#define MMC_FLAG_NON_OS_HANDLE (1 << 14) +#define MMC_FLAG_OS_EVENT_INIT (1 << 15) +#define MMC_FLAG_NO_DETECT_INSERT (1 << 16) + uint32_t type; +#define MMC_TYPE_MMC (1 << 0) +#define MMC_TYPE_SDIO (1 << 1) +#define MMC_TYPE_SD (1 << 2) + + uint32_t pwr; + char *adma_desc; + uint32_t adma_desc_sz; + uint32_t adma_desc_line_sz; + uint32_t align_buf_sz; + uint32_t align_bytes; + uint32_t adma_max_desc; + unsigned long adma_addr; + unsigned long align_addr; + uint16_t vdd; +// MMCSD_BUSMODE_OPENDRAIN 1;MMCSD_BUSMODE_PUSHPULL 2 + uint8_t bus_mode; /* command output mode */ +// MMCSD_CS_IGNORE 0;MMCSD_CS_HIGH 1;MMCSD_CS_LOW 2 + uint8_t chip_select; /* SPI chip select */ +// MMC_POWER_OFF 0;MMC_POWER_UP 1;MMC_POWER_ON 2 + uint8_t power_mode; /* power supply mode */ +// MMCSD_BUS_WIDTH_1 0;MMCSD_BUS_WIDTH_4 2;MMCSD_BUS_WIDTH_8 3 + uint8_t bus_width; /* data bus width */ + unsigned int cmdat; + uint32_t clock; + uint32_t phy_driver_cap; /* phy mode driver capability */ + uint8_t *_dma_buffer; + int sdio_clk; /* clock for sdio */ + uint32_t current_status; + + struct scatterlist *dma_sg; + unsigned int dma_sg_num; + unsigned int *dma_vaddr; + + // mmc_event hi_mmc_event; +#define HISI_WAIT_REQUEST_DONE (1 << 0) +#define HISI_WAIT_ACCIDENT (1 << 1) + uint32_t err_int_count; +}; + +typedef void (* HWI_PROC_FUNC)(void); + +static inline void mmc_writel(struct hi_mmc_drv *host, unsigned int val, uint32_t regs) +{ + writel(host->hw_base_addr + regs, val); +} + +static inline void mmc_writew(struct hi_mmc_drv *host, unsigned short val, uint32_t regs) +{ + writew(host->hw_base_addr + regs, val); +} + +static inline void mmc_writeb(struct hi_mmc_drv *host, unsigned char val, uint32_t regs) +{ + writeb(host->hw_base_addr + regs, val); +} + +static inline void mmc_reg32_setbits(struct hi_mmc_drv *host, uint32_t regs, uint32_t p, uint32_t b, uint32_t val) +{ + reg32_setbits(host->hw_base_addr + regs, p, b, val); +} + +static inline unsigned int mmc_reg32_getbits(struct hi_mmc_drv *host, uint32_t regs, uint32_t p, uint32_t b) +{ + return reg32_getbits(host->hw_base_addr + regs, p, b); +} + +static inline unsigned int mmc_readl(struct hi_mmc_drv *host, uint32_t regs) +{ + return readl(host->hw_base_addr + regs); +} + +static inline unsigned short mmc_readw(struct hi_mmc_drv *host, uint32_t regs) +{ + return readw(host->hw_base_addr + regs); +} + +static inline unsigned char mmc_readb(struct hi_mmc_drv *host, uint32_t regs) +{ + return readb(host->hw_base_addr + regs); +} + +void hal_mmc_set_emmc_ctrl(struct hi_mmc_drv *mmc_drv, uint32_t offset, uint32_t pos, uint32_t bits, uint32_t val); + +uint32_t hal_mmc_get_cap1(struct hi_mmc_drv *mmc_drv); + +uint32_t hal_mmc_get_cap2(struct hi_mmc_drv *mmc_drv); + +void hal_mmc_reset(struct hi_mmc_drv *mmc_drv); + +void hi_mmc_dumpregs(struct hi_mmc_drv *host); + +void hal_mmc_set_power(struct hi_mmc_drv *mmc_drv, uint8_t power_mode); + +void hal_mmc_set_bus_mode(struct hi_mmc_drv *mmc_drv, uint8_t bus_mode); + +void hal_mmc_set_bus_width(struct hi_mmc_drv *mmc_drv, uint8_t bus_width); + +void hal_mmc_set_chip_set(struct hi_mmc_drv *mmc_drv, uint8_t chip_sel); + +void hal_mmc_set_voltage(struct hi_mmc_drv *mmc_drv, uint16_t vdd); + +void hi_mmc_enable_plug_irq(struct hi_mmc_drv* mmc_drv, uint32_t irq); + +void hi_mmc_set_sample_phase(struct hi_mmc_drv *mmc_drv, uint32_t phase); + +void hal_mmc_set_clock(struct hi_mmc_drv *mmc_drv, unsigned int clocknum); + +void hal_mmc_enable_plug_irq(struct hi_mmc_drv* mmc_drv, uint32_t irq); + +void hal_mmc_set_sample_phase(struct hi_mmc_drv *mmc_drv, uint32_t phase); + +void hal_mmc_deassert_status(struct hi_mmc_drv *mmc_drv); + +void hal_mmc_clr_reg(struct hi_mmc_drv *mmc_drv, unsigned int mask); + +void hal_mmc_set_timing(struct hi_mmc_drv *mmc_drv, int timing); + +void hal_mmc_set_preset_val(struct hi_mmc_drv *mmc_drv, bool en); + +void hal_mmc_adma_config(struct hi_mmc_drv *mmc_drv); + +void hal_mmc_set_card_clk(struct hi_mmc_drv *mmc_drv, bool en); + +unsigned int hi_mmc_set_clock_in_fgpa(struct hi_mmc_drv *mmc_drv, unsigned int cfg_clock); + +void hal_mmc_set_sdiom_clk_mode(struct hi_mmc_drv** drv, int mode); + +void hal_mmc_set_clk_en(hal_mmc_bus_num_t mmc_bus, bool en); + +#if (SUPPORT_HI_EMMC_PHY == YES) +void hi_mmc_set_phy_driver_capability(struct hi_mmc_drv *mmc_drv, uint32_t val); +#endif + +bool hi_mmc_set_clock_switch(uint32_t fisrt_div, uint32_t second_div, uint32_t sd_bus_div); + +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/hal_pmu_peripheral_application.h b/code/sdk/bootloader/flashboot/brandy/emmc/hal_pmu_peripheral_application.h new file mode 100644 index 000000000..a015a6a35 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/hal_pmu_peripheral_application.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: APP PMU DRIVER HEADER FILE + * Author: + * Create: 2020-01-13 + */ +#ifndef HAL_PMU_PERIPHERAL_APPLICATION_H +#define HAL_PMU_PERIPHERAL_APPLICATION_H +#include "hal_pmu_peripheral.h" +#include "chip_io.h" +/** @defgroup connectivity_drivers_hal_pmu_peripheral_app PMU Peripheral + * @ingroup connectivity_drivers_hal + * @{ + */ +typedef struct { + uint16_t m_top0_l; + uint16_t m_top0_h; + uint16_t m_top1_l; + uint16_t m_top1_h; + uint16_t m_top2_l; + uint16_t m_top2_h; + uint16_t m_top3_l; + uint16_t m_top3_h; + uint16_t m_top4_l; + uint16_t m_top4_h; + uint16_t m_top5_l; + uint16_t m_top5_h; + uint16_t m_clocken0; + uint16_t m_clocken1; + uint16_t m_clocken2; + uint16_t m_glb_clocken; + uint16_t m_perp_ls_cr; +} hal_pmu_m_clocks_state_t; + +/** + * @brief Get mcpu peripheral work status. + * @param perip The peripheral to config + * @return HAL_PMU_PERIP_STATUS The peripheral work status. + */ +hal_pmu_perip_status_type_t hal_pmu_mcpu_perip_get_status(hal_pmu_mcpu_perips_type_t perip); + +/** + * @brief Reset mcpu peripheral. + * @param perip The peripheral to config + * @param request The request to operate pheripheral + */ +void hal_pmu_mcpu_perip_reset(hal_pmu_mcpu_perips_type_t perip, hal_pmu_perip_request_type_t request); + +/** + * @brief Config mcpu peripheral. + * @param perip The peripheral to config + * @param request The request to operate pheripheral + */ +void hal_pmu_mcpu_perip_config(hal_pmu_mcpu_perips_type_t perip, hal_pmu_perip_request_type_t request); + +/** + * @brief Get mcpu alwasy on peripheral work status. + * @param perip The peripheral to config + * @return HAL_PMU_PERIP_STATUS The peripheral work status. + */ +hal_pmu_perip_status_type_t hal_pmu_maon_perip_get_status(hal_pmu_maon_perips_type_t perip); + +/** + * @brief Config mcpu alwasy on peripheral. + * @param perip The peripheral to config + * @param request The request to operate pheripheral + */ +void hal_pmu_maon_perip_config(hal_pmu_maon_perips_type_t perip, hal_pmu_perip_request_type_t request); + +/** + * @brief Get mem sub peripheral work status. + * @param perip The peripheral to config + * @return HAL_PMU_PERIP_STATUS The peripheral work status. + */ +hal_pmu_perip_status_type_t hal_pmu_mem_perip_get_status(hal_pmu_mem_perips_type_t perip); + +/** + * @brief Config mem sub peripheral. + * @param perip The peripheral to config + * @param request The request to operate pheripheral + */ +void hal_pmu_mem_perip_config(hal_pmu_mem_perips_type_t perip, hal_pmu_perip_request_type_t request); + +/** + * @brief Get dsp cpu always on gpio peripheral work status. + * @return HAL_PMU_PERIP_STATUS The peripheral work status. + */ +hal_pmu_perip_status_type_t hal_pmu_daon_perip_get_status(void); + +/** + * @brief Config dsp cpu alwyas on gpio peripheral. + * @param request The request to operate pheripheral + */ +void hal_pmu_daon_perip_config(hal_pmu_perip_request_type_t request); + +/** + * @brief Config m gpio clock. + * @param on open/close + */ +void hal_pmu_mgpio_low_power_config(switch_type_t on); + +/** + * @brief Get peripheral clcok state in abnormal. + */ +void hal_pmu_get_perip_state(void); + +/** + * @} + */ +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/liteos_adapter.h b/code/sdk/bootloader/flashboot/brandy/emmc/liteos_adapter.h new file mode 100644 index 000000000..f3559b30d --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/liteos_adapter.h @@ -0,0 +1,99 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: LITEOS ADAPTER HEADER FILE + * Author: + * Create: 2020-04 + */ +#ifndef LITEOS_ADAPTER_H +#define LITEOS_ADAPTER_H + +#include "irmalloc.h" +#include "securec.h" +#include "chip_io.h" +#include "rt_sys_header.h" +#include "debug_print.h" + +#ifdef TEST_SUIT +#define SDIO_WAIT_RESPONSE_TIME 1000 +#else +#define SDIO_WAIT_RESPONSE_TIME 100 +#endif +#define RT_NULL NULL +#define rt_tick_get() (uint32_t)uapi_systick_get_count() +#define mmcsd_delay_ms(ms) uapi_tcxo_delay_ms(ms) +#define RT_TICK_PER_SECOND 1000 +#define MMC_RT_LOG_ERR + +#ifdef MMC_OPEN_ALL_LOG +#define MMC_RT_LOG_ERR +#define MMC_RT_LOG_INFO +#define MMC_RT_LOG_WARNING +#define MMC_RT_LOG_DEBUG +#endif +#ifdef MMC_RT_LOG_ERR +#define LOG_E(fmt, arg...) do { \ + PRINT("rt-mmc:%s:%d: ", __FUNCTION__, __LINE__); \ + PRINT(fmt, ##arg); \ + PRINT("\r\n"); \ +} while (0) +#else +#define LOG_E(fmt, arg...) do { } while (0) +#endif +#ifdef MMC_RT_LOG_INFO +#define LOG_I(fmt, arg...) do { \ + PRINT("rt-mmc:%s:%d: ", __FUNCTION__, __LINE__); \ + PRINT(fmt, ##arg); \ + PRINT("\r\n"); \ +} while (0) +#else +#define LOG_I(fmt, arg...) do { } while (0) +#endif +#ifdef MMC_RT_LOG_WARNING +#define LOG_W(fmt, arg...) do { \ + PRINT("rt-mmc:%s:%d: ", __FUNCTION__, __LINE__); \ + PRINT(fmt, ##arg); \ + PRINT("\r\n"); \ +} while (0) +#else +#define LOG_W(fmt, arg...) do { } while (0) +#endif +#ifdef MMC_RT_LOG_DEBUG +#define LOG_D(fmt, arg...) do { \ + PRINT("rt-mmc:%s:%d: ", __FUNCTION__, __LINE__); \ + PRINT(fmt, ##arg); \ + PRINT("\r\n"); \ +} while (0) +#else +#define LOG_D(fmt, arg...) do { } while (0) +#endif + +#define memalign(boundary, size) irmalloc(size) +#define mmc_assert(cond) do { \ + if (!(cond)) \ + panic(1, __LINE__); \ + } while (0) +#define RT_ASSERT(cond) if (!(cond)) \ + panic(1, __LINE__) +#define rt_malloc(size) irmalloc(size) +#define rt_calloc(n, size) irzalloc((n) * (size)) +#define rt_set_errno(error) panic(1, __LINE__) +#define rt_free(rmem) irfree(rmem) +// Encapsulation liteos function +typedef uint32_t mmc_sem; +#define MMC_SEM_WAIT_FOREVER 0xFFFFFFFF +#define mmc_sem_create(sem_id) LOS_SemCreate(1, sem_id) +#define mmc_sem_post(sem_id) LOS_SemPost(sem_id) +#define mmc_sem_pend(sem_id, timeout) LOS_SemPend(sem_id, timeout) +#define mmc_sem_delete(sem_id) LOS_SemDelete(sem_id) +/* define mutex lock */ +typedef uint32_t mmc_mutex; +#define MMC_MUTEX_WAIT_FOREVER 0xFFFFFFFF +#define mmc_mutex_init(mutex) LOS_MuxCreate(mutex) +#define mmc_mutex_lock(mutex, timeout) LOS_MuxPend(mutex, timeout) +#define mmc_mutex_unlock(mutex) LOS_MuxPost(mutex) +#define mmc_mutex_delete(mutex) LOS_MuxDelete(mutex) + +/* define create thread */ +typedef unsigned int mmc_thread; +#define mmc_thread_delete(id) { LOS_TaskDelete(id); } +#endif \ No newline at end of file diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/mmc.c b/code/sdk/bootloader/flashboot/brandy/emmc/mmc.c new file mode 100644 index 000000000..a15c51f52 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/mmc.c @@ -0,0 +1,829 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2015-06-15 hichard first version + */ + +#include "mmcsd_core.h" +#include "drv_mmc_adapter.h" +#include "mshc_reg.h" +#include "mmc.h" + +#define DBG_TAG "SDIO" +#ifdef RT_SDIO_DEBUG +#define DBG_LVL DBG_LOG +#else +#define DBG_LVL DBG_INFO +#endif /* RT_SDIO_DEBUG */ +#define EXT_CSD_LEN 512 + +static const uint32_t tran_unit[] = { + 10000, 100000, 1000000, 10000000, + 0, 0, 0, 0 +}; + +static const uint8_t tran_value[] = { + 0, 10, 12, 13, 15, 20, 25, 30, + 35, 40, 45, 50, 55, 60, 70, 80, +}; + +static const uint32_t tacc_uint[] = { + 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, +}; + +static const uint8_t tacc_value[] = { + 0, 10, 12, 13, 15, 20, 25, 30, + 35, 40, 45, 50, 55, 60, 70, 80, +}; + +rt_inline uint32_t GET_BITS(uint32_t *resp, uint32_t start, uint32_t size) +{ + const int32_t __size = size; + const uint32_t __mask = (__size < 32 ? 1 << __size : 0) - 1; // 32 + const int32_t __off = 3 - ((start) / 32); // 32 3 + const int32_t __shft = (start) & 31; // 31 + uint32_t __res; + + __res = resp[__off] >> __shft; + if (__size + __shft > 32) { // 32 + __res |= resp[__off-1] << ((32 - __shft) % 32); // 32 + } + + return __res & __mask; +} + +/* + * Given a 128-bit response, decode to our card CSD structure. + */ +static int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card) +{ + uint32_t a, b; + struct rt_mmcsd_csd *csd = &card->csd; + uint32_t *resp = card->resp_csd; + + /* + * We only understand CSD structure v1.1 and v1.2. + * v1.2 has extra information in bits 15, 11 and 10. + * We also support eMMC v4.4 & v4.41. + */ + csd->csd_structure = GET_BITS(resp, 126, 2); // 126 2 + if (csd->csd_structure == 0) { + LOG_E("unrecognised CSD structure version %d!", csd->csd_structure); + return -RT_ERROR; + } + csd->spec_vers = GET_BITS(resp, 122, 4); // 122 4 + csd->taac = GET_BITS(resp, 112, 8); // 112 8 + csd->nsac = GET_BITS(resp, 104, 8); // 104 8 + csd->tran_speed = GET_BITS(resp, 96, 8); // 96 8 + csd->card_cmd_class = GET_BITS(resp, 84, 12); // 84 12 + csd->rd_blk_len = GET_BITS(resp, 80, 4); // 80 4 + csd->rd_blk_part = GET_BITS(resp, 79, 1); // 79 1 + csd->wr_blk_misalign = GET_BITS(resp, 78, 1); // 78 1 + csd->rd_blk_misalign = GET_BITS(resp, 77, 1); // 77 1 + csd->dsr_imp = GET_BITS(resp, 76, 1); // 76 1 + csd->c_size = GET_BITS(resp, 62, 12); // 62 12 + csd->c_size_mult = GET_BITS(resp, 47, 3); // 47 3 + csd->r2w_factor = GET_BITS(resp, 26, 3); // 26 3 + csd->wr_blk_len = GET_BITS(resp, 22, 4); // 22 4 + csd->wr_blk_partial = GET_BITS(resp, 21, 1); // 21 1 + csd->csd_crc = GET_BITS(resp, 1, 7); // 1 7 + + card->card_blksize = 1 << csd->rd_blk_len; + card->tacc_clks = csd->nsac * 100; // 100 + card->tacc_ns = (tacc_uint[csd->taac&0x07] * tacc_value[(csd->taac&0x78)>>3] + 9) / 10; // 3 9 10 + card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3]; // 3 + if (csd->wr_blk_len >= 9) { // 9 + a = GET_BITS(resp, 42, 5); // 42 5 + b = GET_BITS(resp, 37, 5); // 37 5 + card->erase_size = (a + 1) * (b + 1); + card->erase_size <<= csd->wr_blk_len - 9; // 9 + } + return 0; +} + +/* + * Read extended CSD. + */ +static int mmc_get_ext_csd(struct rt_mmcsd_card *card, uint8_t **new_ext_csd) +{ + void *ext_csd; + struct rt_mmcsd_req req; + struct rt_mmcsd_cmd cmd; + struct rt_mmcsd_data data; + + *new_ext_csd = RT_NULL; + + if (GET_BITS(card->resp_cid, 122, 4) < 4) { // 122 4 + return 0; + } + + /* + * As the ext_csd is so large and mostly unused, we don't store the + * raw block in mmc_card. + */ + ext_csd = irmalloc(EXT_CSD_LEN); + if (!ext_csd) { + LOG_E("alloc memory failed when get ext csd!"); + return -RT_ENOMEM; + } + (void)memset_s(ext_csd, EXT_CSD_LEN, 0, EXT_CSD_LEN); + (void)memset_s(&req, sizeof(struct rt_mmcsd_req), 0, sizeof(struct rt_mmcsd_req)); + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + (void)memset_s(&data, sizeof(struct rt_mmcsd_data), 0, sizeof(struct rt_mmcsd_data)); + + req.cmd = &cmd; + req.data = &data; + + cmd.cmd_code = SEND_EXT_CSD; + cmd.arg = 0; + + /* NOTE HACK: the RESP_SPI_R1 is always correct here, but we + * rely on callers to never use this with "native" calls for reading + * CSD or CID. Native versions of those commands use the R2 type, + * not R1 plus a data block. + */ + cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC; + + data.blksize = 512; // 512 + data.blks = 1; + data.flags = DATA_DIR_READ; + data.buf = ext_csd; + + /* + * Some cards require longer data read timeout than indicated in CSD. + * Address this by setting the read timeout to a "reasonably high" + * value. For the cards tested, 300ms has proven enough. If necessary, + * this value can be increased if other problematic cards require this. + */ + data.timeout_ns = 300000000; // 300000000 + data.timeout_clks = 0; + + mmcsd_send_request(card->host, &req); + if (cmd.err) { + return cmd.err; + } + + if (data.err) { + return data.err; + } + + *new_ext_csd = ext_csd; + (void)memcpy_s((void *)card->ext_csd_val, EXT_CSD_LEN, ext_csd, EXT_CSD_LEN); + return 0; +} + +/* + * Decode extended CSD. + */ +static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, uint8_t *ext_csd) +{ + rt_uint64_t card_capacity = 0; + int retval = 0; + if (card == RT_NULL || ext_csd == RT_NULL) { + LOG_E("emmc parse ext csd fail, invaild args"); + return -1; + } + struct rt_mmcsd_ext_csd *ext_csd_reg = RT_NULL; + + ext_csd_reg = &(card->ext_csd); + + ext_csd_reg->raw_ext_csd_structure = ext_csd[EXT_CSD_STRUCTURE]; + if (card->csd.csd_structure == 3) { // 3 + if (ext_csd_reg->raw_ext_csd_structure > 2) { // 2 + LOG_E("unrecognised EXT_CSD structure ersion %d", ext_csd_reg->raw_ext_csd_structure); + retval = -EINVAL; + return retval; + } + } + ext_csd_reg->rev = ext_csd[EXT_CSD_REV]; + ext_csd_reg->raw_sectors[0] = ext_csd[EXT_CSD_SEC_CNT + 0]; // 0 + ext_csd_reg->raw_sectors[1] = ext_csd[EXT_CSD_SEC_CNT + 1]; // 1 + ext_csd_reg->raw_sectors[2] = ext_csd[EXT_CSD_SEC_CNT + 2]; // 2 + ext_csd_reg->raw_sectors[3] = ext_csd[EXT_CSD_SEC_CNT + 3]; // 3 + if (ext_csd_reg->rev >= 2) { // 2 + ext_csd_reg->sectors = (ext_csd[EXT_CSD_SEC_CNT + 0] << 0) | + (ext_csd[EXT_CSD_SEC_CNT + 1] << 8) | /* 8 */ + (ext_csd[EXT_CSD_SEC_CNT + 2] << 16) | /* 2 16 */ + (ext_csd[EXT_CSD_SEC_CNT + 3] << 24); /* 3 24 */ + } + + ext_csd_reg->strobe_support = ext_csd[EXT_CSD_STROBE_SUPPORT]; + ext_csd_reg->raw_card_type = ext_csd[EXT_CSD_CARD_TYPE]; + switch (ext_csd[EXT_CSD_CARD_TYPE] & EXT_CSD_CARD_TYPE_MASK) { + case EXT_CSD_CARD_TYPE_ALL_1_8V: + case EXT_CSD_CARD_TYPE_1_8V_HS200: + ext_csd_reg->hs_max_dtr = EXT_CSD_CARD_MAX_RATE_200; + ext_csd_reg->card_type = EXT_CSD_CARD_TYPE_HS200_1_8V; + break; + case EXT_CSD_CARD_TYPE_DDR_52 | EXT_CSD_CARD_TYPE_HS_52 | EXT_CSD_CARD_TYPE_HS_26: + ext_csd_reg->hs_max_dtr = EXT_CSD_CARD_MAX_RATE_52; + ext_csd_reg->card_type = EXT_CSD_CARD_TYPE_DDR_52; + break; + case EXT_CSD_CARD_TYPE_DDR_1_8V | EXT_CSD_CARD_TYPE_HS_52 | EXT_CSD_CARD_TYPE_HS_26: + ext_csd_reg->hs_max_dtr = EXT_CSD_CARD_MAX_RATE_52; + ext_csd_reg->card_type = EXT_CSD_CARD_TYPE_DDR_1_8V; + break; + case EXT_CSD_CARD_TYPE_HS_52 | EXT_CSD_CARD_TYPE_HS_26: + ext_csd_reg->hs_max_dtr = EXT_CSD_CARD_MAX_RATE_52; + break; + default: + LOG_E("card type:%#x, need to parse the type", ext_csd[EXT_CSD_CARD_TYPE]); + break; + } + + ext_csd_reg->raw_s_a_timeout = ext_csd[EXT_CSD_S_A_TIMEOUT]; + ext_csd_reg->raw_erase_timeout_mult = ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; + ext_csd_reg->raw_hc_erase_grp_size = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; + if (ext_csd_reg->rev >= 3) { // 3 + uint8_t shift = ext_csd[EXT_CSD_S_A_TIMEOUT]; + ext_csd_reg->part_config = ext_csd[EXT_CSD_PART_CONFIG]; + ext_csd_reg->part_time_ms = 10 * ext_csd[EXT_CSD_PART_SWITCH_TIME]; // 10 + if (shift > 0 && shift <= 0x17) { + ext_csd_reg->sa_timeout_ns = 1 << ext_csd[EXT_CSD_S_A_TIMEOUT]; + } + + ext_csd_reg->erase_group_def = ext_csd[EXT_CSD_ERASE_GROUP_DEF]; + ext_csd_reg->hc_erase_timeout = 300 * ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; // 300 + ext_csd_reg->hc_erase_size = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] << 10; // 10 + ext_csd_reg->rel_sectors = ext_csd[EXT_CSD_REL_WR_SEC_C]; + ext_csd_reg->boot_size = ext_csd[EXT_CSD_BOOT_MULT] << 17; // 17 + } + + ext_csd_reg->raw_hc_erase_gap_size = ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]; + ext_csd_reg->raw_sec_trim_mult = ext_csd[EXT_CSD_SEC_TRIM_MULT]; + ext_csd_reg->raw_sec_erase_mult = ext_csd[EXT_CSD_SEC_ERASE_MULT]; + ext_csd_reg->raw_sec_feature_support = ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; + ext_csd_reg->raw_trim_mult = ext_csd[EXT_CSD_TRIM_MULT]; + if (ext_csd_reg->rev >= 4) { // 4 + if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) && (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) { + uint8_t hc_erase_grp_sz = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; + uint8_t hc_wp_grp_sz = ext_csd[EXT_CSD_HC_WP_GRP_SIZE]; + ext_csd_reg->enhanced_area_en = 1; + + // 139 24 138 16 137 8 136 + ext_csd_reg->enhanced_area_offset = ((rt_uint64_t)ext_csd[139] << 24) + + ((rt_uint64_t)ext_csd[138] << 16) + ((rt_uint64_t)ext_csd[137] << 8) + (rt_uint64_t)ext_csd[136]; + ext_csd_reg->enhanced_area_offset <<= 9; // device is block device 9 + // 142 16 141 8 140 + ext_csd_reg->enhanced_area_size = (ext_csd[142] << 16) + (ext_csd[141] << 8) + ext_csd[140]; + ext_csd_reg->enhanced_area_size *= (uint32_t)(hc_erase_grp_sz * hc_wp_grp_sz); + ext_csd_reg->enhanced_area_size <<= 9; // 9 + } else { + ext_csd_reg->enhanced_area_offset = (uint64_t)(-EINVAL);/*lint !e570*/ + ext_csd_reg->enhanced_area_size = (uint32_t)(-EINVAL);/*lint !e570*/ + } + ext_csd_reg->sec_trim_mult = ext_csd[EXT_CSD_SEC_TRIM_MULT]; + ext_csd_reg->sec_erase_mult = ext_csd[EXT_CSD_SEC_ERASE_MULT]; + ext_csd_reg->sec_feature_support = ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]; + ext_csd_reg->trim_timeout = 300 * ext_csd[EXT_CSD_TRIM_MULT]; // 300 + } + + if (ext_csd_reg->rev >= 5) { // 5 + /* whether the eMMC card supports HPI */ + if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x1) { + ext_csd_reg->hpi = 1; + if (ext_csd[EXT_CSD_HPI_FEATURES] & 0x2) { + ext_csd_reg->hpi_cmd = STOP_TRANSMISSION; + } else { + ext_csd_reg->hpi_cmd = SEND_STATUS; + } + /* + ** Indicate the maximum timeout to close + ** a command interrupted by HPI + **/ + ext_csd_reg->out_of_int_time = ext_csd[EXT_CSD_OUT_OF_INTERRUPT_TIME] * 10; // 10 + } + ext_csd_reg->rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; + } + + card->hs_max_data_rate = ext_csd_reg->hs_max_dtr; + card_capacity = *((uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]); + card_capacity *= card->card_blksize; + card_capacity >>= 10; /* unit:KB 10 */ + card->card_capacity = card_capacity; + LOG_D("emmc card capacity %d KB. card_type=%d", card->card_capacity, ext_csd_reg->card_type); + return retval; +} + +int32_t mmc_send_status(struct rt_mmcsd_card *card, uint32_t *status) +{ + int32_t err; + struct rt_mmcsd_cmd cmd = {0}; + + cmd.cmd_code = SEND_STATUS; + cmd.arg = card->rca << 16; // 16 + cmd.flags = RESP_R1 | CMD_AC; + err = mmcsd_send_cmd(card->host, &cmd, 5); // 5 + if (err) { + LOG_E("cmd13 requesting status failed ret=%d", err); + } + if (status != NULL) { + *status = cmd.resp[0]; + } + return err; +} + +/** + * mmc_switch - modify EXT_CSD register + * @card: the MMC card associated with the data transfer + * @set: cmd set values + * @fields: EXT_CSD register index + * @value: value to program into EXT_CSD register + * + * Modifies the EXT_CSD register for selected card. + */ +int mmc_switch(struct rt_mmcsd_card *card, uint8_t set, uint8_t fields, uint8_t value) +{ + int err; + struct rt_mmcsd_host *host = card->host; + struct rt_mmcsd_cmd cmd = {0}; + + cmd.cmd_code = SWITCH; + cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | (fields << 16) | (value << 8) | set; // 24 16 8 + cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_AC; + + err = mmcsd_send_cmd(host, &cmd, 3); // 3 + if (err) { + return err; + } + return 0; +} + +static int mmc_compare_ext_csds(struct rt_mmcsd_card *card, uint8_t *ext_csd, uint32_t bus_width) +{ + uint8_t *bw_ext_csd; + int err; + + if (bus_width == MMCSD_BUS_WIDTH_1) { + return 0; + } + err = mmc_get_ext_csd(card, &bw_ext_csd); + if (err || bw_ext_csd == RT_NULL) { + err = -RT_ERROR; + goto out; + } + + /* only compare read only fields */ + err = !((ext_csd[EXT_CSD_PARTITION_SUPPORT] == bw_ext_csd[EXT_CSD_PARTITION_SUPPORT]) && + (ext_csd[EXT_CSD_ERASED_MEM_CONT] == bw_ext_csd[EXT_CSD_ERASED_MEM_CONT]) && + (ext_csd[EXT_CSD_REV] == bw_ext_csd[EXT_CSD_REV]) && + (ext_csd[EXT_CSD_STRUCTURE] == bw_ext_csd[EXT_CSD_STRUCTURE]) && + (ext_csd[EXT_CSD_CARD_TYPE] == bw_ext_csd[EXT_CSD_CARD_TYPE]) && + (ext_csd[EXT_CSD_S_A_TIMEOUT] == bw_ext_csd[EXT_CSD_S_A_TIMEOUT]) && + (ext_csd[EXT_CSD_HC_WP_GRP_SIZE] == bw_ext_csd[EXT_CSD_HC_WP_GRP_SIZE]) && + (ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT] == bw_ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]) && + (ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] == bw_ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]) && + (ext_csd[EXT_CSD_SEC_TRIM_MULT] == bw_ext_csd[EXT_CSD_SEC_TRIM_MULT]) && + (ext_csd[EXT_CSD_SEC_ERASE_MULT] == bw_ext_csd[EXT_CSD_SEC_ERASE_MULT]) && + (ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT] == bw_ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]) && + (ext_csd[EXT_CSD_TRIM_MULT] == bw_ext_csd[EXT_CSD_TRIM_MULT]) && + (ext_csd[EXT_CSD_SEC_CNT + 0] == bw_ext_csd[EXT_CSD_SEC_CNT + 0]) && + (ext_csd[EXT_CSD_SEC_CNT + 1] == bw_ext_csd[EXT_CSD_SEC_CNT + 1]) && + (ext_csd[EXT_CSD_SEC_CNT + 2] == bw_ext_csd[EXT_CSD_SEC_CNT + 2]) && /* 2 */ + (ext_csd[EXT_CSD_SEC_CNT + 3] == bw_ext_csd[EXT_CSD_SEC_CNT + 3]) && /* 3 */ + (ext_csd[EXT_CSD_PWR_CL_52_195] == bw_ext_csd[EXT_CSD_PWR_CL_52_195]) && + (ext_csd[EXT_CSD_PWR_CL_26_195] == bw_ext_csd[EXT_CSD_PWR_CL_26_195]) && + (ext_csd[EXT_CSD_PWR_CL_52_360] == bw_ext_csd[EXT_CSD_PWR_CL_52_360]) && + (ext_csd[EXT_CSD_PWR_CL_26_360] == bw_ext_csd[EXT_CSD_PWR_CL_26_360]) && + (ext_csd[EXT_CSD_PWR_CL_200_195] == bw_ext_csd[EXT_CSD_PWR_CL_200_195]) && + (ext_csd[EXT_CSD_PWR_CL_200_360] == bw_ext_csd[EXT_CSD_PWR_CL_200_360]) && + (ext_csd[EXT_CSD_PWR_CL_DDR_52_195] == bw_ext_csd[EXT_CSD_PWR_CL_DDR_52_195]) && + (ext_csd[EXT_CSD_PWR_CL_DDR_52_360] == bw_ext_csd[EXT_CSD_PWR_CL_DDR_52_360]) && + (ext_csd[EXT_CSD_PWR_CL_DDR_200_360] == bw_ext_csd[EXT_CSD_PWR_CL_DDR_200_360])); + + if (err) { + err = -RT_ERROR; + } + +out: + irfree(bw_ext_csd); + return err; +} + +/* + * Select the bus width amoung 4-bit and 8-bit(SDR). + * If the bus width is changed successfully, return the selected width value. + * Zero is returned instead of error value if the wide width is not supported. + */ +static int mmc_select_bus_width(struct rt_mmcsd_card *card, uint8_t *ext_csd) +{ + uint32_t ext_csd_bits[] = { + EXT_CSD_BUS_WIDTH_8, + EXT_CSD_BUS_WIDTH_4, + EXT_CSD_BUS_WIDTH_1 + }; + uint32_t bus_widths[] = { + MMCSD_BUS_WIDTH_8, + MMCSD_BUS_WIDTH_4, + MMCSD_BUS_WIDTH_1 + }; + struct rt_mmcsd_host *host = card->host; + unsigned idx, bus_width = 0; + int err = 0; + + if (GET_BITS(card->resp_cid, 122, 4) < 4) { // 122 4 + return 0; + } + + /* + * Unlike SD, MMC cards dont have a configuration register to notify + * supported bus width. So bus test command should be run to identify + * the supported bus width or compare the ext csd values of current + * bus width and ext csd values of 1 bit mode read earlier. + */ + for (idx = 0; idx < sizeof(bus_widths) / sizeof(uint32_t); idx++) { + /* + * Host is capable of 8bit transfer, then switch + * the device to work in 8bit transfer mode. If the + * mmc switch command returns error then switch to + * 4bit transfer mode. On success set the corresponding + * bus width on the host. + */ + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_BUS_WIDTH, ext_csd_bits[idx]); + if (err) { + continue; + } + + bus_width = bus_widths[idx]; + mmcsd_set_bus_width(host, bus_width); + uapi_tcxo_delay_ms(20); // delay 20ms + err = mmc_compare_ext_csds(card, ext_csd, bus_width); + if (!err) { + err = bus_width; + break; + } else { + switch (ext_csd_bits[idx]) { + case 0: + LOG_E("switch to bus width 1 bit failed!"); + break; + case 1: + LOG_E("switch to bus width 4 bit failed!"); + break; + case 2: // 2 + LOG_E("switch to bus width 8 bit failed!"); + break; + default: + break; + } + } + } + return err; +} +rt_err_t mmc_send_op_cond(struct rt_mmcsd_host *host, uint32_t ocr, uint32_t *rocr) +{ + struct rt_mmcsd_cmd cmd; + uint32_t i; + rt_err_t err = RT_EOK; + + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + cmd.cmd_code = SEND_OP_COND; + cmd.arg = controller_is_spi(host) ? 0 : ocr; + cmd.flags = RESP_SPI_R1 | RESP_R3 | CMD_BCR; + + for (i = 100; i; i--) { // 100 + err = mmcsd_send_cmd(host, &cmd, 3); // 3 times + if (err) { + break; + } + + /* if we're just probing, do a single pass */ + if (ocr == 0) { + break; + } + + /* otherwise wait until reset completes */ + if (controller_is_spi(host)) { + if (!(cmd.resp[0] & R1_SPI_IDLE)) { + break; + } + } else { + if (cmd.resp[0] & CARD_BUSY) { + break; + } + } + + err = -RT_ETIMEOUT; + uapi_tcxo_delay_ms(10); // delay 10ms + } + + if (rocr && !controller_is_spi(host)) { + *rocr = cmd.resp[0]; + } + return err; +} + +static rt_err_t mmc_set_card_addr(struct rt_mmcsd_host *host, uint32_t rca) +{ + rt_err_t err; + struct rt_mmcsd_cmd cmd; + + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + cmd.cmd_code = SET_RELATIVE_ADDR; + cmd.arg = rca << 16; // 16 + cmd.flags = RESP_R1 | CMD_AC; + + err = mmcsd_send_cmd(host, &cmd, 3); // 3 times + if (err) { + return err; + } + return 0; +} + +static void mmc_set_erase_size(struct rt_mmcsd_card *cur_card) +{ + if (cur_card->ext_csd.erase_group_def & 1) { + cur_card->erase_size = cur_card->ext_csd.hc_erase_size; + } +} + +static int32_t mmc_switch_status(struct rt_mmcsd_card *card) +{ + int32_t err = 0; + uint32_t status = R1_RSP_UNEXP; + + err = mmc_send_status(card, &status); + if (err) { + return err; + } + + if (status & R1_RSP_UNEXP) { + LOG_E("unexpected status %#x after switch", status); + } + if (status & R1_RSP_BIT7_SWITCH_ERROR) { + LOG_E("switch status failed"); + return -EBADMSG; + } + return 0; +} + +static int mmc_select_hs200(struct rt_mmcsd_card *card, uint8_t *ext_csd) +{ + int err = 0; + struct rt_mmcsd_host *host = card->host; + + mmcsd_select_voltage(host, 0); + err = mmc_select_bus_width(card, ext_csd); + if (err >= 0) { + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS200); + if (err) { + LOG_E("set hs timing failed ret=%d", err); + return err; + } + hi_mmc_set_timing(host, TIMING_MMC_HS200); + err = mmc_switch_status(card); + } else { + LOG_E("hs200 select bus width failed ret=%d", err); + } + return err; +} + +static int mmc_select_highspeed(struct rt_mmcsd_card *card, uint8_t *ext_csd) +{ + int err = 0; + struct rt_mmcsd_host *host = card->host; + + err = mmc_select_bus_width(card, ext_csd); + if (err >= 0) { + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, EXT_CSD_TIMING_HS); + if (err) { + LOG_E("set highspeed timing failed ret=%d", err); + return err; + } + hi_mmc_set_timing(host, TIMING_MMC_HS); + err = mmc_switch_status(card); + } else { + LOG_E("high speed select bus width failed ret=%d", err); + } + return err; +} + +static void mmc_set_speed_flag(struct rt_mmcsd_host *host) +{ + struct rt_mmcsd_card *card = host->card; + host->flags &= ~MMCSD_SUP_HS200; + host->flags &= ~MMCSD_SUP_HS400; + host->flags &= ~MMCSD_SUP_HIGHSPEED; + + if (card->ext_csd.card_type == EXT_CSD_CARD_TYPE_HS200_1_8V) { + host->flags |= MMCSD_SUP_HS200; + } else if (card->ext_csd.card_type == EXT_CSD_CARD_TYPE_DDR_1_8V) { + host->flags |= MMCSD_SUP_HIGHSPEED; + } + LOG_I("card_type = %x flags = %x", card->ext_csd.card_type, host->flags); +} + +static int32_t mmcsd_mmc_init_card(struct rt_mmcsd_host *host, uint32_t ocr) +{ + int32_t err; + uint32_t resp[4]; // 4 + uint32_t rocr = 0; + uint32_t max_data_rate; + uint8_t *ext_csd = RT_NULL; + struct rt_mmcsd_card *card = RT_NULL; + + mmcsd_go_idle(host); + /* The extra bit indicates that we support high capacity */ + err = mmc_send_op_cond(host, ocr | (1 << 30), &rocr); // 30 + if (err) { + goto err; + } + + if (controller_is_spi(host)) { + err = mmcsd_spi_use_crc(host, 1); + if (err) { + goto err1; + } + } + + if (controller_is_spi(host)) { + err = mmcsd_get_cid(host, resp); + } else { + err = mmcsd_all_get_cid(host, resp); + } + + if (err) { + goto err; + } + + card = irmalloc(sizeof(struct rt_mmcsd_card)); + if (!card) { + LOG_E("malloc card failed!"); + err = -RT_ENOMEM; + goto err; + } + (void)memset_s(card, sizeof(struct rt_mmcsd_card), 0, sizeof(struct rt_mmcsd_card)); + + host->card = card; + card->card_type = CARD_TYPE_MMC; + card->host = host; + card->rca = 1; + (void)memcpy_s(card->resp_cid, sizeof(card->resp_cid), resp, sizeof(card->resp_cid)); + + /* + * For native busses: get card RCA and quit open drain mode. + */ + if (!controller_is_spi(host)) { + err = mmc_set_card_addr(host, card->rca); + if (err) { + goto err1; + } + + mmcsd_set_bus_mode(host, MMCSD_BUSMODE_PUSHPULL); + } + + err = mmcsd_get_csd(card, card->resp_csd); + if (err) { + goto err1; + } + + err = mmcsd_parse_csd(card); + if (err) { + goto err1; + } + + if (!controller_is_spi(host)) { + err = mmcsd_select_card(card); + if (err) { + goto err1; + } + } + + /* + * Fetch and process extended CSD. + */ + + err = mmc_get_ext_csd(card, &ext_csd); + if (err) { + goto err1; + } + + err = mmc_parse_ext_csd(card, ext_csd); + if (err) { + goto err1; + } + + mmc_set_erase_size(card); + if (card->ext_csd.part_config & EXT_CSD_PART_CONFIG_ACC_MASK) { + card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; + err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG, card->ext_csd.part_config); + if (err && err != -EBADMSG) { + goto err1; + } + } + mmc_set_speed_flag(host); + if (host->flags & MMCSD_SUP_HS200) { + err = mmc_select_hs200(card, ext_csd); + } else if (host->flags & MMCSD_SUP_HIGHSPEED) { + err = mmc_select_highspeed(card, ext_csd); + } + if (err) { + goto err1; + } + + /* If doing byte addressing, check if required to do sector + * addressing. Handle the case of <2GB cards needing sector + * addressing. See section 8.1 JEDEC Standard JED84-A441; + * ocr register has bit 30 set for sector addressing. + */ + if (!(card->flags & CARD_FLAG_SDHC) && (rocr & (1<<30))) { + card->flags |= CARD_FLAG_SDHC; + } + + /* set bus speed */ + max_data_rate = host->freq_max; + + if (max_data_rate > card->hs_max_data_rate) { + max_data_rate = card->hs_max_data_rate; + } + LOG_I("flags=%x mdr=%d hsmdr=%d cmdr=%d", host->flags, max_data_rate, card->hs_max_data_rate, card->max_data_rate); + mmcsd_set_clock(host, max_data_rate); + if (host->flags & MMCSD_SUP_HS200) { + err = hi_mmc_exec_tuning(card->host, SEND_TUNING_BLOCK_HS200); + if (err) { + LOG_W("tuning execution failed\n"); + goto err1; + } + /* switch bus width */ + mmc_select_bus_width(card, ext_csd); + } else { + /* switch bus width */ + mmc_select_bus_width(card, ext_csd); + } + host->card = card; + LOG_I("emmc init finish success clock=%d\n", max_data_rate); + irfree(ext_csd); + return 0; + +err1: + irfree(card); +err: + + return err; +} + +/* + * Starting point for mmc card init. + */ +int32_t init_mmc(struct rt_mmcsd_host *host, uint32_t ocr) +{ + int32_t err; + uint32_t current_ocr; + /* + * We need to get OCR a different way for SPI. + */ + + if (controller_is_spi(host)) { + err = mmcsd_spi_read_ocr(host, 0, &ocr); + if (err) { + goto err; + } + } + + current_ocr = mmcsd_select_voltage(host, ocr); + if (!current_ocr) { + err = -RT_ERROR; + goto err; + } + + /* + * Detect and init the card. + */ + err = mmcsd_mmc_init_card(host, current_ocr); + if (err) { + goto err; + } + + mmcsd_host_unlock(host); + + err = rt_mmcsd_blk_probe(host->card); + if (err) { + goto remove_card; + } + + mmcsd_host_lock(host); + return 0; + +remove_card: + mmcsd_host_lock(host); + rt_mmcsd_blk_remove(host->card); + irfree(host->card); + host->card = RT_NULL; + +err: + LOG_E("init MMC card failed!"); + return err; +} + +int32_t deinit_mmc_free_mem(struct rt_mmcsd_host *host) +{ + if (host == RT_NULL || host->card == RT_NULL) { + return -RT_EINVAL; + } + irfree(host->card); + host->card = RT_NULL; + return 0; +} \ No newline at end of file diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/mmc.h b/code/sdk/bootloader/flashboot/brandy/emmc/mmc.h new file mode 100644 index 000000000..5ed6aaafa --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/mmc.h @@ -0,0 +1,221 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2015-06-15 hichard first version + */ + +#ifndef __MMC_H__ +#define __MMC_H__ + +#include "mmcsd_host.h" +#ifdef __cplusplus +extern "C" { +#endif + +/* + * EXT_CSD fields + */ + +#define EXT_CSD_FLUSH_CACHE 32 /* W */ +#define EXT_CSD_CACHE_CTRL 33 /* R/W */ +#define EXT_CSD_POWER_OFF_NOTIFICATION 34 /* R/W */ +#define EXT_CSD_PACKED_FAILURE_INDEX 35 /* RO */ +#define EXT_CSD_PACKED_CMD_STATUS 36 /* RO */ +#define EXT_CSD_EXP_EVENTS_STATUS 54 /* RO, 2 bytes */ +#define EXT_CSD_EXP_EVENTS_CTRL 56 /* R/W, 2 bytes */ +#define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */ +#define EXT_CSD_GP_SIZE_MULT 143 /* R/W */ +#define EXT_CSD_PARTITION_ATTRIBUTE 156 /* R/W */ +#define EXT_CSD_PARTITION_SUPPORT 160 /* RO */ +#define EXT_CSD_HPI_MGMT 161 /* R/W */ +#define EXT_CSD_RST_N_FUNCTION 162 /* R/W */ +#define EXT_CSD_BKOPS_EN 163 /* R/W */ +#define EXT_CSD_BKOPS_START 164 /* W */ +#define EXT_CSD_SANITIZE_START 165 /* W */ +#define EXT_CSD_WR_REL_PARAM 166 /* RO */ +#define EXT_CSD_RPMB_MULT 168 /* RO */ +#define EXT_CSD_BOOT_WP 173 /* R/W */ +#define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ +#define EXT_CSD_PART_CONFIG 179 /* R/W */ +#define EXT_CSD_ERASED_MEM_CONT 181 /* RO */ +#define EXT_CSD_BUS_WIDTH 183 /* R/W */ +#define EXT_CSD_STROBE_SUPPORT 184 /* RO */ +#define EXT_CSD_HS_TIMING 185 /* R/W */ +#define EXT_CSD_POWER_CLASS 187 /* R/W */ +#define EXT_CSD_REV 192 /* RO */ +#define EXT_CSD_STRUCTURE 194 /* RO */ +#define EXT_CSD_CARD_TYPE 196 /* RO */ +#define EXT_CSD_OUT_OF_INTERRUPT_TIME 198 /* RO */ +#define EXT_CSD_PART_SWITCH_TIME 199 /* RO */ +#define EXT_CSD_PWR_CL_52_195 200 /* RO */ +#define EXT_CSD_PWR_CL_26_195 201 /* RO */ +#define EXT_CSD_PWR_CL_52_360 202 /* RO */ +#define EXT_CSD_PWR_CL_26_360 203 /* RO */ +#define EXT_CSD_SEC_CNT 212 /* RO, 4 bytes */ +#define EXT_CSD_S_A_TIMEOUT 217 /* RO */ +#define EXT_CSD_REL_WR_SEC_C 222 /* RO */ +#define EXT_CSD_HC_WP_GRP_SIZE 221 /* RO */ +#define EXT_CSD_ERASE_TIMEOUT_MULT 223 /* RO */ +#define EXT_CSD_HC_ERASE_GRP_SIZE 224 /* RO */ +#define EXT_CSD_BOOT_MULT 226 /* RO */ +#define EXT_CSD_SEC_TRIM_MULT 229 /* RO */ +#define EXT_CSD_SEC_ERASE_MULT 230 /* RO */ +#define EXT_CSD_SEC_FEATURE_SUPPORT 231 /* RO */ +#define EXT_CSD_TRIM_MULT 232 /* RO */ +#define EXT_CSD_PWR_CL_200_195 236 /* RO */ +#define EXT_CSD_PWR_CL_200_360 237 /* RO */ +#define EXT_CSD_PWR_CL_DDR_52_195 238 /* RO */ +#define EXT_CSD_PWR_CL_DDR_52_360 239 /* RO */ +#define EXT_CSD_BKOPS_STATUS 246 /* RO */ +#define EXT_CSD_POWER_OFF_LONG_TIME 247 /* RO */ +#define EXT_CSD_GENERIC_CMD6_TIME 248 /* RO */ +#define EXT_CSD_CACHE_SIZE 249 /* RO, 4 bytes */ +#define EXT_CSD_PWR_CL_DDR_200_360 253 /* RO */ +#define EXT_CSD_TAG_UNIT_SIZE 498 /* RO */ +#define EXT_CSD_DATA_TAG_SUPPORT 499 /* RO */ +#define EXT_CSD_MAX_PACKED_WRITES 500 /* RO */ +#define EXT_CSD_MAX_PACKED_READS 501 /* RO */ +#define EXT_CSD_BKOPS_SUPPORT 502 /* RO */ +#define EXT_CSD_HPI_FEATURES 503 /* RO */ + +/* + * EXT_CSD field definitions + */ + +#define EXT_CSD_WR_REL_PARAM_EN (1<<2) + +#define EXT_CSD_BOOT_WP_B_PWR_WP_DIS (0x40) +#define EXT_CSD_BOOT_WP_B_PERM_WP_DIS (0x10) +#define EXT_CSD_BOOT_WP_B_PERM_WP_EN (0x04) +#define EXT_CSD_BOOT_WP_B_PWR_WP_EN (0x01) + +#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7) +#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1) +#define EXT_CSD_PART_CONFIG_ACC_RPMB (0x3) +#define EXT_CSD_PART_CONFIG_ACC_GP0 (0x4) + +#define EXT_CSD_PART_SUPPORT_PART_EN (0x1) + +#define EXT_CSD_CMD_SET_NORMAL (1<<0) +#define EXT_CSD_CMD_SET_SECURE (1<<1) +#define EXT_CSD_CMD_SET_CPSECURE (1<<2) + +#define EXT_CSD_CARD_TYPE_HS_26 (1<<0) /* Card can run at 26MHz */ +#define EXT_CSD_CARD_TYPE_HS_52 (1<<1) /* Card can run at 52MHz */ +#define EXT_CSD_CARD_TYPE_HS (EXT_CSD_CARD_TYPE_HS_26 | \ + EXT_CSD_CARD_TYPE_HS_52) +#define EXT_CSD_CARD_TYPE_DDR_1_8V (1<<2) /* Card can run at 52MHz */ + /* DDR mode @1.8V or 3V I/O */ +#define EXT_CSD_CARD_TYPE_DDR_1_2V (1<<3) /* Card can run at 52MHz */ + /* DDR mode @1.2V I/O */ +#define EXT_CSD_CARD_TYPE_DDR_52 (EXT_CSD_CARD_TYPE_DDR_1_8V \ + | EXT_CSD_CARD_TYPE_DDR_1_2V) +#define EXT_CSD_CARD_TYPE_HS200_1_8V (1<<4) /* Card can run at 200MHz */ +#define EXT_CSD_CARD_TYPE_HS200_1_2V (1<<5) /* Card can run at 200MHz */ + /* SDR mode @1.2V I/O */ +#define EXT_CSD_CARD_TYPE_HS200 (EXT_CSD_CARD_TYPE_HS200_1_8V | \ + EXT_CSD_CARD_TYPE_HS200_1_2V) +#define EXT_CSD_CARD_TYPE_HS400_1_8V (1<<6) /* Card can run at 200MHz DDR, 1.8V */ +#define EXT_CSD_CARD_TYPE_HS400_1_2V (1<<7) /* Card can run at 200MHz DDR, 1.2V */ +#define EXT_CSD_CARD_TYPE_HS400 (EXT_CSD_CARD_TYPE_HS400_1_8V | \ + EXT_CSD_CARD_TYPE_HS400_1_2V) +#define EXT_CSD_CARD_TYPE_ALL_1_8V (EXT_CSD_CARD_TYPE_HS_26 | \ + EXT_CSD_CARD_TYPE_HS_52 | EXT_CSD_CARD_TYPE_DDR_1_8V | \ + EXT_CSD_CARD_TYPE_HS200_1_8V | EXT_CSD_CARD_TYPE_HS400_1_8V) +#define EXT_CSD_CARD_TYPE_1_8V_HS200 (EXT_CSD_CARD_TYPE_HS_26 | \ + EXT_CSD_CARD_TYPE_HS_52 | EXT_CSD_CARD_TYPE_DDR_1_8V | \ + EXT_CSD_CARD_TYPE_HS200_1_8V) +#define EXT_CSD_CARD_TYPE_MASK (0xFF) /* CSD[196] Mask with JESDC84-B51 */ +#define EXT_CSD_CARD_MAX_RATE_200 200000000 +#define EXT_CSD_CARD_MAX_RATE_52 52000000 + +#define EXT_CSD_BUS_WIDTH_1 0 /* Card is in 1 bit mode */ +#define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */ +#define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */ +#define EXT_CSD_DDR_BUS_WIDTH_4 5 /* Card is in 4 bit DDR mode */ +#define EXT_CSD_DDR_BUS_WIDTH_8 6 /* Card is in 8 bit DDR mode */ + +#define EXT_CSD_TIMING_BC 0 /* Backwards compatility */ +#define EXT_CSD_TIMING_HS 1 /* High speed */ +#define EXT_CSD_TIMING_HS200 2 /* HS200 */ +#define EXT_CSD_TIMING_HS400 3 /* HS400 */ + +#define EXT_CSD_SEC_ER_EN BIT(0) +#define EXT_CSD_SEC_BD_BLK_EN BIT(2) +#define EXT_CSD_SEC_GB_CL_EN BIT(4) +#define EXT_CSD_SEC_SANITIZE BIT(6) /* v4.5 only */ + +#define EXT_CSD_RST_N_EN_MASK 0x3 +#define EXT_CSD_RST_N_ENABLED 1 /* RST_n is enabled on card */ + +#define EXT_CSD_NO_POWER_NOTIFICATION 0 +#define EXT_CSD_POWER_ON 1 +#define EXT_CSD_POWER_OFF_SHORT 2 +#define EXT_CSD_POWER_OFF_LONG 3 + +#define EXT_CSD_PWR_CL_8BIT_MASK 0xF0 /* 8 bit PWR CLS */ +#define EXT_CSD_PWR_CL_4BIT_MASK 0x0F /* 8 bit PWR CLS */ +#define EXT_CSD_PWR_CL_8BIT_SHIFT 4 +#define EXT_CSD_PWR_CL_4BIT_SHIFT 0 + +#define EXT_CSD_PACKED_EVENT_EN BIT(3) + +/* + * EXCEPTION_EVENT_STATUS field + */ +#define EXT_CSD_URGENT_BKOPS BIT(0) +#define EXT_CSD_DYNCAP_NEEDED BIT(1) +#define EXT_CSD_SYSPOOL_EXHAUSTED BIT(2) +#define EXT_CSD_PACKED_FAILURE BIT(3) + +#define EXT_CSD_PACKED_GENERIC_ERROR BIT(0) +#define EXT_CSD_PACKED_INDEXED_ERROR BIT(1) + +/* + * BKOPS status level + */ +#define EXT_CSD_BKOPS_LEVEL_2 0x2 +/* + * MMC_SWITCH access modes + */ +#define MMC_SWITCH_MODE_CMD_SET 0x00 /* Change the command set */ +#define MMC_SWITCH_MODE_SET_BITS 0x01 /* Set bits which are 1 in value */ +#define MMC_SWITCH_MODE_CLEAR_BITS 0x02 /* Clear bits which are 1 in value */ +#define MMC_SWITCH_MODE_WRITE_BYTE 0x03 /* Set target to value */ + +#define R1_RSP_BIT7_SWITCH_ERROR (1 << 7) +#define R1_RSP_STATUS(x) ((x) & 0xFFFFE000) +#define R1_RSP_UNEXP (0xFDFFA000UL) +#define R1_RSP_ERASE_STATE_ALL_ERR (0xFDF92000) +#define R1_STATE_IDLE 0 +#define R1_STATE_READY 1 +#define R1_STATE_IDENT 2 +#define R1_STATE_STBY 3 +#define R1_STATE_TRAN 4 +#define R1_STATE_DATA 5 +#define R1_STATE_RCV 6 +#define R1_STATE_PRG 7 +#define R1_STATE_DIS 8 + +#define CSD_SPEC_VER_0 0 +#define CSD_SPEC_VER_1 1 +#define CSD_SPEC_VER_2 2 +#define CSD_SPEC_VER_3 3 +#define CSD_SPEC_VER_4 4 + +/* + * extern function + */ +rt_err_t mmc_send_op_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr, rt_uint32_t *rocr); +rt_int32_t init_mmc(struct rt_mmcsd_host *host, rt_uint32_t ocr); +rt_int32_t mmc_send_status(struct rt_mmcsd_card *card, rt_uint32_t *status); +rt_int32_t deinit_mmc_free_mem(struct rt_mmcsd_host *host); +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/mmc_block.c b/code/sdk/bootloader/flashboot/brandy/emmc/mmc_block.c new file mode 100644 index 000000000..cf7dd00bd --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/mmc_block.c @@ -0,0 +1,931 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: MMC BLOCK INTERFACE + * Author: + * Create: 2021-06 + */ +#include "drv_mmc_adapter.h" +#include "mmc.h" +#include "mmcsd_card.h" +#include "mmcsd_core.h" +#include "mmcsd_host.h" +#include "mmc_block.h" + +#define SECTOR_SIZE 512 +#define PIO_SECTOR_SIZE 512 +#define MMC_RW_RETRY_COUNTS 3 +#define VENDOR_CMD 60 +#define DATA_TRANSFER_TIMEOUT 300000000 // 300ms +#define MMC_DMA_ALIGN_SIZE 64 +#define MMC_CURRENT_STATE_TRAN 0x4 +#define MMC_RETRY_TIMES 500 +#define MMC_RETRY_DELAY 1 +#define PADING_LEN 196 +#define MAC_KEY_LEN 32 +#define DATA_LEN 256 +#define RAND_LEN 16 +#define WRITE_CNT_LEN 4 +#define RESULT_LEN 2 +#define HMAC_AUTH_DATA_LEN 284 +#define SET_RELIABLE_WRITE 0x80000000UL +#define OFFSET_8 8 +#define OFFSET_16 16 +#define OFFSET_24 24 +#define AUTH_KEY_REQ 0x1 +#define WRITE_COUNTER_READ_REQ 0x2 +#define AUTH_DATA_WRITE_REQ 0x3 +#define AUTH_DATA_READ_REQ 0x4 +#define RESULT_READ_REQ 0x5 +#define AUTH_DEVICE_CONFIG_WRITE_REQ 0x6 +#define AUTH_DEVICE_CONFIG_READ_REQ 0x7 +#define AUTH_KEY_REPLY 0x0100 +#define WRITE_COUNTER_READ_REPLY 0x0200 +#define AUTH_DATA_WRITE_REPLY 0x0300 +#define AUTH_DATA_READ_REPLY 0x0400 +#define AUTH_DEVICE_CONFIG_WRITE_RESP 0x0600 +#define AUTH_DEVICE_CONFIG_READ_RESP 0x0700 + +typedef struct { + uint8_t padding[PADING_LEN]; + uint8_t mac_key[MAC_KEY_LEN]; + uint8_t data[DATA_LEN]; + uint8_t rand[RAND_LEN]; + uint32_t write_cnt; + uint16_t address; + uint16_t block_cnt; + uint16_t op_result; + uint16_t req_resp; +}rpmb_data_t; + +typedef struct { + uint32_t sector; + uint8_t rw_flag; + uint32_t blks; + uint8_t reliable_flag; +} ioctl_data_t; + +typedef enum { + MMC_READ = 0, + MMC_WRITE = 1, +} mmc_rw_flag_t; + +int g_req_flag = 0; +rpmb_data_t g_rpmb_data __attribute__((__aligned__(64))) = { 0 }; + +static int mmcsd_req_block(struct rt_mmcsd_card *card, uint32_t sector, void *buf, uint32_t blks, mmc_rw_flag_t rw_flag) +{ + struct rt_mmcsd_cmd cmd, stop; + struct rt_mmcsd_data data; + struct rt_mmcsd_req req; + struct rt_mmcsd_host *host = card->host; + uint32_t r_cmd, w_cmd; + + memset_s(&req, sizeof(struct rt_mmcsd_req), 0, sizeof(struct rt_mmcsd_req)); + memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + memset_s(&stop, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + memset_s(&data, sizeof(struct rt_mmcsd_data), 0, sizeof(struct rt_mmcsd_data)); + req.cmd = &cmd; + req.data = &data; + + if (g_req_flag == 1) { + req.cmd->err = -EBUSY; + return -1; + } + g_req_flag = 1; // Avoid reentrant + mmcsd_host_lock(host); + cmd.arg = sector; + cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC; + data.blksize = SECTOR_SIZE; + data.blks = blks; + + if (blks > 1) { + req.stop = &stop; + stop.cmd_code = STOP_TRANSMISSION; + stop.flags = RESP_SPI_R1B | RESP_R1B | CMD_AC; + data.flags |= DATA_CMD_AUTO_STOP; + r_cmd = READ_MULTIPLE_BLOCK; + w_cmd = WRITE_MULTIPLE_BLOCK; + } else { + req.stop = NULL; + r_cmd = READ_SINGLE_BLOCK; + w_cmd = WRITE_BLOCK; + } + if (rw_flag == MMC_READ) { + cmd.cmd_code = r_cmd; + data.flags |= DATA_DIR_READ; + } else { + cmd.cmd_code = w_cmd; + data.flags |= DATA_DIR_WRITE; + } + mmcsd_set_data_timeout(&data, card); + data.buf = buf; + mmcsd_send_request(host, &req); + + mmcsd_host_unlock(host); + g_req_flag = 0; // Avoid reentrant + if ((cmd.err != 0) || (data.err != 0) || (stop.err != 0)) { return -1; } + return 0; +} + +static uint32_t mmc_dma_rw(const void *buf, uint32_t pos, uint32_t size, mmc_rw_flag_t rw_flag) +{ + int32_t err = 0; + uint32_t offset = 0; + uint32_t req_size = 0; + uint32_t remain_size = size; + if (buf == NULL) { + return 0; + } + void *wr_ptr = (void *)buf; + struct rt_mmcsd_host *mmc = NULL; + uint8_t retries = MMC_RW_RETRY_COUNTS; + + if ((uint32_t)buf % EMMC_DMA_ALIGN) { return 0; } + mmc = hi_mmc_get_host(SDIO_EMMC_ID); + if (mmc == NULL) { + panic(1, __LINE__); + return 0; //lint !e527 unreachable code + } + do { + while (remain_size != 0) { + req_size = (remain_size > mmc->max_dma_segs) ? mmc->max_dma_segs : remain_size; + if (rw_flag == MMC_READ) { + err = mmcsd_req_block(mmc->card, pos + offset, wr_ptr, req_size, MMC_READ); + } else { + err = mmcsd_req_block(mmc->card, pos + offset, wr_ptr, req_size, MMC_WRITE); + } + if (err != 0) { break; } + offset += req_size; + wr_ptr = (void *)((uint8_t *)wr_ptr + (req_size << 9)); // 9 + remain_size -= req_size; + } + if (err != 0) { + retries--; + } else { + break; + } + LOG_E("mmc_rw:start:%d,len:%d,rw_flag=%d,retries=%d,err_ret=%d", pos, size, rw_flag, retries, err); + } while (retries != 0); + + if (err != 0) { + return 0; + } + return size - remain_size; +} + +uint32_t hi_mmc_read(void *buffer, uint32_t pos, uint32_t size) +{ + uint32_t ret; + ret = mmc_dma_rw(buffer, pos, size, MMC_READ); + return ret; +} + +uint32_t hi_mmc_write(const void *buffer, uint32_t pos, uint32_t size) +{ + uint32_t ret; + ret = mmc_dma_rw(buffer, pos, size, MMC_WRITE); + return ret; +} + +uint32_t hi_mmc_pio_read(void *buffer, uint32_t pos, uint32_t size) +{ + uint32_t ret; + ret = mmc_dma_rw(buffer, pos, size, MMC_READ); + return ret; +} + +uint32_t hi_mmc_pio_write(const void *buffer, uint32_t pos, uint32_t size) +{ + uint32_t ret; + ret = mmc_dma_rw(buffer, pos, size, MMC_WRITE); + return ret; +} + +int hi_mmc_erase(uint32_t start_sector, uint32_t nsectors, uint32_t type) +{ + struct rt_mmcsd_req req = {0}; + struct rt_mmcsd_erase erase = {0}; + uint32_t tmp_start = start_sector; + uint32_t tmp_len = nsectors; + int ret = 0; + struct rt_mmcsd_host *mmc = NULL; + struct rt_mmcsd_card *card = NULL; + mmc = hi_mmc_get_host(SDIO_EMMC_ID); + if (mmc == NULL || mmc->card == NULL) { + panic(1, __LINE__); + return 0; //lint !e527 unreachable code + } + mmcsd_host_lock(mmc); + card = mmc->card; + req.erase = &erase; + erase.type = type; + do { + erase.start_addr = 0; + erase.len = 0; + if (tmp_len > CONFIG_ERASE_MAX_SECTOR) { + erase.start_addr = tmp_start; + erase.len = CONFIG_ERASE_MAX_SECTOR; + } else { + erase.start_addr = tmp_start; + erase.len = tmp_len; + } + LOG_I("erase: sec str:%d, sec len:%d type %d", erase.start_addr, erase.len, type); + ret = mmc_erase_arae(card, &req); + if (ret != 0) { + LOG_I("erase err ret=%d addr_len=%d type:%d", ret, erase.len, type); + break; + } + tmp_len -= erase.len; + tmp_start += erase.len; + } while (tmp_len != 0); + mmcsd_host_unlock(mmc); + if (tmp_len == 0) { + ret = 0; + } + return ret; +} + +int hi_mmc_init(struct rt_mmcsd_host *mmc) +{ + struct hi_mmc_drv *mmc_drv = NULL; + int ret = 0; + + if (mmc == NULL) { + ret = -EINVAL; + goto err; /*lint !e801*/ + } + mmc_drv = irmalloc(sizeof(struct hi_mmc_drv)); + if (mmc_drv == NULL) { + ret = -EINVAL; + goto err; /*lint !e801*/ + } + + memset_s(mmc_drv, sizeof(struct hi_mmc_drv), 0, sizeof(struct hi_mmc_drv)); + mmc->private_data = mmc_drv; + mmc_drv->host = mmc; + hi_mmc_set_magic_to_aon_area(); + hi_mmc_set_drv_features(mmc_drv, mmc->id); + hi_mmc_set_host_features(mmc); + ret = hi_mmc_set_int_info(mmc, mmc_drv); + if (ret != 0) { + goto err; /*lint !e801*/ + } + + ret = hi_mmc_detect(mmc); + if (ret != 0) { + goto err; /*lint !e801*/ + } + LOG_I("mmc version=%d drv_flags=%x host_flags=%x cap1=%x, cap2=%x\n", + mmc_drv->version, mmc_drv->flags, mmc->flags, + hal_mmc_get_cap1(mmc_drv), hal_mmc_get_cap2(mmc_drv)); + return 0; +err: + if (mmc_drv != NULL) { + irfree(mmc_drv); + mmc_drv = NULL; + } + if (mmc != NULL) { + LOG_E("MMC %d err while initialize ret=%d\n", mmc->id, ret); + irfree(mmc); + } + UNUSED(mmc_drv); + return ret; +} + +int hi_mmc_get_cardstatus(void) +{ + int err; + uint32_t status = 0; + struct rt_mmcsd_host *mmc = hi_mmc_get_host(SDIO_EMMC_ID); + if (mmc == NULL || mmc->card == NULL) { + LOG_E("get mmc error for getcardstate"); + return -1; + } + err = mmc_send_status(mmc->card, &status); + status = R1_CURRENT_STATE((unsigned int)status); + if (err != 0) { + LOG_E("get mmc status err=%d, status=%d", err, status); + return -1; + } + return (int)status; +} + +int hi_mmc_set_ext_csd_partition_config(PART_CONFIG_AREA area) +{ + int ret; + uint32_t status; + struct rt_mmcsd_host *mmc = hi_mmc_get_host(SDIO_EMMC_ID); + if (mmc == NULL || mmc->card == NULL) { + return -EPARAMERR; + } + if (area < PART_CONFIG_AREA_DEFAULT || area > PART_CONFIG_AREA_RPMB) { + return EPARAMERR; + } + struct rt_mmcsd_card *card = mmc->card; + LOG_I("set ext csd partition config %x\n", card->ext_csd.part_config); + card->ext_csd.part_config &= ~EXT_CSD_PART_CONFIG_ACC_MASK; + card->ext_csd.part_config |= (uint8_t)area; + ret = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONFIG, card->ext_csd.part_config); + if (ret != 0) { + LOG_E("mmc set ext_csd partition config error, err=%d", ret); + return ret; + } + do { + ret = mmc_send_status(card, (uint32_t *)&status); + if (ret != 0) { + return ret; + } + } while (((status & R1_READY_FOR_DATA) == 0) || (hi_mmc_card_busy(card->host) != 0)); + return ret; +} + +int hi_mmc_sleep_awake(emmc_sleep_mode_e_type sleep_enable) +{ + int err = 0; + struct rt_mmcsd_host *mmc = hi_mmc_get_host(SDIO_EMMC_ID); + if (mmc == NULL || mmc->card == NULL) { + return -EPARAMERR; + } + if ((sleep_enable != EMMC_SLEEP_DISABLE) && (sleep_enable != EMMC_SLEEP_ENABLE)) { + return EPARAMERR; + } + struct rt_mmcsd_card *card = mmc->card; + struct rt_mmcsd_cmd cmd = {0}; + uint32_t status; + if (sleep_enable != EMMC_SLEEP_DISABLE) { + err = mmcsd_deselect_cards(card); + LOG_I("cmd7 from tran to standby status %x \n", err); + } + memset_s(&cmd, sizeof(cmd), 0, sizeof(cmd)); + cmd.cmd_code = SLEEP_AWAKE; + cmd.arg = (card->rca << 16) | ((uint32_t)sleep_enable << 15); // 16 15 + cmd.flags = RESP_SPI_R1B | RESP_R1B | CMD_AC; + err = mmcsd_send_cmd(card->host, &cmd, 3); // 3 + if (err != 0) { + return err; + } + if (sleep_enable == EMMC_SLEEP_ENABLE) { + return err; + } + if (sleep_enable == EMMC_SLEEP_DISABLE) { + err = mmcsd_select_card(card); + LOG_E("cmd7 from standby to trans status %x \n", err); + } + do { + err = mmc_send_status(card, &status); + if (err != 0) { + return err; + } + } while (((status & R1_READY_FOR_DATA) == 0) || (hi_mmc_card_busy(card->host) != 0)); + LOG_I("cmd5 status %x \n", status); + return err; +} + +int sdio_read_fifo_block(struct rt_sdio_function *func, void *dst, uint32_t addr, uint32_t size) +{ + if (func == NULL || dst == NULL) { + return -EPARAMERR; + } + return sdio_io_rw_extended_block(func, 0, addr, 0, (unsigned char *)dst, size); +} + +int sdio_write_fifo_block(struct rt_sdio_function *func, uint32_t addr, void *src, uint32_t size) +{ + if (func == NULL || src == NULL) { + return -EPARAMERR; + } + return sdio_io_rw_extended_block(func, 1, addr, 0, (unsigned char *)src, size); +} + +int hi_sdio_io_rw_direct(struct rt_mmcsd_card *card, int writeflag, uint32_t fn, + uint32_t addr, uint8_t in, uint8_t *out) +{ + UNUSED(in); + if (card == NULL || out == NULL) { + return -EPARAMERR; + } + return sdio_io_rw_direct(card, writeflag, fn, addr, out, 0); +} + +void sdio_writeb(struct rt_sdio_function *func, uint8_t byte, uint32_t addr, int *err) +{ + if (func == NULL) { + *err = -EPARAMERR; + return; + } + int ret = sdio_io_rw_direct(func->card, 1, func->num, addr, &byte, 0); + if (err != NULL) { + *err = ret; + } +} + +uint8_t sdio_readb(struct rt_sdio_function *func, uint32_t addr, int *err) +{ + uint8_t val = 0; + if (func == NULL) { + *err = -EPARAMERR; + return 0xFF; + } + int ret = sdio_io_rw_direct(func->card, 0, func->num, addr, &val, 0); + *err = ret; + + if (ret != 0) { + return 0xFF; + } else { + return val; + } +} + +int sdio_writesb(struct rt_sdio_function *func, uint32_t addr, void *src, uint32_t size) +{ + if (func == NULL || src == NULL) { + return -EPARAMERR; + } + return sdio_io_rw_extended_block(func, 1, addr, 0, (uint8_t *)src, size); +} + +int sdio_readsb(struct rt_sdio_function *func, void *dst, uint32_t addr, uint32_t size) +{ + if (func == NULL || dst == NULL) { + return -EPARAMERR; + } + return sdio_io_rw_extended_block(func, 0, addr, 0, (uint8_t *)dst, size); +} + +int sdio_memcpy_fromio(struct rt_sdio_function *func, void *dst, uint32_t addr, uint32_t size) +{ + if (func == NULL || dst == NULL) { + return -EPARAMERR; + } + return sdio_io_rw_extended_block(func, 0, addr, 1, (uint8_t *)dst, size); +} + +void sdio_writew(struct rt_sdio_function *func, uint16_t byte, uint32_t addr, int *err) +{ + if (func == NULL) { + *err = -EPARAMERR; + return; + } + int ret = sdio_io_rw_extended_block(func, 1, addr, 1, (uint8_t *)&byte, 2); // 2 means 2byte + if (err != NULL) { + *err = ret; + } +} + +uint16_t sdio_readw(struct rt_sdio_function *func, uint32_t addr, int *err) +{ + uint16_t val = 0; + if (func == NULL) { + *err = -EPARAMERR; + return 0xFFFF; + } + int ret = sdio_io_rw_extended_block(func, 0, addr, 1, (uint8_t *)&val, 2); // 2 means 2byte + if (err != NULL) { + *err = ret; + } + + if (ret != 0) { + return 0xFFFF; + } else { + return val; + } +} + +void sdio_writel(struct rt_sdio_function *func, uint32_t byte, uint32_t addr, int *err) +{ + if (func == NULL) { + *err = -EPARAMERR; + return; + } + int ret = sdio_io_rw_extended_block(func, 1, addr, 1, (uint8_t *)&byte, 4); // 4 means 4byte + if (err != NULL) { + *err = ret; + } +} + +uint32_t sdio_readl(struct rt_sdio_function *func, uint32_t addr, int *err) +{ + uint32_t val = 0; + if (func == NULL) { + *err = -EPARAMERR; + return 0xFFFFFFFF; + } + int ret = sdio_io_rw_extended_block(func, 0, addr, 1, (uint8_t *)&val, 4); // 4 means 4byte + if (err != NULL) { + *err = ret; + } + + if (ret != 0) { + return 0xFFFFFFFF; + } else { + return val; + } +} + +int sdio_reset(struct rt_mmcsd_card *card) +{ + int error; + uint8_t out = 0; + if (card == NULL) { + return -EPARAMERR; + } + error = sdio_io_rw_direct(card, 0, 0, SDIO_REG_CCCR_IO_ABORT, &out, 0); + if (error != 0) { + out = 0x08; + } else { + out |= 0x08; + } + error = sdio_io_rw_direct(card, 1, 0, SDIO_REG_CCCR_IO_ABORT, &out, 0); + return error; +} + +void hi_mmc_set_sdiom_clk_mode(sdiom_clk_cfg_e_type clk_type) +{ + if (clk_type < SDIO_HOST_HIGH_50MHZ_EMMC_HIGH_50MHZ || clk_type >= SDIOM_CLK_MODE_MAX_NUM) { + return; + } + mmc_set_sdiom_clk_mode((int)clk_type); +} + +int32_t hi_mmc_switch_cmd(struct rt_mmcsd_card *card, uint32_t cmd_arg_val) +{ + int32_t err; + if (card == NULL || card->host == NULL) { + return -EPARAMERR; + } + struct rt_mmcsd_host *host = card->host; + struct rt_mmcsd_cmd cmd = { 0 }; + uint32_t val, status; + uint32_t i = 0; + + cmd.cmd_code = SWITCH; + cmd.arg = cmd_arg_val; + cmd.flags = RESP_R1 | CMD_AC; + + err = mmcsd_send_cmd(host, &cmd, 1); + if (err != 0) { + return err; + } else { + for (i = 0; i < MMC_RETRY_TIMES; i++) { + err = mmc_send_status(card, ((uint32_t *)&val)); + status = R1_CURRENT_STATE(val); + if ((err == 0) && (status == MMC_CURRENT_STATE_TRAN)) { + break; + } else { + LOG_E("get mmc status err=%d, status=%d", err, status); + uapi_tcxo_delay_ms(MMC_RETRY_DELAY); + } + } + } + if (i == MMC_RETRY_TIMES) { + return -1; + } + return 0; +} + +int32_t hi_mmc_get_ext_csd(struct rt_mmcsd_card *card, void *ext_csd) +{ + struct rt_mmcsd_req req; + struct rt_mmcsd_cmd cmd; + struct rt_mmcsd_data data; + if (card == NULL || card->host == NULL || ext_csd == NULL) { + return -EPARAMERR; + } + memset_s(&req, sizeof(struct rt_mmcsd_req), 0, sizeof(struct rt_mmcsd_req)); + memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + memset_s(&data, sizeof(struct rt_mmcsd_data), 0, sizeof(struct rt_mmcsd_data)); + + req.cmd = &cmd; + req.data = &data; + cmd.cmd_code = SEND_EXT_CSD; + cmd.arg = 0; + cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC; + data.blksize = SECTOR_SIZE; + data.blks = 1; + data.flags = DATA_DIR_READ; + data.buf = (uint32_t *)ext_csd; + data.timeout_ns = DATA_TRANSFER_TIMEOUT; + data.timeout_clks = 0; + + mmcsd_send_request(card->host, &req); + if (cmd.err != 0) { + return cmd.err; + } + if (data.err != 0) { + return data.err; + } + return 0; +} + +int32_t hi_mmc_gen_cmd(struct rt_mmcsd_card *card, uint32_t cmd_arg_val, uint32_t *data_buf) +{ + struct rt_mmcsd_req req; + struct rt_mmcsd_cmd cmd; + struct rt_mmcsd_data data; + if (card == NULL || card->host == NULL || data_buf == NULL) { + return -EPARAMERR; + } + memset_s(&req, sizeof(struct rt_mmcsd_req), 0, sizeof(struct rt_mmcsd_req)); + memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + memset_s(&data, sizeof(struct rt_mmcsd_data), 0, sizeof(struct rt_mmcsd_data)); + + req.cmd = &cmd; + req.data = &data; + cmd.cmd_code = GEN_CMD; + cmd.arg = cmd_arg_val; + cmd.flags = RESP_R1 | CMD_ADTC; + data.blksize = SECTOR_SIZE; + data.blks = 1; + if ((cmd_arg_val & 0x1) != 0) { + data.flags = DATA_DIR_READ; + } else { + data.flags = DATA_DIR_WRITE; + } + data.buf = (uint32_t *)data_buf; + data.timeout_ns = DATA_TRANSFER_TIMEOUT; + data.timeout_clks = 0; + + mmcsd_send_request(card->host, &req); + if (cmd.err != 0) { + return cmd.err; + } + if (data.err != 0) { + return data.err; + } + return 0; +} + +int32_t hi_mmc_vendor_cmd(struct rt_mmcsd_card *card, uint32_t cmd_arg_val) +{ + int32_t err; + if (card == NULL || card->host == NULL) { + return -EPARAMERR; + } + struct rt_mmcsd_host *host = card->host; + struct rt_mmcsd_cmd cmd = { 0 }; + + cmd.cmd_code = VENDOR_CMD; + cmd.arg = cmd_arg_val; + cmd.flags = RESP_R1 | CMD_ADTC; + + err = mmcsd_send_cmd(host, &cmd, 1); + if (err != 0) { + return err; + } + return 0; +} + +uint32_t* hi_mmc_get_cid(struct rt_mmcsd_card *card) +{ + if (card == NULL) { + return NULL; + } + return (uint32_t*)(card->resp_cid); +} + +void hi_mmc_set_driver_capability(struct rt_mmcsd_host* host, emmc_phy_driver_capability_e_type cap) +{ + if (host == NULL) { + return; + } + mmc_set_driver_capability(host, (uint32_t)cap); +} + +int32_t hi_mmc_set_block_count(struct rt_mmcsd_card *card, uint32_t blk_cnt, uint8_t reliable_write_flag) +{ + int32_t err; + struct rt_mmcsd_cmd cmd = { 0 }; + + cmd.cmd_code = SET_BLOCK_COUNT; + if (reliable_write_flag == 1) { + cmd.arg = blk_cnt | SET_RELIABLE_WRITE; + } else { + cmd.arg = blk_cnt; + } + cmd.flags = RESP_R1 | CMD_AC; + err = mmcsd_send_cmd(card->host, &cmd, 3); // retry 3 times + if (err) { + LOG_E("cmd23 status err=%d, resp=%x", err, cmd.resp[0]); + } + return err; +} + +int32_t hi_mmc_rpmb_ioctl(struct rt_mmcsd_card *card, rpmb_data_t *rpmb_data, ioctl_data_t io_data) +{ + struct rt_mmcsd_cmd cmd, stop; + struct rt_mmcsd_data data; + struct rt_mmcsd_req req; + struct rt_mmcsd_host *host = card->host; + int32_t err; + uint32_t status; + + memset_s(&req, sizeof(struct rt_mmcsd_req), 0, sizeof(struct rt_mmcsd_req)); + memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + memset_s(&stop, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + memset_s(&data, sizeof(struct rt_mmcsd_data), 0, sizeof(struct rt_mmcsd_data)); + req.cmd = &cmd; + req.data = &data; + + mmcsd_host_lock(host); + cmd.arg = io_data.sector; + cmd.flags = RESP_R1 | CMD_ADTC; + data.blksize = SECTOR_SIZE; + data.blks = io_data.blks; + + if (io_data.rw_flag == MMC_READ) { + cmd.cmd_code = READ_MULTIPLE_BLOCK; + data.flags |= DATA_DIR_READ; + } else { + cmd.cmd_code = WRITE_MULTIPLE_BLOCK; + data.flags |= DATA_DIR_WRITE; + } + mmcsd_set_data_timeout(&data, card); + data.buf = (uint32_t *)rpmb_data; + if (io_data.reliable_flag == 1) { + hi_mmc_set_block_count(card, 1, 1); + } else { + hi_mmc_set_block_count(card, 1, 0); + } + mmcsd_send_request(host, &req); + mmcsd_host_unlock(host); + if ((cmd.err != 0) || (data.err != 0) || (stop.err != 0)) { + LOG_E("cmd.err=%x, data.err=%x, stop.err=%x\r\n", cmd.err, data.err, stop.err); + return -1; + } + + do { + err = mmc_send_status(card, (uint32_t *)&status); + if (err) { + return err; + } + } while (((status & R1_READY_FOR_DATA) == 0) || (hi_mmc_card_busy(card->host) != 0)); + + return 0; +} + +int32_t hi_mmc_write_rpmb(struct rt_mmcsd_card *card, uint32_t sector, uint32_t blks, + rpmb_data_t *rpmb_data, uint8_t reliable_flag) +{ + int32_t err = 0; + ioctl_data_t io_data; + io_data.sector = sector; + io_data.rw_flag = MMC_WRITE; + io_data.blks = blks; + io_data.reliable_flag = reliable_flag; + err = hi_mmc_rpmb_ioctl(card, rpmb_data, io_data); + return err; +} + +int32_t hi_mmc_read_rpmb(struct rt_mmcsd_card *card, uint32_t sector, uint32_t blks, rpmb_data_t *rpmb_data) +{ + int32_t err = 0; + ioctl_data_t io_data; + io_data.sector = sector; + io_data.rw_flag = MMC_READ; + io_data.blks = blks; + io_data.reliable_flag = 0; + err = hi_mmc_rpmb_ioctl(card, rpmb_data, io_data); + return err; +} + +int32_t hi_mmc_rpmb_get_write_counter(struct rt_mmcsd_card *card, uint32_t *counter, uint32_t *result) +{ + int err = 0; + memset_s(&g_rpmb_data, sizeof(rpmb_data_t), 0, sizeof(rpmb_data_t)); + g_rpmb_data.req_resp = (WRITE_COUNTER_READ_REQ << OFFSET_8); + + err = hi_mmc_write_rpmb(card, 0, 1, &g_rpmb_data, 0); + if (err != 0) { + LOG_E("mmc write rpmb error, err=%d", err); + return err; + } + + err = hi_mmc_read_rpmb(card, 0, 1, &g_rpmb_data); + if (err != 0) { + LOG_E("mmc read rpmb error, err=%d", err); + return err; + } + + *counter = (g_rpmb_data.write_cnt & 0x000000FF) << OFFSET_24; + *counter |= (g_rpmb_data.write_cnt & 0x0000FF00) << OFFSET_8; + *counter |= (g_rpmb_data.write_cnt & 0x00FF0000) >> OFFSET_8; + *counter |= (g_rpmb_data.write_cnt & 0xFF000000) >> OFFSET_24; + *result = (((g_rpmb_data.op_result & 0xff) << OFFSET_8) | ((g_rpmb_data.op_result & 0xff00) >> OFFSET_8)); + LOG_I("mmc rpmb request=%d, writecounter=%x, result=%d", + g_rpmb_data.req_resp, g_rpmb_data.write_cnt, g_rpmb_data.op_result); + + return err; +} + +int32_t hi_mmc_rpmb_set_key(struct rt_mmcsd_card *card, uint8_t *key, uint32_t *result) +{ + int err = 0; + memset_s(&g_rpmb_data, sizeof(rpmb_data_t), 0, sizeof(rpmb_data_t)); + + for (uint8_t i = 0; i < MAC_KEY_LEN; i++) { + g_rpmb_data.mac_key[i] = ((char *)key)[i]; + } + + g_rpmb_data.req_resp = (AUTH_KEY_REQ << OFFSET_8); + + err = hi_mmc_write_rpmb(card, 0, 1, &g_rpmb_data, 1); + if (err != 0) { + LOG_E("mmc write rpmb error, err=%d", err); + return err; + } + + memset_s(&g_rpmb_data, sizeof(rpmb_data_t), 0, sizeof(rpmb_data_t)); + g_rpmb_data.req_resp = (RESULT_READ_REQ << OFFSET_8); + err = hi_mmc_write_rpmb(card, 0, 1, &g_rpmb_data, 0); + if (err != 0) { + LOG_E("mmc write rpmb error, err=%d", err); + return err; + } + err = hi_mmc_read_rpmb(card, 0, 1, &g_rpmb_data); + if (err != 0) { + LOG_E("mmc read rpmb error, err=%d", err); + return err; + } + + *result = (((g_rpmb_data.op_result & 0xff) << OFFSET_8) | ((g_rpmb_data.op_result & 0xff00) >> OFFSET_8)); + LOG_I("mmc rpmb request=%d, result=%d", g_rpmb_data.req_resp, g_rpmb_data.op_result); + + return err; +} + +int32_t hi_mmc_rpmb_cmp_key(uint8_t *key) +{ + UNUSED(key); + uint8_t auth_data[HMAC_AUTH_DATA_LEN] = { 0 }; + int32_t err = 0; + uint8_t hmac[MAC_KEY_LEN] = { 0 }; + uint8_t *tmp_data = (uint8_t *)g_rpmb_data.data; + + err = memcpy_s(auth_data, HMAC_AUTH_DATA_LEN, tmp_data, HMAC_AUTH_DATA_LEN); + if (err != 0) { + LOG_E("hi_mmc_rpmb_cmp_key memcpy error, err=%d", err); + return -1; + } +#ifdef MEDTLS_MD + err = mbedtls_md_hmac(mbedtls_md_info_from_type(MBEDTLS_MD_SHA256), + key, MAC_KEY_LEN, auth_data, HMAC_AUTH_DATA_LEN, hmac); +#endif + if (err != 0) { + LOG_E("mbedtls hmac error, err=%d", err); + return -1; + } + err = memcmp(g_rpmb_data.mac_key, hmac, MAC_KEY_LEN); + if (err != 0) { + LOG_E("rpmb key check error, err=%d", err); + return -1; + } + return 0; +} + +void hi_mmc_err_recovery(void) +{ + struct rt_mmcsd_host *mmc = hi_mmc_get_host(SDIO_EMMC_ID); + int32_t non_recovery_flag = 0; + int32_t ret = 0; + uint32_t status, val, i; + if (mmc == NULL || mmc->card == NULL) { + LOG_E("get mmc error for getcardstate"); + return ; + } + g_req_flag = 0; + // 1. make sure the data has been transfered completed. + for (i = 0; i < MMC_RETRY_TIMES; i++) { + ret = mmc_send_status(mmc->card, ((uint32_t *)&val)); + status = R1_CURRENT_STATE(val); + if ((ret == 0) && (status == MMC_CURRENT_STATE_TRAN)) { + return; + } else { + uapi_tcxo_delay_ms(MMC_RETRY_DELAY); + } + } + LOG_E("wait to transfer the data, get mmc status err=%d, status=%d", ret, status); + // 2. make the host to reset CMD and DATA + if (mmc_detect_bus_error(mmc)) { + hi_mmc_reset_cmd_data(mmc); // reset the data and cmd line; + } + // 3. make the device to revovery to normal(CMD12) + for (i = 0; i < MMC_RETRY_TIMES; i++) { + ret = hi_mmc_send_stop_cmd(mmc, &status); // send cmd12 to stop the transmission + if ((ret == 0) && (R1_CURRENT_STATE(status) == MMC_CURRENT_STATE_TRAN)) { + LOG_E("recovery send cmd12 err=%d, status=%d", ret, status); + break; + } + uapi_tcxo_delay_ms(MMC_RETRY_DELAY); + } + LOG_E("wait to send cmd12, get mmc status err=%d, status=%d", ret, status); + if (i == MMC_RETRY_TIMES) { non_recovery_flag = 1; } + // 4. at last, judge host if it is ok, if not, record the flag to shareram. + if (non_recovery_flag == 1) { // emmc cannot recovery, need re-initial the device + hi_mmc_set_err_to_aon_area(); + } +} + +mmc_err_info_type_t* hi_mmc_get_emmc_failed_info(void) +{ + return hi_mmc_get_err_from_aon_area(); +} \ No newline at end of file diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/mmc_block.h b/code/sdk/bootloader/flashboot/brandy/emmc/mmc_block.h new file mode 100644 index 000000000..929d1bf06 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/mmc_block.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: MMC BLOCK HEADER FILE + * Author: + * Create: 2020-04 + */ +#ifndef MMC_BLOCK_H +#define MMC_BLOCK_H +#include "drv_mmc_adapter.h" + +typedef enum { + PART_CONFIG_AREA_DEFAULT = 0x0, + PART_CONFIG_AREA_BOOT1 = 0x1, + PART_CONFIG_AREA_BOOT2 = 0x2, + PART_CONFIG_AREA_RPMB = 0x3, +} PART_CONFIG_AREA; + +typedef enum { + SDIO_HOST_HIGH_50MHZ_EMMC_HIGH_50MHZ, + SDIO_HOST_HIGH_50MHZ_EMMC_LOW_32MHZ, + SDIO_HOST_LOW_32MHZ_EMMC_HIGH_50MHZ, + SDIO_HOST_LOW_32MHZ_EMMC_LOW_32MHZ, // closed pll + SDIOM_CLK_MODE_MAX_NUM = HAL_SDIOM_CLK_MODE_MAX_NUM +} sdiom_clk_cfg_e_type; + +typedef enum { + EMMC_PHY_IOCTL_DRIVER_CAPABILITY_0, + EMMC_PHY_IOCTL_DRIVER_CAPABILITY_1, + EMMC_PHY_IOCTL_DRIVER_CAPABILITY_2, + EMMC_PHY_IOCTL_DRIVER_CAPABILITY_3, + EMMC_PHY_IOCTL_DRIVER_CAPABILITY_4, + EMMC_PHY_IOCTL_DRIVER_CAPABILITY_5, + EMMC_PHY_IOCTL_DRIVER_CAPABILITY_6, + EMMC_PHY_IOCTL_DRIVER_CAPABILITY_7, +} emmc_phy_driver_capability_e_type; + +typedef enum { + EMMC_SLEEP_DISABLE = 0, + EMMC_SLEEP_ENABLE = 1, +} emmc_sleep_mode_e_type; + +int hi_mmc_init(struct rt_mmcsd_host *mmc); + +int hi_mmc_deinit(struct rt_mmcsd_host *mmc); + +int hi_mmc_get_cardstatus(void); + +int hi_mmc_erase(uint32_t start_sector, uint32_t nsectors, uint32_t type); + +int mmc_erase_arae(struct rt_mmcsd_card *card, const struct rt_mmcsd_req *req); + +int hi_mmc_set_ext_csd_partition_config(PART_CONFIG_AREA area); + +int hi_mmc_sleep_awake(emmc_sleep_mode_e_type sleep_enable); + +int sdio_read_fifo_block(struct rt_sdio_function *func, void *dst, uint32_t addr, uint32_t size); + +int sdio_write_fifo_block(struct rt_sdio_function *func, uint32_t addr, void *src, uint32_t size); + +int hi_sdio_io_rw_direct(struct rt_mmcsd_card *card, int writeflag, uint32_t fn, + uint32_t addr, uint8_t in, uint8_t *out); + +void sdio_writeb(struct rt_sdio_function *func, uint8_t byte, uint32_t addr, int *err); + +uint8_t sdio_readb(struct rt_sdio_function *func, uint32_t addr, int *err); + +int sdio_writesb(struct rt_sdio_function *func, uint32_t addr, void *src, uint32_t size); + +int sdio_readsb(struct rt_sdio_function *func, void *dst, uint32_t addr, uint32_t size); + +int sdio_memcpy_fromio(struct rt_sdio_function *func, void *dst, uint32_t addr, uint32_t size); + +void sdio_writew(struct rt_sdio_function *func, uint16_t byte, uint32_t addr, int *err); + +uint16_t sdio_readw(struct rt_sdio_function *func, uint32_t addr, int *err); + +void sdio_writel(struct rt_sdio_function *func, uint32_t byte, uint32_t addr, int *err); + +uint32_t sdio_readl(struct rt_sdio_function *func, uint32_t addr, int *err); + +int sdio_reset(struct rt_mmcsd_card *card); + +void hi_mmc_set_sdiom_clk_mode(sdiom_clk_cfg_e_type clk_type); + +int32_t hi_mmc_switch_cmd(struct rt_mmcsd_card *card, uint32_t cmd_arg_val); + +int32_t hi_mmc_get_ext_csd(struct rt_mmcsd_card *card, void *ext_csd); + +int32_t hi_mmc_vendor_cmd(struct rt_mmcsd_card *card, uint32_t cmd_arg_val); + +int32_t hi_mmc_gen_cmd(struct rt_mmcsd_card *card, uint32_t cmd_arg_val, uint32_t *data_buf); + +uint32_t* hi_mmc_get_cid(struct rt_mmcsd_card *card); + +void hi_mmc_set_driver_capability(struct rt_mmcsd_host* host, emmc_phy_driver_capability_e_type cap); + +int32_t hi_mmc_rpmb_get_write_counter(struct rt_mmcsd_card *card, uint32_t *counter, uint32_t *result); + +int32_t hi_mmc_rpmb_set_key(struct rt_mmcsd_card *card, uint8_t *key, uint32_t *result); + +int32_t hi_mmc_rpmb_cmp_key(uint8_t *key); + +void hi_mmc_err_recovery(void); + +mmc_err_info_type_t* hi_mmc_get_emmc_failed_info(void); +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_card.h b/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_card.h new file mode 100644 index 000000000..85cc96b45 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_card.h @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier : Apache-2.0 + * + * Change Logs : + * Date Author Notes + * 2011-07-25 weety first version + */ + +#ifndef __MMCSD_CARD_H__ +#define __MMCSD_CARD_H__ + +#include "mmcsd_host.h" +#ifdef __cplusplus +extern "C" { +#endif + +#define SD_SCR_BUS_WIDTH_1 (1 << 0) +#define SD_SCR_BUS_WIDTH_4 (1 << 2) +#define EXT_CSD_LEN_BY_4BYTES 128 + +struct rt_mmcsd_cid { + uint8_t mid; /* ManufacturerID */ + uint8_t prv; /* Product Revision */ + uint16_t oid; /* OEM/Application ID */ + uint32_t psn; /* Product Serial Number */ + uint8_t pnm[5]; /* Product Name */ + uint8_t reserved1; /* reserved */ + uint16_t mdt; /* Manufacturing Date */ + uint8_t crc; /* CID CRC */ + uint8_t reserved2; /* not used, always 1 */ +}; + +struct rt_mmcsd_csd { + uint8_t csd_structure; /* CSD register version */ + uint8_t spec_vers; + uint8_t taac; + uint8_t nsac; + uint8_t tran_speed; /* max data transfer rate */ + uint16_t card_cmd_class; /* card command classes */ + uint8_t rd_blk_len; /* max read data block length */ + uint8_t rd_blk_part; + uint8_t wr_blk_misalign; + uint8_t rd_blk_misalign; + uint8_t dsr_imp; /* DSR implemented */ + uint8_t c_size_mult; /* CSD 1.0 , device size multiplier */ + uint32_t c_size; /* device size */ + uint8_t r2w_factor; + uint8_t wr_blk_len; /* max wtire data block length */ + uint8_t wr_blk_partial; + uint8_t csd_crc; +}; + +struct rt_sd_scr { + uint8_t sd_version; + uint8_t sd_bus_widths; +}; + +struct rt_sdio_cccr { + uint8_t sdio_version; + uint8_t sd_version; + uint8_t direct_cmd : 1, /* Card Supports Direct Commands during data transfer + only SD mode, not used for SPI mode */ + multi_block : 1, /* Card Supports Multi-Block */ + read_wait : 1, /* Card Supports Read Wait + only SD mode, not used for SPI mode */ + suspend_resume : 1, /* Card supports Suspend/Resume + only SD mode, not used for SPI mode */ + s4mi : 1, /* generate interrupts during a 4-bit + multi-block data transfer */ + e4mi : 1, /* Enable the multi-block IRQ during + 4-bit transfer for the SDIO card */ + low_speed : 1, /* Card is a Low-Speed card */ + low_speed_4 : 1; /* 4-bit support for Low-Speed cards */ + + uint8_t bus_width : 1, /* Support SDIO bus width, 1 : 4bit, 0 : 1bit */ + cd_disable : 1, /* Connect[0]/Disconnect[1] the 10K-90K ohm pull-up + resistor on CD/DAT[3] (pin 1) of the card */ + power_ctrl : 1, /* Support Master Power Control */ + high_speed : 1; /* Support High-Speed */ +}; + +struct rt_sdio_cis { + uint16_t manufacturer; + uint16_t product; + uint16_t func0_blk_size; + uint32_t max_tran_speed; +}; + +/* + * SDIO function CIS tuple (unknown to the core) + */ +struct rt_sdio_function_tuple { + struct rt_sdio_function_tuple *next; + uint8_t code; + uint8_t size; + uint8_t *data; +}; + +struct rt_sdio_function; +typedef void (rt_sdio_irq_handler_t)(struct rt_sdio_function *); + +/* + * SDIO function devices + */ +struct rt_sdio_function { + struct rt_mmcsd_card *card; /* the card this device belongs to */ + rt_sdio_irq_handler_t *irq_handler; /* IRQ callback */ + uint8_t num; /* function number */ + + uint8_t func_code; /* Standard SDIO Function interface code */ + uint16_t manufacturer; /* manufacturer id */ + uint16_t product; /* product id */ + + uint32_t max_blk_size; /* maximum block size */ + uint32_t cur_blk_size; /* current block size */ + + uint32_t enable_timeout_val; /* max enable timeout in msec */ + + struct rt_sdio_function_tuple *tuples; + + void *priv; +}; + +#define SDIO_MAX_FUNCTIONS 7 + +struct rt_mmcsd_ext_csd { + uint8_t rev; + uint8_t erase_group_def; + uint8_t sec_feature_support; + uint8_t rel_sectors; + uint8_t rel_param; + uint8_t part_config; + uint8_t cache_ctrl; + uint8_t rst_n_function; + uint32_t part_time_ms; /* ms */ + uint32_t sa_timeout_ns; /* 100ns */ + uint32_t generic_cmd6_time_ms; /* 10ms */ + uint32_t power_off_longtime_ms; /* ms */ + uint32_t hs_max_dtr; + uint32_t sectors; + uint32_t card_type; + uint32_t hc_erase_size; /* In sectors */ + uint32_t hc_erase_timeout; /* In milliseconds */ + uint32_t sec_trim_mult; /* Secure trim multiplier */ + uint32_t sec_erase_mult; /* Secure erase multiplier */ + uint32_t trim_timeout; /* In milliseconds */ + bool enhanced_area_en; /* enable bit */ + uint64_t enhanced_area_offset; /* Units : Byte */ + uint32_t enhanced_area_size; /* Units : KB */ + uint32_t cache_size; /* Units : KB */ + bool hpi_en; /* HPI enablebit */ + bool hpi; /* HPI support bit */ + uint32_t hpi_cmd; /* cmd used as HPI */ + uint32_t data_sector_size; /* 512 bytes or 4KB */ + uint32_t data_tag_unit_size; /* DATA TAG UNIT size */ + uint32_t boot_ro_lock; /* ro lock support */ + uint32_t boot_size; + uint8_t raw_partition_support; /* 160 */ + uint8_t raw_erased_mem_count; /* 181 */ + uint8_t strobe_support; /* 184 */ + uint8_t raw_ext_csd_structure; /* 194 */ + uint8_t raw_card_type; /* 196 */ + uint8_t out_of_int_time; /* 198 */ + uint8_t raw_s_a_timeout; /* 217 */ + uint8_t raw_hc_erase_gap_size; /* 221 */ + uint8_t raw_erase_timeout_mult; /* 223 */ + uint8_t raw_hc_erase_grp_size; /* 224 */ + uint8_t raw_sec_trim_mult; /* 229 */ + uint8_t raw_sec_erase_mult; /* 230 */ + uint8_t raw_sec_feature_support; /* 231 */ + uint8_t raw_trim_mult; /* 232 */ + uint8_t raw_sectors[4]; /* 212 - 4 bytes */ +}; + + +struct rt_mmcsd_card { + struct rt_mmcsd_host *host; + uint32_t rca; /* card addr */ + uint32_t resp_cid[4]; /* card CID register */ + uint32_t resp_csd[4]; /* card CSD register */ + uint32_t resp_scr[2]; /* card SCR register */ + + uint16_t tacc_clks; /* data access time by ns */ + uint32_t tacc_ns; /* data access time by clk cycles */ + uint32_t max_data_rate; /* max data transfer rate */ + uint32_t card_capacity; /* card capacity, unit : KB */ + uint32_t card_blksize; /* card block size */ + uint32_t erase_size; /* erase size in sectors */ + uint16_t card_type; +#define CARD_TYPE_MMC 0 /* MMC card */ +#define CARD_TYPE_SD 1 /* SD card */ +#define CARD_TYPE_SDIO 2 /* SDIO card */ +#define CARD_TYPE_SDIO_COMBO 3 /* SD combo (IO+mem) card */ + + uint16_t flags; +#define CARD_FLAG_HIGHSPEED (1 << 0) /* SDIO bus speed 50MHz */ +#define CARD_FLAG_SDHC (1 << 1) /* SDHC card */ +#define CARD_FLAG_SDXC (1 << 2) /* SDXC card */ + + struct rt_sd_scr scr; + struct rt_mmcsd_csd csd; + uint32_t hs_max_data_rate; /* max data transfer rate in high speed mode */ + struct rt_mmcsd_ext_csd ext_csd; + uint32_t ext_csd_val[EXT_CSD_LEN_BY_4BYTES]; + uint8_t sdio_function_num; /* totol number of SDIO functions */ + struct rt_sdio_cccr cccr; /* common card info */ + struct rt_sdio_cis cis; /* common tuple info */ + struct rt_sdio_function *sdio_function[SDIO_MAX_FUNCTIONS + 1]; /* SDIO functions (devices) */ +}; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_cmd.h b/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_cmd.h new file mode 100644 index 000000000..5c301ad2c --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_cmd.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2011-07-25 weety first version + */ + +#ifndef __CMD_H__ +#define __CMD_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + /* class 1 */ +#define GO_IDLE_STATE 0 /* bc */ +#define SEND_OP_COND 1 /* bcr [31:0] OCR R3 */ +#define ALL_SEND_CID 2 /* bcr R2 */ +#define SET_RELATIVE_ADDR 3 /* ac [31:16] RCA R1 */ +#define SET_DSR 4 /* bc [31:16] RCA */ +#define SLEEP_AWAKE 5 /* bc [31:16] RCA sleep/awake stuff bits R1 */ +#define SWITCH 6 /* ac [31:0] See below R1b */ +#define SELECT_CARD 7 /* ac [31:16] RCA R1 */ +#define SEND_EXT_CSD 8 /* adtc R1 */ +#define SEND_CSD 9 /* ac [31:16] RCA R2 */ +#define SEND_CID 10 /* ac [31:16] RCA R2 */ +#define READ_DAT_UNTIL_STOP 11 /* adtc [31:0] dadr R1 */ +#define STOP_TRANSMISSION 12 /* ac R1b */ +#define SEND_STATUS 13 /* ac [31:16] RCA R1 */ +#define GO_INACTIVE_STATE 15 /* ac [31:16] RCA */ +#define SPI_READ_OCR 58 /* spi spi_R3 */ +#define SPI_CRC_ON_OFF 59 /* spi [0:0] flag spi_R1 */ + + /* class 2 */ +#define SET_BLOCKLEN 16 /* ac [31:0] block len R1 */ +#define READ_SINGLE_BLOCK 17 /* adtc [31:0] data addr R1 */ +#define READ_MULTIPLE_BLOCK 18 /* adtc [31:0] data addr R1 */ +#define SEND_TUNING_BLOCK 19 /* adtc R1 */ +#define SEND_TUNING_BLOCK_HS200 21 /* adtc R1 */ + /* class 3 */ +#define WRITE_DAT_UNTIL_STOP 20 /* adtc [31:0] data addr R1 */ + + /* class 4 */ +#define SET_BLOCK_COUNT 23 /* adtc [31:0] data addr R1 */ +#define WRITE_BLOCK 24 /* adtc [31:0] data addr R1 */ +#define WRITE_MULTIPLE_BLOCK 25 /* adtc R1 */ +#define PROGRAM_CID 26 /* adtc R1 */ +#define PROGRAM_CSD 27 /* adtc R1 */ + + /* class 6 */ +#define SET_WRITE_PROT 28 /* ac [31:0] data addr R1b */ +#define CLR_WRITE_PROT 29 /* ac [31:0] data addr R1b */ +#define SEND_WRITE_PROT 30 /* adtc [31:0] wpdata addr R1 */ + + /* class 5 */ +#define ERASE_GROUP_START 35 /* ac [31:0] data addr R1 */ +#define ERASE_GROUP_END 36 /* ac [31:0] data addr R1 */ +#define ERASE 38 /* ac R1b */ + + /* class 9 */ +#define FAST_IO 39 /* ac R4 */ +#define GO_IRQ_STATE 40 /* bcr R5 */ + + /* class 7 */ +#define LOCK_UNLOCK 42 /* adtc R1b */ + + /* class 8 */ +#define APP_CMD 55 /* ac [31:16] RCA R1 */ +#define GEN_CMD 56 /* adtc [0] RD/WR R1 */ + + +/* SD commands type argument response */ + /* class 0 */ +/* This is basically the same command as for MMC with some quirks. */ +#define SD_SEND_RELATIVE_ADDR 3 /* bcr R6 */ +#define SD_SEND_IF_COND 8 /* bcr [11:0] See below R7 */ + + /* class 10 */ +#define SD_SWITCH 6 /* adtc [31:0] See below R1 */ + + /* Application commands */ +#define SD_APP_SET_BUS_WIDTH 6 /* ac [1:0] bus width R1 */ +#define SD_APP_SEND_NUM_WR_BLKS 22 /* adtc R1 */ +#define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */ +#define SD_APP_SEND_SCR 51 /* adtc R1 */ + +#define SCR_SPEC_VER_0 0 /* Implements system specification 1.0 - 1.01 */ +#define SCR_SPEC_VER_1 1 /* Implements system specification 1.10 */ +#define SCR_SPEC_VER_2 2 /* Implements system specification 2.00 */ + + +/* SDIO commands type argument response */ +#define SD_IO_SEND_OP_COND 5 /* bcr [23:0] OCR R4 */ +#define SD_IO_RW_DIRECT 52 /* ac [31:0] See below R5 */ +#define SD_IO_RW_EXTENDED 53 /* adtc [31:0] See below R5 */ + + +/* CMD52 arguments */ +#define SDIO_ARG_CMD52_READ (0<<31) +#define SDIO_ARG_CMD52_WRITE (1u<<31) +#define SDIO_ARG_CMD52_FUNC_SHIFT 28 +#define SDIO_ARG_CMD52_FUNC_MASK 0x7 +#define SDIO_ARG_CMD52_RAW_FLAG (1u<<27) +#define SDIO_ARG_CMD52_REG_SHIFT 9 +#define SDIO_ARG_CMD52_REG_MASK 0x1ffff +#define SDIO_ARG_CMD52_DATA_SHIFT 0 +#define SDIO_ARG_CMD52_DATA_MASK 0xff +#define SDIO_R5_DATA(resp) ((resp)[0] & 0xff) + +/* CMD53 arguments */ +#define SDIO_ARG_CMD53_READ (0<<31) +#define SDIO_ARG_CMD53_WRITE (1u<<31) +#define SDIO_ARG_CMD53_FUNC_SHIFT 28 +#define SDIO_ARG_CMD53_FUNC_MASK 0x7 +#define SDIO_ARG_CMD53_BLOCK_MODE (1u<<27) +#define SDIO_ARG_CMD53_INCREMENT (1u<<26) +#define SDIO_ARG_CMD53_REG_SHIFT 9 +#define SDIO_ARG_CMD53_REG_MASK 0x1ffff +#define SDIO_ARG_CMD53_LENGTH_SHIFT 0 +#define SDIO_ARG_CMD53_LENGTH_MASK 0x1ff +#define SDIO_ARG_CMD53_LENGTH_MAX 511 + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_core.c b/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_core.c new file mode 100644 index 000000000..483959cf1 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_core.c @@ -0,0 +1,694 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2011-07-25 weety first version + */ + +#include "mmcsd_core.h" +#include "hal_mmc_common.h" +#include "mmc.h" + +#define DBG_TAG "SDIO" +#ifdef RT_SDIO_DEBUG +#define DBG_LVL DBG_LOG +#else +#define DBG_LVL DBG_INFO +#endif /* RT_SDIO_DEBUG */ + +#ifndef RT_MMCSD_STACK_SIZE +#define RT_MMCSD_STACK_SIZE 1024 +#endif +#ifndef RT_MMCSD_THREAD_PREORITY +#if (RT_THREAD_PRIORITY_MAX == 32) +#define RT_MMCSD_THREAD_PREORITY 0x16 +#else +#define RT_MMCSD_THREAD_PREORITY 0x40 +#endif +#endif +#define EMMC_PINMUX_NUM 10 +#define DELAY_10MS 10 +#define TIME_1000 1000 + +const uint8_t __lowest_bit_bitmap[] = { + 0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 00 */ + 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 10 */ + 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 20 */ + 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 30 */ + 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 40 */ + 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 50 */ + 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 60 */ + 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 70 */ + 7, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 80 */ + 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* 90 */ + 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* A0 */ + 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* B0 */ + 6, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* C0 */ + 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* D0 */ + 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0, /* E0 */ + 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0 /* F0 */ +}; + +/** + * This function finds the first bit set (beginning with the least significant bit) + * in value and return the index of that bit. + * + * Bits are numbered starting at 1 (the least significant bit). A return value of + * zero from any of these functions means that the argument was zero. + * + * @return return the index of the first bit set. If value is 0, then this function + * shall return 0. + */ +static int __rt_ffs(int value) +{ + if (value == 0) { return 0; } + + if (value & 0xff) { + return __lowest_bit_bitmap[value & 0xff] + 1; + } + + if (value & 0xff00) { + return __lowest_bit_bitmap[(value & 0xff00) >> 8] + 9; // 8 9 + } + + if (value & 0xff0000) { + return __lowest_bit_bitmap[(value & 0xff0000) >> 16] + 17; // 16 17 + } + + return __lowest_bit_bitmap[(value & 0xff000000) >> 24] + 25; // 24 25 +} + +int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card) +{ + UNUSED(card); + return 0; +} + +void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card) +{ + UNUSED(card); +} + +void mmcsd_host_lock(struct rt_mmcsd_host *host) +{ + if (host->flags & MMCSD_NO_USE_MUTEX) { + return; + } + non_os_enter_critical(); +} + +void mmcsd_host_unlock(struct rt_mmcsd_host *host) +{ + if (host->flags & MMCSD_NO_USE_MUTEX) { + return; + } + non_os_exit_critical(); +} + +void mmcsd_req_complete(struct rt_mmcsd_host *host) +{ + UNUSED(host); +} + +void mmcsd_send_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req) +{ + do { + req->cmd->retries--; + req->cmd->err = 0; + req->cmd->mrq = req; + if (req->data) { + req->cmd->data = req->data; + req->data->err = 0; + req->data->mrq = req; + if (req->stop) { + req->data->stop = req->stop; + req->stop->err = 0; + req->stop->mrq = req; + } + } + host->ops->request(host, req); + } while (req->cmd->err && (req->cmd->retries > 0)); +} + +int32_t mmcsd_send_cmd(struct rt_mmcsd_host *host, struct rt_mmcsd_cmd *cmd, int retries) +{ + struct rt_mmcsd_req req; + + (void)memset_s(&req, sizeof(struct rt_mmcsd_req), 0, sizeof(struct rt_mmcsd_req)); + (void)memset_s(cmd->resp, sizeof(cmd->resp), 0, sizeof(cmd->resp)); + cmd->retries = retries; + + req.cmd = cmd; + cmd->data = RT_NULL; + + mmcsd_send_request(host, &req); + return cmd->err; +} + +int32_t mmcsd_go_idle(struct rt_mmcsd_host *host) +{ + int32_t err; + struct rt_mmcsd_cmd cmd; + + if (!controller_is_spi(host)) { + mmcsd_set_chip_select(host, MMCSD_CS_HIGH); + uapi_tcxo_delay_ms(1); + } + + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + + cmd.cmd_code = GO_IDLE_STATE; + cmd.arg = 0; + cmd.flags = RESP_SPI_R1 | RESP_NONE | CMD_BC; + + err = mmcsd_send_cmd(host, &cmd, 0); + uapi_tcxo_delay_ms(1); + if (!controller_is_spi(host)) { + mmcsd_set_chip_select(host, MMCSD_CS_IGNORE); + uapi_tcxo_delay_ms(1); + } + + return err; +} + +int32_t mmcsd_spi_read_ocr(struct rt_mmcsd_host *host, int32_t high_capacity, uint32_t *ocr) +{ + struct rt_mmcsd_cmd cmd; + int32_t err; + + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + cmd.cmd_code = SPI_READ_OCR; + cmd.arg = high_capacity ? (1 << 30) : 0; // 30 bits + cmd.flags = RESP_SPI_R3; + + err = mmcsd_send_cmd(host, &cmd, 0); + *ocr = cmd.resp[1]; + return err; +} + +int32_t mmcsd_all_get_cid(struct rt_mmcsd_host *host, uint32_t *cid) +{ + int32_t err; + struct rt_mmcsd_cmd cmd; + + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + cmd.cmd_code = ALL_SEND_CID; + cmd.arg = 0; + cmd.flags = RESP_R2 | CMD_BCR; + err = mmcsd_send_cmd(host, &cmd, 3); // 3 times + if (err) { + return err; + } + + (void)memcpy_s(cid, sizeof(uint32_t) * 4, cmd.resp, sizeof(uint32_t) * 4); // 4 Bytes + return 0; +} + +int32_t mmcsd_get_cid(struct rt_mmcsd_host *host, uint32_t *cid) +{ + int32_t err, i; + struct rt_mmcsd_req req; + struct rt_mmcsd_cmd cmd; + struct rt_mmcsd_data data; + uint32_t *buf = RT_NULL; + + if (!controller_is_spi(host)) { + if (!host->card) { + return -RT_ERROR; + } + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + + cmd.cmd_code = SEND_CID; + cmd.arg = host->card->rca << 16; // 16 Bits + cmd.flags = RESP_R2 | CMD_AC; + err = mmcsd_send_cmd(host, &cmd, 3); // 3 times + if (err) { + return err; + } + + (void)memcpy_s(cid, sizeof(uint32_t) * 4, cmd.resp, sizeof(uint32_t) * 4); // 4 Bytes + return 0; + } + + buf = (uint32_t *)irmalloc(16); // 16 + if (!buf) { + LOG_E("allocate memory failed!"); + return -RT_ENOMEM; + } + + (void)memset_s(&req, sizeof(struct rt_mmcsd_req), 0, sizeof(struct rt_mmcsd_req)); + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + (void)memset_s(&data, sizeof(struct rt_mmcsd_data), 0, sizeof(struct rt_mmcsd_data)); + + req.cmd = &cmd; + req.data = &data; + + cmd.cmd_code = SEND_CID; + cmd.arg = 0; + + /* NOTE HACK: the RESP_SPI_R1 is always correct here, but we + * rely on callers to never use this with "native" calls for reading + * CSD or CID. Native versions of those commands use the R2 type, + * not R1 plus a data block. + */ + cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC; + + data.blksize = 16; // 16 + data.blks = 1; + data.flags = DATA_DIR_READ; + data.buf = buf; + /* + * The spec states that CSR and CID accesses have a timeout + * of 64 clock cycles. + */ + data.timeout_ns = 0; + data.timeout_clks = 64; // 64 + + mmcsd_send_request(host, &req); + + if (cmd.err || data.err) { + irfree(buf); + return -RT_ERROR; + } + + for (i = 0;i < 4; i++) { // 4 times + cid[i] = buf[i]; + } + irfree(buf); + + return 0; +} + +int32_t mmcsd_get_csd(struct rt_mmcsd_card *card, uint32_t *csd) +{ + int32_t err, i; + struct rt_mmcsd_req req; + struct rt_mmcsd_cmd cmd; + struct rt_mmcsd_data data; + uint32_t *buf = RT_NULL; + + if (!controller_is_spi(card->host)) { + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + + cmd.cmd_code = SEND_CSD; + cmd.arg = card->rca << 16; // 16 bits + cmd.flags = RESP_R2 | CMD_AC; + err = mmcsd_send_cmd(card->host, &cmd, 3); // 3 times + if (err) { + return err; + } + (void)memcpy_s(csd, sizeof(uint32_t) * 4, cmd.resp, sizeof(uint32_t) * 4); // 4 Bytes + return 0; + } + + buf = (uint32_t*)irmalloc(16); // 16 Bytes + if (!buf) { + LOG_E("allocate memory failed!"); + return -RT_ENOMEM; + } + + (void)memset_s(&req, sizeof(struct rt_mmcsd_req), 0, sizeof(struct rt_mmcsd_req)); + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + (void)memset_s(&data, sizeof(struct rt_mmcsd_data), 0, sizeof(struct rt_mmcsd_data)); + + req.cmd = &cmd; + req.data = &data; + + cmd.cmd_code = SEND_CSD; + cmd.arg = 0; + + /* NOTE HACK: the RESP_SPI_R1 is always correct here, but we + * rely on callers to never use this with "native" calls for reading + * CSD or CID. Native versions of those commands use the R2 type, + * not R1 plus a data block. + */ + cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC; + + data.blksize = 16; // blksize 16 + data.blks = 1; + data.flags = DATA_DIR_READ; + data.buf = buf; + + /* + * The spec states that CSR and CID accesses have a timeout + * of 64 clock cycles. + */ + data.timeout_ns = 0; + data.timeout_clks = 64; // to clk 64 + + mmcsd_send_request(card->host, &req); + + if (cmd.err || data.err) { + irfree(buf); + return -RT_ERROR; + } + + for (i = 0;i < 4; i++) { // 4 times + csd[i] = buf[i]; + } + irfree(buf); + return 0; +} + +static int32_t _mmcsd_select_card(struct rt_mmcsd_host *host, struct rt_mmcsd_card *card) +{ + int32_t err; + struct rt_mmcsd_cmd cmd; + + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + + cmd.cmd_code = SELECT_CARD; + + if (card) { + cmd.arg = card->rca << 16; // 16 bits + cmd.flags = RESP_R1 | CMD_AC; + } else { + cmd.arg = 0; + cmd.flags = RESP_NONE | CMD_AC; + } + + err = mmcsd_send_cmd(host, &cmd, 3); // 3 times + if (err) { + return err; + } + return 0; +} + +int32_t mmcsd_select_card(struct rt_mmcsd_card *card) +{ + return _mmcsd_select_card(card->host, card); +} + +int32_t mmcsd_deselect_cards(struct rt_mmcsd_card *card) +{ + return _mmcsd_select_card(card->host, RT_NULL); +} + +int32_t mmcsd_spi_use_crc(struct rt_mmcsd_host *host, int32_t use_crc) +{ + struct rt_mmcsd_cmd cmd; + int32_t err; + + (void)memset_s(&cmd, sizeof(struct rt_mmcsd_cmd), 0, sizeof(struct rt_mmcsd_cmd)); + + cmd.cmd_code = SPI_CRC_ON_OFF; + cmd.flags = RESP_SPI_R1; + cmd.arg = use_crc; + + err = mmcsd_send_cmd(host, &cmd, 0); + if (!err) { + host->spi_use_crc = use_crc; + } + return err; +} + +rt_inline void mmcsd_set_iocfg(struct rt_mmcsd_host *host) +{ + struct rt_mmcsd_io_cfg *io_cfg = &host->io_cfg; + + mmcsd_dbg("clock %uHz busmode %u powermode %u cs %u Vdd %u ""width %u \n", + io_cfg->clock, io_cfg->bus_mode, + io_cfg->power_mode, io_cfg->chip_select, io_cfg->vdd, + io_cfg->bus_width); + + host->ops->set_iocfg(host, io_cfg); +} + +/* + * Control chip select pin on a host. + */ +void mmcsd_set_chip_select(struct rt_mmcsd_host *host, int32_t mode) +{ + host->io_cfg.chip_select = mode; + mmcsd_set_iocfg(host); +} + +/* + * Sets the host clock to the highest possible frequency that + * is below "hz". + */ +void mmcsd_set_clock(struct rt_mmcsd_host *host, uint32_t clk) +{ + if (clk < host->freq_min) { + LOG_W("clock too low!"); + } + + host->io_cfg.clock = clk; + mmcsd_set_iocfg(host); +} + +/* + * Change the bus mode (open drain/push-pull) of a host. + */ +void mmcsd_set_bus_mode(struct rt_mmcsd_host *host, uint32_t mode) +{ + host->io_cfg.bus_mode = mode; + mmcsd_set_iocfg(host); +} + +/* + * Change data bus width of a host. + */ +void mmcsd_set_bus_width(struct rt_mmcsd_host *host, uint32_t width) +{ + host->io_cfg.bus_width = width; + mmcsd_set_iocfg(host); +} + +void mmcsd_set_data_timeout(struct rt_mmcsd_data *data, + const struct rt_mmcsd_card *card) +{ + uint32_t mult; + + if (card->card_type == CARD_TYPE_SDIO) { + data->timeout_ns = 1000000000; /* SDIO card 1s, 1000000000ns */ + data->timeout_clks = 0; + return; + } + + // SD cards use a 100 multiplier rather than 10 + mult = (card->card_type == CARD_TYPE_SD) ? 100 : 10; + + /* + * Scale up the multiplier (and therefore the timeout) by + * the r2w factor for writes. + */ + if (data->flags & DATA_DIR_WRITE) { + mult <<= card->csd.r2w_factor; + } + + data->timeout_ns = card->tacc_ns * mult; + data->timeout_clks = card->tacc_clks * mult; + + /* + * SD cards also have an upper limit on the timeout. + */ + if (card->card_type == CARD_TYPE_SD) { + uint32_t timeout_us, limit_us; + + timeout_us = data->timeout_ns / TIME_1000; + timeout_us += data->timeout_clks * TIME_1000 / + (card->host->io_cfg.clock / TIME_1000); + + if (data->flags & DATA_DIR_WRITE) + /* + * The limit is really 250 ms, but that is + * insufficient for some crappy cards. + */ + limit_us = 300000; // 300000 + else + limit_us = 100000; // 100000 + + /* + * SDHC cards always use these fixed values. + */ + if ((timeout_us > limit_us) || (card->flags & CARD_FLAG_SDHC)) { + data->timeout_ns = limit_us * TIME_1000; /* SDHC card fixed 250ms */ + data->timeout_clks = 0; + } + } + + if (controller_is_spi(card->host)) { + if (data->flags & DATA_DIR_WRITE) { + if (data->timeout_ns < 1000000000) { // 1000000000 + data->timeout_ns = 1000000000; /* 1s, 1000000000ns */ + } + } else { + if (data->timeout_ns < 100000000) { // 100000000 + data->timeout_ns = 100000000; /* 100ms, 100000000ns */ + } + } + } +} + +/* + * Mask off any voltages we don't support and select + * the lowest voltage + */ +uint32_t mmcsd_select_voltage(struct rt_mmcsd_host *host, uint32_t ocr) +{ + int bit; + extern int __rt_ffs(int value); + + ocr &= host->valid_ocr; + + bit = __rt_ffs(ocr); + if (bit) { + bit -= 1; + ocr &= 3 << bit; // 3 bit + host->io_cfg.vdd = bit; + mmcsd_set_iocfg(host); + } else { + LOG_W("host doesn't support card's voltages!"); + ocr = 0; + } + + return ocr; +} + +static void mmcsd_power_up(struct rt_mmcsd_host *host) +{ + int bit = __rt_fls(host->valid_ocr) - 1; + + host->io_cfg.vdd = bit; + if (controller_is_spi(host)) { + host->io_cfg.chip_select = MMCSD_CS_HIGH; + host->io_cfg.bus_mode = MMCSD_BUSMODE_PUSHPULL; + } else { + host->io_cfg.chip_select = MMCSD_CS_IGNORE; + host->io_cfg.bus_mode = MMCSD_BUSMODE_OPENDRAIN; + } + host->io_cfg.power_mode = MMCSD_POWER_UP; + host->io_cfg.bus_width = MMCSD_BUS_WIDTH_1; + mmcsd_set_iocfg(host); + + /* + * This delay should be sufficient to allow the power supply + * to reach the minimum voltage. + */ + uapi_tcxo_delay_ms(DELAY_10MS); + + host->io_cfg.clock = host->freq_min; + host->io_cfg.power_mode = MMCSD_POWER_ON; + mmcsd_set_iocfg(host); + + /* + * This delay must be at least 74 clock sizes, or 1 ms, or the + * time required to reach a stable voltage. + */ + uapi_tcxo_delay_ms(DELAY_10MS); +} + +static void mmcsd_power_off(struct rt_mmcsd_host *host) +{ + host->io_cfg.clock = 0; + host->io_cfg.vdd = 0; + if (!controller_is_spi(host)) { + host->io_cfg.bus_mode = MMCSD_BUSMODE_OPENDRAIN; + host->io_cfg.chip_select = MMCSD_CS_IGNORE; + } + host->io_cfg.power_mode = MMCSD_POWER_OFF; + host->io_cfg.bus_width = MMCSD_BUS_WIDTH_1; + mmcsd_set_iocfg(host); +} + +struct rt_mmcsd_host *mmcsd_alloc_host(void) +{ + struct rt_mmcsd_host *host; + + host = irmalloc(sizeof(struct rt_mmcsd_host)); + if (!host) { + PRINT("alloc host failed"); + return RT_NULL; + } + + (void)memset_s(host, sizeof(struct rt_mmcsd_host), 0, sizeof(struct rt_mmcsd_host)); + + host->max_seg_size = 65535; // seg size 65535 + host->max_dma_segs = 1; + host->max_blk_size = 512; // blk_size 512 + host->max_blk_count = 4096; // count 4096 + + hi_mmc_mutex_init(&host->bus_lock); + hi_mmc_sem_init(&host->sem_ack); + return host; +} + +void mmcsd_free_host(struct rt_mmcsd_host *host) +{ + irfree(host); +} + + +// added by hisi for init, no hotpluge, no detect, just init. +int hi_mmc_detect(struct rt_mmcsd_host *host) +{ + uint32_t ocr; + int32_t err; + int n; + + if (host->card == RT_NULL) { + mmcsd_host_lock(host); + mmcsd_power_up(host); + // config mmc pinmux + for (n = 0; n < EMMC_PINMUX_NUM; n++) { + writew(S_HGPIO + S_HGPIO6_OFFSET + n * 0x4, FUNC_EMMC); + } + mmcsd_go_idle(host); + mmcsd_send_if_cond(host, host->valid_ocr); + + err = sdio_io_send_op_cond(host, 0, &ocr); + if (!err) { + if (init_sdio(host, ocr)) { + mmcsd_power_off(host); + mmcsd_host_unlock(host); + return -1; + } + mmcsd_host_unlock(host); + return 0; + } + + /* + * detect SD card + */ + err = mmcsd_send_app_op_cond(host, 0, &ocr); + if (!err) { + if (init_sd(host, ocr)) { + mmcsd_power_off(host); + mmcsd_host_unlock(host); + return -1; + } + mmcsd_host_unlock(host); + return 0; + } + + /* + * detect mmc card + */ + err = mmc_send_op_cond(host, 0, &ocr); + if (!err) { + if (init_mmc(host, ocr)) { + mmcsd_power_off(host); + mmcsd_host_unlock(host); + return -1; + } + mmcsd_host_unlock(host); + return 0; + } + + mmcsd_host_unlock(host); + } else { + /* card removed */ + mmcsd_host_lock(host); + if (host->card->sdio_function_num == 0) { + irfree(host->card); + host->card = RT_NULL; + } + mmcsd_host_unlock(host); + return -1; + } + return -1; +} \ No newline at end of file diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_core.h b/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_core.h new file mode 100644 index 000000000..c725d6866 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_core.h @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2011-07-25 weety first version + */ + +#ifndef __CORE_H__ +#define __CORE_H__ + +#include "mmcsd_host.h" +#include "mmcsd_card.h" +#include "mmcsd_cmd.h" +#include "liteos_adapter.h" +#ifdef __cplusplus +extern "C" { +#endif +#define rt_memset(s, c, count) memset_s(s, count, c, count) +#define rt_memcpy(dst, src, count) memcpy_s(dst, count, src, count) + +#ifdef MMC_OPEN_ALL_LOG +#define mmcsd_dbg(fmt, ...) print_str(fmt, ##__VA_ARGS__) +#else +#define mmcsd_dbg(fmt, ...) +#endif + +struct rt_mmcsd_data { + uint32_t blksize; + uint32_t blks; + uint32_t *buf; + int32_t err; + uint32_t flags; +#define DATA_DIR_WRITE (1 << 0) +#define DATA_DIR_READ (1 << 1) +#define DATA_STREAM (1 << 2) +#define DATA_CMD_STOP (0x1<<5) +#define DATA_CMD_STOP_ENABLE(data) ((data)->flags & DATA_CMD_STOP) + unsigned int bytes_xfered; + + struct rt_mmcsd_cmd *stop; /* stop command */ + struct rt_mmcsd_req *mrq; /* associated request */ + + uint32_t timeout_ns; + uint32_t timeout_clks; +}; + +struct rt_mmcsd_cmd { + uint32_t cmd_code; + uint32_t arg; + uint32_t resp[4]; + uint32_t flags; +/* rsponse types + * bits:0~3 + */ +#define RESP_MASK (0xF) +#define RESP_NONE (0) +#define RESP_R1 (1 << 0) +#define RESP_R1B (2 << 0) +#define RESP_R2 (3 << 0) +#define RESP_R3 (4 << 0) +#define RESP_R4 (5 << 0) +#define RESP_R6 (6 << 0) +#define RESP_R7 (7 << 0) +#define RESP_R5 (8 << 0) /* SDIO command response type */ +/* command types + * bits:4~5 + */ +#define CMD_MASK (3 << 4) /* command type */ +#define CMD_AC (0 << 4) +#define CMD_ADTC (1 << 4) +#define CMD_BC (2 << 4) +#define CMD_BCR (3 << 4) + +#define resp_type(cmd) ((cmd)->flags & RESP_MASK) + +/* spi rsponse types + * bits:6~8 + */ +#define RESP_SPI_MASK (0x7 << 6) +#define RESP_SPI_R1 (1 << 6) +#define RESP_SPI_R1B (2 << 6) +#define RESP_SPI_R2 (3 << 6) +#define RESP_SPI_R3 (4 << 6) +#define RESP_SPI_R4 (5 << 6) +#define RESP_SPI_R5 (6 << 6) +#define RESP_SPI_R7 (7 << 6) + +#define spi_resp_type(cmd) ((cmd)->flags & RESP_SPI_MASK) +/* + * These are the command types + */ +#define cmd_type(cmd) ((cmd)->flags & CMD_MASK) + + int32_t retries; /* max number of retries */ + int32_t err; + + struct rt_mmcsd_data *data; + struct rt_mmcsd_req *mrq; /* associated request */ +}; +struct rt_mmcsd_erase { + uint32_t start_addr; + uint32_t len; + uint32_t type; +#define ERASE_TYPE_ERASE_GROUP 0x0 +#define ERASE_TYPE_TRIM_SECTOR 0x1 +#define ERASE_TYPE_DISCARD_SECTOR 0x3 +}; +struct rt_mmcsd_req { + struct rt_mmcsd_data *data; + struct rt_mmcsd_cmd *cmd; + struct rt_mmcsd_cmd *stop; + struct rt_mmcsd_erase *erase; +}; + +/* the following is response bit */ +#define R1_OUT_OF_RANGE (1 << 31) /* er, c */ +#define R1_ADDRESS_ERROR (1 << 30) /* erx, c */ +#define R1_BLOCK_LEN_ERROR (1 << 29) /* er, c */ +#define R1_ERASE_SEQ_ERROR (1 << 28) /* er, c */ +#define R1_ERASE_PARAM (1 << 27) /* ex, c */ +#define R1_WP_VIOLATION (1 << 26) /* erx, c */ +#define R1_CARD_IS_LOCKED (1 << 25) /* sx, a */ +#define R1_LOCK_UNLOCK_FAILED (1 << 24) /* erx, c */ +#define R1_COM_CRC_ERROR (1 << 23) /* er, b */ +#define R1_ILLEGAL_COMMAND (1 << 22) /* er, b */ +#define R1_CARD_ECC_FAILED (1 << 21) /* ex, c */ +#define R1_CC_ERROR (1 << 20) /* erx, c */ +#define R1_ERROR (1 << 19) /* erx, c */ +#define R1_UNDERRUN (1 << 18) /* ex, c */ +#define R1_OVERRUN (1 << 17) /* ex, c */ +#define R1_CID_CSD_OVERWRITE (1 << 16) /* erx, c, CID/CSD overwrite */ +#define R1_WP_ERASE_SKIP (1 << 15) /* sx, c */ +#define R1_CARD_ECC_DISABLED (1 << 14) /* sx, a */ +#define R1_ERASE_RESET (1 << 13) /* sr, c */ +#define R1_STATUS(x) ((x) & 0xFFFFE000) +#define R1_CURRENT_STATE(x) (((x) & 0x00001E00) >> 9) /* sx, b (4 bits) */ +#define R1_READY_FOR_DATA (1 << 8) /* sx, a */ +#define R1_APP_CMD (1 << 5) /* sr, c */ +#define R1_SWITCH_ERROR (1 << 7) /* sx, c */ + +#define R1_SPI_IDLE (1 << 0) +#define R1_SPI_ERASE_RESET (1 << 1) +#define R1_SPI_ILLEGAL_COMMAND (1 << 2) +#define R1_SPI_COM_CRC (1 << 3) +#define R1_SPI_ERASE_SEQ (1 << 4) +#define R1_SPI_ADDRESS (1 << 5) +#define R1_SPI_PARAMETER (1 << 6) +/* R1 bit 7 is always zero */ +#define R2_SPI_CARD_LOCKED (1 << 8) +#define R2_SPI_WP_ERASE_SKIP (1 << 9) /* or lock/unlock fail */ +#define R2_SPI_LOCK_UNLOCK_FAIL R2_SPI_WP_ERASE_SKIP +#define R2_SPI_ERROR (1 << 10) +#define R2_SPI_CC_ERROR (1 << 11) +#define R2_SPI_CARD_ECC_ERROR (1 << 12) +#define R2_SPI_WP_VIOLATION (1 << 13) +#define R2_SPI_ERASE_PARAM (1 << 14) +#define R2_SPI_OUT_OF_RANGE (1 << 15) /* or CSD overwrite */ +#define R2_SPI_CSD_OVERWRITE R2_SPI_OUT_OF_RANGE + +#define CARD_BUSY 0x80000000 /* Card Power up status bit */ + +/* R5 response bits */ +#define R5_COM_CRC_ERROR (1 << 15) +#define R5_ILLEGAL_COMMAND (1 << 14) +#define R5_ERROR (1 << 11) +#define R5_FUNCTION_NUMBER (1 << 9) +#define R5_OUT_OF_RANGE (1 << 8) +#define R5_STATUS(x) ((x) & 0xCB00) +#define R5_IO_CURRENT_STATE(x) (((x) & 0x3000) >> 12) + +/** + * fls - find last (most-significant) bit set + * @x: the word to search + * + * This is defined the same way as ffs + * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32 + */ + +rt_inline uint32_t __rt_fls(uint32_t val) +{ + uint32_t bit = 32; // 32 + + if (!val) { + return 0; + } + if (!(val & 0xffff0000u)) { + val <<= 16; // 16 + bit -= 16; // 16 + } + if (!(val & 0xff000000u)) { + val <<= 8; // 8 + bit -= 8; // 8 + } + if (!(val & 0xf0000000u)) { + val <<= 4; // 4 + bit -= 4; // 4 + } + if (!(val & 0xc0000000u)) { + val <<= 2; // 2bootloader/flashboot/brandy/emmc/sd.c + bit -= 2; // 2 + } + if (!(val & 0x80000000u)) { + bit -= 1; + } + + return bit; +} + +#define MMCSD_HOST_PLUGED 0 +#define MMCSD_HOST_UNPLUGED 1 + +void hi_mmc_mutex_init(mmc_mutex *mux); +void mmcsd_host_lock(struct rt_mmcsd_host *host); +void mmcsd_host_unlock(struct rt_mmcsd_host *host); +void hi_mmc_mutex_del(mmc_mutex mux); +int hi_mmc_sem_init(mmc_sem *sem); +int hi_mmc_sem_post(mmc_sem sem); +int hi_mmc_sem_pend(mmc_sem sem, uint32_t timeout); +int hi_mmc_sem_del(mmc_sem sem); +int hi_mmc_detect(struct rt_mmcsd_host *host); + +void mmcsd_req_complete(struct rt_mmcsd_host *host); +void mmcsd_send_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req); +int32_t mmcsd_send_cmd(struct rt_mmcsd_host *host, struct rt_mmcsd_cmd *cmd, int retries); +int32_t mmcsd_go_idle(struct rt_mmcsd_host *host); +int32_t mmcsd_spi_read_ocr(struct rt_mmcsd_host *host, int32_t high_capacity, uint32_t *ocr); +int32_t mmcsd_all_get_cid(struct rt_mmcsd_host *host, uint32_t *cid); +int32_t mmcsd_get_cid(struct rt_mmcsd_host *host, uint32_t *cid); +int32_t mmcsd_get_csd(struct rt_mmcsd_card *card, uint32_t *csd); +int32_t mmcsd_select_card(struct rt_mmcsd_card *card); +int32_t mmcsd_deselect_cards(struct rt_mmcsd_card *host); +int32_t mmcsd_spi_use_crc(struct rt_mmcsd_host *host, int32_t use_crc); +void mmcsd_set_chip_select(struct rt_mmcsd_host *host, int32_t mode); +void mmcsd_set_clock(struct rt_mmcsd_host *host, uint32_t clk); +void mmcsd_set_bus_mode(struct rt_mmcsd_host *host, uint32_t mode); +void mmcsd_set_bus_width(struct rt_mmcsd_host *host, uint32_t width); +void mmcsd_set_data_timeout(struct rt_mmcsd_data *data, const struct rt_mmcsd_card *card); +uint32_t mmcsd_select_voltage(struct rt_mmcsd_host *host, uint32_t ocr); +struct rt_mmcsd_host *mmcsd_alloc_host(void); +void mmcsd_free_host(struct rt_mmcsd_host *host); + +int rt_mmcsd_blk_init(void); +int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card); +void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card); + + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_host.h b/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_host.h new file mode 100644 index 000000000..507978edf --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/mmcsd_host.h @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2011-07-25 weety first version + */ + +#ifndef __HOST_H__ +#define __HOST_H__ + +#include "liteos_adapter.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct rt_mmcsd_io_cfg { + uint32_t clock; /* clock rate */ + uint16_t vdd; + +/* vdd stores the bit number of the selected voltage range from below. */ + + uint8_t bus_mode; /* command output mode */ + +#define MMCSD_BUSMODE_OPENDRAIN 1 +#define MMCSD_BUSMODE_PUSHPULL 2 + + uint8_t chip_select; /* SPI chip select */ + +#define MMCSD_CS_IGNORE 0 +#define MMCSD_CS_HIGH 1 +#define MMCSD_CS_LOW 2 + + uint8_t power_mode; /* power supply mode */ + +#define MMCSD_POWER_OFF 0 +#define MMCSD_POWER_UP 1 +#define MMCSD_POWER_ON 2 + + uint8_t bus_width; /* data bus width */ + +#define MMCSD_BUS_WIDTH_1 0 +#define MMCSD_BUS_WIDTH_4 2 +#define MMCSD_BUS_WIDTH_8 3 +}; + +struct rt_mmcsd_host; +struct rt_mmcsd_req; + +struct rt_mmcsd_host_ops { + void (*request)(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req); + void (*set_iocfg)(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg); + int32_t (*get_card_status)(struct rt_mmcsd_host *host); + void (*enable_sdio_irq)(struct rt_mmcsd_host *host, int32_t en); +}; + +struct rt_mmcsd_host { + struct rt_mmcsd_card *card; + const struct rt_mmcsd_host_ops *ops; + uint32_t freq_min; + uint32_t freq_max; + struct rt_mmcsd_io_cfg io_cfg; + uint32_t valid_ocr; /* current valid OCR */ +#define VDD_165_195 (1 << 7) /* VDD voltage 1.65 - 1.95 */ +#define VDD_20_21 (1 << 8) /* VDD voltage 2.0 ~ 2.1 */ +#define VDD_21_22 (1 << 9) /* VDD voltage 2.1 ~ 2.2 */ +#define VDD_22_23 (1 << 10) /* VDD voltage 2.2 ~ 2.3 */ +#define VDD_23_24 (1 << 11) /* VDD voltage 2.3 ~ 2.4 */ +#define VDD_24_25 (1 << 12) /* VDD voltage 2.4 ~ 2.5 */ +#define VDD_25_26 (1 << 13) /* VDD voltage 2.5 ~ 2.6 */ +#define VDD_26_27 (1 << 14) /* VDD voltage 2.6 ~ 2.7 */ +#define VDD_27_28 (1 << 15) /* VDD voltage 2.7 ~ 2.8 */ +#define VDD_28_29 (1 << 16) /* VDD voltage 2.8 ~ 2.9 */ +#define VDD_29_30 (1 << 17) /* VDD voltage 2.9 ~ 3.0 */ +#define VDD_30_31 (1 << 18) /* VDD voltage 3.0 ~ 3.1 */ +#define VDD_31_32 (1 << 19) /* VDD voltage 3.1 ~ 3.2 */ +#define VDD_32_33 (1 << 20) /* VDD voltage 3.2 ~ 3.3 */ +#define VDD_33_34 (1 << 21) /* VDD voltage 3.3 ~ 3.4 */ +#define VDD_34_35 (1 << 22) /* VDD voltage 3.4 ~ 3.5 */ +#define VDD_35_36 (1 << 23) /* VDD voltage 3.5 ~ 3.6 */ + uint32_t flags; /* define device capabilities */ +#define MMCSD_BUSWIDTH_4 (1 << 0) +#define MMCSD_BUSWIDTH_8 (1 << 1) +#define MMCSD_MUTBLKWRITE (1 << 2) +#define MMCSD_HOST_IS_SPI (1 << 3) +#define controller_is_spi(host) ((host)->flags & MMCSD_HOST_IS_SPI) +#define MMCSD_SUP_SDIO_IRQ (1 << 4) /* support signal pending SDIO IRQs */ +#define MMCSD_SUP_HIGHSPEED (1 << 5) /* support high speed */ +#define MMCSD_SUP_HS200 (1 << 6) /* support hs200 */ +#define MMCSD_SUP_HS400 (1 << 7) /* support hs400 */ +#define MMCSD_NON_OS_ENABLE (1 << 8) /* support non os enum */ +#define MMCSD_BUSWIDTH_1 (1 << 9) /* support 1 bit width */ +#define MMCSD_NO_USE_MUTEX (1 << 10) /* no use mutex */ + + uint32_t max_seg_size; /* maximum size of one dma segment */ + uint32_t max_dma_segs; /* maximum number of dma segments in one request */ + uint32_t max_blk_size; /* maximum block size */ + uint32_t max_blk_count; /* maximum block count */ + + uint32_t spi_use_crc; + mmc_mutex bus_lock; + mmc_sem sem_ack; + + uint32_t sdio_irq_num; + mmc_sem sdio_irq_sem; + mmc_thread sdio_irq_thread; + uint8_t id; + uint32_t driver_cap; /* phy mode driver capability */ + void *private_data; +}; + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/mshc_reg.h b/code/sdk/bootloader/flashboot/brandy/emmc/mshc_reg.h new file mode 100644 index 000000000..dd6585087 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/mshc_reg.h @@ -0,0 +1,375 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2018-2020. All rights reserved. + * Description: MSHC REG HEADER FILE + * Author: @CompanyNameTag + * Create: 2020-04 + */ + +#ifndef MSHC_REG_H +#define MSHC_REG_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +/* + * Controller registers + */ +#define MSHC_DMA_ADDRESS 0x00 +#define MSHC_ARGUMENT2 MSHC_DMA_ADDRESS + +#define MSHC_BLOCK_SIZE 0x04 +#define SDMA_BUF_BOUNDARY_512K 7 +#define MSHC_MAKE_BLKSZ(dma, blksz) ((((dma) & 0x7) << 12) | ((blksz) & 0xFFF)) + +#define MSHC_BLOCK_COUNT 0x06 + +#define MSHC_ARGUMENT 0x08 + +#define MSHC_TRANSFER_MODE 0x0C +#define MSHC_TRNS_DMA 0x01 +#define MSHC_TRNS_BLK_CNT_EN 0x02 +#define MSHC_TRNS_AUTO_CMD12 0x04 +#define MSHC_TRNS_AUTO_CMD23 0x08 +#define MSHC_TRNS_READ 0x10 +#define MSHC_TRNS_MULTI 0x20 + +#define MSHC_COMMAND 0x0E +#define MSHC_CMD_RESP_MASK 0x03 +#define MSHC_CMD_CRC 0x08 +#define MSHC_CMD_INDEX 0x10 +#define MSHC_CMD_DATA 0x20 +#define MSHC_CMD_ABORTCMD 0xC0 + +#define MSHC_CMD_RESP_NONE 0x00 +#define MSHC_CMD_RESP_LONG 0x01 +#define MSHC_CMD_RESP_SHORT 0x02 +#define MSHC_CMD_RESP_SHORT_BUSY 0x03 + +#define MSHC_MAKE_CMD(c, f) ((((c) & 0xff) << 8) | ((f) & 0xff)) +#define MSHC_GET_CMD(c) (((c)>>8) & 0x3f) + +#define MSHC_RESPONSE 0x10 + +#define MSHC_BUFFER 0x20 +#define MSHC_BUFFER_LEN 128 + +#define MSHC_PRESENT_STATE 0x24 +#define MSHC_CMD_INHIBIT 0x00000001 +#define MSHC_DATA_INHIBIT 0x00000002 +#define MSHC_DOING_WRITE 0x00000100 +#define MSHC_DOING_READ 0x00000200 +#define MSHC_SPACE_AVAILABLE 0x00000400 +#define MSHC_DATA_AVAILABLE 0x00000800 +#define MSHC_CARD_PRESENT 0x00010000 +#define MSHC_WRITE_PROTECT 0x00080000 +#define MSHC_DATA_LVL_MASK 0x00F00000 +#define MSHC_DATA_LVL_SHIFT 20 +#define MSHC_DATA_0_LVL_MASK 0x00100000 + +#define MSHC_HOST_CONTROL 0x28 +#define MSHC_CTRL_LED 0x01 +#define MSHC_CTRL_4BITBUS 0x02 +#define MSHC_CTRL_HISPD 0x04 +#define MSHC_CTRL_DMA_MASK 0x18 +#define MSHC_CTRL_SDMA 0x00 +#define MSHC_CTRL_ADMA1 0x08 +#define MSHC_CTRL_ADMA32 0x10 +#define MSHC_CTRL_ADMA64 0x18 +#define MSHC_CTRL_8BITBUS 0x20 + +#define MSHC_POWER_CONTROL 0x29 +#define MSHC_POWER_ON 0x01 +#define MSHC_POWER_180 0x0A +#define MSHC_POWER_300 0x0C +#define MSHC_POWER_330 0x0E + +#define MSHC_BLOCK_GAP_CONTROL 0x2A + +#define MSHC_WAKE_UP_CONTROL 0x2B +#define MSHC_WAKE_ON_INT 0x01 +#define MSHC_WAKE_ON_INSERT 0x02 +#define MSHC_WAKE_ON_REMOVE 0x04 + +#define MSHC_CLOCK_CONTROL 0x2C +#define MSHC_DIVIDER_SHIFT 8 +#define MSHC_DIVIDER_HI_SHIFT 6 +#define MSHC_DIV_MASK 0xFF +#define MSHC_DIV_MASK_LEN 8 +#define MSHC_DIV_HI_MASK 0x300 +#define MSHC_PROG_CLOCK_MODE 0x0020 +#define MSHC_CLOCK_PLL_EN 0x0008 +#define MSHC_CLOCK_CARD_EN 0x0004 +#define MSHC_CLOCK_INT_STABLE 0x0002 +#define MSHC_CLOCK_INT_EN 0x0001 + +#define MSHC_TIMEOUT_CONTROL 0x2E +#define MSHC_DEFINE_TIMEOUT 0xE + +#define MSHC_SOFTWARE_RESET 0x2F +#define MSHC_RESET_ALL 0x01 +#define MSHC_RESET_CMD 0x02 +#define MSHC_RESET_DATA 0x04 + +#define MSHC_TOUT_CTRL 0x2e + +#define MSHC_PWR_CTRL 0x29 +#define MSHC_PWR_CTRL_VDD2 0x1 + +#define MSHC_CLK_CTRL 0x2c +#define MSHC_CLK_CTRL_PLL (1 << 3) +#define MSHC_CLK_CTRL_CLK_EN (1 << 2) +#define MSHC_CLK_CTRL_INT_CLK (1 << 0) + +#define MSHC_NOR_INT_STATUS 0x30 +#define MSHC_ERR_INT_STATUS 0x32 +#define MSHC_NOR_INT_ENABLE 0x34 +#define MSHC_ERR_INT_ENABLE 0x36 +#define MSHC_NOR_SIGNAL_ENABLE 0x38 +#define MSHC_ERR_SIGNAL_ENABLE 0x3A + +#define MSHC_NOR_INT_MASK 0x0000FFFF +#define MSHC_ERR_INT_MASK 0xFFFF0000 +#define MSHC_ERR_INT_OFFSET 16 + +#define MSHC_INT_RESPONSE 0x00000001 +#define MSHC_INT_DATA_END 0x00000002 +#define MSHC_INT_BLK_GAP 0x00000004 +#define MSHC_INT_DMA_END 0x00000008 +#define MSHC_INT_SPACE_AVAIL 0x00000010 +#define MSHC_INT_DATA_AVAIL 0x00000020 +#define MSHC_INT_CARD_INSERT 0x00000040 +#define MSHC_INT_CARD_REMOVE 0x00000080 +#define MSHC_INT_CARD_INT 0x00000100 +#define MSHC_INT_ERROR 0x00008000 +#define MSHC_INT_TIMEOUT 0x00010000 +#define MSHC_INT_CRC 0x00020000 +#define MSHC_INT_END_BIT 0x00040000 +#define MSHC_INT_INDEX 0x00080000 +#define MSHC_INT_DATA_TIMEOUT 0x00100000 +#define MSHC_INT_DATA_CRC 0x00200000 +#define MSHC_INT_DATA_END_ERR 0x00400000 +#define MSHC_INT_BUS_POWER 0x00800000 +#define MSHC_INT_AUTO_CMD_ERR 0x01000000 +#define MSHC_INT_ADMA_ERROR 0x02000000 +// do not set it to the HW register +#define MSHC_INT_RESCAN_SW 0x80000000 + +#define MSHC_INT_NORMAL_MASK 0x00007FFF +#define MSHC_INT_ERROR_MASK 0xFFFF8000 + +#define MSHC_INT_CMD_MASK (MSHC_INT_RESPONSE | MSHC_INT_TIMEOUT | \ + MSHC_INT_CRC | MSHC_INT_END_BIT | MSHC_INT_INDEX | \ + MSHC_INT_AUTO_CMD_ERR) + +#define MSHC_INT_DATA_MASK (MSHC_INT_DATA_END | MSHC_INT_DMA_END | \ + MSHC_INT_DATA_AVAIL | MSHC_INT_SPACE_AVAIL | \ + MSHC_INT_DATA_TIMEOUT | MSHC_INT_DATA_CRC | \ + MSHC_INT_DATA_END_ERR | MSHC_INT_ADMA_ERROR | \ + MSHC_INT_BLK_GAP) + +#define MSHC_INT_CMDQ_EN (0x1 << 14) +#define MSHC_INT_ALL_MASK ((unsigned int)-1) + +#define MSHC_AUTO_CMD_HOSTCTRL2 0x3c +#define MSHC_AUTO_CMD_ERR 0x3C +#define MSHC_AUTO_CMD12_NOT_EXEC 0x0001 +#define MSHC_AUTO_CMD_TIMEOUT_ERR 0x0002 +#define MSHC_AUTO_CMD_CRC_ERR 0x0004 +#define MSHC_AUTO_CMD_ENDBIT_ERR 0x0008 +#define MSHC_AUTO_CMD_INDEX_ERR 0x0010 +#define MSHC_AUTO_CMD12_NOT_ISSUED 0x0080 +#define MSHC_AUTO_CMD_SEL 0x10000000 + +#define MSHC_HOST_CONTROL2 0x3E +#define MSHC_CTRL_UHS_MASK 0x0007 +#define MSHC_CTRL_UHS_SDR12 0x0000 +#define MSHC_CTRL_UHS_SDR25 0x0001 +#define MSHC_CTRL_UHS_SDR50 0x0002 +#define MSHC_CTRL_UHS_SDR104 0x0003 +#define MSHC_CTRL_UHS_DDR50 0x0004 +#define MSHC_CTRL_HS_SDR200 0x0005 /* reserved value in SDIO spec */ +#define MSHC_CTRL_HS400 0x0007 +#define MSHC_CTRL_VDD_180 0x0008 +#define MSHC_CTRL_DRV_TYPE_MASK 0x0030 +#define MSHC_CTRL_DRV_TYPE_B 0x0000 +#define MSHC_CTRL_DRV_TYPE_A 0x0010 +#define MSHC_CTRL_DRV_TYPE_C 0x0020 +#define MSHC_CTRL_DRV_TYPE_D 0x0030 +#define MSHC_CTRL_EXEC_TUNING 0x0040 +#define MSHC_CTRL_TUNED_CLK 0x0080 +#define MSHC_CTRL_ASYNC_INT_ENABL 0x4000 +#define MSHC_CTRL_PRESET_VAL_ENABLE 0x8000 + +#define MSHC_CAPABILITIES_1 0x40 +#define MSHC_TIMEOUT_CLK_MASK 0x0000003F +#define MSHC_TIMEOUT_CLK_SHIFT 0 +#define MSHC_TIMEOUT_CLK_UNIT 0x00000080 +#define MSHC_CLOCK_BASE_MASK 0x00003F00 +#define MSHC_CLOCK_V3_BASE_MASK 0x0000FF00 +#define MSHC_CLOCK_BASE_SHIFT 8 +#define MSHC_MAX_BLOCK_MASK 0x00030000 +#define MSHC_MAX_BLOCK_SHIFT 16 +#define MSHC_CAN_DO_8BIT 0x00040000 +#define MSHC_CAN_DO_ADMA2 0x00080000 +#define MSHC_CAN_DO_ADMA1 0x00100000 +#define MSHC_CAN_DO_HISPD 0x00200000 +#define MSHC_CAN_DO_SDMA 0x00400000 +#define MSHC_CAN_VDD_330 0x01000000 +#define MSHC_CAN_VDD_300 0x02000000 +#define MSHC_CAN_VDD_180 0x04000000 +#define MSHC_CAN_64BIT 0x10000000 +#define MSHC_CAN_ASYNC_INT 0x20000000 + +#define MSHC_SUPPORT_SDR50 0x00000001 +#define MSHC_SUPPORT_SDR104 0x00000002 +#define MSHC_SUPPORT_DDR50 0x00000004 +#define MSHC_DRIVER_TYPE_A 0x00000010 +#define MSHC_DRIVER_TYPE_C 0x00000020 +#define MSHC_DRIVER_TYPE_D 0x00000040 +#define MSHC_RETUNING_TIMER_COUNT_MASK 0x00000F00 +#define MSHC_RETUNING_TIMER_COUNT_SHIFT 8 +#define MSHC_USE_SDR50_TUNING 0x00002000 +#define MSHC_RETUNING_MODE_MASK 0x0000C000 +#define MSHC_RETUNING_MODE_SHIFT 14 +#define MSHC_CLOCK_MUL_MASK 0x00FF0000 +#define MSHC_CLOCK_MUL_SHIFT 16 +#define MSHC_CAN_DO_ADMA3 0x8000000 +#define MSHC_SUPPORT_HS400 0x80000000 + +#define MSHC_CAPABILITIES_2 0x44 + +#define MSHC_MAX_CURRENT 0x48 +#define MSHC_MAX_CURRENT_LIMIT 0xFF +#define MSHC_MAX_CURRENT_330_MASK 0x0000FF +#define MSHC_MAX_CURRENT_330_SHIFT 0 +#define MSHC_MAX_CURRENT_300_MASK 0x00FF00 +#define MSHC_MAX_CURRENT_300_SHIFT 8 +#define MSHC_MAX_CURRENT_180_MASK 0xFF0000 +#define MSHC_MAX_CURRENT_180_SHIFT 16 +#define MSHC_MAX_CURRENT_MULTIPLIER 4 + +/* 4C-4F reserved for more max current */ +#define MSHC_SET_ACMD12_ERROR 0x50 +#define MSHC_SET_INT_ERROR 0x52 + +#define MSHC_ADMA_ERROR 0x54 + +/* 55-57 reserved */ +#define MSHC_HI_SHIFT 32 +#define MSHC_ADMA_ADDRESS_LOW 0x58 /* addr[0:31] */ +#define MSHC_ADMA_ADDRESS_HIGH 0x5C /* addr[32:63] DO not support */ + +/* 60-FB reserved */ +#define MSHC_PRESET_FOR_SDR12 0x66 +#define MSHC_PRESET_FOR_SDR25 0x68 +#define MSHC_PRESET_FOR_SDR50 0x6A +#define MSHC_PRESET_FOR_SDR104 0x6C +#define MSHC_PRESET_FOR_DDR50 0x6E +#define MSHC_PRESET_FOR_HS400 0x74 /* Non-standard */ +#define MSHC_PRESET_DRV_MASK 0xC000 +#define MSHC_PRESET_DRV_SHIFT 14 +#define MSHC_PRESET_CLKGEN_SEL_MASK 0x400 +#define MSHC_PRESET_CLKGEN_SEL_SHIFT 10 +#define MSHC_PRESET_SDCLK_FREQ_MASK 0x3FF +#define MSHC_PRESET_SDCLK_FREQ_SHIFT 0 + +#define MSHC_SLOT_INT_STATUS 0xFC + +#define MSHC_HOST_VERSION 0xFE +#define MSHC_VENDOR_VER_MASK 0xFF00 +#define MSHC_VENDOR_VER_SHIFT 8 +#define MSHC_SPEC_VER_MASK 0x00FF +#define MSHC_SPEC_VER_SHIFT 0 +#define MSHC_SPEC_100 0 +#define MSHC_SPEC_200 1 +#define MSHC_SPEC_300 2 +#define MSHC_SPEC_400 3 +#define MSHC_SPEC_410 4 +#define MSHC_SPEC_420 5 + +// The value is from the register value of 0xe8. +#define MSHC_PVENDOR_ADDR_OFFSET 0x500 +#define MSHC_EMMC_CTRL (MSHC_PVENDOR_ADDR_OFFSET + 0x2c) +#define MSHC_CARD_IS_EMMC_START 1 +#define MSHC_CARD_IS_EMMC_BITS 1 +#define MSHC_CARD_IS_EMMC 1 +#define MSHC_ENH_STROBE_EN_START 8 +#define MSHC_ENH_STROBE_EN_BITS 1 +#define MSHC_ENH_STROBE_EN 1 + +#define MSHC_MSHC_CTRL (MSHC_PVENDOR_ADDR_OFFSET + 0x08) +#define MSHC_CMD_CONFLIT_CHECK 0x01 + +#define MSHC_AXI_MBIIU_CTRL (MSHC_PVENDOR_ADDR_OFFSET + 0x10) +#define MSHC_GM_WR_OSRC_LMT_MASK (0x7 << 24) +#define MSHC_GM_WR_OSRC_LMT_SEL(x) ((x) << 24) +#define MSHC_GM_RD_OSRC_LMT_MASK (0x7 << 16) +#define MSHC_GM_RD_OSRC_LMT_SEL(x) ((x) << 16) +#define MSHC_UNDEFL_INCR_EN 0x1 +#define MSHC_GM_WR_OSRC_LMT_VAL ((7) << 24) +#define MSHC_GM_RD_OSRC_LMT_VAL ((7) << 16) + +#define MSHC_AUTO_TUNING_CTRL (MSHC_PVENDOR_ADDR_OFFSET + 0x40) +#define MSHC_SW_TUNING_EN 0x00000010 +#define MSHC_AUTO_TUNING_STATUS (MSHC_PVENDOR_ADDR_OFFSET + 0x44) + +#define MSHC_CENTER_PH_CODE_MASK 0x000000ff +#define MSHC_PHASE_SEL_MASK 0xff +#define MSHC_FOUND_EDGE (0x1 << 11) +#define MSHC_EDGE_DETECT_EN (0x1 << 8) +#define MSHC_DOUT_EN_F_EDGE (0x1 << 6) +#define MSHC_DATA_DLY_EN (0x1 << 3) +#define MSHC_CMD_DLY_EN (0x1 << 2) + +/* + * End of controller registers. + */ +#define REG_MISC_CTRL14 0x14 +#define SDIO0_PWRSW_CTRL_1V8 (0x1 << 8) +#define SDIO0_PWRSW_EN (0x1 << 9) +#define SDIO0_PWRSW_SEL_1V8 (0x1 << 10) + +#define ADMA2_END 0x2 +#define MSHC_PHY_ADDR_OFFSET 0x1000 +#define MSHC_PHY_IOCTL_PUPD (MSHC_PHY_ADDR_OFFSET + 0x260) // IO pul-up/pull-down +#define MSHC_PHY_IOCTL_IOE (MSHC_PHY_ADDR_OFFSET + 0x26c) // IO direction +#define PHY_IOCTL_PUPD_VAL 0x2FF03FF // cmd and dat[0:7] pull up, DS pull down, clock pull disable +#define PHY_IOCTL_IOE_VAL 0x3FF06FF // cmd and dat[0:7] Input/Output enable, DS input enable, clk output enable +#define MSHC_PHY_IOCTL_RONSEL_1_0 (MSHC_PHY_ADDR_OFFSET + 0x264) // IO driver capability bit 0--bit1 +#define MSHC_PHY_IOCTL_OD_RONSEL_2 (MSHC_PHY_ADDR_OFFSET + 0x268) // IO driver capability bit2 +#define PHY_IOCTL_RONSEL_BIT0 0x1 +#define PHY_IOCTL_RONSEL_BIT1 0x2 +#define PHY_IOCTL_RONSEL_BIT2 0x4 +#define PHY_IOCTL_RONSEL_BIT0_VAL_1 0x7FF // value bit0 is 1, bit0--bit10 means [10:0] = {CLK, CMD, DS, DAT7[7:0]} +#define PHY_IOCTL_RONSEL_BIT1_VAL_1 0x7FF0000 // value bit1 is 1, bit16--bit26 +#define PHY_IOCTL_RONSEL_BIT2_VAL_1 0x7FF // value bit2 is 1, bit0--bit10 + +// This register control the initialization of the PHY. +// Please note that write to this register will be ignored if init_en is already at '1' state. +#define PHYINITCTRL (MSHC_PHY_ADDR_OFFSET + 0x004) +#define PHYCTRL2 (MSHC_PHY_ADDR_OFFSET + 0x248) +#define DLY_CTL (MSHC_PHY_ADDR_OFFSET + 0x250) +#define DLY_CTL1 (MSHC_PHY_ADDR_OFFSET + 0x254) + +#define PHY_INV_CLK 0x80000001 // Invert the TXCLK This register create 180 degree delay of TX clock. +#define PHYINITCTRL_DISABLE 0x30c +#define PHYINITCTRL_ENABLE 0x30d +#define PHY_INIT_EN_MASK 0x1 +#define PHY_SET_DLY_MEAS_EN 0xC1674800 +#define PHY_SET_DLY_MEAS_DIS 0xC1670800 +#define PHY_DLAY1_CODE_POS 8 +#define PHY_DLAY1_CODE_LEN 10 +#define PHY_DLAY3_CODE_POS 21 +#define PHY_DLAY3_CODE_LEN 10 +#define PHY_DLY_CODE_R_POS 0 +#define PHY_DLY_CODE_R_LEN 11 + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/rt_sys_header.h b/code/sdk/bootloader/flashboot/brandy/emmc/rt_sys_header.h new file mode 100644 index 000000000..00e0e592a --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/rt_sys_header.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2018-2020. All rights reserved. + * Description: rt-thread system HEADER FILE + * Author: + * Create: 2021-06 + */ +#ifndef RT_SYS_HEADER_H +#define RT_SYS_HEADER_H + +#define RT_THREAD_PRIORITY_MAX 32 +#define rt_inline static inline +/* RT-Thread error code definitions */ +#define RT_EOK 0 /**< There is no error */ +#define RT_ERROR 1 /**< A generic error happens */ +#define RT_ETIMEOUT 2 /**< Timed out */ +#define RT_EFULL 3 /**< The resource is full */ +#define RT_EEMPTY 4 /**< The resource is empty */ +#define RT_ENOMEM 5 /**< No memory */ +#define RT_ENOSYS 6 /**< No system */ +#define RT_EBUSY 7 /**< Busy */ +#define RT_EIO 8 /**< IO error */ +#define RT_EINTR 9 /**< Interrupted system call */ +#define RT_EINVAL 10 /**< Invalid argument */ +/** + * @brief initialize a list object + */ +#define RT_LIST_OBJECT_INIT(object) { &(object), &(object) } + +/* RT-Thread basic data type definitions */ +typedef signed char rt_int8_t; /**< 8bit integer type */ +typedef signed short rt_int16_t; /**< 16bit integer type */ +typedef signed int rt_int32_t; /**< 32bit integer type */ +typedef unsigned char rt_uint8_t; /**< 8bit unsigned integer type */ +typedef unsigned short rt_uint16_t; /**< 16bit unsigned integer type */ +typedef unsigned int rt_uint32_t; /**< 32bit unsigned integer type */ +typedef signed long long rt_int64_t; /**< 64bit integer type */ +typedef unsigned long long rt_uint64_t; /**< 64bit unsigned integer type */ +typedef int rt_bool_t; /**< boolean type */ +typedef long rt_base_t; /**< Nbit CPU related date type */ +typedef unsigned long rt_ubase_t; /**< Nbit unsigned CPU related data type */ +typedef rt_base_t rt_err_t; /**< Type for error number */ +typedef rt_uint32_t rt_time_t; /**< Type for time stamp */ +typedef rt_uint32_t rt_tick_t; /**< Type for tick count */ +typedef rt_base_t rt_flag_t; /**< Type for flags */ +typedef rt_ubase_t rt_size_t; /**< Type for size number */ +typedef rt_ubase_t rt_dev_t; /**< Type for device */ +typedef rt_base_t rt_off_t; /**< Type for offset */ + +typedef struct rt_list_node rt_list_t; /**< Type for lists. */ +/** + * Double List structure + */ +struct rt_list_node { + struct rt_list_node *next; /**< point to next node. */ + struct rt_list_node *prev; /**< point to prev node. */ +}; +/** + * @brief insert a node after a list + * + * @param l list to insert it + * @param n new node to be inserted + */ +rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n) +{ + l->next->prev = n; + n->next = l->next; + + l->next = n; + n->prev = l; +} +/** + * @brief get the struct for this entry + * @param node the entry point + * @param type the type of structure + * @param member the name of list in structure + */ +#define rt_list_entry(node, type, member) \ + rt_container_of(node, type, member) +/** + * rt_container_of - return the member address of ptr, if the type of ptr is the + * struct type. + */ +#define rt_container_of(ptr, type, member) \ + ((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member))) +/** + * @brief tests whether a list is empty + * @param l the list to test. + */ +rt_inline int rt_list_isempty(const rt_list_t *l) +{ + return l->next == l; +} +/** + * @brief remove node from list. + * @param n the node to remove from the list. + */ +rt_inline void rt_list_remove(rt_list_t *n) +{ + n->next->prev = n->prev; + n->prev->next = n->next; + + n->next = n->prev = n; +} +#endif \ No newline at end of file diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/sd.c b/code/sdk/bootloader/flashboot/brandy/emmc/sd.c new file mode 100644 index 000000000..472a9d42c --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/sd.c @@ -0,0 +1,667 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2011-07-25 weety first version + */ + +#include "mmcsd_core.h" +#include "rt_sys_header.h" +#include "sd.h" + +#define DBG_TAG "SDIO" +#ifdef RT_SDIO_DEBUG +#define DBG_LVL DBG_LOG +#else +#define DBG_LVL DBG_INFO +#endif /* RT_SDIO_DEBUG */ + +static const uint32_t tran_unit[] = { + 10000, 100000, 1000000, 10000000, + 0, 0, 0, 0 +}; + +static const uint8_t tran_value[] = { + 0, 10, 12, 13, 15, 20, 25, 30, + 35, 40, 45, 50, 55, 60, 70, 80, +}; + +static const uint32_t tacc_uint[] = { + 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, +}; + +static const uint8_t tacc_value[] = { + 0, 10, 12, 13, 15, 20, 25, 30, + 35, 40, 45, 50, 55, 60, 70, 80, +}; + +rt_inline uint32_t GET_BITS(uint32_t *resp, uint32_t start, uint32_t size) +{ + const int32_t __size = size; + const uint32_t __mask = (__size < 32 ? 1 << __size : 0) - 1; // 32 + const int32_t __off = 3 - ((start) / 32); // 3 32 + const int32_t __shft = (start) & 31; // 31 + uint32_t __res; + + __res = resp[__off] >> __shft; + if (__size + __shft > 32) { // 32 + __res |= resp[__off-1] << ((32 - __shft) % 32); // 32 + } + + return __res & __mask; +} + +static int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card) +{ + struct rt_mmcsd_csd *csd = &card->csd; + uint32_t *resp = card->resp_csd; + + csd->csd_structure = GET_BITS(resp, 126, 2); // 126 2 + + switch (csd->csd_structure) { + case 0: + csd->taac = GET_BITS(resp, 112, 8); // 112 8 + csd->nsac = GET_BITS(resp, 104, 8); // 104 8 + csd->tran_speed = GET_BITS(resp, 96, 8); // 96 8 + csd->card_cmd_class = GET_BITS(resp, 84, 12); // 84 12 + csd->rd_blk_len = GET_BITS(resp, 80, 4); // 80 4 + csd->rd_blk_part = GET_BITS(resp, 79, 1); // 79 1 + csd->wr_blk_misalign = GET_BITS(resp, 78, 1); // 78 1 + csd->rd_blk_misalign = GET_BITS(resp, 77, 1); // 77 1 + csd->dsr_imp = GET_BITS(resp, 76, 1); // 76 1 + csd->c_size = GET_BITS(resp, 62, 12); // 62 12 + csd->c_size_mult = GET_BITS(resp, 47, 3); // 47 3 + csd->r2w_factor = GET_BITS(resp, 26, 3); // 26 3 + csd->wr_blk_len = GET_BITS(resp, 22, 4); // 22 4 + csd->wr_blk_partial = GET_BITS(resp, 21, 1); // 21 1 + csd->csd_crc = GET_BITS(resp, 1, 7); // 1 7 + + card->card_blksize = 1 << csd->rd_blk_len; + card->card_capacity = (csd->c_size + 1) << (csd->c_size_mult + 2); // 2 + card->card_capacity *= card->card_blksize; + card->card_capacity >>= 10; /* unit:10KB */ + card->tacc_clks = csd->nsac * 100; // 100 + card->tacc_ns = (tacc_uint[csd->taac&0x07] * tacc_value[(csd->taac&0x78)>>3] + 9) / 10; // 3 9 10 + card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3]; // 3 + break; + case 1: + card->flags |= CARD_FLAG_SDHC; + + /* This field is fixed to 0Eh, which indicates 1 ms + The host should not use TAAC, NSAC, and R2W_FACTOR + to calculate timeout and should uses fixed timeout + values for read and write operations */ + csd->taac = GET_BITS(resp, 112, 8); // 112 8 + csd->nsac = GET_BITS(resp, 104, 8); // 104 8 + csd->tran_speed = GET_BITS(resp, 96, 8); // 96 8 + csd->card_cmd_class = GET_BITS(resp, 84, 12); // 84 12 + csd->rd_blk_len = GET_BITS(resp, 80, 4); // 80 4 + csd->rd_blk_part = GET_BITS(resp, 79, 1); // 79 1 + csd->wr_blk_misalign = GET_BITS(resp, 78, 1); // 78 1 + csd->rd_blk_misalign = GET_BITS(resp, 77, 1); // 77 1 + csd->dsr_imp = GET_BITS(resp, 76, 1); // 76 1 + csd->c_size = GET_BITS(resp, 48, 22); // 48 22 + + csd->r2w_factor = GET_BITS(resp, 26, 3); // 26 3 + csd->wr_blk_len = GET_BITS(resp, 22, 4); // 22 4 + csd->wr_blk_partial = GET_BITS(resp, 21, 1); // 21 1 + csd->csd_crc = GET_BITS(resp, 1, 7); // 1 7 + + card->card_blksize = 512; // 512 + card->card_capacity = (csd->c_size + 1) * 512; /* unit:512KB */ + card->tacc_clks = 0; + card->tacc_ns = 0; + card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3]; // 3 + break; + default: + LOG_E("unrecognised CSD structure version %d!", csd->csd_structure); + + return -RT_ERROR; + } + LOG_I("SD card capacity %d KB.", card->card_capacity); + + return 0; +} + +static int32_t mmcsd_parse_scr(struct rt_mmcsd_card *card) +{ + struct rt_sd_scr *scr = &card->scr; + uint32_t resp[4]; + + resp[3] = card->resp_scr[1]; // 3 1 + resp[2] = card->resp_scr[0]; // 2 0 + scr->sd_version = GET_BITS(resp, 56, 4); // 56 4 + scr->sd_bus_widths = GET_BITS(resp, 48, 4); // 48 4 + + return 0; +} + +static int32_t mmcsd_switch(struct rt_mmcsd_card *card) +{ + int32_t err = 0; + struct rt_mmcsd_host *host = card->host; + struct rt_mmcsd_req req; + struct rt_mmcsd_cmd cmd; + struct rt_mmcsd_data data; + uint8_t *buf; + + buf = (uint8_t*)rt_malloc(64); // 64 + if (!buf) { + LOG_E("alloc memory failed!"); + return -RT_ENOMEM; + } + + if (card->card_type != CARD_TYPE_SD) { + goto err; + } + + if (card->scr.sd_version < SCR_SPEC_VER_1) { + goto err; + } + + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + + cmd.cmd_code = SD_SWITCH; + cmd.arg = 0x00FFFFF1; + cmd.flags = RESP_R1 | CMD_ADTC; + + rt_memset(&data, 0, sizeof(struct rt_mmcsd_data)); + + mmcsd_set_data_timeout(&data, card); + + data.blksize = 64; // 64 + data.blks = 1; + data.flags = DATA_DIR_READ; + data.buf = (uint32_t *)buf; + + rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); + + req.cmd = &cmd; + req.data = &data; + + mmcsd_send_request(host, &req); + + if (cmd.err || data.err) { + goto err1; + } + + if (buf[13] & 0x02) { // 13 + card->hs_max_data_rate = 50000000; // 50000000 + } + + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + + cmd.cmd_code = SD_SWITCH; + cmd.arg = 0x80FFFFF1; + cmd.flags = RESP_R1 | CMD_ADTC; + + rt_memset(&data, 0, sizeof(struct rt_mmcsd_data)); + + mmcsd_set_data_timeout(&data, card); + + data.blksize = 64; // 64 + data.blks = 1; + data.flags = DATA_DIR_READ; + data.buf = (uint32_t *)buf; + + rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); + + req.cmd = &cmd; + req.data = &data; + + mmcsd_send_request(host, &req); + + if (cmd.err || data.err) { + goto err1; + } + + if ((buf[16] & 0xF) != 1) { // 16 + LOG_I("switching card to high speed failed!"); + goto err; + } + + card->flags |= CARD_FLAG_HIGHSPEED; + +err: + rt_free(buf); + return 0; + +err1: + if (cmd.err) { + err = cmd.err; + } + + if (data.err) { + err = data.err; + } + + return err; +} + +static rt_err_t mmcsd_app_cmd(struct rt_mmcsd_host *host, struct rt_mmcsd_card *card) +{ + rt_err_t err; + struct rt_mmcsd_cmd cmd = {0}; + + cmd.cmd_code = APP_CMD; + + if (card) { + cmd.arg = card->rca << 16; // 16 + cmd.flags = RESP_R1 | CMD_AC; + } else { + cmd.arg = 0; + cmd.flags = RESP_R1 | CMD_BCR; + } + + err = mmcsd_send_cmd(host, &cmd, 0); + if (err) { + return err; + } + + /* Check that card supported application commands */ + if (!controller_is_spi(host) && !(cmd.resp[0] & R1_APP_CMD)) { + return -RT_ERROR; + } + + return RT_EOK; +} + + +rt_err_t mmcsd_send_app_cmd(struct rt_mmcsd_host *host, + struct rt_mmcsd_card *card, + struct rt_mmcsd_cmd *cmd, + uint32_t retry) +{ + struct rt_mmcsd_req req; + + uint32_t i; + rt_err_t err; + + err = -RT_ERROR; + + /* + * We have to resend MMC_APP_CMD for each attempt so + * we cannot use the retries field in mmc_command + */ + for (i = 0;i <= retry; i++) { + rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); + + err = mmcsd_app_cmd(host, card); + if (err) { + /* no point in retrying; no APP commands allowed */ + if (controller_is_spi(host)) { + if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND) { + break; + } + } + continue; + } + + rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); + rt_memset(cmd->resp, 0, sizeof(cmd->resp)); + req.cmd = cmd; + mmcsd_send_request(host, &req); + + err = cmd->err; + if (!cmd->err) { + break; + } + + /* no point in retrying illegal APP commands */ + if (controller_is_spi(host)) { + if (cmd->resp[0] & R1_SPI_ILLEGAL_COMMAND) { + break; + } + } + } + + return err; +} + +rt_err_t mmcsd_app_set_bus_width(struct rt_mmcsd_card *card, int32_t width) +{ + rt_err_t err; + struct rt_mmcsd_cmd cmd; + + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + cmd.cmd_code = SD_APP_SET_BUS_WIDTH; + cmd.flags = RESP_R1 | CMD_AC; + + switch (width) { + case MMCSD_BUS_WIDTH_1: + cmd.arg = MMCSD_BUS_WIDTH_1; + break; + case MMCSD_BUS_WIDTH_4: + cmd.arg = MMCSD_BUS_WIDTH_4; + break; + default: + return -RT_ERROR; + } + + err = mmcsd_send_app_cmd(card->host, card, &cmd, 3); // 3 times + if (err) { + return err; + } + + return RT_EOK; +} + +rt_err_t mmcsd_send_app_op_cond(struct rt_mmcsd_host *host, uint32_t ocr, uint32_t *rocr) +{ + struct rt_mmcsd_cmd cmd; + uint32_t i; + rt_err_t err = RT_EOK; + + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + + cmd.cmd_code = SD_APP_OP_COND; + if (controller_is_spi(host)) { + cmd.arg = ocr & (1 << 30); /* SPI only defines one bit 30 */ + } else { + cmd.arg = ocr; + } + cmd.flags = RESP_SPI_R1 | RESP_R3 | CMD_BCR; + + for (i = 100; i; i--) { // 100 + err = mmcsd_send_app_cmd(host, RT_NULL, &cmd, 3); // 3 + if (err) { + break; + } + + /* if we're just probing, do a single pass */ + if (ocr == 0) { + break; + } + + /* otherwise wait until reset completes */ + if (controller_is_spi(host)) { + if (!(cmd.resp[0] & R1_SPI_IDLE)) { + break; + } + } else { + if (cmd.resp[0] & CARD_BUSY) { + break; + } + } + + err = -RT_ETIMEOUT; + mmcsd_delay_ms(10); // delay 10ms + } + + if (rocr && !controller_is_spi(host)) { + *rocr = cmd.resp[0]; + } + + return err; +} + +/* + * To support SD 2.0 cards, we must always invoke SD_SEND_IF_COND + * before SD_APP_OP_COND. This command will harmlessly fail for + * SD 1.0 cards. + */ +rt_err_t mmcsd_send_if_cond(struct rt_mmcsd_host *host, uint32_t ocr) +{ + struct rt_mmcsd_cmd cmd; + rt_err_t err; + uint8_t pattern; + + cmd.cmd_code = SD_SEND_IF_COND; + cmd.arg = (((ocr & 0xFF8000) != 0) << 8) | 0xAA; // 8 + cmd.flags = RESP_SPI_R7 | RESP_R7 | CMD_BCR; + + err = mmcsd_send_cmd(host, &cmd, 0); + if (err) { + return err; + } + + if (controller_is_spi(host)) { + pattern = cmd.resp[1] & 0xFF; + } else { + pattern = cmd.resp[0] & 0xFF; + } + + if (pattern != 0xAA) { + return -RT_ERROR; + } + return RT_EOK; +} + +rt_err_t mmcsd_get_card_addr(struct rt_mmcsd_host *host, uint32_t *rca) +{ + rt_err_t err; + struct rt_mmcsd_cmd cmd; + + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + + cmd.cmd_code = SD_SEND_RELATIVE_ADDR; + cmd.arg = 0; + cmd.flags = RESP_R6 | CMD_BCR; + + err = mmcsd_send_cmd(host, &cmd, 3); // 3 + if (err) { + return err; + } + *rca = cmd.resp[0] >> 16; // 16 + + return RT_EOK; +} + +#define be32_to_cpu(x) ((uint32_t)( \ + (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ + (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ + (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \ + (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24))) + +int32_t mmcsd_get_scr(struct rt_mmcsd_card *card, uint32_t *scr) +{ + int32_t err; + struct rt_mmcsd_req req; + struct rt_mmcsd_cmd cmd; + struct rt_mmcsd_data data; + + err = mmcsd_app_cmd(card->host, card); + if (err) { + return err; + } + + rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + rt_memset(&data, 0, sizeof(struct rt_mmcsd_data)); + + req.cmd = &cmd; + req.data = &data; + + cmd.cmd_code = SD_APP_SEND_SCR; + cmd.arg = 0; + cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC; + + data.blksize = 8; // 8 + data.blks = 1; + data.flags = DATA_DIR_READ; + data.buf = scr; + + mmcsd_set_data_timeout(&data, card); + mmcsd_send_request(card->host, &req); + if (cmd.err) { + return cmd.err; + } + if (data.err) { + return data.err; + } + + scr[0] = be32_to_cpu(scr[0]); + scr[1] = be32_to_cpu(scr[1]); + + return 0; +} + + +static int32_t mmcsd_sd_init_card(struct rt_mmcsd_host *host, uint32_t ocr) +{ + struct rt_mmcsd_card *card; + int32_t err; + uint32_t resp[4]; // 4 + uint32_t max_data_rate; + + mmcsd_go_idle(host); + + /* + * If SD_SEND_IF_COND indicates an SD 2.0 + * compliant card and we should set bit 30 + * of the ocr to indicate that we can handle + * block-addressed SDHC cards. + */ + err = mmcsd_send_if_cond(host, ocr); + if (!err) { + ocr |= 1 << 30; // 30 + } + + err = mmcsd_send_app_op_cond(host, ocr, RT_NULL); + if (err) { + goto err; + } + + if (controller_is_spi(host)) { + err = mmcsd_get_cid(host, resp); + } else { + err = mmcsd_all_get_cid(host, resp); + } + if (err) { + goto err; + } + + card = rt_malloc(sizeof(struct rt_mmcsd_card)); + if (!card) { + LOG_E("malloc card failed!"); + err = -RT_ENOMEM; + goto err; + } + rt_memset(card, 0, sizeof(struct rt_mmcsd_card)); + + card->card_type = CARD_TYPE_SD; + card->host = host; + rt_memcpy(card->resp_cid, resp, sizeof(card->resp_cid)); + + /* + * For native busses: get card RCA and quit open drain mode. + */ + if (!controller_is_spi(host)) { + err = mmcsd_get_card_addr(host, &card->rca); + if (err) { + goto err1; + } + + mmcsd_set_bus_mode(host, MMCSD_BUSMODE_PUSHPULL); + } + + err = mmcsd_get_csd(card, card->resp_csd); + if (err) { goto err1; } + err = mmcsd_parse_csd(card); + if (err) { goto err1; } + + if (!controller_is_spi(host)) { + err = mmcsd_select_card(card); + if (err) { goto err1; } + } + + err = mmcsd_get_scr(card, card->resp_scr); + if (err) { goto err1; } + + mmcsd_parse_scr(card); + if (controller_is_spi(host)) { + err = mmcsd_spi_use_crc(host, 1); + if (err) { goto err1; } + } + + /* + * change SD card to high-speed, only SD2.0 spec + */ + err = mmcsd_switch(card); + if (err) { goto err1; } + + /* set bus speed */ + max_data_rate = (unsigned int)-1; + + if (card->flags & CARD_FLAG_HIGHSPEED) { + if (max_data_rate > card->hs_max_data_rate) { + max_data_rate = card->hs_max_data_rate; + } + } else if (max_data_rate > card->max_data_rate) { + max_data_rate = card->max_data_rate; + } + + mmcsd_set_clock(host, max_data_rate); + + /* switch bus width */ + if ((host->flags & MMCSD_BUSWIDTH_4) && (card->scr.sd_bus_widths & SD_SCR_BUS_WIDTH_4)) { + err = mmcsd_app_set_bus_width(card, MMCSD_BUS_WIDTH_4); + if (err) { goto err1; } + mmcsd_set_bus_width(host, MMCSD_BUS_WIDTH_4); + } + + host->card = card; + return 0; + +err1: + rt_free(card); +err: + + return err; +} + +/* + * Starting point for SD card init + */ +int32_t init_sd(struct rt_mmcsd_host *host, uint32_t ocr) +{ + int32_t err = 0; + uint32_t current_ocr; + /* + * We need to get OCR a different way for SPI + */ + if (controller_is_spi(host)) { + mmcsd_go_idle(host); + + err = mmcsd_spi_read_ocr(host, 0, &ocr); + if (err) { goto err; } + } + + if (ocr & VDD_165_195) { + LOG_I(" SD card claims to support the " "incompletely defined 'low voltage range'. This " "will be ignored."); + ocr &= ~VDD_165_195; + } + + current_ocr = mmcsd_select_voltage(host, ocr); + if (!current_ocr) { + err = -RT_ERROR; + goto err; + } + + /* + * Detect and init the card + */ + err = mmcsd_sd_init_card(host, current_ocr); + if (err) { goto err; } + + mmcsd_host_unlock(host); + err = rt_mmcsd_blk_probe(host->card); + if (err) { goto remove_card; } + mmcsd_host_lock(host); + + return 0; + +remove_card: + mmcsd_host_lock(host); + rt_mmcsd_blk_remove(host->card); + rt_free(host->card); + host->card = RT_NULL; +err: + + LOG_D("init SD card failed!"); + + return err; +} diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/sd.h b/code/sdk/bootloader/flashboot/brandy/emmc/sd.h new file mode 100644 index 000000000..186f74171 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/sd.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2011-07-25 weety first version + */ + +#ifndef __SD_H__ +#define __SD_H__ + +#include "mmcsd_host.h" + +#ifdef __cplusplus +extern "C" { +#endif + +rt_err_t mmcsd_send_if_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr); +rt_err_t mmcsd_send_app_op_cond(struct rt_mmcsd_host *host, rt_uint32_t ocr, rt_uint32_t *rocr); + +rt_err_t mmcsd_get_card_addr(struct rt_mmcsd_host *host, rt_uint32_t *rca); +rt_int32_t mmcsd_get_scr(struct rt_mmcsd_card *card, rt_uint32_t *scr); + +rt_int32_t init_sd(struct rt_mmcsd_host *host, rt_uint32_t ocr); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/sdio.c b/code/sdk/bootloader/flashboot/brandy/emmc/sdio.c new file mode 100644 index 000000000..e95e5f604 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/sdio.c @@ -0,0 +1,1180 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2012-01-13 weety first version + */ + +#include "mmcsd_core.h" +#include "liteos_adapter.h" +#include "systick.h" +#include "sd.h" +#include "sdio.h" + +#define DBG_TAG "SDIO" +#ifdef RT_SDIO_DEBUG +#define DBG_LVL DBG_LOG +#else +#define DBG_LVL DBG_INFO +#endif /* RT_SDIO_DEBUG */ + +#ifndef RT_SDIO_STACK_SIZE +#define RT_SDIO_STACK_SIZE 512 +#endif +#ifndef RT_SDIO_THREAD_PRIORITY +#define RT_SDIO_THREAD_PRIORITY 0x40 +#endif + +static rt_list_t sdio_cards = RT_LIST_OBJECT_INIT(sdio_cards); +static rt_list_t sdio_drivers = RT_LIST_OBJECT_INIT(sdio_drivers); + +struct sdio_card { + struct rt_mmcsd_card *card; + rt_list_t list; +}; + +struct sdio_driver { + struct rt_sdio_driver *drv; + rt_list_t list; +}; + +#ifndef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#endif +int32_t sdio_register_card(struct rt_mmcsd_card *card); + +static const uint8_t speed_value[16] = { + 0, 10, 12, 13, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 70, 80 +}; + +static const uint32_t speed_unit[8] = { + 10000, 100000, 1000000, 10000000, 0, 0, 0, 0 +}; + +rt_inline int32_t sdio_match_card(struct rt_mmcsd_card *card, const struct rt_sdio_device_id *id); +void sdio_free_cis(struct rt_sdio_function *func); + +#define LOS_TASK_STATUS_DETACHED 0x0100 // add liteos type and function in mmc code + +int32_t sdio_io_send_op_cond(struct rt_mmcsd_host *host, uint32_t ocr, uint32_t *cmd5_resp) +{ + struct rt_mmcsd_cmd cmd; + int32_t i, err = 0; + + RT_ASSERT(host != RT_NULL); + + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + + cmd.cmd_code = SD_IO_SEND_OP_COND; + cmd.arg = ocr; + cmd.flags = RESP_SPI_R4 | RESP_R4 | CMD_BCR; + + for (i = 100; i; i--) { // 100 + err = mmcsd_send_cmd(host, &cmd, 0); + if (err) + break; + + /* if we're just probing, do a single pass */ + if (ocr == 0) + break; + + /* otherwise wait until reset completes */ + if (controller_is_spi(host)) { + /* + * Both R1_SPI_IDLE and MMC_CARD_BUSY indicate + * an initialized card under SPI, but some cards + * (Marvell's) only behave when looking at this + * one. + */ + if (cmd.resp[1] & CARD_BUSY) + break; + } else { + if (cmd.resp[0] & CARD_BUSY) + break; + } + + err = -RT_ETIMEOUT; + mmcsd_delay_ms(10); // 10 + } + + if (cmd5_resp) { + *cmd5_resp = cmd.resp[controller_is_spi(host) ? 1 : 0]; + } + return err; +} + +int32_t sdio_io_rw_direct(struct rt_mmcsd_card *card, + int32_t rw, + uint32_t fn, + uint32_t reg_addr, + uint8_t *pdata, + uint8_t raw) +{ + struct rt_mmcsd_cmd cmd; + int32_t err; + + RT_ASSERT(card != RT_NULL); + RT_ASSERT(fn <= SDIO_MAX_FUNCTIONS); + RT_ASSERT(pdata != RT_NULL); + + if (reg_addr & ~SDIO_ARG_CMD53_REG_MASK) { return -RT_ERROR; } + + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + cmd.cmd_code = SD_IO_RW_DIRECT; + cmd.arg = rw ? SDIO_ARG_CMD52_WRITE : SDIO_ARG_CMD52_READ; + cmd.arg |= fn << SDIO_ARG_CMD52_FUNC_SHIFT; + cmd.arg |= raw ? SDIO_ARG_CMD52_RAW_FLAG : 0x00000000; + cmd.arg |= reg_addr << SDIO_ARG_CMD52_REG_SHIFT; + cmd.arg |= *pdata; + cmd.flags = RESP_SPI_R5 | RESP_R5 | CMD_AC; + + err = mmcsd_send_cmd(card->host, &cmd, 0); + if (err) { return err; } + if (!controller_is_spi(card->host)) { + if (cmd.resp[0] & R5_ERROR) { return -RT_EIO; } + if (cmd.resp[0] & R5_FUNCTION_NUMBER) { return -RT_ERROR; } + if (cmd.resp[0] & R5_OUT_OF_RANGE) { return -RT_ERROR; } + } + + if (!rw || raw) { + if (controller_is_spi(card->host)) { + *pdata = (cmd.resp[0] >> 8) & 0xFF; // 8 + } else { + *pdata = cmd.resp[0] & 0xFF; + } + } + + return 0; +} + +int32_t sdio_io_rw_extended(struct rt_mmcsd_card *card, + int32_t rw, + uint32_t fn, + uint32_t addr, + int32_t op_code, + uint8_t *buf, + uint32_t blocks, + uint32_t blksize) +{ + struct rt_mmcsd_req req; + struct rt_mmcsd_cmd cmd; + struct rt_mmcsd_data data; + + RT_ASSERT(card != RT_NULL); + RT_ASSERT(fn <= SDIO_MAX_FUNCTIONS); + RT_ASSERT(blocks != 1 || blksize <= RT_SDIO_STACK_SIZE); + RT_ASSERT(blocks != 0); + RT_ASSERT(blksize != 0); + + if (addr & ~SDIO_ARG_CMD53_REG_MASK) { return -RT_ERROR; } + + rt_memset(&req, 0, sizeof(struct rt_mmcsd_req)); + rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd)); + rt_memset(&data, 0, sizeof(struct rt_mmcsd_data)); + + req.cmd = &cmd; + req.data = &data; + + cmd.cmd_code = SD_IO_RW_EXTENDED; + cmd.arg = rw ? SDIO_ARG_CMD53_WRITE : SDIO_ARG_CMD53_READ; + cmd.arg |= fn << SDIO_ARG_CMD53_FUNC_SHIFT; + cmd.arg |= op_code ? SDIO_ARG_CMD53_INCREMENT : 0x00000000; + cmd.arg |= addr << SDIO_ARG_CMD53_REG_SHIFT; + if (blocks == 1 && blksize <= RT_SDIO_STACK_SIZE) { + cmd.arg |= (blksize == RT_SDIO_STACK_SIZE) ? 0 : blksize; /* 512 byte mode */ + } else { + cmd.arg |= SDIO_ARG_CMD53_BLOCK_MODE | blocks; /* block mode */ + } + cmd.flags = RESP_SPI_R5 | RESP_R5 | CMD_ADTC; + + data.blksize = blksize; + data.blks = blocks; + data.flags = rw ? DATA_DIR_WRITE : DATA_DIR_READ; + data.buf = (uint32_t *)buf; + + mmcsd_set_data_timeout(&data, card); + + mmcsd_send_request(card->host, &req); + + if (cmd.err) { return cmd.err; } + if (data.err) { return data.err; } + + if (!controller_is_spi(card->host)) { + if (cmd.resp[0] & R5_ERROR) { return -RT_EIO; } + if (cmd.resp[0] & R5_FUNCTION_NUMBER) { return -RT_ERROR; } + if (cmd.resp[0] & R5_OUT_OF_RANGE) { return -RT_ERROR; } + } + + return 0; +} + +rt_inline uint32_t sdio_max_block_size(struct rt_sdio_function *func) +{ + uint32_t size = MIN(func->card->host->max_seg_size, func->card->host->max_blk_size); + size = MIN(size, func->max_blk_size); + return MIN(size, 512u); /* maximum size for byte mode 512 */ +} + +int32_t sdio_io_rw_extended_block(struct rt_sdio_function *func, + int32_t rw, + uint32_t addr, + int32_t op_code, + uint8_t *buf, + uint32_t len) +{ + int32_t ret; + uint32_t left_size; + uint32_t max_blks, blks; + + left_size = len; + + /* Do the bulk of the transfer using block mode (if supported). */ + if (func->card->cccr.multi_block && (len > sdio_max_block_size(func))) { + max_blks = MIN(func->card->host->max_blk_count, func->card->host->max_seg_size / func->cur_blk_size); + max_blks = MIN(max_blks, 511u); // 511 + + while (left_size > func->cur_blk_size) { + blks = left_size / func->cur_blk_size; + if (blks > max_blks) { + blks = max_blks; + } + len = blks * func->cur_blk_size; + + ret = sdio_io_rw_extended(func->card, rw, func->num, addr, op_code, buf, blks, func->cur_blk_size); + if (ret) { return ret; } + left_size -= len; + buf += len; + if (op_code) { + addr += len; + } + } + } + + while (left_size > 0) { + len = MIN(left_size, sdio_max_block_size(func)); + ret = sdio_io_rw_extended(func->card, rw, func->num, addr, op_code, buf, 1, len); + if (ret) { return ret; } + left_size -= len; + buf += len; + if (op_code) { + addr += len; + } + } + return 0; +} + +uint8_t sdio_io_readb(struct rt_sdio_function *func, uint32_t reg, int32_t *err) +{ + uint8_t data = 0; + int32_t ret; + + ret = sdio_io_rw_direct(func->card, 0, func->num, reg, &data, 0); + if (err) { + *err = ret; + } + + return data; +} + +int32_t sdio_io_writeb(struct rt_sdio_function *func, uint32_t reg, uint8_t data) +{ + return sdio_io_rw_direct(func->card, 1, func->num, reg, &data, 0); +} + +rt_uint16_t sdio_io_readw(struct rt_sdio_function *func, uint32_t addr, int32_t *err) +{ + int32_t ret; + uint32_t dmabuf; + + if (err) { + *err = 0; + } + + ret = sdio_io_rw_extended_block(func, 0, addr, 1, (uint8_t *)&dmabuf, 2); // 2 + if (ret) { + if (err) { + *err = ret; + } + } + + return (rt_uint16_t)dmabuf; +} + +int32_t sdio_io_writew(struct rt_sdio_function *func, rt_uint16_t data, uint32_t addr) +{ + uint32_t dmabuf = data; + return sdio_io_rw_extended_block(func, 1, addr, 1, (uint8_t *)&dmabuf, 2); // 2 +} + +uint32_t sdio_io_readl(struct rt_sdio_function *func, uint32_t addr, int32_t *err) +{ + int32_t ret; + uint32_t dmabuf; + + if (err) { + *err = 0; + } + + ret = sdio_io_rw_extended_block(func, 0, addr, 1, (uint8_t *)&dmabuf, 4); // 4 + if (ret) { + if (err) { + *err = ret; + } + } + + return dmabuf; +} + +int32_t sdio_io_writel(struct rt_sdio_function *func, uint32_t data, uint32_t addr) +{ + uint32_t dmabuf = data; + return sdio_io_rw_extended_block(func, 1, addr, 1, (uint8_t *)&dmabuf, 4); // 4 +} + +int32_t sdio_io_read_multi_fifo_b(struct rt_sdio_function *func, uint32_t addr, uint8_t *buf, uint32_t len) +{ + return sdio_io_rw_extended_block(func, 0, addr, 0, buf, len); +} + +int32_t sdio_io_write_multi_fifo_b(struct rt_sdio_function *func, uint32_t addr, uint8_t *buf, uint32_t len) +{ + return sdio_io_rw_extended_block(func, 1, addr, 0, buf, len); +} + +int32_t sdio_io_read_multi_incr_b(struct rt_sdio_function *func, uint32_t addr, uint8_t *buf, uint32_t len) +{ + return sdio_io_rw_extended_block(func, 0, addr, 1, buf, len); +} + +int32_t sdio_io_write_multi_incr_b(struct rt_sdio_function *func, uint32_t addr, uint8_t *buf, uint32_t len) +{ + return sdio_io_rw_extended_block(func, 1, addr, 1, buf, len); +} + +static int32_t sdio_read_cccr(struct rt_mmcsd_card *card) +{ + int32_t ret; + int32_t cccr_version; + uint8_t data; + + rt_memset(&card->cccr, 0, sizeof(struct rt_sdio_cccr)); + + data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_CCCR_REV, &ret); + if (ret) { goto out; } + + cccr_version = data & 0x0f; + if (cccr_version > SDIO_CCCR_REV_3_00) { + LOG_E("unrecognised CCCR structure version %d", cccr_version); + return -RT_ERROR; + } + + card->cccr.sdio_version = (data & 0xf0) >> 4; // 4 + data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_CARD_CAPS, &ret); + if (ret) { goto out; } + + if (data & SDIO_CCCR_CAP_SMB) { + card->cccr.multi_block = 1; + } + if (data & SDIO_CCCR_CAP_LSC) { + card->cccr.low_speed = 1; + } + if (data & SDIO_CCCR_CAP_4BLS) { + card->cccr.low_speed_4 = 1; + } + if (data & SDIO_CCCR_CAP_4BLS) { + card->cccr.bus_width = 1; + } + + if (cccr_version >= SDIO_CCCR_REV_1_10) { + data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_POWER_CTRL, &ret); + if (ret) { goto out; } + if (data & SDIO_POWER_SMPC) { + card->cccr.power_ctrl = 1; + } + } + + if (cccr_version >= SDIO_CCCR_REV_1_20) { + data = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_SPEED, &ret); + if (ret) { goto out; } + if (data & SDIO_SPEED_SHS) { + card->cccr.high_speed = 1; + } + } + +out: + return ret; +} + +static int32_t cistpl_funce_func0(struct rt_mmcsd_card *card, const uint8_t *buf, uint32_t size) +{ + if (size < 0x04 || buf[0] != 0) { + return -RT_ERROR; + } + + /* TPLFE_FN0_BLK_SIZE */ + card->cis.func0_blk_size = buf[1] | (buf[2] << 8); // 2 8 + + /* TPLFE_MAX_TRAN_SPEED */ + card->cis.max_tran_speed = speed_value[(buf[3] >> 3) & 15] * speed_unit[buf[3] & 7]; // 3 15 7 + return 0; +} + +static int32_t cistpl_funce_func(struct rt_sdio_function *func, const uint8_t *buf, uint32_t size) +{ + uint32_t version; + uint32_t min_size; + + version = func->card->cccr.sdio_version; + min_size = (version == SDIO_SDIO_REV_1_00) ? 28 : 42; // 28 42 + + if (size < min_size || buf[0] != 1) { + return -RT_ERROR; + } + + /* TPLFE_MAX_BLK_SIZE */ + func->max_blk_size = buf[12] | (buf[13] << 8); // 12 13 8 + + /* TPLFE_ENABLE_TIMEOUT_VAL, present in ver 1.1 and above */ + if (version > SDIO_SDIO_REV_1_00) { + func->enable_timeout_val = (buf[28] | (buf[29] << 8)) * 10; // 28 29 8 10 + } else { + func->enable_timeout_val = 1000; /* 1000ms */ + } + return 0; +} + +static int32_t sdio_read_cis(struct rt_sdio_function *func) +{ + int32_t ret; + struct rt_sdio_function_tuple *curr, **prev; + uint32_t i, cisptr = 0; + uint8_t data; + uint8_t tpl_code, tpl_link; + + struct rt_mmcsd_card *card = func->card; + struct rt_sdio_function *func0 = card->sdio_function[0]; + + RT_ASSERT(func0 != RT_NULL); + + for (i = 0; i < 3; i++) { // 3 + data = sdio_io_readb(func0, SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_CIS + i, &ret); + if (ret) { return ret; } + cisptr |= data << (i * 8); // 8 + } + + prev = &func->tuples; + + do { + tpl_code = sdio_io_readb(func0, cisptr++, &ret); + if (ret) { break; } + + tpl_link = sdio_io_readb(func0, cisptr++, &ret); + if (ret) { break; } + + if ((tpl_code == CISTPL_END) || (tpl_link == 0xff)) { + break; + } + + if (tpl_code == CISTPL_NULL) { continue; } + + curr = rt_malloc(sizeof(struct rt_sdio_function_tuple) + tpl_link); + if (!curr) { return -RT_ENOMEM; } + curr->data = (uint8_t *)curr + sizeof(struct rt_sdio_function_tuple); + + for (i = 0; i < tpl_link; i++) { + curr->data[i] = sdio_io_readb(func0, cisptr + i, &ret); + if (ret) { break; } + } + if (ret) { + rt_free(curr); + break; + } + + switch (tpl_code) { + case CISTPL_MANFID: + if (tpl_link < 4) { // 4 + LOG_D("bad CISTPL_MANFID length"); + break; + } + if (func->num != 0) { + func->manufacturer = curr->data[0]; + func->manufacturer |= curr->data[1] << 8; // 8 + func->product = curr->data[2]; // 2 + func->product |= curr->data[3] << 8; // 8 3 + } else { + card->cis.manufacturer = curr->data[0]; + card->cis.manufacturer |= curr->data[1] << 8; // 8 + card->cis.product = curr->data[2]; // 2 + card->cis.product |= curr->data[3] << 8; // 3 8 + } + break; + case CISTPL_FUNCE: + if (func->num != 0) { + ret = cistpl_funce_func(func, curr->data, tpl_link); + } else { + ret = cistpl_funce_func0(card, curr->data, tpl_link); + } + + if (ret) { + LOG_D("bad CISTPL_FUNCE size %u " + "type %u", tpl_link, curr->data[0]); + } + + break; + case CISTPL_VERS_1: + if (tpl_link < 2) { // 2 + LOG_D("CISTPL_VERS_1 too short"); + } + break; + default: + /* this tuple is unknown to the core */ + curr->next = RT_NULL; + curr->code = tpl_code; + curr->size = tpl_link; + *prev = curr; + prev = &curr->next; + LOG_D("function %d, CIS tuple code %#x, length %d", func->num, tpl_code, tpl_link); + break; + } + + cisptr += tpl_link; + } while (1); + + /* + * Link in all unknown tuples found in the common CIS so that + * drivers don't have to go digging in two places. + */ + if (func->num != 0) { + *prev = func0->tuples; + } + + return ret; +} + + +void sdio_free_cis(struct rt_sdio_function *func) +{ + struct rt_sdio_function_tuple *tuple, *tmp; + struct rt_mmcsd_card *card = func->card; + + tuple = func->tuples; + + while (tuple && ((tuple != card->sdio_function[0]->tuples) || (!func->num))) { + tmp = tuple; + tuple = tuple->next; + rt_free(tmp); + } + + func->tuples = RT_NULL; +} + +static int32_t sdio_read_fbr(struct rt_sdio_function *func) +{ + int32_t ret; + uint8_t data; + struct rt_sdio_function *func0 = func->card->sdio_function[0]; + + data = sdio_io_readb(func0, SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_STD_FUNC_IF, &ret); + if (ret) { goto err; } + + data &= 0x0f; + if (data == 0x0f) { + data = sdio_io_readb(func0, SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_STD_IF_EXT, &ret); + if (ret) { goto err; } + } + + func->func_code = data; + +err: + return ret; +} + +static int32_t sdio_initialize_function(struct rt_mmcsd_card *card, uint32_t func_num) +{ + int32_t ret; + struct rt_sdio_function *func; + + RT_ASSERT(func_num <= SDIO_MAX_FUNCTIONS); + + func = rt_malloc(sizeof(struct rt_sdio_function)); + if (!func) { + LOG_E("malloc rt_sdio_function failed"); + ret = -RT_ENOMEM; + goto err; + } + rt_memset(func, 0, sizeof(struct rt_sdio_function)); + + func->card = card; + func->num = func_num; + + ret = sdio_read_fbr(func); + if (ret) { goto err1; } + + ret = sdio_read_cis(func); + if (ret) { goto err1; } + /* + * product/manufacturer id is optional for function CIS, so + * copy it from the card structure as needed. + */ + if (func->product == 0) { + func->manufacturer = card->cis.manufacturer; + func->product = card->cis.product; + } + card->sdio_function[func_num] = func; + return 0; + +err1: + sdio_free_cis(func); + rt_free(func); + card->sdio_function[func_num] = RT_NULL; + +err: + return ret; +} + +static int32_t sdio_set_highspeed(struct rt_mmcsd_card *card) +{ + int32_t ret; + uint8_t speed; + + if (!(card->host->flags & MMCSD_SUP_HIGHSPEED)) { return 0; } + if (!card->cccr.high_speed) { return 0; } + + speed = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_SPEED, &ret); + if (ret) { return ret; } + + speed |= SDIO_SPEED_EHS; + ret = sdio_io_writeb(card->sdio_function[0], SDIO_REG_CCCR_SPEED, speed); + if (ret) { return ret; } + card->flags |= CARD_FLAG_HIGHSPEED; + return 0; +} + +static int32_t sdio_set_bus_wide(struct rt_mmcsd_card *card) +{ + int32_t ret; + uint8_t busif; + + if (!(card->host->flags & MMCSD_BUSWIDTH_4)) { return 0; } + if (card->cccr.low_speed && !card->cccr.bus_width) { return 0; } + + busif = sdio_io_readb(card->sdio_function[0], SDIO_REG_CCCR_BUS_IF, &ret); + if (ret) { return ret; } + + busif |= SDIO_BUS_WIDTH_4BIT; + ret = sdio_io_writeb(card->sdio_function[0], SDIO_REG_CCCR_BUS_IF, busif); + if (ret) { return ret; } + + mmcsd_set_bus_width(card->host, MMCSD_BUS_WIDTH_4); + return 0; +} + +int32_t sdio_register_card(struct rt_mmcsd_card *card) +{ + struct sdio_card *sc; + struct sdio_driver *sd; + rt_list_t *l; + + sc = rt_malloc(sizeof(struct sdio_card)); + if (sc == RT_NULL) { + LOG_E("malloc sdio card failed"); + return -RT_ENOMEM; + } + + sc->card = card; + rt_list_insert_after(&sdio_cards, &sc->list); + + if (rt_list_isempty(&sdio_drivers)) { + goto out; + } + + for (l = (&sdio_drivers)->next; l != &sdio_drivers; l = l->next) { + sd = (struct sdio_driver *)rt_list_entry(l, struct sdio_driver, list); + if (sdio_match_card(card, sd->drv->id)) { + sd->drv->probe(card); + } + } + +out: + return 0; +} + +static int32_t sdio_init_card(struct rt_mmcsd_host *host, uint32_t ocr) +{ + int32_t err = 0; + int32_t i, function_num; + uint32_t cmd5_resp; + struct rt_mmcsd_card *card; + + err = sdio_io_send_op_cond(host, ocr, &cmd5_resp); + if (err) { goto err; } + + if (controller_is_spi(host)) { + err = mmcsd_spi_use_crc(host, host->spi_use_crc); + if (err) { goto err; } + } + + function_num = (cmd5_resp & 0x70000000) >> 28; // 28 + + card = rt_malloc(sizeof(struct rt_mmcsd_card)); + if (!card) { + LOG_E("malloc card failed"); + err = -RT_ENOMEM; + goto err; + } + rt_memset(card, 0, sizeof(struct rt_mmcsd_card)); + + card->card_type = CARD_TYPE_SDIO; + card->sdio_function_num = function_num; + card->host = host; + host->card = card; + + card->sdio_function[0] = rt_malloc(sizeof(struct rt_sdio_function)); + if (!card->sdio_function[0]) { + LOG_E("malloc sdio_func0 failed"); + err = -RT_ENOMEM; + goto err1; + } + rt_memset(card->sdio_function[0], 0, sizeof(struct rt_sdio_function)); + card->sdio_function[0]->card = card; + card->sdio_function[0]->num = 0; + + if (!controller_is_spi(host)) { + err = mmcsd_get_card_addr(host, &card->rca); + if (err) { goto err2; } + + mmcsd_set_bus_mode(host, MMCSD_BUSMODE_PUSHPULL); + } + + if (!controller_is_spi(host)) { + err = mmcsd_select_card(card); + if (err) { goto err2; } + } + + err = sdio_read_cccr(card); + if (err) { goto err2; } + + err = sdio_read_cis(card->sdio_function[0]); + if (err) { goto err2; } + + err = sdio_set_highspeed(card); + if (err) { goto err2; } + + if (card->flags & CARD_FLAG_HIGHSPEED) { + mmcsd_set_clock(host, 50000000); // 50000000 + } else { + mmcsd_set_clock(host, card->cis.max_tran_speed); + } + + err = sdio_set_bus_wide(card); + if (err) { goto err2; } + + for (i = 1; i < function_num + 1; i++) { + err = sdio_initialize_function(card, i); + if (err) { goto err3; } + } + + return 0; + +err3: + if (host->card) { + for (i = 1; i < host->card->sdio_function_num + 1; i++) { + if (host->card->sdio_function[i]) { + sdio_free_cis(host->card->sdio_function[i]); + rt_free(host->card->sdio_function[i]); + host->card->sdio_function[i] = RT_NULL; + rt_free(host->card); + host->card = RT_NULL; + break; + } + } + } + +err2: + if (host->card && host->card->sdio_function[0]) { + sdio_free_cis(host->card->sdio_function[0]); + rt_free(host->card->sdio_function[0]); + host->card->sdio_function[0] = RT_NULL; + } + +err1: + if (host->card) { + rt_free(host->card); + } + +err: + LOG_E("error %d while initialising SDIO card", err); + return err; +} + +int32_t init_sdio(struct rt_mmcsd_host *host, uint32_t ocr) +{ + int32_t err; + uint32_t current_ocr; + + RT_ASSERT(host != RT_NULL); + + if (ocr & 0x7F) { + LOG_W("Card ocr below the defined voltage rang."); + ocr &= ~0x7F; + } + + if (ocr & VDD_165_195) { + LOG_W("Can't support the low voltage SDIO card."); + ocr &= ~VDD_165_195; + } + + current_ocr = mmcsd_select_voltage(host, ocr); + if (!current_ocr) { + err = -RT_ERROR; + goto err; + } + + err = sdio_init_card(host, current_ocr); + if (err) { + goto remove_card; + } + return 0; + +remove_card: + rt_free(host->card); + host->card = RT_NULL; + +err: + LOG_E("init SDIO card failed"); + return err; +} + +int32_t deinit_sdio_free_mem(struct rt_mmcsd_host *host) +{ + if (host == RT_NULL || host->card == RT_NULL) { + return -RT_EINVAL; + } + for (int i = 0; i < host->card->sdio_function_num + 1; i++) { + if (host->card->sdio_function[i]) { + sdio_free_cis(host->card->sdio_function[i]); + rt_free(host->card->sdio_function[i]); + host->card->sdio_function[i] = RT_NULL; + } + } + rt_free(host->card); + host->card = RT_NULL; + return 0; +} + +static void sdio_irq_thread(void *param) +{ + int32_t i, ret; + uint8_t pending; + struct rt_mmcsd_card *card; + struct rt_mmcsd_host *host = (struct rt_mmcsd_host *)param; + RT_ASSERT(host != RT_NULL); + card = host->card; + RT_ASSERT(card != RT_NULL); + + while (1) { + if (hi_mmc_sem_pend(host->sdio_irq_sem, MMC_SEM_WAIT_FOREVER) == RT_EOK) { + mmcsd_host_lock(host); + pending = sdio_io_readb(host->card->sdio_function[0], SDIO_REG_CCCR_INT_PEND, &ret); + if (ret) { + mmcsd_dbg("error %d reading SDIO_REG_CCCR_INT_PEND\n", ret); + goto out; + } + + for (i = 1; i <= 7; i++) { // 7 + if (pending & (1 << i)) { + struct rt_sdio_function *func = card->sdio_function[i]; + if (!func) { + mmcsd_dbg("pending IRQ for " + "non-existant function %d\n", func->num); + goto out; + } else if (func->irq_handler) { + func->irq_handler(func); + } else { + mmcsd_dbg("pending IRQ with no register handler\n"); + goto out; + } + } + } + + out: + mmcsd_host_unlock(host); + if (host->flags & MMCSD_SUP_SDIO_IRQ) { + host->ops->enable_sdio_irq(host, 1); + } + continue; + } + } +} + +int32_t sdio_attach_irq(struct rt_sdio_function *func, rt_sdio_irq_handler_t *handler) +{ + int32_t ret; + uint8_t reg; + struct rt_sdio_function *func0; + + RT_ASSERT(func != RT_NULL); + RT_ASSERT(func->card != RT_NULL); + + func0 = func->card->sdio_function[0]; + + mmcsd_dbg("SDIO: enabling IRQ for function %d\n", func->num); + + if (func->irq_handler) { + mmcsd_dbg("SDIO: IRQ for already in use.\n"); + return -RT_EBUSY; + } + + reg = sdio_io_readb(func0, SDIO_REG_CCCR_INT_EN, &ret); + if (ret) { return ret; } + + reg |= 1 << func->num; + reg |= 1; /* Master interrupt enable */ + + ret = sdio_io_writeb(func0, SDIO_REG_CCCR_INT_EN, reg); + if (ret) { return ret; } + + func->irq_handler = handler; + ret = sdio_irq_thread_create(func->card); + if (ret) { + func->irq_handler = RT_NULL; + } + + return ret; +} + +int32_t sdio_detach_irq(struct rt_sdio_function *func) +{ + int32_t ret; + uint8_t reg; + struct rt_sdio_function *func0; + + RT_ASSERT(func != RT_NULL); + RT_ASSERT(func->card != RT_NULL); + + func0 = func->card->sdio_function[0]; + + mmcsd_dbg("SDIO: disabling IRQ for function %d\n", func->num); + + if (func->irq_handler) { + func->irq_handler = RT_NULL; + sdio_irq_thread_delete(func->card); + } + + reg = sdio_io_readb(func0, SDIO_REG_CCCR_INT_EN, &ret); + if (ret) { return ret; } + reg &= ~(1 << func->num); + /* Disable master interrupt with the last function interrupt */ + if (!(reg & 0xFE)) { + reg = 0; + } + + ret = sdio_io_writeb(func0, SDIO_REG_CCCR_INT_EN, reg); + if (ret) { return ret; } + + return 0; +} + +void sdio_irq_wakeup(struct rt_mmcsd_host *host) +{ + if (host->flags & MMCSD_SUP_SDIO_IRQ) { + host->ops->enable_sdio_irq(host, 0); + } + if (host->sdio_irq_sem != 0) { + hi_mmc_sem_post(host->sdio_irq_sem); + } +} + +int32_t sdio_enable_func(struct rt_sdio_function *func) +{ + int32_t ret; + uint8_t reg; + uint32_t timeout; + struct rt_sdio_function *func0; + + RT_ASSERT(func != RT_NULL); + RT_ASSERT(func->card != RT_NULL); + + func0 = func->card->sdio_function[0]; + + mmcsd_dbg("SDIO: enabling function %d\n", func->num); + + reg = sdio_io_readb(func0, SDIO_REG_CCCR_IO_EN, &ret); + if (ret) { goto err; } + reg |= 1 << func->num; + ret = sdio_io_writeb(func0, SDIO_REG_CCCR_IO_EN, reg); + if (ret) { goto err; } + + timeout = uapi_systick_get_count() + func->enable_timeout_val * RT_TICK_PER_SECOND / 1000; // 1000 + while (1) { + reg = sdio_io_readb(func0, SDIO_REG_CCCR_IO_RDY, &ret); + if (ret) { goto err; } + if (reg & (1 << func->num)) { break; } + ret = -RT_ETIMEOUT; + if (uapi_systick_get_count() > timeout) { goto err; } + } + + mmcsd_dbg("SDIO: enabled function successfull\n"); + return 0; + +err: + mmcsd_dbg("SDIO: failed to enable function %d\n", func->num); + return ret; +} + +int32_t sdio_disable_func(struct rt_sdio_function *func) +{ + int32_t ret; + uint8_t reg; + struct rt_sdio_function *func0; + + RT_ASSERT(func != RT_NULL); + RT_ASSERT(func->card != RT_NULL); + + func0 = func->card->sdio_function[0]; + mmcsd_dbg("SDIO: disabling function %d\n", func->num); + reg = sdio_io_readb(func0, SDIO_REG_CCCR_IO_EN, &ret); + if (ret) { goto err; } + + reg &= ~(1 << func->num); + ret = sdio_io_writeb(func0, SDIO_REG_CCCR_IO_EN, reg); + if (ret) { goto err; } + mmcsd_dbg("SDIO: disabled function successfull\n"); + return 0; + +err: + mmcsd_dbg("SDIO: failed to disable function %d\n", func->num); + return -RT_EIO; +} + +void sdio_set_drvdata(struct rt_sdio_function *func, void *data) +{ + func->priv = data; +} + +void* sdio_get_drvdata(struct rt_sdio_function *func) +{ + return func->priv; +} + +int32_t sdio_set_block_size(struct rt_sdio_function *func, uint32_t blksize) +{ + int32_t ret; + struct rt_sdio_function *func0 = func->card->sdio_function[0]; + + if (blksize > func->card->host->max_blk_size) { + return -RT_ERROR; + } + + if (blksize == 0) { + blksize = MIN(func->max_blk_size, func->card->host->max_blk_size); + blksize = MIN(blksize, 512u); // 512 + } + + ret = sdio_io_writeb(func0, SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_BLKSIZE, blksize & 0xff); + if (ret) { return ret; } + + ret = sdio_io_writeb(func0, SDIO_REG_FBR_BASE(func->num) + SDIO_REG_FBR_BLKSIZE + 1, (blksize >> 8) & 0xff); // 8 + if (ret) { return ret; } + + func->cur_blk_size = blksize; + return 0; +} + +rt_inline int32_t sdio_match_card(struct rt_mmcsd_card *card, const struct rt_sdio_device_id *id) +{ + uint8_t num = 1; + + if ((id->manufacturer != SDIO_ANY_MAN_ID) && (id->manufacturer != card->cis.manufacturer)) { + return 0; + } + + while (num <= card->sdio_function_num) { + if ((id->product != SDIO_ANY_PROD_ID) && (id->product == card->sdio_function[num]->product)) { + return 1; + } + num++; + } + + return 0; +} + +static struct rt_mmcsd_card *sdio_match_driver(struct rt_sdio_device_id *id) +{ + rt_list_t *l; + struct sdio_card *sc; + struct rt_mmcsd_card *card; + + for (l = (&sdio_cards)->next; l != &sdio_cards; l = l->next) { + sc = (struct sdio_card *)rt_list_entry(l, struct sdio_card, list); + card = sc->card; + + if (sdio_match_card(card, id)) { + return card; + } + } + + return RT_NULL; +} + +int32_t sdio_register_driver(struct rt_sdio_driver *driver) +{ + struct sdio_driver *sd; + struct rt_mmcsd_card *card; + + sd = rt_malloc(sizeof(struct sdio_driver)); + if (sd == RT_NULL) { + LOG_E("malloc sdio driver failed"); + return -RT_ENOMEM; + } + + sd->drv = driver; + rt_list_insert_after(&sdio_drivers, &sd->list); + + if (!rt_list_isempty(&sdio_cards)) { + card = sdio_match_driver(driver->id); + if (card != RT_NULL) { + return driver->probe(card); + } + } + + return -RT_EEMPTY; +} + +int32_t sdio_unregister_driver(struct rt_sdio_driver *driver) +{ + rt_list_t *l; + struct sdio_driver *sd = RT_NULL; + struct rt_mmcsd_card *card; + + for (l = (&sdio_drivers)->next; l != &sdio_drivers; l = l->next) { + sd = (struct sdio_driver *)rt_list_entry(l, struct sdio_driver, list); + if (sd->drv != driver) { + sd = RT_NULL; + } + } + + if (sd == RT_NULL) { + LOG_E("SDIO driver %s not register", driver->name); + return -RT_ERROR; + } + + if (!rt_list_isempty(&sdio_cards)) { + card = sdio_match_driver(driver->id); + if (card != RT_NULL) { + driver->remove(card); + rt_list_remove(&sd->list); + rt_free(sd); + } + } + + return 0; +} + +void rt_sdio_init(void) +{ +} + diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/sdio.h b/code/sdk/bootloader/flashboot/brandy/emmc/sdio.h new file mode 100644 index 000000000..6de09c6b8 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/sdio.h @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2012-01-15 weety first version + */ + +#ifndef __SDIO_H__ +#define __SDIO_H__ + +#include "mmcsd_host.h" +#include "mmcsd_card.h" +#include "sdio_func_ids.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Card Common Control Registers (CCCR) + */ + +#define SDIO_REG_CCCR_CCCR_REV 0x00 + +#define SDIO_CCCR_REV_1_00 0 /* CCCR/FBR Version 1.00 */ +#define SDIO_CCCR_REV_1_10 1 /* CCCR/FBR Version 1.10 */ +#define SDIO_CCCR_REV_1_20 2 /* CCCR/FBR Version 1.20 */ +#define SDIO_CCCR_REV_3_00 3 /* CCCR/FBR Version 2.00 */ + +#define SDIO_SDIO_REV_1_00 0 /* SDIO Spec Version 1.00 */ +#define SDIO_SDIO_REV_1_10 1 /* SDIO Spec Version 1.10 */ +#define SDIO_SDIO_REV_1_20 2 /* SDIO Spec Version 1.20 */ +#define SDIO_SDIO_REV_2_00 3 /* SDIO Spec Version 2.00 */ + +#define SDIO_REG_CCCR_SD_REV 0x01 + +#define SDIO_SD_REV_1_01 0 /* SD Physical Spec Version 1.01 */ +#define SDIO_SD_REV_1_10 1 /* SD Physical Spec Version 1.10 */ +#define SDIO_SD_REV_2_00 2 /* SD Physical Spec Version 2.00 */ + +#define SDIO_REG_CCCR_IO_EN 0x02 +#define SDIO_REG_CCCR_IO_RDY 0x03 + +#define SDIO_REG_CCCR_INT_EN 0x04 /* Function/Master Interrupt Enable */ +#define SDIO_REG_CCCR_INT_PEND 0x05 /* Function Interrupt Pending */ + +#define SDIO_REG_CCCR_IO_ABORT 0x06 /* function abort/card reset */ + +#define SDIO_REG_CCCR_BUS_IF 0x07 /* bus interface controls */ + +#define SDIO_BUS_WIDTH_1BIT 0x00 +#define SDIO_BUS_WIDTH_4BIT 0x02 +#define SDIO_BUS_ECSI 0x20 /* Enable continuous SPI interrupt */ +#define SDIO_BUS_SCSI 0x40 /* Support continuous SPI interrupt */ + +#define SDIO_BUS_ASYNC_INT 0x20 + +#define SDIO_BUS_CD_DISABLE 0x80 /* disable pull-up on DAT3 (pin 1) */ + +#define SDIO_REG_CCCR_CARD_CAPS 0x08 + +#define SDIO_CCCR_CAP_SDC 0x01 /* can do CMD52 while data transfer */ +#define SDIO_CCCR_CAP_SMB 0x02 /* can do multi-block xfers (CMD53) */ +#define SDIO_CCCR_CAP_SRW 0x04 /* supports read-wait protocol */ +#define SDIO_CCCR_CAP_SBS 0x08 /* supports suspend/resume */ +#define SDIO_CCCR_CAP_S4MI 0x10 /* interrupt during 4-bit CMD53 */ +#define SDIO_CCCR_CAP_E4MI 0x20 /* enable ints during 4-bit CMD53 */ +#define SDIO_CCCR_CAP_LSC 0x40 /* low speed card */ +#define SDIO_CCCR_CAP_4BLS 0x80 /* 4 bit low speed card */ + +#define SDIO_REG_CCCR_CIS_PTR 0x09 /* common CIS pointer (3 bytes) */ + +/* Following 4 regs are valid only if SBS is set */ +#define SDIO_REG_CCCR_BUS_SUSPEND 0x0c +#define SDIO_REG_CCCR_FUNC_SEL 0x0d +#define SDIO_REG_CCCR_EXEC_FLAG 0x0e +#define SDIO_REG_CCCR_READY_FLAG 0x0f + +#define SDIO_REG_CCCR_FN0_BLKSIZE 0x10 /* 2bytes, 0x10~0x11 */ + +#define SDIO_REG_CCCR_POWER_CTRL 0x12 + +#define SDIO_POWER_SMPC 0x01 /* Supports Master Power Control */ +#define SDIO_POWER_EMPC 0x02 /* Enable Master Power Control */ + +#define SDIO_REG_CCCR_SPEED 0x13 + +#define SDIO_SPEED_SHS 0x01 /* Supports High-Speed mode */ +#define SDIO_SPEED_EHS 0x02 /* Enable High-Speed mode */ + +/* + * Function Basic Registers (FBR) + */ + +#define SDIO_REG_FBR_BASE(f) ((f) * 0x100) /* base of function f's FBRs */ + +#define SDIO_REG_FBR_STD_FUNC_IF 0x00 + +#define SDIO_FBR_SUPPORTS_CSA 0x40 /* supports Code Storage Area */ +#define SDIO_FBR_ENABLE_CSA 0x80 /* enable Code Storage Area */ + +#define SDIO_REG_FBR_STD_IF_EXT 0x01 + +#define SDIO_REG_FBR_POWER 0x02 + +#define SDIO_FBR_POWER_SPS 0x01 /* Supports Power Selection */ +#define SDIO_FBR_POWER_EPS 0x02 /* Enable (low) Power Selection */ + +#define SDIO_REG_FBR_CIS 0x09 /* CIS pointer (3 bytes) */ + + +#define SDIO_REG_FBR_CSA 0x0C /* CSA pointer (3 bytes) */ + +#define SDIO_REG_FBR_CSA_DATA 0x0F + +#define SDIO_REG_FBR_BLKSIZE 0x10 /* block size (2 bytes) */ + +/* SDIO CIS Tuple code */ +#define CISTPL_NULL 0x00 +#define CISTPL_CHECKSUM 0x10 +#define CISTPL_VERS_1 0x15 +#define CISTPL_ALTSTR 0x16 +#define CISTPL_MANFID 0x20 +#define CISTPL_FUNCID 0x21 +#define CISTPL_FUNCE 0x22 +#define CISTPL_SDIO_STD 0x91 +#define CISTPL_SDIO_EXT 0x92 +#define CISTPL_END 0xff + +/* SDIO device id */ +#define SDIO_ANY_FUNC_ID 0xff +#define SDIO_ANY_MAN_ID 0xffff +#define SDIO_ANY_PROD_ID 0xffff + +struct rt_sdio_device_id { + rt_uint8_t func_code; + rt_uint16_t manufacturer; + rt_uint16_t product; +}; + +struct rt_sdio_driver { + char *name; + rt_int32_t (*probe)(struct rt_mmcsd_card *card); + rt_int32_t (*remove)(struct rt_mmcsd_card *card); + struct rt_sdio_device_id *id; +}; + +rt_int32_t sdio_io_send_op_cond(struct rt_mmcsd_host *host, + rt_uint32_t ocr, + rt_uint32_t *cmd5_resp); +rt_int32_t sdio_io_rw_direct(struct rt_mmcsd_card *card, + rt_int32_t rw, + rt_uint32_t fn, + rt_uint32_t reg_addr, + rt_uint8_t *pdata, + rt_uint8_t raw); +rt_int32_t sdio_io_rw_extended(struct rt_mmcsd_card *card, + rt_int32_t rw, + rt_uint32_t fn, + rt_uint32_t addr, + rt_int32_t op_code, + rt_uint8_t *buf, + rt_uint32_t blocks, + rt_uint32_t blksize); +rt_int32_t sdio_io_rw_extended_block(struct rt_sdio_function *func, + rt_int32_t rw, + rt_uint32_t addr, + rt_int32_t op_code, + rt_uint8_t *buf, + rt_uint32_t len); +rt_uint8_t sdio_io_readb(struct rt_sdio_function *func, + rt_uint32_t reg, + rt_int32_t *err); +rt_int32_t sdio_io_writeb(struct rt_sdio_function *func, + rt_uint32_t reg, + rt_uint8_t data); +rt_uint16_t sdio_io_readw(struct rt_sdio_function *func, + rt_uint32_t addr, + rt_int32_t *err); +rt_int32_t sdio_io_writew(struct rt_sdio_function *func, + rt_uint16_t data, + rt_uint32_t addr); +rt_uint32_t sdio_io_readl(struct rt_sdio_function *func, + rt_uint32_t addr, + rt_int32_t *err); +rt_int32_t sdio_io_writel(struct rt_sdio_function *func, + rt_uint32_t data, + rt_uint32_t addr); +rt_int32_t sdio_io_read_multi_fifo_b(struct rt_sdio_function *func, + rt_uint32_t addr, + rt_uint8_t *buf, + rt_uint32_t len); +rt_int32_t sdio_io_write_multi_fifo_b(struct rt_sdio_function *func, + rt_uint32_t addr, + rt_uint8_t *buf, + rt_uint32_t len); +rt_int32_t sdio_io_read_multi_incr_b(struct rt_sdio_function *func, + rt_uint32_t addr, + rt_uint8_t *buf, + rt_uint32_t len); +rt_int32_t sdio_io_write_multi_incr_b(struct rt_sdio_function *func, + rt_uint32_t addr, + rt_uint8_t *buf, + rt_uint32_t len); +rt_int32_t init_sdio(struct rt_mmcsd_host *host, rt_uint32_t ocr); +rt_int32_t sdio_attach_irq(struct rt_sdio_function *func, + rt_sdio_irq_handler_t *handler); +rt_int32_t sdio_detach_irq(struct rt_sdio_function *func); +void sdio_irq_wakeup(struct rt_mmcsd_host *host); +rt_int32_t sdio_enable_func(struct rt_sdio_function *func); +rt_int32_t sdio_disable_func(struct rt_sdio_function *func); +void sdio_set_drvdata(struct rt_sdio_function *func, void *data); +void* sdio_get_drvdata(struct rt_sdio_function *func); +rt_int32_t sdio_set_block_size(struct rt_sdio_function *func, + rt_uint32_t blksize); +rt_int32_t sdio_register_driver(struct rt_sdio_driver *driver); +rt_int32_t sdio_unregister_driver(struct rt_sdio_driver *driver); +void rt_sdio_init(void); +rt_int32_t deinit_sdio_free_mem(struct rt_mmcsd_host *host); + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/sdio_func_ids.h b/code/sdk/bootloader/flashboot/brandy/emmc/sdio_func_ids.h new file mode 100644 index 000000000..79085a593 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/sdio_func_ids.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2006-2018, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2012-02-26 weety first version + */ + +#ifndef __SDIO_FUNC_IDS_H__ +#define __SDIO_FUNC_IDS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/* Standard SDIO Function Interfaces */ + +#define SDIO_FUNC_CODE_NONE 0x00 /* Not a SDIO standard interface */ +#define SDIO_FUNC_CODE_UART 0x01 /* SDIO Standard UART */ +#define SDIO_FUNC_CODE_BT_A 0x02 /* SDIO Type-A for Bluetooth standard interface */ +#define SDIO_FUNC_CODE_BT_B 0x03 /* SDIO Type-B for Bluetooth standard interface */ +#define SDIO_FUNC_CODE_GPS 0x04 /* SDIO GPS standard interface */ +#define SDIO_FUNC_CODE_CAMERA 0x05 /* SDIO Camera standard interface */ +#define SDIO_FUNC_CODE_PHS 0x06 /* SDIO PHS standard interface */ +#define SDIO_FUNC_CODE_WLAN 0x07 /* SDIO WLAN interface */ +#define SDIO_FUNC_CODE_ATA 0x08 /* Embedded SDIO-ATA standard interface */ + +/* manufacturer id, product io */ + +#define SDIO_MANUFACTURER_ID_MARVELL 0x02df +#define SDIO_PRODUCT_ID_MARVELL_88W8686 0x9103 + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/code/sdk/bootloader/flashboot/brandy/emmc/soc_mmc.h b/code/sdk/bootloader/flashboot/brandy/emmc/soc_mmc.h new file mode 100644 index 000000000..3cc5cc232 --- /dev/null +++ b/code/sdk/bootloader/flashboot/brandy/emmc/soc_mmc.h @@ -0,0 +1,479 @@ +/* ---------------------------------------------------------------------------- + * Copyright (c) @CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: Platform Config HeadFile + * Author: @CompanyNameTag + * Create: 2021-09-03 + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * --------------------------------------------------------------------------- */ + +#ifndef _BRANDY_SOC_MMC_H +#define _BRANDY_SOC_MMC_H + +#include +#include +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#define EMMC_BOARD_DEBUG_ON 0 + +#define GLB_CTL_M_RB_BASE 0x57000000 +#define M_CTL_RB_BASE 0x52000000 +#define COM_CTL_RB_BASE 0x55000000 + +#ifndef BIT +#define BIT(x) (1UL << (uint32_t)(x)) +#endif + +#define MAX_MMC_NUM 2 + +#define BRANDY_INTERRUPT_SDIO 76 +#define BRANDY_INTERRUPT_EMMC 78 + +#define S_HGPIO 0x52065800 +#define S_HGPIO_PAD 0x5700d000 + +#define S_HGPIO0_OFFSET 0 +#define S_HGPIO0_PAD_OFFSET 0x200 + +#define S_HGPIO6_OFFSET 0x18 +#define S_HGPIO6_PAD_OFFSET 0x218 +#define FUNC_SDIO 0x01 +#define FUNC_EMMC 0x02 +#ifdef PRE_FPGA +#define IE_PINMUX_EN 0x02 +#else +#define IE_PINMUX_EN 0xC7 +#endif + +#define BRANDY_SDIO_REG_BASE 0x52061000 +#define BRANDY_SDIO_REG_END 0x52061FFF + +#define BRANDY_EMMC_REG_BASE 0x52062000 +#define BRANDY_EMMC_REG_END 0x52063FFF +// emmc external clk EMMC_CCLK_DIV +#define BRANDY_EXTERNAL_EMMC_CCLK_DIV 0x52000100 +#define EMMC_TUNING_COARSE_MODE_BIT 0xD + +#define PERI_EMMC_CRG_RST_CTL (GLB_CTL_M_RB_BASE + 0xc8) +#define SOFT_RST_GLB_SDIO_CRG_N BIT(0) +#define SOFT_RST_GLB_SDIO_LGC_N BIT(1) +#define SOFT_RST_GLB_SDIO_DERESET ((SOFT_RST_GLB_SDIO_CRG_N) | (SOFT_RST_GLB_SDIO_LGC_N)) + +#define ARGUMENT (BRANDY_EMMC_REG_BASE + 0x8) +#define CMD (BRANDY_EMMC_REG_BASE + 0xE) +#define RESP01 (BRANDY_EMMC_REG_BASE + 0x10) +#define RESP23 (BRANDY_EMMC_REG_BASE + 0x14) +#define RESP45 (BRANDY_EMMC_REG_BASE + 0x18) +#define RESP67 (BRANDY_EMMC_REG_BASE + 0x1C) +#define PSTATE_REG (BRANDY_EMMC_REG_BASE + 0x24) +#define HOST_CTRL1 (BRANDY_EMMC_REG_BASE + 0x28) +#define HIGH_SPEED_EN_BIT 0x2 +#define EXT_DAT_XFER_BIT 0x5 +#define PWR_CTRL (BRANDY_EMMC_REG_BASE + 0x29) +#define POWR_ON_1_8V 0xBF +#define CLK_CTRL (BRANDY_EMMC_REG_BASE + 0x2C) +#define TOUT_CTRL (BRANDY_EMMC_REG_BASE + 0x2E) +#define SW_RST (BRANDY_EMMC_REG_BASE + 0x2F) +#define SW_RST_ALL BIT(0) +#define SW_RST_CMD BIT(1) +#define SW_RST_DAT BIT(2) +#define SW_RE_RST_ALL (SW_RST_ALL | SW_RST_CMD | SW_RST_DAT) +#define NORMAL_INT_STAT (BRANDY_EMMC_REG_BASE + 0x30) +#define ERROR_INT_STAT (BRANDY_EMMC_REG_BASE + 0x32) +#define ALL_NORMAL_ERR_INT 0xffff +#define NORMAL_INT_STAT_EN (BRANDY_EMMC_REG_BASE + 0x34) +#define ERROR_INT_STAT_EN (BRANDY_EMMC_REG_BASE + 0x36) +#define NORMAL_ERR_INT_EN 0x7EFF +#define NORMAL_INT_SIGNAL_EN (BRANDY_EMMC_REG_BASE + 0x38) +#define ERROR_INT_SIGNAL_EN (BRANDY_EMMC_REG_BASE + 0x3A) +#define HOST_CTRL2 (BRANDY_EMMC_REG_BASE + 0x3E) +#define SAMPLE_CLK_SEL_BIT 0x7 +#define SIGNALING_EN_BIT 0x3 +#define UHS_MODE_SEL_BIT 0x0 +#define UHS_MODE_SEL_LEN 0x3 +#define HS_SDR 0x1 +#define HS_DDR 0x4 +#define HS200 0x3 +#define HS400 0x7 +#define MBIIU_CTRL (BRANDY_EMMC_REG_BASE + DWC_MSHC_PTR_VENDOR1 + 0x10) +#define AT_CTRL (BRANDY_EMMC_REG_BASE + DWC_MSHC_PTR_VENDOR1 + 0x40) +#define AT_STAT (BRANDY_EMMC_REG_BASE + DWC_MSHC_PTR_VENDOR1 + 0x44) +#define EMMC_CTRL (BRANDY_EMMC_REG_BASE + DWC_MSHC_PTR_VENDOR1 + 0x2C) +#define LEN_3BIT 0x3 +#define LEN_8BIT 0x8 + +#define CMD1_RESP_READY_BIT 0x80000000 +#define ERR_INT_BIT 0x8000 +#define RETRY_CNT1 1000 +#define RETRY_CNT2 10000 +#define CMD_COMPLETE 0x1 +#define XFER_COMPLETE 0x2 +#define CMD_XFER_COMPLETE (CMD_COMPLETE | XFER_COMPLETE) +#define CMD_INHIBIT 0x1 +#define CMD_INHIBIT_DAT 0x2 +#define DAT_LINE_ACTIVE 0x4 +#define CMD_DATA_NOT_READY (CMD_INHIBIT | CMD_INHIBIT_DAT | DAT_LINE_ACTIVE) +#define CMD_DATA_INHIBIT (CMD_INHIBIT | CMD_INHIBIT_DAT) +#define CMD6_4BIT_WIDTH_ARGS 0x3b70100 +#define CMD6_8BIT_WIDTH_ARGS 0x3b70200 +#define CMD6_TIMING_HS_ARGS 0x3b90100 +#define CMD6_TIMING_HS200_ARGS 0x3b90200 +#define CMD6_TIMING_HS400_ARGS 0x3b90300 +#define CMD0_INDEX 0x10 +#define CMD1_INDEX 0x102 +#define CMD1_ARGS 0xC0FF8080 +#define CMD2_INDEX 0x209 +#define CMD3_INDEX 0x31a +#define CMD3_ARGS 0x10000 +#define CMD9_INDEX 0x909 +#define CMD9_ARGS 0x10000 +#define CMD7_INDEX 0x71a +#define CMD7_ARGS 0x10000 +#define CMD6_INDEX 0x61b + +#define EMMC_CCLK_DIV_REG (M_CTL_RB_BASE + 0x0100) +#define EMMC_CCLK_ORI_DIV_NUM_MASK 0x0FF0 +#define EMMC_CCLK_ORI_DIV_NUM_2 0x20 +#define EMMC_TUNING_BM0_REG (M_CTL_RB_BASE + 0x104) +#define EMMC_TUNING_BM1_REG (M_CTL_RB_BASE + 0x108) +#define SD_HOST_CCLK_DIV_REG (M_CTL_RB_BASE + 0x0110) +#define SDIO_HOST_CCLK_DIV_REG (M_CTL_RB_BASE + 0x014C) + +#define SDIO_HOST_CLKEN BIT(0) +#define SDIO_CCLK_ORI_DIV_EN BIT(1) +#define SDIO_CCLK_ORI_LOAD_DIV_EN BIT(2) +#define SDIO_HOST_DIV_EN BIT(0) +#define SDIO_HOST_DIV_SHFIT 1 +#define SDIO_HOST_DIV_MASK 0xE + +#define EMMC_DIV_REG (M_CTL_RB_BASE + 0x0120) +#define SDIO_BUS_CGDIV_REG (M_CTL_RB_BASE + 0x0124) +#define SD_BUS_CLKEN BIT(0) +#define SD_BUS_DIV_EN BIT(1) +#define SD_BUS_LOAD_DIV_EN BIT(8) +#define SD_BUS_DIV_NUM_MASK 0xF8 // bit3---bit7 +#define SD_BUS_DIV_NUM_POST_SHIFT 3 + +#define EMMC_TUNING_BM0_VAL (0x4210) +#define EMMC_TUNING_BM1_VAL (0x707) +#define EMMC_TUNING_COARSE_MODE BIT(13) + +#define DWC_MSHC_PTR_VENDOR1 0x500 +#define SDHCI_MSHC_CTRL (DWC_MSHC_PTR_VENDOR1 + 0x08) +#define SDHCI_AXI_MBIIU_CTRL (DWC_MSHC_PTR_VENDOR1 + 0x10) + +#define SDHCI_AXI_MBIIU_BURST_INCR16_EN 8 +#define SDHCI_GM_WR_OSRC_LMT_MASK (0x7u << 24) +#define SDHCI_GM_WR_OSRC_LMT_SEL(x) ((x) << 24) +#define SDHCI_GM_RD_OSRC_LMT_MASK (0x7u << 16) +#define SDHCI_GM_RD_OSRC_LMT_SEL(x) ((x) << 16) +#define SDHCI_UNDEFL_INCR_EN 0x1 +#define SDHCI_GM_WR_OSRC_LMT_VAL (0x7u << 24) +#define SDHCI_GM_RD_OSRC_LMT_VAL (0x7u << 16) + +#define COM_GP_REG0_ADDR (COM_CTL_RB_BASE + 0x10) +#ifdef PRE_FPGA +#define EMMC_SDIO_RAM_CONTROL_MASK 1 +#else +#define EMMC_SDIO_RAM_CONTROL_MASK 8 +#endif +#define EMMC_CARD_CLK_INV_SET BIT(14) + +#define GLB_CLKEN_REG (COM_CTL_RB_BASE + 0x0608) +#define GLB_CLKEN_SDIOM BIT(4) +#define GLB_CLKEN_DISABLE (0x7fee) +#define GLB_CLKEN_ENABLE 0x7ffe + +#define SDIOM_CR_REG (COM_CTL_RB_BASE + 0x0628) +#define SDIOM_CR_CTRL_CH_ENABLE BIT(0) +#define SDIOM_CR_CTRL_DIV_EN BIT(4) + +#define SDIOM_CR_CTRL_DIV_OFFSET 5 +#define SDIOM_CR_CTRL_MIN_DIV 2 + +#define SDIOM_CR_CTRL_CLK_RESOURCE_RC 0 +#define SDIOM_CR_CTRL_CLK_RESOURCE_XO 1 +#define SDIOM_CR_CTRL_CLK_RESOURCE_XO_DLL2 2 +#define SDIOM_CR_CTRL_CLK_RESOURCE_PLL 3 + +#define SDIOM_CR_CTRL_CLK_RESOURCE_PLL_EN (SDIOM_CR_CTRL_CH_ENABLE | (SDIOM_CR_CTRL_CLK_RESOURCE_PLL << 1)) +#define SDIOM_CR_CTRL_XO_32M_CLK_EN (SDIOM_CR_CTRL_CH_ENABLE | (SDIOM_CR_CTRL_CLK_RESOURCE_XO << 1)) + +#define MCU_GPIO3_BASE_ADDR (0x5701c000) + +#define EMMC_EMMC_CCLK_EN BIT(0) +#define EMMC_CCLK_LOAD_DIV_EN BIT(1) + +#define SDIO_EMMC_CCLK_EN BIT(0) +#define SDIO_EMMC_ORI_DIV_EN BIT(1) + +#define SDIO_DIV_NUM_MASK 0xF8 // bit3---bit7 +#define EMMC_DIV_NUM_MASK 0x70 // bit4---bit6 + +#define SDIO_DIV_NUM_POST_SHIFT 3 +#define SDIO_EMMC_DIV_NUM_POST_SHIFT 4 + +#define OFF_CLK2CARD_ON_DELAY 25 + +#define CONFIG_MMC0_CCLK_MIN 400000 // 400KHz +#define CONFIG_MMC1_CCLK_MIN 100000 // 100KHz + +#define CONFIG_MMC1_CCLK_MAX 32000000 // 32MHz +#define SDIO_EMMC_DIV_NUM_MASK 0xFF0 + +#define SDIOM_SRC_CLK_LOW_FREQ_VAL 32000000 // 32MHz +#define SDIOM_SRC_CLK_FREQ_LVL_50M_VAL 52000000 // 52MHz +#define SDIOM_SRC_CLK_FREQ_LVL_64M_VAL 64000000 // 64MHz +#define SDIOM_SRC_CLK_FREQ_LVL_49M_VAL 49000000 +#define SDIOM_SRC_CLK_FREQ_LVL_98M_VAL 98000000 // 98MHz +#define SDIOM_SRC_CLK_HIGH_FREQ_LVL_VAL 294000000 // 294MHz + +#define SDHCI_CMD_CONFLIT_CHECK 0x01 + +#define DRV_PHASE_112P5_DEGREE 10 /* 112.5 degree */ +#define DRV_PHASE_258P75_DEGREE 23 /* 258.75 degree */ +#define DRV_PHASE_225_DEGREE 20 /* 225 degree */ +#define DRV_PHASE_180_DEGREE 16 /* 180 degree */ + +#define SAMPLE_PHASE 4 +#define DEFAULT_PHASE 0x10 + +#define MSHC_WAIT_INT_PER_MSEC 1 + +#define CMU_CLOCKS_SDIO_RST_DEVICE_SD_BIT 0 + +#define CMU_CLOCK_SOFT_RST6_REG (GLB_CTL_M_RB_BASE + 0xC8) +#define CMU_CLOCK_SOFT_RST_GLB_SDIO_CRG_BIT 0 +#define CMU_CLOCK_SOFT_RST_GLB_SDIO_LGC_BIT 1 + +#define CMU_CLOCKS_SDIO_CRG_SOFT_RST_REG (M_CTL_RB_BASE + 0x128) +#define CMU_CLOCKS_SDIO_RST_DEVICE_SD_BIT 0 + +#define brandy_reg32(register) (*(volatile uint32_t*)(uintptr_t)(register)) +#define brandy_reg16(register) (*(volatile uint16_t*)(uintptr_t)(register)) +#define brandy_reg8(register) (*(volatile uint8_t*)(uintptr_t)(register)) + +#define brandy_reg32_clrbit(register, pos) (brandy_reg32(register) &= ~((uint32_t)((1U) << (uint32_t)(pos)))) +#define brandy_reg16_clrbit(register, pos) (brandy_reg16(register) &= ~((uint16_t)((1U) << (uint16_t)(pos)))) +#define brandy_reg8_clrbit(register, pos) (brandy_reg8(register) &= ~((uint8_t)((1U) << (pos)))) + +#define brandy_reg32_setbit(register, pos) (brandy_reg32(register) |= ((uint32_t)((1U) << (uint32_t)(pos)))) +#define brandy_reg16_setbit(register, pos) (brandy_reg16(register) |= ((uint16_t)((1U) << (uint16_t)(pos)))) +#define brandy_reg8_setbit(register, pos) (brandy_reg8(register) |= ((uint8_t)((1U) << (pos)))) + +#define brandy_reg16_setbits(r, p, b, v) (brandy_reg16(r) = (brandy_reg16(r) & \ + (uint16_t)(~((((uint32_t)1 << (uint16_t)(b)) - 1) << (uint16_t)(p)))) \ + | (uint16_t)((uint32_t)((uint16_t)(v) & \ + (((uint32_t)1 << (uint16_t)(b)) - 1)) << (uint16_t)(p))) + +#define PMU_TOP_PERIPHERALS_MTOP0_L_REG (M_CTL_RB_BASE + 0x150) +#define PMU_MTOP0_MDMA_RST 2 +#define PMU_MTOP0_SMDMA_RST 1 +#define PMU_MTOP0_TIMER_RST 0 +#define PMU_TOP_PERIPHERALS_MTOP0_H_REG (M_CTL_RB_BASE + 0x154) +#define PMU_MTOP0_MDMA_STS_OFFSET 2 +#define PMU_MTOP0_SMDMA_STS_OFFSET 1 +#define PMU_MTOP0_MTIMER_STS_OFFSET 0 + +/* I2C0/1/2/3 peripheral clock gating. */ +#define PMU_TOP_PERIPHERALS_MTOP1_L_REG (M_CTL_RB_BASE + 0x158) +#define PMU_MTOP1_I2C3_RST 3 +#define PMU_MTOP1_I2C2_RST 2 +#define PMU_MTOP1_I2C1_RST 1 +#define PMU_MTOP1_I2C0_RST 0 +#define PMU_TOP_PERIPHERALS_MTOP1_H_REG (M_CTL_RB_BASE + 0x15C) +#define PMU_MTOP1_I2C3_STS_OFFSET 3 +#define PMU_MTOP1_I2C2_STS_OFFSET 2 +#define PMU_MTOP1_I2C1_STS_OFFSET 1 +#define PMU_MTOP1_I2C0_STS_OFFSET 0 + +/* SPI0_M, SPI1_MS, SPI2_MS and QSPI2_1CS peripheral clock gating. */ +#define PMU_TOP_PERIPHERALS_MTOP2_L_REG (M_CTL_RB_BASE + 0x160) +#define PMU_MTOP2_QSPI2_1CS_RST 3 +#define PMU_MTOP2_SPI2_RST 2 +#define PMU_MTOP2_SPI1_RST 1 +#define PMU_MTOP2_SPI0_RST 0 +#define PMU_TOP_PERIPHERALS_MTOP2_H_REG (M_CTL_RB_BASE + 0x164) +#define PMU_MTOP2_QSPI2_1CS_STS_OFFSET 3 +#define PMU_MTOP2_SPI2_STS_OFFSET 2 +#define PMU_MTOP2_SPI1_STS_OFFSET 1 +#define PMU_MTOP2_SPI0_STS_OFFSET 0 + +/* UART_H0, UART_H1 and UART_L0 peripheral clock gating. */ +#define PMU_TOP_PERIPHERALS_MTOP3_L_REG (M_CTL_RB_BASE + 0x168) +#define PMU_MTOP3_UART_L0_RST 2 +#define PMU_MTOP3_UART_H1_RST 1 +#define PMU_MTOP3_UART_H0_RST 0 +#define PMU_TOP_PERIPHERALS_MTOP3_H_REG (M_CTL_RB_BASE + 0x16C) +#define PMU_MTOP3_UART_L0_STS_OFFSET 2 +#define PMU_MTOP3_UART_H1_STS_OFFSET 1 +#define PMU_MTOP3_UART_H0_STS_OFFSET 0 + +/* EMMC and SDIO_HOST peripheral clock gating. */ +#define PMU_TOP_PERIPHERALS_MTOP4_L_REG (M_CTL_RB_BASE + 0x170) +#define PMU_MTOP4_SDIO_HOST_RST 1 +#define PMU_MTOP4_EMMC_RST 0 +#define PMU_TOP_PERIPHERALS_MTOP4_H_REG (M_CTL_RB_BASE + 0x174) +#define PMU_MTOP4_SDIO_HOST_STS_OFFSET 1 +#define PMU_MTOP4_EMMC_STS_OFFSET 0 + +/* I2C4 5 6 and spi3 peripheral clock gating. */ +#define PMU_TOP_PERIPHERALS_MTOP5_L_REG (M_CTL_RB_BASE + 0x178) +#define PMU_MTOP4_I2C_BUS_4_RST 0 +#define PMU_MTOP4_I2C_BUS_5_RST 1 +#define PMU_MTOP4_I2C_BUS_6_RST 2 +#define PMU_MTOP4_SPI_M3_RST 3 + +#define CMU_CLOCKS_MSUB_NORMAL_REG (M_CTL_RB_BASE + 0x3e0) + +#define MSUB_CFG_REFRESH_REG (M_CTL_RB_BASE + 0x3F0) +#define MSUB_CFG_REFRESH_BIT 0 + +#define CMU_CLOCKS_COM_CR_CH_EN_BIT 0 +#define CMU_CLOCKS_COM_CR_CLK_SEL_BIT 1 +#define CMU_CLOCKS_COM_CR_CLK_SEL_LEN 3 +#define CMU_CLOCKS_COM_CR_CLK_DIV_EN_BIT 4 +#define CMU_CLOCKS_COM_CR_CLK_DIV_NUM_BIT 5 +#define CMU_CLOCKS_COM_CR_CLK_DIV_NUM_LEN 4 +#define CMU_CLOCKS_COM_CR_CH_SEL_STS_BIT 12 +#define CMU_CLOCKS_COM_CR_CH_SEL_STS_LEN 2 + +#define CMU_CLOCKS_COM_BUS_CR_REG (GLB_CTL_M_RB_BASE + 0x8C) +#define CMU_CLOCKS_MCU_CORE_CR_CH0_REG (M_CTL_RB_BASE + 0x550) +#define CMU_CLOCKS_MCU_CORE_CR_CH1_REG (M_CTL_RB_BASE + 0x554) +#define CMU_CLOCKS_MCU_PERP_LS_CR_REG (M_CTL_RB_BASE + 0x558) +#define CMU_CLOCKS_MCU_PERP_HS_CR_REG (M_CTL_RB_BASE + 0x55C) +#define CMU_CLOCKS_SDIOM_CR_REG (M_CTL_RB_BASE + 0x564) +#define CMU_CLOCKS_MEM_BUS_CR_REG (M_CTL_RB_BASE + 0x568) +#define CMU_CLOCKS_XIP_OPI_CR_REG (M_CTL_RB_BASE + 0x56C) +#define CMU_CLOCKS_XIP_QSPI_CR_REG (M_CTL_RB_BASE + 0x570) +#define CMU_CLOCKS_GPU_CR_REG (M_CTL_RB_BASE + 0x574) +#define CMU_CLOCKS_RGB_CR_REG (M_CTL_RB_BASE + 0x578) +#define CMU_CLOCKS_HIFI_CR_REG (M_CTL_RB_BASE + 0x57C) +#define CMU_CLOCKS_CODEC_CR_REG (M_CTL_RB_BASE + 0x580) +#define CMU_CLOCKS_PAD_CLK_OUT0_CR_REG (M_CTL_RB_BASE + 0x584) +#define CMU_CLOCKS_PAD_CLK_OUT1_CR_REG (M_CTL_RB_BASE + 0x588) +#define CMU_CLOCKS_PAD_CLK_OUT2_CR_REG (M_CTL_RB_BASE + 0x58C) + +#define EMMC_CAPCITY_SIZE (4ULL * GB) /* emmc capcity size, unit: bytes */ +#define RESERVED_BOOT_SECTOR 2048 /* reserved sector number for boot */ +#define SECTOR_NUM_PER_CLUSTER 8 /* cluster size, unit: sector */ +#define GB (1024ULL * 1024ULL * 1024ULL) + +/** reg32 bit pos types */ +typedef enum { + BRANDY_POS_0, + BRANDY_POS_1, + BRANDY_POS_2, + BRANDY_POS_3, + BRANDY_POS_4, + BRANDY_POS_5, + BRANDY_POS_6, + BRANDY_POS_7, + BRANDY_POS_8, + BRANDY_POS_9, + BRANDY_POS_10, + BRANDY_POS_11, + BRANDY_POS_12, + BRANDY_POS_13, + BRANDY_POS_14, + BRANDY_POS_15 +} BRANDY_REG16_POS; + +/** PMU_LPM wakeup types */ +typedef enum { + BRANDY_TURN_OFF, + BRANDY_TURN_ON +} brandy_switch_type_t; + +/** + * @brief Describe pheriphral request behavior. + */ +typedef enum { + HAL_PMU_PERIP_REQUEST_RESET = 0, // !< Request reset the peripheral, make it in initial status, can't running. + HAL_PMU_PERIP_REQUEST_DERESET = 1, // !< Request dereset the peripheral, make it can run. + HAL_PMU_PERIP_REQUEST_ENTER_LOW_POWER = 2, // !< Request the peripheral enter low power mode. + HAL_PMU_PERIP_REQUEST_EXIT_LOW_POWER = 3, // !< Request the peripheral exit low power mode. +} hal_pmu_perip_request_type_t; + +typedef enum { + HAL_SOFT_RST6_SDIO_CRG, + HAL_SOFT_RST6_SDIO_LGC, +} hal_glb_sdio_soft_rst_type_t; + +typedef enum { + BRANDY_CLOCKS_SDIO_FREQ_32M, // sdio:32M + BRANDY_CLOCKS_SDIO_FREQ_50M, // rc clock, real value 49.512MHz + BRANDY_CLOCKS_SDIO_FREQ_64M, // sdio:64M + BRANDY_CLOCKS_SDIO_FREQ_H, // 193.3M + BRANDY_CLOCKS_SDIO_FREQ_MAX, +} brandy_system_sdio_freq_t; + +/** + * @brief Describe mcpu pheriphrals. + */ +typedef enum { + HAL_PMU_MCPU_PERIP_TIMER = 0, // !< The mcpu peripheral timer, can not enter low power mode. + HAL_PMU_MCPU_PERIP_SMDMA = 1, // !< The smcpu peripheral dma + HAL_PMU_MCPU_PERIP_MDMA = 2, // !< The mcpu peripheral dma + HAL_PMU_MCPU_PERIP_I2C_BUS_0 = 3, // !< The mcpu peripheral I2C BUS0 + HAL_PMU_MCPU_PERIP_I2C_BUS_1 = 4, // !< The mcpu peripheral I2C BUS1 + HAL_PMU_MCPU_PERIP_I2C_BUS_2 = 5, // !< The mcpu peripheral I2C BUS2 + HAL_PMU_MCPU_PERIP_I2C_BUS_3 = 6, // !< The mcpu peripheral I2C BUS3 + HAL_PMU_MCPU_PERIP_SPI_MST = 7, // !< The mcpu peripheral SPI BUS0 + HAL_PMU_MCPU_PERIP_SPI_MS_0 = 8, // !< The mcpu peripheral SPI BUS1 + HAL_PMU_MCPU_PERIP_SPI_MS_1 = 9, // !< The mcpu peripheral SPI BUS2 + HAL_PMU_MCPU_PERIP_QSPI2_1CS = 10, // !< The mcpu peripheral QSPI BUS2 + HAL_PMU_MCPU_PERIP_UART_H0 = 11, // !< The mcpu peripheral UARTH0 + HAL_PMU_MCPU_PERIP_UART_H1 = 12, // !< The mcpu peripheral UARTH1 + HAL_PMU_MCPU_PERIP_UART_L0 = 13, // !< The mcpu peripheral UARTL0 + HAL_PMU_MCPU_PERIP_EMMC = 14, // !< The mcpu peripheral EMMC + HAL_PMU_MCPU_PERIP_SDIO_HOST = 15, // !< The mcpu peripheral SDIO HOST + HAL_PMU_MCPU_PERIP_I2C_BUS_4 = 16, // !< The mcpu peripheral I2C BUS4 + HAL_PMU_MCPU_PERIP_I2C_BUS_5 = 17, // !< The mcpu peripheral I2C BUS5 + HAL_PMU_MCPU_PERIP_I2C_BUS_6 = 18, // !< The mcpu peripheral I2C BUS6 + HAL_PMU_MCPU_PERIP_SPI_M3 = 19, // !< The mcpu peripheral SPI BUS3 + HAL_PMU_MCPU_PERIP_MAX, +} hal_pmu_mcpu_perips_type_t; + +int emmc_drv_context_init(void); +void init_emmc_pinmux(void); + +void sdio_drv_context_init(void); +void init_sdio_pinmux(void); +void mmc_set_internal_clk(uint16_t clk_level); +void mmc_set_first_init_flag(bool flag); +bool mmc_get_first_init_flag(void); +void mmc_set_sleep_init_flag(bool flag); +bool mmc_get_sleep_init_flag(void); +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _BRANDY_MMC_H */ + diff --git a/code/sdk/bootloader/flashboot/brandy/main.c b/code/sdk/bootloader/flashboot/brandy/main.c index 3a6c4dcea..916923e03 100644 --- a/code/sdk/bootloader/flashboot/brandy/main.c +++ b/code/sdk/bootloader/flashboot/brandy/main.c @@ -62,6 +62,10 @@ #include "nandflash_config.h" #endif +#ifdef CFG_DRIVERS_MMC +#include "drv_mmc_adapter.h" +#endif + #define CFG_PMU_PROTECT_WDT_RESET 1 #define FLASH_INIT_DATA 0xff @@ -614,11 +618,6 @@ static void ssb_resume_flash_pin(void) uapi_pin_set_mode(QSPI0_D3, (pin_mode_t)HAL_PIO_FUNC_QSPI0); } -#ifdef SW_RTT_DEBUG -extern uint32_t __rtt_bss_end; -extern uint32_t __rtt_bss_start; -#endif - #if CFG_PMU_PROTECT_WDT_RESET == 1 void software_delay_us(uint32_t delay) { @@ -718,19 +717,8 @@ static void pmu_protect_config_and_reset(bool rom_codeloadered) } #endif -void main(void) +static void chip_init(bool rom_codeloadered) { - errno_t ret = 0; - uint32_t manufacture_id = 0; - uint8_t unique_id = 0; - bool rom_codeloadered = is_rom_codeloadered(); -#ifdef SW_RTT_DEBUG - uint32_t size = (uint32_t)(&__rtt_bss_end) - (uint32_t)(&__rtt_bss_start); - ret = memset_s((void *)((uint32_t)(&__rtt_bss_start)), size, 0, size); - if (ret != EOK) { - PRINT("rtt bss memset fail."NEWLINE); - } -#endif int_setup(); uapi_pin_init(); uapi_tcxo_init(); @@ -749,9 +737,15 @@ void main(void) hw_init(); uapi_ulp_systick_self_verification(); show_reboot_info(); - otp_init(); irmalloc_init_default(); +} + +static void flash_init(void) +{ + uint32_t manufacture_id = 0; + uint8_t unique_id = 0; + ssb_hold_flash_pin(); uapi_flash_init(0); ssb_try_read_flash_id(&manufacture_id); @@ -762,28 +756,10 @@ void main(void) uapi_flash_config_cmd_at_xip_mode(0, unique_id); ssb_enable_qe_mode_if_need(manufacture_id); ssb_resume_flash_pin(); - while (uapi_uart_has_pending_transmissions(SW_DEBUG_UART_BUS)) { } -#ifdef PRE_ASIC - pmu_init(); - clocks_system_init(); -#endif -#ifdef SW_UART_DEBUG - sw_debug_uart_reset_baund(); -#endif -#ifdef CFG_DRIVERS_NANDFLASH - nandflash_qspi_init(); -#endif - if ((flash_is_empty() || (rom_codeloadered == true)) && ssb_save_sign_in_flash()) { - PRINT("flash is empty, save image into flash" NEWLINE); - ret = ssb_save_image_in_flash(); - if (ret == false) { - PRINT("save ssb into flash err" NEWLINE); - uapi_tcxo_delay_ms((uint64_t)TCXO_REBOOT_DELAY); - cpu_utils_set_system_status_by_cause(REBOOT_CAUSE_BT_SSB_EXCEPTION_REBOOT); - // This will reset the aliased regions, you will go to ROM - hal_reboot_chip(); - } - } +} + +static void xip_and_save_ssb(void) +{ xip_init(); bootloader_configuration_init(); create_ssb_to_application_table(hal_reboot_get_reset_reason()); @@ -801,6 +777,57 @@ void main(void) #endif set_ssb_to_application_image_vaild(true, true); uapi_partition_init(); +} + +static void fs_init(void) +{ +#ifdef CFG_DRIVERS_NANDFLASH + nandflash_qspi_init(); +#endif +#ifdef CFG_DRIVERS_MMC + ssb_emmc_init(); +#endif +} + +#ifdef SW_RTT_DEBUG +extern uint32_t __rtt_bss_end; +extern uint32_t __rtt_bss_start; +#endif + +void main(void) +{ + errno_t ret = 0; + bool rom_codeloadered = is_rom_codeloadered(); +#ifdef SW_RTT_DEBUG + uint32_t size = (uint32_t)(&__rtt_bss_end) - (uint32_t)(&__rtt_bss_start); + ret = memset_s((void *)((uint32_t)(&__rtt_bss_start)), size, 0, size); + if (ret != EOK) { + PRINT("rtt bss memset fail."NEWLINE); + } +#endif + + chip_init(rom_codeloadered); + flash_init(); + + while (uapi_uart_has_pending_transmissions(SW_DEBUG_UART_BUS)) { } +#ifdef PRE_ASIC + pmu_init(); + clocks_system_init(); +#endif +#ifdef SW_UART_DEBUG + sw_debug_uart_reset_baund(); +#endif + + if (flash_is_empty() || (rom_codeloadered == true)) { + PRINT("flash is empty, save image into flash" NEWLINE); + if (ssb_save_sign_in_flash()) { + ssb_save_image_in_flash(); + } + } + fs_init(); + + xip_and_save_ssb(); + if (non_os_is_driver_initialised(DRIVER_INIT_OTP) == true) { otp_deinit(); } ssb_enter_app(); PRINT("No jump, reset now" NEWLINE); diff --git a/code/sdk/build/config/target_config/brandy/config.py b/code/sdk/build/config/target_config/brandy/config.py index 3ee13945e..31b5d67a7 100644 --- a/code/sdk/build/config/target_config/brandy/config.py +++ b/code/sdk/build/config/target_config/brandy/config.py @@ -133,6 +133,17 @@ target = { 'base_target_name': 'brandy-native-js', 'defines': ['-:SW_UART_DEBUG'], }, + #auto-ota-server + 'brandy-auto-ota-ser': { + 'base_target_name': 'brandy-native-js', + 'defines': ['SUPPORT_AUTO_OTA_SERVER', 'CONFIG_DFX_SUPPORT_DIAG_UP_MACHINE=1'], + }, + #auto-ota-client + 'brandy-auto-ota-cli': { + 'base_target_name': 'brandy-native-js', + 'defines': ['SUPPORT_AUTO_OTA_SERVER', 'SUPPORT_AUTO_OTA', 'CONFIG_DFX_SUPPORT_DIAG_UP_MACHINE=1'], + 'ram_component': ['auto_ota'] + }, #native-xts: liteos + uikit + nandflash + mipi + psram + audio 典型合封UIKIT版本 'brandy-xts': { 'board': 'evb', @@ -274,7 +285,7 @@ target = { "LIBCODELOADER_SSB", "LIBJLINK_LOAD", "LIBLIB_UTILS", "LIBBUILD_VERSION", "NO_TIMEOUT", "CONFIG_UART_BAUD_RATE_DIV_8", 'SW_UART_DEBUG', 'LARGE_BUFFER'], 'ram_component': ['arch_port', 'hal_l2ram', 'sec_boot', 'libboundscheck', - 'dfx_exception', 'error_code', 'psram', 'osal', 'cmn_header', 'boot_ulp', 'boot_nandflash'], + 'dfx_exception', 'error_code', 'psram', 'osal', 'cmn_header', 'boot_ulp', 'boot_nandflash', 'boot_emmc'], 'ram_component_set': ['pinctrl'], 'target': 'ssb', } diff --git a/code/sdk/build/config/target_config/brandy/mk_emmc_image/README.txt b/code/sdk/build/config/target_config/brandy/mk_emmc_image/README.txt new file mode 100644 index 000000000..e58069303 --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_emmc_image/README.txt @@ -0,0 +1,9 @@ +本文档为生成emmc文件镜像的使用指导 + +1.如果想要生成文件镜像,需要在对应target中添加配置:'fs_image': True +2.当前目录适配的是emmc的FAT文件镜像。 +3.生成emmc的FAT文件镜像前,请打开mkfatimgtool.py脚本进行相关配置,详细见脚本说明 +4.将要烧录的资源文件放到fs目录中,可以有子目录,此目录对应A核系统挂载第一分区的目录,默认为system目录。 +5.因为生成FAT镜像的工具是windows平台的工具,生成过程需要在windows平台上进行。 +6.执行脚本是python脚本,所以需要预先安装python3软件,建议python3.7及以上的版本。 +7.执行python mkfatimgtool.py即可在当前目录生成FAT镜像,即file.bin文件。 \ No newline at end of file diff --git a/code/sdk/build/config/target_config/brandy/mk_emmc_image/fs/test1.txt b/code/sdk/build/config/target_config/brandy/mk_emmc_image/fs/test1.txt new file mode 100644 index 000000000..b15149be0 --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_emmc_image/fs/test1.txt @@ -0,0 +1 @@ +this is test1 file \ No newline at end of file diff --git a/code/sdk/build/config/target_config/brandy/mk_emmc_image/mkfatimg.exe b/code/sdk/build/config/target_config/brandy/mk_emmc_image/mkfatimg.exe new file mode 100644 index 000000000..91297d38f Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_emmc_image/mkfatimg.exe differ diff --git a/code/sdk/build/config/target_config/brandy/mk_emmc_image/mkfatimgtool.py b/code/sdk/build/config/target_config/brandy/mk_emmc_image/mkfatimgtool.py new file mode 100644 index 000000000..db6dd9491 --- /dev/null +++ b/code/sdk/build/config/target_config/brandy/mk_emmc_image/mkfatimgtool.py @@ -0,0 +1,55 @@ +#!/usr/local/bin/python3.7 +# -*- coding: utf-8 -*- + +import os +import sys +import time +import struct +import shutil + +""" +介绍: + 本脚本主要实现调用mkyaffs2image工具生成文件镜像 + 请注意使用本脚本时支持的python版本,本脚本只支持python3版本。 + 请根据实际情况配置对应信息,主要是nandflash的信息,以及分区信息 + +""" + +cur_dir = os.getcwd() +image_tool_path = os.getcwd() + +# 配置生成文件镜像工具路径 +mkfatimgtool = os.path.join(image_tool_path, 'mkfatimg.exe') +image_name = "file" + +# 配置emmc信息 +cfg_sector_size = 512 + +# 配置分区信息,请根据实际情况进行配置,添加格式为[分区路径, 分区大小] +# 分区大小需要根据按照百分系统分配好后的sector数进行计算,大小=sector(对应区域扇区数) * cfg_sector_size(单扇区字节数) / 1024(KB单位换算) +# 分区大小必须指定,按照当前系统默认emmc总容量4GB, 第一分区system大小为11%,换算分区大小为461260 +partition_list = [ + [os.path.join(cur_dir, 'fs'), "461260"], +] + +if __name__ == "__main__": + image_file = os.path.join(cur_dir, "%s.bin" %image_name) + tmp_file = os.path.join(cur_dir, "%s_tmp.bin" %image_name) + sector_size = " 4096" + ret = 0 + + if sys.platform == 'win32': + if os.path.exists(image_file): + os.remove(image_file) + + for partition in partition_list: + command = mkfatimgtool + " " + partition[0] + " " + image_file + " " + partition[1] + sector_size + print(command) + ret = os.system(command) + else: + print("sys platform err!not windows system!\n") + + if ret == 0: + print("make fat image file success!") + else: + print("make fat image file fail!") diff --git a/code/sdk/build/config/target_config/common_config.py b/code/sdk/build/config/target_config/common_config.py index 63ff9985c..67b90a8a0 100644 --- a/code/sdk/build/config/target_config/common_config.py +++ b/code/sdk/build/config/target_config/common_config.py @@ -116,7 +116,7 @@ component_set = { 'efuse_v120': ['efuse', 'hal_efuse_v120', 'efuse_porting'], 'efuse_v100': ['efuse', 'hal_efuse_v100', 'efuse_porting'], 'efuse_v130': ['efuse', 'hal_efuse_v130', 'efuse_port'], - 'ohos_set' : ['bootstrap', 'samgr', 'ams', 'bms', 'bms_sign_mode', 'ace', 'ace_adapt', 'permission', 'appverify', 'jerryscript','js_player', 'js_audio_capturer', 'baidumapcomponent', 'i18n', + 'ohos_set' : ['bootstrap', 'samgr', 'ams', 'bms', 'bms_sign_mode', 'ace', 'ace_adapt', 'permission', 'appverify', 'jerryscript','js_player', 'js_audio_capturer', 'baidumapcomponent', 'brightness', 'i18n', 'resmgr', 'syspara', 'utils_kv_store', 'native_file', 'storage_jsapi', 'brightness'], 'wearable_set' : ['nativeabilityfwk', 'nativelauncher', 'ai_voice_service', 'ai_voice_engine_hal', 'ai_voice_audio_stream_wrapper', 'ohos_deps', 'broadcast', 'msg_center', 'msg_center_adapt', 'ohos_startup'], diff --git a/code/sdk/build/script/cmake_builder.py b/code/sdk/build/script/cmake_builder.py index 3972fe7bc..1a22b3258 100644 --- a/code/sdk/build/script/cmake_builder.py +++ b/code/sdk/build/script/cmake_builder.py @@ -131,16 +131,30 @@ class CMakeBuilder(BuildEnvironment): return if env.get("fs_image"): - fs_image_path = os.path.join(root_path, 'build', 'config', 'target_config', env.get('chip'), 'mk_fs_image') - fs_script_path = os.path.join(fs_image_path, 'mkyaffs2tool.py') - output_path = env.get_output_path() - print(output_path) - errcode = exec_shell([self.python_path, fs_script_path, output_path], None, True) - if errcode != 0: - print("creat fs image error!") - self.print_build_result(target, errcode) + defines = env.get("defines") + if "CFG_DRIVERS_NANDFLASH" in defines: + print("fs img nandflash mode") + fs_image_path = os.path.join(root_path, 'build', 'config', 'target_config', env.get('chip'), 'mk_fs_image') + fs_script_path = os.path.join(fs_image_path, 'mkyaffs2tool.py') + errcode = exec_shell([self.python_path, fs_script_path], None, True) + if errcode != 0: + print("creat fs image error!") + self.print_build_result(target, errcode) + sys.exit(1) + print("nandflash yaffs image generate success!") + elif "CFG_DRIVERS_MMC" in defines: + print("fs img emmc mode") + fs_image_path = os.path.join(root_path, 'build', 'config', 'target_config', env.get('chip'), 'mk_emmc_image',) + else: + print("not cfg emmc or nandflash, cfg error!!!\n") sys.exit(1) - print("fs image success!") + + # copy file.bin from make dir to application dir + file_path = os.path.join(fs_image_path, 'file.bin') + outfile_path = os.path.join(env.get_output_path(), 'file.bin') + if os.path.exists(file_path): + shutil.copyfile(file_path, outfile_path) + print("copy file.bin to application dir over!\n") if env.get('packet'): self.pack_fwpkg(env.get('chip'), target) diff --git a/code/sdk/drivers/boards/brandy_evb/linker/standard/acore.prelds b/code/sdk/drivers/boards/brandy_evb/linker/standard/acore.prelds index 69a5f10b6..a8f86bb0e 100644 --- a/code/sdk/drivers/boards/brandy_evb/linker/standard/acore.prelds +++ b/code/sdk/drivers/boards/brandy_evb/linker/standard/acore.prelds @@ -301,6 +301,7 @@ SECTIONS SORT(*platform/testsuite/test_update*.a:*.o*) (.text .text* .rodata .rodata* .srodata .srodata*) SORT(*platform/testsuite/test_dhry*.a:*.o*) (.text .text* .rodata .rodata* .srodata .srodata*) #endif + SORT(*systemview.a:*.o*) (.text .text* .rodata .rodata* .srodata .srodata*) . = ALIGN(8); __init_array_start = .; KEEP(*(.ctors .init_array*)) @@ -549,6 +550,7 @@ SECTIONS SORT(*test/common/testsuite*.a:*.o*) (.data .data*) SORT(*test/platform/testsuite*.a:*.o*) (.data .data*) #endif + SORT(*systemview.a:*.o*) (.data .data*) *(.data) *(.data*) *(.got) @@ -620,6 +622,7 @@ SECTIONS SORT(*test/common/testsuite*.a:*.o*) (.bss .bss* .sbss .sbss* COMMON) SORT(*test/platform/testsuite*.a:*.o*) (.bss .bss* .sbss .sbss* COMMON) #endif + SORT(*systemview.a:*.o*) (.bss .bss* .sbss .sbss* COMMON) *(.bss) *(.bss*) *(.sbss) diff --git a/code/sdk/drivers/chips/brandy/porting/calendar/calendar_porting.c b/code/sdk/drivers/chips/brandy/porting/calendar/calendar_porting.c index 92d4609ee..6a611e8b6 100644 --- a/code/sdk/drivers/chips/brandy/porting/calendar/calendar_porting.c +++ b/code/sdk/drivers/chips/brandy/porting/calendar/calendar_porting.c @@ -16,6 +16,7 @@ #define ULP_CALIBRATION_INTERVAL 900000 #define VERIFICATIN_TIME 0xFFFFFFFFFFFFFFFFUL +#define SELFHEAL_TIME 500UL #define CALENDAR_BASE_ADDR ULP_RAM_CALENDAR uintptr_t g_calendar_base_addr = (uintptr_t)CALENDAR_BASE_ADDR; @@ -71,4 +72,9 @@ static errcode_t calendar_get_alarm(uint64_t *alarm) void uapi_calendar_calibration_enable(void) { calendar_set_alarm(VERIFICATIN_TIME); +} + +void uapi_self_heal_timer_enable(void) +{ + calendar_set_alarm(SELFHEAL_TIME); } \ No newline at end of file diff --git a/code/sdk/drivers/chips/brandy/porting/include/calendar_porting.h b/code/sdk/drivers/chips/brandy/porting/include/calendar_porting.h index 4420bc9c3..023bc6519 100644 --- a/code/sdk/drivers/chips/brandy/porting/include/calendar_porting.h +++ b/code/sdk/drivers/chips/brandy/porting/include/calendar_porting.h @@ -44,6 +44,11 @@ uintptr_t hal_calendar_hw_base_addr_get(void); * @brief Calendar clock calibration enable. */ void uapi_calendar_calibration_enable(void); + +/** + * @brief Calendar Self Heal enable. + */ +void uapi_self_heal_timer_enable(void); /** * @} */ diff --git a/code/sdk/drivers/drivers/driver/ipc/ipc_old/shared/ipc.c b/code/sdk/drivers/drivers/driver/ipc/ipc_old/shared/ipc.c index 601f4e92e..4bf3d3b4c 100644 --- a/code/sdk/drivers/drivers/driver/ipc/ipc_old/shared/ipc.c +++ b/code/sdk/drivers/drivers/driver/ipc/ipc_old/shared/ipc.c @@ -38,6 +38,14 @@ #define IPC_SHIFT_BIT 28 #define IPC_COMMPUTE_TIME_COEF 4 +#define IPC_CONTINUOUS_FAIL_MAX 200 +#define IPC_REG_INT_EN 0x52000020 +#define IPC_REG_INT 0x52000024 +#define IPC_REG_INT_STS 0x52000028 +#define IPC_REG_INT_CLR 0x5200002c +#define IPC_REG_CLR_STS 0x52000030 +#define IPC_REG_INT_SET 0x52000034 +static volatile uint32_t g_ipc_to_bcore_continuous_fail_nums = 0; static uint32_t g_ipc_ssend_default_timeout = 0; static volatile ipc_send_info g_ipc_sinfo[CORES_MAX_NUMBER_PHYSICAL]; @@ -91,6 +99,32 @@ static uint32_t g_ipc_timer_index = 0; static void ipc_timer_callback(void); static void ipc_start_timer(void); + +static inline void ipc_reg_info_debug(void) +{ + PRINT("ipc reg info:int en:%x,int:%x,int sts:%x.\r\n", readw(IPC_REG_INT_EN), readw(IPC_REG_INT), + readw(IPC_REG_INT_STS)); + PRINT("int clr:%x,clr sts:%x,int set:%x.\r\n", readw(IPC_REG_INT_CLR), readw(IPC_REG_CLR_STS), + readw(IPC_REG_INT_SET)); +} + +static inline void ipc_to_bcore_timeout_proc(cores_t dst) +{ + if (dst == CORES_BT_CORE) { + g_ipc_to_bcore_continuous_fail_nums++; + if (g_ipc_to_bcore_continuous_fail_nums > IPC_CONTINUOUS_FAIL_MAX) { + panic(PANIC_BT_STS_ABNORMAL, __LINE__); + } + } +} + +static inline void ipc_to_bcore_clr_fail_num(cores_t dst) +{ + if (dst == CORES_BT_CORE) { + g_ipc_to_bcore_continuous_fail_nums = 0; + } +} + #ifdef IPC_DATA_SEND_TEST static bool test_ipc_receive_data_callback(ipc_action_t message, const volatile ipc_payload *payload_p, cores_t src, uint32_t id) @@ -201,7 +235,7 @@ void ipc_init(void) if (non_os_is_driver_initialised(DRIVER_INIT_IPC) == true) { return; } - + ipc_reg_info_debug(); #if CORE == MASTER_BY_ALL memset_s((void *)IPC_MAILBOX_REGION_START, IPC_MAILBOX_REGION_LENGTH, 0, IPC_MAILBOX_REGION_LENGTH); #endif @@ -764,7 +798,7 @@ ipc_status_t ipc_spin_send_message_timeout(cores_t dst, ipc_action_t action, con curr_tick = uapi_systick_get_count(); if (curr_tick >= timeout_tick) { /* timeout */ - + ipc_to_bcore_timeout_proc(dst); break; } } @@ -772,8 +806,10 @@ ipc_status_t ipc_spin_send_message_timeout(cores_t dst, ipc_action_t action, con if (ret_val != IPC_STATUS_OK) { /* fail process */ g_ipc_sinfo[dst].loop_cnt = j; + ipc_reg_info_debug(); ipc_spin_send_fail_process(dst, ret_val, action); } else { + ipc_to_bcore_clr_fail_num(dst); g_ipc_sinfo[dst].send_data_called = 0; } UNUSED(failed_flag); diff --git a/code/sdk/drivers/drivers/driver/mmc/host/sdhci/brandy/mmc_sdhci.c b/code/sdk/drivers/drivers/driver/mmc/host/sdhci/brandy/mmc_sdhci.c index d286b662a..9f6645767 100644 --- a/code/sdk/drivers/drivers/driver/mmc/host/sdhci/brandy/mmc_sdhci.c +++ b/code/sdk/drivers/drivers/driver/mmc/host/sdhci/brandy/mmc_sdhci.c @@ -723,13 +723,20 @@ uint32_t sdhci_set_clock(struct hci_softc *sc, uint32_t clock) hci_writeb(sc, SDHCI_AXI_MBIIU_CTRL, val); inited = true; } - // After the tuning phase value is configured, the tuning clk function is automatically enabled. - uint32_t phase = dpal_readl(AT_STAT); - dpal_writel(phase, AT_STAT); - // The fixed clock is less than or equal to 52 MHz, and the tuning clock is not used. - if (clock <= SDIOM_SRC_CLK_FREQ_LVL_50M_VAL) { - brandy_reg16_clrbit(HOST_CTRL2, SAMPLE_CLK_SEL_BIT); + +#ifdef CFG_SDIO_EMMC_COEXIST + if (sc->num == 0) { +#endif + // After the tuning phase value is configured, the tuning clk function is automatically enabled. + uint32_t phase = dpal_readl(AT_STAT); + dpal_writel(phase, AT_STAT); + // The fixed clock is less than or equal to 52 MHz, and the tuning clock is not used. + if (clock <= SDIOM_SRC_CLK_FREQ_LVL_50M_VAL) { + brandy_reg16_clrbit(HOST_CTRL2, SAMPLE_CLK_SEL_BIT); + } +#ifdef CFG_SDIO_EMMC_COEXIST } +#endif return clock; } diff --git a/code/sdk/drivers/drivers/driver/mmc/mmc_init.c b/code/sdk/drivers/drivers/driver/mmc/mmc_init.c index 954ed7c33..691046ff3 100644 --- a/code/sdk/drivers/drivers/driver/mmc/mmc_init.c +++ b/code/sdk/drivers/drivers/driver/mmc/mmc_init.c @@ -52,7 +52,8 @@ extern "C" { #define EMMC_PART_MODE 0666 #define EMMC_MSLEEP_20 20 #define EMMC_ACCESS_OFFSET 20 -#define FF_VOLUME_NAME_STRS "/system/", "/user/", "/update/", "/music/" +#define EMMC_SECTOR_TO_KB 2 +#define FF_VOLUME_NAME_STRS "/user/", "/system/", "/update/", "/music/" uint32_t g_volume_percent[FF_VOLUMES_NUM] = { 11, 11, 8, 70 }; static const char * const g_volume_names[FF_VOLUMES_NUM] = { FF_VOLUME_NAME_STRS }; @@ -125,7 +126,8 @@ int emmc_drv_init(void) for (index = 0; index < FF_VOLUMES_NUM; ++index) { part_count_sector = (size_t)((total_sector_num * g_volume_percent[index]) / EMMC_NUM100); - + dpal_log_warn("mmc_partition[%d]:sector size=%d capacity=%dKB\n", + index, part_count_sector, part_count_sector / EMMC_SECTOR_TO_KB); ret = add_mmc_partition(&emmc, part_start_sector, part_count_sector); if (ret != 0) { return -EIO; diff --git a/code/sdk/drivers/drivers/driver/nand_flash/nand/hal_nandflash.c b/code/sdk/drivers/drivers/driver/nand_flash/nand/hal_nandflash.c index a4570e485..f8e9a604c 100644 --- a/code/sdk/drivers/drivers/driver/nand_flash/nand/hal_nandflash.c +++ b/code/sdk/drivers/drivers/driver/nand_flash/nand/hal_nandflash.c @@ -19,6 +19,8 @@ #include "nandflash_config.h" #include "hal_nandflash.h" #include "nandflash.h" +#include "pinctrl_porting.h" +#include "gpio.h" #include "pm.h" #define OFFSET 0 @@ -49,6 +51,28 @@ uint8_t mc_flash_get_offset(void) return OFFSET; } +uint32_t read_buffer_single_line_width_32(qspi_data_type_def *qspi_data); + +void cs_pulldown(void) { + if (SER_SELECT == 1) { + uapi_pin_set_mode(S_HGPIO11, (pin_mode_t)HAL_PIO_FUNC_GPIO); + uapi_gpio_set_dir(S_HGPIO11, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(S_HGPIO11, GPIO_LEVEL_LOW); + } else { + uapi_pin_set_mode(S_HGPIO12, (pin_mode_t)HAL_PIO_FUNC_GPIO); + uapi_gpio_set_dir(S_HGPIO12, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(S_HGPIO12, GPIO_LEVEL_LOW); + } +} + +void cs_pullup(void) { + if (SER_SELECT == 1) { + uapi_pin_set_mode(S_HGPIO11, (pin_mode_t)HAL_PIO_FUNC_QSPI2); + } else { + uapi_pin_set_mode(S_HGPIO12, (pin_mode_t)HAL_PIO_FUNC_QSPI2); + } +} + uint16_t read_id(qspi_data_type_def *qspi_data) { while (is_nandflash_working) { @@ -365,7 +389,18 @@ static void read_oob(uint8_t *oob, uint32_t oob_len) return; } -uint32_t read_buffer(qspi_data_type_def *qspi_data, uint8_t *data, uint32_t data_len, uint8_t *oob, uint32_t oob_len) +void debug_read_buffer(void) { + if (readw(0x57000010) == 0x5a) + { + for (uint32_t i = 0; i < DEFALUT_BUFLENGTH; i++) + { + PRINT("nand_read_buf index:%d , VALUE:%d] \r\n", i, nand_read_buf[i]); + } + writew(0x57000010, 0); + } +} + +uint32_t read_buffer(qspi_data_type_def *qspi_data, uint8_t *data, uint32_t data_len, uint8_t *oob, uint32_t oob_len, enum nandflash_trans_type type) { while (is_nandflash_working) { uapi_tcxo_delay_us(HAL_NAND_WAIT_3US); @@ -373,12 +408,20 @@ uint32_t read_buffer(qspi_data_type_def *qspi_data, uint8_t *data, uint32_t data is_nandflash_working = true; errno_t err_code; uint32_t result; - if (get_trans_type() == TRANS_BY_DMA_QUAD) { + memset_s(nand_read_buf, DEFALUT_BUFLENGTH, 0, DEFALUT_BUFLENGTH); + if (type == TRANS_DEFAULT) { + if (get_trans_type() == TRANS_BY_DMA_QUAD) { + result = read_buffer_by_dma_width32_quad(qspi_data); + } else { + result = read_buffer_single_line_width_32(qspi_data); + } + } else if (type == TRANS_BY_DMA_QUAD) { result = read_buffer_by_dma_width32_quad(qspi_data); - } else { + } else if (type == TRANS_BY_CPU_SINGLE_LINE) { result = read_buffer_single_line_width_32(qspi_data); } + debug_read_buffer(); if ((data != NULL) && (data_len > 0)) { err_code = memcpy_s(data, data_len, nand_read_buf, data_len); if (err_code != EOK) { @@ -392,6 +435,7 @@ uint32_t read_buffer(qspi_data_type_def *qspi_data, uint8_t *data, uint32_t data static void dma_send_done_callback(hal_dma_interrupt_t int_type) { + cs_pullup(); switch (int_type) { case HAL_DMA_INTERRUPT_TFR: g_dma_send_done = true; @@ -824,6 +868,7 @@ uint32_t program_load_by_dma_width_32_quad(qspi_data_type_def *qspi_data) dma_channel_t channel = dma_send_data(qspi_data->data_size / HAL_NAND_BYTE_ALIGN, (uint8_t *)send_buffer, HAL_DMA_TRANSFER_WIDTH_32); nand_qspi_enable(); + cs_pulldown(); writel(SER, 0x0); nand_qspi_write_data(ins); nand_qspi_write_data(0); @@ -833,6 +878,7 @@ uint32_t program_load_by_dma_width_32_quad(qspi_data_type_def *qspi_data) writel(SER, SER_SELECT); if (osal_sem_down_timeout((osal_semaphore *)&dma_send_sem, DMA_TRANSFER_TIMEOUT_MS) != OSAL_SUCCESS) { PRINT("program_load_by_dma fail \r\n"); + cs_pullup(); ret = MC_FAILURE; } uapi_pm_remove_sleep_veto(PM_ID_DMA); @@ -950,6 +996,7 @@ uint32_t program_load_width_32(qspi_data_type_def *qspi_data) uint32_t write_by_cpu_single_line(qspi_data_type_def *qspi_data) { + PRINT("write_by_cpu_single_line !!!\r\n"); qspi_busy_wait(); uint16_t address = SWAP_U16(qspi_data->address); uint8_t *addr = (uint8_t *)&address; @@ -957,7 +1004,7 @@ uint32_t write_by_cpu_single_line(qspi_data_type_def *qspi_data) nand_qspi_disable(); ctrl0.d.spi_frf = SPI_STD_SPI_FRF; ctrl0.d.dfs_32 = DFR_32_FRAME_08BITS; - ctrl0.d.tmod = SPI_EEPROM_TMOD; + ctrl0.d.tmod = SPI_TX_ONLY_TMOD; nand_qspi_ctlr0_cfg(ctrl0.d32); nand_qspi_ctlr1_cfg(0); nand_qspi_enable(); @@ -972,6 +1019,7 @@ uint32_t write_by_cpu_single_line(qspi_data_type_def *qspi_data) static_time_before = uapi_tcxo_get_us(); } unsigned int irq_sts = osal_irq_lock(); + cs_pulldown(); writel(SER, 0x0); nand_qspi_write_data(ins); nand_qspi_write_data(0); // addr is 0 @@ -991,6 +1039,7 @@ uint32_t write_by_cpu_single_line(qspi_data_type_def *qspi_data) nand_qspi_write_data(qspi_data->data_ptr[i]); } } + cs_pullup(); osal_irq_restore(irq_sts); if (SUPPORT_STATISTIC == 1) { static_time_after = uapi_tcxo_get_us(); diff --git a/code/sdk/drivers/drivers/driver/nand_flash/nand/include/hal_nandflash.h b/code/sdk/drivers/drivers/driver/nand_flash/nand/include/hal_nandflash.h index 02a24f360..44cd9a722 100644 --- a/code/sdk/drivers/drivers/driver/nand_flash/nand/include/hal_nandflash.h +++ b/code/sdk/drivers/drivers/driver/nand_flash/nand/include/hal_nandflash.h @@ -100,7 +100,7 @@ typedef struct { uint8_t mc_flash_get_offset(void); uint16_t read_id(qspi_data_type_def *qspi_data); uint32_t read_cell_array(qspi_data_type_def *qspi_data); -uint32_t read_buffer(qspi_data_type_def *qspi_data, uint8_t *data, uint32_t data_len, uint8_t *oob, uint32_t oob_len); +uint32_t read_buffer(qspi_data_type_def *qspi_data, uint8_t *data, uint32_t data_len, uint8_t *oob, uint32_t oob_len, enum nandflash_trans_type type); uint8_t read_sr(qspi_data_type_def *qspi_data, uint8_t address); uint32_t write_sr(qspi_data_type_def *qspi_data, uint8_t addr, uint8_t data); void write_cmd(uint8_t command); @@ -119,7 +119,7 @@ void change_div(uint32_t div); dma_channel_t dma_send_data(uint32_t trans_num, uint8_t *data_ptr, uint8_t width); dma_channel_t dma_recv_data(uint32_t trans_num, uint8_t *data_ptr, uint8_t width); uint32_t read_buffer_single_line_width_8(qspi_data_type_def *qspi_data); -uint32_t read_buffer_single_line_width_32(qspi_data_type_def *qspi_data); +uint32_t read_bPffer_single_line_width_32(qspi_data_type_def *qspi_data); uint32_t read_buffer_by_dma(qspi_data_type_def *qspi_data); uint32_t program_load_by_dma_width_32(qspi_data_type_def *qspi_data); uint32_t read_buffer_by_dma_width32(qspi_data_type_def *qspi_data); diff --git a/code/sdk/drivers/drivers/driver/nand_flash/nand/include/nandflash_config.h b/code/sdk/drivers/drivers/driver/nand_flash/nand/include/nandflash_config.h index a940f3a8f..687148ae8 100644 --- a/code/sdk/drivers/drivers/driver/nand_flash/nand/include/nandflash_config.h +++ b/code/sdk/drivers/drivers/driver/nand_flash/nand/include/nandflash_config.h @@ -49,4 +49,5 @@ void nandflash_qspi_resume(void); void test_nand_flash_read_8(struct nand_driver_struct *test_nand_flash_driver, uint32_t nand_page); void test_nand_flash_write_width8(struct nand_driver_struct *test_nand_flash_driver, uint32_t nand_page); void nandflash_yaffs_sync(void); +void nandflash_yaffs_format(void); #endif /* End of #ifndef MC_NAND_CONFIG_H */ diff --git a/code/sdk/drivers/drivers/driver/nand_flash/nand/include/nandflash_inner.h b/code/sdk/drivers/drivers/driver/nand_flash/nand/include/nandflash_inner.h index c940be23e..f8a91003a 100644 --- a/code/sdk/drivers/drivers/driver/nand_flash/nand/include/nandflash_inner.h +++ b/code/sdk/drivers/drivers/driver/nand_flash/nand/include/nandflash_inner.h @@ -52,19 +52,20 @@ typedef enum nandflash_trans_type { TRANS_BY_DMA_QUAD, TRANS_BY_CPU_SINGLE_LINE, + TRANS_DEFAULT } nandflash_trans_type_t; typedef enum nandflash_trans_speed { SPEED_HIGH = 8, SPEED_MID = 12, - SPEED_SLOW = 14, + SPEED_SLOW = 16, } nandflash_speed_type_t; struct nand_driver_struct { uint32_t (*nand_flash_init)(void); uint16_t (*check_id)(void); uint32_t (*read_page)(uint32_t nand_page, uint8_t *data, uint32_t data_len, - uint8_t *oob, uint32_t oob_len, uint8_t *status_reg); + uint8_t *oob, uint32_t oob_len, uint8_t *status_reg, enum nandflash_trans_type type); uint32_t (*write_page)(uint32_t nand_page, uint8_t *data, uint32_t data_len, uint8_t *oob, uint32_t oob_len); uint32_t (*erase_block)(uint32_t block_no); uint32_t (*mark_bad_block)(uint32_t block_no); @@ -91,7 +92,7 @@ uint32_t mc_flash_write_sr(uint8_t addr, uint8_t data); void mc_flash_write_cmd(uint8_t cmd); void mc_flash_busy_wait(void); uint32_t mc_flash_read_page(uint32_t nand_page, uint8_t *data, uint32_t data_len, - uint8_t *oob, uint32_t oob_len, uint8_t *status_reg); + uint8_t *oob, uint32_t oob_len, uint8_t *status_reg, enum nandflash_trans_type type); uint32_t mc_flash_write_page(uint32_t nand_page, uint8_t *data, uint32_t data_len, uint8_t *oob, uint32_t oob_len); uint32_t mc_flash_erase_block(uint32_t block_no); uint32_t mc_flash_mark_bad_block(uint32_t block_no); diff --git a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash.c b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash.c index d01f8dc1d..ed2357b43 100644 --- a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash.c +++ b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash.c @@ -108,7 +108,7 @@ void mc_flash_busy_wait(void) } uint32_t mc_flash_read_page(uint32_t nand_page, uint8_t *data, uint32_t data_len, - uint8_t *oob, uint32_t oob_len, uint8_t *status_reg) + uint8_t *oob, uint32_t oob_len, uint8_t *status_reg, enum nandflash_trans_type type) { uapi_watchdog_kick(); NFPRINT("mc_flash_read_page nand_page = %d\r\n", nand_page); @@ -130,7 +130,7 @@ uint32_t mc_flash_read_page(uint32_t nand_page, uint8_t *data, uint32_t data_len qspi_data_type_def qspi_read_buffer = {0}; qspi_read_buffer.instruction = 0x03; qspi_read_buffer.data_size = get_nand_flash()->bytes_per_page + get_nand_flash()->bytes_per_oob; - read_buffer(&qspi_read_buffer, data, data_len, oob, oob_len); + read_buffer(&qspi_read_buffer, data, data_len, oob, oob_len, type); mc_flash_read_sr(CMD_FLASH_SR3_ADDR, status_reg); NFPRINT("mc_flash_read_page success status = %x\r\n", *status_reg); return MC_SUCCESS; diff --git a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_config.c b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_config.c index dbc64fcf2..fa6a2e270 100644 --- a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_config.c +++ b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_config.c @@ -39,6 +39,7 @@ #define ERASE_ALL_TIMES 10 #define NAND_PAGE_MAX_SIZE 0x100 +extern uint8_t nand_read_buf[DEFALUT_BUFLENGTH] __attribute__((aligned(4))); uint8_t buffer_verify[DEFALUT_BUFLENGTH] __attribute__((aligned(4))); uint8_t buffer_oob_verify[128] __attribute__((aligned(4))); // 128 is one max oob size int has_nandflash_init = 0; @@ -119,12 +120,18 @@ void nandflash_yaffs_sync(void) } } +void nandflash_yaffs_format(void) +{ + for (uint8_t index = 0; index < YF_VOLUMES_NUM; index++) { + int32_t ret = yaffs_format(g_volume_names[index], 1, 1, 1); + PRINT("[%s] yaffs_format ret = %d", g_volume_names[index], ret); + } +} + void erase_all(struct nand_driver_struct *driver) { uint32_t ret; uint8_t status; - uint32_t *read_buf = (uint32_t *)&buffer_verify[0]; - uint32_t *read_buf_oob = (uint32_t *)&buffer_oob_verify[0]; for (uint32_t j = 0; j < 1; j++) { for (uint32_t i = 0; i < driver->total_block; i++) { ret = driver->erase_block(i); @@ -141,21 +148,24 @@ void erase_all(struct nand_driver_struct *driver) } } - +#include "chip_io.h" void test_nand_flash_read_8(struct nand_driver_struct *test_nand_flash_driver, uint32_t nand_page) { - uint8_t status; - for (uint32_t i = 0; i < test_nand_flash_driver->bytes_per_page; i++) { - buffer_verify[i] = 0x0; - } - for (uint8_t i = 0; i < test_nand_flash_driver->bytes_per_oob; i++) { - buffer_oob_verify[i] = 0x0; + + struct mtd_info *mtd; + mtd = get_mtd("nand"); + if (mtd == NULL) + { + nand_register(mtd); } - PRINT("nandflash [READ][PAGE:%d]\r\n", nand_page); + memset_s(buffer_verify, DEFALUT_BUFLENGTH, 0, DEFALUT_BUFLENGTH); - test_nand_flash_driver->read_page(nand_page, buffer_verify, test_nand_flash_driver->bytes_per_page, - buffer_oob_verify, test_nand_flash_driver->bytes_per_oob, &status); + PRINT("nandflash [READ][PAGE:%d]\r\n", nand_page); + uint32_t retlen; + writew(0x57000010, 0x5a); + os_nand_read_oob(mtd, mtd->writesize * nand_page, mtd->writesize + mtd->oobsize, &retlen, (const char *)buffer_verify); + writew(0x57000010, 0x0); for (uint32_t i = 0; i < test_nand_flash_driver->bytes_per_page; i++) { PRINT("[READ DATA INDEX:%d , VALUE:%d] \r\n", i, buffer_verify[i]); } @@ -173,6 +183,14 @@ void test_nand_flash_read_8(struct nand_driver_struct *test_nand_flash_driver, void test_nand_flash_write_width8(struct nand_driver_struct *test_nand_flash_driver, uint32_t nand_page) { + struct mtd_info *mtd; + mtd = get_mtd("nand"); + if (mtd == NULL) + { + nand_register(mtd); + } + + int j = 0; for (uint32_t i = 0; i < test_nand_flash_driver->bytes_per_page; i++) { buffer_verify[i] = i; @@ -195,8 +213,8 @@ void test_nand_flash_write_width8(struct nand_driver_struct *test_nand_flash_dri buffer_oob_verify[1] = 0xff; PRINT("nandflash [READ][PAGE:%d]\r\n", nand_page); PRINT("[WRITE][WRITE][WRITE][WRITE][WRITE][WRITE][WRITE][WRITE]\r\n"); - test_nand_flash_driver->write_page(nand_page, buffer_verify, test_nand_flash_driver->bytes_per_page, - buffer_oob_verify, test_nand_flash_driver->bytes_per_oob); + uint32_t retlen; + os_nand_write_oob(mtd, mtd->writesize * nand_page, mtd->writesize + mtd->oobsize, &retlen, (const char *)buffer_verify); } void nandflash_qspi_init(void) diff --git a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_ds35x1g.c b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_ds35x1g.c index dddad5bad..419141a65 100644 --- a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_ds35x1g.c +++ b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_ds35x1g.c @@ -24,12 +24,12 @@ static qspi_data_type_def g_qspi_data = {0}; static uint32_t mc_ds35x1g_read_page( - uint32_t nand_page, uint8_t *data, uint32_t data_len, uint8_t *oob, uint32_t oob_len, const uint32_t *ecc_result) + uint32_t nand_page, uint8_t *data, uint32_t data_len, uint8_t *oob, uint32_t oob_len, const uint32_t *ecc_result, enum nandflash_trans_type type) { unused(ecc_result); uint32_t ret; uint8_t status_reg; - ret = mc_flash_read_page(nand_page, data, data_len, oob, oob_len, &status_reg); + ret = mc_flash_read_page(nand_page, data, data_len, oob, oob_len, &status_reg, type); if (get_nand_flash()->enable_ecc == true) { if (DS35X1G_GET_ECC_STATUS(status_reg) >= DS35X1G_ECC_ERROR) { return MC_FAILURE; diff --git a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_tc58cyg.c b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_tc58cyg.c index b2e5f484d..4c414293c 100644 --- a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_tc58cyg.c +++ b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_tc58cyg.c @@ -24,12 +24,12 @@ static qspi_data_type_def g_qspi_data = {0}; static uint32_t mc_tc58cyg_read_page( - uint32_t nand_page, uint8_t *data, uint32_t data_len, uint8_t *oob, uint32_t oob_len, const uint32_t *ecc_result) + uint32_t nand_page, uint8_t *data, uint32_t data_len, uint8_t *oob, uint32_t oob_len, const uint32_t *ecc_result, enum nandflash_trans_type type) { unused(ecc_result); uint32_t ret; uint8_t status_reg; - ret = mc_flash_read_page(nand_page, data, data_len, oob, oob_len, &status_reg); + ret = mc_flash_read_page(nand_page, data, data_len, oob, oob_len, &status_reg,type); if (ret != MC_SUCCESS) { return MC_FAILURE; } diff --git a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_to_os.c b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_to_os.c index 5892314c5..fe231efbd 100644 --- a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_to_os.c +++ b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_to_os.c @@ -15,21 +15,81 @@ #endif #include "nandflash_config.h" #include "nandflash_to_os.h" +#include "soc_osal.h" +#include "soc_errno.h" +#include "pinctrl_porting.h" +#include "hal_gpio.h" +#include "platform_core.h" +#include "pinctrl.h" #define NAND_FLASH_TYLE 4 #define NAND_FLASH_FLAGS 0x400 -#define OS_DUMP_LEN 0x14 +#define OS_DUMP_LEN 200 #define SUCCESS 0 #define FAILURE 1 #define MAX_RETRYS 3 +extern uint8_t nand_read_buf[DEFALUT_BUFLENGTH] __attribute__((aligned(4))); +bool test_overturn = false; -extern uint8_t buffer_verify[DEFALUT_BUFLENGTH]; +void test_nand_io_init(void) +{ + test_overturn = false; + uapi_pin_set_mode(S_AGPIO_R8, (pin_mode_t)HAL_PIO_FUNC_GPIO); + uapi_gpio_set_dir(S_AGPIO_R8, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(S_AGPIO_R8, GPIO_LEVEL_HIGH); +} +void test_nand_io_overturn(void) +{ + if(test_overturn) + { + test_overturn = false; + uapi_gpio_set_dir(S_AGPIO_R8, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(S_AGPIO_R8, GPIO_LEVEL_LOW); + } + else + { + test_overturn = true; + uapi_gpio_set_dir(S_AGPIO_R8, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(S_AGPIO_R8, GPIO_LEVEL_HIGH); + } +} + +extern uint8_t buffer_verify[DEFALUT_BUFLENGTH]; struct nand_driver_struct *nand_driver; +#ifdef __LITEOS__ extern char *OsCurTaskNameGet(void); +#endif +osal_mutex file_system_mux; + +void nand_lock(void) +{ + if (get_trans_type() == TRANS_BY_CPU_SINGLE_LINE) { + return; + } + osal_mutex_lock(&(file_system_mux)); +} + +void nand_unlock(void) +{ + if (get_trans_type() == TRANS_BY_CPU_SINGLE_LINE) { + return; + } + osal_mutex_unlock(&(file_system_mux)); +} void nand_register(struct mtd_info *mtd) { + test_nand_io_init(); + ext_errno ret; + if (file_system_mux.mutex == NULL) { + ret = osal_mutex_init(&(file_system_mux)); + if (ret != OSAL_SUCCESS) + { + return; + } + } + nand_driver = get_nand_flash(); mtd->size = nand_driver->pages_per_block * nand_driver->bytes_per_page * nand_driver->total_block; mtd->erasesize = nand_driver->pages_per_block * nand_driver->bytes_per_page; @@ -57,6 +117,10 @@ void nand_register(struct mtd_info *mtd) int os_nand_erase(const struct mtd_info *mtd, const struct erase_info *instr) { +#ifdef __LITEOS__ + NFPRINT("os_nand_erase %s \r\n",OsCurTaskNameGet()); +#endif + nand_lock(); uint32_t addr = (uint32_t)instr->addr; uint32_t len = (uint32_t)instr->len; NFPRINT("liteos_nand_erase addr=%u ,len=%u \r\n", addr, len); @@ -65,15 +129,18 @@ int os_nand_erase(const struct mtd_info *mtd, const struct erase_info *instr) NFPRINT("start block = %d\r\n", start_block); NFPRINT("block_num = %d \r\n", block_num); if ((addr & (mtd->erasesize - 1)) != 0) { - NFPRINT("Unaligned erase address!\r\n"); + PRINT("Unaligned erase address!\r\n"); + nand_unlock(); return FAILURE; } if ((len + addr) > mtd->size) { - NFPRINT("Out of range!\r\n"); + PRINT("Out of range!\r\n"); + nand_unlock(); return FAILURE; } if (len < mtd->erasesize) { - NFPRINT("Erase size 0x%08x smaller than one erase block 0x%08x\r\n!", len, mtd->erasesize); + PRINT("Erase size 0x%08x smaller than one erase block 0x%08x\r\n!", len, mtd->erasesize); + nand_unlock(); return FAILURE; } for (uint32_t i = 0; i < block_num; i++) { @@ -94,25 +161,30 @@ int os_nand_erase(const struct mtd_info *mtd, const struct erase_info *instr) } } NFPRINT("liteos_nand_erase SUCCESS \r\n"); + nand_unlock(); return SUCCESS; } int os_nand_read_oob(struct mtd_info *mtd, size_t from, size_t len, size_t *retlen, char *buf) { + + nand_lock(); uint32_t *change = (uint32_t *)&from; uint32_t addr_from = change[0]; *retlen = len; NFPRINT("read oob addr_from=%x len=%d \r\n", addr_from, len); if ((addr_from & (mtd->writesize - 1)) != 0) { - NFPRINT("Attempt to read non page aligned data, addr_from %08x.\n", + PRINT("Attempt to read non page aligned data, addr_from %08x.\n", (uint32_t)addr_from); + nand_unlock(); return FAILURE; } if ((len % (mtd->writesize + mtd->oobsize)) != 0) { - NFPRINT("Attempt to read non aligned data, read length should " + PRINT("Attempt to read non aligned data, read length should " "be aligned with (pagesize + oobsize), length:%d " "pagesize:%d oobsize:%d\n", (uint32_t)len, mtd->writesize, mtd->oobsize); + nand_unlock(); return FAILURE; } uint32_t len_data = len / (mtd->writesize + mtd->oobsize) * mtd->writesize; @@ -123,24 +195,34 @@ int os_nand_read_oob(struct mtd_info *mtd, size_t from, size_t len, size_t *retl NFPRINT("read oob len_data = %d , from_page = %d , currrent_page = %d\r\n", len_data, frompage, frompage + i); ret = nand_driver->read_page(frompage + i, (uint8_t *)buf + i * (mtd->writesize + mtd->oobsize), mtd->writesize, (uint8_t *)buf + i * (mtd->writesize + mtd->oobsize) + - mtd->writesize, mtd->oobsize, &status); + mtd->writesize, mtd->oobsize, &status, TRANS_DEFAULT); if (ret != MC_SUCCESS) { - NFPRINT("NAND read to from %08x failed %d \r\n", + ret = nand_driver->read_page(frompage + i, (uint8_t *)buf + i * (mtd->writesize + mtd->oobsize), + mtd->writesize, (uint8_t *)buf + i * (mtd->writesize + mtd->oobsize) + mtd->writesize, mtd->oobsize, &status, TRANS_BY_CPU_SINGLE_LINE); + } + if (ret != MC_SUCCESS) { + PRINT("NAND read to from %08x failed %d \r\n", (uint32_t)addr_from + i * mtd->writesize, ret); + nand_unlock(); return FAILURE; } len -= mtd->writesize + mtd->oobsize; } + nand_unlock(); return SUCCESS; } int os_nand_write_oob(struct mtd_info *mtd, size_t to, size_t len, size_t *retlen, const char *buf) { +#ifdef __LITEOS__ + NFPRINT("os_nand_write_oob %s \r\n",OsCurTaskNameGet()); +#endif + nand_lock(); uint32_t *change = (uint32_t *)&to; uint32_t from = change[0]; - *retlen = len; if ((from & (mtd->writesize - 1)) != 0) { NFPRINT("Attempt to read non page aligned data, to %08x.\n", (uint32_t)from); + nand_unlock(); return FAILURE; } if ((len % (mtd->writesize + mtd->oobsize)) != 0) { @@ -148,6 +230,7 @@ int os_nand_write_oob(struct mtd_info *mtd, size_t to, size_t len, size_t *retle "be aligned with (pagesize + oobsize), length:%d " "pagesize:%d oobsize:%d\n", (uint32_t)len, mtd->writesize, mtd->oobsize); + nand_unlock(); return FAILURE; } uint32_t len_data = len / (mtd->writesize + mtd->oobsize) * mtd->writesize; @@ -157,65 +240,78 @@ int os_nand_write_oob(struct mtd_info *mtd, size_t to, size_t len, size_t *retle for (uint32_t i = 0; i < len_data / mtd->writesize; i++) { uint8_t status; write_ret = nand_driver->write_page(frompage + i, (uint8_t *)buf + i * (mtd->writesize + mtd->oobsize), - mtd->writesize, (uint8_t *)buf + i * (mtd->writesize + mtd->oobsize) + - mtd->writesize, mtd->oobsize); - + mtd->writesize, (uint8_t *)buf + i * (mtd->writesize + mtd->oobsize) + mtd->writesize, mtd->oobsize); + memset_s(buffer_verify, OS_DUMP_LEN, 0, OS_DUMP_LEN); read_ret = nand_driver->read_page(frompage + i, (uint8_t *)buffer_verify, mtd->writesize, (uint8_t *)buffer_verify + mtd->writesize, mtd->oobsize, - &status); - if (write_ret != MC_SUCCESS) { - PRINT("NAND write to %08x failed %d \r\n", - (uint32_t)from + i * mtd->writesize, write_ret); + &status, TRANS_BY_CPU_SINGLE_LINE); + if (write_ret != MC_SUCCESS) + { + PRINT("NAND write to %08x failed %d \r\n", (uint32_t)from + i * mtd->writesize, write_ret); + nand_unlock(); return FAILURE; } if (read_ret != MC_SUCCESS) { - PRINT("NAND write read %08x failed %d \r\n", - (uint32_t)from + i * mtd->writesize, read_ret); + PRINT("NAND write read %08x failed %d \r\n", (uint32_t)from + i * mtd->writesize, read_ret); + nand_unlock(); return FAILURE; } for (uint32_t t = 0; t < (mtd->writesize + mtd->oobsize); t++) { if ((uint8_t)buffer_verify[t] != (uint8_t)(buf[i * (mtd->writesize + mtd->oobsize) + t])) { #ifdef __LITEOS__ + PRINT("PAGE = %d\r\n", frompage + i); PRINT("origin-----------------------------------------, diff index = %d\r\n", t); - OsDumpMemByte(OS_DUMP_LEN, (const char *)buf + i * (mtd->writesize + mtd->oobsize) + t); - PRINT("after------------------------------------------, diff index = %d\r\n", t); - OsDumpMemByte(OS_DUMP_LEN, buffer_verify + t); + OsDumpMemByte(OS_DUMP_LEN, (const char *)buf + i * (mtd->writesize + mtd->oobsize)); + PRINT("after1--nand_read_buf---------------------------, diff index = %d\r\n", t); + OsDumpMemByte(200, nand_read_buf); + PRINT("after2------------------------------------------, diff index = %d\r\n", t); + OsDumpMemByte(OS_DUMP_LEN, buffer_verify); + #endif PRINT("os_nand_write_oob check write fail, page = %d\r\n", frompage + i); - + nand_unlock(); return FAILURE; } } len -= mtd->writesize + mtd->oobsize; + *retlen = *retlen + mtd->writesize + mtd->oobsize; } + nand_unlock(); return SUCCESS; } int os_nand_block_isbad(const struct mtd_info *mtd, size_t ofs) { + nand_lock(); uint32_t *change = (uint32_t *)&ofs; uint32_t addr = change[0]; NFPRINT("check is bad addr = %x\r\n", addr); if ((addr & (mtd->erasesize - 1)) != 0) { NFPRINT("Unaligned checkbad address!\n"); + nand_unlock(); return FAILURE; } - uint8_t ret = (uint8_t)nand_driver->check_bad_block(addr / mtd->erasesize); + int ret = (uint8_t)nand_driver->check_bad_block(addr / mtd->erasesize); NFPRINT("liteos_nand_block_isbad ret = %d \r\n", ret); + nand_unlock(); return ret; } int os_nand_block_markbad(const struct mtd_info *mtd, size_t ofs) { + nand_lock(); uint32_t *change = (uint32_t *)&ofs; uint32_t addr = change[0]; NFPRINT("mark bad addr = %x \r\n", addr); if ((addr & (mtd->erasesize - 1)) != 0) { NFPRINT("Unaligned markbad address!\n"); + nand_unlock(); return FAILURE; } PRINT("mark bad block %d \r\n", addr / mtd->erasesize); - return (int)nand_driver->mark_bad_block(addr / mtd->erasesize); + int ret = (int)nand_driver->mark_bad_block(addr / mtd->erasesize); + nand_unlock(); + return ret; } int os_nand_read(const struct mtd_info *mtd, size_t from, size_t len, const size_t *retlen, const char *buf) diff --git a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_w25n01g.c b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_w25n01g.c index ee20594ee..6cf36fad8 100644 --- a/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_w25n01g.c +++ b/code/sdk/drivers/drivers/driver/nand_flash/nand/nandflash_w25n01g.c @@ -22,12 +22,12 @@ #define NAND_ID_DATA_SIZE 0x2 static uint32_t mc_w25n01g_read_page(uint32_t nand_page, uint8_t *data, uint32_t data_len, - uint8_t *oob, uint32_t oob_len, const uint32_t *ecc_result) + uint8_t *oob, uint32_t oob_len, const uint32_t *ecc_result, enum nandflash_trans_type type) { unused(ecc_result); uint32_t ret; uint8_t status_reg; - ret = mc_flash_read_page(nand_page, data, data_len, oob, oob_len, &status_reg); + ret = mc_flash_read_page(nand_page, data, data_len, oob, oob_len, &status_reg, type); if (get_nand_flash()->enable_ecc == true) { if (W25N01G_GET_ECC_STATUS(status_reg) >= W25N01G_ECC_ERROR) { return MC_FAILURE; diff --git a/code/sdk/drivers/drivers/driver/touch/touch_screen_drv.c b/code/sdk/drivers/drivers/driver/touch/touch_screen_drv.c index e729a5a34..56ca1561b 100644 --- a/code/sdk/drivers/drivers/driver/touch/touch_screen_drv.c +++ b/code/sdk/drivers/drivers/driver/touch/touch_screen_drv.c @@ -137,6 +137,7 @@ ext_errno touch_info_process(void) ret = tsdd->touch_api->touch_get_tpinfo((uint8_t *)(&touch_info), sizeof(input_event_info)); if (ret != EXT_ERR_SUCCESS) { tp_err("get touch info fail! ret=0x%x", ret); + return ret; } report_or_enqueue_event(&touch_info, tsdd); diff --git a/code/sdk/include/driver/flash/flash_config_info.h b/code/sdk/include/driver/flash/flash_config_info.h index bf6bc49dd..cc5b92628 100644 --- a/code/sdk/include/driver/flash/flash_config_info.h +++ b/code/sdk/include/driver/flash/flash_config_info.h @@ -95,7 +95,7 @@ static const flash_device_parameter_t g_flash_device_parameter[FLASH_MANUFACTURE g_gigadevice_gd25wq64_enter_qspi_mode_cmd, NULL, &g_gigadevice_gd25le64_config }, { FLASH_MANUFACTURER_GIGADEVICE_GD25LX128, FLASH_SIZE_16MB, 0x20, 0x0, WAIT_CYCLES_4, 0x05, 0x75, 0x7A, g_gigadevice_gd25lq128_enter_qspi_mode_cmd, NULL, &g_gigadevice_gd25lx_config }, - { FLASH_MANUFACTURER_GIGADEVICE_GD25LQ256, FLASH_SIZE_32MB, 0x20, 0x0, WAIT_CYCLES_4, 0x05, 0x75, 0x7A, + { FLASH_MANUFACTURER_GIGADEVICE_GD25LQ256, FLASH_SIZE_32MB, 0x20, 0x0, WAIT_CYCLES_6, 0x05, 0x75, 0x7A, g_gigadevice_gd25lq256_enter_qspi_mode_cmd, NULL, &g_gigadevice_gd25lq256_config }, { FLASH_MANUFACTURER_DOSILICON_FM25M64, FLASH_SIZE_8MB, 0xA0, 0x00, WAIT_CYCLES_2, 0x35, 0x75, 0x7A, g_dosilicon_fm25m64_enter_qspi_mode_cmd, NULL, &g_dosilicon_fm25m64_config }, diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/a2dp_service.c.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/a2dp_service.c.xml index 11dcdf6c6..f0aa24230 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/a2dp_service.c.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/a2dp_service.c.xml @@ -51,7 +51,10 @@ - - - + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/a2dp_snk_service.c.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/a2dp_snk_service.c.xml index 9081ff4ca..0688a090d 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/a2dp_snk_service.c.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/a2dp_snk_service.c.xml @@ -1,57 +1,60 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ability_mgr_service.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ability_mgr_service.cpp.xml index a0f6fdae9..fa34143c3 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ability_mgr_service.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ability_mgr_service.cpp.xml @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ability_service.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ability_service.cpp.xml index fe34a7b89..88b5026a7 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ability_service.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ability_service.cpp.xml @@ -28,8 +28,8 @@ - - - - + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style.cpp.xml index 308065ce2..58e9c459c 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style.cpp.xml @@ -1,10 +1,10 @@ - - - - - - - - - + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style_item.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style_item.cpp.xml index 24286d25e..26b47e879 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style_item.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style_item.cpp.xml @@ -1,9 +1,9 @@ - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style_manager.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style_manager.cpp.xml index edf505557..5d33c0cde 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style_manager.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/app_style_manager.cpp.xml @@ -1,5 +1,5 @@ - - - - + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/display_vau.c.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/display_vau.c.xml index d14d70828..3a1531925 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/display_vau.c.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/display_vau.c.xml @@ -2,49 +2,49 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/image_cache_manager.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/image_cache_manager.cpp.xml index 2777196cc..0477d384a 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/image_cache_manager.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/image_cache_manager.cpp.xml @@ -8,25 +8,25 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_fwk_common.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_fwk_common.cpp.xml index a881298a3..c8abf7dfd 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_fwk_common.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_fwk_common.cpp.xml @@ -8,39 +8,39 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_page_state.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_page_state.cpp.xml index e2fef883c..73ce328db 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_page_state.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_page_state.cpp.xml @@ -1,11 +1,11 @@ - - - - - - - - - - + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_page_state_machine.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_page_state_machine.cpp.xml index 5b549c3df..b7bb8bfda 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_page_state_machine.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_page_state_machine.cpp.xml @@ -1,22 +1,22 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_router.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_router.cpp.xml index 4e5c0b9f5..efe8c9181 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_router.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/js_router.cpp.xml @@ -1,9 +1,9 @@ - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/lite_m_gfx_engine.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/lite_m_gfx_engine.cpp.xml index abaa4dab8..58d336d49 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/lite_m_gfx_engine.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/lite_m_gfx_engine.cpp.xml @@ -1,33 +1,33 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/local_device_manager.c.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/local_device_manager.c.xml index 1c84d85dd..24f7bca23 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/local_device_manager.c.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/local_device_manager.c.xml @@ -9,86 +9,86 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/map_svg_parser.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/map_svg_parser.cpp.xml index 3fabf8d45..fdff0566e 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/map_svg_parser.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/map_svg_parser.cpp.xml @@ -1,72 +1,72 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/platform_adapter.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/platform_adapter.cpp.xml index f7d415b0f..4e9d3cc90 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/platform_adapter.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/platform_adapter.cpp.xml @@ -1,4 +1,4 @@ - - - + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/stack_av_if.c.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/stack_av_if.c.xml index eb6570bc3..7735bfb69 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/stack_av_if.c.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/stack_av_if.c.xml @@ -1,5 +1,6 @@ - - - - + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_coverflow_view2.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_coverflow_view2.cpp.xml new file mode 100644 index 000000000..cf81c8609 --- /dev/null +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_coverflow_view2.cpp.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_icosahedron_view.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_icosahedron_view.cpp.xml index 6c6fb96ee..c474fb166 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_icosahedron_view.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_icosahedron_view.cpp.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_map_view.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_map_view.cpp.xml index 102176720..ee2cc76b0 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_map_view.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_map_view.cpp.xml @@ -1,3 +1,3 @@ - - + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_roller_view.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_roller_view.cpp.xml index 6a4b694fa..2645a8d50 100644 --- a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_roller_view.cpp.xml +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_roller_view.cpp.xml @@ -1,12 +1,12 @@ - - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_transform_group.cpp.xml b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_transform_group.cpp.xml new file mode 100644 index 000000000..a9391cb37 --- /dev/null +++ b/code/sdk/interim_binary/brandy/acore/build_hso_cfg/hso_database/xml/base/closed_comp/ui_transform_group.cpp.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hdb/hdbcfg/mss_prim_db.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hdb/hdbcfg/mss_prim_db.xml index 27025ebea..0b2ac288f 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hdb/hdbcfg/mss_prim_db.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hdb/hdbcfg/mss_prim_db.xml @@ -178,7 +178,7 @@ - + @@ -307,22 +307,22 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + @@ -374,8 +374,8 @@ - - + + @@ -1824,7 +1824,7 @@ - + @@ -1977,7 +1977,7 @@ - + @@ -2467,10 +2467,10 @@ - + - + @@ -2609,8 +2609,7 @@ - - + @@ -2665,12 +2664,11 @@ - - - - - - + + + + + @@ -2732,8 +2730,8 @@ - - + + @@ -3597,7 +3595,7 @@ - + @@ -3907,14 +3905,14 @@ - - - - - - - - + + + + + + + + @@ -4409,27 +4407,27 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_av.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_av.c.xml index 4a907ae1c..6b93cc7d9 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_av.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_av.c.xml @@ -1,17 +1,17 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_gap.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_gap.c.xml index 80a7f158c..3aef8abe8 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_gap.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_gap.c.xml @@ -21,7 +21,7 @@ - + diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_spp.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_spp.c.xml index 8b8e67500..665529cf2 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_spp.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_ahi_spp.c.xml @@ -2,8 +2,8 @@ - + - + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_tran_task.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_tran_task.c.xml index 27e258d6e..8e263dece 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_tran_task.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/bt_tran_task.c.xml @@ -3,25 +3,25 @@ - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/ipc.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/ipc.c.xml index ea655be31..10c0f9fa0 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/ipc.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/ipc.c.xml @@ -1,4 +1,4 @@ - - + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/ld_acl_sniff_ram.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/ld_acl_sniff_ram.c.xml index 8f8db3f67..ff3554279 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/ld_acl_sniff_ram.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/ld_acl_sniff_ram.c.xml @@ -1,7 +1,6 @@ - - - - - - + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/packet_dl.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/packet_dl.c.xml index cc30b2798..7b6c1247f 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/packet_dl.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/packet_dl.c.xml @@ -1,12 +1,12 @@ - - - - - - - - + + + + + + + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/patch_bth.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/patch_bth.c.xml index 1b4dd880b..42e965be0 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/patch_bth.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/patch_bth.c.xml @@ -2,5 +2,5 @@ - + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/patch_lld_pdu.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/patch_lld_pdu.c.xml index 6cdef533a..f576d96b1 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/patch_lld_pdu.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/patch_lld_pdu.c.xml @@ -1,3 +1,2 @@ - - + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_av.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_av.c.xml index 777f4b09a..bc290a630 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_av.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_av.c.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_gap_conn_management.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_gap_conn_management.c.xml index 14ad471e7..cfbd09878 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_gap_conn_management.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_gap_conn_management.c.xml @@ -1,2 +1,2 @@ - + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_spp.c.xml b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_spp.c.xml index b98b09d3a..7a189df16 100644 --- a/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_spp.c.xml +++ b/code/sdk/interim_binary/brandy/bt/build_hso_cfg/hso_database/xml/base/bt_core/sdk_spp.c.xml @@ -3,6 +3,6 @@ - - + + \ No newline at end of file diff --git a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_audio_manager_wrapper.a b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_audio_manager_wrapper.a index d674673ce..e57248c91 100644 Binary files a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_audio_manager_wrapper.a and b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_audio_manager_wrapper.a differ diff --git a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_brandy_service.a b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_brandy_service.a index 4ce35cb9c..1e35cc3a5 100644 Binary files a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_brandy_service.a and b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_brandy_service.a differ diff --git a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_sdk.a b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_sdk.a index 22fdbfafc..3ed07885c 100644 Binary files a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_sdk.a and b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/freertos/br/libbt_host_sdk.a differ diff --git a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_audio_manager_wrapper.a b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_audio_manager_wrapper.a index 420cba03b..d3a056ddd 100644 Binary files a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_audio_manager_wrapper.a and b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_audio_manager_wrapper.a differ diff --git a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_brandy_service.a b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_brandy_service.a index b96a938ea..bb54f889b 100644 Binary files a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_brandy_service.a and b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_brandy_service.a differ diff --git a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_sdk.a b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_sdk.a index fe618d221..36388d058 100644 Binary files a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_sdk.a and b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/br/libbt_host_sdk.a differ diff --git a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/mini/br/libbt_host_brandy_service.a b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/mini/br/libbt_host_brandy_service.a index 789518409..50f9fb2a7 100644 Binary files a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/mini/br/libbt_host_brandy_service.a and b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/mini/br/libbt_host_brandy_service.a differ diff --git a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/mini/br/libbt_host_sdk.a b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/mini/br/libbt_host_sdk.a index fb9a2bdf1..cba656b53 100644 Binary files a/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/mini/br/libbt_host_sdk.a and b/code/sdk/interim_binary/brandy/libs/bt/evb_standard/liteos/mini/br/libbt_host_sdk.a differ diff --git a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/include/los_sched_pri.h b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/include/los_sched_pri.h index 6a07f0ca1..fea749591 100644 --- a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/include/los_sched_pri.h +++ b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/include/los_sched_pri.h @@ -34,6 +34,9 @@ #include "los_percpu_pri.h" #include "los_hwi.h" #include "los_spinlock_pri.h" +#ifdef LOSCFG_SYSTEM_VIEW +#include "SEGGER_SYSVIEW_LiteOS.h" +#endif #ifdef __cplusplus extern "C" { @@ -438,7 +441,9 @@ STATIC INLINE UINT32 OsSchedYield(LosTaskCB *runTask) if (OsPriQueueIsEmpty(runTask->priority)) { return LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK; } - +#ifdef LOSCFG_SYSTEM_VIEW + traceMOVED_TASK_TO_READY_STATE(runTask); +#endif runTask->taskStatus |= OS_TASK_STATUS_READY; OsPriQueueEnqueue(&runTask->pendList, runTask->priority, PRI_QUEUE_TAIL); diff --git a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/los_task.c b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/los_task.c index a86b6963f..d6947d6aa 100644 --- a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/los_task.c +++ b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/los_task.c @@ -982,7 +982,9 @@ STATIC UINT32 OsTaskCreateOnly(UINT32 *taskId, TSK_INIT_PARAM_S *initParam, VOID #endif *taskId = taskCB->taskId; - +#ifdef LOSCFG_SYSTEM_VIEW + traceTASK_CREATE(taskCB); +#endif return LOS_OK; LOS_ERREND_REWIND_TCB: @@ -1282,7 +1284,9 @@ LITE_OS_SEC_TEXT UINT32 LOS_TaskDelay(UINT32 tick) if (!OsPreemptable()) { return LOS_ERRNO_TSK_DELAY_IN_LOCK; } - +#ifdef LOSCFG_SYSTEM_VIEW + traceMOVED_TASK_TO_DELAYED_LIST(runTask); +#endif if (tick == 0) { return LOS_TaskYield(); } else { diff --git a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/sched/sched_sq/los_sched.c b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/sched/sched_sq/los_sched.c index 8d1a02667..8bfe31502 100644 --- a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/sched/sched_sq/los_sched.c +++ b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/base/sched/sched_sq/los_sched.c @@ -197,6 +197,9 @@ VOID OsSchedWait(LosTaskCB *runTask, LOS_DL_LIST *list, UINT32 timeout) { LOS_ASSERT(LOS_SpinHeld(&g_taskSpin)); +#ifdef LOSCFG_SYSTEM_VIEW + traceMOVED_TASK_TO_OVERFLOW_DELAYED_LIST(runTask); +#endif runTask->taskStatus |= OS_TASK_STATUS_PEND; LOS_ListTailInsert(list, &runTask->pendList); if (timeout != LOS_WAIT_FOREVER) { @@ -222,6 +225,9 @@ VOID OsSchedWake(LosTaskCB *resumedTask) } if (!(resumedTask->taskStatus & (OS_TASK_STATUS_SUSPEND))) { +#ifdef LOSCFG_SYSTEM_VIEW + traceMOVED_TASK_TO_READY_STATE(resumedTask); +#endif resumedTask->taskStatus |= OS_TASK_STATUS_READY; OsPriQueueEnqueue(&resumedTask->pendList, resumedTask->priority, PRI_QUEUE_TAIL); } diff --git a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/include/los_trace.h b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/include/los_trace.h index 6ba303242..1b2a220a6 100644 --- a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/include/los_trace.h +++ b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/kernel/include/los_trace.h @@ -39,6 +39,10 @@ #include "los_perf.h" +#ifdef LOSCFG_SYSTEM_VIEW +#include "SEGGER_SYSVIEW_LiteOS.h" +#endif + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ @@ -409,6 +413,8 @@ extern TRACE_EVENT_HOOK g_traceEventHook; g_traceEventHook(TYPE, _inner[1], _n > 2 ? &_inner[2] : NULL, _n - 2); \ } \ } while (0) +#elif defined(LOSCFG_SYSTEM_VIEW) +#define LOS_TRACE(TYPE, ...) LOS_TRACE_##TYPE(__VA_ARGS__) #else #define LOS_TRACE(TYPE, ...) LOS_PERF(TYPE) #endif diff --git a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/targets/brandy_app/board.cmake b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/targets/brandy_app/board.cmake index 2a2215746..5de5f4697 100644 --- a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/targets/brandy_app/board.cmake +++ b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/targets/brandy_app/board.cmake @@ -5,6 +5,10 @@ set(CFBB_DRV_INCLUDE ${ROOT_DIR}/drivers/chips/${CHIP}/include/ ${ROOT_DIR}/middleware/utils/common_headers/ ${ROOT_DIR}/include + ${ROOT_DIR}/application/wearable/SystemView/Src/SEGGER + ${ROOT_DIR}/application/wearable/SystemView/Src/Config + ${ROOT_DIR}/application/wearable/SystemView/Src/Sample/LiteOS + ) list(APPEND LOCAL_SRCS_y ${USER_SRC_TEMP}) diff --git a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/tools/build/config/brandy.config b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/tools/build/config/brandy.config index cb44da38b..69daa6ffb 100644 --- a/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/tools/build/config/brandy.config +++ b/code/sdk/kernel/liteos/liteos_v207.1.0/Huawei_LiteOS/tools/build/config/brandy.config @@ -230,3 +230,8 @@ LOSCFG_DRIVERS_SIMPLE_UART=y LOSCFG_CC_STACKPROTECTOR_STRONG=y # LOSCFG_CC_STACKPROTECTOR_ALL is not set # end of Stack Smashing Protector (SSP) Compiler Feature + +# +# SystemView Feature Switch +# +# LOSCFG_SYSTEM_VIEW is not set diff --git a/code/sdk/middleware/chips/brandy/dfx/dfx_system_init.c b/code/sdk/middleware/chips/brandy/dfx/dfx_system_init.c index b395d9451..044b717a7 100644 --- a/code/sdk/middleware/chips/brandy/dfx/dfx_system_init.c +++ b/code/sdk/middleware/chips/brandy/dfx/dfx_system_init.c @@ -419,8 +419,8 @@ errcode_t dfx_system_init(void) if (ret != ERRCODE_SUCC) { return ret; } -#ifdef USER_VERSION diag_highest_level_proc(DIAG_LOG_LEVEL_WARN); +#ifdef USER_VERSION mon_log_output_ctrl_init(); mon_log_output_enable(true); #endif diff --git a/code/sdk/middleware/chips/brandy/dfx/include/log_def_gui.h b/code/sdk/middleware/chips/brandy/dfx/include/log_def_gui.h index df22386cc..eadd45120 100644 --- a/code/sdk/middleware/chips/brandy/dfx/include/log_def_gui.h +++ b/code/sdk/middleware/chips/brandy/dfx/include/log_def_gui.h @@ -425,6 +425,7 @@ typedef enum { UI_KALEIDOSCOPE_VIEW_CPP, KALEIDOSCOPE_UTILS_CPP, UI_COVERFLOW_VIEW_CPP, + UI_COVERFLOW_VIEW2_CPP, UI_ROLLER_VIEW_CPP, UI_ICOSAHEDRON_VIEW_CPP, UI_MAP_VIEW_CPP, @@ -434,6 +435,11 @@ typedef enum { UI_PINYIN_CANDIDATE_CPP, HEXAGONSTRANSITION_CPP, BACKTOHEXAGONSTRANSITION_CPP, + UI_TRANSFORM_GROUP_CPP, + TURN_PAGE_VIEW_CPP, + TURN_PAGE_EFFECT_CPP, + NATIVEREGISTERMANAGER_CPP, + DFX_FRAME_TRACE_CPP, FILE_ID_MAX = 1024, } log_file_list_enum_gui_t; #endif diff --git a/code/sdk/middleware/chips/brandy/dfx/include/log_def_ohos.h b/code/sdk/middleware/chips/brandy/dfx/include/log_def_ohos.h index 13d1422a0..b5e2a6581 100644 --- a/code/sdk/middleware/chips/brandy/dfx/include/log_def_ohos.h +++ b/code/sdk/middleware/chips/brandy/dfx/include/log_def_ohos.h @@ -120,6 +120,9 @@ typedef enum { JSI_CPP, APP_MODULE_CPP, DEVICE_MODULE_CPP, + VIBRATOR_MODULE_CPP, + BATTERY_MODULE_CPP, + SENSOR_MODULE_CPP, DFX_MODULE_CPP, DIALOG_MODULE_CPP, LOCALE_MODULE_CPP, diff --git a/code/sdk/middleware/chips/brandy/dfx/zdiag_adapt_sdt.c b/code/sdk/middleware/chips/brandy/dfx/zdiag_adapt_sdt.c index ea74ec417..8049538a5 100644 --- a/code/sdk/middleware/chips/brandy/dfx/zdiag_adapt_sdt.c +++ b/code/sdk/middleware/chips/brandy/dfx/zdiag_adapt_sdt.c @@ -111,7 +111,7 @@ static void zdiag_adapt_sdt_om_log_parse(uint8_t *sdt_buf, uint16_t sdt_buf_size para->no = om_log->header.sn; para->buf = sdt_buf + sizeof(om_log_header_t); para->buf_size = (uint16_t)(sdt_buf_size - sizeof(om_log_header_t) - sizeof(uint8_t)); - para->level = (uint8_t)log_level_trans(sdt_level); + para->level = DIAG_LOG_LEVEL_ERROR; } static void zdiag_adapt_sdt_om_status_parse(uint8_t *sdt_buf, uint16_t sdt_buf_size, diag_msg_para_t *para) @@ -124,7 +124,7 @@ static void zdiag_adapt_sdt_om_status_parse(uint8_t *sdt_buf, uint16_t sdt_buf_s para->no = om_status->header.sn; para->buf = om_status->data; para->buf_size = om_status->data_len; - para->level = DIAG_LOG_LEVEL_INFO; + para->level = DIAG_LOG_LEVEL_ERROR; } static void zdiag_adapt_sdt_om_ota_parse(uint8_t *sdt_buf, uint16_t sdt_buf_size, diag_msg_para_t *para) @@ -135,7 +135,7 @@ static void zdiag_adapt_sdt_om_ota_parse(uint8_t *sdt_buf, uint16_t sdt_buf_size para->no = om_ota->header.sn; para->buf = sdt_buf + sizeof(om_ota_header_t); para->buf_size = (uint16_t)(sdt_buf_size - sizeof(om_ota_header_t) - sizeof(uint8_t)); - para->level = DIAG_LOG_LEVEL_INFO; + para->level = DIAG_LOG_LEVEL_ERROR; } static void zdiag_adapt_sdt_om_last_parse(uint8_t *sdt_buf, uint16_t sdt_buf_size, diag_msg_para_t *para) @@ -146,7 +146,7 @@ static void zdiag_adapt_sdt_om_last_parse(uint8_t *sdt_buf, uint16_t sdt_buf_siz para->no = om_last->msg_header.sn; para->buf = sdt_buf + sizeof(om_msg_header_stru_t); para->buf_size = (uint16_t)(sdt_buf_size - sizeof(om_msg_header_stru_t) - sizeof(uint8_t)); - para->level = DIAG_LOG_LEVEL_INFO; + para->level = DIAG_LOG_LEVEL_ERROR; } static void zdiag_adapt_sdt_msg_report(uint8_t *sdt_buf, uint16_t sdt_buf_size) @@ -338,10 +338,6 @@ void diag_debug_cmd_proc(uint8_t *data, uint32_t len) void diag_auto_log_report_enable(void) { uint32_t level[] = { -#ifndef USER_VERSION - DIAG_LOG_LEVEL_DBG, -#endif - DIAG_LOG_LEVEL_INFO, DIAG_LOG_LEVEL_WARN, DIAG_LOG_LEVEL_ERROR, }; diff --git a/code/sdk/middleware/chips/brandy/exception/chip_exception_utils.c b/code/sdk/middleware/chips/brandy/exception/chip_exception_utils.c index 0af3409a1..c7bcde5f0 100644 --- a/code/sdk/middleware/chips/brandy/exception/chip_exception_utils.c +++ b/code/sdk/middleware/chips/brandy/exception/chip_exception_utils.c @@ -8,6 +8,9 @@ #include #include "hal_reboot.h" #include "chip_io.h" +#include "sys/stat.h" +#include "fcntl.h" +#include "unistd.h" #define STATUS_ADDRESS 0x5702C1E8 #define VBUS_INSERT_POS 4 @@ -32,4 +35,69 @@ bool is_pwren_press(void) return true; } return false; +} + +static int32_t mkdir_all_path(const char *path) +{ + int path_len = (int)strlen(path); + if (path_len <= 0) { + return -1; + } + + char *str_path = (char *)malloc((uint32_t)path_len + 1); + if (str_path == NULL) { + return -1; + } + (void)memset_s(str_path, (uint32_t)path_len + 1, 0, (uint32_t)path_len + 1); + if (strcpy_s(str_path, (uint32_t)path_len + 1, path) != 0) { + free(str_path); + return -1; + } + + for (int i = 0; i < path_len; i++) { + if (i > 0 && str_path[i] == '/') { + str_path[i] = '\0'; + if (access(str_path, 0) == 0) { + str_path[i] = '/'; + continue; + } + if (mkdir(str_path, S_IREAD | S_IWRITE) != 0) { + free(str_path); + return -1; + } + str_path[i] = '/'; + } + } + free(str_path); + return 0; +} + +int32_t write_fileinfo(const char *path, uint32_t offset, const uint8_t *buf, uint32_t size) +{ + int fd; + int ret; + ssize_t len; + fd = open(path, O_RDWR | O_CREAT, 0); + if (fd < 0) { + if (mkdir_all_path(path) != 0) { + return -1; + } + fd = open(path, O_RDWR | O_CREAT, 0); + if (fd < 0) { + return -1; + } + } + int pos = (int)lseek(fd, offset, SEEK_SET); + if (pos < 0) { + return -1; + } + len = write(fd, buf, size); + if (len < 0) { + return -1; + } + ret = close(fd); + if (ret < 0) { + return -1; + } + return len; } \ No newline at end of file diff --git a/code/sdk/middleware/chips/brandy/exception/chip_exception_utils.h b/code/sdk/middleware/chips/brandy/exception/chip_exception_utils.h index 2a7a67998..003e01a90 100644 --- a/code/sdk/middleware/chips/brandy/exception/chip_exception_utils.h +++ b/code/sdk/middleware/chips/brandy/exception/chip_exception_utils.h @@ -28,4 +28,10 @@ bool is_vbus_insert(void); * @return true if PWREN is pressed, false otherwise. */ bool is_pwren_press(void); + +/** + * @brief create a file and write info + * @return write length + */ +int32_t write_fileinfo(const char *path, uint32_t offset, const uint8_t *buf, uint32_t size); #endif diff --git a/code/sdk/middleware/chips/brandy/exception/exception_dump.c b/code/sdk/middleware/chips/brandy/exception/exception_dump.c index 6d42aea84..aa46e3a60 100644 --- a/code/sdk/middleware/chips/brandy/exception/exception_dump.c +++ b/code/sdk/middleware/chips/brandy/exception/exception_dump.c @@ -12,16 +12,23 @@ #include "time.h" #include "sys/time.h" #include "chip_io.h" +#include "flash.h" +#include "soc_osal.h" +#include "vectors.h" +#include "chip_exception_utils.h" + +#define MAX_FILE_NAME_LENGTH 100 +#define REGS_BUFF_SIZE 500 + #ifdef CFG_DRIVERS_NANDFLASH #include "nandflash_config.h" - #define PSRAM_DUMP_TO_FILE_LENGTH 0x40000 // 256KB void exception_dump_memory_to_file(char *file_name, uint32_t dump_time, uintptr_t startAddr, uint32_t length) { - char *str = (char *)malloc(200); - memset_s(str, 200, 0, 200); - sprintf(str, file_name, dump_time); + char *str = (char *)malloc(MAX_FILE_NAME_LENGTH); + memset_s(str, MAX_FILE_NAME_LENGTH, 0, MAX_FILE_NAME_LENGTH); + sprintf_s(str, MAX_FILE_NAME_LENGTH, file_name, dump_time); exc_info_write(str, 0, (const uint8_t *)startAddr, length); } @@ -50,27 +57,16 @@ void dump_mem_to_file(uint32_t time_sec) #endif #ifdef CFG_DUMP_REG_SUPPORT -char *g_regist_str = "[PMU1_B_SOC_PWR_EN_REG %x, %x]\r\n - [PMU1_BT_CBB_PWR_EN_REG %x, %x]\r\n - [PMU1_BMEM_PWR_EN_REG %x, %x]\r\n - [PMU1_BT_EM_PWR_EN_REG %x, %x]\r\n - [PMU1_MCU_HS_PWR_EN_REG %x, %x]\r\n - [PMU1_DSUB_PWR_EN_REG %x, %x]\r\n - [PMU1_ASUB_PWR_EN_REG %x, %x]\r\n - [PMU1_S_EGPIO_PWR_EN_REG %x, %x]\r\n - [PMU1_BT_RF_PWR_EN_REG %x, %x]\r\n - [PMU1_MCU_PWR_EN_REG %x, %x]\r\n - [PMU1_MEM_PWR_EN_REG %x, %x]\r\n - [PMU1_COM_PWR_EN_REG %x, %x]"; +char *g_regist_str = "[PMU1_B_SOC_PWR_EN_REG %x, %x]\r\n[PMU1_BT_CBB_PWR_EN_REG %x, %x]\r\n[PMU1_BMEM_PWR_EN_REG %x, %x]\r\n[PMU1_BT_EM_PWR_EN_REG %x, %x]\r\n[PMU1_MCU_HS_PWR_EN_REG %x, %x]\r\n[PMU1_DSUB_PWR_EN_REG %x, %x]\r\n[PMU1_ASUB_PWR_EN_REG %x, %x]\r\n[PMU1_S_EGPIO_PWR_EN_REG %x, %x]\r\n[PMU1_BT_RF_PWR_EN_REG %x, %x]\r\n[PMU1_MCU_PWR_EN_REG %x, %x]\r\n[PMU1_MEM_PWR_EN_REG %x, %x]\r\n[PMU1_COM_PWR_EN_REG %x, %x]"; static const char *g_reg_path = "/user/exc/reg_path%d.txt"; void dump_reg_to_file(uint32_t time_sec) { - char *file_name = (char *)malloc(100); - sprintf(file_name, g_reg_path, time_sec); - char *str = (char *)malloc(500); + char *file_name = (char *)malloc(MAX_FILE_NAME_LENGTH); + sprintf_s(file_name, MAX_FILE_NAME_LENGTH, g_reg_path, time_sec); + char *str = (char *)malloc(REGS_BUFF_SIZE); uint32_t ctrl_base = 0x57004000; - sprintf(str, g_regist_str, + sprintf_s(str, REGS_BUFF_SIZE, g_regist_str, ctrl_base + 0x20, readl(ctrl_base + 0x20), ctrl_base + 0x24, readl(ctrl_base + 0x24), ctrl_base + 0x28, readl(ctrl_base + 0x28), @@ -96,4 +92,71 @@ void dump_all_to_file(void) #ifdef CFG_DUMP_REG_SUPPORT dump_reg_to_file(timestamp); #endif +} + +#define MAGIC_SIZE 8 +#define NORFLASH_TRACE_START 0x3d000 +#define NORFLASH_DEBUG_LENGTH 0x3000 +#define NORFLASH_DEVIATION 0x70000000 +static const char *g_trace_in_norflash = "/user/exc/norflash_trace_%s_%d.bin"; +static const char *g_exc_in_norflash = "/user/exc/norflash_exc_%s_%d.bin"; +void write_trace(exc_context_t *exc_buff_addr) +{ +#if defined(BUILD_APPLICATION_STANDARD) && !defined(BUILD_RECOVERY_IMAGE) + uint8_t magic_array[MAGIC_SIZE] = {0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a}; + uapi_flash_exit_from_xip_mode(CHIP_FLASH_ID); + uapi_flash_write_data(CHIP_FLASH_ID, NORFLASH_TRACE_START, magic_array, MAGIC_SIZE); + uapi_flash_write_data(CHIP_FLASH_ID, + NORFLASH_TRACE_START + MAGIC_SIZE, + (const uint8_t *)MCPU_TRACE_MEM_REGION_START, + CPU_TRACE_MEM_REGION_LENGTH); + uint32_t exc_buff_size = sizeof(exc_context_t); + uapi_flash_write_data( + CHIP_FLASH_ID, NORFLASH_TRACE_START + MAGIC_SIZE + CPU_TRACE_MEM_REGION_LENGTH, exc_buff_addr, exc_buff_size); + uapi_flash_switch_to_xip_mode(CHIP_FLASH_ID); +#endif +} + +void dump_norflash_trace_to_file(void) +{ +#if defined(BUILD_APPLICATION_STANDARD) && !defined(BUILD_RECOVERY_IMAGE) + if (readl(NORFLASH_DEVIATION + NORFLASH_TRACE_START) == 0x5a5a5a5a) { + uint32_t current_time = get_local_timestamp(); + char file_name_buff[MAX_FILE_NAME_LENGTH]; + uint32_t exc_buff_size = sizeof(exc_context_t); + sprintf_s(file_name_buff, MAX_FILE_NAME_LENGTH, g_trace_in_norflash, "FIRMWARE_VERSION", current_time); + write_fileinfo(file_name_buff, + 0, + (const uint8_t *)(NORFLASH_DEVIATION + NORFLASH_TRACE_START + MAGIC_SIZE), + CPU_TRACE_MEM_REGION_LENGTH); + memset_s(file_name_buff, MAX_FILE_NAME_LENGTH, 0, MAX_FILE_NAME_LENGTH); + sprintf_s(file_name_buff, MAX_FILE_NAME_LENGTH, g_exc_in_norflash, "FIRMWARE_VERSION", current_time); + write_fileinfo(file_name_buff, + 0, + (const uint8_t *)(NORFLASH_DEVIATION + NORFLASH_TRACE_START + MAGIC_SIZE + CPU_TRACE_MEM_REGION_LENGTH), + exc_buff_size); + unsigned int irq_sts = osal_irq_lock(); + if (uapi_flash_exit_from_xip_mode(0) != ERRCODE_SUCC) { + return; + } + uapi_flash_block_erase(CHIP_FLASH_ID, NORFLASH_TRACE_START, NORFLASH_DEBUG_LENGTH, true); + if (uapi_flash_switch_to_xip_mode(0) != ERRCODE_SUCC) { + return; + } + osal_irq_restore(irq_sts); + } +#endif +} + +void printcpu_tracemem(void) +{ + uint32_t colum = 16; + uint32_t line = CPU_TRACE_MEM_REGION_LENGTH / colum; + for (uint32_t j = 0; j < line; j++) { + for (uint32_t i = 0; i < colum; i++) { + uint32_t index = j * colum + i + MCPU_TRACE_MEM_REGION_START; + printf("%02x ", readb(index)); + } + printf("\r\n"); + } } \ No newline at end of file diff --git a/code/sdk/middleware/chips/brandy/exception/exception_dump.h b/code/sdk/middleware/chips/brandy/exception/exception_dump.h index e375ec13c..b6d75c83e 100644 --- a/code/sdk/middleware/chips/brandy/exception/exception_dump.h +++ b/code/sdk/middleware/chips/brandy/exception/exception_dump.h @@ -6,6 +6,7 @@ */ #ifndef EXCEPTION_DUMP_H #define EXCEPTION_DUMP_H +#include "vectors.h" /** * @brief support nandflash storage dump sysmem to file. @@ -13,4 +14,10 @@ */ void dump_all_to_file(void); +void printcpu_tracemem(void); + +void write_trace(exc_context_t *exc_buff_addr); + +void dump_norflash_trace_to_file(void); + #endif \ No newline at end of file diff --git a/code/sdk/middleware/chips/brandy/exception/exception_riscv.c b/code/sdk/middleware/chips/brandy/exception/exception_riscv.c index 819b816b8..39e82ad00 100644 --- a/code/sdk/middleware/chips/brandy/exception/exception_riscv.c +++ b/code/sdk/middleware/chips/brandy/exception/exception_riscv.c @@ -382,6 +382,7 @@ void exc_info_display(const exc_info_t *exc) #endif PRINT("ra = 0x%x\n", exc->context->task_context.ra); PRINT("sp = 0x%x\n", exc->context->task_context.sp); +#ifndef BUILD_RECOVERY_IMAGE PRINT("gp = 0x%x\n", exc->context->gp); PRINT("tp = 0x%x\n", exc->context->task_context.tp); PRINT("t0 = 0x%x\n", exc->context->task_context.t0); @@ -411,8 +412,9 @@ void exc_info_display(const exc_info_t *exc) PRINT("t4 = 0x%x\n", exc->context->task_context.t4); PRINT("t5 = 0x%x\n", exc->context->task_context.t5); PRINT("t6 = 0x%x\n", exc->context->task_context.t6); - PRINT("**************Exception Information end************** \n"); +#endif + return; } @@ -918,6 +920,11 @@ void do_hard_fault_handler(exc_context_t *exc_buf_addr) /* Some exception apis are in the XIP region. Ensure the flash in XIP mode */ uapi_flash_switch_to_xip_mode(CHIP_FLASH_ID); #if (CORE == MASTER_BY_ALL) && (CORE != WIFI) + if (g_is_repeat_exc == false) { + // if is first excepion write cpu trace to norflash + write_trace(exc_buf_addr); + } + if (g_is_repeat_exc == true) { cpu_utils_reset_chip_with_log((cores_t)MASTER_BY_ALL, REBOOT_CAUSE_APPLICATION_SECOND_FAULT); } diff --git a/code/sdk/middleware/services/gpu/drv/dpu/disp/dpu_disp.c b/code/sdk/middleware/services/gpu/drv/dpu/disp/dpu_disp.c index 0bef4b513..5f487bc26 100644 --- a/code/sdk/middleware/services/gpu/drv/dpu/disp/dpu_disp.c +++ b/code/sdk/middleware/services/gpu/drv/dpu/disp/dpu_disp.c @@ -123,7 +123,6 @@ static td_void disp_set_cbm_default_priority(td_void) static td_void disp_set_isr_enable(td_bool enable) { dpu_hal_disp_set_dhd0_te_mode(enable); /* set dpu work te mode */ - dpu_hal_disp_set_int_enable(DPU_DISP_INT_TYPE_TE_INT, enable); dpu_hal_disp_set_int_enable(DPU_DISP_INT_TYPE_LOWBAND, enable); dpu_hal_disp_set_int_enable(DPU_DISP_INT_TYPE_BUS_ERR, enable); dpu_hal_disp_set_int_enable(DPU_DISP_INT_TYPE_FRM_DONE, enable); diff --git a/code/sdk/middleware/services/gpu/drv/vau/hal/vau_hal_apb.c b/code/sdk/middleware/services/gpu/drv/vau/hal/vau_hal_apb.c index 63889bdc7..c4491187d 100644 --- a/code/sdk/middleware/services/gpu/drv/vau/hal/vau_hal_apb.c +++ b/code/sdk/middleware/services/gpu/drv/vau/hal/vau_hal_apb.c @@ -7,6 +7,7 @@ #include "vau_reg_define.h" #include "vau_dfx.h" +static td_float g_cubic_threshold = 0.125f; static td_void hal_apb_set_vau_srst_req(td_bool reset) { volatile u_video_srst_reg video_srst_reg; @@ -227,7 +228,7 @@ td_void vau_hal_apb_vector_draw_init(td_void) u_vau_draw_cvrg_weight1 weight1; quad.bits.threshold_quad = 0.125; /* 0.125 : default threshold for quad split */ - cubic.bits.threshold_cubic = 0.125; /* 0.125 : default threshold for cubic split */ + cubic.bits.threshold_cubic = g_cubic_threshold; /* 0.125 : default threshold for cubic split */ weight0.bits.weight0 = 32; /* 32 default weithg for 8x */ weight0.bits.weight1 = 32; /* 32 default weithg for 8x */ @@ -250,14 +251,10 @@ td_void vau_hal_apb_vector_draw_init(td_void) td_void vau_hal_apb_set_cubic_threshold(td_float cubic_threshold) { u_vau_draw_threshold_cubic cubic; + cubic.bits.threshold_cubic = cubic_threshold; + uapi_reg_write(HAL_VAU_DRAW_THRESHOLD_CUBIC, cubic.u32); - if (cubic_threshold != 0) { - cubic.bits.threshold_cubic = cubic_threshold; - uapi_reg_write(HAL_VAU_DRAW_THRESHOLD_CUBIC, cubic.u32); - } else { - cubic.bits.threshold_cubic = 0.125; /* 0.125 : default threshold for cubic split */ - uapi_reg_write(HAL_VAU_DRAW_THRESHOLD_CUBIC, cubic.u32); - } + g_cubic_threshold = cubic_threshold; } td_void vau_hal_apb_vector_cmddata_range(td_u32 type, td_u32 start, td_u32 end) diff --git a/code/sdk/middleware/services/gui/hal/display/brandy-native-js/libdisplay_gfx.a b/code/sdk/middleware/services/gui/hal/display/brandy-native-js/libdisplay_gfx.a index 821e28a4a..74ed30a9b 100644 Binary files a/code/sdk/middleware/services/gui/hal/display/brandy-native-js/libdisplay_gfx.a and b/code/sdk/middleware/services/gui/hal/display/brandy-native-js/libdisplay_gfx.a differ diff --git a/code/sdk/middleware/services/gui/hal/display/brandy-target1/libdisplay_gfx.a b/code/sdk/middleware/services/gui/hal/display/brandy-target1/libdisplay_gfx.a index e2d1e495a..e4ea39739 100644 Binary files a/code/sdk/middleware/services/gui/hal/display/brandy-target1/libdisplay_gfx.a and b/code/sdk/middleware/services/gui/hal/display/brandy-target1/libdisplay_gfx.a differ diff --git a/code/sdk/middleware/services/gui/hal/display/brandy-target3/libdisplay_gfx.a b/code/sdk/middleware/services/gui/hal/display/brandy-target3/libdisplay_gfx.a index 1f6453e6c..975c3d690 100644 Binary files a/code/sdk/middleware/services/gui/hal/display/brandy-target3/libdisplay_gfx.a and b/code/sdk/middleware/services/gui/hal/display/brandy-target3/libdisplay_gfx.a differ diff --git a/code/sdk/middleware/services/gui/hal/display/brandy-target5/libdisplay_gfx.a b/code/sdk/middleware/services/gui/hal/display/brandy-target5/libdisplay_gfx.a index 048b824df..cacde7271 100644 Binary files a/code/sdk/middleware/services/gui/hal/display/brandy-target5/libdisplay_gfx.a and b/code/sdk/middleware/services/gui/hal/display/brandy-target5/libdisplay_gfx.a differ diff --git a/code/sdk/middleware/services/gui/hal/display/brandy-xts/libdisplay_gfx.a b/code/sdk/middleware/services/gui/hal/display/brandy-xts/libdisplay_gfx.a index 904c630e4..1a0160a6b 100644 Binary files a/code/sdk/middleware/services/gui/hal/display/brandy-xts/libdisplay_gfx.a and b/code/sdk/middleware/services/gui/hal/display/brandy-xts/libdisplay_gfx.a differ diff --git a/code/sdk/middleware/services/gui/uikit/CMakeLists.txt b/code/sdk/middleware/services/gui/uikit/CMakeLists.txt index 3abb11ebb..cdc8492c9 100644 --- a/code/sdk/middleware/services/gui/uikit/CMakeLists.txt +++ b/code/sdk/middleware/services/gui/uikit/CMakeLists.txt @@ -218,7 +218,10 @@ set(COMPONENT_SRC ${PROP_UI_SRC}/components_ext/ui_map_view.cpp ${PROP_UI_SRC}/components_ext/map_svg_parser.cpp ${PROP_UI_SRC}/components_ext/ui_coverflow_view.cpp + ${PROP_UI_SRC}/components_ext/ui_coverflow_view2.cpp ${PROP_UI_SRC}/components_ext/ui_icosahedron_view.cpp + ${PROP_UI_SRC}/components_ext/ui_transform_group.cpp + ${PROP_UI_SRC}/components_ext/ui_transform_list.cpp ) set(SOURCES diff --git a/code/sdk/middleware/services/gui/uikit/brandy-native-js/libuikit_ext.a b/code/sdk/middleware/services/gui/uikit/brandy-native-js/libuikit_ext.a index 213b424c9..5c9785d25 100644 Binary files a/code/sdk/middleware/services/gui/uikit/brandy-native-js/libuikit_ext.a and b/code/sdk/middleware/services/gui/uikit/brandy-native-js/libuikit_ext.a differ diff --git a/code/sdk/middleware/services/gui/uikit/brandy-target3/libuikit_ext.a b/code/sdk/middleware/services/gui/uikit/brandy-target3/libuikit_ext.a index fbd2d9546..e92e26d04 100644 Binary files a/code/sdk/middleware/services/gui/uikit/brandy-target3/libuikit_ext.a and b/code/sdk/middleware/services/gui/uikit/brandy-target3/libuikit_ext.a differ diff --git a/code/sdk/middleware/services/gui/uikit/brandy-xts/libuikit_ext.a b/code/sdk/middleware/services/gui/uikit/brandy-xts/libuikit_ext.a index 66d9bc246..d3760eba6 100644 Binary files a/code/sdk/middleware/services/gui/uikit/brandy-xts/libuikit_ext.a and b/code/sdk/middleware/services/gui/uikit/brandy-xts/libuikit_ext.a differ diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_coverflow_view2.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_coverflow_view2.h new file mode 100644 index 000000000..d6595bc34 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_coverflow_view2.h @@ -0,0 +1,131 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UI_COVERFLOW_VIEW_2_H +#define UI_COVERFLOW_VIEW_2_H +#include "components/ui_image_view.h" +#include "components/ui_label.h" +#include "components/ui_swipe_view.h" +#include "components/ui_transform_group.h" +#include "gfx_utils/vector.h" + +namespace OHOS { +class UICoverFlowView2 : public UISwipeView { +public: + explicit UICoverFlowView2(bool supportMirror = true, uint8_t mirrorOpa = 50); // 50:mirror view opaque + ~UICoverFlowView2() override; + + /** + * @brief Obtains the component type. + * + * @return Returns the component type, as defined in {@link UIViewType}. + * @since 1.0 + * @version 1.0 + */ + UIViewType GetViewType() const override + { + return UI_COVER_FLOW_2; + } + + /** + * @brief Adds a child view. + * + * @param view Indicates the pointer to the child view to add. + * Only UITransform are allowed to be added. + * Mirror image with UICanvasExt in UITransform are not supported. + * @since 1.0 + * @version 1.0 + */ + void Add(UIView* view) override; + + /** + * @brief Inserts a new child view behind the current one. + * + * @param prevView Indicates the pointer to the current child view, previous to the new child view to insert. + * @param view Indicates the pointer to the new child view to insert. + * @since 1.0 + * @version 1.0 + */ + void Insert(UIView* prevView, UIView* insertView) override; + + /** + * @brief Removes a child view. + * + * @param view Indicates the pointer to the child view to remove. + * @since 1.0 + * @version 1.0 + */ + void Remove(UIView* view) override; + + /** + * @brief Set page direct interval. + * + * @param padding setting padding value. The interval between two images is twice the padding. + */ + void SetPagePadding(uint16_t padding); + + /** + * @brief Set rotate angle between the left and right items in static display mode. + * + * @param angle setting rotate angle. + */ + void SetChildMaxRotateAngle(float angle); + + /** + * @brief Represents a listener for swipe of the coverflow view. + */ + class OnCoverflowScrollListener : public HeapBase { + public: + virtual bool OnScroll(uint16_t distance) = 0; + virtual ~OnCoverflowScrollListener() {} + }; + + /** + * @brief Sets the listener that contains a callback to be invoked upon a swipe event. + * + * @param onCoverflowListener Indicates the listener to set. + * @since 1.0 + * @version 1.0 + */ + void SetOnCoverflowListener(OnCoverflowScrollListener* onCoverflowListener) + { + coverflowListener_ = onCoverflowListener; + } + + void SetDirection(uint8_t direction) = delete; + uint8_t GetDirection() const = delete; +protected: + bool DragXInner(int16_t distance) override; + void RefreshCurrentView(int16_t distance, uint8_t dragDirection) override; + +private: + void ReMeasure(void) override; + bool CalCurViewInfo(); + void UpdatePerspectiveMatrix(); + + using UISwipeView::Add; + using UISwipeView::Remove; + Matrix4 perspectiveMatrix_; + OnCoverflowScrollListener* coverflowListener_; + uint16_t swipeMid_; + float rotateAngle_; + bool isFirstRender_; + uint16_t padding_; + uint8_t mirrorOpa_; + bool isShowMirrorImg_; + Graphic::Vector mirrorViews_; +}; +} // namespace OHOS +#endif // UI_COVERFLOW_VIEW_2_H diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_label_ext.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_label_ext.h index 12a4b7ec1..701bd2ac2 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_label_ext.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_label_ext.h @@ -83,8 +83,6 @@ public: * */ void ForceResetText() override; - - void SetTextTransformMap(TransformMap& transMap); protected: void InitLabelText() override; }; diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_roller_view.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_roller_view.h index f5b6c0843..7401eadf2 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_roller_view.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_roller_view.h @@ -28,7 +28,10 @@ enum RollerViewMode { class UIRollerView : public UIAbstractScroll { public: - UIRollerView(); + /** + * @brief If want to turn off mirroring, It needs to be configured during construction. + */ + UIRollerView(bool isShowMirrorImg_ = true); virtual ~UIRollerView() override; /** @@ -83,7 +86,7 @@ public: UIViewGroup* GetCurrentItem(); /** - * @brief Set current item. + * @brief Set current item. must to call it once. */ void SetCurrentItem(std::string name, bool enableAnimator = false); @@ -330,6 +333,7 @@ private: bool needLayout_ = false; UIViewGroup* currentItem_ = nullptr; UIViewGroup* alignItem_ = nullptr; + bool isShowMirrorImg_; float alignAngle_ = 0.0f; }; } // namespace OHOS diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_transform_group.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_transform_group.h new file mode 100644 index 000000000..ade79f632 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_transform_group.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GRAPHIC_UI_TRANSFORM_GROUP_H +#define GRAPHIC_UI_TRANSFORM_GROUP_H +#include "graphic_config.h" +#include "components/ui_view_group.h" + +namespace OHOS { +class UITransformGroup : public UIViewGroup { +public: + UITransformGroup(); + UITransformGroup(UITransformGroup* view); + virtual ~UITransformGroup(); + + /** + * @brief Obtains the view type. + * + * @return Returns UI_TRANSFORM_GROUP, as defined in {@link UIViewType}. + */ + UIViewType GetViewType() const override + { + return UI_TRANSFORM_GROUP; + } + + /** + * @brief Adds a child view. + * + * @param view Indicates the pointer to the child view to add. + * Support add . + */ + virtual void Add(UIView* view) override; + + /** + * @brief Set camera position the view in 3d. + * @param position Indicates camera position. + * @since 5.0 + * @version 3.0 + */ + void SetCameraPosition(const Vector3& position); + + /** + * @brief Sets a style. + * + * @param key Indicates the key of the style to set. + * @param value Indicates the value matching the key. + * @since 1.0 + * @version 1.0 + */ + void SetStyle(uint8_t key, int64_t value) override; +private: + void ReMeasure() override; + void DeleteMirrorView(); + TransformMap labelTextTransMap_; +}; +} // namespace OHOS +#endif // GRAPHIC_UI_TRANSFORM_GROUP_H \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_transform_list.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_transform_list.h new file mode 100644 index 000000000..863756e71 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/components/ui_transform_list.h @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GRAPHIC_UI_TRANSFORM_LIST_H +#define GRAPHIC_UI_TRANSFORM_LIST_H +#include "graphic_config.h" +#include "components/ui_list.h" +#include "components/ui_transform_group.h" +#include "gfx_utils/vector.h" + +namespace OHOS { +class UITransformList : public UIList { +public: + /** + * @brief A constructor used to create a UITransformList instance. + * + * @since 1.0 + * @version 1.0 + */ + UITransformList() : transformFunc_(nullptr), space_(5) {} // 5: default item space + + /** + * @brief A constructor used to create a UITransformList instance. + * + * @since 1.0 + * @version 1.0 + */ + explicit UITransformList(uint8_t direction) + { + SetDirection(direction); + } + + /** + * @brief A destructor used to delete the UITransformList instance. + * + * @since 1.0 + * @version 1.0 + */ + ~UITransformList() override {} + + /** + * @brief Obtains the view type. + * @return Returns the view type, as defined in {@link UIViewType}. + * @since 1.0 + * @version 1.0 + */ + UIViewType GetViewType() const override + { + return UI_TRANSFORM_LIST; + } + + /** + * @brief Sets the spacing between items. + * + * @param value Indicates spacing between items. + */ + void SetItemSpace(uint16_t value) + { + space_ = value; + } + + /** + * @brief Customized transformation function type. + * + * @param list Indicates current transformlist obj. + * @param item Indicates current item obj. + * @return whether an item is in the middle. + * true current item is center view. + * false current item is not center view. + */ + using TransformFunc = bool (*)(UITransformList* list, UIView* item); + + /** + * @brief Setting a custom transformation function. + * + * @param func Indicates Transformation function point. + */ + void SetItemTransformFunc(TransformFunc func); + +protected: + void ModifyItemSpace(int16_t centerIndex); + void ReMeasure() override; + +private: + TransformFunc transformFunc_; + uint16_t space_; + Graphic::Vector items_; +}; +} // namespace OHOS +#endif // GRAPHIC_UI_TRANSFORM_LIST_H \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/dfx/dfx_dom_dump.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/dfx/dfx_dom_dump.h new file mode 100644 index 000000000..1bbeaed06 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/dfx/dfx_dom_dump.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GRAPHIC_LITE_DFX_DOM_DUMP_H +#define GRAPHIC_LITE_DFX_DOM_DUMP_H +#include +#include "cJSON.h" +#include "graphic_config.h" +#include "gfx_utils/vector.h" +#include "components/ui_view.h" +#include "components/root_view.h" + +namespace OHOS { +class DfxDomDump : public HeapBase { + struct DomNode : public HeapBase { + DomNode *parent = nullptr; + UIView *view = nullptr; + cJSON *obj = nullptr; + DomNode(DomNode *par = nullptr, UIView *vw = nullptr, cJSON *object = nullptr) + : parent(par), view(vw), obj(object) {} + ~DomNode() {} + }; +public: + static DfxDomDump &GetInstance(); + virtual ~DfxDomDump(); + DfxDomDump(const DfxDomDump&) = delete; + DfxDomDump &operator=(const DfxDomDump&) = delete; + + void DumpRootView(); + void DumpView(UIView *view); + +private: + DfxDomDump(); + bool AddAttribute(cJSON *node, UIView *view) const; + bool AddCommonAttribute(cJSON *node, UIView *view) const; + void AddSpecialAttribute(cJSON *node, UIView *view) const; + bool AddChildNodeToStack(UIViewGroup *group, DomNode *parent, Graphic::Vector &stackView) const; + bool RecordAndAddToParent(DomNode &curNode, Graphic::Vector &buf) const; + void FreeDomNodeVector(Graphic::Vector &vec) const; + void PrintAndReleaseCjson(cJSON *obj) const; + const char *UIViewType2Name(UIViewType type) const; +}; +} +#endif // GRAPHIC_LITE_DFX_DOM_DUMP_H diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/dfx/dfx_frame_trace.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/dfx/dfx_frame_trace.h new file mode 100644 index 000000000..a7cf2ea79 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/dfx/dfx_frame_trace.h @@ -0,0 +1,146 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef GRAPHIC_LITE_DFX_FRAME_TRACE_H +#define GRAPHIC_LITE_DFX_FRAME_TRACE_H +#include +#include "tcxo.h" +#include "graphic_config.h" +#include "gfx_utils/vector.h" +#include "components/ui_view.h" +#include "components/root_view.h" +#include "common/graphic_utils.h" +#include "graphic_service_wrapper.h" + +#if ENABLE_DFX_CMD +#define FRAME_TRACE_ENABLE 1 +#else +#define FRAME_TRACE_ENABLE 0 +#endif +#if FRAME_TRACE_ENABLE +#define FRAME_TRACE_START(type) DfxFrameTrace::GetInstance().FrameTraceStart(type) +#define FRAME_TRACE_END(type, prect) DfxFrameTrace::GetInstance().FrameTraceEnd((type), (prect)) +#define FRAME_TRACE_ENABLE_COUNT(cnt) DfxFrameTrace::GetInstance().EnableFrameTrace(cnt) +#define FRAME_TRACE_BEGIN_TRACE() DfxFrameTrace::GetInstance().BeginTrace() +#define FRAME_TRACE_SET_RECT(rect) DfxFrameTrace::GetInstance().SetDrawRect(rect) +#define FRAME_TRACE_END_TRACE() DfxFrameTrace::GetInstance().EndTrace() +#define FRAME_TRACE_SHOW() DfxFrameTrace::GetInstance().ShowFrameTrace() +#else +#define FRAME_TRACE_START(type) +#define FRAME_TRACE_END(type, prect) +#define FRAME_TRACE_ENABLE_COUNT(cnt) +#define FRAME_TRACE_BEGIN_TRACE() +#define FRAME_TRACE_SET_RECT(rect) +#define FRAME_TRACE_END_TRACE() +#define FRAME_TRACE_SHOW() +#endif + +namespace OHOS { +enum class FrameTraceType { + SW_DRAW_TRANSFORM = 0, + SW_DRAW_IMGBLIT, + HW_DRAW_IMGBLIT, + HW_DRAW_PATH, + HW_CLIP_IMGBYPATH, + SW_DRAW_CUBICBEZIER, + SW_DRAW_RECT, + HW_DRAW_RECT, + HW_DRAW_BLUR, + SW_DRAW_LETTER, + SW_DRAW_ARC, + SW_DRAW_LINE, + HW_DRAW_SUBMIT, + HW_DRAW_FLUSH, + HW_DRAW_WAIT, + DRAW_MAX +}; + +class DfxFrameTrace : public HeapBase { +public: + virtual ~DfxFrameTrace() {} + static DfxFrameTrace& GetInstance(); + DfxFrameTrace(const DfxFrameTrace&) = delete; + DfxFrameTrace& operator=(DfxFrameTrace&) = delete; + void EnableFrameTrace(int enable) + { + enableTrace_ = enable; + } + + void BeginTrace() + { + beginTrace_ = enableTrace_ > 0 ? true : false; + if (beginTrace_) { + isNativeRunning_ = IsNativeRunning(); + freq_ = GetFrequence(); + --enableTrace_; + } + } + + void SetDrawRect(const Rect &rect) + { + drawRect_ = beginTrace_ ? rect : drawRect_; + } + + void EndTrace() + { + if (beginTrace_) { + ClearState(); + } + } + + void FrameTraceStart(FrameTraceType type); + void FrameTraceEnd(FrameTraceType type, const Rect *rect = nullptr); + void ShowFrameTrace() const; + +private: + DfxFrameTrace() + { + ClearState(); + } + + bool CanTrace() const + { + return beginTrace_ && drawCount_ < DRAW_RECORD_MAX; + } + + void ClearState(); + std::string ToString(FrameTraceType type) const; + uint64_t GetDuration(uint64_t start, uint64_t end) const; + uint64_t ComputeTime() const; + void RecordStart(FrameTraceType type); + void RecordEnd(FrameTraceType type, const Rect *rect); + static constexpr int32_t DRAW_RECORD_MAX = 128; + struct { + FrameTraceType cmd; + uint64_t preTime; + uint64_t costTime; + bool isNeedWait; + } trace_[DRAW_RECORD_MAX]; + Rect rect_[DRAW_RECORD_MAX]; + int pathCnt_ = 0; + int pathIndex_ = -1; + Rect drawRect_; + uint64_t firstDrawTime_ = 0; + uint64_t startTime_ = 0; + uint64_t endTime_ = 0; + int32_t drawCount_ = 0; + int32_t drawStack_ = 0; + int enableTrace_ = 0; + bool beginTrace_ = false; + int isNativeRunning_ = 0; + int freq_ = 0; +}; +} // OHOS +#endif // GRAPHIC_LITE_DFX_FRAME_TRACE_H diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/dfx/dfx_record.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/dfx/dfx_record.h index 58a3ea7b2..9e62700e6 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/dfx/dfx_record.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/dfx/dfx_record.h @@ -28,45 +28,19 @@ struct DfxRecord { uint32_t setEventGapMax; // The max time gap for current tp event to last one. uint32_t getToSetTimeTotal; // The total time accumulated by each gap from get event time to set event time. uint32_t getToSetTimeMax; // The max for get event time to set event time. - - /* Render */ - uint8_t renderCnt; // Render count. - uint32_t renderTimeTotal; // Total time for render. - uint32_t renderTimeStart; // Render start time. - uint32_t renderTimeSWCurr; // Software render time consume for courrent render cycle. - uint32_t renderTimeSWTotal; // Total software render time consume. - uint32_t renderTimeSWMax; // Max software render time consume. - uint32_t renderTimeHWCurr; // Hardware render time consume for courrent render cycle. - uint32_t renderTimeHWTotal; // Total hardware render time consume. - uint32_t renderTimeHWMax; // Max hardware render time consume. - uint32_t renderTimeFlushCurr; // Hardware render time consume for courrent render cycle. - uint32_t renderTimeFlushTotal; // Total hardware render time consume. - uint32_t renderTimeFlushMax; // Max hardware render time consume. }; enum class ShowType { DFX_SHOW_TP = 0, DFX_SHOW_POINT, - DFX_SHOW_RENDER, - DFX_SHOW_ULPS, DFX_SHOW_DISABLE }; -enum class TimeRecordType { - DFX_TIME_RECORD_SW_CURR = 0, - DFX_TIME_RECORD_HW_CURR, - DFX_TIME_RECORD_FLUSH_CURR, - DFX_TIME_RECORD_END -}; - void DfxShowType(ShowType type); bool IsShowTPRaw(); bool IsShowPoint(); -void DfxRecordTime(TimeRecordType type); void DfxTPSetEvent(uint32_t time); void DfxTPGetEvent(); void DfxRecordShow(); -void DfxRenderReset(); -void DfxUlpsFlushRecord(uint8_t flag); } #endif // GRAPHIC_LITE_DFX_TYPE_H diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/gfx_utils/mem_check.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/gfx_utils/mem_check.h index ae77edaa7..e1a266d62 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/gfx_utils/mem_check.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/gfx_utils/mem_check.h @@ -171,58 +171,6 @@ private: int32_t leakSize_ = 0; }; } // namespace OHOS - -/** - * @brief Overrides the new function. - * @param size Indicates the size of the memory to be allocated. - * - * @since 1.0 - * @version 1.0 - */ -inline void* operator new(std::size_t size) -{ - return OHOS::UIMalloc(size); -} - -/** - * @brief Overrides the new[] function. - * @param size Indicates the size of the memory to be allocated. - * - * @since 1.0 - * @version 1.0 - */ -inline void* operator new[](std::size_t size) -{ - return OHOS::UIMalloc(size); -} - -/** - * @brief Overrides the delete function. - * @param ptr Indicates the pointer to the memory to be released. - * - * @since 1.0 - * @version 1.0 - */ -inline void operator delete(void *ptr) -{ - if (ptr != nullptr) { - OHOS::UIFree(ptr); - } -} - -/** - * @brief Overrides the delete[] function. - * @param ptr Indicates the pointer to the memory to be released. - * - * @since 1.0 - * @version 1.0 - */ -inline void operator delete[](void *ptr) -{ - if (ptr != nullptr) { - OHOS::UIFree(ptr); - } -} #endif #endif /** diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service.h index fa8d6a03c..4d7d16521 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service.h @@ -26,7 +26,11 @@ #ifndef OHOS_GRAPHIC_SERVICE_H #define OHOS_GRAPHIC_SERVICE_H #include "graphic_event_handler.h" +#if !defined(_WIN32) #include "soc_osal.h" +#else +#include +#endif /** * @ignore @@ -73,6 +77,12 @@ public: */ void SetNativeUIRunning(bool isRunning); + int IsNativeRunning() const; + + int IsScreenOn() const; + + int GetGraphicTaskTriggeredCount() const; + /** * @brief Post a task to an asynchronous thread, which would handle posted tasks sequently. * @param event, indicates the task to post. @@ -122,9 +132,15 @@ public: private: friend class GraphicEventHandler; static VsyncCallback jsVsyncCallback_; +#if !defined(_WIN32) static osal_atomic isNativeRunning_; static osal_atomic graphicTaskTriggeredCount_; static osal_atomic isScreenOn_; +#else + static std::atomic isNativeRunning_; + static std::atomic graphicTaskTriggeredCount_; + static std::atomic isScreenOn_; +#endif static OHOS::GraphicMutex rtcEventMutex_; static OHOS::GraphicCond rtcEventCond_; static bool fullRefreshFlag_; diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service_wrapper.h b/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service_wrapper.h index 95b859e49..821da854f 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service_wrapper.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/include/service/graphic_service_wrapper.h @@ -29,11 +29,21 @@ extern "C" { #endif +/** + * @brief Get current frequence. + */ +int GetFrequence(void); + /** * @brief Set frequence for graphic, cannot use PostGraphicEvent() to excute this method. */ void SetFrequence(int freq); +/** + * @brief Get native running state. + */ +int IsNativeRunning(void); + /** * @brief Set frequence for graphic inner. */ @@ -64,16 +74,6 @@ void ShowGraphicLogo(void); */ void HideGraphicLogo(void); -/** - * @brief GPU Reset start. - */ -void GpuResetStart(void); - -/** - * @brief GPU Reset end. - */ -void GpuResetEnd(void); - #ifdef __cplusplus }; #endif diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_event_handler.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_event_handler.cpp index 5bb58392a..1a1559fb4 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_event_handler.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_event_handler.cpp @@ -16,6 +16,7 @@ #include "graphic_event_handler.h" #include "dfx/dfx_record.h" #include "common/low_power_manager.h" +#include "gfx_utils/graphic_log.h" namespace OHOS { GraphicEventHandler::GraphicEventHandler() {} @@ -52,6 +53,7 @@ void GraphicEventHandler::PostGraphicEvent(const GraphicEvent& event, bool exitL void GraphicEventHandler::ClearGraphicEvent() { queueMutex_.Lock(); + GRAPHIC_LOGP("ClearGraphicEvent! EventQueue's size: %d", eventQueue_.size()); while (!eventQueue_.empty()) { eventQueue_.pop(); } diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service.cpp index 7fc0370d5..626d232bb 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service.cpp @@ -21,7 +21,9 @@ #include "gfx_utils/graphic_log.h" #include "graphic_config.h" #include "hals/display_dev.h" +#if !defined(_WIN32) #include "soc_lcd_api.h" +#endif #include "graphic_thread.h" #include "dock/input_device.h" #include "dock/lite_touch_device.h" @@ -32,9 +34,15 @@ #include "components/root_view.h" VsyncCallback GraphicService::jsVsyncCallback_; +#if !defined(_WIN32) osal_atomic GraphicService::isNativeRunning_{1}; osal_atomic GraphicService::graphicTaskTriggeredCount_{0}; osal_atomic GraphicService::isScreenOn_{0}; +#else +std::atomic GraphicService::isNativeRunning_(1); +std::atomic GraphicService::graphicTaskTriggeredCount_(0); +std::atomic GraphicService::isScreenOn_(0); +#endif OHOS::GraphicMutex GraphicService::rtcEventMutex_; OHOS::GraphicCond GraphicService::rtcEventCond_; static ThreadId g_rtcEventThreadId; @@ -52,11 +60,19 @@ void GraphicService::RegJSVsyncCallback(VsyncCallback callback) bool GraphicService::SyncTriggerJSGraphicTask() { +#if !defined(_WIN32) if ((osal_atomic_read(&isNativeRunning_) == 1) || osal_atomic_read(&graphicTaskTriggeredCount_) > 0 || osal_atomic_read(&isScreenOn_) == 0) { GRAPHIC_LOGI("Trigger JS Task failed. Native is running or Graphic Task is already triggered."); return false; } +#else + if ((isNativeRunning_.load() == 1) || graphicTaskTriggeredCount_.load() > 0 || + isScreenOn_.load() == 0) { + GRAPHIC_LOGI("Trigger JS Task failed. Native is running or Graphic Task is already triggered."); + return false; + } +#endif OHOS::TaskManager::GetInstance()->TaskHandler(); return true; @@ -64,8 +80,13 @@ bool GraphicService::SyncTriggerJSGraphicTask() bool GraphicService::AsyncTriggerNativeGraphicTask() { +#if !defined(_WIN32) if (osal_atomic_read(&graphicTaskTriggeredCount_) <= 1) { osal_atomic_inc(&graphicTaskTriggeredCount_); +#else + if (graphicTaskTriggeredCount_.load() <= 1) { + graphicTaskTriggeredCount_.fetch_add(1); +#endif OHOS::GraphicEventHandler::GetInstance()->PostGraphicEvent( [] { OHOS::TaskManager::GetInstance()->TaskHandler(); @@ -80,17 +101,56 @@ bool GraphicService::AsyncTriggerNativeGraphicTask() void GraphicService::SetNativeUIRunning(bool isRunning) { if (isRunning) { +#if !defined(_WIN32) osal_atomic_set(&isNativeRunning_, 1); } else { osal_atomic_set(&isNativeRunning_, 0); OHOS::GraphicEventHandler::GetInstance()->ClearGraphicEvent(); osal_atomic_set(&graphicTaskTriggeredCount_, 0); +#else + isNativeRunning_.store(1); + } else { + isNativeRunning_.store(0); + OHOS::GraphicEventHandler::GetInstance()->ClearGraphicEvent(); + graphicTaskTriggeredCount_.store(0); +#endif } } +int GraphicService::IsNativeRunning() const +{ +#if !defined(_WIN32) + return osal_atomic_read(&isNativeRunning_); +#else + return isNativeRunning_.load(); +#endif +} + +int GraphicService::GetGraphicTaskTriggeredCount() const +{ +#if !defined(_WIN32) + return osal_atomic_read(&graphicTaskTriggeredCount_); +#else + return graphicTaskTriggeredCount_.load(); +#endif +} + +int GraphicService::IsScreenOn() const +{ +#if !defined(_WIN32) + return osal_atomic_read(&isScreenOn_); +#else + return isScreenOn_.load(); +#endif +} + void GraphicService::DecreaseTriggerCount() { +#if !defined(_WIN32) osal_atomic_dec(&graphicTaskTriggeredCount_); +#else + graphicTaskTriggeredCount_.fetch_sub(1); +#endif } void GraphicService::PostGraphicEvent(const OHOS::GraphicEvent& event) @@ -100,17 +160,29 @@ void GraphicService::PostGraphicEvent(const OHOS::GraphicEvent& event) void GraphicService::NotifyScreenOn() { + fullRefreshFlag_ = true; +#if !defined(_WIN32) if (osal_atomic_read(&isScreenOn_) == 0) { osal_atomic_set(&isScreenOn_, 1); - fullRefreshFlag_ = true; } +#else + if (isScreenOn_.load() == 0) { + isScreenOn_.store(1); + } +#endif } void GraphicService::NotifyScreenOff() { +#if !defined(_WIN32) osal_atomic_set(&isScreenOn_, 0); OHOS::GraphicEventHandler::GetInstance()->ClearGraphicEvent(); osal_atomic_set(&graphicTaskTriggeredCount_, 0); +#else + isScreenOn_.store(0); + OHOS::GraphicEventHandler::GetInstance()->ClearGraphicEvent(); + graphicTaskTriggeredCount_.store(0); +#endif } void GraphicService::EnableAsyncMode(bool enable) @@ -146,7 +218,11 @@ void* GraphicService::RtcEventThread(void* args) rtcEventMutex_.Lock(); rtcEventCond_.Wait(rtcEventMutex_); rtcEventMutex_.Unlock(); +#if !defined(_WIN32) if (osal_atomic_read(&isScreenOn_) == 0) { +#else + if (isScreenOn_.load() == 0) { +#endif continue; } if (fullRefreshFlag_) { @@ -156,11 +232,17 @@ void* GraphicService::RtcEventThread(void* args) fullRefreshFlag_ = false; } +#if !defined(_WIN32) if (osal_atomic_read(&isNativeRunning_) == 1) { AsyncTriggerNativeGraphicTask(); } else { jsVsyncCallback_(); } +#else + if (isNativeRunning_.load() == 1) { + AsyncTriggerNativeGraphicTask(); + } +#endif } #if !defined(ENABLE_CMSIS) return nullptr; @@ -176,12 +258,16 @@ void GraphicService::SetUpRootView(void) bool GraphicService::InitGraphicService() { +#if !defined(_WIN32) if (!uapi_is_lcd_connect()) { return false; } +#endif OHOS::GraphicStartUp::Init(); +#if !defined(_WIN32) OHOS::LiteInputHal::GetInstance()->SetUp(); +#endif #ifndef QSPI_DISPLAY OHOS::BaseGfxEngine::GetInstance()->SetScreenShape(OHOS::CIRCLE); #endif @@ -192,7 +278,7 @@ bool GraphicService::InitGraphicService() #ifdef ENABLE_CMSIS rtcAttr.priority = static_cast(osPriorityAboveNormal2); #endif - g_rtcEventThreadId = ThreadCreate(GraphicService::RtcEventThread, nullptr, &rtcAttr); + g_rtcEventThreadId = (ThreadId)ThreadCreate((Runnable)GraphicService::RtcEventThread, nullptr, &rtcAttr); if (g_rtcEventThreadId == nullptr) { GRAPHIC_LOGE("%s: create thread fail\n", __func__); return false; @@ -204,7 +290,7 @@ bool GraphicService::InitGraphicService() #ifdef ENABLE_CMSIS mainAttr.priority = static_cast(osPriorityAboveNormal2); #endif - g_mainThreadId = ThreadCreate(GraphicService::NativeMainThread, nullptr, &mainAttr); + g_mainThreadId = (ThreadId)ThreadCreate((Runnable)GraphicService::NativeMainThread, nullptr, &mainAttr); if (g_mainThreadId == nullptr) { GRAPHIC_LOGE("create thread fail\n"); return false; diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp index f10692f3e..2e1768266 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/service/src/graphic_service_wrapper.cpp @@ -14,7 +14,9 @@ */ #include "graphic_service_wrapper.h" +#if !defined(_WIN32) #include "rtc.h" +#endif #include "graphic_event_handler.h" #include "graphic_service.h" #include "gfx_utils/graphic_log.h" @@ -29,7 +31,9 @@ extern "C" { #endif static const uint32_t SECOND_TO_MILLISECOND = 1000; static const int32_t FULL_FREQUENCE = 60; +#if !defined(_WIN32) static rtc_handle_t g_rtcHandle = nullptr; +#endif static int32_t g_timeInterval = 16; static int32_t g_freq = FULL_FREQUENCE; static bool g_initialized = false; @@ -50,7 +54,9 @@ static void UikitRTCCallBack(uintptr_t data) if (!g_initialized || !g_isScreenOn) { return; } +#if !defined(_WIN32) uapi_rtc_start(g_rtcHandle, g_timeInterval, UikitRTCCallBack, 0); +#endif GraphicService::GetInstance()->UpdateGraphicEvent(); } @@ -75,10 +81,22 @@ void SetFrequenceInner(int freq) } else { GraphicService::GetInstance()->EnableAsyncMode(false); } +#if !defined(_WIN32) uapi_rtc_start(g_rtcHandle, g_timeInterval, UikitRTCCallBack, 0); +#endif } } +int GetFrequence(void) +{ + return g_freq; +} + +int IsNativeRunning(void) +{ + return GraphicService::GetInstance()->IsNativeRunning(); +} + void SetFrequence(int freq) { GraphicService::GetInstance()->PostGraphicEvent([=] { @@ -88,26 +106,36 @@ void SetFrequence(int freq) void NotifyScreenOn(void) { +#if !defined(_WIN32) if (g_rtcHandle == nullptr) { return; } +#endif if (!g_isScreenOn) { g_isScreenOn = true; OHOS::LowPowerManager::GetInstance()->ExitLowPower(); +#if !defined(_WIN32) + GRAPHIC_LOGP("ScreenOn and start RTC! time interval: %d", g_timeInterval); uapi_rtc_start(g_rtcHandle, g_timeInterval, static_cast(UikitRTCCallBack), 0); +#endif } GraphicService::GetInstance()->NotifyScreenOn(); } void NotifyScreenOff(void) { +#if !defined(_WIN32) if (g_rtcHandle == nullptr) { return; } +#endif if (g_isScreenOn) { g_isScreenOn = false; +#if !defined(_WIN32) + GRAPHIC_LOGP("ScreenOff and stop RTC!"); uapi_rtc_stop(g_rtcHandle); +#endif } g_freq = 1; g_timeInterval = SECOND_TO_MILLISECOND; @@ -125,17 +153,21 @@ void InitGraphicService(void) return; } +#if !defined(_WIN32) /* start RTC timer */ uapi_rtc_create(RTC_0, &g_rtcHandle); if (g_rtcHandle == nullptr) { GRAPHIC_LOGE("create RTC timer fail!!"); return; } +#endif if (!GraphicService::GetInstance()->InitGraphicService()) { GRAPHIC_LOGE("InitGraphicService fail!!"); +#if !defined(_WIN32) uapi_rtc_stop(g_rtcHandle); uapi_rtc_delete(g_rtcHandle); +#endif return; } g_initialized = true; diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/common/low_power_manager.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/common/low_power_manager.cpp index 15eb859d3..94f987afa 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/common/low_power_manager.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/common/low_power_manager.cpp @@ -10,24 +10,33 @@ #include "engines/gfx/lite_m_gfx_engine.h" #include "components/root_view.h" #include "hal_tick.h" +#include "gfx_utils/list.h" namespace OHOS { -static const uint32_t RE_ENTRY_CLAMP = 1000; +static const uint32_t TRY_ENTER_LOW_POWER_INTERVAL = 100; // to avoid switch refresh rate frequently during roate void LowPowerManager::TryToEnterLowPower() { - if (HALTick::GetInstance().GetElapseTime(lastExitTime_) < RE_ENTRY_CLAMP) { + // this condition can be removed later, switching refresh rate frequently doesn't seen to have any effect + if (HALTick::GetInstance().GetElapseTime(lastExitTime_) < TRY_ENTER_LOW_POWER_INTERVAL) { return; } - if (CheckGuiState()) { - EnterLowPower(); + if (AnimatorManager::GetInstance()->IsActive() || InputDeviceManager::GetInstance()->IsEventExist()) { + return; } -} -void LowPowerManager::EnterLowPower() -{ - SetFrequenceInner(1); + if (LiteMGfxEngine::GetInstance()->HasPendingFrame()) { + return; + } + + if (IsLiteSurfaceInRootView()) { + return; + } + + uint32_t period = TaskManager::GetInstance()->GetMinimumCustomerTaskPeriod(); + int freq = (period == 0) ? 1 : 1000 / static_cast(period); + SetFrequenceInner(freq); } void LowPowerManager::ExitLowPower() @@ -50,26 +59,4 @@ bool LowPowerManager::IsLiteSurfaceInRootView() return (view == RootView::GetInstance()); } - -bool LowPowerManager::CheckTaskState() -{ - uint32_t period = TaskManager::GetInstance()->GetMinimumCustomerTaskPeriod(); - if (period == 0) { - return false; - } else { - int freq = 1000 / static_cast(period); // 1000: 1000ms per second - SetFrequenceInner(freq); - return true; - } -} - -bool LowPowerManager::CheckGuiState() -{ - if ((powerLock_ != 0) || AnimatorManager::GetInstance()->IsActive() || IsLiteSurfaceInRootView() || - InputDeviceManager::GetInstance()->IsEventExist() || CheckTaskState()) { - return false; - } - - return true; -} } // namespace OHOS diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_lite_surface_view.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_lite_surface_view.cpp index e3537227c..4cfd78f7b 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_lite_surface_view.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components/ui_lite_surface_view.cpp @@ -19,6 +19,7 @@ #include "graphic_service.h" #include "draw/draw_rect.h" #include "draw/draw_utils.h" +#include "dfx/dfx_frame_trace.h" #include "gfx_utils/graphic_log.h" #include "hals/display_dev.h" #include "securec.h" @@ -41,7 +42,6 @@ UILiteSurfaceView::UILiteSurfaceView() : isLayerInit_(false), flushCount_(0) return; } surface_->RegisterConsumerListener(*this); - LowPowerManager::GetInstance()->PowerLock(); } UILiteSurfaceView::~UILiteSurfaceView() @@ -62,7 +62,6 @@ UILiteSurfaceView::~UILiteSurfaceView() LiteMGfxEngine::GetInstance()->ClearHardwareLayer(); GraphicService::GetInstance()->PostGraphicEvent([] { GraphicService::GetInstance()->EnableAsyncMode(true); - LowPowerManager::GetInstance()->PowerUnLock(); }); if (preView_ != nullptr) { @@ -136,8 +135,10 @@ void UILiteSurfaceView::Flush() layer.data.phyAddr = currentBuffer_->addr; layer.data.virAddr = reinterpret_cast(currentBuffer_->addr); + FRAME_TRACE_START(FrameTraceType::HW_DRAW_FLUSH); DisplayDev::GetInstance()->SetHardwareLayerBuffer(LAYER_1, BUFFER_0, layer); DisplayDev::GetInstance()->LcdFlush(LAYER_1); + FRAME_TRACE_END(FrameTraceType::HW_DRAW_FLUSH, nullptr); } if (flushCount_ > 0) { @@ -341,6 +342,7 @@ void UILiteSurfaceView::OnBufferAvailable() }); } else if (isStopped_) { isStopped_ = false; + LowPowerManager::GetInstance()->ExitLowPower(); GraphicService::GetInstance()->PostGraphicEvent( [&, ws] { if (!ws.expired()) { diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/hor_swipe_view.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/hor_swipe_view.h index 5a5fb8e8b..a672154fc 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/hor_swipe_view.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/components_ext/hor_swipe_view.h @@ -9,6 +9,7 @@ #define UI_HOR_SWIPE_VIEW_H #include "components/ui_swipe_view.h" #include "components/card_swipe.h" +#include "animator/animator.h" namespace OHOS { class HorSwipeView : public UISwipeView { @@ -64,6 +65,16 @@ public: */ void SwipeStart(void); + /* * + * @brief Get state of scroll animator. + * @since 1.0 + * @version 1.0 + */ + uint8_t GetScrollState() + { + return scrollAnimator_.GetState(); + } + private: bool enableScreenCap_ = false; CardSwipe* swipeCallback_ = nullptr; diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_cmd.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_cmd.cpp index babd2f769..cc221dcf5 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_cmd.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_cmd.cpp @@ -15,6 +15,8 @@ #include #include "graphic_config.h" +#include "dfx/dfx_dom_dump.h" +#include "graphic_service.h" #include "dfx/dfx_cmd.h" #if ENABLE_DFX_CMD #include @@ -27,6 +29,7 @@ #include "gfx_utils/image_info.h" #include "securec.h" #include "dfx/dfx_record.h" +#include "dfx/dfx_frame_trace.h" #include "common/low_power_manager.h" #include "common/image_cache_manager.h" @@ -71,12 +74,27 @@ void DumpViewIdCmd(int argc, char *argv[]) printf("=== Dump Widget ViewId End===\n"); } +void DumpRootView(int argc, char *argv[]) +{ + printf("=== Begin Dump RootView ===\n"); + DfxDomDump::GetInstance().DumpRootView(); + printf("=== Dump RootView End===\n"); +} + #if ENABLE_MEMORY_CHECK void DumpMemoryCmd(int argc, char *argv[]) { MemCheck::GetInstance()->DumpMemInfo(); } +void DumpState(int argc, char *argv[]) +{ + printf("=== Dump State ===\n"); + printf(" NativeRunninng: %d\n", GraphicService::GetInstance()->IsNativeRunning()); + printf(" IsScreenOn: %d\n", GraphicService::GetInstance()->IsScreenOn()); + printf(" GraphicTaskTriggeredCount_: %d\n", GraphicService::GetInstance()->GetGraphicTaskTriggeredCount()); +} + void LeakPanic(int argc, char *argv[]) { if (argc != 2) { // 2: param num @@ -337,13 +355,24 @@ void ShowTime(int argc, char *argv[]) DfxShowType(ShowType::DFX_SHOW_TP); } else if (strcmp(argv[0], "point") == 0) { DfxShowType(ShowType::DFX_SHOW_POINT); - } else if (strcmp(argv[0], "render") == 0) { - DfxShowType(ShowType::DFX_SHOW_RENDER); } else if (strcmp(argv[0], "close") == 0) { DfxShowType(ShowType::DFX_SHOW_DISABLE); - } else if (strcmp(argv[0], "ulps") == 0) { - DfxShowType(ShowType::DFX_SHOW_ULPS); } + } else if (argc == 3) { // 3: argc + if (strcmp(argv[0], "render") != 0) { + printf("param err."); + return; + } + uint16_t cnt; + uint16_t invalid; + if (!ConvertToInt(argv[1], cnt) || !ConvertToInt(argv[2], invalid)) { + printf("param err."); + return; + } + if (invalid != 0) { + GraphicService::GetInstance()->PostGraphicEvent([]() { RootView::GetInstance()->Invalidate(); }); + } + DfxFrameTrace::GetInstance().EnableFrameTrace(static_cast(cnt)); } else { printf("param err."); } @@ -513,11 +542,13 @@ struct DfxCmd { struct DfxCmd g_dfxCmdList[] = { {"screencap", OHOS::ScreencapCmd}, {"dump_view_id", OHOS::DumpViewIdCmd}, + {"dump_root_view", OHOS::DumpRootView}, {"printfps", OHOS::PrintFPS}, {"hidefps", OHOS::HideFPS}, {"showfps", OHOS::ShowFPS}, {"showtime", OHOS::ShowTime}, #if ENABLE_MEMORY_CHECK + {"dumpstate", OHOS::DumpState}, {"dumpmem", OHOS::DumpMemoryCmd}, {"mem_monitor", OHOS::SetMemMonitorCmd}, {"dumpimg", OHOS::DumpImgCmd}, diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_dom_dump.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_dom_dump.cpp new file mode 100644 index 000000000..038b17e48 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_dom_dump.cpp @@ -0,0 +1,286 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dfx/dfx_dom_dump.h" +#include "graphic_service.h" +#include "draw/draw_image.h" +#include "common/graphic_utils.h" + +namespace OHOS { +static const struct { + UIViewType type; + const char *name; +} g_type2Name[] = { + {UI_ROOT_VIEW, "UI_ROOT_VIEW"}, + {UI_VIEW_GROUP, "UI_VIEW_GROUP"}, + {UI_LABEL, "UI_LABEL"}, + {UI_ARC_LABEL, "UI_ARC_LABEL"}, + {UI_LABEL_BUTTON, "UI_LABEL_BUTTON"}, + {UI_CHECK_BOX, "UI_CHECK_BOX"}, + {UI_TOGGLE_BUTTON, "UI_TOGGLE_BUTTON"}, + {UI_RADIO_BUTTON, "UI_RADIO_BUTTON"}, + {UI_IMAGE_VIEW, "UI_IMAGE_VIEW"}, + {UI_BOX_PROGRESS, "UI_BOX_PROGRESS"}, + {UI_SLIDER, "UI_SLIDER"}, + {UI_CIRCLE_PROGRESS, "UI_CIRCLE_PROGRESS"}, + {UI_SCROLL_VIEW, "UI_SCROLL_VIEW"}, + {UI_LIST, "UI_LIST"}, + {UI_DIGITAL_CLOCK, "UI_DIGITAL_CLOCK"}, + {UI_ANALOG_CLOCK, "UI_ANALOG_CLOCK"}, +#if ENABLE_SWEEP_CLOCK + {UI_SWEEP_CLOCK, "UI_SWEEP_CLOCK"}, +#endif + {UI_PICKER, "UI_PICKER"}, + {UI_SWIPE_VIEW, "UI_SWIPE_VIEW"}, + {UI_TIME_PICKER, "UI_TIME_PICKER"}, + {UI_ABSTRACT_CLOCK, "UI_ABSTRACT_CLOCK"}, + {UI_ABSTRACT_PROGRESS, "UI_ABSTRACT_PROGRESS"}, + {UI_ABSTRACT_SCROLL, "UI_ABSTRACT_SCROLL"}, + {UI_AXIS, "UI_AXIS"}, + {UI_BUTTON, "UI_BUTTON"}, + {UI_CANVAS, "UI_CANVAS"}, + {UI_CHART, "UI_CHART"}, + {UI_IMAGE_ANIMATOR_VIEW, "UI_IMAGE_ANIMATOR_VIEW"}, + {UI_REPEAT_BUTTON, "UI_REPEAT_BUTTON"}, + {UI_TEXTURE_MAPPER, "UI_TEXTURE_MAPPER"}, + {UI_DIALOG, "UI_DIALOG"}, + {UI_QRCODE, "UI_QRCODE"}, + {UI_LABEL_EXT, "UI_LABEL_EXT"}, + {UI_LABEL_BUTTON_EXT, "UI_LABEL_BUTTON_EXT"}, + {UI_CANVAS_EXT, "UI_CANVAS_EXT"}, + {UI_CHART_PILLAR, "UI_CHART_PILLAR"}, + {UI_CHART_POLYLINE, "UI_CHART_POLYLINE"}, + {UI_X_AXIS, "UI_X_AXIS"}, + {UI_Y_AXIS, "UI_Y_AXIS"}, + {UI_LITE_SURFACE_VIEW, "UI_LITE_SURFACE_VIEW"}, + {LAYOUT, "LAYOUT"}, + {LIST_LAYOUT, "LIST_LAYOUT"}, + {FLEX_LAYOUT, "FLEX_LAYOUT"}, + {GRID_LAYOUT, "GRID_LAYOUT"}, +#if ENABLE_SOFT_KEYBOARD + {UI_EDIT_TEXT, "UI_EDIT_TEXT"}, + {UI_TEXT_PREVIEW_BOX, "UI_TEXT_PREVIEW_BOX"}, + {UI_KEYBOARD_BUTTON, "UI_KEYBOARD_BUTTON"}, +#endif + {UI_MENU_ITEM, "UI_MENU_ITEM"}, + {UI_CARD_PAGE, "UI_CARD_PAGE"}, + {UI_COVER_FLOW, "UI_COVER_FLOW"}, + {UI_CROSS_VIEW, "UI_CROSS_VIEW"}, + {UI_BARCODE, "UI_BARCODE"}, + {UI_MAP_VIEW, "UI_MAP_VIEW"}, + {UI_KALEIDOSCOPE_VIEW, "UI_KALEIDOSCOPE_VIEW"}, + {UI_ROLLER_VIEW, "UI_ROLLER_VIEW"}, + {UI_HEXAGONS_LIST, "UI_HEXAGONS_LIST"}, + {UI_IMAGE_PICKER, "UI_IMAGE_PICKER"}, + {UI_ICOSAHEDRON_VIEW, "UI_ICOSAHEDRON_VIEW"}, + {UI_TRANSFORM_GROUP, "UI_TRANSFORM_GROUP"}, + {UI_TRANSFORM_LIST, "UI_TRANSFORM_LIST"}, + {UI_NUMBER_MAX, "UI_NUMBER_MAX"}, +}; + +DfxDomDump::DfxDomDump() +{ +} + +DfxDomDump::~DfxDomDump() +{ +} + +DfxDomDump& DfxDomDump::GetInstance() +{ + static DfxDomDump dfxDomDump; + return dfxDomDump; +} + +void DfxDomDump::DumpRootView() +{ + DumpView(RootView::GetInstance()); +} + +void DfxDomDump::DumpView(UIView *view) +{ + if (view == nullptr) { + return; + } + + Graphic::Vector stackView; // traverse stack + Graphic::Vector buf; // nodes to free + DomNode domNode(nullptr, view, nullptr); + stackView.PushBack(&domNode); + while (!stackView.IsEmpty()) { + DomNode &curNode = *(stackView.Back()); + stackView.PopBack(); + curNode.obj = cJSON_CreateObject(); + if (curNode.obj == nullptr) { + break; + } + + if (!RecordAndAddToParent(curNode, buf)) { + break; + } + + if (!AddAttribute(curNode.obj, curNode.view)) { + break; + } + + UIViewGroup *group = dynamic_cast(curNode.view); + if (group == nullptr) { + continue; + } + + if (!AddChildNodeToStack(group, &curNode, stackView)) { + break; + } + } + PrintAndReleaseCjson(domNode.obj); + + FreeDomNodeVector(buf); + FreeDomNodeVector(stackView); +} + +bool DfxDomDump::AddAttribute(cJSON *node, UIView *view) const +{ + if (node == nullptr || view == nullptr) { + return false; + } + bool ret = AddCommonAttribute(node, view); + AddSpecialAttribute(node, view); + return ret; +} + +bool DfxDomDump::AddCommonAttribute(cJSON *node, UIView *view) const +{ + if (node == nullptr || view == nullptr) { + return false; + } + + Rect rect = view->GetRect(); + const size_t size = 256; + char *buf = new char[size]; + defer { + if (buf != nullptr) { + delete []buf; + } + }; + cJSON_AddStringToObject(node, "typename", UIViewType2Name(view->GetViewType())); + if (buf == nullptr) { + return false; + } + memset_s(buf, size, 0, size); + sprintf_s(buf, size, "[ptr %p, x %d y %d w %d h %d, opa %u, visible %d, touchable %d, draggable %d, view-id %s]", + view, rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight(), view->GetOpaScale(), view->IsVisible(), + view->IsTouchable(), view->IsDraggable(), view->GetViewId()); + cJSON_AddStringToObject(node, "common-info", buf); + return true; +} + +void DfxDomDump::AddSpecialAttribute(cJSON *node, UIView *view) const +{ + if (node == nullptr || view == nullptr) { + return; + } + cJSON_AddStringToObject(node, "special info", view->GetGuiInfo().c_str()); +} + +bool DfxDomDump::AddChildNodeToStack(UIViewGroup *group, DomNode *parent, Graphic::Vector &stackView) const +{ + if (group == nullptr || parent == nullptr) { + return false; + } + Graphic::Vector reverse; + for (UIView *child = group->GetChildrenHead(); + child != nullptr; child = child->GetNextSibling()) { + reverse.PushBack(child); + } + int size = reverse.Size(); + if (size == 0) { + return true; + } + if (cJSON_AddNumberToObject(parent->obj, "child-num", size) == nullptr) { + return false; + } + if (cJSON_AddArrayToObject(parent->obj, "children") == nullptr) { + return false; + } + for (int i = size - 1; i >= 0; --i) { + DomNode *childNode = new DomNode(parent, reverse[i]); + if (childNode == nullptr) { + return false; + } + stackView.PushBack(childNode); + } + return true; +} + +bool DfxDomDump::RecordAndAddToParent(DomNode &curNode, Graphic::Vector &buf) const +{ + if (curNode.parent != nullptr) { + buf.PushBack(&curNode); + cJSON *parentArray = cJSON_GetObjectItemCaseSensitive(curNode.parent->obj, "children"); + if (parentArray == nullptr) { + return false; + } + if (!cJSON_AddItemToArray(parentArray, curNode.obj)) { + return false; + } + } + return true; +} + +void DfxDomDump::FreeDomNodeVector(Graphic::Vector &vec) const +{ + for (uint16_t i = 0; i < vec.Size(); ++i) { + if (vec[i]->parent == nullptr) { + continue; + } + delete vec[i]; + } +} + +void DfxDomDump::PrintAndReleaseCjson(cJSON *obj) const +{ + if (obj == nullptr) { + return; + } + GraphicService::GetInstance()->PostGraphicEvent([obj]() { + FILE *file = fopen(RES_PATH"view_tree.json", "w"); + defer { + if (file != nullptr) { + fclose(file); + } + }; + char *info = cJSON_Print(obj); + if (info != nullptr) { + printf("%s\n", info); + if (file != nullptr) { + fwrite(info, 1, strlen(info), file); + } + cJSON_free(info); + } + cJSON_free(obj); + }); +} + +const char *DfxDomDump::UIViewType2Name(UIViewType type) const +{ + constexpr int size = sizeof(g_type2Name) / sizeof(g_type2Name[0]); + for (int i = 0; i < size; ++i) { + if (g_type2Name[i].type == type) { + return g_type2Name[i].name; + } + } + return "unkonwn"; +} +} \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_frame_trace.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_frame_trace.cpp new file mode 100644 index 000000000..3c5594d46 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_frame_trace.cpp @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "securec.h" +#include "dfx/dfx_frame_trace.h" + +namespace OHOS { +static struct { + FrameTraceType type; + std::string str; +} g_type2string[] = { + {FrameTraceType::SW_DRAW_TRANSFORM, "sw_tran"}, + {FrameTraceType::SW_DRAW_IMGBLIT, "sw_blit"}, + {FrameTraceType::HW_DRAW_IMGBLIT, "hw_blit"}, + {FrameTraceType::HW_DRAW_PATH, "hw_path"}, + {FrameTraceType::HW_CLIP_IMGBYPATH, "hw_clip"}, + {FrameTraceType::SW_DRAW_CUBICBEZIER, "sw_bezier"}, + {FrameTraceType::SW_DRAW_RECT, "sw_rect"}, + {FrameTraceType::HW_DRAW_RECT, "hw_rect"}, + {FrameTraceType::HW_DRAW_BLUR, "hw_blur"}, + {FrameTraceType::SW_DRAW_LETTER, "sw_letter"}, + {FrameTraceType::SW_DRAW_ARC, "sw_arc"}, + {FrameTraceType::SW_DRAW_LINE, "sw_line"}, + {FrameTraceType::HW_DRAW_SUBMIT, "hw_submit"}, + {FrameTraceType::HW_DRAW_FLUSH, "hw_flush"}, + {FrameTraceType::HW_DRAW_WAIT, "hw_wait"}, +}; + +uint64_t DfxFrameTrace::GetDuration(uint64_t start, uint64_t end) const +{ + uint64_t dur = end >= start ? end - start : UINT64_MAX - start + end + 1; + return dur; +} + +DfxFrameTrace& DfxFrameTrace::GetInstance() +{ + static DfxFrameTrace dfx; + return dfx; +} + +void DfxFrameTrace::FrameTraceStart(FrameTraceType type) +{ + if (!CanTrace()) { + return; + } + if (drawStack_ == 0) { + RecordStart(type); + } + ++drawStack_; +} + +void DfxFrameTrace::FrameTraceEnd(FrameTraceType type, const Rect *rect) +{ + if (!CanTrace()) { + return; + } + --drawStack_; + if (drawStack_ != 0) { + return; + } + + RecordEnd(type, rect); +} + +void DfxFrameTrace::RecordStart(FrameTraceType type) +{ + startTime_ = uapi_tcxo_get_us(); + uint64_t preTime = 0; + if (drawCount_ == 0) { + preTime = 0; + firstDrawTime_ = startTime_; + } else { + preTime = GetDuration(endTime_, startTime_); + } + + if (type == FrameTraceType::HW_DRAW_PATH) { + if (pathIndex_ == -1) { + pathIndex_ = drawCount_; + ++drawCount_; + } + trace_[pathIndex_].cmd = type; + trace_[pathIndex_].preTime += preTime; + return; + } + trace_[drawCount_].cmd = type; + trace_[drawCount_].preTime = preTime; +} + +void DfxFrameTrace::RecordEnd(FrameTraceType type, const Rect *rect) +{ + endTime_ = uapi_tcxo_get_us(); + uint64_t costTime = GetDuration(startTime_, endTime_); + + if (type == FrameTraceType::HW_DRAW_PATH) { + trace_[pathIndex_].costTime += costTime; + ++pathCnt_; + return; + } + trace_[drawCount_].costTime = costTime; + rect_[drawCount_] = rect == nullptr ? Rect() : *rect; + if (type == FrameTraceType::HW_DRAW_SUBMIT) { + trace_[drawCount_].isNeedWait = (rect != nullptr); + } + ++drawCount_; +} + +void DfxFrameTrace::ShowFrameTrace() const +{ + if (!beginTrace_) { + return; + } + + uint64_t totalTime = GetDuration(firstDrawTime_, endTime_); + printf("\nisNativeRunning %d, freq %d", isNativeRunning_, freq_); + printf("\nCmd count: %d time: %llu, {%d %d %d %d}\n", drawCount_, totalTime, + drawRect_.GetLeft(), drawRect_.GetTop(), drawRect_.GetRight(), drawRect_.GetBottom()); + for (int32_t i = 0; i < drawCount_; ++i) { + if (trace_[i].cmd == FrameTraceType::HW_DRAW_PATH) { + printf("%d. %s: %llu, %llu, %d\n", + i, ToString(trace_[i].cmd).c_str(), trace_[i].preTime, trace_[i].costTime, pathCnt_); + continue; + } + if (trace_[i].cmd == FrameTraceType::HW_DRAW_SUBMIT) { + printf("%d. %s: %llu, %llu, %d\n", + i, ToString(trace_[i].cmd).c_str(), trace_[i].preTime, trace_[i].costTime, trace_[i].isNeedWait); + continue; + } + if (!rect_[i].IsValid()) { + printf("%d. %s: %llu, %llu\n", i, ToString(trace_[i].cmd).c_str(), trace_[i].preTime, trace_[i].costTime); + continue; + } + printf("%d. %s: %llu, %llu, {%d, %d, %d, %d}\n", + i, ToString(trace_[i].cmd).c_str(), trace_[i].preTime, trace_[i].costTime, + rect_[i].GetLeft(), rect_[i].GetTop(), rect_[i].GetRight(), rect_[i].GetBottom()); + } +} + +void DfxFrameTrace::ClearState() +{ + memset_s(trace_, sizeof(trace_), 0, sizeof(trace_)); + drawRect_ = Rect(); + drawCount_ = 0; + drawStack_ = 0; + beginTrace_ = false; + startTime_ = 0; + endTime_ = 0; + firstDrawTime_ = 0; + pathCnt_ = 0; + pathIndex_ = -1; + freq_ = 0; + isNativeRunning_ = 0; +} + +std::string DfxFrameTrace::ToString(FrameTraceType type) const +{ + constexpr int size = sizeof(g_type2string) / sizeof(g_type2string[0]); + for (int i = 0; i < size; ++i) { + if (g_type2string[i].type == type) { + return g_type2string[i].str; + } + } + return ""; +} +} // OHOS diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_record.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_record.cpp index 2d84cd6b7..087e296e2 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_record.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/dfx/dfx_record.cpp @@ -27,12 +27,9 @@ namespace OHOS { static uint32_t g_lastTime; static uint32_t g_currentTime; static uint32_t g_tpSetTime; -static uint32_t g_renderStartTime; static ShowType g_dfxShow = ShowType::DFX_SHOW_DISABLE; static DfxRecord g_dfxRecord = {0}; static const uint16_t MS_TO_US = 1000; -static uint32_t g_ulpsExit = 0; -static uint32_t g_flush = 0; static uint32_t GetTimeUs() { @@ -46,64 +43,6 @@ void DfxShowType(ShowType type) g_dfxShow = type; } -void DfxUlpsFlushRecord(uint8_t flag) -{ - if (flag == 1) { - g_ulpsExit++; - } else { - g_flush++; - } -} - -static void DfxUpdateTime(uint32_t& record) -{ - uint32_t temp = GetTimeUs(); - record += (temp - g_dfxRecord.renderTimeStart); - g_dfxRecord.renderTimeStart = temp; -} - -static void DfxRenderRecordEnd(void) -{ - g_dfxRecord.renderTimeSWTotal += g_dfxRecord.renderTimeSWCurr; - if (g_dfxRecord.renderTimeSWCurr > g_dfxRecord.renderTimeSWMax) { - g_dfxRecord.renderTimeSWMax = g_dfxRecord.renderTimeSWCurr; - } - - g_dfxRecord.renderTimeHWTotal += g_dfxRecord.renderTimeHWCurr; - if (g_dfxRecord.renderTimeHWCurr > g_dfxRecord.renderTimeHWMax) { - g_dfxRecord.renderTimeHWMax = g_dfxRecord.renderTimeHWCurr; - } - - g_dfxRecord.renderTimeFlushTotal += g_dfxRecord.renderTimeFlushCurr; - if (g_dfxRecord.renderTimeFlushCurr > g_dfxRecord.renderTimeFlushMax) { - g_dfxRecord.renderTimeFlushMax = g_dfxRecord.renderTimeFlushCurr; - } - g_dfxRecord.renderTimeTotal += GetTimeUs() - g_renderStartTime; -} - -void DfxRecordTime(TimeRecordType type) -{ - if (g_dfxShow != ShowType::DFX_SHOW_RENDER) { - return; - } - switch (type) { - case TimeRecordType::DFX_TIME_RECORD_SW_CURR: - DfxUpdateTime(g_dfxRecord.renderTimeSWCurr); - break; - case TimeRecordType::DFX_TIME_RECORD_HW_CURR: - DfxUpdateTime(g_dfxRecord.renderTimeHWCurr); - break; - case TimeRecordType::DFX_TIME_RECORD_FLUSH_CURR: - DfxUpdateTime(g_dfxRecord.renderTimeFlushCurr); - break; - case TimeRecordType::DFX_TIME_RECORD_END: - DfxRenderRecordEnd(); - break; - default: - return; - } -} - bool IsShowTPRaw() { return (g_dfxShow == ShowType::DFX_SHOW_TP); @@ -138,29 +77,9 @@ void DfxTPGetEvent() g_tpSetTime = 0; } -void DfxRenderReset() -{ - if (g_dfxShow == ShowType::DFX_SHOW_RENDER) { - g_dfxRecord.renderTimeStart = GetTimeUs(); - g_dfxRecord.renderTimeSWCurr = 0; - g_dfxRecord.renderTimeHWCurr = 0; - g_dfxRecord.renderTimeFlushCurr = 0; - g_dfxRecord.renderTimeSWMax = 0; - g_dfxRecord.renderTimeHWMax = 0; - g_dfxRecord.renderTimeFlushMax = 0; - g_dfxRecord.renderCnt++; - g_renderStartTime = g_dfxRecord.renderTimeStart; - } -} - void DfxRecordShow() { - if (g_dfxShow == ShowType::DFX_SHOW_ULPS) { - GRAPHIC_LOGP("g_ulpsExit: %u, g_flush: %u\n", g_ulpsExit, g_flush); - return; - } - - if ((g_dfxShow != ShowType::DFX_SHOW_POINT) && (g_dfxShow != ShowType::DFX_SHOW_RENDER)) { + if (g_dfxShow != ShowType::DFX_SHOW_POINT) { return; } @@ -172,19 +91,6 @@ void DfxRecordShow() GRAPHIC_LOGP("TP: sc: %u, gc: %u, sMin: %u, sMax: %u, g2sAvg: %u, g2sMax: %u", g_dfxRecord.setEventCnt, g_dfxRecord.getEventCnt, g_dfxRecord.setEventGapMin, g_dfxRecord.setEventGapMax, g2sAvg, g_dfxRecord.getToSetTimeMax / MS_TO_US); - } else if (g_dfxShow == ShowType::DFX_SHOW_RENDER) { - float swAvg = (g_dfxRecord.renderCnt == 0) ? 0 : - static_cast(g_dfxRecord.renderTimeSWTotal) / (g_dfxRecord.renderCnt * MS_TO_US); - float hwAvg = (g_dfxRecord.renderCnt == 0) ? 0 : - static_cast(g_dfxRecord.renderTimeHWTotal) / (g_dfxRecord.renderCnt * MS_TO_US); - float dpuAvg = (g_dfxRecord.renderCnt == 0) ? 0 : - static_cast(g_dfxRecord.renderTimeFlushTotal) / (g_dfxRecord.renderCnt * MS_TO_US); - float totalAvg = (g_dfxRecord.renderCnt == 0) ? 0 : - static_cast(g_dfxRecord.renderTimeTotal) / (g_dfxRecord.renderCnt * MS_TO_US); - GRAPHIC_LOGP("Render: Cnt: %u, totalAvg: %4.2f, swAvg: %4.2f, swMax: %u, subAvg: %4.2f " - "subMax: %u, flushAvg: %4.2f, flushMax: %u", - g_dfxRecord.renderCnt, totalAvg, swAvg, g_dfxRecord.renderTimeSWMax / MS_TO_US, hwAvg, - g_dfxRecord.renderTimeHWMax / MS_TO_US, dpuAvg, g_dfxRecord.renderTimeFlushMax / MS_TO_US); } g_lastTime = g_currentTime; memset_s(&g_dfxRecord, sizeof(g_dfxRecord), 0, sizeof(g_dfxRecord)); @@ -196,11 +102,6 @@ void DfxShowType(ShowType type) return; } -void DfxUlpsFlushRecord(uint8_t flag) -{ - return; -} - bool IsShowTPRaw() { return false; @@ -211,11 +112,6 @@ bool IsShowPoint() return false; } -void DfxRecordTime(TimeRecordType type) -{ - return; -} - void DfxTPSetEvent(uint32_t time) { return; @@ -229,11 +125,6 @@ void DfxRecordShow() { return; } - -void DfxRenderReset() -{ - return; -} #endif // ENABLE_DFX_CMD } diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/engines/gfx/lite_m_gfx_engine.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/engines/gfx/lite_m_gfx_engine.h index 43de3905c..e7c296d93 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/engines/gfx/lite_m_gfx_engine.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/engines/gfx/lite_m_gfx_engine.h @@ -141,6 +141,11 @@ public: hardwareView_ = nullptr; } + bool HasPendingFrame() + { + return lastAsyncInfo_.hasPendingFrame; + } + #endif private: LiteMGfxEngine() {} @@ -178,6 +183,7 @@ private: void AddHwDraw(uint16_t cnt); void AsyncFlush(); #endif + void FlushInner(const Rect &rect); }; } #endif // GRAPHIC_LITE_LITE_M_GFX_ENGINE_H diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_effect.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_effect.cpp index fda678038..79ac0ce4d 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_effect.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_effect.cpp @@ -4,206 +4,52 @@ * Author: * Create: 2023-10 */ - -#include "draw/draw_utils.h" -#include "common/screen.h" -#include "engines/gfx/lite_m_gfx_engine.h" #include "turn_page_effect.h" +#include "imgdecode/image_load.h" namespace OHOS { -static constexpr int16_t CAMERA_DISTANCE = 600; -static constexpr int16_t EASE_RANGE = 100; - -void TurnPageEffect::GetImgs(UIView* leftCard, UIView* rightCard) -{ - ImageInfo info; - ImageInfo leftInfo; - ImageInfo rightInfo; - - if (preLeftCard != nullptr) { - info = *(imgll_.GetImageInfo()); - ImageCacheFree(info); - info = *(imglr_.GetImageInfo()); - ImageCacheFree(info); - info = *(imgrl_.GetImageInfo()); - ImageCacheFree(info); - info = *(imgrr_.GetImageInfo()); - ImageCacheFree(info); - preLeftCard->SetVisible(true); - preRightCard->SetVisible(true); - } - - if (leftCard->GetViewType() == UI_IMAGE_VIEW) { - leftInfo = *(static_cast(leftCard)->GetImageInfo()); - rightInfo = *(static_cast(rightCard)->GetImageInfo()); - } else { - leftCard->GetBitmap(leftInfo); - rightCard->GetBitmap(rightInfo); - } - - int16_t height = Screen::GetInstance().GetHeight(); - int16_t middleWidth = Screen::GetInstance().GetWidth() / 2; - int16_t middleHeight = height / 2; - imgll_.SetPosition(0, 0, middleWidth, height); - GetBitmapByRect(leftInfo, info, Rect(0, 0, middleWidth - 1, height - 1)); - imgll_.SetSrc(&info); - - imglr_.SetPosition(middleWidth - 1, 0, middleWidth, height); - imglr_.SetCameraPosition(Vector2(0, middleHeight)); - imglr_.SetCameraDistance(CAMERA_DISTANCE); - GetBitmapByRect(leftInfo, info, Rect(middleWidth - 1, 0, leftCard->GetWidth() - 1, height - 1)); - imglr_.SetSrc(&info); - - imgrl_.SetPosition(0, 0, middleWidth, height); - imgrl_.SetCameraPosition(Vector2(middleWidth, middleHeight)); - imgrl_.SetCameraDistance(CAMERA_DISTANCE); - GetBitmapByRect(rightInfo, info, Rect(0, 0, middleWidth - 1, height - 1)); - imgrl_.SetSrc(&info); - - imgrr_.SetPosition(middleWidth, 0, middleWidth, height); - GetBitmapByRect(rightInfo, info, Rect(middleWidth, 0, leftCard->GetWidth() - 1, height - 1)); - imgrr_.SetSrc(&info); - - leftCard->SetVisible(false); - rightCard->SetVisible(false); - preLeftCard = leftCard; - preRightCard = rightCard; - - if (leftCard->GetViewType() != UI_IMAGE_VIEW) { - ImageCacheFree(leftInfo); - ImageCacheFree(rightInfo); - } -} - -bool TurnPageEffect::GetBitmapByRect(ImageInfo& srcInfo, ImageInfo& dstInfo, const Rect rect) -{ - BufferInfo srcBuff; - uint8_t bpp = DrawUtils::GetByteSizeByColorMode(srcInfo.header.colorMode); - srcBuff.mode = static_cast(srcInfo.header.colorMode); - srcBuff.compressMode = 0; - srcBuff.stride = ALIGN_BYTE(srcInfo.header.width, BYTE_ALIGNMENT) * bpp; - srcBuff.phyAddr = static_cast(const_cast(srcInfo.phyAddr)); - srcBuff.virAddr = static_cast(const_cast(srcInfo.data)); - srcBuff.width = srcInfo.header.width; - srcBuff.height = srcInfo.header.height; - srcBuff.rect = rect; - - dstInfo.header.width = rect.GetWidth(); - dstInfo.header.height = rect.GetHeight(); - dstInfo.header.colorMode = srcBuff.mode; - dstInfo.dataSize = ALIGN_BYTE(dstInfo.header.width, BYTE_ALIGNMENT) * dstInfo.header.height * bpp; - dstInfo.header.compressMode = 0; - if (ImageCacheMalloc(dstInfo) == nullptr) { - return false; - } - - Rect dstRect = Rect(0, 0, rect.GetWidth() - 1, rect.GetHeight() - 1); - BufferInfo dstBuf; - dstBuf.mode = srcBuff.mode; - dstBuf.compressMode = 0; - dstBuf.stride = ALIGN_BYTE(rect.GetWidth(), BYTE_ALIGNMENT) * bpp; - dstBuf.phyAddr = static_cast(const_cast(dstInfo.phyAddr)); - dstBuf.virAddr = static_cast(const_cast(dstInfo.data)); - dstBuf.width = rect.GetWidth(); - dstBuf.height = rect.GetHeight(); - dstBuf.rect = dstRect; - - BlendOption opt; - opt.opacity = OPA_OPAQUE; - opt.mode = BLEND_SRC; - if (LiteMGfxEngine::GetInstance()->IsAsyncModeEnabled()) { - LiteMGfxEngine::GetInstance()->Flush(Rect(0, 0, 0, 0)); - } - BaseGfxEngine::GetInstance()->Blit(dstBuf, {0, 0}, srcBuff, dstRect, opt); -#if ENABLE_VGU_ENGINE - LiteMGfxEngine::GetInstance()->SyncHwDraw(); -#endif - return true; -} - void TurnPageEffect::OnSwipe(UISwipeView& view) { if (preLeftCard != nullptr) { - container_->UIViewGroup::Remove(&imgll_); - container_->UIViewGroup::Remove(&imglr_); - container_->UIViewGroup::Remove(&imgrl_); - container_->UIViewGroup::Remove(&imgrr_); + RemoveFromContainer(); + preLeftCard->SetVisible(true); preRightCard->SetVisible(true); preLeftCard = nullptr; preRightCard = nullptr; - visibleCard_ = nullptr; - ImageInfo info = *(imgll_.GetImageInfo()); - ImageCacheFree(info); - info = *(imglr_.GetImageInfo()); - ImageCacheFree(info); - info = *(imgrl_.GetImageInfo()); - ImageCacheFree(info); - info = *(imgrr_.GetImageInfo()); - ImageCacheFree(info); + FreeInfo(); } } void TurnPageEffect::CommonAlg(UIView* leftCard, UIView* rightCard, int16_t xOffset) { - if (preLeftCard == nullptr) { - container_->UIViewGroup::Add(&imgrr_); - container_->UIViewGroup::Add(&imgll_); - } - if (preLeftCard != leftCard && preRightCard != rightCard) { - GetImgs(leftCard, rightCard); - } - - int16_t width = Screen::GetInstance().GetWidth(); - int16_t middleWidth = width / 2; - float factor; - if (abs(xOffset) < middleWidth) { - factor = EasingEquation::LinearEaseNone(0, EASE_RANGE, abs(xOffset), middleWidth); - } else { - factor = EasingEquation::LinearEaseNone(0, EASE_RANGE, width - abs(xOffset), middleWidth); - } - - float angle = 90 * factor / EASE_RANGE; // 90: quarter cycle degrees - Vector3 rotateStart = {middleWidth, 0, 0}; - Vector3 rotateEnd = {middleWidth, 1, 0}; - UIView* tmpCard = nullptr; - - if (xOffset > 0) { - if (xOffset < middleWidth) { - tmpCard = &imgrl_; - } else { - tmpCard = &imglr_; - angle = -angle; - rotateStart.x_ = 0.0; - rotateEnd.x_ = 0.0; + if (preLeftCard != nullptr) { + preLeftCard->SetVisible(true); + preRightCard->SetVisible(true); + FreeInfo(); } - } else if (xOffset < 0) { - if (abs(xOffset) < middleWidth) { - tmpCard = &imglr_; - angle = -angle; - rotateStart.x_ = 0.0; - rotateEnd.x_ = 0.0; + if (leftCard->GetViewType() == UI_IMAGE_VIEW) { + lInfo_ = *(static_cast(leftCard)->GetImageInfo()); + rInfo_ = *(static_cast(rightCard)->GetImageInfo()); } else { - tmpCard = &imgrl_; + FreeInfo(); + if (!AllocInfo(leftCard, rightCard)) { + GRAPHIC_LOGE("get bitmap failed!"); + return; + } + lInfo_ = *leftInfo_; + rInfo_ = *rightInfo_; } - } else { - if (preLeftCard == leftCard) { - tmpCard = &imglr_; - } else { - tmpCard = &imgrl_; - } - } - if (visibleCard_ != tmpCard) { - container_->UIViewGroup::Remove(visibleCard_); - container_->UIViewGroup::Add(tmpCard); - visibleCard_ = tmpCard; + leftCard->SetVisible(false); + rightCard->SetVisible(false); + preLeftCard = leftCard; + preRightCard = rightCard; } - - visibleCard_->Rotate(angle, rotateStart, rotateEnd); - return; + AddToContainer(); + turnPageView_.SetTurnPageInfo(&lInfo_, &rInfo_, ComputeAngle(xOffset)); } void TurnPageEffect::CardSwipeAlg(UICardPage* leftCard, UICardPage* rightCard, int16_t xOffset) @@ -215,4 +61,52 @@ void TurnPageEffect::CardSwipeAlg(UIImageView* leftCard, UIImageView* rightCard, { CommonAlg(leftCard, rightCard, xOffset); } + +void TurnPageEffect::FreeInfo() +{ + if (leftInfo_ != nullptr) { + ImageCacheFree(*leftInfo_); + delete leftInfo_; + leftInfo_ = nullptr; + } + if (rightInfo_ != nullptr) { + ImageCacheFree(*rightInfo_); + delete rightInfo_; + rightInfo_ = nullptr; + } +} + +bool TurnPageEffect::AllocInfo(UIView* leftCard, UIView* rightCard) +{ + if (leftCard == nullptr || rightCard == nullptr) { + return false; + } + leftInfo_ = new ImageInfo; + rightInfo_ = new ImageInfo; + if (leftInfo_ == nullptr || rightInfo_ == nullptr) { + delete leftInfo_; + delete rightInfo_; + return false; + } + memset_s(leftInfo_, sizeof(ImageInfo), 0, sizeof(ImageInfo)); + memset_s(rightInfo_, sizeof(ImageInfo), 0, sizeof(ImageInfo)); + leftCard->GetBitmap(*leftInfo_); + rightCard->GetBitmap(*rightInfo_); + return true; +} + +float TurnPageEffect::ComputeAngle(int16_t xOffset) +{ + float w = Screen::GetInstance().GetWidth(); + float x = xOffset; + const float maxAngle = 180; + const float rightAngle = 90; + x = x < 0 ? -x : w - x; + float angle = x / w * maxAngle; + if (xOffset == 0) { + angle = lastPage_ ? 0 : maxAngle; + } + lastPage_ = (angle < rightAngle); + return angle; +} } diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_effect.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_effect.h index b05514280..9a21bcf1b 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_effect.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_effect.h @@ -7,6 +7,8 @@ #ifndef UI_TURN_PAGE_H #define UI_TURN_PAGE_H +#include "common/screen.h" +#include "turn_page_view.h" #include "components/ui_cross_view.h" namespace OHOS { @@ -16,7 +18,10 @@ public: { isNeedClip_ = true; } - ~TurnPageEffect() override {} + ~TurnPageEffect() override + { + FreeInfo(); + } void CardSwipeAlg(UICardPage* leftCard, UICardPage* rightCard, int16_t xOffset) override; void CardSwipeAlg(UIImageView* leftCard, UIImageView* rightCard, int16_t xOffset) override; void OnSwipe(UISwipeView& view) override; @@ -26,18 +31,37 @@ public: } private: - UIImageView imgll_; - UIImageView imglr_; - UIImageView imgrl_; - UIImageView imgrr_; - UIView* visibleCard_ = nullptr; + TurnPageView turnPageView_; + ImageInfo lInfo_ = {0}; + ImageInfo rInfo_ = {0}; + bool added_ = false; UIView* preLeftCard = nullptr; UIView* preRightCard = nullptr; UICrossView* container_ = nullptr; + ImageInfo *leftInfo_ = nullptr; + ImageInfo *rightInfo_ = nullptr; + bool lastPage_ = false; // false for left, true for right - void GetImgs(UIView* leftCard, UIView* rightCard); - bool GetBitmapByRect(ImageInfo& srcInfo, ImageInfo& dstInfo, const Rect rect); void CommonAlg(UIView* leftCard, UIView* rightCard, int16_t xOffset); + void FreeInfo(); + bool AllocInfo(UIView* leftCard, UIView* rightCard); + float ComputeAngle(int16_t xOffset); + void AddToContainer() + { + if (!added_) { + turnPageView_.SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->UIViewGroup::Add(&turnPageView_); + added_ = true; + } + } + + void RemoveFromContainer() + { + if (added_) { + container_->UIViewGroup::Remove(&turnPageView_); + added_ = false; + } + } }; } #endif diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_view.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_view.cpp new file mode 100644 index 000000000..b13870b6d --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_view.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) CompanyNameMagicTag 2024. All rights reserved. + * Description: TurnPageView + * Author: + * Create: 2024-6 + */ + +#include "turn_page_view.h" +#include "imgdecode/image_load.h" +#include "engines/gfx/lite_m_gfx_engine.h" + +namespace OHOS { +void TurnPageView::SetTurnPageInfo(ImageInfo* leftCard, ImageInfo* rightCard, float angle) +{ + if (leftCard == nullptr || rightCard == nullptr) { + leftInfo_ = nullptr; + rightInfo_ = nullptr; + return; + } + + int16_t height = GetHeight(); + int16_t width = GetWidth(); + if (height != leftCard->header.height || width != leftCard->header.width + || height != rightCard->header.height || width != rightCard->header.width) { + GRAPHIC_LOGE("image shape not coninsides with the view rect!"); + leftInfo_ = nullptr; + rightInfo_ = nullptr; + return; + } + int16_t middleWidth = width / 2; // 2: half + int16_t middleHeight = height / 2; // 2: half + Rect origRect = GetOrigRect(); + leftInfo_ = leftCard; + rightInfo_ = rightCard; + Rect rect; + rect.SetWidth(middleWidth); + rect.SetHeight(height); + + // ll + rect.SetPosition(origRect.GetX(), origRect.GetY()); + transll_.SetTransMapRect(rect); + // lr + rect.SetPosition(origRect.GetX() + middleWidth - 1, origRect.GetY()); + translr_.SetTransMapRect(rect); + SetCamera({0, middleWidth}, translr_); + // rl + rect.SetPosition(origRect.GetX(), origRect.GetY()); + transrl_.SetTransMapRect(rect); + SetCamera({middleWidth, middleHeight}, transrl_); + // rr + rect.SetPosition(origRect.GetX() + middleWidth, origRect.GetY()); + transrr_.SetTransMapRect(rect); + + RotateImg(angle); + UpdateInvalidArea(); +} + +void TurnPageView::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) +{ + DrawPartialRect(gfxDstBuffer, invalidatedArea, leftInfo_, transll_); + DrawPartialRect(gfxDstBuffer, invalidatedArea, rightInfo_, transrr_); + if (usingLeft_) { + DrawPartialRect(gfxDstBuffer, invalidatedArea, leftInfo_, translr_); + } else { + DrawPartialRect(gfxDstBuffer, invalidatedArea, rightInfo_, transrl_); + } +} + +void TurnPageView::DrawPartialRect(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, + ImageInfo *info, const TransformMap &transform) +{ + uint8_t opa = GetMixOpaScale(); + if (info == nullptr) { + return; + } + Rect dstRect(invalidatedArea); + if (!dstRect.Intersect(dstRect, transform.GetBoxRect())) { + return; + } + BufferInfo src = {{0, 0, info->header.width - 1, info->header.height - 1}}; + src.width = info->header.width; + src.height = info->header.height; + src.stride = static_cast(ImageLoad::GetAlignedStride(src.width, + info->header.compressMode, info->header.colorMode)); + src.compressMode = info->header.compressMode; + src.mode = static_cast(info->header.colorMode); + src.virAddr = reinterpret_cast(const_cast(info->data)); + src.phyAddr = reinterpret_cast(const_cast(info->data)); + + BlendOption opt; + opt.mode = BLEND_SRC_OVER; + opt.opacity = opa; + src.rect = transform.GetTransMapRect(); + + opt.transMap.SetMatrix(transform.GetTransformMatrix()); + BaseGfxEngine::GetInstance()->Blit(gfxDstBuffer, {0, 0}, src, dstRect, opt); +} + +void TurnPageView::RotateImg(float angle) +{ + const float maxAngle = 180; + const float rightAngle = 90; + TransformMap *transform = angle < rightAngle ? &translr_ : &transrl_; + float w = GetWidth(); + float x = angle < rightAngle ? 0 : w / 2; // 2: half + angle = angle < rightAngle ? angle : angle - maxAngle; + usingLeft_ = (transform == &translr_); + transform->Rotate(angle, Vector3{x, 0, 0}, Vector3{x, 1, 0}); +} + +void TurnPageView::UpdateInvalidArea() +{ + Rect joinRect = transll_.GetBoxRect(); + joinRect.Join(joinRect, transrr_.GetBoxRect()); + joinRect.Join(joinRect, translr_.GetBoxRect()); + joinRect.Join(joinRect, transrl_.GetBoxRect()); + InvalidateRect(joinRect); +} +} // OHOS \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_view.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_view.h new file mode 100644 index 000000000..4ad4be6fb --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/frameworks/swipe_effect/turn_page_view.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) CompanyNameMagicTag 2024. All rights reserved. + * Description: TurnPageView + * Author: + * Create: 2024-6 + */ + +#ifndef UI_TURN_PAGE_VIEW_H +#define UI_TURN_PAGE_VIEW_H +#include "securec.h" +#include "components/ui_view.h" + +namespace OHOS { +class TurnPageView : public UIView { +public: + TurnPageView() + { + } + ~TurnPageView() override {} + TurnPageView &operator=(const TurnPageView&) = delete; + TurnPageView(const TurnPageView&) = delete; + void SetTurnPageInfo(ImageInfo* leftCard, ImageInfo* rightCard, float angle); + void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override; + +private: + void DrawPartialRect(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea, + ImageInfo *info, const TransformMap &transform); + void SetCamera(Vector2 pos, TransformMap &transform) + { + constexpr int16_t CAMERA_ZPOS = -600; + transform.SetCameraPosition(pos); + transform.SetCameraDistance(CAMERA_ZPOS); + } + void RotateImg(float angle); + void UpdateInvalidArea(); + ImageInfo *leftInfo_ = nullptr; + ImageInfo *rightInfo_ = nullptr; + bool usingLeft_ = false; + TransformMap transll_; + TransformMap translr_; + TransformMap transrl_; + TransformMap transrr_; +}; +} // OHOS +#endif // UI_TURN_PAGE_VIEW_H \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/innerkits/common/low_power_manager.h b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/innerkits/common/low_power_manager.h index f019216b1..e0dc86041 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/innerkits/common/low_power_manager.h +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/ui/innerkits/common/low_power_manager.h @@ -43,40 +43,14 @@ public: * */ void ExitLowPower(); - /** * @brief Check if LiteSurface is in rootView. * */ bool IsLiteSurfaceInRootView(); - /** - * @brief Increase use count for powerLock_, witch is used to lock at full freq(60fps). - * - */ - void PowerLock() - { - powerLock_++; - } - - /** - * @brief Decrease use count for powerLock_, witch is used to lock at full freq(60fps). - * - */ - void PowerUnLock() - { - if (powerLock_ > 0) { - powerLock_--; - } - } - -protected: +private: uint32_t lastExitTime_ = 0; - int8_t powerLock_ = 0; - - bool CheckGuiState(); - bool CheckTaskState(); - void EnterLowPower(); }; } // OHOS #endif // GRAPHIC_LOW_POWER_MANAGER diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/display_dev.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/display_dev.cpp index b173f99fc..6dbca60ee 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/display_dev.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/display_dev.cpp @@ -21,6 +21,7 @@ #include "gfx_utils/mem_api.h" #include "graphic_config.h" #include "hals/gralloc_engines.h" +#include "dfx/dfx_frame_trace.h" namespace OHOS { DisplayDev::DisplayDev() : isDisplayDevInited_{false}, devId_(0), layerFuncs_{nullptr} @@ -356,6 +357,7 @@ void DisplayDev::SetLayerDirtyRegion(uint8_t layerId, const Rect& rect) } if (layerFuncs_->SetLayerDirtyRegion != nullptr) { + FRAME_TRACE_SET_RECT(rect); IRect iRect = {rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight()}; if (layerFuncs_->SetLayerDirtyRegion(devId_, layer_[layerId].layerHdl, &iRect) != DISPLAY_SUCCESS) { diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/gralloc_engines.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/gralloc_engines.cpp index 3a98cda47..9a6a33edc 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/gralloc_engines.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/gralloc_engines.cpp @@ -78,7 +78,9 @@ bool GrallocEngines::AllocBuffer(const AllocInfo& info, GrallocBuffer& buffer) if (!AllocBufferOnce(info, buffer)) { GRAPHIC_LOGE("GrallocEngines::AllocBuffer realloc size: %u", info.expectedSize); if (ImageCacheManager::GetInstance().FreeAndGetBuf(info, buffer) == nullptr) { +#if ENABLE_MEMORY_CHECK DumpMem(); +#endif #ifdef __LITEOS__ OsMemInfoPrint(reinterpret_cast(MEM_POOL_UI_OTHER)); #endif diff --git a/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/lite_input_distributer.cpp b/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/lite_input_distributer.cpp index 87ba20080..53179160f 100644 --- a/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/lite_input_distributer.cpp +++ b/code/sdk/middleware/services/gui/uikit/proprietary/src/utils/frameworks/hals/lite_input_distributer.cpp @@ -33,6 +33,7 @@ LiteInputDistributer::~LiteInputDistributer() {} void LiteInputDistributer::SendRawEvent(const RawEvent& rawEvent) { +#if !defined(_WIN32) RawEvent event = rawEvent; DisplayDev* displayDev = DisplayDev::GetInstance(); if ((event.type == InputDevType::INDEV_TYPE_TOUCH) && @@ -50,6 +51,7 @@ void LiteInputDistributer::SendRawEvent(const RawEvent& rawEvent) SendEventToPM(event); #endif SetEventData(event); +#endif } void LiteInputDistributer::GetEventData(DeviceData& data, InputDevType type) @@ -131,7 +133,7 @@ void LiteInputDistributer::SetEventData(const RawEvent& event) bool LiteInputDistributer::IsEventEmpty(InputDevType type) { if (type == InputDevType::INDEV_TYPE_TOUCH) { - return ((g_lastData.state == 0) && (deviceData_.state == 0)); + return ((g_lastData.state == 0) && (deviceData_.state == 0) && (dataBuf_.IsEmpty())); } else if (type == InputDevType::INDEV_TYPE_KEY) { return keyList_.IsEmpty(); } diff --git a/code/sdk/middleware/services/gui/uikit/res/add.bin b/code/sdk/middleware/services/gui/uikit/res/add.bin new file mode 100644 index 000000000..6a4bc43b3 Binary files /dev/null and b/code/sdk/middleware/services/gui/uikit/res/add.bin differ diff --git a/code/sdk/middleware/services/gui/uikit/res/sub.bin b/code/sdk/middleware/services/gui/uikit/res/sub.bin new file mode 100644 index 000000000..4f3f37290 Binary files /dev/null and b/code/sdk/middleware/services/gui/uikit/res/sub.bin differ diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow2.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow2.cpp new file mode 100644 index 000000000..e23737aa3 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow2.cpp @@ -0,0 +1,240 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ui_test_coverflow2.h" +#include "common/screen.h" +#include "font/ui_font.h" +#include "gfx_utils/graphic_math.h" +#include "gfx_utils/rect.h" +#include "common/image_cache_manager.h" +#include "components/ui_image_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_transform_group.h" + +namespace OHOS { +namespace { +struct FaceInfo { + const char* name; + const char* path; +} ; + +static constexpr uint8_t COVERFLOW_MAX_PAGE_NUM = 6; +static FaceInfo g_faceInfo[COVERFLOW_MAX_PAGE_NUM] = { + {"1 rainbow", RES_PATH"/rainbow.bin"}, + {"2 kaleidoscope", RES_PATH"/kaleidoscope.bin"}, + {"3 planet", RES_PATH"/planet.bin"}, + {"4 rainbow", RES_PATH"/rainbow.bin"}, + {"5 kaleidoscope", RES_PATH"/kaleidoscope.bin"}, + {"6 planet", RES_PATH"/planet.bin"} +}; +const char* addImgPath = RES_PATH"/add.bin"; +const char* subImgPath = RES_PATH"/sub.bin"; +static constexpr uint8_t PAGE_MARGIN = 20; +static constexpr uint16_t PAGE_WIDTH = 250; +static constexpr uint16_t PAGE_HEIGHT = 250; +static constexpr uint8_t DIVISOR_TWO = 2; +static constexpr int16_t LABEL_FONT_SIZE = 30; +static constexpr uint16_t IMAGE_WIDTH = 200; +static constexpr uint16_t IMAGE_HEIGHT = 200; +} // namespace + +void UITestCoverflow2::SetUp() +{ + if (container_ == nullptr) { + container_ = new UIScrollView(); + container_->SetThrowDrag(true); + container_->SetHorizontalScrollState(false); + container_->Resize(Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + } +} + +void UITestCoverflow2::TearDown() +{ + if (coverflow_ != nullptr) { + UITransformGroup* child = dynamic_cast(coverflow_->GetChildrenHead()); + while (child != nullptr) { + UIView* node = child; + child = dynamic_cast(child->GetNextSibling()); + coverflow_->Remove(node); + delete node; + } + delete coverflow_; + coverflow_ = nullptr; + } + lastIndex_ = 0; + lastPage_ = nullptr; + addImage_ = nullptr; + if (label_ != nullptr) { + delete label_; + label_ = nullptr; + } + + if (container_ != nullptr) { + delete container_; + container_ = nullptr; + } +} + +const UIView* UITestCoverflow2::GetTestView() +{ + UITestCoverflow2001(); + return container_; +} + +void UITestCoverflow2::UITestCoverflow2001() +{ + if (container_ == nullptr) { + return; + } + if (coverflow_ == nullptr) { + coverflow_ = new UICoverFlowView2(); + } + coverflow_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + coverflow_->SetThrowDrag(true); + coverflow_->SetOnCoverflowListener(this); + coverflow_->SetPagePadding(PAGE_MARGIN); + container_->Add(coverflow_); + for (uint8_t i = 0; i < COVERFLOW_MAX_PAGE_NUM - 1; i++) { + UITransformGroup* page = new UITransformGroup(); + page->SetPosition(0, 100, PAGE_WIDTH, PAGE_HEIGHT); // 100: y position + UIImageView* image = new UIImageView(); + image->Resize(IMAGE_WIDTH, IMAGE_HEIGHT); + page->Add(image); + ImageInfo* src = ImageCacheManager::GetInstance().LoadSingleRes(std::string(g_faceInfo[i].path)); + image->SetSrc(src); + image->LayoutCenterOfParent(); + + UIImageView* imageSub = new UIImageView(); + imageSub->SetPosition(200, 0, 50, 50); // 200: x position 50: width and height + page->Add(imageSub); + src = ImageCacheManager::GetInstance().LoadSingleRes(std::string(subImgPath)); + imageSub->SetSrc(src); + imageSub->SetTouchable(true); + imageSub->SetOnClickListener(this); + coverflow_->Add(page); + lastPage_ = page; + } + CreateAddButton(); + CreateTitleLabel(); +} + +void UITestCoverflow2::CreateAddButton() +{ + UITransformGroup* page = new UITransformGroup(); + page->SetPosition(0, 100, PAGE_WIDTH, PAGE_HEIGHT); + + if (addImage_ == nullptr) { + addImage_ = new UIImageView(); + } + + addImage_->Resize(IMAGE_WIDTH, IMAGE_HEIGHT); + addImage_->SetTouchable(true); + addImage_->SetAutoEnable(false); + addImage_->SetResizeMode(UIImageView::ImageResizeMode::FILL); + addImage_->SetOnClickListener(this); + page->Add(addImage_); + addImage_->LayoutCenterOfParent(); + + ImageInfo* src = ImageCacheManager::GetInstance().LoadSingleRes(std::string(addImgPath)); + addImage_->SetSrc(src); + coverflow_->Add(page); +} + +void UITestCoverflow2::CreateTitleLabel() +{ + if (label_ == nullptr) { + label_ = new UILabel(); + } + label_->SetPosition(127, 50, 200, 50); // 127 50 200 50: label position + label_->SetTextColor(Color::White()); + label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + lastIndex_ = coverflow_->GetCurrentPage(); + label_->SetText(g_faceInfo[lastIndex_].name); + label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, LABEL_FONT_SIZE); + container_->Add(label_); +} + +bool UITestCoverflow2::OnClick(UIView& view, const ClickEvent& event) +{ + if (&view == addImage_) { + UITransformGroup* page = new UITransformGroup(); + page->SetPosition(0, 100, PAGE_WIDTH, PAGE_HEIGHT); + + UIImageView* image = new UIImageView(); + image->Resize(IMAGE_WIDTH, IMAGE_HEIGHT); + page->Add(image); + ImageInfo* src = ImageCacheManager::GetInstance().LoadSingleRes(RES_PATH"/planet.bin"); + image->SetSrc(src); + image->LayoutCenterOfParent(); + + UIImageView* imageSub = new UIImageView(); + imageSub->SetPosition(200, 0, 50, 50); // 200: x position 50: width and height + page->Add(imageSub); + src = ImageCacheManager::GetInstance().LoadSingleRes(std::string(subImgPath)); + imageSub->SetSrc(src); + imageSub->SetTouchable(true); + imageSub->SetOnClickListener(this); + coverflow_->Insert(lastPage_, page); + lastPage_ = page; + } else { + UITransformGroup* page = dynamic_cast(view.GetParent()); + UIView* child = page->GetChildrenHead(); + while (child != nullptr) { + UIView* node = child; + child = child->GetNextSibling(); + page->Remove(node); + delete node; + } + coverflow_->Remove(page); + delete page; + } + return true; +} + +bool UITestCoverflow2::OnScroll(uint16_t distance) +{ + int16_t contMidX = static_cast(Screen::GetInstance().GetWidth() / DIVISOR_TWO); + int16_t minOffset = contMidX; + uint8_t newCenterIndex = lastIndex_; + for (uint8_t i = 0; i < coverflow_->GetChildrenNumber(); i++) { + Rect rect = coverflow_->GetViewByIndex(i)->GetOrigRect(); + int16_t x = rect.GetLeft(); + int16_t x1 = rect.GetRight(); + int16_t xMid = static_cast(x + (x1 - x + 1) / DIVISOR_TWO); + int16_t distance = MATH_ABS(xMid - contMidX); + if (distance < minOffset) { + newCenterIndex = i; + minOffset = distance; + } + } + if (newCenterIndex != lastIndex_ && newCenterIndex < COVERFLOW_MAX_PAGE_NUM) { + lastIndex_ = newCenterIndex; + label_->SetText(g_faceInfo[newCenterIndex].name); + } else if (newCenterIndex >= COVERFLOW_MAX_PAGE_NUM) { + label_->SetText(""); + } + + Rect curViewRect = coverflow_->GetViewByIndex(lastIndex_)->GetOrigRect(); + int16_t centerMid = curViewRect.GetLeft() + curViewRect.GetWidth() / DIVISOR_TWO; + int16_t offset = MATH_ABS(contMidX - centerMid); + if (offset > curViewRect.GetWidth() / DIVISOR_TWO) { + label_->SetStyle(STYLE_TEXT_OPA, 0); + } else { + uint8_t alpha = (uint8_t)((1.0f - ((float)offset / (curViewRect.GetWidth() / DIVISOR_TWO))) * OPA_OPAQUE); + label_->SetStyle(STYLE_TEXT_OPA, alpha); + } + return true; +} +} // namespace OHOS diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow2.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow2.h new file mode 100644 index 000000000..6cb1d9051 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_coverflow/ui_test_coverflow2.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UI_TEST_COVERFLOW_VIEW_2_H +#define UI_TEST_COVERFLOW_VIEW_2_H + +#include "components/ui_coverflow_view2.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "ui_test.h" + +namespace OHOS { +class UITestCoverflow2 : public UITest, + public UICoverFlowView2::OnCoverflowScrollListener, public UIView::OnClickListener { +public: + UITestCoverflow2() {} + ~UITestCoverflow2() override {} + void SetUp() override; + void TearDown() override; + const UIView* GetTestView() override; + /** + * @brief Test display UICoverflow + */ + void UITestCoverflow2001(); + +protected: + bool OnScroll(uint16_t distance) override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + void CreateAddButton(); + void CreateTitleLabel(); + + UIScrollView* container_ = nullptr; + UICoverFlowView2* coverflow_ = nullptr; + UILabel* label_ = nullptr; + UIImageView* addImage_ = nullptr; + uint16_t lastIndex_ = 0; + UITransformGroup* lastPage_ = nullptr; +}; +} // namespace OHOS +#endif // UI_TEST_COVERFLOW_VIEW_2_H diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_icosahedron/ui_test_icosahedron.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_icosahedron/ui_test_icosahedron.cpp new file mode 100644 index 000000000..2d2352809 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_icosahedron/ui_test_icosahedron.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ui_test_icosahedron.h" +#include "common/screen.h" +#include "common/image_cache_manager.h" +#include "components/ui_image_view.h" + +namespace OHOS { +static constexpr uint8_t PLANES_NUM = 20; +void EntryAnimatorCallback::Callback(UIView *view) +{ + UIIcosahedronView* footView = dynamic_cast(view); + int16_t el = EasingEquation::LinearEaseNone(startPos_, endPos_, animator_->GetRunTime(), animator_->GetTime()); + footView->SetSideLength(el); + footView->RefreshIcosahedron(); + const Vector3 rotateStart(Screen::GetInstance().GetWidth() / 2.0, // 2.0: divisor + Screen::GetInstance().GetHeight() / 2.0, 0); // 2.0: divisor + const Vector3 rotateEnd(0, 0, 0); + // 270 : stop angle + int16_t angle = EasingEquation::LinearEaseNone(0, 270, animator_->GetRunTime(), animator_->GetTime()); + footView->RotatePlanes(angle, rotateStart, rotateEnd); +} + +bool UITestIcosahedron::OnClick(UIView& view, const ClickEvent& event) +{ + if (view.GetViewType() == UI_IMAGE_VIEW) { + UIImageView* img = static_cast(&view); + img->SetSrc(imgInverseInfo_); + } + return true; +} + +void UITestIcosahedron::SetUp() +{ + if (imgInfo_ == nullptr) { + imgInfo_ = ImageCacheManager::GetInstance().LoadSingleRes(RES_PATH"regular_hexagon.bin"); + if (imgInfo_ == nullptr) { + return; + } + } + if (imgInverseInfo_ == nullptr) { + imgInverseInfo_ = ImageCacheManager::GetInstance().LoadSingleRes(RES_PATH"regular_hexagon_inverse.bin"); + if (imgInverseInfo_ == nullptr) { + return; + } + } + + if (container_ == nullptr) { + container_ = new UIIcosahedronView(); + container_->SetThrowDrag(true); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetDefaultImage(imgInverseInfo_); + container_->SetLuminanceFactor(2); // 2: Twice as bright + for (uint8_t i = 0; i < PLANES_NUM - 5; i++) { // 5: Reduce the quantity and test the default image. + UIImageView* view = new UIImageView(); + view->SetTouchable(true); + view->SetOnClickListener(this); + view->SetSrc(imgInfo_); + container_->Add(view); + } + if (callback_ == nullptr) { + callback_ = new EntryAnimatorCallback(container_, 30, 200); // 30: Initial Size 200: Final display size + } + enterAnimator_ = callback_->GetAnimator(); + } +} + +void UITestIcosahedron::TearDown() +{ + if (container_ != nullptr) { + DeleteChildren(container_); + container_ = nullptr; + } + if (imgInfo_ != nullptr) { + ImageCacheManager::GetInstance().UnloadSingleRes(RES_PATH"regular_hexagon.bin"); + imgInfo_ = nullptr; + } + if (imgInverseInfo_ != nullptr) { + ImageCacheManager::GetInstance().UnloadSingleRes(RES_PATH"regular_hexagon_inverse.bin"); + imgInverseInfo_ = nullptr; + } + if (callback_ != nullptr) { + delete callback_; + callback_ = nullptr; + } +} + +const UIView* UITestIcosahedron::GetTestView() +{ + enterAnimator_->Start(); + return container_; +} +} \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_icosahedron/ui_test_icosahedron.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_icosahedron/ui_test_icosahedron.h new file mode 100644 index 000000000..8a202a08d --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_icosahedron/ui_test_icosahedron.h @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UI_TEST_ICOSAHEDRON_H +#define UI_TEST_ICOSAHEDRON_H + +#include "ui_test.h" +#include "components/ui_icosahedron_view.h" +#include "components/ui_image_view.h" +#include "animator/animator_manager.h" + +namespace OHOS { +class EntryAnimatorCallback : public AnimatorCallback { +public: + explicit EntryAnimatorCallback(UIView* view, int16_t startPos, int16_t endPos) + : startPos_(startPos), + endPos_(endPos), + animator_(new Animator(this, view, 1000, false)) {} // 1000:duration of animator_, in milliseconds. + + ~EntryAnimatorCallback() override + { + if (animator_ != nullptr) { + delete animator_; + animator_ = nullptr; + } + } + + void Callback(UIView* view) override; + + Animator* GetAnimator() const + { + return animator_; + } + +protected: + int16_t startPos_; + int16_t endPos_; + Animator* animator_; +}; + +class UITestIcosahedron : public UITest, public UIView::OnClickListener { +public: + UITestIcosahedron() {} + ~UITestIcosahedron() override {} + void SetUp() override; + void TearDown() override; + const UIView* GetTestView() override; + bool OnClick(UIView& view, const ClickEvent& event) override; + +private: + UIIcosahedronView* container_ = nullptr; + ImageInfo* imgInfo_ = nullptr; + ImageInfo* imgInverseInfo_ = nullptr; + EntryAnimatorCallback* callback_ = nullptr; + Animator* enterAnimator_ = nullptr; +}; +} +#endif // UI_TEST_ICOSAHEDRON_H \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_list_ext/menu_item_adapter.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_list_ext/menu_item_adapter.cpp index f8eb0d962..d91670d36 100644 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_list_ext/menu_item_adapter.cpp +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_list_ext/menu_item_adapter.cpp @@ -145,7 +145,6 @@ UIView* MenuItemAdapter::GetView(UIView* inView, int16_t index) item->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); item->SetImgResizeMode(UIImageView::ImageResizeMode::CENTER); item->SetFont(fontName_, fontSize_); - item->SetAlign(TEXT_ALIGNMENT_CENTER); item->SetScaleAlignMode(UIMenuItem::ScaleAlignMode::ALIGN_ITEM_CENTER); item->SetLineBreakMode(UILabel::LineBreakMode::LINE_BREAK_MARQUEE); } else { @@ -158,6 +157,7 @@ UIView* MenuItemAdapter::GetView(UIView* inView, int16_t index) } item->SetImageSrc(node->data_->imgInfo); item->SetText(node->data_->txt); + item->SetAlign(TEXT_ALIGNMENT_CENTER); item->SetViewIndex(index); } return item; diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_roller_view/ui_test_roller_view.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_roller_view/ui_test_roller_view.cpp index c05ad0b60..12c280aad 100644 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_roller_view/ui_test_roller_view.cpp +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_roller_view/ui_test_roller_view.cpp @@ -15,14 +15,18 @@ struct RollerItemStruct { ImageInfo* info; }; -static constexpr uint8_t ITEM_CNT = 6; +static constexpr uint8_t ITEM_CNT = 10; static RollerItemStruct g_rollerItems[ITEM_CNT] = { {"planet", RES_PATH"/planet.bin", nullptr}, - {"kaleidoscope", RES_PATH"/kaleidoscope.bin", nullptr}, - {"rainbow", RES_PATH"/rainbow.bin", nullptr}, {"kaleidoscope1", RES_PATH"/kaleidoscope.bin", nullptr}, - {"planet1", RES_PATH"/planet.bin", nullptr}, - {"rainbow1", RES_PATH"/rainbow.bin", nullptr}, + {"kaleidoscope2", RES_PATH"/kaleidoscope.bin", nullptr}, + {"kaleidoscope3", RES_PATH"/kaleidoscope.bin", nullptr}, + {"kaleidoscope4", RES_PATH"/kaleidoscope.bin", nullptr}, + {"kaleidoscope5", RES_PATH"/kaleidoscope.bin", nullptr}, + {"kaleidoscope6", RES_PATH"/kaleidoscope.bin", nullptr}, + {"kaleidoscope7", RES_PATH"/kaleidoscope.bin", nullptr}, + {"kaleidoscope8", RES_PATH"/kaleidoscope.bin", nullptr}, + {"rainbow", RES_PATH"/rainbow.bin", nullptr} }; void UITestRollerView::CreateButton(UILabelButton*& button, const char* text, int16_t x, int16_t y) @@ -35,8 +39,28 @@ void UITestRollerView::CreateButton(UILabelButton*& button, const char* text, in container_->Add(button); } +void UITestRollerView::CreateNoMirrorRollerView() +{ + noMirrorRollerView_ = new UIRollerView(false); + noMirrorRollerView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + noMirrorRollerView_->SetItemSize(150, 150); // 150: item size + noMirrorRollerView_->SetThrowDrag(true); + noMirrorRollerView_->SetItemPadding(80); // 80: item padding + noMirrorRollerView_->SetCamDistance(380); // 380: Camer distance + noMirrorRollerView_->SetCamY(48); // 48: Camer Y position + for (uint8_t i = 0; i < ITEM_CNT; i++) { + if (g_rollerItems[i].info == nullptr) { + g_rollerItems[i].info = ImageCacheManager::GetInstance().LoadSingleRes(g_rollerItems[i].path); + } + noMirrorRollerView_->AddItem(g_rollerItems[i].name, g_rollerItems[i].info); + } + noMirrorRollerView_->SetCurrentItem("rainbow", false); +} + void UITestRollerView::SetUp() { + CreateNoMirrorRollerView(); + container_ = new UIViewGroup(); container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); container_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); @@ -48,7 +72,7 @@ void UITestRollerView::SetUp() rollerView_->SetThrowDrag(true); rollerView_->SetItemPadding(80); // 80: item padding container_->Add(rollerView_); - + curRollerView_ = rollerView_; for (uint8_t i = 0; i < ITEM_CNT; i++) { if (g_rollerItems[i].info == nullptr) { g_rollerItems[i].info = ImageCacheManager::GetInstance().LoadSingleRes(g_rollerItems[i].path); @@ -56,7 +80,7 @@ void UITestRollerView::SetUp() rollerView_->AddItem(g_rollerItems[i].name, g_rollerItems[i].info); } - rollerView_->SetCurrentItem("rainbow1", false); + rollerView_->SetCurrentItem("rainbow", false); rollerView_->SetOnClickListener(this); rollerView_->SetOnModeChangeListener(this); @@ -66,6 +90,7 @@ void UITestRollerView::SetUp() CreateButton(alignBtn_, "align", 60, 370); // 60, 370: x y CreateButton(switchAnimBtn_, "switchAnim", 180, 370); // 180, 370: x y CreateButton(switchBtn_, "switch", 300, 370); // 300, 370: x y + CreateButton(offMirrorBtn_, "offMirror", 180, 420); // 180, 420: x y } void UITestRollerView::HideOrShowBtn() @@ -77,6 +102,7 @@ void UITestRollerView::HideOrShowBtn() alignBtn_->SetVisible(isVisible); switchAnimBtn_->SetVisible(isVisible); switchBtn_->SetVisible(isVisible); + offMirrorBtn_->SetVisible(isVisible); isBtnVisible_ = isVisible; } void UITestRollerView::OnModeChange(UIRollerView* view, RollerViewMode targetMode) @@ -107,7 +133,7 @@ bool UITestRollerView::OnClick(UIView& view, const ClickEvent& event) rollerView_->ClearAll(); } else if (&view == alignBtn_) { printf("Align kaleidoscope."); - rollerView_->SetCurrentItem("kaleidoscope", true); + rollerView_->SetCurrentItem("kaleidoscope5", true); } else if (&view == switchBtn_) { RollerViewMode mode = rollerView_->GetMode(); RollerViewMode setMode = (mode == DISPLAY) ? COVER : DISPLAY; @@ -116,15 +142,32 @@ bool UITestRollerView::OnClick(UIView& view, const ClickEvent& event) RollerViewMode mode = rollerView_->GetMode(); RollerViewMode setMode = (mode == DISPLAY) ? COVER : DISPLAY; rollerView_->SetMode(setMode, true); + } else if (&view == offMirrorBtn_) { + if (curRollerView_ == rollerView_) { + container_->Remove(rollerView_); + container_->Insert(nullptr, noMirrorRollerView_); + curRollerView_ = noMirrorRollerView_; + } else { + container_->Remove(noMirrorRollerView_); + container_->Insert(nullptr, rollerView_); + curRollerView_ = rollerView_; + } } return true; } void UITestRollerView::TearDown() { - container_->Remove(rollerView_); + if (curRollerView_ == rollerView_) { + container_->Remove(rollerView_); + } else { + container_->Remove(noMirrorRollerView_); + } + curRollerView_ = nullptr; delete rollerView_; + delete noMirrorRollerView_; rollerView_ = nullptr; + noMirrorRollerView_ = nullptr; DeleteChildren(container_); removeCurrentBtn_ = nullptr; @@ -134,7 +177,7 @@ void UITestRollerView::TearDown() switchAnimBtn_ = nullptr; switchBtn_ = nullptr; container_ = nullptr; - + offMirrorBtn_ = nullptr; isBtnVisible_ = false; } diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_roller_view/ui_test_roller_view.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_roller_view/ui_test_roller_view.h index cfcbf33a3..480ae6039 100644 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_roller_view/ui_test_roller_view.h +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_roller_view/ui_test_roller_view.h @@ -23,17 +23,18 @@ public: private: void CreateButton(UILabelButton*& button, const char* text, int16_t x, int16_t y); void HideOrShowBtn(); - + void CreateNoMirrorRollerView(); UIViewGroup* container_ = nullptr; UIRollerView* rollerView_ = nullptr; - + UIRollerView* noMirrorRollerView_ = nullptr; + UIRollerView* curRollerView_ = nullptr; UILabelButton* removeCurrentBtn_ = nullptr; UILabelButton* addBackBtn_ = nullptr; UILabelButton* clearBtn_ = nullptr; UILabelButton* alignBtn_ = nullptr; UILabelButton* switchAnimBtn_ = nullptr; UILabelButton* switchBtn_ = nullptr; - + UILabelButton* offMirrorBtn_ = nullptr; bool isBtnVisible_ = false; }; } diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/scale_item_adapter.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/scale_item_adapter.cpp new file mode 100644 index 000000000..dff318e6e --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/scale_item_adapter.cpp @@ -0,0 +1,232 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "scale_item_adapter.h" +#include "common/image_cache_manager.h" +#include "components/ui_transform_group.h" +#include "components/ui_image_view.h" +#include "components/ui_label_ext.h" +#include "graphic_config.h" +#include "ui_test_list_fps/ui_list_fps_res.h" +#include "securec.h" + +namespace OHOS { +class ItemContainer : public UITransformGroup { +public: + ItemContainer() : image_(nullptr), label_(nullptr) + { + SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + } + + ~ItemContainer() override + { + RemoveAll(); + if (image_ != nullptr) { + delete image_; + image_ = nullptr; + } + if (label_ != nullptr) { + delete label_; + label_ = nullptr; + } + } + + bool InitContainer() + { + if (image_ == nullptr) { + image_ = new UIImageView(); + if (image_ == nullptr) { + return false; + } + } + image_->SetResizeMode(UIImageView::ImageResizeMode::CENTER); + + if (label_ == nullptr) { + label_ = new UILabelExt(); + if (label_ == nullptr) { + delete image_; + image_ = nullptr; + return false; + } + } + label_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + label_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); // 40: item font size + + Add(label_); + Add(image_); + return true; + } + + UIImageView* GetImageView() + { + return image_; + } + + UILabelExt* GetLabelView() + { + return label_; + } + + ItemContainer(const ItemContainer &) = delete; + ItemContainer &operator=(const ItemContainer &) = delete; +private: + UIImageView* image_; + UILabelExt* label_; +}; + +ScaleItemAdapter::~ScaleItemAdapter() +{ + ClearData(); +} + +uint16_t ScaleItemAdapter::GetCount() +{ + return nodeList_.Size(); +} + +void ScaleItemAdapter::ClearData() +{ + ListNode* node = nodeList_.Begin(); + while (node != nodeList_.End()) { + if (node->data_ != nullptr) { + if (node->data_->txt != nullptr) { + UIFree(node->data_->txt); + node->data_->txt = nullptr; + } + UIFree(node->data_); + node->data_ = nullptr; + } + node = node->next_; + } + ImageCacheManager::GetInstance().UnloadAllInMultiRes(LIST_FPS); +} + +void ScaleItemAdapter::FreeNode(ItemDataNode* node) +{ + if (node != nullptr) { + if (node->txt != nullptr) { + UIFree(node->txt); + node->txt = nullptr; + } + UIFree(node); + node = nullptr; + } +} + +void ScaleItemAdapter::SetData(const List* data) +{ + if (data == nullptr) { + return; + } + if (!nodeList_.IsEmpty()) { + ClearData(); + } + ListNode* node = data->Begin(); + while (node != data->End()) { + ItemDataNode* tmpNode = static_cast(UIMalloc(sizeof(ItemDataNode))); + if (tmpNode == nullptr) { + return; + } + + tmpNode->resId = node->data_->resId; + uint32_t len = strlen(node->data_->txt); + tmpNode->txt = static_cast(UIMalloc(len + 1)); + if (tmpNode->txt == nullptr) { + FreeNode(tmpNode); + return; + } + if (memcpy_s(tmpNode->txt, len + 1, node->data_->txt, len) != EOK) { + FreeNode(tmpNode); + return; + } + tmpNode->txt[len] = '\0'; + tmpNode->lineBreakMode = node->data_->lineBreakMode; + tmpNode->imgInfo = nullptr; + + nodeList_.PushBack(tmpNode); + node = node->next_; + } +} + +UIView* ScaleItemAdapter::GetView(UIView* inView, int16_t index) +{ + if (nodeList_.IsEmpty() || index > nodeList_.Size() - 1 || index < 0) { + return nullptr; + } + + ListNode* node = nodeList_.Begin(); + for (uint16_t i = 0; i < index; i++) { + node = node->next_; + } + ItemContainer* item = nullptr; + if (inView == nullptr) { + item = new ItemContainer(); + if (item == nullptr) { + return nullptr; + } + if (!item->InitContainer()) { + delete item; + return nullptr; + } + item->Resize(width_, height_); + + UIImageView* image = item->GetImageView(); + image->SetPosition(imageRect_.GetX(), imageRect_.GetY(), imageRect_.GetWidth(), imageRect_.GetHeight()); + + UILabelExt* label = item->GetLabelView(); + label->SetPosition(labelRect_.GetX(), labelRect_.GetY(), labelRect_.GetWidth(), labelRect_.GetHeight()); + } else { + item = static_cast(inView); + } + + if (item != nullptr) { + if (node->data_->imgInfo == nullptr) { + node->data_->imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(node->data_->resId, LIST_FPS); + } + UIImageView* image = item->GetImageView(); + if (image != nullptr) { + image->SetSrc(node->data_->imgInfo); + } + UILabelExt* label = item->GetLabelView(); + if (label != nullptr) { + label->SetText(node->data_->txt); + label->SetLineBreakMode(node->data_->lineBreakMode); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + } + item->SetViewIndex(index); + } + return item; +} + +void ScaleItemAdapter::ItemResize(uint16_t w, uint16_t h) +{ + width_ = w; + height_ = h; +} + +void ScaleItemAdapter::SetLabelPosition(int16_t x, int16_t y, uint16_t w, uint16_t h) +{ + labelRect_.SetPosition(x, y); + labelRect_.SetWidth(w); + labelRect_.SetHeight(h); +} + +void ScaleItemAdapter::SetImagePosition(int16_t x, int16_t y, uint16_t w, uint16_t h) +{ + imageRect_.SetPosition(x, y); + imageRect_.SetWidth(w); + imageRect_.SetHeight(h); +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/scale_item_adapter.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/scale_item_adapter.h new file mode 100644 index 000000000..bd1c5e97c --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/scale_item_adapter.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef SCALE_ITEM_ADAPTER_H +#define SCALE_ITEM_ADAPTER_H +#include "components/abstract_adapter.h" +#include "gfx_utils/list.h" +#include "gfx_utils/vector.h" + +namespace OHOS { +struct ItemDataNode { + int resId; + char* txt; + uint8_t lineBreakMode; + ImageInfo* imgInfo; +}; + +class ScaleItemAdapter : public AbstractAdapter { +public: + ScaleItemAdapter() : width_(0), height_(0) {} + ~ScaleItemAdapter() override; + + UIView* GetView(UIView* inView, int16_t index) override; + uint16_t GetCount() override; + void SetData(const List* data); + + void ItemResize(uint16_t w, uint16_t h); + void SetLabelPosition(int16_t x, int16_t y, uint16_t w, uint16_t h); + void SetImagePosition(int16_t x, int16_t y, uint16_t w, uint16_t h); +private: + void ClearData(void); + void FreeNode(ItemDataNode* node); + List nodeList_; + uint16_t width_; + uint16_t height_; + Rect imageRect_; + Rect labelRect_; +}; +} // namespace OHOS +#endif // SCALE_ITEM_ADAPTER_H diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/ui_test_scale_list.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/ui_test_scale_list.cpp new file mode 100644 index 000000000..30cef91da --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/ui_test_scale_list.cpp @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ui_test_scale_list.h" +#include "ui_test_list_fps/ui_list_fps_res.h" +#include "graphic_config.h" +#include "securec.h" + +namespace OHOS { +static const int16_t LIST_WIDTH = 454; +static const int16_t LIST_HEIGHT = 454; +static const uint16_t ITEM_WIDTH = 400; +static const uint16_t ITEM_HEIGHT = 100; +static const uint16_t IMAGE_WIDTH = 100; +static const uint16_t IMAGE_HEIGHT = 100; +static const uint16_t LABEL_WIDTH = 350; +static const uint16_t LABEL_HEIGHT = 100; +static const uint16_t SCALE_FACTOR = 400; +static ItemDataNode g_itemNode[] = { + {APPLIST_ALARM, "闹钟", UILabel::LINE_BREAK_ELLIPSIS}, + {BLUETOOTH_TITLE, "蓝牙", UILabel::LINE_BREAK_ELLIPSIS}, + {APPLIST_CALLER_IMAGE, "通话记录", UILabel::LINE_BREAK_ELLIPSIS}, + {APPLIST_COMPASS_IMAGE, "指南针", UILabel::LINE_BREAK_ELLIPSIS}, + {APPLIST_SETTING, "设置", UILabel::LINE_BREAK_ELLIPSIS}, + {APPLIST_SPO2, "血氧饱和度", UILabel::LINE_BREAK_ELLIPSIS}, + {APPLIST_VOCASSIST_IMAGE, "语音助手", UILabel::LINE_BREAK_ELLIPSIS}, + {APPLIST_ALARM, "长文本滚动测试ABCD", UILabel::LINE_BREAK_MARQUEE}, + {APPLIST_ALARM, "闹钟", UILabel::LINE_BREAK_ELLIPSIS}, + {BLUETOOTH_TITLE, "蓝牙", UILabel::LINE_BREAK_ELLIPSIS}, + {APPLIST_CALLER_IMAGE, "通话记录", UILabel::LINE_BREAK_ELLIPSIS}, + {APPLIST_COMPASS_IMAGE, "指南针", UILabel::LINE_BREAK_ELLIPSIS} +}; + +static bool TransformItemBaseOnPosition(UITransformList* list, UIView* item) +{ + if (list == nullptr || item == nullptr) { + return false; + } + if (item->GetViewType() != UI_TRANSFORM_GROUP) { + return false; + } + UITransformGroup* group = dynamic_cast(item); + if (group == nullptr) { + return false; + } + int16_t w = group->GetWidth(); + int16_t h = group->GetHeight(); + if (list->GetDirection() == UIList::VERTICAL) { + int16_t midY = list->GetY() + (list->GetHeight() >> 1); + int16_t y = group->GetY(); + int offset = (y + (h >> 1) - midY); + int temp = EasingEquation::SineEaseIn(0, SCALE_FACTOR, abs(offset), SCALE_FACTOR); + float scale = 1.0 - (static_cast(temp) / SCALE_FACTOR); + group->Scale(Vector2(scale, scale), Vector2(w >> 1, h >> 1)); + if ((y <= midY) && (y + group->GetHeight() >= midY)) { + return true; + } + } + return false; +} + +void UITestScaleList::SetUp() +{ + if (data_ == nullptr) { + data_ = new List(); + if (data_ == nullptr) { + return; + } + for (uint8_t i = 0; i < (sizeof(g_itemNode) / sizeof(ItemDataNode)); ++i) { + data_->PushBack(&g_itemNode[i]); + } + } +} + +void UITestScaleList::TearDown() +{ + if (data_ != nullptr) { + data_->Clear(); + delete data_; + data_ = nullptr; + } + if (adapter_ != nullptr) { + delete adapter_; + adapter_ = nullptr; + } + if (list_ != nullptr) { + delete list_; + list_ = nullptr; + } +} + +UIView* UITestScaleList::GetTestView() +{ + UIScaleListTest(); + return list_; +} + +void UITestScaleList::UIScaleListTest() +{ + adapter_ = new ScaleItemAdapter(); + if (adapter_ == nullptr) { + TearDown(); + return; + } + adapter_->ItemResize(ITEM_WIDTH, ITEM_HEIGHT); + adapter_->SetLabelPosition(IMAGE_WIDTH, 0, LABEL_WIDTH, LABEL_HEIGHT); + adapter_->SetImagePosition(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT); + adapter_->SetData(data_); + + if (list_ == nullptr) { + list_ = new UITransformList(); + } + list_->SetPosition(0, 0, LIST_WIDTH, LIST_HEIGHT); + list_->SetItemTransformFunc(&TransformItemBaseOnPosition); + list_->SetAdapter(adapter_); + list_->SetThrowDrag(true); + list_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + list_->SetMaxScrollDistance(1000); // 1000: max scroll distance + list_->SetSwipeACCLevel(800); // 800: compensation distance + list_->SetDragACCLevel(5); // 5: drag acceleration + list_->SetYScrollBarVisible(true); +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/ui_test_scale_list.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/ui_test_scale_list.h new file mode 100644 index 000000000..3b5cb1566 --- /dev/null +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_transform_list/ui_test_scale_list.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 CompanyNameMagicTag. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef UI_TEST_SCALEABEL_LIST_H +#define UI_TEST_SCALEABEL_LIST_H + +#include "graphic_config.h" +#include "components/ui_transform_list.h" +#include "ui_test.h" +#include "ui_test_transform_list/scale_item_adapter.h" + +namespace OHOS { +class UITestScaleList : public UITest { +public: + UITestScaleList() : list_(nullptr), data_(nullptr), adapter_(nullptr) {} + ~UITestScaleList() override {} + void SetUp() override; + void TearDown() override; + UIView* GetTestView() override; + void UIScaleListTest(); + +private: + UITransformList* list_; + List* data_; + ScaleItemAdapter* adapter_; +}; +} // namespace OHOS +#endif // UI_TEST_SCALEABEL_LIST_H \ No newline at end of file diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/ui_test_group.cpp b/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/ui_test_group.cpp index 8491893bf..b62122c78 100644 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/ui_test_group.cpp +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/framework/src/ui_test_group.cpp @@ -62,6 +62,7 @@ #if ENABLE_ICU && ENABLE_MULTI_FONT && ENABLE_SHAPING #include "ui_test_font/ui_test_multi_font.h" #endif +#include "ui_test_icosahedron/ui_test_icosahedron.h" #include "ui_test_texture_mapper/ui_test_texture_mapper.h" #include "ui_test_label/ui_test_arc_label.h" #include "ui_test_clock_dial/ui_test_clock_dial.h" @@ -78,8 +79,10 @@ #include "ui_test_cross/ui_test_cross.h" #include "ui_test_map/ui_test_map.h" #include "ui_test_coverflow/ui_test_coverflow.h" +#include "ui_test_coverflow/ui_test_coverflow2.h" #include "ui_test_kaleidoscope/ui_test_kaleidoscope.h" #include "ui_test_roller_view/ui_test_roller_view.h" +#include "ui_test_transform_list/ui_test_scale_list.h" namespace OHOS { void UITestGroup::AddTestCase(TestCaseInfo testCaseInfo) @@ -101,8 +104,9 @@ void UITestGroup::SetUpTestCase() #ifndef QSPI_DISPLAY testCaseList_->PushBack(TestCaseInfo{"蜂窝表盘", new UITestHexagonsList()}); #endif - testCaseList_->PushBack(TestCaseInfo{"滑动列表", new UITestListFPS()}); - testCaseList_->PushBack(TestCaseInfo{"缩放型滑动列表", new UITestListExt()}); + testCaseList_->PushBack(TestCaseInfo{"无变换滑动列表", new UITestListFPS()}); + testCaseList_->PushBack(TestCaseInfo{"带缩放滑动列表", new UITestListExt()}); + testCaseList_->PushBack(TestCaseInfo{"自定义变换滑动列表", new UITestScaleList()}); testCaseList_->PushBack(TestCaseInfo{"扫秒", new UITestSweepClock()}); testCaseList_->PushBack(TestCaseInfo{"指南针", new UITestCompass()}); testCaseList_->PushBack(TestCaseInfo{"界面切换", new UITestClockDial()}); @@ -120,6 +124,7 @@ void UITestGroup::SetUpTestCase() #if !defined(_WIN32) testCaseList_->PushBack(TestCaseInfo{"万花筒", new UITestKaleidoscope()}); #endif + testCaseList_->PushBack(TestCaseInfo{"容器覆盖流", new UITestCoverflow2()}); testCaseList_->PushBack(TestCaseInfo{"覆盖流", new UITestCoverflow()}); #endif testCaseList_->PushBack(TestCaseInfo{"滚筒", new UITestRollerView()}); @@ -131,6 +136,7 @@ void UITestGroup::SetUpTestCase() testCaseList_->PushBack(TestCaseInfo{"绘制SVG", new UITestSVG()}); #endif #endif + testCaseList_->PushBack(TestCaseInfo{"足球效果", new UITestIcosahedron()}); #if ENABLE_ICU && ENABLE_MULTI_FONT && ENABLE_SHAPING testCaseList_->PushBack(TestCaseInfo{"多语言混排", new UITestMultiFont()}); #endif diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/animator/animator.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/animator/animator.cpp index 5d750742b..24e17a220 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/animator/animator.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/animator/animator.cpp @@ -17,6 +17,7 @@ #include "animator/animator_manager.h" #include "hal_tick.h" +#include "common/low_power_manager.h" namespace OHOS { Animator::~Animator() @@ -26,6 +27,7 @@ Animator::~Animator() void Animator::Start() { + LowPowerManager::GetInstance()->ExitLowPower(); SetState(START); runTime_ = 0; lastRunTime_ = HALTick::GetInstance().GetTime(); diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/root_view.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/root_view.cpp index d87f0f51a..cc3f5a0c9 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/root_view.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/root_view.cpp @@ -802,7 +802,9 @@ void RootView::DrawTop(UIView* view, const Rect& rect) #if ENABLE_MAP_BUFFER if ((curView->GetViewType() != UI_IMAGE_VIEW) && (curView->GetViewType() != UI_TEXTURE_MAPPER) && (curView->GetViewType() != UI_CANVAS_EXT) && (curView->GetViewType() != UI_MENU_ITEM) && - (curView->GetViewType() != UI_MAP_VIEW) && !curView->IsTransInvalid() && !enableAnimator) { + (curView->GetViewType() != UI_MAP_VIEW) && (curView->GetViewType() != UI_LABEL_EXT) && + (curView->GetViewType() != UI_LABEL) && (curView->GetViewType() != UI_TRANSFORM_GROUP) && + !curView->IsTransInvalid() && !enableAnimator) { origRect = curView->GetOrigRect(); relativeRect = curView->GetRelativeRect(); curView->GetTransformMap().SetInvalid(true); diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_arc_label.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_arc_label.cpp index da9e2d9e5..b20349295 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_arc_label.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_arc_label.cpp @@ -129,6 +129,25 @@ void UIArcLabel::OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) DrawArcText(gfxDstBuffer, trunc, opa); } +std::string UIArcLabel::GetGuiInfo() const +{ + if (arcLabelText_ == nullptr) { + return ""; + } + const size_t size = 256; + char *buf = new char[size]; + + if (buf == nullptr) { + return ""; + } + memset_s(buf, size, 0, size); + sprintf_s(buf, size, "text: %s, start angle: %f, end angle %f, radius: %u, center[%d, %d]", + arcLabelText_->GetText(), startAngle_, endAngle_, radius_, arcCenter_.x, arcCenter_.y); + std::string res(buf); + delete []buf; + return res; +} + void UIArcLabel::DrawArcText(BufferInfo& gfxDstBuffer, const Rect& mask, OpacityType opaScale) { Point center; diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_view.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_view.cpp index 5b2af86c0..6402c36b9 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_view.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_image_view.cpp @@ -577,6 +577,27 @@ void UIImageView::DumpImgInfo() } } +std::string UIImageView::GetGuiInfo() const +{ + const size_t size = 256; + char *buf = new char[size]; + if (buf == nullptr) { + return ""; + } + if (image_.GetSrcType() == IMG_SRC_VARIABLE && buf != nullptr) { + memset_s(buf, size, 0, size); + const ImageInfo* info = image_.GetImageInfo(); + sprintf_s(buf, size, "ImgInfo[%p]: size = [%d, %d], fmt = %d, data = %p, dataSize = %d, cacheNode = %p", + info, info->header.width, info->header.height, + info->header.colorMode, info->data, info->dataSize, info->cacheNode); + std::string res(buf); + delete []buf; + return res; + } + delete []buf; + return ""; +} + #ifndef VERSION_LITE void UIImageView::AddAndStartGifAnimator() { diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_label.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_label.cpp index d64c95439..0fa53ac70 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_label.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_label.cpp @@ -334,6 +334,13 @@ void UILabel::SetHeight(int16_t height) } } +void UILabel::SetTextTransformMap(TransformMap& transMap) +{ + InitLabelText(); + labelText_->SetTransformMap(transMap); + SetTransformMap(transMap); +} + void UILabel::RefreshLabel() { Invalidate(); @@ -387,15 +394,34 @@ void UILabel::ReMeasure() } } +std::string UILabel::GetGuiInfo() const +{ + const size_t size = 256; + char *buf = new char[size]; + if (buf == nullptr) { + return ""; + } + if (labelText_ == nullptr) { + delete []buf; + return ""; + } + memset_s(buf, size, 0, size); + sprintf_s(buf, size, "text: %s, breakmode %u, font id: %u", + labelText_->GetText(), lineBreakMode_, labelText_->GetFontId()); + std::string res(buf); + delete []buf; + return res; +} + void UILabel::RemeasureForAnimation(int16_t textWidth, LineBreakMode mode) { int16_t rectWidth = GetWidth(); if (textWidth > rectWidth) { offsetX_ = GetRollStartPos(); if (labelText_->GetDirect() == TEXT_DIRECT_RTL) { - labelText_->SetAlign(TEXT_ALIGNMENT_RIGHT); + labelText_->SetAlign(TEXT_ALIGNMENT_RIGHT, labelText_->GetVerAlign()); } else { - labelText_->SetAlign(TEXT_ALIGNMENT_LEFT); + labelText_->SetAlign(TEXT_ALIGNMENT_LEFT, labelText_->GetVerAlign()); } if (hasAnimator_) { static_cast(animator_.animator)->UpdateWidth(textWidth, rectWidth); diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp index cfd695a8f..242f67e9a 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp @@ -212,22 +212,6 @@ bool UIList::OnDragEvent(const DragEvent& event) bool UIList::OnDragEndEvent(const DragEvent& event) { - if (isElastic_ && (reboundSize_ > 0)) { - bool elasticFlag = false; - if (direction_ == HORIZONTAL) { - elasticFlag = (childrenHead_->GetX() > 0) || - (childrenTail_->GetX() + childrenTail_->GetRelativeRect().GetWidth() < GetWidth()); - } else { - elasticFlag = (childrenHead_->GetY() > 0) || - (childrenTail_->GetY() + childrenTail_->GetRelativeRect().GetHeight() < GetHeight()); - } - if (elasticFlag) { - ElasticAnimator(elasticTime_ / DEFAULT_TASK_PERIOD); - return true; - } - accumulatedSize_ = 0; - } - Point last = event.GetPreLastPoint(); Point current = event.GetLastPoint(); if ((last.x == current.x) && (last.y == current.y)) { @@ -305,38 +289,44 @@ bool UIList::DragXInner(int16_t distance) if (isLoopList_) { return MoveOffset(distance, 0); } - if (isElastic_ && (reboundSize_ > 0) && - (((childrenHead_->GetX() >= 0) && (distance > 0)) || - ((childrenTail_->GetX() + childrenTail_->GetRelativeRect().GetWidth() <= listWidth) && (distance < 0)))) { - int16_t elasticLen = childrenHead_->GetX(); - if (distance < 0) { - elasticLen = listWidth - (childrenTail_->GetX() + childrenTail_->GetRelativeRect().GetWidth()); - } - accumulatedSize_ += distance; - distance = CalculateElasticDragLen(reboundSize_ + scrollBlankSize_, elasticLen, accumulatedSize_); - if (distance != 0) { - accumulatedSize_ = 0; - } - } else { - if (distance > 0) { - if (childrenHead_ && ((childrenHead_->GetX() + distance) > - (scrollBlankSize_ + reboundSize + childrenHead_->GetStyle(STYLE_MARGIN_LEFT)))) { + + if (distance > 0) { + if (childrenHead_ != nullptr) { + if (isElastic_ && (reboundSize > 0) && + (childrenHead_->GetX() > (scrollBlankSize_ + childrenHead_->GetStyle(STYLE_MARGIN_LEFT)))) { + int16_t offset = childrenHead_->GetX() - (scrollBlankSize_ + childrenHead_->GetStyle(STYLE_MARGIN_LEFT)); + if (offset > reboundSize) { + offset = reboundSize; + } + distance = CalculateElasticDragLen(reboundSize, offset, distance); + } + + if ((childrenHead_->GetX() + distance) > + (scrollBlankSize_ + reboundSize + childrenHead_->GetStyle(STYLE_MARGIN_LEFT))) { distance = scrollBlankSize_ + reboundSize + childrenHead_->GetStyle(STYLE_MARGIN_LEFT) - childrenHead_->GetX(); } - } else { - if (childrenTail_) { - if (childrenTail_->GetRelativeRect().GetRight() <= - (listWidth - scrollBlankSize_ - reboundSize - childrenTail_->GetStyle(STYLE_MARGIN_RIGHT))) { - distance = 0; - } else if ((listWidth - childrenTail_->GetX() - childrenTail_->GetRelativeRect().GetWidth() - distance) > - (scrollBlankSize_ + reboundSize + childrenTail_->GetStyle(STYLE_MARGIN_RIGHT))) { - distance = listWidth - scrollBlankSize_ - reboundSize - childrenTail_->GetX() - - childrenTail_->GetRelativeRect().GetWidth() - childrenTail_->GetStyle(STYLE_MARGIN_RIGHT); + } + } else { + if (childrenTail_ != nullptr) { + if (isElastic_ && (reboundSize > 0) && + (childrenTail_->GetRelativeRect().GetRight() < + (listWidth - scrollBlankSize_ - childrenTail_->GetStyle(STYLE_MARGIN_RIGHT)))) { + int16_t offset = (listWidth - scrollBlankSize_ - childrenTail_->GetStyle(STYLE_MARGIN_RIGHT)) + - (childrenTail_->GetRelativeRect().GetRight()); + if (offset > reboundSize) { + offset = reboundSize; } + distance = CalculateElasticDragLen(reboundSize, offset, distance); + } + if ((childrenTail_->GetRelativeRect().GetRight() + distance) < + (listWidth - scrollBlankSize_ - reboundSize - childrenTail_->GetStyle(STYLE_MARGIN_RIGHT))) { + distance = listWidth - scrollBlankSize_ - reboundSize - childrenTail_->GetStyle(STYLE_MARGIN_RIGHT) + - childrenTail_->GetRelativeRect().GetRight(); } } } + return MoveOffset(distance, 0); } @@ -361,37 +351,43 @@ bool UIList::DragYInner(int16_t distance) if (isLoopList_) { return MoveOffset(0, distance); } - if (isElastic_ && (reboundSize_ > 0) && (((childrenHead_->GetY() >= 0) && (distance > 0)) || - ((childrenTail_->GetY() + childrenTail_->GetRelativeRect().GetHeight() <= listHeight) && (distance < 0)))) { - int16_t elasticLen = childrenHead_->GetY(); - if (distance < 0) { - elasticLen = listHeight - (childrenTail_->GetY() + childrenTail_->GetRelativeRect().GetHeight()); - } - accumulatedSize_ += distance; - distance = CalculateElasticDragLen(reboundSize + scrollBlankSize_, elasticLen, accumulatedSize_); - if (distance != 0) { - accumulatedSize_ = 0; - } - } else { - if (distance > 0) { - if (childrenHead_ && ((childrenHead_->GetY() + distance) > - (scrollBlankSize_ + reboundSize + childrenHead_->GetStyle(STYLE_MARGIN_TOP)))) { + + if (distance > 0) { + if (childrenHead_ != nullptr) { + if (isElastic_ && (reboundSize > 0) && + (childrenHead_->GetY() > (scrollBlankSize_ + childrenHead_->GetStyle(STYLE_MARGIN_TOP)))) { + int16_t offset = childrenHead_->GetY() - (scrollBlankSize_ + childrenHead_->GetStyle(STYLE_MARGIN_TOP)); + if (offset > reboundSize) { + offset = reboundSize; + } + distance = CalculateElasticDragLen(reboundSize, offset, distance); + } + if ((childrenHead_->GetY() + distance) > + (scrollBlankSize_ + reboundSize + childrenHead_->GetStyle(STYLE_MARGIN_TOP))) { distance = scrollBlankSize_ + reboundSize + childrenHead_->GetStyle(STYLE_MARGIN_TOP) - childrenHead_->GetY(); } - } else { - if (childrenTail_) { - if (childrenTail_->GetRelativeRect().GetBottom() <= - (listHeight - scrollBlankSize_ - reboundSize - childrenTail_->GetStyle(STYLE_MARGIN_BOTTOM))) { - distance = 0; - } else if ((listHeight - childrenTail_->GetY() - childrenTail_->GetRelativeRect().GetHeight() - distance) > - (scrollBlankSize_ + reboundSize + childrenTail_->GetStyle(STYLE_MARGIN_BOTTOM))) { - distance = listHeight - scrollBlankSize_ - reboundSize - childrenTail_->GetY() - - childrenTail_->GetRelativeRect().GetHeight() - childrenTail_->GetStyle(STYLE_MARGIN_BOTTOM); + } + } else { + if (childrenTail_ != nullptr) { + if (isElastic_ && (reboundSize > 0) && + (childrenTail_->GetRelativeRect().GetBottom() < + (listHeight - scrollBlankSize_ - childrenTail_->GetStyle(STYLE_MARGIN_BOTTOM)))) { + int16_t offset = (listHeight - scrollBlankSize_ - childrenTail_->GetStyle(STYLE_MARGIN_BOTTOM)) + - (childrenTail_->GetRelativeRect().GetBottom()); + if (offset > reboundSize) { + offset = reboundSize; } + distance = CalculateElasticDragLen(reboundSize, offset, distance); + } + if ((childrenTail_->GetRelativeRect().GetBottom() + distance) < + (listHeight - scrollBlankSize_ - reboundSize - childrenTail_->GetStyle(STYLE_MARGIN_BOTTOM))) { + distance = listHeight - scrollBlankSize_ - reboundSize - childrenTail_->GetStyle(STYLE_MARGIN_BOTTOM) + - childrenTail_->GetRelativeRect().GetBottom(); } } } + return MoveOffset(0, distance); } @@ -441,6 +437,7 @@ bool UIList::IsNeedReCalculateDragEnd() } return true; } + bool UIList::ReCalculateDragEnd() { if ((onSelectedView_ == nullptr) || isReCalculateDragEnd_ || !autoAlign_) { @@ -881,6 +878,25 @@ void UIList::FixDistance(int16_t& distanceX, int16_t& distanceY) void UIList::FixHorDistance(int16_t& distanceX) { + int16_t ofs = 0; + Rect childrenRect = GetAllChildRelativeRect(); + if (childrenRect.GetX() > 0) { + int16_t headMid = childrenHead_->GetX() + childrenHead_->GetRelativeRect().GetWidth() / 2; + if ((headMid + distanceX >= selectPosition_) || (headMid >= selectPosition_)) { + ofs = selectPosition_ - (headMid + distanceX); + } + } else if (childrenRect.GetRight() < GetWidth() - 1) { + int16_t tailMid = childrenTail_->GetX() + childrenTail_->GetRelativeRect().GetWidth() / 2; + if ((tailMid + distanceX <= selectPosition_) || (tailMid <= selectPosition_)) { + ofs = selectPosition_ - (tailMid + distanceX); + } + } + + if (ofs != 0) { + distanceX += ofs; + return; + } + UIView* targetView = childrenHead_; while (targetView != nullptr) { int16_t pos = targetView->GetX(); @@ -901,6 +917,25 @@ void UIList::FixHorDistance(int16_t& distanceX) void UIList::FixVerDistance(int16_t& distanceY) { + int16_t ofs = 0; + Rect childrenRect = GetAllChildRelativeRect(); + if (childrenRect.GetY() > 0) { + int16_t headMid = childrenHead_->GetY() + childrenHead_->GetRelativeRect().GetHeight() / 2; + if ((headMid + distanceY >= selectPosition_) || (headMid >= selectPosition_)) { + ofs = selectPosition_ - (headMid + distanceY); + } + } else if (childrenRect.GetBottom() < GetHeight() - 1) { + int16_t tailMid = childrenTail_->GetY() + childrenTail_->GetRelativeRect().GetHeight() / 2; + if ((tailMid + distanceY <= selectPosition_) || (tailMid <= selectPosition_)) { + ofs = selectPosition_ - (tailMid + distanceY); + } + } + + if (ofs != 0) { + distanceY += ofs; + return; + } + UIView* targetView = childrenHead_; while (targetView != nullptr) { int16_t pos = targetView->GetY(); diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view.cpp index 3f63d2ea0..247d8886f 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view.cpp @@ -271,15 +271,6 @@ void UIView::Rotate(float angle, const Vector2& pivot) void UIView::Rotate(int16_t angle, const Vector2& pivot) #endif { -#if !ENABLE_MAP_BUFFER - UIViewType type = GetViewType(); - if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW) && - (type != UI_MENU_ITEM)) { - GRAPHIC_LOGE("Rotate is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); - return; - } -#endif - Vector3 pivotStart3D = Vector3(pivot.x_, pivot.y_, 0); Vector3 pivotEnd3D = Vector3(pivot.x_, pivot.y_, 1.0f); Rotate(angle, pivotStart3D, pivotEnd3D); @@ -294,7 +285,7 @@ void UIView::Rotate(int16_t angle, const Vector3& pivotStart, const Vecto #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW) && - (type != UI_MENU_ITEM)) { + (type != UI_MENU_ITEM) && (type != UI_LABEL_EXT) && (type != UI_LABEL) && (type != UI_TRANSFORM_GROUP)) { GRAPHIC_LOGE("Rotate is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } @@ -318,14 +309,6 @@ void UIView::Rotate(int16_t angle, const Vector3& pivotStart, const Vecto void UIView::Scale(const Vector2& scale, const Vector2& pivot) { -#if !ENABLE_MAP_BUFFER - UIViewType type = GetViewType(); - if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW) && - (type != UI_MENU_ITEM)) { - GRAPHIC_LOGE("Scale is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); - return; - } -#endif Vector3 scale3D = Vector3(scale.x_, scale.y_, 1.0f); Vector3 pivot3D = Vector3(pivot.x_, pivot.y_, 0); Scale(scale3D, pivot3D); @@ -336,7 +319,7 @@ void UIView::Scale(const Vector3& scale, const Vector3& pivot) #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW) && - (type != UI_MENU_ITEM)) { + (type != UI_MENU_ITEM) && (type != UI_LABEL_EXT) && (type != UI_LABEL) && (type != UI_TRANSFORM_GROUP)) { GRAPHIC_LOGE("Scale is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } @@ -395,14 +378,6 @@ void UIView::Shear(const Vector2& shearX, const Vector2& shearY, c void UIView::Translate(const Vector2& trans) { -#if !ENABLE_MAP_BUFFER - UIViewType type = GetViewType(); - if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW) && - (type != UI_MENU_ITEM)) { - GRAPHIC_LOGE("Translate is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); - return; - } -#endif Vector3 trans3D = Vector3(trans.x_, trans.y_, 0); Translate(trans3D); } @@ -412,7 +387,7 @@ void UIView::Translate(const Vector3& trans) #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW) && - (type != UI_MENU_ITEM)) { + (type != UI_MENU_ITEM) && (type != UI_LABEL_EXT) && (type != UI_LABEL) && (type != UI_TRANSFORM_GROUP)) { GRAPHIC_LOGE("Translate is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } @@ -810,7 +785,7 @@ void UIView::SetTransformMap(const TransformMap& transMap) #if !ENABLE_MAP_BUFFER UIViewType type = GetViewType(); if ((type != UI_IMAGE_VIEW) && (type != UI_TEXTURE_MAPPER) && (type != UI_CANVAS_EXT) && (type != UI_MAP_VIEW) && - (type != UI_MENU_ITEM)) { + (type != UI_MENU_ITEM) && (type != UI_LABEL) && (type != UI_LABEL_EXT) && (type != UI_TRANSFORM_GROUP)) { GRAPHIC_LOGE("SetTransformMap is not supported for view type %d if ENABLE_MAP_BUFFER is 0", type); return; } @@ -1251,4 +1226,9 @@ void UIView::DumpImgInfoRecursive() } } } + +std::string UIView::GetGuiInfo() const +{ + return ""; +} } // namespace OHOS diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view_group.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view_group.cpp index 5fd45f15b..090a2bdd9 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view_group.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_view_group.cpp @@ -40,7 +40,7 @@ UIViewGroup::~UIViewGroup() {} void UIViewGroup::Add(UIView* view) { if ((view == this) || (view == nullptr)) { - GRAPHIC_LOGE("view can not be nullptr and added to self"); + GRAPHIC_LOGE("view %p can not be nullptr or added to self!", view); return; } if (view->GetParent() != nullptr) { @@ -166,7 +166,7 @@ void UIViewGroup::RemoveAndDeleteAllRecursively(UIViewGroup*& group) GRAPHIC_LOGE("param group is nullptr !!"); return; } - + UIViewType type = group->GetViewType(); if ((type == UI_DIGITAL_CLOCK) || (type == UI_PICKER) || (type == UI_TIME_PICKER) || (type == UI_MENU_ITEM) || (type == UI_IMAGE_PICKER) || (type == UI_ROLLER_VIEW) || (type == UI_COVER_FLOW)) { @@ -174,14 +174,14 @@ void UIViewGroup::RemoveAndDeleteAllRecursively(UIViewGroup*& group) group = nullptr; return; } - + if (type == UI_CROSS_VIEW) { GRAPHIC_LOGE("Need to remove UICardPage in UICrossView manully !!"); delete group; group = nullptr; return; } - + UIView* node = group->GetChildrenHead(); UIView* tmp = nullptr; while (node != nullptr) { diff --git a/code/sdk/middleware/services/gui/uikit/ui/interfaces/innerkits/engines/gfx/gfx_engine_manager.h b/code/sdk/middleware/services/gui/uikit/ui/interfaces/innerkits/engines/gfx/gfx_engine_manager.h index faf11331e..108f3ed84 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/interfaces/innerkits/engines/gfx/gfx_engine_manager.h +++ b/code/sdk/middleware/services/gui/uikit/ui/interfaces/innerkits/engines/gfx/gfx_engine_manager.h @@ -40,6 +40,8 @@ enum BlendMode { BLEND_MULTIPLY, /* S * (1 - Da) + D * (1 - Sa) + S * D */ BLEND_ADDITIVE, /* S + D */ BLEND_SUBTRACT, /* D * (1 - S) */ + BLEND_SRC_ATOP, + BLEND_DST_ATOP, }; #ifndef TRANSFORMOPTION diff --git a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_arc_label.h b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_arc_label.h index eb095a4f7..8217124db 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_arc_label.h +++ b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_arc_label.h @@ -358,6 +358,8 @@ public: UITextLanguageDirect direct; }; + std::string GetGuiInfo() const override; + protected: Text* arcLabelText_; diff --git a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_image_view.h b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_image_view.h index 24c62e790..8a1683abe 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_image_view.h +++ b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_image_view.h @@ -274,6 +274,8 @@ public: void DumpImgInfo() override; + std::string GetGuiInfo() const override; + protected: /** * @brief Represents the width of this image. diff --git a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_label.h b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_label.h index 59dac9ddc..71d3d1318 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_label.h +++ b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_label.h @@ -410,8 +410,19 @@ public: */ void SetHeight(int16_t height) override; + /** + * @brief Sets the transform for this label text. + * + * @param transMap Indicates the transformation matrix. + * @since 1.0 + * @version 1.0 + */ + void SetTextTransformMap(TransformMap& transMap); + void ReMeasure() override; + std::string GetGuiInfo() const override; + #if ENABLE_FONT_VECTOR_GLOBAL virtual void ForceResetText() {}; #endif diff --git a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_list.h b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_list.h index 5620ea86e..4157283fe 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_list.h +++ b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_list.h @@ -392,7 +392,7 @@ public: UIView* onSelectedView_; protected: - static constexpr int16_t RECALCULATE_DRAG_DISTANCE = 10; + static constexpr int16_t RECALCULATE_DRAG_DISTANCE = 0; static constexpr int16_t RECALCULATE_DRAG_TIMES = 10; static constexpr int16_t DEFAULT_ALIGN_TIMES = 100; void StopAnimator() override; diff --git a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_picker.h b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_picker.h index 568c7567b..1ecca2ff8 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_picker.h +++ b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_picker.h @@ -455,6 +455,98 @@ public: { return list_.GetRotateFactor(); } + + /** + * @brief Sets a rotation event listener for the view. + * @param onRotateListener Indicates the pointer to the rotation event listener to set. + * @since 5.0 + * @version 3.0 + */ + void SetOnRotateListener(OnRotateListener* onRotateListener) override + { + list_.SetOnRotateListener(onRotateListener); + } + + /** + * @brief Obtains the rotation event listener for the view. + * @return Returns the rotation event listener. + * @since 5.0 + * @version 3.0 + */ + OnRotateListener*& GetOnRotateListener() override + { + return list_.GetOnRotateListener(); + } +#endif + +#if ENABLE_FOCUS_MANAGER + /** + * @brief 设置视图是否可获焦. + * + * @param focusable 是否可获焦. + * @since 5.0 + * @version 3.0 + */ + void SetFocusable(bool focusable) override + { + list_.SetFocusable(focusable); + } + + /** + * @brief 获取视图是否可获焦. + * + * @return 是否可获焦. + * @since 5.0 + * @version 3.0 + */ + bool IsFocusable() const override + { + return list_.IsFocusable(); + } + + /** + * @brief 组件获焦响应 + * + * @since 5.0 + * @version 3.0 + */ + void Focus() override + { + list_.Focus(); + } + + /** + * @brief 组件失焦响应 + * + * @since 5.0 + * @version 3.0 + */ + void Blur() override + { + list_.Blur(); + } + + /** + * @brief 设置当前视图焦点改变事件监听者. + * @param onFocusListener 焦点改变事件监听者. + * @since 5.0 + * @version 3.0 + */ + void SetOnFocusListener(OnFocusListener* onFocusListener) override + { + list_.SetOnFocusListener(onFocusListener); + } + + /** + * @brief 获取当前视图焦点改变事件监听者. + * @return 焦点改变事件监听者. + * @since 5.0 + * @version 3.0 + */ + OnFocusListener* GetOnFocusListener() const override + { + return list_.GetOnFocusListener(); + } #endif protected: diff --git a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_view.h b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_view.h index c97493d4a..47df1bd4f 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_view.h +++ b/code/sdk/middleware/services/gui/uikit/ui/interfaces/kits/components/ui_view.h @@ -36,6 +36,8 @@ #ifndef GRAPHIC_LITE_UI_VIEW_H #define GRAPHIC_LITE_UI_VIEW_H +#include +#include "securec.h" #include "events/cancel_event.h" #include "events/click_event.h" #include "events/drag_event.h" @@ -120,6 +122,9 @@ enum UIViewType : uint8_t { UI_HEXAGONS_LIST, UI_IMAGE_PICKER, UI_ICOSAHEDRON_VIEW, + UI_TRANSFORM_GROUP, + UI_TRANSFORM_LIST, + UI_COVER_FLOW_2, UI_NUMBER_MAX }; @@ -428,7 +433,7 @@ public: * @since 5.0 * @version 3.0 */ - void SetOnRotateListener(OnRotateListener* onRotateListener) + virtual void SetOnRotateListener(OnRotateListener* onRotateListener) { onRotateListener_ = onRotateListener; } @@ -439,7 +444,7 @@ public: * @since 5.0 * @version 3.0 */ - OnRotateListener*& GetOnRotateListener() + virtual OnRotateListener*& GetOnRotateListener() { return onRotateListener_; } @@ -1684,7 +1689,7 @@ public: * @since 5.0 * @version 3.0 */ - void SetFocusable(bool focusable) + virtual void SetFocusable(bool focusable) { focusable_ = focusable; } @@ -1696,7 +1701,7 @@ public: * @since 5.0 * @version 3.0 */ - bool IsFocusable() const + virtual bool IsFocusable() const { return focusable_; } @@ -1761,7 +1766,7 @@ public: * @since 5.0 * @version 3.0 */ - void SetOnFocusListener(OnFocusListener* onFocusListener) + virtual void SetOnFocusListener(OnFocusListener* onFocusListener) { onFocusListener_ = onFocusListener; } @@ -1772,7 +1777,7 @@ public: * @since 5.0 * @version 3.0 */ - OnFocusListener* GetOnFocusListener() const + virtual OnFocusListener* GetOnFocusListener() const { return onFocusListener_; } @@ -1802,6 +1807,8 @@ public: virtual void DumpImgInfo() {} + virtual std::string GetGuiInfo() const; + protected: bool touchable_ : 1; bool visible_ : 1; diff --git a/code/sdk/middleware/services/media/foundation/audio_capturer/interfaces/kits/audio_capturer_lite/recording_module.cpp b/code/sdk/middleware/services/media/foundation/audio_capturer/interfaces/kits/audio_capturer_lite/recording_module.cpp index a7c012aeb..023ea294f 100644 --- a/code/sdk/middleware/services/media/foundation/audio_capturer/interfaces/kits/audio_capturer_lite/recording_module.cpp +++ b/code/sdk/middleware/services/media/foundation/audio_capturer/interfaces/kits/audio_capturer_lite/recording_module.cpp @@ -440,7 +440,7 @@ int32_t AudioCaptureStart_sample(int32_t argc, const char **argv) return ERRCODE_FAIL; } - MediaThreadattr attr = { "AudioCaptureTask", 0x2000, THREAD_SCHED_INVALID, 0, true }; + MediaThreadattr attr = { "AudioCaptureTask", 0x2000, THREAD_SCHED_INVALID, 0, false }; g_sample.audioCaptureProcess = MediaThreadCreate(AudioCaptureProcess, NULL, &attr); if (g_sample.audioCaptureProcess == nullptr) { MEDIA_ERR_LOG("thread create failed"); @@ -465,6 +465,8 @@ JSIValue AudioCapturerModule::Start(const JSIValue thisVal, const JSIValue *args JSIValue AudioCapturerModule::Stop(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) { g_sample.needStop = true; + MediaThreadJoin(&g_sample.audioCaptureProcess); + g_sample.audioCaptureProcess = nullptr; return JSI::CreateBoolean(0); } diff --git a/code/sdk/middleware/services/media/foundation/sample/wrapper/video_play_wrapper.cpp b/code/sdk/middleware/services/media/foundation/sample/wrapper/video_play_wrapper.cpp index 207d0af67..89c3399eb 100644 --- a/code/sdk/middleware/services/media/foundation/sample/wrapper/video_play_wrapper.cpp +++ b/code/sdk/middleware/services/media/foundation/sample/wrapper/video_play_wrapper.cpp @@ -417,6 +417,7 @@ int32_t MediaVideoPlay::StartVideoPlay(void) isEntered_ = true; MediaThreadattr attr = { "VideoPlayThread", 0x2000, THREAD_SCHED_INVALID, 0, true }; if (isSyncExitMode_) { + MediaThreadJoin(&threadHandle_); attr.detached = false; } threadHandle_ = MediaThreadCreate(VideoPlayThread, this, &attr); @@ -500,9 +501,7 @@ int32_t MediaVideoPlay::StopVideoPlay(void) MediaMutexLock(mutex_); if (!isPlayed_) { MEDIA_INFO_LOG("video play is not start,can not stop!"); - isPlaybackStopped_ = true; - MediaMutexUnLock(mutex_); - return MEDIA_OK; + goto EXIT; } if (isPlaybackStopped_ || isPlaybackCompleted_ || interruptHintStop_) { if (isLoop_) { @@ -517,6 +516,7 @@ int32_t MediaVideoPlay::StopVideoPlay(void) return MEDIA_OK; } } +EXIT: isPlaybackStopped_ = true; MediaThreadCondSignal(cond_); MediaMutexUnLock(mutex_); @@ -552,6 +552,11 @@ void MediaVideoPlay::SetSyncExitMode(bool isSyncExitMode) void MediaVideoPlay::DestroyVideoPlaySource(void) { if (!isEntered_) { + if (isSyncExitMode_) { + MediaThreadJoin(&threadHandle_); + // clear buffers safely in sync mode to reduce peak memory + dynamic_cast(surface_)->ClearBuffers(); + } MEDIA_ERR_LOG("video is not played\n"); return; } diff --git a/code/sdk/middleware/services/media/foundation/utils/src/media_thread_adapt.cpp b/code/sdk/middleware/services/media/foundation/utils/src/media_thread_adapt.cpp index 97239fa2b..4dfe52f5a 100644 --- a/code/sdk/middleware/services/media/foundation/utils/src/media_thread_adapt.cpp +++ b/code/sdk/middleware/services/media/foundation/utils/src/media_thread_adapt.cpp @@ -294,6 +294,8 @@ static int32_t MediaDoCreateThread(MediaThreadMember *member, const MediaThreada osThreadAttr_t taskAttr = { attr->name, attrBits, nullptr, 0, nullptr, attr->stackSize, osPriorityNormal, 0, 0 }; + // Allocate the memory of the thread to the psram. + taskAttr.stack_mem = memalign(0x10, attr->stackSize); MediaSetCmsisThreadPriorityAttr(&taskAttr, attr->prioty); subId = osThreadNew((osThreadFunc_t)MediaThreadFunc, member, &taskAttr); } diff --git a/code/sdk/middleware/services/media/hal/common/src/media_hal_thread_adapt.c b/code/sdk/middleware/services/media/hal/common/src/media_hal_thread_adapt.c index 593481cd5..21b116b0d 100644 --- a/code/sdk/middleware/services/media/hal/common/src/media_hal_thread_adapt.c +++ b/code/sdk/middleware/services/media/hal/common/src/media_hal_thread_adapt.c @@ -295,6 +295,8 @@ static int32_t MediaHalDoCreateThread(MediaHalThreadMember *member, const MediaH uint32_t attrBits = osThreadDetached; #endif osThreadAttr_t taskAttr = { attr->name, attrBits, NULL, 0, NULL, attr->stackSize, osPriorityNormal, 0, 0 }; + // Allocate the memory of the thread to the psram. + taskAttr.stack_mem = memalign(0x10, attr->stackSize); MediaHalSetCmsisThreadPriorityAttr(&taskAttr, attr->prioty); subId = osThreadNew(MediaHalThreadFunc, member, &taskAttr); } diff --git a/code/sdk/middleware/utils/codeloader/private/codeloader_execute_command_flash_writing_commands.c b/code/sdk/middleware/utils/codeloader/private/codeloader_execute_command_flash_writing_commands.c index 9ab9b48a5..96738ce14 100644 --- a/code/sdk/middleware/utils/codeloader/private/codeloader_execute_command_flash_writing_commands.c +++ b/code/sdk/middleware/utils/codeloader/private/codeloader_execute_command_flash_writing_commands.c @@ -23,6 +23,9 @@ #ifdef CFG_DRIVERS_NANDFLASH #include "nandflash_inner.h" #endif +#ifdef CFG_DRIVERS_MMC +#include "drv_mmc_adapter.h" +#endif #include "memory_core.h" #ifdef SUPPORT_HW_SHA256 #include "sec_sha.h" @@ -233,6 +236,11 @@ static bool codeloader_execute_command_flash_writing_helper_flash_buffer( static bool codeloader_execute_command_nandflash_writing_buffer( const uint8_t *input_buffer_to_write, uint32_t bytes_to_write); #endif +#ifdef CFG_DRIVERS_MMC +/* write to emmc and update the internal state */ +static bool codeloader_execute_command_emmc_writing_buffer( + const uint8_t *input_buffer_to_write, uint32_t bytes_to_write); +#endif //lint -esym(459, codeloader_command_processor_start_flashing) /* Start flashing command function */ @@ -395,6 +403,9 @@ int8_t codeloader_command_processor_send_data( } else if (g_codeloader_data_save_position.type == CODELOADER_COMMAND_SET_BIN_POSITION_AT_FS_BIN) { #ifdef CFG_DRIVERS_NANDFLASH if (!codeloader_execute_command_nandflash_writing_buffer(input_buffer->buffer, input_buffer->length)) +#endif +#ifdef CFG_DRIVERS_MMC + if (!codeloader_execute_command_emmc_writing_buffer(input_buffer->buffer, input_buffer->length)) #endif { return_code = CODELOADER_COMMAND_FLASH_COMMANDS_ERROR_CODE_ERROR_WR_NANDFLASH; @@ -688,6 +699,30 @@ static bool codeloader_execute_command_nandflash_writing_buffer( } #endif +#ifdef CFG_DRIVERS_MMC +static bool codeloader_execute_command_emmc_writing_buffer( + const uint8_t *input_buffer_to_write, uint32_t bytes_to_write) +{ + const char *ptr = (char*)input_buffer_to_write; + uint16_t len; + int ret; + if (bytes_to_write % MAX_BLOCK_SIZE == 0) { + len = bytes_to_write / MAX_BLOCK_SIZE; + } else { + len = bytes_to_write / MAX_BLOCK_SIZE + 1; + } + + ret = ssb_emmc_write(ptr, g_codeloader_flash_writing_commands_location, len); + PRINT("emmc pos=%d len=%d ret=%d\n", g_codeloader_flash_writing_commands_location, len, ret); + if (ret == len) { + g_codeloader_flash_writing_commands_location += len; + return true; + } else { + return false; + } +} +#endif + int8_t codeloader_command_processor_dbg_show_disk_info( const codeloader_rx_buffer_t *input_buffer, codeloader_common_generic_buffer_t *output_buffer) { @@ -740,7 +775,7 @@ int8_t codeloader_command_processor_clear_dataflash_region( } #ifdef CFG_DRIVERS_NANDFLASH -static int8_t codeloader_nand_set_bin_head_info(uint32_t* start_addr, uint32_t* length) +static int8_t codeloader_set_bin_head_info(uint32_t* start_addr, uint32_t* length) { struct nand_driver_struct *nand_drv = (struct nand_driver_struct *)get_nand_flash(); if (g_nandflash_init != 0) { @@ -762,6 +797,19 @@ static int8_t codeloader_nand_set_bin_head_info(uint32_t* start_addr, uint32_t* } #endif +#ifdef CFG_DRIVERS_MMC +#define MMC_START_LOCATION 2048 +static int8_t codeloader_set_bin_head_info(uint32_t* start_addr, uint32_t* length) +{ + struct rt_mmcsd_host* mmc = get_ssb_emmc(); + + (void)ssb_emmc_erase(0, mmc->card->erase_size); + g_codeloader_flash_writing_commands_location = MMC_START_LOCATION; + PRINT("mmc erase size=%d pos=%d\n", mmc->card->erase_size, g_codeloader_flash_writing_commands_location); + return CODELOADER_COMMAND_GENERAL_RETURN_CODE_SUCCESS; +} +#endif + int8_t codeloader_command_processor_set_bin_head_info(const codeloader_rx_buffer_t *input_buffer, codeloader_common_generic_buffer_t *output_buffer) { @@ -822,8 +870,8 @@ int8_t codeloader_command_processor_set_bin_head_info(const codeloader_rx_buffer } if (input_parameters->type == CODELOADER_COMMAND_SET_BIN_POSITION_AT_FS_BIN) { -#ifdef CFG_DRIVERS_NANDFLASH - return_code = codeloader_nand_set_bin_head_info(&load_start_addr, &load_length); +#if (defined CFG_DRIVERS_NANDFLASH) || (defined CFG_DRIVERS_MMC) + return_code = codeloader_set_bin_head_info(&load_start_addr, &load_length); if (return_code != CODELOADER_COMMAND_GENERAL_RETURN_CODE_SUCCESS) { return return_code; } diff --git a/code/sdk/middleware/utils/dfx/panic/private/panic.c b/code/sdk/middleware/utils/dfx/panic/private/panic.c index 08e480f32..4a16e9f8b 100644 --- a/code/sdk/middleware/utils/dfx/panic/private/panic.c +++ b/code/sdk/middleware/utils/dfx/panic/private/panic.c @@ -35,8 +35,15 @@ #endif #include "panic.h" +#if !defined(BUILD_APPLICATION_SSB) && !defined(BUILD_RECOVERY_IMAGE) +#include "calendar_porting.h" +#include "tcxo.h" +#include "pm.h" +#endif + #define NON_OS_ENTER_MAX_NUM 8 #define MAX_STR_LEN 64 +#define SELF_HEAL_WAIT_TIME 100 static bool g_already_panicking = false; @@ -231,7 +238,13 @@ void panic_deal(panic_id_t origin, uint32_t code, uint32_t caller) #ifdef SUPPORT_CPU_TRACE cpu_trace_disable(); #endif - +#if !defined(BUILD_APPLICATION_SSB) && !defined(BUILD_RECOVERY_IMAGE) + if (origin == PANIC_BT_STS_ABNORMAL) { + uapi_self_heal_timer_enable(); + uapi_sys_shipmode(0); + uapi_tcxo_delay_ms(SELF_HEAL_WAIT_TIME); + } +#endif panic_deal_log(origin, code, caller); non_os_enter_critical(); diff --git a/code/sdk/middleware/utils/dfx/panic/public/panic.h b/code/sdk/middleware/utils/dfx/panic/public/panic.h index 9db723611..b3c5b0a89 100644 --- a/code/sdk/middleware/utils/dfx/panic/public/panic.h +++ b/code/sdk/middleware/utils/dfx/panic/public/panic.h @@ -102,6 +102,7 @@ typedef enum panic_id { PANIC_DSS_MIPI_ERR = 100, PANIC_GNSS_DFR_ERR = 101, PANIC_BT_SEC_BOOT_ERR = 102, + PANIC_BT_STS_ABNORMAL = 103, } panic_id_t; typedef struct { diff --git a/code/sdk/middleware/utils/nv/nv_storage_lib/nv_async_store.c b/code/sdk/middleware/utils/nv/nv_storage_lib/nv_async_store.c index 7908a8a27..a132b7934 100644 --- a/code/sdk/middleware/utils/nv/nv_storage_lib/nv_async_store.c +++ b/code/sdk/middleware/utils/nv/nv_storage_lib/nv_async_store.c @@ -65,7 +65,7 @@ static bool nv_async_check_writeable(uint16_t key, nv_key_attr_t *attr, uint16_t nv_key_map_t *cur_key = (nv_key_map_t *)value; if (cur_key->permanent == 1 || (cur_key->encrypted == 1 && (attr == NULL || (attr != NULL && attr->encrypted == false))) - || (attr == NULL && cur_key->upgrade == 1)) { + || (attr == NULL && cur_key->non_upgrade == 1)) { return false; } @@ -98,9 +98,21 @@ static errcode_t nv_async_update_attr(nv_key_map_t* cur_key, nv_key_attr_t *attr return ERRCODE_SUCC; } /* 保持hash表中数据和传入的属性保持一致 */ - cur_key->permanent = attr->permanent; - cur_key->encrypted = attr->encrypted; - cur_key->upgrade = attr->non_upgrade; + if (attr->permanent) { + cur_key->permanent = 1; + cur_key->non_upgrade = 1; + } + if (attr->encrypted) { + cur_key->encrypted = 1; + cur_key->non_upgrade = 1; + } + + /* 可升级属性支持属性更改 */ + if (attr->non_upgrade) { + cur_key->non_upgrade = 1; + } else { + cur_key->non_upgrade = 0; + } return ERRCODE_SUCC; } @@ -173,14 +185,14 @@ static errcode_t nv_async_store_init_keys_one_page(kv_page_handle_t *page) /* 对三个属性进行判断 */ if (key.header.type != KV_KEY_TYPE_NORMAL) { cur_key->permanent = 1; - cur_key->upgrade = 1; + cur_key->non_upgrade = 1; } if (key.header.enc_key != 0) { cur_key->encrypted = 1; - cur_key->upgrade = 1; + cur_key->non_upgrade = 1; } if (key.header.upgrade != KV_KEY_TYPE_NORMAL) { - cur_key->upgrade = 1; + cur_key->non_upgrade = 1; } /* 传入柔性数组的数组名既首地址,获取flash数据 */ res = kv_key_read_data(&key, cur_key->kvalue); @@ -238,7 +250,7 @@ errcode_t nv_async_read_with_attr(uint16_t key, uint16_t kvalue_max_length, attr->encrypted = true; attr->non_upgrade = true; } - if (cur_key->upgrade == 1) { + if (cur_key->non_upgrade == 1) { attr->non_upgrade = true; } osal_sem_up(&nv_async_sem); @@ -318,7 +330,7 @@ static errcode_t nv_async_msg_process(nv_queue_msg_handle_t *msg_data_t) nv_key_attr_t attr; attr.permanent = (msg_data->permanent == 1) ? true : false; attr.encrypted = (msg_data->encrypted == 1) ? true : false; - attr.non_upgrade = (msg_data->upgrade == 1) ? true : false; + attr.non_upgrade = (msg_data->non_upgrade == 1) ? true : false; nv_log_debug("[NV] nv async msg process key=0x%x,len=%d,attr %d %d %d\r\n", msg_data->key_id, msg_data->key_len, attr.permanent, attr.encrypted, attr.non_upgrade); res = nv_direct_write_with_attr(msg_data->key_id, msg_data->kvalue, msg_data->key_len, &attr, NULL); diff --git a/code/sdk/middleware/utils/nv/nv_storage_lib/nv_async_store.h b/code/sdk/middleware/utils/nv/nv_storage_lib/nv_async_store.h index a99a47b3a..46a519229 100644 --- a/code/sdk/middleware/utils/nv/nv_storage_lib/nv_async_store.h +++ b/code/sdk/middleware/utils/nv/nv_storage_lib/nv_async_store.h @@ -19,7 +19,7 @@ typedef struct nv_key_map { uint16_t key_len : 13; /* Key length */ uint16_t permanent : 1; /* 是否是永久Key */ uint16_t encrypted : 1; /* 是否是加密Key */ - uint16_t upgrade : 1; /* 是否可以升级 */ + uint16_t non_upgrade : 1; /* 是否不可以升级 */ uint8_t kvalue[0]; /* key value */ } nv_key_map_t; diff --git a/code/sdk/open_source/freebsd/liteos/drivers/mmc/host/sdhci/sdhci_init.c b/code/sdk/open_source/freebsd/liteos/drivers/mmc/host/sdhci/sdhci_init.c index 4d2e843db..3b62d5119 100644 --- a/code/sdk/open_source/freebsd/liteos/drivers/mmc/host/sdhci/sdhci_init.c +++ b/code/sdk/open_source/freebsd/liteos/drivers/mmc/host/sdhci/sdhci_init.c @@ -388,7 +388,13 @@ hi_sdhci_attach(struct dpal_platform_device *pdev) struct hci_softc *sc; struct sdhci_slot *slot; dpal_resource_t *res; + +#ifdef CFG_SDIO_EMMC_COEXIST + static bool emmc_initialized = false; + static bool sdio_initialized = false; +#else static bool mmc_initialized = false; +#endif sc = dpal_zalloc(sizeof(struct hci_softc)); if (sc == NULL) @@ -479,6 +485,24 @@ hi_sdhci_attach(struct dpal_platform_device *pdev) if (err != 0) goto clear_mmc_proc; +#ifdef CFG_SDIO_EMMC_COEXIST + if (slot->num == 0 && !emmc_initialized) { + emmc_initialized = true; + err = sdhci_thread_create((dpal_tsk_entry_func)sdhci_task, + "cdsw_emmc_task", (uint32_t *)&slot->cd_tsk_id); + if (err) { + goto clear_mem_resource; + } + } + if (slot->num == 1 && !sdio_initialized) { + sdio_initialized = true; + err = sdhci_thread_create((dpal_tsk_entry_func)sdhci_task, + "cdsw_sdio_task", (uint32_t *)&slot->cd_tsk_id); + if (err) { + goto clear_mem_resource; + } + } +#else if (!mmc_initialized) { mmc_initialized = true; err = sdhci_thread_create((dpal_tsk_entry_func)sdhci_task, @@ -487,6 +511,7 @@ hi_sdhci_attach(struct dpal_platform_device *pdev) goto clear_mem_resource; } } +#endif return (0); clear_mem_resource: diff --git a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/CMakeLists.txt b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/CMakeLists.txt index b7c150a01..80ea88c60 100644 --- a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/CMakeLists.txt +++ b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/CMakeLists.txt @@ -43,6 +43,7 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/dfx ${ROOT_DIR}/application/wearable/nativeabilityfwk/include + ${ROOT_DIR}/open_source/openharmony/foundation/ace/ace_engine_lite/modules/presets ) if("__LITEOS__" IN_LIST DEFINES) diff --git a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-native-js/libams.a b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-native-js/libams.a index 31894302a..bec8d62ba 100644 Binary files a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-native-js/libams.a and b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-native-js/libams.a differ diff --git a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-xts/libams.a b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-xts/libams.a index 26e3fed79..17e3a8856 100644 Binary files a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-xts/libams.a and b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/brandy-xts/libams.a differ diff --git a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/include/aafwk/aafwk_lite/services/abilitymgr_lite/include/ability_service.h b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/include/aafwk/aafwk_lite/services/abilitymgr_lite/include/ability_service.h index 913b45a59..d1e8f40de 100644 --- a/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/include/aafwk/aafwk_lite/services/abilitymgr_lite/include/ability_service.h +++ b/code/sdk/open_source/openharmony/foundation/aafwk/aafwk_lite/include/aafwk/aafwk_lite/services/abilitymgr_lite/include/ability_service.h @@ -27,6 +27,7 @@ #include "want.h" #include "slite_ability.h" #include "ability_state.h" +#include "timer_module.h" namespace OHOS { struct AbilitySvcInfo { diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/CMakeLists.txt b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/CMakeLists.txt index 91489b6fd..d259e499d 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/CMakeLists.txt +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/CMakeLists.txt @@ -43,8 +43,11 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/innerkits/common ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/font ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/dfx + ${ROOT_DIR}/middleware/services/gui/uikit/ui/frameworks ${ROOT_DIR}/open_source/openharmony/drivers/peripheral/display/interfaces/include ${ROOT_DIR}/application/wearable/ohos_deps + ${ROOT_DIR}/application/wearable/nativeabilityfwk/include + ${ROOT_DIR}/application/wearable/nativeapp/nativelauncher/include ${ROOT_DIR}/open_source/openharmony/third_party/cJSON ${ROOT_DIR}/open_source/openharmony/third_party/qrcodegen/cpp ${ROOT_DIR}/open_source/openharmony/base/global/i18n_lite/frameworks/i18n/include @@ -209,8 +212,11 @@ set(PRIVATE_HEADER ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/font ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/dfx ${ROOT_DIR}/middleware/services/gui/uikit/ui/interfaces/kits/common + ${ROOT_DIR}/middleware/services/gui/uikit/ui/frameworks ${ROOT_DIR}/open_source/openharmony/drivers/peripheral/display/interfaces/include ${ROOT_DIR}/application/wearable/ohos_deps + ${ROOT_DIR}/application/wearable/nativeabilityfwk/include + ${ROOT_DIR}/application/wearable/nativeapp/nativelauncher/include ${ROOT_DIR}/open_source/openharmony/third_party/cJSON ${ROOT_DIR}/open_source/openharmony/third_party/qrcodegen/cpp ${ROOT_DIR}/open_source/openharmony/base/global/i18n_lite/frameworks/i18n/include @@ -254,6 +260,9 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/components/baidu_map_component.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modules/app_module.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modules/device_module.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/modules/vibrator_module.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/modules/battery_module.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/modules/sensor_module.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modules/dfx_module.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modules/module_manager.cpp ${CMAKE_CURRENT_SOURCE_DIR}/modules/locale_module.cpp diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/js_fwk_common.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/js_fwk_common.h index 2dd037a99..12c525fb3 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/js_fwk_common.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/js_fwk_common.h @@ -24,6 +24,7 @@ #endif #include "graphic_config.h" #include "wrapper/js.h" +#include "events/rotate_event.h" namespace OHOS { namespace ACELite { @@ -274,8 +275,10 @@ jerry_value_t *ConvertBaseEventInfo(const Event &event, const uint16_t id); bool CallBaseEvent(const jerry_value_t func, const Event &event, const uint16_t id); jerry_value_t *ConvertDragEventInfo(const DragEvent &event, const uint16_t id); jerry_value_t *ConvertKeyEventInfo(const KeyEvent &event); -void ClearEventListener(const jerry_value_t args[], uint8_t argc); #endif +void ClearEventListener(const jerry_value_t args[], uint8_t argc); + +jerry_value_t *ConvertRotateEventInfo(const RotateEvent &event); JSValue GetRootAbilitySlice(); JSValue CallWithRootAbilitySlice(JSValue func, JSValue args[], JSSize size); JSValue CallWithRootAbilitySlice(JSValue func); diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/keys.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/keys.h index f047f4e67..be06b85da 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/keys.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/base/keys.h @@ -231,12 +231,14 @@ enum { KEYWORD(REVERSE, reverse) // image-animator attribute KEYWORD(RIGHT, right) // text align type KEYWORD(ROTATE, rotate) // animation rotate + KEYWORD(ROTATE_INPUT, rotate_input) KEYWORD(ROW, row) // layout style KEYWORD(ROW_REVERSE, row-reverse) // layout style KEYWORD(SCALE_DOWN, scaleDown) // image component scale down KEYWORD(SCROLLAMOUNT, scrollamount) // marquee scroll speed KEYWORD(SCROLLEND, scrollend) // scroll end event listener KEYWORD(SCROLLSTART, scrollstart) // scroll start event listener + KEYWORD(SCROLLBAR, scrollbar) // list scroll bar #ifdef FEATURE_COMPONENT_ANALOG_CLOCK KEYWORD(SEC, sec) // analog-clock second #endif // FEATURE_COMPONENT_ANALOG_CLOCK diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libace.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libace.a index fff3f6fbc..defda6c56 100644 Binary files a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libace.a and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-native-js/libace.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libace.a b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libace.a index 97280be94..1c00ced39 100644 Binary files a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libace.a and b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/brandy-xts/libace.a differ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/baidu_map_component.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/baidu_map_component.cpp index 58a91159a..8b50db0da 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/baidu_map_component.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/baidu_map_component.cpp @@ -18,6 +18,7 @@ #include "ace_log.h" #include "key_parser.h" #include "keys.h" +#include "soc_vau_api.h" namespace OHOS { namespace ACELite { @@ -88,6 +89,14 @@ BaiduMapComponent::BaiduMapComponent(jerry_value_t options, jerry_value_t childr for (uint16_t index = 0; index < funcMapLength; index++) { RegisterNamedFunction(funcMap[index].funcName, funcMap[index].handler); } + uapi_vau_set_cubic_threshold(1.0f); +} + +BaiduMapComponent::~BaiduMapComponent() +{ + HILOG_INFO(HILOG_MODULE_ACE,"BaiduMapComponent destructor"); + MapComponentApi::getInstance().destroy(); + uapi_vau_set_cubic_threshold(0.125f); } UIView *BaiduMapComponent::GetComponentRootView() const diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/baidu_map_component.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/baidu_map_component.h index af7ca152a..04988132f 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/baidu_map_component.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/baidu_map_component.h @@ -37,7 +37,7 @@ public: ACE_DISALLOW_COPY_AND_MOVE(BaiduMapComponent); BaiduMapComponent() = delete; BaiduMapComponent(jerry_value_t options, jerry_value_t children, AppStyleManager* styleManager); - ~BaiduMapComponent() override{} + ~BaiduMapComponent() override; /** * SetZoomEventEnabled, enabled Indicates whether to allow scaling events. This function is disabled by default diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.cpp index 8a9e46da2..b8c24d7e3 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.cpp @@ -72,6 +72,7 @@ Component::Component(jerry_value_t options, jerry_value_t children, AppStyleMana onClickListener_(nullptr), onLongPressListener_(nullptr), onSwipeListener_(nullptr), + onKeyInputListener_(nullptr), #ifdef JS_TOUCH_EVENT_SUPPORT onTouchStartListener_(nullptr), onTouchMoveListener_(nullptr), @@ -79,6 +80,7 @@ Component::Component(jerry_value_t options, jerry_value_t children, AppStyleMana onTouchEndListener_(nullptr), keyBoardEventListener_(nullptr), #endif + onRotateListener_(nullptr), viewId_(nullptr), componentName_(K_UNKNOWN), rendered_(false), @@ -1186,6 +1188,21 @@ void Component::SetKeyBoardEventListener(jerry_value_t eventFunc, uint16_t event } #endif +void Component::SetKeyInputEventListener(UIView &view, jerry_value_t eventFunc, uint16_t eventTypeId) +{ + RootView *rootView = RootView::GetInstance(); + if (rootView == nullptr) { + HILOG_ERROR(HILOG_MODULE_ACE, "get rootView is nullptr"); + return; + } + onKeyInputListener_ = new KeyInputEventListener(eventFunc, eventTypeId); + if (onKeyInputListener_ == nullptr) { + HILOG_ERROR(HILOG_MODULE_ACE, "on key input event listener create failed"); + return; + } + rootView->SetOnKeyActListener(onKeyInputListener_); +} + void Component::SetLongPressEventListener(UIView &view, const jerry_value_t eventFunc, bool isStopPropagation) { onLongPressListener_ = new ViewOnLongPressListener(eventFunc, isStopPropagation); @@ -1211,6 +1228,16 @@ void Component::SetSwipeEventListener(UIView &view, jerry_value_t eventFunc, boo view.SetTouchable(true); } +void Component::SetRotateEventListener(UIView& view, jerry_value_t eventFunc) +{ + onRotateListener_ = new ViewOnRotateListener(eventFunc); + if (onRotateListener_ == nullptr) { + HILOG_ERROR(HILOG_MODULE_ACE, "rotate listener create failed"); + return; + } + view.SetOnRotateListener(onRotateListener_); +} + // default implementation bool Component::RegisterEventListener(uint16_t eventTypeId, jerry_value_t funcValue, bool isStopPropagation) { @@ -1247,6 +1274,10 @@ bool Component::RegisterCommonEventListener(UIView &view, SetLongPressEventListener(view, funcValue, isStopPropagation); break; } + case K_ROTATE_INPUT: { + SetRotateEventListener(view, funcValue); + break; + } case K_SWIPE: { SetSwipeEventListener(view, funcValue, isStopPropagation); break; @@ -1277,6 +1308,7 @@ bool Component::RegisterCommonEventListener(UIView &view, return false; } } + SetKeyInputEventListener(view, funcValue, eventTypeId); return true; } @@ -1284,6 +1316,7 @@ void Component::ReleaseCommonEventListeners() { ACE_DELETE(onClickListener_); ACE_DELETE(onLongPressListener_); + ACE_DELETE(onKeyInputListener_); #ifdef JS_TOUCH_EVENT_SUPPORT ACE_DELETE(keyBoardEventListener_); ACE_DELETE(onTouchStartListener_); @@ -1292,6 +1325,7 @@ void Component::ReleaseCommonEventListeners() ACE_DELETE(onTouchEndListener_); #endif ACE_DELETE(onSwipeListener_); + ACE_DELETE(onRotateListener_); } void Component::AppendDescriptorOrElements(Component *parent, const JSValue descriptorOrElements) diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.h index 3d0097957..354cea5f3 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/component.h @@ -542,6 +542,7 @@ private: void SetClickEventListener(UIView& view, const jerry_value_t eventFunc, bool isStopPropagation); void SetLongPressEventListener(UIView& view, const jerry_value_t eventFunc, bool isStopPropagation); void SetSwipeEventListener(UIView& view, jerry_value_t eventFunc, bool isStopPropagation); + void SetRotateEventListener(UIView& view, jerry_value_t eventFunc); #ifdef JS_TOUCH_EVENT_SUPPORT void SetTouchStartEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation); void SetTouchMoveEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation); @@ -549,6 +550,7 @@ private: void SetTouchCancelEventListener(UIView &view, jerry_value_t eventFunc, bool isStopPropagation); void SetKeyBoardEventListener(jerry_value_t eventFunc, bool isStopPropagation); #endif + void SetKeyInputEventListener(UIView &view, jerry_value_t eventFunc, uint16_t eventTypeId); /** * @brief release common event listeners if any is set */ @@ -621,6 +623,7 @@ private: ViewOnClickListener *onClickListener_; ViewOnLongPressListener *onLongPressListener_; ViewOnSwipeListener *onSwipeListener_; + ViewOnRotateListener *onRotateListener_; #ifdef JS_TOUCH_EVENT_SUPPORT ViewOnTouchStartListener *onTouchStartListener_; ViewOnTouchMoveListener *onTouchMoveListener_; @@ -628,6 +631,7 @@ private: ViewOnTouchEndListener *onTouchEndListener_; KeyBoardEventListener *keyBoardEventListener_; #endif + KeyInputEventListener *onKeyInputListener_; /** * record view id, need to be released when this component get released */ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.cpp index 8f63c5fbd..1615474c2 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.cpp @@ -115,6 +115,130 @@ bool ViewOnTouchCancelListener::OnCancel(UIView &view, const CancelEvent &event) } #endif // JS_TOUCH_EVENT_SUPPORT +ViewOnRotateListener::ViewOnRotateListener(jerry_value_t fn) +{ + fn_ = jerry_acquire_value(fn); +} + +ViewOnRotateListener::~ViewOnRotateListener() +{ + jerry_release_value(fn_); +} + +bool ViewOnRotateListener::OnRotateStart(UIView& view, const RotateEvent& event) +{ + if (jerry_value_is_undefined(fn_)) { + HILOG_ERROR(HILOG_MODULE_ACE, "OnRotateStart received, but no JS function to call"); + return false; + } + HILOG_DEBUG(HILOG_MODULE_ACE, "OnRotateStart received"); + jerry_value_t *args = ConvertRotateEventInfo(event); + jerry_release_value(CallJSFunctionOnRoot(fn_, args, 1)); + ClearEventListener(args, 1); + return true; +} + +bool ViewOnRotateListener::OnRotate(UIView& view, const RotateEvent& event) +{ + if (jerry_value_is_undefined(fn_)) { + HILOG_ERROR(HILOG_MODULE_ACE, "OnRotate received, but no JS function to call"); + return false; + } + HILOG_DEBUG(HILOG_MODULE_ACE, "OnRotate received"); + jerry_value_t *args = ConvertRotateEventInfo(event); + jerry_release_value(CallJSFunctionOnRoot(fn_, args, 1)); + ClearEventListener(args, 1); + return true; +} + +bool ViewOnRotateListener::OnRotateEnd(UIView& view, const RotateEvent& event) +{ + if (jerry_value_is_undefined(fn_)) { + HILOG_ERROR(HILOG_MODULE_ACE, "OnRotateEnd received, but no JS function to call"); + return false; + } + HILOG_DEBUG(HILOG_MODULE_ACE, "OnRotateEnd received"); + jerry_value_t *args = ConvertRotateEventInfo(event); + jerry_release_value(CallJSFunctionOnRoot(fn_, args, 1)); + ClearEventListener(args, 1); + return true; +} + +KeyInputEventListener::KeyInputEventListener(jerry_value_t fn, uint16_t id) +{ + fn_ = jerry_acquire_value(fn); + id_ = id; +} + +KeyInputEventListener::~KeyInputEventListener() +{ + jerry_release_value(fn_); +} + +void KeyInputEventListener::OnKeyPress(void) +{ + pressFlag = 1; // 短按标志 + return; +} + +void KeyInputEventListener::OnKeyLongPress(const KeyEvent& event) +{ + longPressFlag = 1; // 长按标志 + + uint16_t keyID = event.GetKeyId(); + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) { + // 切换到关机/重启卡片 + NativeAbility::GetInstance().ChangeSlice(VIEW_REBOOT); + } else if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_FUNC)) { + // 切换到查看系统版本卡片 + } + return; +} + +void KeyInputEventListener::OnKeyRelease(const KeyEvent& event) +{ + uint16_t currentViewId = NativeAbility::GetInstance().GetCurSliceId(); + uint16_t keyID = event.GetKeyId(); + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) { + if (longPressFlag == 0 && pressFlag == 1) { // 短按电源键 + // 退出JS应用 + JsAppContext::GetInstance()->TerminateAbility(); + } + } else if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_FUNC)) { + if (longPressFlag == 0 && pressFlag == 1) { // 短按功能键 + // 短按功能键处理 + } + } + + pressFlag = 0; + longPressFlag = 0; + return; +} + +bool KeyInputEventListener::OnKeyAct(UIView& view, const KeyEvent& event) +{ + UNUSED(view); + + uint8_t state = event.GetState(); + + switch (state) { + case InputDevice::STATE_PRESS: // 短按 + OnKeyPress(); + break; +#ifdef __LITEOS_M__ + case InputDevice::STATE_LONG_PRESS: // 长按 + OnKeyLongPress(event); + break; +#endif + case InputDevice::STATE_RELEASE: // 释放 + OnKeyRelease(event); + break; + default: + break; + } + return true; +} + void ViewOnSwipeListener::SetStopPropagation(bool isStopPropogation) { isStopPropagation_ = isStopPropogation; @@ -156,7 +280,7 @@ void ValueChangeListener::OnChange(UIView &view, const char *value) if (IS_UNDEFINED(fn_)) { return; } - + jerry_value_t textValue = jerry_create_string(reinterpret_cast(value)); jerry_value_t args[1] = {textValue}; if (jerry_value_is_function(fn_)) { diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.h index 375f8670b..abca41544 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/event_listener.h @@ -28,6 +28,13 @@ #include "ui_slider.h" #include "ui_toggle_button.h" #include "ui_edit_text.h" +#include "dock/input_device.h" +#include "components/root_view.h" +#include "events/key_event.h" +#include "common/key_code.h" +#include "js_app_context.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" namespace OHOS { namespace ACELite { @@ -88,17 +95,17 @@ public: ACE_DISALLOW_COPY_AND_MOVE(ValueChangeListener); explicit ValueChangeListener(jerry_value_t fn) : fn_(jerry_acquire_value(fn)) {} - + ~ValueChangeListener() { jerry_release_value(fn_); } - + void OnChange(UIView& view, const char* value) override; private: jerry_value_t fn_; }; - + class ViewOnClickListener final : public UIView::OnClickListener { public: ACE_DISALLOW_COPY_AND_MOVE(ViewOnClickListener); @@ -227,6 +234,22 @@ private: }; #endif +class KeyInputEventListener final : public RootView::OnKeyActListener { +public: + ACE_DISALLOW_COPY_AND_MOVE(KeyInputEventListener); + KeyInputEventListener(jerry_value_t fn, const uint16_t id); + ~KeyInputEventListener(); + bool OnKeyAct(UIView &view, const KeyEvent &event) override; +private: + void OnKeyPress(void); + void OnKeyLongPress(const KeyEvent& event); + void OnKeyRelease(const KeyEvent& event); + int32_t pressFlag{0}; + int32_t longPressFlag{0}; + jerry_value_t fn_; + uint16_t id_; +}; + class ViewOnSwipeListener final : public UIView::OnDragListener { public: ACE_DISALLOW_COPY_AND_MOVE(ViewOnSwipeListener); @@ -250,6 +273,20 @@ private: bool isStopPropagation_; }; +class ViewOnRotateListener final : public UIView::OnRotateListener { +public: + ACE_DISALLOW_COPY_AND_MOVE(ViewOnRotateListener); + ViewOnRotateListener(jerry_value_t fn); + + ~ViewOnRotateListener() override; + + bool OnRotateStart(UIView& view, const RotateEvent& event) override; + bool OnRotate(UIView& view, const RotateEvent& event) override; + bool OnRotateEnd(UIView& view, const RotateEvent& event) override; +private: + jerry_value_t fn_; +}; + class SliderEventListener final : public UISlider::UISliderEventListener { public: ACE_DISALLOW_COPY_AND_MOVE(SliderEventListener); diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/list_component.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/list_component.cpp index a229cbb38..7c39599b3 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/list_component.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/list_component.cpp @@ -84,6 +84,19 @@ bool ListComponent::ApplyPrivateStyle(const AppStyleItem *style) return true; } +bool ListComponent::SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrValue) +{ + if (attrKeyId == K_SCROLLBAR) { + if (jerry_value_is_boolean(attrValue)) { + list_.SetYScrollBarVisible(BoolOf(attrValue)); + } else { + list_.SetYScrollBarVisible(false); + } + return true; + } + return false; +} + bool ListComponent::RegisterPrivateEventListener(uint16_t eventTypeId, JSValue funcValue, bool isStopPropagation) { list_.SetScrollStateListener(&listEventListener_); diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/list_component.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/list_component.h index 59db3ad9b..80dd7d2a9 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/list_component.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/components/list_component.h @@ -35,6 +35,7 @@ protected: UIView *GetComponentRootView() const override; bool ApplyPrivateStyle(const AppStyleItem* style) override; bool RegisterPrivateEventListener(uint16_t eventTypeId, JSValue funcValue, bool isStopPropagation) override; + bool SetPrivateAttribute(uint16_t attrKeyId, jerry_value_t attrValue) override; bool ProcessChildren() override; void OnViewAttached() override; bool UpdateForView() override; diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/interfaces/acelite_config.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/interfaces/acelite_config.h index 9fef1e282..036f121d0 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/interfaces/acelite_config.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/interfaces/acelite_config.h @@ -172,6 +172,16 @@ */ #define FEATURE_MODULE_DEVICE +/** + * support sensor module + */ +#define FEATURE_MODULE_SENSOR + +/** + * support battery module + */ +#define FEATURE_MODULE_BATTERY + /** * date time module */ diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/baidumapcomponent/baidumap.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/baidumapcomponent/baidumap.cpp index ce1cf77bf..4f55505a9 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/baidumapcomponent/baidumap.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/baidumapcomponent/baidumap.cpp @@ -1053,6 +1053,18 @@ JSIValue BaiduMapComponentModule::onBTConnect(const JSIValue thisVal, const JSIV return JSI::CreateBoolean(0); } +/** + * exit Navigation + */ +JSIValue BaiduMapComponentModule::NaviDestroy(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) +{ + HILOG_INFO(HILOG_MODULE_ACE,"exitNavigation"); + char *data = JSI::JsonStringify(args[0]); + HILOG_INFO(HILOG_MODULE_ACE,"exitNavigation : %s \n",data); + msg_center_vector_navi_req_destroy_from_watch(MSGCENTER_CMD_VECTOR_NAVI,MSGCENTER_TYPE_ID_VECTOR_NAVI_REQ_DESTROY_FROM_WATCH,data,strlen(data)); + return JSI::CreateBoolean(0); +} + void InitBaiduMapComponentModule(JSIValue exports) { HILOG_INFO(HILOG_MODULE_ACE,"InitBaiduMapComponentModule"); @@ -1106,28 +1118,31 @@ void InitBaiduMapComponentModule(JSIValue exports) * BT connect interface */ JSI::SetModuleAPI(exports, "onBTConnect", BaiduMapComponentModule::onBTConnect); - + /** + * exit navigation + */ + JSI::SetModuleAPI(exports, "naviDestroy", BaiduMapComponentModule::NaviDestroy); } } // namespace ACELite } // namespace OHOS -void BaidumapSendMsgToJS(const char *msgBody,uint8_t type) +int32_t BaidumapSendMsgToJS(const char *msgBody,uint8_t type) { BaiduMapAsyncMsgParams *params = new BaiduMapAsyncMsgParams(); if (params == nullptr) { - HILOG_ERROR(HILOG_MODULE_ACE,"Failed to allocate memory for params"); - return; + HILOG_ERROR(HILOG_MODULE_ACE,"Failed to allocate memory for params"); + return -1; } params->type = type; params->flag = true; int32_t copyRet = OHOS::ACELite::DmsLiteCpoyStr(¶ms->msgBody, msgBody); if (copyRet != 0) { - HILOG_ERROR(HILOG_MODULE_ACE,"Failed to copy msgBody"); + HILOG_ERROR(HILOG_MODULE_ACE,"Failed to copy msgBody"); delete params; params = nullptr; - return; + return copyRet; } bool ret = OHOS::ACELite::JsAsyncWork::DispatchAsyncWork(OHOS::ACELite::ExecuteSendMsgToJS,static_cast(params)); @@ -1135,17 +1150,18 @@ void BaidumapSendMsgToJS(const char *msgBody,uint8_t type) HILOG_ERROR(HILOG_MODULE_ACE, "Failed to dispatch async work"); delete params; params = nullptr; + return -1; } - return; + return 0; } -void BaidumapFailSendMsgToJS(const char *msgBody,uint8_t type) +int32_t BaidumapFailSendMsgToJS(const char *msgBody,uint8_t type) { BaiduMapAsyncMsgParams *params = new BaiduMapAsyncMsgParams(); if (params == nullptr) { HILOG_ERROR(HILOG_MODULE_ACE,"Failed to allocate memory for params"); - return; + return -1; } params->type = type; params->flag = false; @@ -1155,7 +1171,7 @@ void BaidumapFailSendMsgToJS(const char *msgBody,uint8_t type) HILOG_ERROR(HILOG_MODULE_ACE,"Failed to copy msgBody"); delete params; params = nullptr; - return; + return copyRet; } bool ret = OHOS::ACELite::JsAsyncWork::DispatchAsyncWork(OHOS::ACELite::ExecuteSendMsgToJS, static_cast(params)); @@ -1163,8 +1179,9 @@ void BaidumapFailSendMsgToJS(const char *msgBody,uint8_t type) HILOG_ERROR(HILOG_MODULE_ACE, "Failed to dispatch async work"); delete params; params = nullptr; + return -1; } - return; + return 0; } diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/baidumapcomponent/baidumap.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/baidumapcomponent/baidumap.h index 93a3182cd..b874985d7 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/baidumapcomponent/baidumap.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/baidumapcomponent/baidumap.h @@ -102,12 +102,17 @@ public: */ static JSIValue onBTConnect(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + /** + * exit navigation + */ + static JSIValue NaviDestroy(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + }; void InitBaiduMapComponentModule(JSIValue exports); } } -void BaidumapSendMsgToJS(const char *msgBody,uint8_t type); -void BaidumapFailSendMsgToJS(const char *msgBody,uint8_t type); +int32_t BaidumapSendMsgToJS(const char *msgBody,uint8_t type); +int32_t BaidumapFailSendMsgToJS(const char *msgBody,uint8_t type); #endif diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/battery_module.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/battery_module.cpp new file mode 100644 index 000000000..ba7982705 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/battery_module.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "ace_log.h" +#include "js_app_context.h" +#include "js_async_work.h" +#include "product_adapter.h" +#include +#include "battery_module.h" +#include "media_log.h" +#include "global.h" +#include "screen.h" + + +namespace OHOS { +namespace ACELite { + +const char * const BatteryModule::BATTERY_CHARGING_NAME = "charging"; +const char * const BatteryModule::BATTERY_LEVEL_NAME = "level"; +const bool BatteryModule::DFAULT_BATTERY_CHARGING = false; +const double BatteryModule::DFAULT_BATTERY_LEVEL = 0.5; // 50% + +JSIValue BatteryModule::GetStatus(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetStatus); +} + +JSIValue BatteryModule::ExecuteAsyncWork(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum, AsyncWorkHandler ExecuteFunc) +{ + JSIValue undefValue = JSI::CreateUndefined(); + if ((args == nullptr) || (argsNum == 0) || (JSI::ValueIsUndefined(args[0]))) { + HILOG_ERROR(HILOG_MODULE_ACE, "Error in obtaining Battery information parameters"); + return undefValue; + } + BatteryParams* params = new(std::nothrow) BatteryParams(); + if (params == nullptr) { + return undefValue; + } + params->thisVal = JSI::AcquireValue(thisVal); + params->args = JSI::AcquireValue(args[0]); + JsAsyncWork::DispatchAsyncWork(ExecuteFunc, reinterpret_cast(params)); + return undefValue; +} + +void BatteryModule::ExecuteGetStatus(void* data) +{ + BatteryParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + JSIValue args = params->args; + JSIValue thisVal = params->thisVal; + JSIValue result = JSI::CreateObject(); + JSI::SetBooleanProperty(result, BATTERY_CHARGING_NAME, DFAULT_BATTERY_CHARGING); + JSI::SetNumberProperty(result, BATTERY_LEVEL_NAME, DFAULT_BATTERY_LEVEL); + if (true) { + SuccessCallBack(thisVal, args, result); + } else { + FailCallBack(thisVal, args, -1); + } + JSI::ReleaseValueList(args, thisVal, result, ARGS_END); + delete params; +} + +void BatteryModule::SuccessCallBack(const JSIValue thisVal, const JSIValue args, JSIValue jsiValue) +{ + if (JSI::ValueIsUndefined(args)) { + return; + } + JSIValue success = JSI::GetNamedProperty(args, CB_SUCCESS); + JSIValue complete = JSI::GetNamedProperty(args, CB_COMPLETE); + if (!JSI::ValueIsUndefined(success)) { + if (JSI::ValueIsUndefined(jsiValue)) { + JSI::CallFunction(success, thisVal, nullptr, 0); + } else { + JSI::CallFunction(success, thisVal, &jsiValue, ARGC_ONE); + } + } + if (!JSI::ValueIsUndefined(complete)) { + JSI::CallFunction(complete, thisVal, nullptr, 0); + } + JSI::ReleaseValueList(success, complete, ARGS_END); +} + +void BatteryModule::FailCallBack(const JSIValue thisVal, const JSIValue args, int ret) +{ + if (JSI::ValueIsUndefined(args)) { + return; + } + JSIValue errInfo; + errInfo = JSI::CreateString("Battery faild"); + JSIValue errCode = JSI::CreateNumber(ret); + JSIValue fail = JSI::GetNamedProperty(args, CB_FAIL); + JSIValue complete = JSI::GetNamedProperty(args, CB_COMPLETE); + JSIValue argv[ARGC_TWO] = {errInfo, errCode}; + if (!JSI::ValueIsUndefined(fail)) { + JSI::CallFunction(fail, thisVal, argv, ARGC_TWO); + } + if (!JSI::ValueIsUndefined(complete)) { + JSI::CallFunction(complete, thisVal, nullptr, 0); + } + JSI::ReleaseValueList(fail, complete, errInfo, errCode, ARGS_END); +} + +} // namespace ACELite +} // namespace OHOS diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/battery_module.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/battery_module.h new file mode 100644 index 000000000..64b48dba0 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/battery_module.h @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ACELITE_BATTERY_MODULE_H +#define OHOS_ACELITE_BATTERY_MODULE_H + +#include +#include "acelite_config.h" +#include "jsi.h" +#include "js_async_work.h" +#include "non_copyable.h" +#include "product_adapter.h" +#include "abilityms_slite_client.h" + +namespace OHOS { +namespace ACELite { + +struct BatteryParams { + JSIValue args = JSI::CreateUndefined(); + JSIValue thisVal = JSI::CreateUndefined(); +}; + +class BatteryModule final : public MemoryHeap { +public: + ACE_DISALLOW_COPY_AND_MOVE(BatteryModule); + BatteryModule() = default; + ~BatteryModule() = default; + static const char * const BATTERY_CHARGING_NAME; + static const char * const BATTERY_LEVEL_NAME; + static const bool DFAULT_BATTERY_CHARGING; + static const double DFAULT_BATTERY_LEVEL; + static JSIValue GetStatus(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); + +private: + static JSIValue ExecuteAsyncWork(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum, AsyncWorkHandler ExecuteFunc); + static void SuccessCallBack(const JSIValue thisVal, const JSIValue args, JSIValue jsiValue); + static void FailCallBack(const JSIValue thisVal, const JSIValue args, int ret); + static void ExecuteGetStatus(void *data); + +}; + +void InitBatteryModule(JSIValue exports) +{ + JSI::SetModuleAPI(exports, "getStatus", BatteryModule::GetStatus); +} + +} // namespace ACELite +} // namespace OHOS +#endif // OHOS_ACELITE_APP_MODULE_H diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/display/display.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/display/display.cpp index bf97b75ed..4f3a16e7f 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/display/display.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/display/display.cpp @@ -22,7 +22,11 @@ #endif constexpr char KEEPSCREENON[] = "keepScreenOn"; +constexpr char MODE[] = "mode"; +constexpr char VALUE[] = "value"; uint32_t g_keepOnTimeout = 5000; // 5000ms +brightness_mode_t g_brightness_mode = static_cast(50); +uint8_t g_brightness_value = 50; const char * ERR_GENERAL = "display error"; const char * ERR_NOT_SUPPORT = "display set is not support"; const int DISPLAY_SUCCESS = 0; @@ -103,9 +107,118 @@ JSIValue DisplayModule::SetKeepScreenOn(const JSIValue thisVal, const JSIValue * } return JSI::CreateUndefined(); } + +JSIValue DisplayModule::SetMode(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) +{ + int ret = DISPLAY_NOT_SUPPORT; +#if defined(SUPPORT_POWER_MANAGER) + errcode_t result; + brightness_mode_t mode = static_cast(JSI::GetNumberProperty(args[0], MODE)); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + screen_context_t * curScreenCtx = power_display_get_screen_context(); + g_brightness_mode = curScreenCtx->brightness_mode; + if (mode <= AUTO) { + if (display_api->get_screen_state() != SCREEN_ON) { + display_api->turn_on_screen(); + } + result = display_api->set_brightness_mode(mode); + } else { + result = display_api->set_brightness_mode(g_brightness_mode); + } + if (result == ERRCODE_SUCC) { + ret = DISPLAY_SUCCESS; + } + else { + ret = DISPLAY_FAIL; + } +#endif + if (ret == DISPLAY_SUCCESS) { + SuccessCallBack(thisVal, args[0], JSI::CreateUndefined()); + } else { + FailCallBack(thisVal, args[0], ret); + } + return JSI::CreateUndefined(); +} + +JSIValue DisplayModule::GetMode(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) +{ + int ret = DISPLAY_NOT_SUPPORT; +#if defined(SUPPORT_POWER_MANAGER) + JSIValue result = JSI::CreateObject(); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (display_api->get_screen_state() != SCREEN_ON) { + display_api->turn_on_screen(); + } + brightness_mode_t mode = display_api->get_brightness_mode(); + JSI::SetNumberProperty(result, MODE, static_cast(mode)); +#endif + if (mode >= 0) { + SuccessCallBack(thisVal, args[0], result); + } else { + FailCallBack(thisVal, args[0], ret); + } + return JSI::CreateUndefined(); +} + +JSIValue DisplayModule::SetValue(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) +{ + int ret = DISPLAY_NOT_SUPPORT; +#if defined(SUPPORT_POWER_MANAGER) + errcode_t result; + uint8_t brightness_value = static_cast(JSI::GetNumberProperty(args[0], VALUE)); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + screen_context_t * curScreenCtx = power_display_get_screen_context(); + uint8_t g_brightness_value = curScreenCtx->brightness_value; + if (brightness_value >= 0) { + if (display_api->get_screen_state() != SCREEN_ON) { + display_api->turn_on_screen(); + } + result = display_api->set_brightness(brightness_value); + } else { + result = display_api->set_brightness(g_brightness_mode); + } + if (result == ERRCODE_SUCC) { + ret = DISPLAY_SUCCESS; + } + else { + ret = DISPLAY_FAIL; + } +#endif + if (ret == DISPLAY_SUCCESS) { + SuccessCallBack(thisVal, args[0], JSI::CreateUndefined()); + } else { + FailCallBack(thisVal, args[0], ret); + } + return JSI::CreateUndefined(); +} + +JSIValue DisplayModule::GetValue(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize) +{ + int ret = DISPLAY_NOT_SUPPORT; +#if defined(SUPPORT_POWER_MANAGER) + JSIValue result = JSI::CreateObject(); + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (display_api->get_screen_state() != SCREEN_ON) { + display_api->turn_on_screen(); + } + uint8_t brightness_value = display_api->get_brightness(); + JSI::SetNumberProperty(result, VALUE, static_cast(brightness_value)); +#endif + if (brightness_value >= 0) { + SuccessCallBack(thisVal, args[0], result); + } else { + FailCallBack(thisVal, args[0], ret); + } + return JSI::CreateUndefined(); +} + void InitBrightnessModule(JSIValue exports) { JSI::SetModuleAPI(exports, "setKeepScreenOn", DisplayModule::SetKeepScreenOn); + JSI::SetModuleAPI(exports, "setMode", DisplayModule::SetMode); + JSI::SetModuleAPI(exports, "getMode", DisplayModule::GetMode); + JSI::SetModuleAPI(exports, "setValue", DisplayModule::SetValue); + JSI::SetModuleAPI(exports, "getValue", DisplayModule::GetValue); } } // namespace ACELite } // namespace OHOS \ No newline at end of file diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/display/display.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/display/display.h index 387495535..5bc78615c 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/display/display.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/display/display.h @@ -30,6 +30,25 @@ public: */ static JSIValue SetKeepScreenOn(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + /** + * Display interface + */ + static JSIValue SetMode(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + + /** + * Display interface + */ + static JSIValue GetMode(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + + /** + * Display interface + */ + static JSIValue SetValue(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); + + /** + * Display interface + */ + static JSIValue GetValue(const JSIValue thisVal, const JSIValue *args, uint8_t argsSize); }; void InitBrightnessModule(JSIValue exports); diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/module_manager.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/module_manager.cpp index ad287d38a..787e46db8 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/module_manager.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/module_manager.cpp @@ -20,6 +20,7 @@ #include "ace_log.h" #include "internal/jsi_internal.h" #include "ohos_module_config.h" +#include "timer_module.h" namespace OHOS { namespace ACELite { @@ -66,6 +67,7 @@ JSIValue ModuleManager::RequireModule(const char * const moduleName) void ModuleManager::CleanUpModule() { + ACELite::TimerModule::GetInstance()->Clear(); if (requiredSystemModules != 0) { JSI::ReleaseValue(requiredSystemModules); requiredSystemModules = 0; diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/ohos_module_config.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/ohos_module_config.h index 731ee5bd9..db16bf374 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/ohos_module_config.h +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/ohos_module_config.h @@ -58,18 +58,18 @@ extern void InitDeviceModule(JSIValue exports); // extern void InitLocationModule(JSIValue exports); // #endif -// #ifdef FEATURE_MODULE_SENSOR -// extern void InitVibratorModule(JSIValue exports); -// extern void InitSensorModule(JSIValue exports); -// #endif +#ifdef FEATURE_MODULE_SENSOR +extern void InitVibratorModule(JSIValue exports); +extern void InitSensorModule(JSIValue exports); +#endif #ifdef FEATURE_MODULE_BRIGHTNESS extern void InitBrightnessModule(JSIValue exports); #endif -// #ifdef FEATURE_MODULE_BATTERY -// extern void InitBatteryModule(JSIValue exports); -// #endif +#ifdef FEATURE_MODULE_BATTERY +extern void InitBatteryModule(JSIValue exports); +#endif #ifdef FEATURE_MODULE_CONFIGURATION extern void InitLocaleModule(JSIValue exports); @@ -116,16 +116,16 @@ const Module OHOS_MODULES[] = { // #ifdef FEATURE_MODULE_GEO // {"geolocation", InitLocationModule}, // #endif -// #ifdef FEATURE_MODULE_SENSOR -// {"vibrator", InitVibratorModule}, -// {"sensor", InitSensorModule}, -// #endif +#ifdef FEATURE_MODULE_SENSOR + {"vibrator", InitVibratorModule}, + {"sensor", InitSensorModule}, +#endif #ifdef FEATURE_MODULE_BRIGHTNESS {"brightness", InitBrightnessModule}, #endif -// #ifdef FEATURE_MODULE_BATTERY -// {"battery", InitBatteryModule}, -// #endif +#ifdef FEATURE_MODULE_BATTERY + {"battery", InitBatteryModule}, +#endif #ifdef FEATURE_MODULE_CONFIGURATION {"configuration", InitLocaleModule}, #endif diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/presets/timer_module.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/presets/timer_module.cpp index 1f92d0756..c410e333c 100644 --- a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/presets/timer_module.cpp +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/presets/timer_module.cpp @@ -190,8 +190,8 @@ void TimerModule::Task(void *arguments) if (timer != nullptr) { StopTimerTask(timer->timerId); } -#endif timerList->DeleteTimer(arg->index); +#endif } #else // SYNC_TIMER_CALLBACK if (jerry_value_is_function(arg->func)) { @@ -225,8 +225,8 @@ void TimerModule::Execute(void *data) if ((currentTimer != nullptr) && (!funcArgs->repeated)) { #if defined(__LITEOS_A__) StopTimerTask(timer->timerId); -#endif timerList->DeleteTimer(funcArgs->index); +#endif } } } diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/sensor_module.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/sensor_module.cpp new file mode 100644 index 000000000..98ec6691e --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/sensor_module.cpp @@ -0,0 +1,294 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "ace_log.h" +#include "js_app_context.h" +#include "js_async_work.h" +#include "product_adapter.h" +#include +#include "sensor_module.h" +#include "media_log.h" +#include "global.h" +#include "screen.h" + +namespace OHOS { +namespace ACELite { + +const char * const SensorModule::STEPS = "steps"; +const uint32_t SensorModule::DEFAULT_STEPS = 2000; // 2000 steps +const char * const SensorModule::PRESSURE = "pressure"; +const uint32_t SensorModule::DEFAULT_PRESSURE = 101300; // 1.013×10^5 Pa +const char * const SensorModule::HEARTRATE = "heartRate"; +const uint32_t SensorModule::DEFAULT_HEARTRATE = 80; // 80/min +const char * const SensorModule::ISONBODY = "value"; +const bool SensorModule::DEFAULT_ISONBODY = true; + +void SensorModule::SuccessCallBack(const JSIValue thisVal, const JSIValue args, JSIValue jsiValue, bool flag) +{ + if (JSI::ValueIsUndefined(args)) { + return; + } + JSIValue success = JSI::GetNamedProperty(args, CB_SUCCESS); + JSIValue complete = JSI::GetNamedProperty(args, CB_COMPLETE); + if (!JSI::ValueIsUndefined(success)) { + if (JSI::ValueIsUndefined(jsiValue)) { + JSI::CallFunction(success, thisVal, nullptr, 0); + } else { + JSI::CallFunction(success, thisVal, &jsiValue, ARGC_ONE); + } + } + if (!JSI::ValueIsUndefined(complete) && flag) { + JSI::CallFunction(complete, thisVal, nullptr, 0); + } + JSI::ReleaseValueList(success, complete, ARGS_END); +} + +void SensorModule::FailCallBack(const JSIValue thisVal, const JSIValue args, int ret, bool flag) +{ + if (JSI::ValueIsUndefined(args)) { + return; + } + JSIValue errInfo; + errInfo = JSI::CreateString("Sensor faild"); + JSIValue errCode = JSI::CreateNumber(ret); + JSIValue fail = JSI::GetNamedProperty(args, CB_FAIL); + JSIValue complete = JSI::GetNamedProperty(args, CB_COMPLETE); + JSIValue argv[ARGC_TWO] = {errInfo, errCode}; + if (!JSI::ValueIsUndefined(fail)) { + JSI::CallFunction(fail, thisVal, argv, ARGC_TWO); + } + if (!JSI::ValueIsUndefined(complete) && flag) { + JSI::CallFunction(complete, thisVal, nullptr, 0); + } + JSI::ReleaseValueList(fail, complete, errInfo, errCode, ARGS_END); +} + +void SensorModule::ExecuteSubscribeStepCounter(void* data) +{ + SensorParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + JSIValue args = params->args; + JSIValue thisVal = params->thisVal; + JSIValue result = JSI::CreateObject(); + uint32_t steps = DEFAULT_STEPS; + JSI::SetNumberProperty(result, STEPS, static_cast(steps)); + if (true) { + SuccessCallBack(thisVal, args, result, false); + } else { + FailCallBack(thisVal, args, -1, false); + } + JSI::ReleaseValueList(args, thisVal, result, ARGS_END); + delete params; +} + +void SensorModule::ExecuteUnsubscribeStepCounter(void* data) +{ + SensorParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + JSIValue thisVal = params->thisVal; + printf("--------ExecuteUnsubscribeStepCounter--------\n"); + JSI::ReleaseValueList(thisVal, JSI::CreateUndefined(), ARGS_END); + delete params; +} + +void SensorModule::ExecuteSubscribeBarometer(void* data) +{ + SensorParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + JSIValue args = params->args; + JSIValue thisVal = params->thisVal; + JSIValue result = JSI::CreateObject(); + uint32_t pressure = DEFAULT_PRESSURE; + JSI::SetNumberProperty(result, PRESSURE, static_cast(pressure)); + if (true) { + SuccessCallBack(thisVal, args, result, false); + } else { + FailCallBack(thisVal, args, -1, false); + } + JSI::ReleaseValueList(args, thisVal, result, ARGS_END); + delete params; +} + +void SensorModule::ExecuteUnsubscribeBarometer(void* data) +{ + printf("--------ExecuteUnsubscribeBarometer--------\n"); + SensorParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + JSIValue thisVal = params->thisVal; + JSI::ReleaseValueList(thisVal, JSI::CreateUndefined(), ARGS_END); + delete params; +} + +void SensorModule::ExecuteSubscribeHeartRate(void* data) +{ + SensorParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + JSIValue args = params->args; + JSIValue thisVal = params->thisVal; + JSIValue result = JSI::CreateObject(); + uint32_t heartRate = DEFAULT_HEARTRATE; + JSI::SetNumberProperty(result, HEARTRATE, static_cast(heartRate)); + if (true) { + SuccessCallBack(thisVal, args, result, false); + } else { + FailCallBack(thisVal, args, -1, false); + } + JSI::ReleaseValueList(args, thisVal, result, ARGS_END); + delete params; +} + +void SensorModule::ExecuteUnsubscribeHeartRate(void* data) +{ + SensorParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + JSIValue thisVal = params->thisVal; + printf("--------ExecuteUnsubscribeHeartRate--------\n"); + JSI::ReleaseValueList(thisVal, JSI::CreateUndefined(), ARGS_END); + delete params; +} + +void SensorModule::ExecuteSubscribeOnBodyState(void* data) +{ + SensorParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + JSIValue args = params->args; + JSIValue thisVal = params->thisVal; + JSIValue result = JSI::CreateObject(); + bool value = DEFAULT_ISONBODY; + JSI::SetBooleanProperty(result, ISONBODY, static_cast(value)); + if (true) { + SuccessCallBack(thisVal, args, result, false); + } else { + FailCallBack(thisVal, args, -1, false); + } + JSI::ReleaseValueList(args, thisVal, result, ARGS_END); + delete params; +} + +void SensorModule::ExecuteUnsubscribeOnBodyState(void* data) +{ + SensorParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + JSIValue thisVal = params->thisVal; + printf("--------ExecuteUnsubscribeOnBodyState--------\n"); + JSI::ReleaseValueList(thisVal, JSI::CreateUndefined(), ARGS_END); + delete params; +} + +void SensorModule::ExecuteGetOnBodyState(void* data) +{ + SensorParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + JSIValue args = params->args; + JSIValue thisVal = params->thisVal; + JSIValue result = JSI::CreateObject(); + bool value = DEFAULT_ISONBODY; + JSI::SetBooleanProperty(result, ISONBODY, static_cast(value)); + if (true) { + SuccessCallBack(thisVal, args, result, true); + } else { + FailCallBack(thisVal, args, -1, true); + } + JSI::ReleaseValueList(args, thisVal, result, ARGS_END); + delete params; +} + +JSIValue SensorModule::ExecuteAsyncWork(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum, AsyncWorkHandler ExecuteFunc) +{ + printf("args=%p argsNum=%d\n", args, argsNum); + JSIValue undefValue = JSI::CreateUndefined(); + // if ((args == nullptr) || (argsNum == 0) || (JSI::ValueIsUndefined(args[0]))) { + // HILOG_ERROR(HILOG_MODULE_ACE, "Error in obtaining Sensor information parameters"); + // return undefValue; + // } + + SensorParams* params = new(std::nothrow) SensorParams(); + if (params == nullptr) { + return undefValue; + } + params->thisVal = JSI::AcquireValue(thisVal); + if (args != nullptr) { + params->args = JSI::AcquireValue(args[0]); + } + JsAsyncWork::DispatchAsyncWork(ExecuteFunc, reinterpret_cast(params)); + return undefValue; +} + +JSIValue SensorModule::SubscribeStepCounter(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteSubscribeStepCounter); +} + +JSIValue SensorModule::UnsubscribeStepCounter(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteUnsubscribeStepCounter); +} + +JSIValue SensorModule::SubscribeBarometer(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteSubscribeBarometer); +} + +JSIValue SensorModule::UnsubscribeBarometer(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteUnsubscribeBarometer); +} + +JSIValue SensorModule::SubscribeHeartRate(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteSubscribeHeartRate); +} + +JSIValue SensorModule::UnsubscribeHeartRate(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteUnsubscribeHeartRate); +} + +JSIValue SensorModule::SubscribeOnBodyState(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteSubscribeOnBodyState); +} + +JSIValue SensorModule::UnsubscribeOnBodyState(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteUnsubscribeOnBodyState); +} + +JSIValue SensorModule::GetOnBodyState(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteGetOnBodyState); +} + +} // namespace ACELite +} // namespace OHOS diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/sensor_module.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/sensor_module.h new file mode 100644 index 000000000..66e7f8882 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/sensor_module.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ACELITE_SENSOR_MODULE_H +#define OHOS_ACELITE_SENSOR_MODULE_H + +#include +#include "acelite_config.h" +#include "jsi.h" +#include "js_async_work.h" +#include "non_copyable.h" +#include "product_adapter.h" +#include "abilityms_slite_client.h" + +namespace OHOS { +namespace ACELite { + +struct SensorParams { + JSIValue args = JSI::CreateUndefined(); + JSIValue thisVal = JSI::CreateUndefined(); +}; + +class SensorModule final : public MemoryHeap { +public: + ACE_DISALLOW_COPY_AND_MOVE(SensorModule); + SensorModule() = default; + ~SensorModule() = default; + static const char * const STEPS; + static const uint32_t DEFAULT_STEPS; + static const char * const PRESSURE; + static const uint32_t DEFAULT_PRESSURE; + static const char * const HEARTRATE; + static const uint32_t DEFAULT_HEARTRATE; + static const char * const ISONBODY; + static const bool DEFAULT_ISONBODY; + static JSIValue SubscribeStepCounter(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); + static JSIValue UnsubscribeStepCounter(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); + static JSIValue SubscribeBarometer(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); + static JSIValue UnsubscribeBarometer(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); + static JSIValue SubscribeHeartRate(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); + static JSIValue UnsubscribeHeartRate(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); + static JSIValue SubscribeOnBodyState(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); + static JSIValue UnsubscribeOnBodyState(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); + static JSIValue GetOnBodyState(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); + +private: + static JSIValue ExecuteAsyncWork(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum, AsyncWorkHandler ExecuteFunc); + static void SuccessCallBack(const JSIValue thisVal, const JSIValue args, JSIValue jsiValue, bool flag); + static void FailCallBack(const JSIValue thisVal, const JSIValue args, int ret, bool flag); + static void ExecuteSubscribeStepCounter(void *data); + static void ExecuteUnsubscribeStepCounter(void *data); + static void ExecuteSubscribeBarometer(void *data); + static void ExecuteUnsubscribeBarometer(void *data); + static void ExecuteSubscribeHeartRate(void *data); + static void ExecuteUnsubscribeHeartRate(void *data); + static void ExecuteSubscribeOnBodyState(void *data); + static void ExecuteUnsubscribeOnBodyState(void *data); + static void ExecuteGetOnBodyState(void *data); + +}; + +void InitSensorModule(JSIValue exports) +{ + JSI::SetModuleAPI(exports, "subscribeStepCounter", SensorModule::SubscribeStepCounter); + JSI::SetModuleAPI(exports, "unsubscribeStepCounter", SensorModule::UnsubscribeStepCounter); + JSI::SetModuleAPI(exports, "subscribeBarometer", SensorModule::SubscribeBarometer); + JSI::SetModuleAPI(exports, "unsubscribeBarometer", SensorModule::UnsubscribeBarometer); + JSI::SetModuleAPI(exports, "subscribeHeartRate", SensorModule::SubscribeHeartRate); + JSI::SetModuleAPI(exports, "unsubscribeHeartRate", SensorModule::UnsubscribeHeartRate); + JSI::SetModuleAPI(exports, "subscribeOnBodyState", SensorModule::SubscribeOnBodyState); + JSI::SetModuleAPI(exports, "unsubscribeOnBodyState", SensorModule::UnsubscribeOnBodyState); + JSI::SetModuleAPI(exports, "getOnBodyState", SensorModule::GetOnBodyState); +} + +} // namespace ACELite +} // namespace OHOS +#endif // OHOS_ACELITE_APP_MODULE_H diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/vibrator_module.cpp b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/vibrator_module.cpp new file mode 100644 index 000000000..421f4c710 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/vibrator_module.cpp @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include "ace_log.h" +#include "js_app_context.h" +#include "js_async_work.h" +#include "product_adapter.h" +#include +#include "vibrator_module.h" +#include "media_log.h" +#include "global.h" +#include "screen.h" + +namespace OHOS { +namespace ACELite { + +const char * const VibratorModule::VIBTATOR_MODE = "mode"; + +JSIValue VibratorModule::Vibrate(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum) +{ + return ExecuteAsyncWork(thisVal, args, argsNum, ExecuteVibrate); +} + +JSIValue VibratorModule::ExecuteAsyncWork(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum, AsyncWorkHandler ExecuteFunc) +{ + JSIValue undefValue = JSI::CreateUndefined(); + if ((args == nullptr) || (argsNum == 0) || (JSI::ValueIsUndefined(args[0]))) { + HILOG_ERROR(HILOG_MODULE_ACE, "Error in obtaining device information parameters"); + return undefValue; + } + VibratorParams* params = new(std::nothrow) VibratorParams(); + if (params == nullptr) { + return undefValue; + } + params->thisVal = JSI::AcquireValue(thisVal); + params->args = JSI::AcquireValue(args[0]); + JsAsyncWork::DispatchAsyncWork(ExecuteFunc, reinterpret_cast(params)); + return undefValue; +} + +void VibratorModule::ExecuteVibrate(void* data) +{ + VibratorParams* params = reinterpret_cast(data); + if (params == nullptr) { + return; + } + JSIValue args = params->args; + JSIValue thisVal = params->thisVal; + JSIValue result = JSI::CreateObject(); + char* mode = JSI::GetStringProperty(args, VIBTATOR_MODE); + if (strcmp(mode, "long") == 0|| strcmp(mode, "short") == 0) { + SuccessCallBack(thisVal, args, result); + } else { + FailCallBack(thisVal, args, -1); + } + + JSI::ReleaseValueList(args, thisVal, result, ARGS_END); + delete params; +} + +void VibratorModule::SuccessCallBack(const JSIValue thisVal, const JSIValue args, JSIValue jsiValue) +{ + if (JSI::ValueIsUndefined(args)) { + return; + } + JSIValue success = JSI::GetNamedProperty(args, CB_SUCCESS); + JSIValue complete = JSI::GetNamedProperty(args, CB_COMPLETE); + if (!JSI::ValueIsUndefined(success)) { + if (JSI::ValueIsUndefined(jsiValue)) { + JSI::CallFunction(success, thisVal, nullptr, 0); + } else { + JSI::CallFunction(success, thisVal, &jsiValue, ARGC_ONE); + } + } + if (!JSI::ValueIsUndefined(complete)) { + JSI::CallFunction(complete, thisVal, nullptr, 0); + } + JSI::ReleaseValueList(success, complete, ARGS_END); +} + +void VibratorModule::FailCallBack(const JSIValue thisVal, const JSIValue args, int ret) +{ + if (JSI::ValueIsUndefined(args)) { + return; + } + JSIValue errInfo; + errInfo = JSI::CreateString("Vibrator faild"); + JSIValue errCode = JSI::CreateNumber(ret); + JSIValue fail = JSI::GetNamedProperty(args, CB_FAIL); + JSIValue complete = JSI::GetNamedProperty(args, CB_COMPLETE); + JSIValue argv[ARGC_TWO] = {errInfo, errCode}; + if (!JSI::ValueIsUndefined(fail)) { + JSI::CallFunction(fail, thisVal, argv, ARGC_TWO); + } + if (!JSI::ValueIsUndefined(complete)) { + JSI::CallFunction(complete, thisVal, nullptr, 0); + } + JSI::ReleaseValueList(fail, complete, errInfo, errCode, ARGS_END); +} + +} // namespace ACELite +} // namespace OHOS diff --git a/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/vibrator_module.h b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/vibrator_module.h new file mode 100644 index 000000000..3def06107 --- /dev/null +++ b/code/sdk/open_source/openharmony/foundation/ace/ace_engine_lite/modules/vibrator_module.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_ACELITE_VIBRATOR_MODULE_H +#define OHOS_ACELITE_VIBRATOR_MODULE_H + +#include +#include "acelite_config.h" +#include "jsi.h" +#include "js_async_work.h" +#include "non_copyable.h" +#include "product_adapter.h" +#include "abilityms_slite_client.h" + +namespace OHOS { +namespace ACELite { + +struct VibratorParams { + JSIValue args = JSI::CreateUndefined(); + JSIValue thisVal = JSI::CreateUndefined(); +}; + +class VibratorModule final : public MemoryHeap { +public: + ACE_DISALLOW_COPY_AND_MOVE(VibratorModule); + VibratorModule() = default; + ~VibratorModule() = default; + static const char * const VIBTATOR_MODE; + static JSIValue Vibrate(const JSIValue thisVal, const JSIValue *args, uint8_t argsNum); + +private: + static JSIValue ExecuteAsyncWork(const JSIValue thisVal, const JSIValue* args, uint8_t argsNum, AsyncWorkHandler ExecuteFunc); + static void SuccessCallBack(const JSIValue thisVal, const JSIValue args, JSIValue jsiValue); + static void FailCallBack(const JSIValue thisVal, const JSIValue args, int ret); + static void ExecuteVibrate(void *data); + +}; + +void InitVibratorModule(JSIValue exports) +{ + JSI::SetModuleAPI(exports, "vibrate", VibratorModule::Vibrate); +} + +} // namespace ACELite +} // namespace OHOS +#endif // OHOS_ACELITE_APP_MODULE_H diff --git a/code/sdk/open_source/openharmony/third_party/jerryscript/CMakeLists.txt b/code/sdk/open_source/openharmony/third_party/jerryscript/CMakeLists.txt index 0648d1d11..a0dc84a92 100644 --- a/code/sdk/open_source/openharmony/third_party/jerryscript/CMakeLists.txt +++ b/code/sdk/open_source/openharmony/third_party/jerryscript/CMakeLists.txt @@ -281,7 +281,7 @@ set(PUBLIC_DEFINES ) set(PRIVATE_DEFINES - JERRY_GLOBAL_HEAP_SIZE=128 + JERRY_GLOBAL_HEAP_SIZE=512 JERRY_ERROR_MESSAGES=1 JERRY_LINE_INFO=1 JERRY_FUNCTION_NAME diff --git a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-native-js/libjerryscript.a b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-native-js/libjerryscript.a index 9d650b590..0eb9f5921 100644 Binary files a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-native-js/libjerryscript.a and b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-native-js/libjerryscript.a differ diff --git a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-xts/libjerryscript.a b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-xts/libjerryscript.a index fc64215d9..732f3c970 100644 Binary files a/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-xts/libjerryscript.a and b/code/sdk/open_source/openharmony/third_party/jerryscript/brandy-xts/libjerryscript.a differ diff --git a/code/sdk/protocol/bt/host/bt/bts/bg_common/include/ahi_common/mpc_code_def.h b/code/sdk/protocol/bt/host/bt/bts/bg_common/include/ahi_common/mpc_code_def.h index 34e7c9cbe..3278af05f 100644 --- a/code/sdk/protocol/bt/host/bt/bts/bg_common/include/ahi_common/mpc_code_def.h +++ b/code/sdk/protocol/bt/host/bt/bts/bg_common/include/ahi_common/mpc_code_def.h @@ -331,6 +331,7 @@ typedef enum { MC_BT_SRV_A2DP_RPT_STREAM_REJECT, MC_BT_SRV_A2DP_STREAM_START_ACCEPT, MC_BT_SRV_A2DP_SNK_UNREGISTER_SERVICE, + MC_BT_SRV_A2DP_SNK_REGISTER_SERVICE, MC_BT_SRC_A2DP_MAX, } mc_bt_a2dp_command_type; diff --git a/code/sdk/protocol/bt/host/bt/bts/sdk/inc/stack_api/stack_av_if.h b/code/sdk/protocol/bt/host/bt/bts/sdk/inc/stack_api/stack_av_if.h index 300099826..ea337a9df 100644 --- a/code/sdk/protocol/bt/host/bt/bts/sdk/inc/stack_api/stack_av_if.h +++ b/code/sdk/protocol/bt/host/bt/bts/sdk/inc/stack_api/stack_av_if.h @@ -448,6 +448,7 @@ int32_t btsdk_a2dp_set_audio_shmid(uint32_t stream_hdl, bool enable, uint32_t sh int32_t btsdk_a2dp_stream_start(void *stream_hdl); int32_t btsdk_a2dp_stream_suspend(void *stream_hdl); int32_t a2dp_src_set_stream_codec_req(bool reconfig, const void *stream_hdl, const void *cfg, uint32_t size); +int32_t btsdk_registera2dpsnk_service(uint16_t len, const uint8_t *audio_card); int32_t btsdk_unregistera2dpsnk_service(void); void btsdk_a2dp_reg_cbk(const btsdka2dp_cbk *a2dp_cbk); void btsdk_a2dp_snk_reg_cbk(const btsdka2dp_cbk *a2dp_cbk); diff --git a/code/sdk/tools/pkg/bin/brandy/bt.bin b/code/sdk/tools/pkg/bin/brandy/bt.bin index 35bf53b0c..d74338701 100644 Binary files a/code/sdk/tools/pkg/bin/brandy/bt.bin and b/code/sdk/tools/pkg/bin/brandy/bt.bin differ diff --git a/jsapp/baidu_voiceassistant/.gradle/6.3/fileChanges/last-build.bin b/jsapp/baidu_voiceassistant/.gradle/6.3/fileChanges/last-build.bin new file mode 100644 index 000000000..f76dd238a Binary files /dev/null and b/jsapp/baidu_voiceassistant/.gradle/6.3/fileChanges/last-build.bin differ diff --git a/jsapp/baidu_voiceassistant/.gradle/6.3/fileHashes/fileHashes.lock b/jsapp/baidu_voiceassistant/.gradle/6.3/fileHashes/fileHashes.lock new file mode 100644 index 000000000..2ef8a38f7 Binary files /dev/null and b/jsapp/baidu_voiceassistant/.gradle/6.3/fileHashes/fileHashes.lock differ diff --git a/jsapp/baidu_voiceassistant/.gradle/6.3/gc.properties b/jsapp/baidu_voiceassistant/.gradle/6.3/gc.properties new file mode 100644 index 000000000..e69de29bb diff --git a/jsapp/baidu_voiceassistant/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/jsapp/baidu_voiceassistant/.gradle/buildOutputCleanup/buildOutputCleanup.lock new file mode 100644 index 000000000..ce8036ad7 Binary files /dev/null and b/jsapp/baidu_voiceassistant/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/jsapp/baidu_voiceassistant/.gradle/buildOutputCleanup/cache.properties b/jsapp/baidu_voiceassistant/.gradle/buildOutputCleanup/cache.properties new file mode 100644 index 000000000..99e10f1ca --- /dev/null +++ b/jsapp/baidu_voiceassistant/.gradle/buildOutputCleanup/cache.properties @@ -0,0 +1,2 @@ +#Tue Aug 27 08:59:29 CST 2024 +gradle.version=6.3 diff --git a/jsapp/baidu_voiceassistant/.gradle/checksums/checksums.lock b/jsapp/baidu_voiceassistant/.gradle/checksums/checksums.lock new file mode 100644 index 000000000..243f2ee24 Binary files /dev/null and b/jsapp/baidu_voiceassistant/.gradle/checksums/checksums.lock differ diff --git a/jsapp/baidu_voiceassistant/.gradle/checksums/md5-checksums.bin b/jsapp/baidu_voiceassistant/.gradle/checksums/md5-checksums.bin new file mode 100644 index 000000000..9e59259bc Binary files /dev/null and b/jsapp/baidu_voiceassistant/.gradle/checksums/md5-checksums.bin differ diff --git a/jsapp/baidu_voiceassistant/.gradle/checksums/sha1-checksums.bin b/jsapp/baidu_voiceassistant/.gradle/checksums/sha1-checksums.bin new file mode 100644 index 000000000..23856926a Binary files /dev/null and b/jsapp/baidu_voiceassistant/.gradle/checksums/sha1-checksums.bin differ diff --git a/jsapp/baidu_voiceassistant/.gradle/vcs-1/gc.properties b/jsapp/baidu_voiceassistant/.gradle/vcs-1/gc.properties new file mode 100644 index 000000000..e69de29bb diff --git a/patch_0626_to_0720.txt b/patch_0626_to_0720.txt new file mode 100644 index 000000000..c566e9f40 --- /dev/null +++ b/patch_0626_to_0720.txt @@ -0,0 +1,58 @@ +【补丁名称】patch_0626_to_0720 +【基础版本】b602 + 0521 + 0626 +【修复问题】 +BT合入内容 + 1、解决【spp client被动断连死锁】问题 + 2、解决【B核内存维测缺少空判断】问题 + 3、解决【数传和音乐日志打印过多】问题 + 4、B核日志精简 + 5、B核上电超时主动panic +PLT合入内容 + 1、ssb支持mmc资源烧录,分区顺序调整 + 2、修复NV异步存储不可升级属性更改为可升级属性失败问题 + 3、ipc异常场景自愈处理 + 4、支持死机trace保存到norflash + 5、解决nandflash写断流问题 + 6、SystemView适配 +GUI合入内容 + 1、修复亮屏局刷问题 + 2、修复足球图片镜像问题 + 3、修复ImageCacheManager资源加载问题 + 4、修复离线表盘资源释放及视频相关问题 + 5、修复UICrossView调用不匹配,对齐动画卡顿,快速拖动等问题 + 6、支持帧耗时统计 + 7、支持UIList阻尼效果 + 8、支持Dump控件树信息 + 9、TurnPage效果内存优化 + 10、UIPicker重写焦点相关函数 + 11、增加DFX打印NativeUI状态 + 12、修复资源加载问题 +GPU合入内容 + 1、贝塞尔阈值,保持进出低功耗前后寄存器值一致 + 2、屏蔽TE中断 +AUDIO&MEDIA合入内容 + 1、修改视频播放自动停止再起播,重复几次导致线程创建失败的问题 + 2、把小度语音的录制线程改成同步,防止在反复录制的时候,出现时序的问题 + 3、把线程使用的内存改到psram上面,以让出DTCM的内存空间 +OHOS合入内容 + 1、新增泄露定时器清理方法。 + 2、新增JS应用内对HOME键的响应。 + 3、Notify 清理函数改为注册方式。 + 4、新增 brightness、battery、sensor、Vibrator Js接口自测用例。 + 5、新增 AT命令两个:根据包名起JS应用、强切native应用。 + 6、Baidumap消息函数新增返回值。 + 7、地图,新增百度协议,JS主动发起退出导航。 + 8、修复定时器泄露问题。 + 9、新增编码器旋转事件支持。 + 10、修复JSapp切换表盘大概率卡住黑屏问题。 +【修改影响】NA +【使用方法】 + 1、合入0521补丁 + 2、合入0626补丁 + 3、合入0720补丁 +【自测情况】 + 自验证范围: + 全功能冒烟 + 自验证target: + Native-js、target3 rc版本 +【是否合入版本】根据测试结果确定