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 ARM Limited
borlanic 0:380207fcb5c1 3 *
borlanic 0:380207fcb5c1 4 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:380207fcb5c1 5 * you may not use this file except in compliance with the License.
borlanic 0:380207fcb5c1 6 * You may obtain a copy of the License at
borlanic 0:380207fcb5c1 7 *
borlanic 0:380207fcb5c1 8 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:380207fcb5c1 9 *
borlanic 0:380207fcb5c1 10 * Unless required by applicable law or agreed to in writing, software
borlanic 0:380207fcb5c1 11 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:380207fcb5c1 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:380207fcb5c1 13 * See the License for the specific language governing permissions and
borlanic 0:380207fcb5c1 14 * limitations under the License.
borlanic 0:380207fcb5c1 15 */
borlanic 0:380207fcb5c1 16
borlanic 0:380207fcb5c1 17 #include "SlicingBlockDevice.h"
borlanic 0:380207fcb5c1 18
borlanic 0:380207fcb5c1 19
borlanic 0:380207fcb5c1 20 SlicingBlockDevice::SlicingBlockDevice(BlockDevice *bd, bd_addr_t start, bd_addr_t stop)
borlanic 0:380207fcb5c1 21 : _bd(bd)
borlanic 0:380207fcb5c1 22 , _start_from_end(false), _start(start)
borlanic 0:380207fcb5c1 23 , _stop_from_end(false), _stop(stop)
borlanic 0:380207fcb5c1 24 {
borlanic 0:380207fcb5c1 25 if ((int64_t)_start < 0) {
borlanic 0:380207fcb5c1 26 _start_from_end = true;
borlanic 0:380207fcb5c1 27 _start = -_start;
borlanic 0:380207fcb5c1 28 }
borlanic 0:380207fcb5c1 29
borlanic 0:380207fcb5c1 30 if ((int64_t)_stop <= 0) {
borlanic 0:380207fcb5c1 31 _stop_from_end = true;
borlanic 0:380207fcb5c1 32 _stop = -_stop;
borlanic 0:380207fcb5c1 33 }
borlanic 0:380207fcb5c1 34 }
borlanic 0:380207fcb5c1 35
borlanic 0:380207fcb5c1 36 int SlicingBlockDevice::init()
borlanic 0:380207fcb5c1 37 {
borlanic 0:380207fcb5c1 38 int err = _bd->init();
borlanic 0:380207fcb5c1 39 if (err) {
borlanic 0:380207fcb5c1 40 return err;
borlanic 0:380207fcb5c1 41 }
borlanic 0:380207fcb5c1 42
borlanic 0:380207fcb5c1 43 bd_size_t size = _bd->size();
borlanic 0:380207fcb5c1 44
borlanic 0:380207fcb5c1 45 // Calculate from_end values
borlanic 0:380207fcb5c1 46 if (_start_from_end) {
borlanic 0:380207fcb5c1 47 _start_from_end = false;
borlanic 0:380207fcb5c1 48 _start = size - _start;
borlanic 0:380207fcb5c1 49 }
borlanic 0:380207fcb5c1 50
borlanic 0:380207fcb5c1 51 if (_stop_from_end) {
borlanic 0:380207fcb5c1 52 _stop_from_end = false;
borlanic 0:380207fcb5c1 53 _stop = size - _stop;
borlanic 0:380207fcb5c1 54 }
borlanic 0:380207fcb5c1 55
borlanic 0:380207fcb5c1 56 // Check that block addresses are valid
borlanic 0:380207fcb5c1 57 MBED_ASSERT(_bd->is_valid_erase(_start, _stop - _start));
borlanic 0:380207fcb5c1 58
borlanic 0:380207fcb5c1 59 return 0;
borlanic 0:380207fcb5c1 60 }
borlanic 0:380207fcb5c1 61
borlanic 0:380207fcb5c1 62 int SlicingBlockDevice::deinit()
borlanic 0:380207fcb5c1 63 {
borlanic 0:380207fcb5c1 64 return _bd->deinit();
borlanic 0:380207fcb5c1 65 }
borlanic 0:380207fcb5c1 66
borlanic 0:380207fcb5c1 67 int SlicingBlockDevice::sync()
borlanic 0:380207fcb5c1 68 {
borlanic 0:380207fcb5c1 69 return _bd->sync();
borlanic 0:380207fcb5c1 70 }
borlanic 0:380207fcb5c1 71
borlanic 0:380207fcb5c1 72 int SlicingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
borlanic 0:380207fcb5c1 73 {
borlanic 0:380207fcb5c1 74 MBED_ASSERT(is_valid_read(addr, size));
borlanic 0:380207fcb5c1 75 return _bd->read(b, addr + _start, size);
borlanic 0:380207fcb5c1 76 }
borlanic 0:380207fcb5c1 77
borlanic 0:380207fcb5c1 78 int SlicingBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
borlanic 0:380207fcb5c1 79 {
borlanic 0:380207fcb5c1 80 MBED_ASSERT(is_valid_program(addr, size));
borlanic 0:380207fcb5c1 81 return _bd->program(b, addr + _start, size);
borlanic 0:380207fcb5c1 82 }
borlanic 0:380207fcb5c1 83
borlanic 0:380207fcb5c1 84 int SlicingBlockDevice::erase(bd_addr_t addr, bd_size_t size)
borlanic 0:380207fcb5c1 85 {
borlanic 0:380207fcb5c1 86 MBED_ASSERT(is_valid_erase(addr, size));
borlanic 0:380207fcb5c1 87 return _bd->erase(addr + _start, size);
borlanic 0:380207fcb5c1 88 }
borlanic 0:380207fcb5c1 89
borlanic 0:380207fcb5c1 90 bd_size_t SlicingBlockDevice::get_read_size() const
borlanic 0:380207fcb5c1 91 {
borlanic 0:380207fcb5c1 92 return _bd->get_read_size();
borlanic 0:380207fcb5c1 93 }
borlanic 0:380207fcb5c1 94
borlanic 0:380207fcb5c1 95 bd_size_t SlicingBlockDevice::get_program_size() const
borlanic 0:380207fcb5c1 96 {
borlanic 0:380207fcb5c1 97 return _bd->get_program_size();
borlanic 0:380207fcb5c1 98 }
borlanic 0:380207fcb5c1 99
borlanic 0:380207fcb5c1 100 bd_size_t SlicingBlockDevice::get_erase_size() const
borlanic 0:380207fcb5c1 101 {
borlanic 0:380207fcb5c1 102 return _bd->get_erase_size();
borlanic 0:380207fcb5c1 103 }
borlanic 0:380207fcb5c1 104
borlanic 4:75df35ef4fb6 105 bd_size_t SlicingBlockDevice::get_erase_size(bd_addr_t addr) const
borlanic 4:75df35ef4fb6 106 {
borlanic 4:75df35ef4fb6 107 return _bd->get_erase_size(_start + addr);
borlanic 4:75df35ef4fb6 108 }
borlanic 4:75df35ef4fb6 109
borlanic 0:380207fcb5c1 110 int SlicingBlockDevice::get_erase_value() const
borlanic 0:380207fcb5c1 111 {
borlanic 0:380207fcb5c1 112 return _bd->get_erase_value();
borlanic 0:380207fcb5c1 113 }
borlanic 0:380207fcb5c1 114
borlanic 0:380207fcb5c1 115 bd_size_t SlicingBlockDevice::size() const
borlanic 0:380207fcb5c1 116 {
borlanic 0:380207fcb5c1 117 return _stop - _start;
borlanic 0:380207fcb5c1 118 }