Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 1 | /* |
Mikael Olsson | 34b190b | 2024-02-12 13:14:18 +0100 | [diff] [blame] | 2 | * SPDX-FileCopyrightText: Copyright 2022-2024 Arm Limited and/or its affiliates <open-source-office@arm.com> |
Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 3 | * SPDX-License-Identifier: Apache-2.0 |
| 4 | * |
| 5 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| 6 | * not use _this file except in compliance with the License. |
| 7 | * You may obtain a copy of the License at |
| 8 | * |
| 9 | * www.apache.org/licenses/LICENSE-2.0 |
| 10 | * |
| 11 | * Unless required by applicable law or agreed to in writing, software |
| 12 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | * See the License for the specific language governing permissions and |
| 15 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #pragma once |
| 19 | |
| 20 | /***************************************************************************** |
| 21 | * Includes |
| 22 | *****************************************************************************/ |
| 23 | |
Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 24 | #include <mailbox.hpp> |
Mikael Olsson | 34b190b | 2024-02-12 13:14:18 +0100 | [diff] [blame] | 25 | #include <rpmsg/ethosu_rpmsg.h> |
Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 26 | |
| 27 | #include "queue.hpp" |
| 28 | #include "remoteproc.hpp" |
| 29 | |
| 30 | /***************************************************************************** |
| 31 | * Messages |
| 32 | *****************************************************************************/ |
| 33 | |
| 34 | struct Message { |
| 35 | Message() {} |
| 36 | |
| 37 | Message(const uint32_t _src, |
Mikael Olsson | 6870951 | 2024-02-12 13:30:31 +0100 | [diff] [blame^] | 38 | const EthosU::ethosu_rpmsg_type _type = EthosU::ETHOSU_RPMSG_MAX, |
| 39 | const uint64_t msgId = 0, |
| 40 | const uint32_t _length = 0) : |
Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 41 | src(_src), |
| 42 | length(_length) { |
Mikael Olsson | 6870951 | 2024-02-12 13:30:31 +0100 | [diff] [blame^] | 43 | rpmsg.header.magic = ETHOSU_RPMSG_MAGIC; |
Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 44 | rpmsg.header.type = _type; |
| 45 | rpmsg.header.msg_id = msgId; |
| 46 | } |
| 47 | |
| 48 | uint32_t src = 0; |
| 49 | uint32_t length = 0; |
Mikael Olsson | 6870951 | 2024-02-12 13:30:31 +0100 | [diff] [blame^] | 50 | EthosU::ethosu_rpmsg rpmsg; |
Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /***************************************************************************** |
| 54 | * MessageHandler |
| 55 | *****************************************************************************/ |
| 56 | |
| 57 | class MessageHandler : public Rpmsg { |
| 58 | public: |
| 59 | using InferenceQueue = Queue<Message *>; |
| 60 | using ResponseQueue = Queue<Message *>; |
| 61 | |
| 62 | MessageHandler(RProc &rproc, const char *const name); |
| 63 | virtual ~MessageHandler(); |
| 64 | |
| 65 | InferenceQueue &getInferenceQueue() { |
| 66 | return inferenceQueue; |
| 67 | } |
| 68 | |
| 69 | InferenceQueue &getResponseQueue() { |
| 70 | return responseQueue; |
| 71 | } |
| 72 | |
| 73 | protected: |
| 74 | // Handle incoming rpmsg |
| 75 | int handleMessage(void *data, size_t len, uint32_t src) override; |
| 76 | |
| 77 | // Outgoing messages |
Mikael Olsson | 6870951 | 2024-02-12 13:30:31 +0100 | [diff] [blame^] | 78 | void sendError(const uint32_t src, const EthosU::ethosu_rpmsg_err_type type, const char *message); |
Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 79 | void sendPong(const uint32_t src, const uint64_t msgId); |
| 80 | void sendVersionRsp(const uint32_t src, const uint64_t msgId); |
| 81 | void sendCapabilitiesRsp(const uint32_t src, const uint64_t msgId); |
Mikael Olsson | 6870951 | 2024-02-12 13:30:31 +0100 | [diff] [blame^] | 82 | void sendNetworkInfoRsp(const uint32_t src, const uint64_t msgId, EthosU::ethosu_rpmsg_network_buffer &network); |
| 83 | void |
| 84 | forwardInferenceReq(const uint32_t src, const uint64_t msgId, const EthosU::ethosu_rpmsg_inference_req &inference); |
| 85 | void sendInferenceRsp(const uint32_t src, const uint64_t msgId, const EthosU::ethosu_rpmsg_status status); |
| 86 | void sendCancelInferenceRsp(const uint32_t src, const uint64_t msgId, const EthosU::ethosu_rpmsg_status status); |
Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 87 | |
Mikael Olsson | 6870951 | 2024-02-12 13:30:31 +0100 | [diff] [blame^] | 88 | EthosU::ethosu_rpmsg_capabilities_rsp getCapabilities() const; |
| 89 | bool getNetwork(EthosU::ethosu_rpmsg_network_buffer &buffer); |
Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 90 | |
| 91 | // Tasks returning response messages |
| 92 | static void responseTask(void *param); |
| 93 | |
| 94 | private: |
Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 95 | InferenceQueue inferenceQueue; |
| 96 | ResponseQueue responseQueue; |
Mikael Olsson | 6870951 | 2024-02-12 13:30:31 +0100 | [diff] [blame^] | 97 | EthosU::ethosu_rpmsg_capabilities_rsp capabilities; |
Kristofer Jonsson | 3f5510f | 2023-02-08 14:23:00 +0100 | [diff] [blame] | 98 | |
| 99 | // FreeRTOS |
| 100 | TaskHandle_t taskHandle; |
| 101 | }; |