mbed-os5 only for TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Committer:
kenjiArai
Date:
Tue Dec 31 06:02:27 2019 +0000
Revision:
1:9db0e321a9f4
Parent:
0:5b88d5760320
updated based on mbed-os5.15.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 0:5b88d5760320 1 /* mbed Microcontroller Library
kenjiArai 0:5b88d5760320 2 * Copyright (c) 2017-2017 ARM Limited
kenjiArai 0:5b88d5760320 3 *
kenjiArai 0:5b88d5760320 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
kenjiArai 0:5b88d5760320 5 * of this software and associated documentation files (the "Software"), to deal
kenjiArai 0:5b88d5760320 6 * in the Software without restriction, including without limitation the rights
kenjiArai 0:5b88d5760320 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
kenjiArai 0:5b88d5760320 8 * copies of the Software, and to permit persons to whom the Software is
kenjiArai 0:5b88d5760320 9 * furnished to do so, subject to the following conditions:
kenjiArai 0:5b88d5760320 10 *
kenjiArai 0:5b88d5760320 11 * The above copyright notice and this permission notice shall be included in
kenjiArai 0:5b88d5760320 12 * all copies or substantial portions of the Software.
kenjiArai 0:5b88d5760320 13 *
kenjiArai 0:5b88d5760320 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
kenjiArai 0:5b88d5760320 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
kenjiArai 0:5b88d5760320 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
kenjiArai 0:5b88d5760320 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
kenjiArai 0:5b88d5760320 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kenjiArai 0:5b88d5760320 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
kenjiArai 0:5b88d5760320 20 * SOFTWARE.
kenjiArai 0:5b88d5760320 21 */
kenjiArai 0:5b88d5760320 22
kenjiArai 0:5b88d5760320 23 #include "ObservingBlockDevice.h"
kenjiArai 0:5b88d5760320 24 #include "ReadOnlyBlockDevice.h"
kenjiArai 0:5b88d5760320 25
kenjiArai 0:5b88d5760320 26 namespace mbed {
kenjiArai 0:5b88d5760320 27
kenjiArai 0:5b88d5760320 28 ObservingBlockDevice::ObservingBlockDevice(BlockDevice *bd)
kenjiArai 0:5b88d5760320 29 : _bd(bd)
kenjiArai 0:5b88d5760320 30 {
kenjiArai 0:5b88d5760320 31 // Does nothing
kenjiArai 0:5b88d5760320 32 }
kenjiArai 0:5b88d5760320 33
kenjiArai 0:5b88d5760320 34 ObservingBlockDevice::~ObservingBlockDevice()
kenjiArai 0:5b88d5760320 35 {
kenjiArai 0:5b88d5760320 36 // Does nothing
kenjiArai 0:5b88d5760320 37 }
kenjiArai 0:5b88d5760320 38
kenjiArai 0:5b88d5760320 39 void ObservingBlockDevice::attach(mbed::Callback<void(BlockDevice *)> cb)
kenjiArai 0:5b88d5760320 40 {
kenjiArai 0:5b88d5760320 41 _change = cb;
kenjiArai 0:5b88d5760320 42 }
kenjiArai 0:5b88d5760320 43
kenjiArai 0:5b88d5760320 44 int ObservingBlockDevice::init()
kenjiArai 0:5b88d5760320 45 {
kenjiArai 0:5b88d5760320 46 return _bd->init();
kenjiArai 0:5b88d5760320 47 }
kenjiArai 0:5b88d5760320 48
kenjiArai 0:5b88d5760320 49 int ObservingBlockDevice::deinit()
kenjiArai 0:5b88d5760320 50 {
kenjiArai 0:5b88d5760320 51 return _bd->deinit();
kenjiArai 0:5b88d5760320 52 }
kenjiArai 0:5b88d5760320 53
kenjiArai 0:5b88d5760320 54 int ObservingBlockDevice::sync()
kenjiArai 0:5b88d5760320 55 {
kenjiArai 0:5b88d5760320 56 return _bd->sync();
kenjiArai 0:5b88d5760320 57 }
kenjiArai 0:5b88d5760320 58
kenjiArai 0:5b88d5760320 59 int ObservingBlockDevice::read(void *buffer, bd_addr_t addr, bd_size_t size)
kenjiArai 0:5b88d5760320 60 {
kenjiArai 0:5b88d5760320 61 return _bd->read(buffer, addr, size);
kenjiArai 0:5b88d5760320 62 }
kenjiArai 0:5b88d5760320 63
kenjiArai 0:5b88d5760320 64 int ObservingBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_t size)
kenjiArai 0:5b88d5760320 65 {
kenjiArai 0:5b88d5760320 66 int res = _bd->program(buffer, addr, size);
kenjiArai 0:5b88d5760320 67 if (_change) {
kenjiArai 0:5b88d5760320 68 ReadOnlyBlockDevice dev(_bd);
kenjiArai 0:5b88d5760320 69 _change(&dev);
kenjiArai 0:5b88d5760320 70 }
kenjiArai 0:5b88d5760320 71 return res;
kenjiArai 0:5b88d5760320 72 }
kenjiArai 0:5b88d5760320 73
kenjiArai 0:5b88d5760320 74 int ObservingBlockDevice::erase(bd_addr_t addr, bd_size_t size)
kenjiArai 0:5b88d5760320 75 {
kenjiArai 0:5b88d5760320 76 int res = _bd->erase(addr, size);
kenjiArai 0:5b88d5760320 77 if (_change) {
kenjiArai 0:5b88d5760320 78 ReadOnlyBlockDevice dev(_bd);
kenjiArai 0:5b88d5760320 79 _change(&dev);
kenjiArai 0:5b88d5760320 80 }
kenjiArai 0:5b88d5760320 81 return res;
kenjiArai 0:5b88d5760320 82 }
kenjiArai 0:5b88d5760320 83
kenjiArai 0:5b88d5760320 84 bd_size_t ObservingBlockDevice::get_read_size() const
kenjiArai 0:5b88d5760320 85 {
kenjiArai 0:5b88d5760320 86 return _bd->get_read_size();
kenjiArai 0:5b88d5760320 87 }
kenjiArai 0:5b88d5760320 88
kenjiArai 0:5b88d5760320 89 bd_size_t ObservingBlockDevice::get_program_size() const
kenjiArai 0:5b88d5760320 90 {
kenjiArai 0:5b88d5760320 91 return _bd->get_program_size();
kenjiArai 0:5b88d5760320 92 }
kenjiArai 0:5b88d5760320 93
kenjiArai 0:5b88d5760320 94 bd_size_t ObservingBlockDevice::get_erase_size() const
kenjiArai 0:5b88d5760320 95 {
kenjiArai 0:5b88d5760320 96 return _bd->get_erase_size();
kenjiArai 0:5b88d5760320 97 }
kenjiArai 0:5b88d5760320 98
kenjiArai 0:5b88d5760320 99 bd_size_t ObservingBlockDevice::get_erase_size(bd_addr_t addr) const
kenjiArai 0:5b88d5760320 100 {
kenjiArai 0:5b88d5760320 101 return _bd->get_erase_size(addr);
kenjiArai 0:5b88d5760320 102 }
kenjiArai 0:5b88d5760320 103
kenjiArai 0:5b88d5760320 104 int ObservingBlockDevice::get_erase_value() const
kenjiArai 0:5b88d5760320 105 {
kenjiArai 0:5b88d5760320 106 return _bd->get_erase_value();
kenjiArai 0:5b88d5760320 107 }
kenjiArai 0:5b88d5760320 108
kenjiArai 0:5b88d5760320 109 bd_size_t ObservingBlockDevice::size() const
kenjiArai 0:5b88d5760320 110 {
kenjiArai 0:5b88d5760320 111 return _bd->size();
kenjiArai 0:5b88d5760320 112 }
kenjiArai 0:5b88d5760320 113
kenjiArai 0:5b88d5760320 114 const char *ObservingBlockDevice::get_type() const
kenjiArai 0:5b88d5760320 115 {
kenjiArai 0:5b88d5760320 116 if (_bd != NULL) {
kenjiArai 0:5b88d5760320 117 return _bd->get_type();
kenjiArai 0:5b88d5760320 118 }
kenjiArai 0:5b88d5760320 119
kenjiArai 0:5b88d5760320 120 return NULL;
kenjiArai 0:5b88d5760320 121 }
kenjiArai 0:5b88d5760320 122
kenjiArai 0:5b88d5760320 123 } // namespace mbed
kenjiArai 0:5b88d5760320 124