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,31 @@
if (DEFINED CONFIG_IPC_LSF)
listenai_library_named(ipclsf)
listenai_library_sources(
ic_message/ic_message.c
)
listenai_library_sources_ifdef(
CONFIG_DISK_MEM_CLIENT
diskmem/client/disk_mem_urpc.c
)
listenai_library_sources_ifdef(
CONFIG_DISK_MEM_SERVER
diskmem/server/disk_mem_urpc.c
)
if (CONFIG_DISK_MEM_SERVER)
listenai_include_directories(diskmem/server)
endif()
if (CONFIG_DISK_MEM_CLIENT)
listenai_include_directories(diskmem/client)
endif()
target_include_directories(ipclsf PRIVATE port)
listenai_include_directories(ic_message)
endif()

View File

@@ -0,0 +1,37 @@
menuconfig IPC_LSF
bool "based on lsf's inter-core communication module"
default n
select ARCS_HAL_LSF
if IPC_LSF
choice
prompt "lsf type"
config LSF_CLIENT
bool "lsf client"
depends on HAL_LSF_CLIENT
config LSF_SERVER
bool "lsf server"
depends on HAL_LSF_SERVER
endchoice
config LSF_IC_MESSAGE_DEPRECATED
bool "lsf ic message api deprecated"
default n
help
lsf ic message api deprecated
config LSF_IC_MESSAGE_EP_ID
int "lsf ic message endpoint id"
default 5
range 0 15
help
lsf ic message endpoint id
orsource "Kconfig.diskmem"
endif

View File

@@ -0,0 +1,43 @@
config DISK_MEM
bool "disk memory"
default y
if DISK_MEM
config DISK_MEMORY_CACHE
bool "disk memory cache "
default n
config DISK_MEM_PSRAM_BASE
hex "Disk memory PSRAM base address"
default 0x28000000
config DISK_MEM_THREAD_PRIORITY
int "Disk memory thread priority"
default 10
config DISK_MEM_THREAD_STACK_SIZE
int "Disk memory thread stack size"
default 0x600
choice
prompt "disk memory type"
default DISK_MEM_SERVER if LSF_CLIENT
default DISK_MEM_CLIENT if LSF_SERVER
config DISK_MEM_CLIENT
bool "disk memory client"
config DISK_MEM_SERVER
bool "disk memory server"
endchoice
if DISK_MEM_SERVER
config DISK_MEM_SD_INDEX
int "Disk memory SD index"
default 0
endif
endif

View File

@@ -0,0 +1,38 @@
#ifndef __DISK_MEM_H__
#define __DISK_MEM_H__
#define DISK_MEM_TEST 0
#if DISK_MEM_TEST == 1
#define DISK_MEM_TEST_PSRAM_MAX_SIZE_MB (6)
#define DISK_MEM_TEST_RUNTIME_CRC 0
#endif
#define DISK_MEM_RESERVED_FLAG_IMMEDIATELY (1 << 0)
typedef struct disk_mem_msg {
uint32_t opcode : 1; /* 0: request, 1:responese */
uint32_t err : 1;
uint32_t reserved : 30;
uint32_t nand_addr; /* max support 1024M */
uint32_t buf; /* max support 16M */
uint32_t size; /* max support 16M */
} __attribute__((packed)) disk_mem_msg_t;
typedef void (*disk_mem_callback_t)(disk_mem_msg_t *, void *);
/* Make sure don't touch the buf address before the callback */
int32_t disk_mem_request(disk_mem_msg_t *msg, disk_mem_callback_t cb, void *datas);
int32_t disk_mem_init(void);
int32_t disk_mem_read_request(void *dst, void *src, uint32_t size, disk_mem_callback_t cb,
void *user_data);
int32_t disk_mem_read_request_sync(void *dst, void *src, uint32_t size, void *user_data);
int32_t disk_mem_read_request_async(void *dst, void *src, uint32_t size, void *user_data);
int32_t disk_mem_read_request_async_wait(uint32_t timeout_ms);
#endif

View File

