Erste version der Software für der Prototyp

Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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