适配系统适配层的更新
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
if(POLICY CMP0079)
|
||||
cmake_policy(SET CMP0079 NEW)
|
||||
endif()
|
||||
|
||||
project(has_project_host LANGUAGES C)
|
||||
|
||||
# 当前宿主工程通过 add_subdirectory(has_platform) 的方式接入平台子仓库,
|
||||
@@ -8,6 +12,25 @@ project(has_project_host LANGUAGES C)
|
||||
set(CMAKE_C_STANDARD 11)
|
||||
set(CMAKE_C_STANDARD_REQUIRED ON)
|
||||
|
||||
add_library(has_project_warnings INTERFACE)
|
||||
|
||||
target_compile_options(has_project_warnings
|
||||
INTERFACE
|
||||
$<$<COMPILE_LANG_AND_ID:C,GNU,Clang,AppleClang>:
|
||||
-Wall
|
||||
-Wextra
|
||||
# -Wpedantic
|
||||
-Wformat=2
|
||||
-Wundef
|
||||
-Wshadow
|
||||
-Wpointer-arith
|
||||
-Wwrite-strings
|
||||
-Wstrict-prototypes
|
||||
# -Wmissing-prototypes
|
||||
-Werror=implicit-function-declaration
|
||||
>
|
||||
)
|
||||
|
||||
# 宿主工程选择如何集成 has_platform:
|
||||
# static: 链接静态库
|
||||
# shared: 链接动态库
|
||||
@@ -44,6 +67,7 @@ else()
|
||||
endif()
|
||||
|
||||
add_subdirectory(has_platform)
|
||||
target_link_libraries(has_platform_obj PRIVATE has_project_warnings)
|
||||
|
||||
# 宿主工程业务源码。保持 has_project 现有目录结构不变。
|
||||
file(GLOB HOST_APP_SOURCES CONFIGURE_DEPENDS
|
||||
@@ -70,6 +94,7 @@ endif()
|
||||
add_executable(test ${HOST_PROJECT_SOURCES})
|
||||
|
||||
target_compile_features(test PRIVATE c_std_11)
|
||||
target_link_libraries(test PRIVATE has_project_warnings)
|
||||
|
||||
# 宿主工程根据选择的模式链接或嵌入 has_platform。
|
||||
if(HAS_PLATFORM_LINK_MODE STREQUAL "static")
|
||||
@@ -87,4 +112,3 @@ set_target_properties(test PROPERTIES
|
||||
)
|
||||
|
||||
message(STATUS "HAS_PLATFORM_LINK_MODE = ${HAS_PLATFORM_LINK_MODE}")
|
||||
|
||||
|
||||
2
build.sh
2
build.sh
@@ -30,7 +30,7 @@ case "${ACTION}" in
|
||||
mkdir -p "${BUILD_DIR}"
|
||||
rm -rf "${BUILD_DIR:?}/"*
|
||||
cmake -S . -B "${BUILD_DIR}" \
|
||||
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DHAS_PLATFORM_LINK_MODE="${LINK_MODE}"
|
||||
cmake --build "${BUILD_DIR}" -j"$(nproc)"
|
||||
;;
|
||||
|
||||
Submodule has_platform updated: 304f035f44...7b234d0f7c
@@ -192,16 +192,11 @@ int has_sem_deinit(has_sem_t *sem)
|
||||
}
|
||||
|
||||
/* ------------------------------------------------ 线程创建API ------------------------------------------------ */
|
||||
int has_task_create(const char *task_name, int priority, unsigned int stack_size,
|
||||
has_taskentry pfnEntry, void *pEntryParm, OS_THREAD_ID *pthread_id)
|
||||
int has_task_create(const has_task_attr_t *task_attr, OS_THREAD_ID *thread_id)
|
||||
{
|
||||
(void)task_name;
|
||||
(void)priority;
|
||||
(void)stack_size;
|
||||
(void)pfnEntry;
|
||||
(void)pEntryParm;
|
||||
if (pthread_id != NULL) {
|
||||
*pthread_id = NULL;
|
||||
(void)task_attr;
|
||||
if (thread_id != NULL) {
|
||||
*thread_id = NULL;
|
||||
}
|
||||
port_printf("has_task_create is not implemented for HAS_OS_USER_DEFINED.\n");
|
||||
return -1;
|
||||
@@ -209,9 +204,14 @@ int has_task_create(const char *task_name, int priority, unsigned int stack_size
|
||||
|
||||
int has_task_delete(OS_THREAD_ID thread_id)
|
||||
{
|
||||
#if HAS_ENABLE_FORCE_TASK_DELETE
|
||||
(void)thread_id;
|
||||
port_printf("has_task_delete is not implemented for HAS_OS_USER_DEFINED.\n");
|
||||
return -1;
|
||||
#else
|
||||
(void)thread_id;
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint64_t has_get_time_ms(void)
|
||||
@@ -244,12 +244,10 @@ void has_sleep_ms(uint32_t ms)
|
||||
// }
|
||||
}
|
||||
|
||||
int has_task_exit(OS_THREAD_ID task_id, uint32_t dw_cookie)
|
||||
void has_task_exit(void)
|
||||
{
|
||||
(void)task_id;
|
||||
(void)dw_cookie;
|
||||
port_printf("has_task_exit is not implemented for HAS_OS_USER_DEFINED.\n");
|
||||
return -1;
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
|
||||
#include "has_platform_config.h"
|
||||
|
||||
|
||||
#if defined(HAS_OS_USER_DEFINED)
|
||||
|
||||
#define HAS_ENABLE_MUTEX_SEM // 支持互斥量和信号量
|
||||
|
||||
|
||||
/* 下面示例是基于xr806移植 */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -20,16 +18,45 @@
|
||||
|
||||
#define has_mutex_t OS_Mutex_t
|
||||
#define has_sem_t OS_Semaphore_t
|
||||
|
||||
#define TASK_PRIORITY_SYS 0
|
||||
#define TASK_PRIORITY_HIGH 1
|
||||
#define TASK_PRIORITY_LOW 8
|
||||
#define TASK_PRIORITY_NORMAL 4
|
||||
#define TASK_PRIORITY_ABOVE_NORMAL 3
|
||||
#define TASK_PRIORITY_BELOW_NORMAL 6
|
||||
typedef void *OS_THREAD_ID;
|
||||
typedef void *(*has_taskentry)(void *param);
|
||||
|
||||
typedef void (*has_task_entry_t)(void *param);
|
||||
|
||||
typedef enum {
|
||||
HAS_TASK_PRIORITY_SYS = 0,
|
||||
HAS_TASK_PRIORITY_HIGH,
|
||||
HAS_TASK_PRIORITY_ABOVE_NORMAL,
|
||||
HAS_TASK_PRIORITY_NORMAL,
|
||||
HAS_TASK_PRIORITY_BELOW_NORMAL,
|
||||
HAS_TASK_PRIORITY_LOW,
|
||||
} has_task_priority_t;
|
||||
|
||||
typedef struct {
|
||||
int32_t sched_policy; /* -1: use OS default */
|
||||
} has_task_linux_attr_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t reserved; /* reserved for future FreeRTOS-specific options */
|
||||
} has_task_freertos_attr_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t tick; /* 0: use default time slice */
|
||||
} has_task_rtthread_attr_t;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
has_task_entry_t entry;
|
||||
void *arg;
|
||||
uint32_t stack_size_bytes;
|
||||
has_task_priority_t priority;
|
||||
has_task_linux_attr_t linux_attr;
|
||||
has_task_freertos_attr_t freertos_attr;
|
||||
has_task_rtthread_attr_t rtthread_attr;
|
||||
} has_task_attr_t;
|
||||
|
||||
#ifndef HAS_ENABLE_FORCE_TASK_DELETE
|
||||
#define HAS_ENABLE_FORCE_TASK_DELETE 0
|
||||
#endif
|
||||
|
||||
#ifdef HAS_ENABLE_MUTEX_SEM
|
||||
enum MSG_WAIT_RET{
|
||||
@@ -61,9 +88,9 @@ int has_sem_deinit(has_sem_t *sem);
|
||||
#define has_sem_deinit(s)
|
||||
#endif
|
||||
|
||||
int has_task_create(const char *task_name, int priority, unsigned int stack_size,
|
||||
has_taskentry pfnEntry, void *pEntryParm, OS_THREAD_ID *pthread_id);
|
||||
int has_task_exit(OS_THREAD_ID task_id, uint32_t dw_cookie);
|
||||
int has_task_create(const has_task_attr_t *attr, OS_THREAD_ID *thread_id);
|
||||
void has_task_exit(void);
|
||||
/* Compatibility-only API: prefer cooperative stop + return/has_task_exit(). */
|
||||
int has_task_delete(OS_THREAD_ID thread_id);
|
||||
uint64_t has_get_time_ms(void);
|
||||
void has_sleep_ms(uint32_t ms);
|
||||
|
||||
@@ -14,17 +14,17 @@ static has_ptcl_handler *g_handler = NULL;
|
||||
static void has_receive_from_mcu(const has_tlv_t *box)
|
||||
{
|
||||
printf("receive event:%d\n", box->event);
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
static void has_receive_from_mcu_1(const has_tlv_t *box)
|
||||
{
|
||||
printf("receive event:%d\n", box->event);
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
static void has_receive_from_mcu_2(const has_tlv_t *box)
|
||||
{
|
||||
printf("receive event:%d\n", box->event);
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
||||
int acm_hal_send(uint8_t *buff, uint32_t len)
|
||||
@@ -47,10 +47,11 @@ void send_fail_callback(has_tlv_t *p_tlv)
|
||||
printf("event %x send fail\n", p_tlv->event);
|
||||
}
|
||||
|
||||
void *protocol_task(void *param)
|
||||
static void protocol_task(void *param)
|
||||
{
|
||||
int actuall_len;
|
||||
|
||||
(void)param;
|
||||
while (1)
|
||||
{
|
||||
/* reads */
|
||||
@@ -61,7 +62,6 @@ void *protocol_task(void *param)
|
||||
}
|
||||
has_sleep_ms(PROCESS_MSG_PERIOD);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void msg_handle_cb(unsigned char module_id, const unsigned char *buf, unsigned int len)
|
||||
@@ -72,9 +72,11 @@ static void msg_handle_cb(unsigned char module_id, const unsigned char *buf, uns
|
||||
}
|
||||
|
||||
|
||||
void *send_test_task(void *param)
|
||||
static void send_test_task(void *param)
|
||||
{
|
||||
unsigned char data = 3;
|
||||
|
||||
(void)param;
|
||||
while (1)
|
||||
{
|
||||
/* write */
|
||||
@@ -87,6 +89,22 @@ void *send_test_task(void *param)
|
||||
int example_protocol_init(void)
|
||||
{
|
||||
has_protocol_attr attr;
|
||||
has_task_attr_t protocol_task_attr = {
|
||||
.name = "acm_read",
|
||||
.entry = protocol_task,
|
||||
.arg = NULL,
|
||||
.stack_size_bytes = 1024U,
|
||||
.priority = HAS_TASK_PRIORITY_NORMAL,
|
||||
.linux_attr = { .sched_policy = -1 },
|
||||
};
|
||||
has_task_attr_t send_task_attr = {
|
||||
.name = "acm_send",
|
||||
.entry = send_test_task,
|
||||
.arg = NULL,
|
||||
.stack_size_bytes = 1024U,
|
||||
.priority = HAS_TASK_PRIORITY_NORMAL,
|
||||
.linux_attr = { .sched_policy = -1 },
|
||||
};
|
||||
kbox_event uart_list[] =
|
||||
{
|
||||
{TEST_EVENT, has_receive_from_mcu},
|
||||
@@ -102,21 +120,35 @@ int example_protocol_init(void)
|
||||
attr.success_cb = send_success_callback;
|
||||
attr.fail_cb = send_fail_callback;
|
||||
|
||||
if (read_buffer == NULL) {
|
||||
read_buffer = has_malloc(REC_BUFFER_LEN_MAX);
|
||||
if (read_buffer == NULL) {
|
||||
printf("alloc ACM read buffer failed\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
g_handler = has_protocol_create(&attr);
|
||||
if (g_handler == NULL)
|
||||
{
|
||||
printf("create ACM handler err!\n");
|
||||
return NULL;
|
||||
has_free(read_buffer);
|
||||
read_buffer = NULL;
|
||||
return -1;
|
||||
}
|
||||
printf("module:ACM\n");
|
||||
/* 创建线程 */
|
||||
if (has_task_create("read_test", TASK_PRIORITY_NORMAL, 1024, protocol_task, NULL, &protocol_tid) != 0) {
|
||||
printf("module:WIFI create task failed\n");
|
||||
if (has_task_create(&protocol_task_attr, &protocol_tid) != 0) {
|
||||
printf("module:ACM create read task failed\n");
|
||||
has_protocol_destroy(g_handler);
|
||||
g_handler = NULL;
|
||||
has_free(read_buffer);
|
||||
read_buffer = NULL;
|
||||
return -1;
|
||||
}
|
||||
if (has_task_create("send_test", TASK_PRIORITY_NORMAL, 1024, send_test_task, NULL, &send_test_tid) != 0) {
|
||||
printf("module:WIFI create task failed\n");
|
||||
return -1;
|
||||
if (has_task_create(&send_task_attr, &send_test_tid) != 0) {
|
||||
printf("module:ACM create send task failed\n");
|
||||
// return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ static void timer_cb(void *arg)
|
||||
}
|
||||
|
||||
static OS_THREAD_ID gui_tid;
|
||||
void *gui_task(void *param)
|
||||
static void gui_task(void *param)
|
||||
{
|
||||
(void)param;
|
||||
uint8_t data[2];
|
||||
@@ -18,17 +18,25 @@ void *gui_task(void *param)
|
||||
while (1)
|
||||
{
|
||||
has_msg_publish(GUI, data, sizeof(data));
|
||||
sleep(10);
|
||||
has_sleep_ms(10000);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int example_gui_init(void)
|
||||
{
|
||||
has_task_attr_t task_attr = {
|
||||
.name = "gui",
|
||||
.entry = gui_task,
|
||||
.arg = NULL,
|
||||
.stack_size_bytes = 1024U,
|
||||
.priority = HAS_TASK_PRIORITY_NORMAL,
|
||||
.linux_attr = { .sched_policy = -1 },
|
||||
};
|
||||
|
||||
printf("module:GUI\n");
|
||||
/* 创建线程 */
|
||||
if (has_task_create("wifi", TASK_PRIORITY_NORMAL, 1024, gui_task, NULL, &gui_tid) != 0) {
|
||||
printf("module:WIFI create task failed\n");
|
||||
if (has_task_create(&task_attr, &gui_tid) != 0) {
|
||||
printf("module:GUI create task failed\n");
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -39,7 +39,7 @@ int main()
|
||||
}
|
||||
|
||||
while (1) {
|
||||
sleep(1);
|
||||
has_sleep_ms(1000);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,9 @@ void msg_handle_cb(unsigned char module_id, const unsigned char *buf, unsigned i
|
||||
}
|
||||
|
||||
static OS_THREAD_ID wifi_tid;
|
||||
void *wifi_task(void *param)
|
||||
static void wifi_task(void *param)
|
||||
{
|
||||
(void)param;
|
||||
uint8_t buffer[10] = {1, 2, 8};
|
||||
uint8_t data[2];
|
||||
data[0] = 0x5c;
|
||||
@@ -25,16 +26,24 @@ void *wifi_task(void *param)
|
||||
has_msg_handle(WIFI, msg_handle_cb, 1000);
|
||||
has_msg_publish(WIFI, data, sizeof(data));
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int example_wifi_init(void)
|
||||
{
|
||||
has_task_attr_t task_attr = {
|
||||
.name = "wifi",
|
||||
.entry = wifi_task,
|
||||
.arg = NULL,
|
||||
.stack_size_bytes = 1024U,
|
||||
.priority = HAS_TASK_PRIORITY_NORMAL,
|
||||
.linux_attr = { .sched_policy = -1 },
|
||||
};
|
||||
|
||||
printf("module:WIFI\n");
|
||||
// has_msg_printf_subscribe(WIFI);
|
||||
|
||||
/* 创建线程 */
|
||||
if (has_task_create("wifi", TASK_PRIORITY_NORMAL, 1024, wifi_task, NULL, &wifi_tid) != 0) {
|
||||
if (has_task_create(&task_attr, &wifi_tid) != 0) {
|
||||
printf("module:WIFI create task failed\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
int uart_open(int param)
|
||||
{
|
||||
|
||||
printf("init uart %d\n", param);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uart_close(int param)
|
||||
@@ -14,17 +15,25 @@ int uart_close(int param)
|
||||
|
||||
int uart_write(int param, void *buff, unsigned int len)
|
||||
{
|
||||
unsigned char *temp = buff;
|
||||
(void)param;
|
||||
(void)buff;
|
||||
(void)len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uart_read(int param, void *buff, unsigned int len)
|
||||
{
|
||||
(void)param;
|
||||
(void)buff;
|
||||
(void)len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int uart_ioctl(int param, void *buff, unsigned int len)
|
||||
{
|
||||
(void)param;
|
||||
(void)buff;
|
||||
(void)len;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user