瀏覽代碼

[update]独立平台适配层

RiceChen 2 年之前
父節點
當前提交
e3eff1bcee

+ 0 - 46
BUILD.gn

@@ -1,46 +0,0 @@
-# Copyright (c) 2022 Hunan OpenValley Digital Industry Development 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.
-
-import("//kernel/liteos_m/liteos.gni")
-module_name = get_path_info(rebase_path("."), "name")
-kernel_module(module_name) {
-  sources = [
-    "core/source/tp_manage.c",
-  ]
-
-  if(ohos_kernel_type == "liteos_m") {
-    sources += [
-      "adapter/source/cmsis/emq_thread_adapter.c",
-      "adapter/source/cmsis/emq_queue_adapter.c",
-      "adapter/source/cmsis/emq_mutex_adapter.c",
-      "adapter/source/cmsis/emq_sem_adapter.c",
-      "adapter/source/cmsis/emq_time_adapter.c",
-    ]
-  }
-
-  if(ohos_kernel_type == "liteos_a" || ohos_kernel_type == "linux") {
-    sources += [
-      "adapter/source/posix/emq_thread_adapter.c",
-      "adapter/source/posix/emq_queue_adapter.c",
-      "adapter/source/posix/emq_mutex_adapter.c",
-      "adapter/source/posix/emq_sem_adapter.c",
-      "adapter/source/posix/emq_time_adapter.c",
-      "adapter/source/posix/lock_free_queue.c",
-    ]
-  }
-
-  include_dirs = [
-    "core/include",
-    "adapter/include",
-  ]
-}

+ 0 - 5
SConscript

@@ -5,14 +5,9 @@ cwd     = GetCurrentDir()
 CPPPATH = [cwd, str(Dir('#'))]
 src     = Split("""
 src/rthread_pool.c
-platform/rtthread/pf_task_adapter.c
-platform/rtthread/pf_mutex_adapter.c
-platform/rtthread/pf_sem_adapter.c
-platform/rtthread/pf_event_adapter.c
 """)
 
 CPPPATH = [cwd + '/include']
-CPPPATH += [cwd + '/platform']
 
 group = DefineGroup('rthread_pool', src, depend = [''], CPPPATH = CPPPATH)
 

+ 0 - 39
platform/cmsis/pf_event_adapter.c

@@ -1,39 +0,0 @@
-#include "platform_def.h"
-#include "cmsis_os2.h"
-
-pf_event_id pf_event_create(void)
-{
-    osEventFlagsId_t event = NULL;
-    event = osEventFlagsNew(NULL);
-
-    return (pf_event_id)event;
-}
-
-uint32_t pf_event_recv(pf_event_id event, uint32_t flags)
-{
-    uint32_t flag = 0;
-    if (event == NULL) {
-        return RALARM_ERROR;
-    }
-    flag = osEventFlagsWait((osEventFlagsId_t)event, flags, osFlagsWaitAny, osWaitForever);
-    return flag;
-}
-
-pf_err_t pf_event_send(pf_event_id event, uint32_t flags)
-{
-    if (event == NULL) {
-        return RALARM_ERROR;
-    }
-    if((osEventFlagsSet((osEventFlagsId_t)event, flags) & flags) == flags) {
-        return RALARM_EOK;
-    }
-    return RALARM_ERROR;
-}
-
-void pf_event_delete(pf_event_id event)
-{
-    if (event == NULL) {
-        return;
-    }
-    osEventFlagsDelete(event);
-}

+ 0 - 40
platform/cmsis/pf_mutex_adapter.c

