1 /*
2 * Copyright (c) 2020 Nanjing Xiaoxiongpai Intelligent Technology Co., Ltd.
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 <stdio.h>
17 #include <unistd.h>
18
19 #include "cmsis_os2.h"
20 #include "iot_gpio.h"
21 #include "ohos_init.h"
22
23 #define LED_TASK_STACK_SIZE (1024 * 4)
24 #define LED_TASK_PRIO 25
25 #define LED_GPIO 2
26
27 /**
28 * @brief led task output high and low levels to turn on and off LED
29 *
30 */
LedTask(void)31 static void LedTask(void)
32 {
33 // init gpio of LED
34 IoTGpioInit(LED_GPIO);
35
36 // set GPIO_2 is output mode
37 IoTGpioSetDir(LED_GPIO, IOT_GPIO_DIR_OUT);
38
39 while (1) {
40 // set GPIO_2 output high levels to turn on LED
41 IoTGpioSetOutputVal(LED_GPIO, 1);
42
43 // delay 1s
44 sleep(1);
45
46 // set GPIO_2 output low levels to turn off LED
47 IoTGpioSetOutputVal(LED_GPIO, 0);
48
49 // delay 1s
50 sleep(1);
51 }
52 }
53
54 /**
55 * @brief Main Entry of the Led Example
56 *
57 */
LedExampleEntry(void)58 static void LedExampleEntry(void)
59 {
60 osThreadAttr_t attr;
61
62 attr.name = "LedTask";
63 attr.attr_bits = 0U;
64 attr.cb_mem = NULL;
65 attr.cb_size = 0U;
66 attr.stack_mem = NULL;
67 attr.stack_size = LED_TASK_STACK_SIZE;
68 attr.priority = LED_TASK_PRIO;
69
70 if (osThreadNew((osThreadFunc_t)LedTask, NULL, &attr) == NULL) {
71 printf("Failed to create LedTask!\n");
72 }
73 }
74
75 APP_FEATURE_INIT(LedExampleEntry);