@@ -0,0 +1,455 @@
#include <stdint.h>
#include <string.h>
#include "disk_mem.h"
#include "ic_message.h"
#include "platform.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "disk_mem.h"
#include "log_print.h"
#include "lisa_log.h"
#define DISK_MEM_CALLBACK_COUNT 10
#define DISK_MEM_RESP_COUNT 3
// 缓存清理分段配置
#define DCACHE_CHUNK_SIZE (128 << 10) // 每次清理128KB
#define DISK_MEM_PSRAM_2_URPC_VALUE(addr) ((addr) - CONFIG_DISK_MEM_PSRAM_BASE)
#define DISK_MEM_URPC_2_PSRAM_VALUE(addr) ((addr) + CONFIG_DISK_MEM_PSRAM_BASE)
typedef struct disk_mem_urpc_msg {
uint32_t opcode : 1; /* 0: request, 1:responese */
uint32_t ext : 1; /* 0: ok, 1:err for responese, 0: normal 1: immediately of request*/
uint32_t nand_addr : 30; /* max support 1024M */
uint32_t buf : 24; /* max support 16M */
uint32_t size : 24; /* max support 16M */
} __attribute__((packed)) disk_mem_urpc_msg_t;
typedef struct callback_info {
uint32_t nand;
uint32_t size;
disk_mem_callback_t cb;
void *datas;
} callback_info_t;
typedef struct{
uint32_t err_code;/*0:拷贝成功,其他:拷贝失败*/
}disk_mem_copy_resp_t;
#define INVALID_NAND_ADDR (0xFFFFFFFF)
typedef struct disk_mem_msgq_item {
disk_mem_urpc_msg_t msg;
} __attribute__((aligned(4))) disk_mem_msgq_item_t;
static callback_info_t callbacks[DISK_MEM_CALLBACK_COUNT] = { 0 };
static callback_info_t callbacks_break[DISK_MEM_CALLBACK_COUNT] = { 0 };
static QueueHandle_t disk_mem_msgq;
static QueueHandle_t rx_queue;
#define DISK_MEM_THREAD_STACK_SIZE CONFIG_DISK_MEM_THREAD_STACK_SIZE
#define DISK_MEM_THREAD_PRIORITY CONFIG_DISK_MEM_THREAD_PRIORITY
int32_t disk_mem_handler(ic_message_handle_info_t *header, ic_message_msg_info_t* body)
{
uint8_t *frame = (uint8_t *)body->msg;
disk_mem_msgq_item_t item;
/* urpc payload size is 10 byte */
memcpy(&item.msg, &frame[0], 10);
xQueueSend(disk_mem_msgq, &item, portMAX_DELAY);
return 0;
}
static void disk_mem_cb(disk_mem_msg_t *msg, void *user_data){
disk_mem_copy_resp_t resp;
resp.err_code = msg->err;
if (pdTRUE != xQueueSend(rx_queue, &resp, 0)){
LOGE("Drop message");
}
}
/**
* @brief 分段缓存清理函数确保32字节对齐
* @param start 起始地址
* @param end 结束地址
*/
static void disk_mem_dcache_invalidate_chunked(unsigned long start, unsigned long end)
{
if (start >= end) {
return;
}
unsigned long total_size = end - start;
unsigned long processed = 0;
while (processed < total_size) {
unsigned long chunk_start = start + processed;
unsigned long chunk_size = (total_size - processed > DCACHE_CHUNK_SIZE) ?
DCACHE_CHUNK_SIZE : (total_size - processed);
unsigned long chunk_end = chunk_start + chunk_size;
dcache_invalidate_range(chunk_start, chunk_end);
processed += chunk_size;
}
}
// static void disk_mem_dcache_clean_chunked(unsigned long start, unsigned long end)
// {
// if (start >= end) {
// return;
// }
// unsigned long total_size = end - start;
// unsigned long processed = 0;
// while (processed < total_size) {
// unsigned long chunk_start = start + processed;
// unsigned long chunk_size = (total_size - processed > DCACHE_CHUNK_SIZE) ?
// DCACHE_CHUNK_SIZE : (total_size - processed);
// unsigned long chunk_end = chunk_start + chunk_size;
// dcache_clean_range(chunk_start, chunk_end);
// processed += chunk_size;
// }
// }
static void disk_mem_thread(void * arg)
{
disk_mem_msgq_item_t item;
uint8_t i;
callback_info_t *cb_info = NULL;
while (1) {
int is_found = 0;
xQueueReceive(disk_mem_msgq, &item, portMAX_DELAY);
// CLOGD("disk mem request done, err:%d, buf:0x%x, nand:0x%x, size:%d", item.msg.ext,
// item.msg.buf, item.msg.nand_addr, item.msg.size);
cb_info = (item.msg.ext == 1) ? callbacks_break : callbacks;
for (i = 0; i < DISK_MEM_CALLBACK_COUNT; i++) {
if (cb_info[i].size == item.msg.size) {
if (cb_info[i].cb != NULL) {
disk_mem_msg_t msg = { 0 };
msg.buf = DISK_MEM_URPC_2_PSRAM_VALUE(item.msg.buf);
msg.err = item.msg.ext;
msg.nand_addr = item.msg.nand_addr;
msg.size = item.msg.size;
msg.opcode = item.msg.opcode;
if((msg.buf != CONFIG_DISK_MEM_PSRAM_BASE)&&(msg.size != 0)){
// DISK_MEM_CACHE_INVALID((uint32_t *)(uintptr_t)msg.buf, msg.size);
disk_mem_dcache_invalidate_chunked((unsigned long)msg.buf, (unsigned long)(msg.buf + msg.size));
}
#if DISK_MEM_TEST_RUNTIME_CRC == 1
crc32_init(0);
uint32_t crc = crc32_calc(msg.buf, msg.size, 0);
LOGI("buf:%x, size:%d, crc value:%x", msg.buf, msg.size,
crc);
#endif
// __disable_irq();
disk_mem_callback_t cb_cb = cb_info[i].cb;
// cb_info[i].cb(&msg, cb_info[i].datas);
is_found = 1;
cb_info[i].nand = INVALID_NAND_ADDR;
cb_info[i].cb = 0;
cb_info[i].size = 0;
cb_cb(&msg, cb_info[i].datas);
// __enable_irq();
// (void)ps;
break;
}
}
}
if((is_found == 0)&&(!((item.msg.ext == 0)&&(item.msg.size)))){
LOGW("Can't find %s,size(%d),ext(%d),ch_info:",
(item.msg.ext == 1) ? "callbacks_break" : "callbacks",
item.msg.size,
item.msg.ext);
for (i = 0; i < DISK_MEM_CALLBACK_COUNT; i++) {
LOGD("i:%d,size:%d,cb:%p",i,cb_info[i].size,cb_info[i].cb);
}
}
/*如果资源加载被打断仍然调用资源加载的cb避免加载阻塞*/
if(item.msg.ext == 1){
is_found = 0;
cb_info = callbacks;
for (i = 0; i < DISK_MEM_CALLBACK_COUNT; i++) {
if (cb_info[i].size == item.msg.size) {
if (cb_info[i].cb != NULL) {
disk_mem_msg_t msg = { 0 };
msg.buf = DISK_MEM_URPC_2_PSRAM_VALUE(item.msg.buf);
msg.err = item.msg.ext;
msg.nand_addr = item.msg.nand_addr;
msg.size = item.msg.size;
msg.opcode = item.msg.opcode;
if((msg.buf != CONFIG_DISK_MEM_PSRAM_BASE)&&(msg.size != 0)){
// DISK_MEM_CACHE_INVALID((uint32_t *)(uintptr_t)msg.buf, msg.size);
disk_mem_dcache_invalidate_chunked((unsigned long)msg.buf, (unsigned long)(msg.buf + msg.size));
}
#if DISK_MEM_TEST_RUNTIME_CRC == 1
crc32_init(0);
uint32_t crc = crc32_calc(msg.buf, msg.size, 0);
LOGI("buf:%x, size:%d, crc value:%x", msg.buf, msg.size,
crc);
#endif
cb_info[i].cb(&msg, cb_info[i].datas);
is_found = 1;
// __disable_irq();
cb_info[i].nand = INVALID_NAND_ADDR;
cb_info[i].cb = 0;
cb_info[i].size = 0;
// __enable_irq();
// (void)ps;
break;
}
}
}
if(is_found == 0){
LOGW("Can't find callback,size(%d) by break request,ch_info:", item.msg.size);
for (i = 0; i < DISK_MEM_CALLBACK_COUNT; i++) {
LOGD("i:%d,size:%d,cb:%p",i,cb_info[i].size,cb_info[i].cb);
}
}
}
}
}
int32_t disk_mem_init(void)
{
int err;
uint32_t i;
err = ic_message_register_by_id(IC_MESSAGE_ID_DISK_MEM, disk_mem_handler,NULL);
if (err != 0) {
LOGE("disk mem service register failed, err:%d", err);
return err;
}
disk_mem_msgq = xQueueCreate(DISK_MEM_CALLBACK_COUNT, sizeof(disk_mem_msgq_item_t));
if (disk_mem_msgq == NULL) {
LOGE("disk mem create msgq failed, size:%d",sizeof(disk_mem_msgq_item_t));
return -1;
}
rx_queue = xQueueCreate(DISK_MEM_RESP_COUNT, sizeof(disk_mem_copy_resp_t));
if (rx_queue == NULL) {
LOGE("disk mem create rx_queue failed, size:%d",sizeof(disk_mem_copy_resp_t));
return -1;
}
err = xTaskCreate(
disk_mem_thread,
"disk_mem_thread",
DISK_MEM_THREAD_STACK_SIZE,
NULL,
DISK_MEM_THREAD_PRIORITY,
NULL);
if (err != pdTRUE) {
LOGE("disk mem create task failed, err:%d", err);
return err;
}
for (i = 0; i < DISK_MEM_CALLBACK_COUNT; i++) {
callbacks[i].nand = INVALID_NAND_ADDR;
callbacks[i].cb = 0;
}
#if DISK_MEM_TEST == 1
extern void disk_mem_request_run(void);
disk_mem_request_run();
#endif
return 0;
}
int32_t disk_mem_request(disk_mem_msg_t *msg, disk_mem_callback_t cb, void *user_data)
{
uint8_t i = 0;
int err;
if (msg == NULL || msg->nand_addr == INVALID_NAND_ADDR) {
return -1;
}
if (msg->size > (16 * 1024 * 1024)) {
return -2;
}
if (DISK_MEM_PSRAM_2_URPC_VALUE(msg->buf) > (16 * 1024 * 1024)) {
return -3;
}
if (msg->nand_addr > (1024 * 1024 * 1024)) {
return -4;
}
if (msg->reserved & DISK_MEM_RESERVED_FLAG_IMMEDIATELY) {
/* clear all callbacks */
for (i = 0; i < DISK_MEM_CALLBACK_COUNT; i++) {
// __disable_irq();
callbacks[i].nand = INVALID_NAND_ADDR;
callbacks[i].size = 0;
callbacks[i].cb = 0;
callbacks[i].datas = NULL;
// __enable_irq();
// (void)ps;
}
}
if(msg->buf != 0x60000000){
for (i = 0; i < DISK_MEM_CALLBACK_COUNT; i++) {
if (callbacks[i].size == 0 || callbacks[i].size == msg->size) {
// __disable_irq();
callbacks[i].nand = msg->nand_addr;
callbacks[i].cb = cb;
callbacks[i].datas = user_data;
callbacks[i].size = msg->size;
// __enable_irq();
// (void)ps;
break;
}
}
if (i >= DISK_MEM_CALLBACK_COUNT) {
/* no more free space */
return -5;
}
} else {
if(cb != NULL){
for (i = 0; i < DISK_MEM_CALLBACK_COUNT; i++) {
if (callbacks_break[i].cb == NULL || callbacks_break[i].size == msg->size) {
// __disable_irq();
callbacks_break[i].nand = msg->nand_addr;
callbacks_break[i].cb = cb;
callbacks_break[i].datas = user_data;
callbacks_break[i].size = msg->size;
// __enable_irq();
// (void)ps;
LOGI("Add callbacks_break cb:%p size:%d", callbacks_break[i].cb, callbacks_break[i].size );
break;
}
}
}
else{
LOGW("cb is NULL not add callback(%p) for size:%d", cb,callbacks_break[i].size );
}
}
disk_mem_urpc_msg_t urpc_msg = { 0 };
urpc_msg.buf = DISK_MEM_PSRAM_2_URPC_VALUE(msg->buf);
urpc_msg.ext = msg->reserved & DISK_MEM_RESERVED_FLAG_IMMEDIATELY;
urpc_msg.opcode = 0;
urpc_msg.nand_addr = msg->nand_addr;
urpc_msg.size = msg->size;
/* Ensure that the address is cleared from the cache */
// DISK_MEM_CACHE_CLEAN((uint32_t *)(uintptr_t)msg->buf, msg->size);
dcache_clean_range((unsigned long)msg->buf, (unsigned long)(msg->buf + msg->size));
// LOGD("disk mem request, buf:0x%x, nand:0x%x, size:%d", urpc_msg.buf, urpc_msg.nand_addr, urpc_msg.size);
while(!ic_message_remote_is_connected(IC_MESSAGE_ID_DISK_MEM)) {
vTaskDelay(pdMS_TO_TICKS(10));
}
/* send msg to ap */
err = ic_message_msg_send_by_id(IC_MESSAGE_ID_DISK_MEM, IC_MESSAGE_MSG_TYPE_EVT,
(uint8_t *)&urpc_msg, sizeof(disk_mem_urpc_msg_t));
if (err != 0) {
LOGE("disk mem request failed: %d", err);
return err;
}
return 0;
}
int32_t disk_mem_read_request(void *dst, void *src, uint32_t size, disk_mem_callback_t cb,
void *user_data)
{
disk_mem_msg_t msg = {
.buf = (uint32_t)dst,
.size = size,
.opcode = 0,
.nand_addr = (uint32_t)src,
};
return disk_mem_request(&msg, cb, user_data);
}
int32_t disk_mem_read_request_sync(void *dst, void *src, uint32_t size, void *user_data)
{
int ret;
disk_mem_copy_resp_t resp;
ret = disk_mem_read_request(dst, src, size, disk_mem_cb, user_data);
if(pdTRUE != xQueueReceive(rx_queue, &resp, pdMS_TO_TICKS(10000))){
LOGE("disk_mem_read_request_sync timeout ret:%d!", ret);
}
return ret;
}
int32_t disk_mem_read_request_async(void *dst, void *src, uint32_t size, void *user_data)
{
return disk_mem_read_request(dst, src, size, disk_mem_cb, user_data);
}
int32_t disk_mem_read_request_async_wait(uint32_t timeout_ms)
{
disk_mem_copy_resp_t resp;
if(pdTRUE != xQueueReceive(rx_queue, &resp, pdMS_TO_TICKS(timeout_ms))){
LOGE("disk_mem_read_request_sync timeout!");
return -5;
}
return 0;
}
int32_t disk_mem_clear_request(disk_mem_callback_t cb, void *user_data)
{
disk_mem_msg_t msg = {
.buf = (uint32_t)0x60000000, /* */
.size = 0,
.opcode = 0,
.reserved = DISK_MEM_RESERVED_FLAG_IMMEDIATELY,
.nand_addr = 0,
};
return disk_mem_request(&msg, cb, user_data);
}
int32_t disk_mem_read_request_stop_by_size(disk_mem_callback_t cb, void *user_data, uint32_t size)
{
disk_mem_msg_t msg = {
.buf = (uint32_t)0x60000000, /* */
.size = size,
.opcode = 0,
.reserved = 0,
.nand_addr = 0,
};
return disk_mem_request(&msg, cb, user_data);
}

