diff --git a/app/demolink/BUILD.gn b/app/demolink/BUILD.gn index f46075f9430bda14b11444b96866edf67b0470b7..48ce7caf74844e188ec008c1c6d5561eaf685aa8 100644 --- a/app/demolink/BUILD.gn +++ b/app/demolink/BUILD.gn @@ -12,10 +12,11 @@ # limitations under the License. static_library("example_demolink") { - sources = [ "helloworld.c" ] - - include_dirs = [ - "//utils/native/lite/include", - "//domains/iot/link/libbuild", + sources = [ + "demosdk.c", + "demosdk_adapter.c", + "helloworld.c", ] + + include_dirs = [ "//utils/native/lite/include" ] } diff --git a/app/demolink/demosdk.c b/app/demolink/demosdk.c new file mode 100644 index 0000000000000000000000000000000000000000..beb196f68fd0f7845cad2678df21ceddb80ffff8 --- /dev/null +++ b/app/demolink/demosdk.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "demosdk.h" + +#include + +#include "demosdk_adapter.h" + +#define TASK_STACK_SIZE 1000 +#define TASK_PRIO 20 +#define SECOND_CNT 1000 + +void *DemoSdkBiz(const char *arg) +{ + (void)arg; + while (1) { + printf("it is demo biz: hello world.\n"); + DemoSdkSleepMs(SECOND_CNT); + } + return NULL; +} + +int DemoSdkEntry(void) +{ + printf("it is demosdk entry.\n"); + struct TaskPara para = {0}; + para.name = "demotask"; + para.func = (void *)DemoSdkBiz; + para.prio = TASK_PRIO; + para.size = TASK_STACK_SIZE; + unsigned int handle; + int ret = DemoSdkCreateTask(&handle, ¶); + if (ret != 0) { + printf("create task fail.\n"); + return -1; + } + return 0; +} diff --git a/app/demolink/demosdk.h b/app/demolink/demosdk.h new file mode 100644 index 0000000000000000000000000000000000000000..cecd86bf70fd4c0a0f25c0e61514a6c27fc48519 --- /dev/null +++ b/app/demolink/demosdk.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEMOSDK_H +#define DEMOSDK_H + +int DemoSdkEntry(void); + +#endif // DEMOSDK_H diff --git a/app/demolink/demosdk_adapter.c b/app/demolink/demosdk_adapter.c new file mode 100644 index 0000000000000000000000000000000000000000..aecd2a7558a392b0d1041cae4cb8ed998ec9794c --- /dev/null +++ b/app/demolink/demosdk_adapter.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "demosdk_adapter.h" +#include + +#include "cmsis_os2.h" + +#define MS_CNT 1000 + +int DemoSdkCreateTask(unsigned int *handle, const struct TaskPara *para) +{ + osThreadAttr_t attr = {0}; + osThreadId_t threadId; + if (handle == 0 || para == 0) { + return DEMOSDK_ERR; + } + + if (para->func == 0) { + return DEMOSDK_ERR; + } + + if (para->name == 0) { + return DEMOSDK_ERR; + } + + attr.name = para->name; + attr.priority = para->prio; + attr.stack_size = para->size; + threadId = osThreadNew((osThreadFunc_t)para->func, para->arg, &attr); + if (threadId == 0) { + printf("osThreadNew fail\n"); + return DEMOSDK_ERR; + } + + *(unsigned int *)handle = (unsigned int)threadId; + return DEMOSDK_OK; +} + +void DemoSdkSleepMs(int ms) +{ + usleep(MS_CNT * ms); +} + diff --git a/app/demolink/demosdk_adapter.h b/app/demolink/demosdk_adapter.h new file mode 100644 index 0000000000000000000000000000000000000000..5c836099a77c08c83dcd839867a7a5d0e056bb9e --- /dev/null +++ b/app/demolink/demosdk_adapter.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DEMOSDK_ADAPTER_H +#define DEMOSDK_ADAPTER_H + +#define DEMOSDK_ERR (-1) +#define DEMOSDK_OK 0 + +struct TaskPara { + char *name; + void *(*func)(char* arg); + void *arg; + unsigned char prio; + unsigned int size; +}; + +int DemoSdkCreateTask(unsigned int *handle, const struct TaskPara *para); +void DemoSdkSleepMs(int ms); + +#endif // DEMOSDK_ADAPTER_H