1 /* 2 * Copyright (c) 2022 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 16 #include <stdio.h> 17 #include <unistd.h> 18 #include "ohos_init.h" 19 #include "cmsis_os2.h" 20 #include "iot_gpio.h" 21 #include "iot_watchdog.h" 22 #include "hi_io.h" 23 24 25 #define IOT_GPIO_IDX_10 10 // for hispark_pegasus 26 LedCntrolDemo(const char *arg)27static void *LedCntrolDemo(const char *arg) 28 { 29 (void)arg; 30 printf("LedTask start\r\n"); 31 // 配置GPIO引脚号和输出值 32 IoTGpioSetOutputVal(IOT_GPIO_IDX_10, IOT_GPIO_VALUE1); 33 return NULL; 34 } 35 LedControlTask(void)36static void LedControlTask(void) 37 { 38 osThreadAttr_t attr; 39 // 初始化GPIO 40 IoTGpioInit(IOT_GPIO_IDX_10); 41 // 设置GPIO为输出方向 42 IoTGpioSetDir(IOT_GPIO_IDX_10, IOT_GPIO_DIR_OUT); 43 44 attr.name = "LedCntrolDemo"; 45 attr.attr_bits = 0U; 46 attr.cb_mem = NULL; 47 attr.cb_size = 0U; 48 attr.stack_mem = NULL; 49 attr.stack_size = 1024; /* 堆栈大小为1024 */ 50 attr.priority = osPriorityNormal; 51 // 报错 52 if (osThreadNew((osThreadFunc_t)LedCntrolDemo, NULL, &attr) == NULL) { 53 printf("[LedExample] Failed to create LedTask!\n"); 54 } 55 } 56 57 SYS_RUN(LedControlTask); 58