@@ -1,40 +0,0 @@
-#include "platform_def.h"
-#include "cmsis_os2.h"
-
-pf_mutex_id pf_mutex_create(void)
-{
-    osMutexId_t mutex = NULL;
-    mutex = osMutexNew(NULL);
-
-    return (pf_mutex_id)mutex;
-}
-
-pf_err_t pf_mutex_lock(pf_mutex_id mutex)
-{
-    if (mutex == NULL) {
-        return RALARM_EINVAL;
-    }
-    if(osMutexAcquire((osMutexId_t)mutex, osWaitForever) == osOK) {
-        return RALARM_EOK;
-    }
-    return RALARM_ERROR;
-}
-
-pf_err_t pf_mutex_unlock(pf_mutex_id mutex)
-{
-    if (mutex == NULL) {
-        return RALARM_EINVAL;
-    }
-    if(osMutexRelease((osMutexId_t)mutex) == osOK) {
-        return RALARM_EOK;
-    }
-    return RALARM_ERROR;
-}
-
-void pf_mutex_delete(pf_mutex_id mutex)
-{
-    if (mutex == NULL) {
-        return;
-    }
-    osMutexDelete(mutex);
-}

+ 0 - 40
platform/cmsis/pf_sem_adapter.c

@@ -1,40 +0,0 @@
-#include "platform_def.h"
-#include "cmsis_os2.h"
-
-pf_sem_id pf_sem_create(void)
-{
-    osSemaphoreId_t sem = NULL;
-    sem = osSemaphoreNew(1, value, NULL);
-
-    return (pf_sem_id)sem;
-}
-
-pf_err_t pf_sem_lock(pf_sem_id sem)
-{
-    if (sem == NULL) {
-        return PF_EINVAL;
-    }
-    if(osSemaphoreAcquire((osSemaphoreId_t)sem, osWaitForever) == osOK) {
-        return PF_EOK;
-    }
-    return PF_ERROR;
-}
-
-pf_err_t pf_sem_unlock(pf_sem_id sem)
-{
-    if (sem == NULL) {
-        return PF_EINVAL;
-    }
-    if(osSemaphoreRelease((osSemaphoreId_t)sem) == osOK) {
-        return PF_EOK;
-    }
-    return PF_ERROR;
-}
-
-void pf_sem_delete(pf_sem_id sem)
-{
-    if (sem == NULL) {
-        return;
-    }
-    osSemaphoreDelete((osSemaphoreId_t)sem);
-}

+ 0 - 28
platform/cmsis/pf_task_adapter.c

@@ -1,28 +0,0 @@
-#include "platform_def.h"
-#include "cmsis_os2.h"
-
-pf_task_id pf_task_create(pf_task_func func, void *arg, const struct pf_task_attr *attr)
-{
-    osThreadId_t thread = NULL;
-    osThreadAttr_t task_attr = {
-        .name = attr->name,
-        .attr_bits = 0,
-        .cb_mem = NULL,
-        .cb_size = 0,
-        .stack_mem = NULL,
-        .stack_size = attr->stack_size,
-        .priority = (osPriority_t)attr->priority,
-        .tz_module = 0,
-        .reserved = 0,
-    };
-
-    thread = osThreadNew((osThreadFunc_t)func, arg, &task_attr);
-    return (pf_task_id)thread;
-}
-
-void pf_task_delete(pf_task_id thread)
-{
-    if(thread != NULL) {
-        osThreadTerminate(thread);
-    }
-}

+ 0 - 166
platform/platform_def.h

