/* * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. * * SPDX-License-Identifier: MIT */ #include #include #include "FreeRTOS.h" #include "task.h" #include "queue.h" #include "semphr.h" #include #include #include "n200_func.h" #include "uart.h" #include "common.h" #include "riscv_encoding.h" #include "mailbox-rpc-test.h" #define MBTAG "AOCPU" #define PRINT(...) printf(__VA_ARGS__) #define PRINT_DBG(...) //printf(__VA_ARGS__) #ifdef CONFIG_MAILBOX_SEND #define AO2ARM_INTERVAL (2000) // ms TaskHandle_t AoSendHandler; static struct xClientMboxChan *pxAO2ARMChan; #endif struct Uintcase { char data[20]; uint32_t ulTaskDelay; }; static inline void *mbmemset(void *dst, int val, size_t count) { char *ptr = dst; while (count--) *ptr++ = val; return dst; } static inline void *mbmemcpy(void *dst, const void *src, size_t len) { const char *s = src; char *d = dst; while (len--) *d++ = *s++; return dst; } static void xMboxUintReeTestCase(void *msg) { struct Uintcase *pdata = msg; char back[20] = "Response AOCPU\n"; PRINT("[%s]: scpi %s\n", MBTAG, pdata->data); mbmemset(msg, 0, MBOX_BUF_LEN); mbmemcpy(msg, back, sizeof(back)); PRINT("[%s]: delay after %d\n", MBTAG, pdata->ulTaskDelay); } static void xMboxUintTeeTestCase(void *msg) { char *s = msg; PRINT("[%s]: from tee: %s\n", MBTAG, s); } #ifdef CONFIG_MAILBOX_SEND static void xMboxAoSendTestCase(void *msg) { char *str = msg; PRINT("[%s]: received: %s\n", MBTAG, str); xTaskNotifyGive(AoSendHandler); } /* AOCPU send mailbox to ARMREE test task */ static void vAoSendTask(void *pvParameters) { struct xMboxData xMboxData; char cSendMsg[20] = {0}; (void)pvParameters; snprintf(cSendMsg, sizeof(cSendMsg), "Data from AOCPU\n"); xMboxData.ulCmd = MBX_CMD_SEND_AO2AP_TEST; xMboxData.pvTxbuf = cSendMsg; xMboxData.pvRxbuf = NULL; xMboxData.ucTxSize = sizeof(cSendMsg); xMboxData.ucRxSize = 0; while (1) { ulTaskNotifyTake(pdTRUE, portMAX_DELAY); PRINT("[%s]: Received notify, start to send mailbox to ARMREE\n", MBTAG); xMboxSendMsg(pxAO2ARMChan, &xMboxData); vTaskDelay(pdMS_TO_TICKS(AO2ARM_INTERVAL)); } } #endif static int vRegisterRpcCallBack(void) { int ret; ret = xInstallRemoteMessageCallbackFeedBack(REE2AO_CHANNEL, MBX_CMD_RPCUINTREE_TEST, (void *)xMboxUintReeTestCase, 1); if (ret) return ERR_MBOX(ENOSPC); ret = xInstallRemoteMessageCallbackFeedBack(TEE2AO_CHANNEL, MBX_CMD_RPCUINTTEE_TEST, (void *)xMboxUintTeeTestCase, 0); if (ret) return ERR_MBOX(ENOSPC); #ifdef CONFIG_MAILBOX_SEND if (pxAO2ARMChan) { ret = xInstallRemoteMessageCallbackFeedBack(REE2AO_CHANNEL, MBX_CMD_TRIGGER_AO2AP_SEND, (void *)xMboxAoSendTestCase, 0); if (ret) { PRINT("[%s]: mbox cmd 0x%x register fail\n", MBTAG, MBX_CMD_TRIGGER_AO2AP_SEND); return ERR_MBOX(ENOSPC); } xTaskCreate(vAoSendTask, "AOSendTask", configMINIMAL_STACK_SIZE, 0, TASK_PRIORITY, (TaskHandle_t *)&AoSendHandler); } #endif return 0; } int vRpcUserCmdInit(void) { int ret; #ifdef CONFIG_MAILBOX_SEND pxAO2ARMChan = xMboxRequestChan(AO2REE_DEV); if (!pxAO2ARMChan) PRINT("[%s]: pxAO2ARMChan request fail!\n", MBTAG); #endif ret = vRegisterRpcCallBack(); return ret; }