first commit
This commit is contained in:
5
application/samples/peripheral/uflash/CMakeLists.txt
Executable file
5
application/samples/peripheral/uflash/CMakeLists.txt
Executable file
@ -0,0 +1,5 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
set(SOURCES "${SOURCES}" "${CMAKE_CURRENT_SOURCE_DIR}/hfuflash_demo.c" PARENT_SCOPE)
|
94
application/samples/peripheral/uflash/hfuflash_demo.c
Executable file
94
application/samples/peripheral/uflash/hfuflash_demo.c
Executable file
@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
*
|
||||
* Description: WDT Sample Source. \n
|
||||
*
|
||||
* History: \n
|
||||
* 2023-06-29, Create file. \n
|
||||
*/
|
||||
#include "hsf.h"
|
||||
#define UFLASH_TASK_STACK_SIZE 0x1000
|
||||
USER_FUNC int test_uflash_one_page(uint32_t addr)
|
||||
{
|
||||
static char test_data[4096];
|
||||
int i;
|
||||
|
||||
hfuflash_erase_page(addr,1);
|
||||
memset(test_data, 0, sizeof(test_data));
|
||||
hfuflash_read(addr,test_data,4096);
|
||||
for(i=0;i<4096;i++)
|
||||
{
|
||||
if(test_data[i]!=0xFF)
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(test_data,0x55,4096);
|
||||
hfuflash_write(addr,test_data,4096);
|
||||
memset(test_data, 0, sizeof(test_data));
|
||||
hfuflash_read(addr,test_data,4096);
|
||||
for(i=0;i<4096;i++)
|
||||
{
|
||||
if(test_data[i]!=0x55)
|
||||
return 2;
|
||||
}
|
||||
|
||||
memset(test_data,0xAA,4096);
|
||||
hfuflash_erase_page(addr,1);
|
||||
hfuflash_write(addr,test_data,4096);
|
||||
memset(test_data, 0, sizeof(test_data));
|
||||
hfuflash_read(addr,test_data,4096);
|
||||
for(i=0;i<4096;i++)
|
||||
{
|
||||
if(test_data[i]!=0xAA)
|
||||
return 3;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
USER_FUNC int test_uflash(void)
|
||||
{
|
||||
uint32_t addr = 0;
|
||||
for(addr=0; addr<hfuflash_size(); addr+=4096)
|
||||
{
|
||||
if(test_uflash_one_page(addr))
|
||||
{
|
||||
u_printf("addr = 0x%x failed\r\n", addr);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *uflash_task(const char *arg)
|
||||
{
|
||||
UNUSED(arg);
|
||||
int i, fail_times = 0;
|
||||
u_printf("\r\n****************************************************\r\n");
|
||||
u_printf(" TIMES OK FAIL \r\n\r\n");
|
||||
for(i=0; i<1000; i++)
|
||||
{
|
||||
if(test_uflash() != 0)
|
||||
{
|
||||
fail_times++;
|
||||
}
|
||||
u_printf("\r %05d %05d %05d", i+1, i+1-fail_times, fail_times);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void hfuflash_entry(void)
|
||||
{
|
||||
osal_task *task_handle = NULL;
|
||||
osal_kthread_lock();
|
||||
task_handle = osal_kthread_create((osal_kthread_handler)uflash_task, 0, "uflashTask", UFLASH_TASK_STACK_SIZE);
|
||||
if (task_handle != NULL) {
|
||||
osal_kthread_set_priority(task_handle, WDT_TASK_PRIO);
|
||||
osal_kfree(task_handle);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
}
|
||||
|
||||
/* Run the watchdog_entry. */
|
||||
app_run(hfuflash_entry);
|
Reference in New Issue
Block a user