View File

@@ -0,0 +1,13 @@
#ifndef __DISK_MEM_H__
#define __DISK_MEM_H__
enum {
DISK_MEM_ERR_NONE = 0,
DISK_MEM_ERR_BREAKED = -1,
DISK_MEM_ERR_ACCESS_FAILED = -2,
DISK_MEM_ERR_DMA_FAILED = -3,
};
void disk_mem_urpc_init(void);
#endif

View File

@@ -0,0 +1,194 @@
#include "stdint.h"
#include "disk/disk_access.h"
#include "ic_message.h"
#include "platform.h"
#include "FreeRTOS.h"
#include "task.h"
#include "queue.h"
#include "lib_sdc.h"
#include "drv_sdc.h"
#include "disk_mem.h"
#include "log_print.h"
#if CONFIG_DISK_MEMORY_DEBUG_CRC
#include "../crc32/crc32.h"
#endif
#define DISK_MEM_MSG_OPCODE_REQUEST (0)
#define DISK_MEM_MSG_OPCODE_RESPONSE (1)
#define DISK_MEM_PSRAM_2_URPC_VALUE(addr) ((addr)- CONFIG_DISK_MEM_PSRAM_BASE)
#define DISK_MEM_URPC_2_PSRAM_VALUE(addr) ((addr) + CONFIG_DISK_MEM_PSRAM_BASE)
#define DISK_MEM2SEC(addr, sec_size) ((addr) / (sec_size))
#define DISK_MEM_MSGQ_COUNT 10
enum {
DISK_MEM_RES_ERR_CODE_NONE = 0,
DISK_MEM_RES_ERR_CODE_FAILED = 1,
};
enum {
DISK_MEM_REQ_NORMAL = 0,
DISK_MEM_REQ_IMMEDIATELY = 1,
};
typedef struct disk_mem_msg {
uint32_t opcode : 1; /* 0: request, 1:responese */
uint32_t ext : 1; /* err code for responese, flag for request */
uint32_t nand_addr : 30; /* max support 1024M */
uint32_t buf : 24; /* max support 16M */
uint32_t size : 24; /* max support 16M */
} __attribute__((packed)) disk_mem_msg_t;
typedef struct disk_mem_context {
const void *disk_drv;
uint32_t sec_cnt;
uint32_t sec_size;
} disk_mem_context_t;
disk_mem_context_t disk_mem_ctx;
static QueueHandle_t disk_mem_msgq;
static int disk_mem_init(void)
{
int err;
uint32_t blk_len, blk_num, erase_size;
disk_mem_ctx.disk_drv = CONFIG_DISK_SDMMC_VOLUME_NAME;
err = lib_sdc_get_card_info(CONFIG_DISK_MEM_SD_INDEX, &blk_len, &blk_num, &erase_size);
if(err != 0){
CLOGE("disk init failed, err:%d", err);
return err;
}
disk_mem_ctx.sec_cnt = blk_num;
disk_mem_ctx.sec_size = blk_len;
CLOGI("disk init succeeded, sector count:%d, sector size:%d", disk_mem_ctx.sec_cnt,
disk_mem_ctx.sec_size);
return 0;
}
static void disk_mem_urpc_evt_handler(uint8_t *frame)
{
disk_mem_msg_t *msg = (disk_mem_msg_t *)frame;
CLOGD("disk mem request received, nand:0x%x, buf:0x%x, size:%d", msg->nand_addr,
DISK_MEM_URPC_2_PSRAM_VALUE(msg->buf), msg->size);
if (msg->ext == DISK_MEM_REQ_IMMEDIATELY) {
CLOGE("Unsupported DISK_MEM_REQ_IMMEDIATELY request");
} else {
if (msg->buf == 0x00 && msg->nand_addr == 0x00) {
CLOGE("Invailed request address");
} else {
int err = xQueueSend(disk_mem_msgq, msg, portMAX_DELAY);
if (err != pdTRUE) {
CLOGE("disk mem msgq put failed, err:%d", err);
}
}
}
}
static int32_t disk_mem_ic_message_handler(ic_message_handle_info_t *handle_info, ic_message_msg_info_t* msg_info)
{
(void)handle_info;
disk_mem_urpc_evt_handler((uint8_t *)(msg_info->msg));
return 0;
}
static inline int disk_memcpy(void *dst, void *src, uint32_t size)
{
int err;
uint8_t* data = dst;
uint32_t len;
len = (size + disk_mem_ctx.sec_size - 1) / disk_mem_ctx.sec_size * disk_mem_ctx.sec_size;
err = gm_sdc_api_sdcard_sector_read(
CONFIG_DISK_MEM_SD_INDEX,
DISK_MEM2SEC((uint32_t)src,disk_mem_ctx.sec_size),
DISK_MEM2SEC((uint32_t)len,disk_mem_ctx.sec_size),
dst);
return err;
}
static void disk_mem_urpc_notify_done(disk_mem_msg_t *msg)
{
int err = ic_message_msg_send_by_id(IC_MESSAGE_ID_DISK_MEM, IC_MESSAGE_MSG_TYPE_CMD, (uint8_t *)msg, sizeof(disk_mem_msg_t));
if (err != IC_MESSAGE_ERR_NONE) {
CLOGE("disk mem send notify failed: %d", err);
}
}
static void disk_mem_server_thread_handler(void *p1)
{
int err;
disk_mem_msg_t msg;
TickType_t ticks;
while (1) {
err = xQueueReceive(disk_mem_msgq, &msg, portMAX_DELAY);
if ((err != pdTRUE)||(msg.buf == 0)) {
continue;
}
ticks = xTaskGetTickCount();
err = disk_memcpy((void *)DISK_MEM_URPC_2_PSRAM_VALUE(msg.buf),
(void *)((uint32_t)msg.nand_addr), msg.size);
ticks = xTaskGetTickCount() - ticks;
msg.opcode = DISK_MEM_MSG_OPCODE_RESPONSE;
msg.ext = !!err;
DISK_MEM_CACHE_CLEAN((void *)DISK_MEM_URPC_2_PSRAM_VALUE(msg.buf), msg.size);
#if CONFIG_DISK_MEMORY_DEBUG_CRC
uint32_t crc32 = crc32_calc(DISK_MEM_URPC_2_PSRAM_VALUE(msg.buf), msg.size, 0);
#endif
CLOGD("disk memcpy done, err:%d, nand:0x%x, buf:0x%x, size:%d, time:%lld ms\n",
err,
msg.nand_addr,
DISK_MEM_URPC_2_PSRAM_VALUE(msg.buf),
msg.size,
(ticks * (1000 / configTICK_RATE_HZ)));
#if CONFIG_DISK_MEMORY_DEBUG_CRC
CLOGI("crc32:0x%x", crc32);
#endif
disk_mem_urpc_notify_done(&msg);
}
}
#define DISK_MEM_SERVER_THREAD_STACK_SIZE CONFIG_DISK_MEM_THREAD_STACK_SIZE
#define DISK_MEM_THREAD_PRIORITY CONFIG_DISK_MEM_THREAD_PRIORITY
void disk_mem_urpc_init(void)
{
int err;
disk_mem_msgq = xQueueCreate(DISK_MEM_MSGQ_COUNT, sizeof(disk_mem_msg_t));
disk_mem_init();
ic_message_register_by_id(IC_MESSAGE_ID_DISK_MEM, disk_mem_ic_message_handler, NULL);
err = xTaskCreate(
disk_mem_server_thread_handler,
"disk_mem_server_thread",
DISK_MEM_SERVER_THREAD_STACK_SIZE,
NULL,
DISK_MEM_THREAD_PRIORITY,
NULL);
CLOGI("disk mem inited");
}

