• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 FuZhou Lockzhiner Electronic Co., Ltd. All rights reserved.
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 
16 #include "nfc.h"
17 #include "los_task.h"
18 #include "ohos_init.h"
19 
20 /* 任务的堆栈大小 */
21 #define TASK_STACK_SIZE     10240
22 /* 任务的优先级 */
23 #define TASK_PRIO           24
24 
25 /* 循环等待时间 */
26 #define WAIT_MSEC           1000
27 
28 #define TEXT        "XiaoZhiPai!"
29 #define WEB         "fzlzdz.com"
30 
31 /***************************************************************
32 * 函数名称: nfc_process
33 * 说    明: nfc例程
34 * 参    数: 无
35 * 返 回 值: 无
36 ***************************************************************/
nfc_process(void)37 void nfc_process(void)
38 {
39     unsigned int ret = 0;
40 
41     /* 初始化NFC设备 */
42     nfc_init();
43 
44     ret = nfc_store_text(NDEFFirstPos, (uint8_t *)TEXT);
45     if (ret != 1) {
46         printf("NFC Write Text Failed: %d\n", ret);
47     }
48 
49     ret = nfc_store_uri_http(NDEFLastPos, (uint8_t *)WEB);
50     if (ret != 1) {
51         printf("NFC Write Url Failed: %d\n", ret);
52     }
53 
54     while (1) {
55         printf("==============NFC Example==============\r\n");
56         printf("Please use the mobile phone with NFC function close to the development board!\r\n");
57         printf("\n\n");
58         LOS_Msleep(WAIT_MSEC);
59     }
60 }
61 
62 
63 /***************************************************************
64 * 函数名称: nfc_example
65 * 说    明: 开机自启动调用函数
66 * 参    数: 无
67 * 返 回 值: 无
68 ***************************************************************/
nfc_example(void)69 void nfc_example(void)
70 {
71     unsigned int thread_id;
72     TSK_INIT_PARAM_S task = {0};
73     unsigned int ret = LOS_OK;
74 
75     task.pfnTaskEntry = (TSK_ENTRY_FUNC)nfc_process;
76     task.uwStackSize = TASK_STACK_SIZE;
77     task.pcName = "nfc process";
78     task.usTaskPrio = TASK_PRIO;
79     ret = LOS_TaskCreate(&thread_id, &task);
80     if (ret != LOS_OK) {
81         printf("Falied to create task ret:0x%x\n", ret);
82         return;
83     }
84 }
85 
86 
87 APP_FEATURE_INIT(nfc_example);
88