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