View File

@@ -0,0 +1,217 @@
#include "ic_message.h"
#include "urpc_api.h"
#include <string.h>
#if CONFIG_LSF_CLIENT
#include "rpc_client.h"
#include "ic_proxy.h"
#elif CONFIG_LSF_SERVER
#include "ic_service.h"
#include "rpc_server.h"
#else
#error lsf type not configured
#endif
#if CONFIG_ARCS_HAL_IC_MUTEX
#include "ic.h"
#endif
#ifndef NULL
#define NULL 0
#endif
#ifndef CONFIG_LSF_IC_MESSAGE_EP_ID
#error The value of CONFIG_LSF_IC_MESSAGE_EP_ID is not defined, uncomment this line to use the default value.
#define CONFIG_LSF_IC_MESSAGE_EP_ID 5
#endif
#if CONFIG_LSF_IC_MESSAGE_LOG
#endif
#if CONFIG_LSF_OS_XOS
/* FIXME: */
#define lsf_task_enter_critcal()
#define lsf_task_exit_critcal()
#else
#define lsf_task_enter_critcal()
#define lsf_task_exit_critcal()
#endif
typedef struct ic_message_inner_conn_data {
uint8_t id;
} __attribute__ ((__packed__)) ic_message_inner_conn_data_t;
static ic_message_handle_info_t handle_infos[IC_MESSAGE_ID_MAX] = {0};
static urpc_handle ic_message_ep_handles[IC_MESSAGE_ID_MAX] = {0};
static uint8_t ic_message_inited = 0;
static int32_t ic_message_inner_conn_msg_send(uint8_t id)
{
ic_message_inner_conn_data_t data = {
.id = id,
};
return ic_message_msg_send_by_id(IC_MESSAGE_ID_INNER_CONN, IC_MESSAGE_MSG_TYPE_CMD, &data, sizeof(data));
}
static void ic_message_urpc_handler(urpc_frame *frame)
{
uint8_t id = frame->rpc.dst_id;
if (id >= IC_MESSAGE_ID_MAX) {
/* error invalid id */
}
if (handle_infos[id].cb != NULL) {
ic_message_msg_info_t msg;
msg.len = 10;
msg.msg_type = IC_MESSAGE_MSG_TYPE_CMD;
msg.msg = &frame->rpc.payload[0];
(void)((ic_message_callback_t)handle_infos[id].cb)(&handle_infos[id], &msg);
}
}
int ic_message_register_by_id(uint8_t id, ic_message_callback_t cb, void *user_datas)
{
if (id >= IC_MESSAGE_ID_MAX) {
return IC_MESSAGE_ERR_ID_INVALID;
}
if (handle_infos[id].cb != NULL) {
return IC_MESSAGE_ERR_NOT_NULL;
}
if (!ic_message_inited) {
return IC_MESSAGE_ERR_NOT_INITED;
}
lsf_task_enter_critcal();
handle_infos[id].cb = cb;
handle_infos[id].id = id;
handle_infos[id].user_datas = user_datas;
lsf_task_exit_critcal();
return ic_message_inner_conn_msg_send(id);
}
int ic_message_msg_send_by_id(uint8_t id, uint8_t type, void *msg, uint32_t len)
{
urpc_frame frame[16] = { 0 };
int r = 0;
if (!ic_message_inited) {
return IC_MESSAGE_ERR_NOT_INITED;
}
if (id >= IC_MESSAGE_ID_MAX) {
return IC_MESSAGE_ERR_ID_INVALID;
}
if (len > 10 || msg == NULL ) {
return IC_MESSAGE_ERR_PARAM_INVALID;
}
if (id != IC_MESSAGE_ID_INNER_CONN && !handle_infos[id].remote_conn) {
return IC_MESSAGE_ERR_REMOTE_NOT_CONN;
}
frame->header.eps = CONFIG_LSF_IC_MESSAGE_EP_ID;
if (type == IC_MESSAGE_MSG_TYPE_EVT) {
frame->rpc.dst_id = id;
frame->rpc.src_id = id;
} else if (type == IC_MESSAGE_MSG_TYPE_CMD) {
frame->rpc.dst_id = id;
frame->rpc.src_id = id;
/* TODO: FIX ME */
} else {
return IC_MESSAGE_ERR_PARAM_INVALID;
}
memcpy(&frame->rpc.payload[0], msg, len);
#if CONFIG_LSF_CLIENT
r = urpc_send_async_client(RPC_Client_stub, (urpc_frame *)&frame);
#elif CONFIG_LSF_SERVER
r = urpc_push_event_server(RPC_Server_stub, (urpc_frame *)&frame);
#endif
if (r) {
return IC_MESSAGE_ERR_URPC;
}
return IC_MESSAGE_ERR_NONE;
}
static int32_t ic_message_inner_conn_cb(ic_message_handle_info_t *handle_info, ic_message_msg_info_t* msg_info)
{
(void)handle_info;
ic_message_inner_conn_data_t *inner_conn_data = msg_info->msg;
if (inner_conn_data->id >= IC_MESSAGE_ID_MAX) {
return IC_MESSAGE_ERR_ID_INVALID;
}
handle_infos[inner_conn_data->id].remote_conn = 1;
return 0;
}
int ic_message_init(void)
{
uint8_t i;
if (ic_message_inited) {
return IC_MESSAGE_ERR_INITED;
}
for (i = 0; i < IC_MESSAGE_ID_MAX; i++) {
ic_message_ep_handles[i].flag = URPC_FLAG_ASYNC;
ic_message_ep_handles[i].handler = ic_message_urpc_handler;
}
/* inner conn handle, uper not care, must before RPC_XXX_START() */
handle_infos[IC_MESSAGE_ID_INNER_CONN].cb = ic_message_inner_conn_cb;
handle_infos[IC_MESSAGE_ID_INNER_CONN].id = IC_MESSAGE_ID_INNER_CONN;
handle_infos[IC_MESSAGE_ID_INNER_CONN].user_datas = NULL;
handle_infos->remote_conn = 1;
#if CONFIG_LSF_CLIENT
RPC_Client_eps[CONFIG_LSF_IC_MESSAGE_EP_ID].handles = ic_message_ep_handles;
RPC_Client_eps[CONFIG_LSF_IC_MESSAGE_EP_ID].handles_cnt = ARRSIZE(ic_message_ep_handles);
#ifndef CONFIG_ARCS_HAL_IC_MUTEX
RPC_Client_init();
IC_Proxy_init();
RPC_Client_Start();
#else
IC_System_initialize();
IC_System_sync();
#endif
#elif CONFIG_LSF_SERVER
RPC_Server_eps[CONFIG_LSF_IC_MESSAGE_EP_ID].handles = ic_message_ep_handles;
RPC_Server_eps[CONFIG_LSF_IC_MESSAGE_EP_ID].handles_cnt = ARRSIZE(ic_message_ep_handles);
#ifndef CONFIG_ARCS_HAL_IC_MUTEX
RPC_Server_init();
RPC_Server_Start();
IC_Service_init();
#else
IC_System_initialize();
IC_System_sync();
#endif
#else
#error lsf config error
#endif
ic_message_inited = 1;
return IC_MESSAGE_ERR_NONE;
}
uint8_t ic_message_remote_is_connected(uint8_t id)
{
return (id < IC_MESSAGE_ID_MAX) & handle_infos[id].remote_conn;
}