@@ -1,166 +0,0 @@
-/*
- * Change Logs:
- * Date           Author       Notes
- * 2023-05-12     RiceChen     the first version
- */
-
-#ifndef __PLATFORM_DEF_H__
-#define __PLATFORM_DEF_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <stdbool.h>
-#include <string.h>
-
-typedef enum {
-    PF_EOK = 0,                         /**< There is no error */
-    PF_ERROR,                           /**< A generic error happens */
-    PF_EFULL,                           /**< The resource is full */
-    PF_EEMPTY,                          /**< The resource is empty */
-    PF_ENOMEM,                          /**< No memory */
-    PF_EINVAL,                          /**< Invalid argument */
-}pf_err_t;
-
-#define PF_INLINE                       static __inline
-
-/**
- * memory API
-*/
-#ifndef PF_MALLOC
-    #define PF_MALLOC                   malloc
-#endif
-
-#ifndef PF_FREE
-    #define PF_FREE                     free
-#endif
-
-#ifndef PF_PRINT
-    #define PF_PRINT                    printf
-#endif
-
-#ifndef PF_PRINT_TAG
-    #define PF_PRINT_TAG                "PF"
-#endif
-
-#define PF_LOGE(...)                    PF_PRINT("\033[31;22m[E/%s](%s:%d) ", PF_PRINT_TAG, __FUNCTION__, __LINE__);     \
-                                        PF_PRINT(__VA_ARGS__);                                                           \
-                                        PF_PRINT("\033[0m\n")
-#define PF_LOGI(...)                    PF_PRINT("\033[32;22m[I/%s](%s:%d) ", PF_PRINT_TAG, __FUNCTION__, __LINE__);     \
-                                        PF_PRINT(__VA_ARGS__);                                                           \
-                                        PF_PRINT("\033[0m\n")
-#define PF_LOGD(...)                    PF_PRINT("[D/%s](%s:%d) ", PF_PRINT_TAG, __FUNCTION__, __LINE__);                \
-                                        PF_PRINT(__VA_ARGS__);                                                           \
-                                        PF_PRINT("\n")
-
-typedef void *pf_task_id;
-typedef void *pf_mutex_id;
-typedef void *pf_event_id;
-typedef void *pf_sem_id;
-
-struct pf_task_attr{
-    char *name;       // name of the task
-    uint32_t stack_size;     // size of stack
-    uint8_t priority;       // initial task priority
-};
-
-typedef void(*pf_task_func)(void *arg);
-
-pf_task_id pf_task_create(pf_task_func func, void *arg, const struct pf_task_attr *attr);
-void pf_task_delete(pf_task_id thread);
-
-/**
- * Mutex API
-*/
-pf_mutex_id pf_mutex_create(void);
-pf_err_t pf_mutex_lock(pf_mutex_id mutex);
-pf_err_t pf_mutex_unlock(pf_mutex_id mutex);
-void pf_mutex_delete(pf_mutex_id mutex);
-
-/**
- * Sem API
-*/
-pf_sem_id pf_sem_create(uint32_t value);
-pf_err_t pf_sem_lock(pf_sem_id sem);
-pf_err_t pf_sem_unlock(pf_sem_id sem);
-void pf_sem_delete(pf_sem_id sem);
-
-/**
- * Event API
-*/
-pf_event_id pf_event_create(void);
-uint32_t pf_event_recv(pf_event_id event, uint32_t flags);
-pf_err_t pf_event_send(pf_event_id event, uint32_t flags);
-void pf_event_delete(pf_event_id event);
-
-struct pf_list_node {
-    struct pf_list_node *next;
-    struct pf_list_node *prev;
-};
-typedef struct pf_list_node pf_list_t;
-
-PF_INLINE void pf_list_init(pf_list_t *l)
-{
-    l->next = l->prev = l;
-}
-
-PF_INLINE void pf_list_insert_after(pf_list_t *l, pf_list_t *n)
-{
-    l->next->prev = n;
-    n->next = l->next;
-    l->next = n;
-    n->prev = l;
-}
-
-PF_INLINE void pf_list_insert_before(pf_list_t *l, pf_list_t *n)
-{
-    l->prev->next = n;
-    n->prev = l->prev;
-    l->prev = n;
-    n->next = l;
-}
-
-PF_INLINE void pf_list_remove(pf_list_t *n)
-{
-    n->next->prev = n->prev;
-    n->prev->next = n->next;
-    n->next = n->prev = n;
-}
-
-PF_INLINE int pf_list_is_empty(const pf_list_t *l)
-{
-    return l->next == l;
-}
-
-PF_INLINE int pf_list_len(const pf_list_t *l)
-{
-    int len = 0;
-    const pf_list_t *p = l;
-    while (p->next != l) {
-        p = p->next;
-        len ++;
-    }
-    return len;
-}
-
-#define pf_container_of(ptr, type, member)                                   \
-    ((type *)((char *)(ptr) - (unsigned long)(&((type *)0)->member)))
-
-#define pf_list_obj_init(obj) {&(obj), &(obj)}
-
-#define pf_list_entry(node, type, member)                                    \
-    pf_container_of(node, type, member)
-
-#define pf_list_for_each(pos, head)                                           \
-    for (pos = (head)->next; pos != (head); pos = pos->next)
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif

