chore: migrate project into clean repository

This commit is contained in:
yuuux
2026-08-13 16:50:52 +08:00
commit d1d25a09e7
27405 changed files with 9422808 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
FILE(GLOB SRCS
acomp_ipc.c
)
listenai_library_sources(${SRCS})

View File

@@ -0,0 +1,212 @@
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include "assert.h"
#include "FreeRTOS.h"
#include "semphr.h"
#include "ic_message.h"
#include "acomp_ipc.h"
#include "gcl_cb_list/gcl_cb_list.h"
#include "dlist.h"
#include "acomp_err.h"
#define TAG "acomp_ipc"
#include "lisa_log.h"
#define CACHE_LINE_SIZE (32)
#define ASSERT(exp, fmt, ...) \
do { \
if (!(exp)) { \
LISA_LOGI(TAG, "error:" fmt, ##__VA_ARGS__); \
assert(exp); \
} \
} while (0)
#define IPC_TIMOUT_MS (10000)
typedef struct {
uint32_t dev_index;
ipc_event_cb_t cb;
void *priv;
sys_dnode_t node;
} acomp_cb_list_item_t;
typedef struct {
uint32_t index;
uint8_t name[ACOMP_DEV_NAME_MAX_LEN];
sys_dnode_t node;
} acomp_ipc_dev_info_list_item_t;
typedef struct {
sys_dlist_t cb_list;
sys_dlist_t dev_info_list;
SemaphoreHandle_t reply_sem;
} acomp_ipc_handle_t;
acomp_ipc_handle_t *ipc_handle = NULL;
static int32_t acomp_ipc_callback_wrap(ic_message_handle_info_t *handle_info, ic_message_msg_info_t *msg)
{
sys_dnode_t *node;
acomp_cb_list_item_t *cb_item;
acomp_ipc_handle_t *handle = (acomp_ipc_handle_t *)handle_info->user_datas;
acomp_ipc_message_t *ipc_msg = (acomp_ipc_message_t *)msg->msg;
if (ipc_msg->hdr.hdr.cmd == ACOMP_CONTEXT_IPC_GLB_REPLY) {
xSemaphoreGive(handle->reply_sem);
return 0;
}
if ((ipc_msg->address != 0) && (ipc_msg->len > 0)) {
HAL_InvalidateDCache_by_Addr((void *)ipc_msg->address, ipc_msg->len);
}
if (ipc_msg->hdr.hdr.cmd == ACOMP_CONTEXT_IPC_GLB_NOTIFY) {
SYS_DLIST_FOR_EACH_NODE(&handle->cb_list, node)
{
cb_item = CONTAINER_OF(node, acomp_cb_list_item_t, node);
if (cb_item->dev_index == ipc_msg->dev_index) {
cb_item->cb(ipc_msg, cb_item->priv);
}
}
} else if (ipc_msg->hdr.hdr.cmd == ACOMP_CONTEXT_IPC_GLB_DEVINFO_QUERY_RESP) {
acomp_ipc_dev_info_query_msg_t *dev_info = (acomp_ipc_dev_info_query_msg_t *)ipc_msg->address;
for (int ii = 0; ii < dev_info->number; ii++) {
acomp_ipc_dev_info_list_item_t *dev_info_item =
(acomp_ipc_dev_info_list_item_t *)psram_malloc(sizeof(acomp_ipc_dev_info_list_item_t));
if (dev_info_item == NULL) {
LISA_LOGE(TAG, "acomp ipc dev info item malloc failed");
return -1;
}
memset(dev_info_item, 0, sizeof(acomp_ipc_dev_info_list_item_t));
dev_info_item->index = dev_info->item[ii].index;
snprintf(dev_info_item->name, sizeof(dev_info_item->name), "%s", dev_info->item[ii].name);
sys_dlist_append(&handle->dev_info_list, &dev_info_item->node);
LISA_LOGI(TAG, "[%d]acomp remote dev index %d name %s", ii, dev_info_item->index, dev_info_item->name);
}
} else {
LISA_LOGE(TAG, "acomp ipc unknown cmd:%d", ipc_msg->hdr.hdr.cmd);
}
if (ipc_msg->hdr.hdr.req_reply) {
acomp_ipc_build_frame_send_sync(ipc_msg->dev_index, ACOMP_CONTEXT_IPC_GLB_REPLY, 0, 0, 0, 0);
}
return 0;
}
int acomp_ipc_init(void)
{
int ret;
if (ipc_handle != NULL) {
return -ACOMP_ERR_INVALID_STATE;
}
ipc_handle = (acomp_ipc_handle_t *)psram_malloc(sizeof(acomp_ipc_handle_t));
if (ipc_handle == NULL) {
return -ACOMP_ERR_NO_MEM;
}
memset(ipc_handle, 0, sizeof(acomp_ipc_handle_t));
sys_dlist_init(&ipc_handle->cb_list);
sys_dlist_init(&ipc_handle->dev_info_list);
ipc_handle->reply_sem = xSemaphoreCreateBinary();
ic_message_register_by_id(IC_MESSAGE_ID_ACOMP, acomp_ipc_callback_wrap, ipc_handle);
ret =
acomp_ipc_build_frame_send_sync(0, ACOMP_CONTEXT_IPC_GLB_DEVINFO_QUERY | IPC_HEADER_REQ_REPALY, 0, 0, NULL, 0);
return ret;
}
int acomp_ipc_add_callback(uint32_t dev_index, ipc_event_cb_t cb, void *priv)
{
acomp_cb_list_item_t *cb_item;
cb_item = (acomp_cb_list_item_t *)psram_malloc(sizeof(acomp_cb_list_item_t));
if (cb_item == NULL) {
return -ACOMP_ERR_NO_MEM;
}
memset(cb_item, 0, sizeof(acomp_cb_list_item_t));
cb_item->dev_index = dev_index;
cb_item->cb = cb;
cb_item->priv = priv;
sys_dlist_append(&ipc_handle->cb_list, &cb_item->node);
return 0;
}
int acomp_ipc_remove_callback(uint32_t dev_index, ipc_event_cb_t cb)
{
acomp_cb_list_item_t *cb_item;
sys_dnode_t *node, *tmp;
int ret = -ACOMP_ERR_NOT_FOUND;
if (ipc_handle == NULL || cb == NULL) {
return -EINVAL;
}
// Search for the callback item with matching dev_index
SYS_DLIST_FOR_EACH_NODE_SAFE(&ipc_handle->cb_list, node, tmp)
{
cb_item = CONTAINER_OF(node, acomp_cb_list_item_t, node);
if (cb_item->dev_index == dev_index) {
sys_dlist_remove(&cb_item->node);
psram_free(cb_item);
return 0;
}
}
return ret;
}
int acomp_ipc_build_frame_send_sync(int dev_index, int cmd, int acomp_cmd, uint8_t flags, void *data, uint16_t len)
{
acomp_ipc_message_t ipc_msg;
uint8_t *pdata;
int ret = 0;
ipc_msg.hdr.glb_cmd = cmd;
ipc_msg.dev_index = dev_index;
ipc_msg.acomp_cmd = acomp_cmd;
ipc_msg.req.flags = flags;
ipc_msg.len = len;
ipc_msg.address = (uint32_t)data;
if ((data != NULL) && (len > 0)) {
ASSERT(!(((uint32_t)data % CACHE_LINE_SIZE) && (len % CACHE_LINE_SIZE)),
"comp ipc buffer not aligned cache line(32)");
HAL_FlushDCache_by_Addr((void *)data, len);
}
pdata = (uint8_t *)&ipc_msg;
ic_message_msg_send_by_id(IC_MESSAGE_ID_ACOMP, IC_MESSAGE_MSG_TYPE_CMD, (uint8_t *)&ipc_msg,
sizeof(acomp_ipc_message_t));
if ((ipc_msg.hdr.hdr.cmd != ACOMP_CONTEXT_IPC_GLB_REPLY) && (ipc_msg.hdr.hdr.req_reply)) {
if (xSemaphoreTake(ipc_handle->reply_sem, pdMS_TO_TICKS(IPC_TIMOUT_MS)) != pdTRUE) {
CLOGE("[%s %d]urpc_send_async_client hdr(0x%x) timeout(%d),ret %d !\n", __FUNCTION__, __LINE__,
ipc_msg.hdr.glb_cmd, IPC_TIMOUT_MS, ret);
ret = -ACOMP_ERR_TIMEOUT;
}
}
return ret;
}
int acomp_ipc_get_dev_index(const char *name)
{
int ret;
sys_dnode_t *node;
SYS_DLIST_FOR_EACH_NODE(&ipc_handle->dev_info_list, node)
{
acomp_ipc_dev_info_list_item_t *dev_info_item = CONTAINER_OF(node, acomp_ipc_dev_info_list_item_t, node);
if (strcmp(dev_info_item->name, name) == 0) {
return dev_info_item->index;
}
}
return -ACOMP_ERR_NOT_FOUND;
}

View File

@@ -0,0 +1,165 @@
#ifndef __ACOMP_IPC_H_
#define __ACOMP_IPC_H_
#include <stdint.h>
#define IPC_ALIGN_SIZE (32)
#define ACOMP_DEV_NAME_MAX_LEN (16)
/*components ipc global define*/
typedef union{
uint8_t glb_cmd;
struct{
uint8_t cmd:4; /*global cmd*/
uint8_t req_reply:1; /*request global reply*/
uint8_t resp:1; /*resp 0:成功,1:失败*/
uint8_t reserved:2;
}hdr;
}__attribute__((packed)) acomp_ipc_header_t;
/*components ipc global define*/
#ifndef BIT
#define BIT(x) (1<<x)
#endif
#define IPC_HEADER_REQ_REPALY BIT(4)
#define IPC_HEADER_GLB_CMD(cmd) (cmd & 0x0f)
/*components global commands APP CORE <-> ALGO CORE */
#define ACOMP_CONTEXT_IPC_GLB_REPLY (0x00)
/*components global commands APP CORE -> ALGO CORE*/
#define ACOMP_CONTEXT_IPC_GLB_NEW (0x01)
#define ACOMP_CONTEXT_IPC_GLB_FREE (0x02)
#define ACOMP_CONTEXT_IPC_GLB_CONTROL (0x03)
#define ACOMP_CONTEXT_IPC_GLB_DEVINFO_QUERY (0x04)
/*components global commands ALGO CORE -> APP CORE*/
#define ACOMP_CONTEXT_IPC_GLB_NOTIFY (0x01)
#define ACOMP_CONTEXT_IPC_GLB_DEVINFO_QUERY_RESP (0x02)
/*components subcmd define APP CORE -> ALGO CORE*/
#define ACOMP_IPC_CMD_PREPARE (0x00) /*sync prepare load resource ,init memory ...*/
#define ACOMP_IPC_CMD_CLEANUP (0x01) /*sync cleanup free resource ,free memory ...*/
#define ACOMP_IPC_CMD_START (0x02)
#define ACOMP_IPC_CMD_STOP (0x03)
#define ACOMP_IPC_CMD_ABORT (0x04)
#define ACOMP_IPC_CMD_CONTROL (0x05)
#define ACOMP_IPC_CMD_STREAM_CREATE (0x06)
#define ACOMP_IPC_CMD_STREAM_DESTROY (0x07)
#define ACOMP_IPC_CMD_STREAM_UPDATE (0x08) /*sync stream update*/
/*components subcmd ALGO CORE -> APP CORE*/
#define ACOMP_IPC_CMD_NOTIFY_RESULT (0x01) /*async notify result*/
#define ACOMP_IPC_CMD_NOTIFY_STREAM_UPDATE (0x02) /*async notify data write*/
#define ACOMP_IPC_CMD_NOTIFY_SUBCMD (0x03) /*async notify subcmd*/
typedef struct {
acomp_ipc_header_t hdr;
uint8_t dev_index;
uint8_t acomp_cmd;
union {
struct{
uint8_t flags;
}req;
struct{
uint8_t err;
}reply;
};
uint16_t len;
uint32_t address;
} __attribute__((packed)) acomp_ipc_message_t;
typedef union{
uint32_t data;
struct{
uint32_t storage:3; /*0:FLASH;1:SD;2:PSRAM;*/
uint32_t reserved:29;
}hdr;
}acomp_res_item_attr_t;
typedef struct {
uint32_t index;
acomp_res_item_attr_t attr;
uint32_t addr;
uint32_t offset;
uint32_t size;
}__attribute__((packed))acomp_res_item_t;
typedef struct {
uint32_t number;
acomp_res_item_t item[0];
}__attribute__((packed,aligned(32)))acomp_ipc_prepare_t;
typedef struct{
uint32_t index;
uint8_t name[ACOMP_DEV_NAME_MAX_LEN];
}__attribute__((packed))acomp_ipc_dev_info_t;
typedef struct{
uint32_t number;
acomp_ipc_dev_info_t item[0];
}__attribute__((packed,aligned(32)))acomp_ipc_dev_info_query_msg_t;
typedef struct{
int control;
uint32_t len;
uint8_t data[0];
}__attribute__((packed,aligned(32)))acomp_ipc_control_t;
typedef struct{
uint32_t len;
uint8_t data[];
}__attribute__((packed,aligned(32)))acomp_ipc_notify_result_t;
typedef struct{
uint32_t len;
uint8_t data[];
}__attribute__((packed,aligned(32)))acomp_ipc_notify_subcmd_t;
typedef struct{
char name[16];
uint8_t direction; /*0: m2r,1: r2m*/
uint8_t index;
uint32_t kick_policy; /* Kick policy: 0:manual/ >0: buffer count to kick */
/* vring memory*/
void *phy_addr;
uint32_t mem_size;
uint32_t align;
uint32_t buffer_size;
}__attribute__((packed,aligned(32)))acomp_ipc_stream_create_desc_t;
typedef struct{
uint32_t index;
}__attribute__((packed,aligned(32)))acomp_ipc_stream_destroy_desc_t;
typedef struct{
uint32_t index;
}__attribute__((packed,aligned(32)))acomp_ipc_stream_update_t;
#define ACOMP_IPC_NOTIFY_DATA_ALIGN(len) ACOMP_IPC_ALIGN(offsetof(acomp_ipc_notify_t,data)+ len)
typedef void(*ipc_event_cb_t) (acomp_ipc_message_t *message, void *priv);
extern int acomp_ipc_init(void);
extern int acomp_ipc_add_callback(uint32_t dev_index, ipc_event_cb_t cb, void *priv);
extern int acomp_ipc_build_frame_send_sync(int dev_index,int cmd,int acomp_cmd,uint8_t flags,void* data,uint16_t len);
extern int acomp_ipc_get_dev_index(const char *name);
#endif