View File

@@ -0,0 +1,78 @@
#ifndef __IC_MESSAGE_H__
#define __IC_MESSAGE_H__
#include <stdint.h>
#ifndef ARRSIZE
#define ARRSIZE(x) (sizeof(x) / sizeof((x)[0]))
#endif
enum {
IC_MESSAGE_ID_RESERVE_0 = 0,
IC_MESSAGE_ID_RESERVE_1,
IC_MESSAGE_ID_RESERVE_2,
IC_MESSAGE_ID_RESERVE_3,
IC_MESSAGE_ID_INNER_CONN, /* Do not touch this id */
IC_MESSAGE_ID_OCR,
IC_MESSAGE_ID_STREAM,
IC_MESSAGE_ID_COMMON,
IC_MESSAGE_ID_TTS,
IC_MESSAGE_ID_TRANS,
IC_MESSAGE_ID_MIC,
IC_MESSAGE_ID_RESOURCE,
IC_MESSAGE_ID_DISK_MEM,
IC_MESSAGE_ID_CSP,
IC_MESSAGE_ID_WSP,
IC_MESSAGE_ID_COMP_RES,
IC_MESSAGE_ID_SPD,
IC_MESSAGE_ID_CSPS,
IC_MESSAGE_ID_EQUALIZER,
IC_MESSAGE_ID_GOCR,
IC_MESSAGE_ID_FLASH_MSG,
IC_MESSAGE_ID_SPINLOCK,
IC_MESSAGE_ID_IVW,
IC_MESSAGE_ID_DAC,
IC_MESSAGE_ID_ADC,
IC_MESSAGE_ID_ACOMP,
IC_MESSAGE_ID_MAX,
};
typedef enum {
IC_MESSAGE_MSG_TYPE_ERR,
IC_MESSAGE_MSG_TYPE_CMD,
IC_MESSAGE_MSG_TYPE_EVT,
IC_MESSAGE_MSG_TYPE_STREAM,
} ic_message_msg_type_t;
typedef struct ic_message_handle_info {
void *user_datas;
void *cb;
uint8_t id;
uint8_t remote_conn;
} ic_message_handle_info_t;
typedef struct ic_message_msg_info {
void *msg;
uint32_t len;
uint8_t msg_type;
} ic_message_msg_info_t;
typedef int32_t (*ic_message_callback_t)(ic_message_handle_info_t *, ic_message_msg_info_t*);
int ic_message_init();
int ic_message_register_by_id(uint8_t service_id, ic_message_callback_t cb, void *user_datas);
int ic_message_msg_send_by_id(uint8_t service_id, uint8_t type, void *msg, uint32_t len);
uint8_t ic_message_remote_is_connected(uint8_t id);
enum {
IC_MESSAGE_ERR_NONE = 0,
IC_MESSAGE_ERR_NOT_NULL,
IC_MESSAGE_ERR_ID_INVALID,
IC_MESSAGE_ERR_PARAM_INVALID,
IC_MESSAGE_ERR_INITED,
IC_MESSAGE_ERR_URPC,
IC_MESSAGE_ERR_REMOTE_NOT_CONN,
IC_MESSAGE_ERR_NOT_INITED,
};
#endif

View File

@@ -0,0 +1,13 @@
#ifndef _DISK_MEM_PLATFORM_H_
#define _DISK_MEM_PLATFORM_H_
#include "cache.h"
#define DISK_MEM_CACHE_FLUSH(addr, size) HAL_FlushInvalidateDCache_by_Addr(addr, size)
#define DISK_MEM_CACHE_CLEAN(addr, size) HAL_FlushDCache_by_Addr(addr, size)
#define DISK_MEM_CACHE_INVALID(addr, size) HAL_InvalidateDCache_by_Addr(addr, size)
#define DISK_MEM_ENTER_CRITCAL() (0)
#define DISK_MEM_EXIT_CRITCAL(x)
#endif