1 /* 2 * Copyright (c) 2020 Huawei Device 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 "demosdk_adapter.h" 17 #include <stdio.h> 18 19 #include "cmsis_os2.h" 20 21 #define MS_CNT 1000 22 DemoSdkCreateTask(unsigned int *handle, const struct TaskPara *para)23int DemoSdkCreateTask(unsigned int *handle, const struct TaskPara *para) 24 { 25 osThreadAttr_t attr = {0}; 26 osThreadId_t threadId; 27 if (handle == 0 || para == 0) { 28 return DEMOSDK_ERR; 29 } 30 31 if (para->func == 0) { 32 return DEMOSDK_ERR; 33 } 34 35 if (para->name == 0) { 36 return DEMOSDK_ERR; 37 } 38 39 attr.name = para->name; 40 attr.priority = para->prio; 41 attr.stack_size = para->size; 42 threadId = osThreadNew((osThreadFunc_t)para->func, para->arg, &attr); 43 if (threadId == 0) { 44 printf("osThreadNew fail\n"); 45 return DEMOSDK_ERR; 46 } 47 48 *(unsigned int *)handle = (unsigned int)threadId; 49 return DEMOSDK_OK; 50 } 51 DemoSdkSleepMs(int ms)52void DemoSdkSleepMs(int ms) 53 { 54 usleep(MS_CNT * ms); 55 } 56 57