• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15  * Description: Provides SFC sample source \n
16  *
17  * History: \n
18  * 2024-03-04, Create file. \n
19  */
20 #include "soc_osal.h"
21 #include "securec.h"
22 #include "sfc.h"
23 #include "sfc_porting.h"
24 #include "app_init.h"
25 #include "memory_config_common.h"
26 
27 #define SFC_TASK_PRIO                   24
28 #define SFC_TASK_STACK_SIZE             0x1000
29 #define SFC_SAMPLE_LEN                  0x80000
30 #define SFC_PRINT_BUFF_LEN              32
31 uint8_t g_print_data_buff[SFC_PRINT_BUFF_LEN] = {0};
32 uint8_t g_write_data_buff[SFC_PRINT_BUFF_LEN] = {0};
33 
sfc_sample_start_api_test(void)34 static void sfc_sample_start_api_test(void)
35 {
36     osal_printk("API test start\r\n");
37     uint32_t remained_len = CONFIG_SFC_SAMPLE_USER_SIZE;
38     uint32_t start_addr = CONFIG_SFC_SAMPLE_USER_ADDR;
39     while (remained_len > 0) {
40         uint32_t cur_len = remained_len > SFC_PRINT_BUFF_LEN ? SFC_PRINT_BUFF_LEN : remained_len;
41         uapi_sfc_reg_read(start_addr, g_print_data_buff, cur_len);
42         for (uint8_t i = 0; i < cur_len; i++) {
43             osal_printk("%02x ", g_print_data_buff[i]);
44         }
45         uapi_sfc_reg_write(start_addr, g_write_data_buff, cur_len);
46         start_addr += cur_len;
47         remained_len -= cur_len;
48         osal_printk("\r\n");
49     }
50     start_addr = CONFIG_SFC_SAMPLE_USER_ADDR;
51     remained_len = CONFIG_SFC_SAMPLE_USER_SIZE;
52     while (remained_len > 0) {
53         uint32_t cur_len = remained_len > SFC_PRINT_BUFF_LEN ? SFC_PRINT_BUFF_LEN : remained_len;
54         uapi_sfc_reg_read(start_addr, g_print_data_buff, cur_len);
55         for (uint8_t i = 0; i < cur_len; i++) {
56             osal_printk("%02x ", g_print_data_buff[i]);
57         }
58         start_addr += cur_len;
59         remained_len -= cur_len;
60         osal_printk("\r\n");
61     }
62 }
63 
sfc_task(const char * arg)64 static void *sfc_task(const char *arg)
65 {
66     unused(arg);
67     for (uint8_t i = 0; i < SFC_PRINT_BUFF_LEN; i++) {
68         g_write_data_buff[i] = i;
69     }
70     /* Erase User space */
71     osal_printk("Erasing for API sample...\r\n");
72     errcode_t ret = uapi_sfc_reg_erase(CONFIG_SFC_SAMPLE_USER_ADDR, CONFIG_SFC_SAMPLE_USER_SIZE);
73     if (ret != ERRCODE_SUCC) {
74         osal_printk("flash erase failed! ret = %x\r\n", ret);
75         return NULL;
76     }
77     osal_printk("Start API read sample...\r\n");
78     sfc_sample_start_api_test();
79     return NULL;
80 }
81 
sfc_entry(void)82 static void sfc_entry(void)
83 {
84     osal_task *task_handle = NULL;
85     osal_kthread_lock();
86     task_handle = osal_kthread_create((osal_kthread_handler)sfc_task, 0, "SFCTask", SFC_TASK_STACK_SIZE);
87     if (task_handle != NULL) {
88         osal_kthread_set_priority(task_handle, SFC_TASK_PRIO);
89         osal_kfree(task_handle);
90     }
91     osal_kthread_unlock();
92 }
93 
94 /* Run the spi_master_entry. */
95 app_run(sfc_entry);