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 | #include <mailbox.hpp> |
| 20 | |
Jonny Svärd | 44398c8 | 2020-10-06 14:18:28 +0200 | [diff] [blame] | 21 | #include <cassert> |
Kristofer Jonsson | 73ebc48 | 2020-10-12 11:17:04 +0200 | [diff] [blame] | 22 | #include <cstddef> |
Jonny Svärd | 44398c8 | 2020-10-06 14:18:28 +0200 | [diff] [blame] | 23 | |
| 24 | namespace Mailbox { |
| 25 | |
| 26 | Mailbox::Mailbox() {} |
| 27 | Mailbox::~Mailbox() {} |
| 28 | |
| 29 | bool Mailbox::verifyHardware() { |
| 30 | return true; |
| 31 | } |
| 32 | |
| 33 | void Mailbox::registerCallback(CallbackFptr callback, void *userArg) { |
| 34 | callbacks.push_back({callback, userArg}); |
| 35 | } |
| 36 | |
| 37 | void Mailbox::deregisterCallback(CallbackFptr callback, void *userArg) { |
| 38 | callbacks.remove({callback, userArg}); |
| 39 | } |
| 40 | |
| 41 | void Mailbox::notify() { |
| 42 | for (auto &it : callbacks) { |
| 43 | it.callback(it.userArg); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | uint32_t Mailbox::read32(volatile uint32_t *baseAddr, const uint32_t offset) { |
| 48 | assert(offset % 4 == 0); |
| 49 | volatile uint32_t *addr = baseAddr + (offset / 4); |
| 50 | |
| 51 | return *addr; |
| 52 | } |
| 53 | |
| 54 | void Mailbox::write32(volatile uint32_t *baseAddr, const uint32_t offset, const uint32_t value) { |
| 55 | assert(offset % 4 == 0); |
| 56 | volatile uint32_t *addr = baseAddr + (offset / 4); |
| 57 | |
| 58 | *addr = value; |
| 59 | } |
| 60 | |
| 61 | bool Mailbox::Callback::operator==(const Callback &b) const { |
| 62 | return (callback == b.callback && userArg == b.userArg); |
| 63 | } |
| 64 | |
| 65 | } // namespace Mailbox |