Davide Grohmann | ec72e9b | 2022-08-08 17:30:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 Arm Limited. |
| 3 | * |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the License); you may |
| 7 | * not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT |
| 14 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | */ |
| 18 | |
| 19 | #ifndef MESSAGE_CLIENT_H |
| 20 | #define MESSAGE_CLIENT_H |
| 21 | |
| 22 | #include <inttypes.h> |
| 23 | #include <stdio.h> |
| 24 | |
| 25 | #include "message_queue.hpp" |
| 26 | #include <mailbox.hpp> |
| 27 | |
| 28 | namespace MessageHandler { |
| 29 | |
| 30 | class MessageClient { |
| 31 | public: |
| 32 | MessageClient(EthosU::ethosu_core_queue &inputMessageQueue, |
| 33 | EthosU::ethosu_core_queue &outputMessageQueue, |
| 34 | Mailbox::Mailbox &mailbox); |
| 35 | |
| 36 | template <typename T> |
| 37 | bool sendInputMessage(const uint32_t type, const T &src) { |
| 38 | return sendInputMessage(type, reinterpret_cast<const uint8_t *>(&src), sizeof(src)); |
| 39 | } |
| 40 | bool sendInputMessage(const uint32_t type, const void *src = nullptr, uint32_t length = 0); |
| 41 | template <typename T> |
| 42 | bool waitAndReadOutputMessage(const uint32_t expected_type, T &dst) { |
| 43 | return waitAndReadOutputMessage(expected_type, reinterpret_cast<uint8_t *>(&dst), sizeof(dst)); |
| 44 | } |
| 45 | bool waitAndReadOutputMessage(const uint32_t expected_type, uint8_t *dst = nullptr, uint32_t length = 0); |
| 46 | |
| 47 | private: |
| 48 | MessageQueue::QueueImpl input; |
| 49 | MessageQueue::QueueImpl output; |
| 50 | Mailbox::Mailbox &mailbox; |
| 51 | }; |
| 52 | } // namespace MessageHandler |
| 53 | |
| 54 | #endif |