+ 0 - 35
platform/rtthread/pf_event_adapter.c

@@ -1,35 +0,0 @@
-#include "platform_def.h"
-#include "rtthread.h"
-
-pf_event_id pf_event_create(void)
-{
-    rt_event_t event = NULL;
-
-    event = rt_event_create("pf", RT_IPC_FLAG_FIFO);
-    return (pf_event_id)event;
-}
-
-uint32_t pf_event_recv(pf_event_id event, uint32_t flags)
-{
-    uint32_t flag = 0;
-    if (event == NULL) {
-        return PF_ERROR;
-    }
-    rt_event_recv((rt_event_t)event, flags, RT_EVENT_FLAG_OR | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &flag);
-    return flag;
-}
-
-pf_err_t pf_event_send(pf_event_id event, uint32_t flags)
-{
-    if (event == NULL) {
-        return PF_ERROR;
-    }
-    rt_event_send((rt_event_t)event, flags);
-
-    return PF_ERROR;
-}
-
-void pf_event_delete(pf_event_id event)
-{
-    rt_event_delete((rt_event_t)event);
-}

+ 0 - 33
platform/rtthread/pf_mutex_adapter.c

@@ -1,33 +0,0 @@
-#include "platform_def.h"
-#include "rtthread.h"
-
-pf_mutex_id pf_mutex_create(void)
-{
-    rt_mutex_t mutex = NULL;
-
-    mutex = rt_mutex_create("pf", RT_IPC_FLAG_FIFO);
-    return (pf_mutex_id)mutex;
-}
-
-pf_err_t pf_mutex_lock(pf_mutex_id mutex)
-{
-    if (mutex == NULL) {
-        return PF_EINVAL;
-    }
-    rt_mutex_take((rt_mutex_t)mutex, RT_WAITING_FOREVER);
-    return PF_ERROR;
-}
-
-pf_err_t pf_mutex_unlock(pf_mutex_id mutex)
-{
-    if (mutex == NULL) {
-        return PF_EINVAL;
-    }
-    rt_mutex_release((rt_mutex_t)mutex);
-    return PF_ERROR;
-}
-
-void pf_mutex_delete(pf_mutex_id mutex)
-{
-    rt_mutex_delete((rt_mutex_t)mutex);
-}

+ 0 - 33
platform/rtthread/pf_sem_adapter.c

@@ -1,33 +0,0 @@
-#include "platform_def.h"
-#include "rtthread.h"
-
-pf_sem_id pf_sem_create(uint32_t value)
-{
-    rt_sem_t sem = NULL;
-
-    sem = rt_sem_create("pf", value, RT_IPC_FLAG_FIFO);
-    return (pf_sem_id)sem;
-}
-
-pf_err_t pf_sem_lock(pf_sem_id sem)
-{
-    if (sem == NULL) {
-        return PF_EINVAL;
-    }
-    rt_sem_take((rt_sem_t)sem, RT_WAITING_FOREVER);
-    return PF_ERROR;
-}
-
-pf_err_t pf_sem_unlock(pf_sem_id sem)
-{
-    if (sem == NULL) {
-        return PF_EINVAL;
-    }
-    rt_sem_release((rt_sem_t)sem);
-    return PF_ERROR;
-}
-
-void pf_sem_delete(pf_sem_id sem)
-{
-    rt_sem_delete((rt_sem_t)sem);
-}

+ 0 - 17
platform/rtthread/pf_task_adapter.c

@@ -1,17 +0,0 @@
-#include "platform_def.h"
-#include "rtthread.h"
-
-pf_task_id pf_task_create(pf_task_func func, void *arg, const struct pf_task_attr *attr)
-{
-    rt_thread_t thread = NULL;
-
-    thread = rt_thread_create(attr->name, func, arg, attr->stack_size, attr->priority, 20);
-    rt_thread_startup(thread);
-
-    return (pf_task_id)thread;
-}
-
-void pf_task_delete(pf_task_id thread)
-{
-    rt_thread_delete((rt_thread_t)thread);
-}