• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 Copyright (C) 2024 HiHope Open Source Organization .
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 
18 #include <unistd.h>
19 
20 #include "cmsis_os2.h"
21 #include "ohos_init.h"
22 #include "iot_gpio.h"
23 
24 #define LED_TASK_GPIO 10
25 #define LED_TASK_STACK_SIZE 0x1000
26 #define LED_TASK_PRIO 25
27 
GpioTask(const char * arg)28 static void *GpioTask(const char *arg)
29 {
30     (void) arg;
31 
32     IoTGpioInit(LED_TASK_GPIO);
33     IoTGpioSetDir(LED_TASK_GPIO, IOT_GPIO_DIR_OUT);
34     uint32_t counter  = 0;
35     uint32_t running = 1;
36     while (running) {
37         printf(" LED_SPARK! \n");
38         IoTGpioSetOutputVal(LED_TASK_GPIO, 0);
39         osDelay(50);
40         IoTGpioSetOutputVal(LED_TASK_GPIO, 1);
41         osDelay(50);
42 
43         counter++;
44         if (counter >= 100) {
45             running = 0;
46         }
47     }
48     return NULL;
49 }
50 
GpioExampleEntry(void)51 static void GpioExampleEntry(void)
52 {
53     osThreadAttr_t attr;
54 
55     attr.name = "GpioTask";
56     attr.attr_bits = 0U;
57     attr.cb_mem = NULL;
58     attr.cb_size = 0U;
59     attr.stack_mem = NULL;
60     attr.stack_size = LED_TASK_STACK_SIZE;
61     attr.priority = LED_TASK_PRIO;
62 
63     if (osThreadNew((osThreadFunc_t) GpioTask, NULL, &attr) == NULL) {
64         printf("[GpioExample] Falied to create GpioTask!\n");
65     }
66 }
67 
68 SYS_RUN(GpioExampleEntry); // if test add it
69