Jonny Svärd | 44398c8 | 2020-10-06 14:18:28 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2020 Arm Limited. All rights reserved. |
| 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 MAILBOX_HPP |
| 20 | #define MAILBOX_HPP |
| 21 | |
| 22 | #include <cstddef> |
| 23 | #include <list> |
| 24 | |
| 25 | namespace Mailbox { |
| 26 | |
| 27 | class Mailbox { |
| 28 | public: |
| 29 | Mailbox(); |
| 30 | virtual ~Mailbox(); |
| 31 | virtual bool sendMessage() = 0; |
| 32 | virtual void handleMessage() = 0; |
| 33 | virtual bool verifyHardware(); |
| 34 | typedef void (*CallbackFptr)(void *userArg); |
| 35 | void registerCallback(CallbackFptr callback, void *userArg); |
| 36 | void deregisterCallback(CallbackFptr callback, void *userArg); |
| 37 | |
| 38 | protected: |
| 39 | void notify(); |
| 40 | uint32_t read32(volatile uint32_t *baseAddr, const uint32_t offset); |
| 41 | void write32(volatile uint32_t *baseAddr, const uint32_t offset, const uint32_t value); |
| 42 | |
| 43 | private: |
| 44 | struct Callback { |
| 45 | bool operator==(const Callback &b) const; |
| 46 | CallbackFptr callback; |
| 47 | void *userArg; |
| 48 | }; |
| 49 | |
| 50 | std::list<Callback> callbacks; |
| 51 | }; |
| 52 | |
| 53 | } // namespace Mailbox |
| 54 | |
| 55 | #endif |