赞
踩
#include <stdio.h> #include <unistd.h> #include "ohos_init.h" #include "cmsis_os2.h" #include "wifiiot_gpio.h" #include "wifiiot_gpio_ex.h" osThreadId_t thread1_id; osThreadId_t thread2_id; void thread1(void) { int sum = 0; while(1) { printf("This is BearPi Harmony Thread1----%d\r\n", sum++); usleep(1000000); } } void thread2(void) { int sum = 0; while(1) { printf("This is BearPi Harmony Thread2----%d\r\n", sum++); usleep(500000); } } void my_led_example(void) { GpioInit(); IoSetFunc(WIFI_IOT_IO_NAME_GPIO_2,WIFI_IOT_IO_FUNC_GPIO_2_GPIO); GpioSetDir(WIFI_IOT_IO_NAME_GPIO_2,WIFI_IOT_GPIO_DIR_OUT); osThreadAttr_t attr; attr.name = "thread1"; attr.attr_bits = 0U; attr.cb_mem = NULL; attr.cb_size = 0U; attr.stack_mem = NULL; attr.stack_size = 1024 * 4; attr.priority = 25; if (osThreadNew((osThreadFunc_t)thread1, NULL, &attr) == NULL) { printf("Falied to create thread1!\n"); } attr.name = "thread2"; if (osThreadNew((osThreadFunc_t)thread2, NULL, &attr) == NULL) { printf("Falied to create thread2!\n"); } } APP_FEATURE_INIT(my_led_example);
static_library("myled") {
sources = [
"myled.c"
]
include_dirs = [
"//utils/native/lite/include",
"//kernel/liteos_m/components/cmsis/2.0",
"//base/iot_hardware/interfaces/kits/wifiiot_lite",
"//kernel/liteos_m/components/cmsis/2.0",
]
}
#include <stdio.h> #include <unistd.h> #include "ohos_init.h" #include "cmsis_os2.h" #include "wifiiot_gpio.h" #include "wifiiot_gpio_ex.h" osThreadId_t thread1_id; osThreadId_t thread2_id; void thread1(void) { printf("enter hread1,hi priority\r\n"); osDelay(1); printf("\r\nthread1 delay done\r\n"); osThreadSuspend(thread1_id); printf("\r\nthread1 osThreadResume success\r\n"); osThreadTerminate(thread1_id); } void thread2(void) { for(int i=0; i<10; i++) { printf("\r\nenter thread2,lo priority\r\n"); } printf("\r\nthread1 osThreadSuspend success\r\n"); osThreadResume(thread1_id); osThreadTerminate(thread2_id); } void my_led_example(void) { GpioInit(); IoSetFunc(WIFI_IOT_IO_NAME_GPIO_2,WIFI_IOT_IO_FUNC_GPIO_2_GPIO); GpioSetDir(WIFI_IOT_IO_NAME_GPIO_2,WIFI_IOT_GPIO_DIR_OUT); osThreadAttr_t attr; attr.name = "thread1"; attr.attr_bits = 0U; attr.cb_mem = NULL; attr.cb_size = 0U; attr.stack_mem = NULL; attr.stack_size = 1024 * 4; attr.priority = 25; thread1_id = osThreadNew((osThreadFunc_t)thread1, NULL, &attr); if (thread1_id == NULL) { printf("Falied to create thread1!\n"); } attr.name = "thread2"; attr.priority = 24; thread2_id = osThreadNew((osThreadFunc_t)thread2, NULL, &attr) ; if (thread2_id == NULL) { printf("Falied to create thread2!\n"); } } SYS_RUN(my_led_example);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。