Files
2026-08-24 10:03:24 +08:00

127 lines
2.8 KiB
C

/*
* Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
*
* SPDX-License-Identifier: MIT
*/
#include <stdlib.h>
#include <string.h>
#include "FreeRTOS.h"
#include "common.h"
#include "queue.h"
#include "semphr.h"
#include "mailbox_soc.h"
#include "mailbox-htbl.h"
#define MBTAG "AOCPU"
#define PRINT_ERR(...) printf(__VA_ARGS__)
#define PRINT_DBG(...) //printf(__VA_ARGS__)
struct xClientMboxChan *xMboxRequestChan(uint8_t ucClientChId)
{
BaseType_t xRet;
struct xMboxChan *pxChan;
struct xClientMboxChan *pxClientChan = NULL;
PRINT_DBG("[%s]: request channel: %d\n", MBTAG, ucClientChId);
xRet = xRegMboxClientChId(ucClientChId);
if (xRet)
return NULL;
pxChan = xGetMboxChan(ucClientChId);
if (pxChan) {
pxClientChan = malloc(sizeof(*pxClientChan));
if (pxClientChan == NULL) {
PRINT_ERR("[%s]: no enough memory!\n", MBTAG);
return NULL;
}
pxClientChan->ucClientChId = ucClientChId;
pxClientChan->pxMboxChan = pxChan;
}
return pxClientChan;
}
BaseType_t xMboxFreeChan(struct xClientMboxChan *pxClientChan)
{
BaseType_t xRet;
uint8_t ucClientChId;
if (!pxClientChan) {
PRINT_ERR("[%s]: error: pxChan is NULL!\n", MBTAG);
return ERR_MBOX(EINVAL);
}
ucClientChId = pxClientChan->ucClientChId;
xRet = xFreeMboxClientChId(ucClientChId);
vPortFree(pxClientChan);
return xRet;
}
#ifdef CONFIG_MAILBOX_SEND
BaseType_t xMboxSendMsg(struct xClientMboxChan *pxMboxChan, struct xMboxData *pxMboxData)
{
BaseType_t xRet;
if (!pxMboxChan || !pxMboxData) {
PRINT_ERR("[%s]: error: mbox_chan or mbox_data is NULL!\n", MBTAG);
return ERR_MBOX(EINVAL);
}
if (!pxMboxData->pvTxbuf || !pxMboxData->ucTxSize ||
pxMboxData->ucTxSize > MBOX_DATA_SIZE) {
PRINT_ERR("[%s]: error: mbox_data params are invalid!\n", MBTAG);
return ERR_MBOX(EINVAL);
}
xRet = iMboxTransData(pxMboxChan, pxMboxData);
return xRet;
}
#else
BaseType_t xMboxSendMsg(struct xClientMboxChan *pxMboxChan, struct xMboxData *pxMboxData)
{
UNUSED(pxMboxChan);
UNUSED(pxMboxData);
return 0;
}
#endif
int xInstallRemoteMessageCallbackFeedBack(uint32_t ulChan, uint32_t cmd,
void *(*handler)(void *arg), uint8_t needFdBak)
{
uint32_t ret;
REV_VALID_CHANNEL(ulChan);
UNUSED(ulChan);
ret = ulChkHtblInit(g_tbl_ao);
if (ret) {
PRINT_ERR("error: mailbox htbl is not initialized\n");
return ERR_MBOX(ENOSPC);
}
ret = mailbox_htbl_reg_feedback(g_tbl_ao, cmd, handler, needFdBak);
if (ret == MAX_ENTRY_NUM)
return ERR_MBOX(ENOSPC);
return 0;
}
int xUninstallRemoteMessageCallback(uint32_t ulChan, int32_t cmd)
{
uint32_t ret;
UNUSED(ulChan);
ret = ulChkHtblInit(g_tbl_ao);
if (ret) {
PRINT_ERR("error: mailbox htbl is not initialized\n");
return ERR_MBOX(ENOSPC);
}
ret = mailbox_htbl_unreg(g_tbl_ao, cmd);
if (ret == MAX_ENTRY_NUM)
return ERR_MBOX(EINVAL);
return 0;
}