Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marcozecchini 0:9fca2b23d0ba 1 /* mbed Microcontroller Library
marcozecchini 0:9fca2b23d0ba 2 * Copyright (c) 2017 ARM Limited
marcozecchini 0:9fca2b23d0ba 3 *
marcozecchini 0:9fca2b23d0ba 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
marcozecchini 0:9fca2b23d0ba 5 * of this software and associated documentation files (the "Software"), to deal
marcozecchini 0:9fca2b23d0ba 6 * in the Software without restriction, including without limitation the rights
marcozecchini 0:9fca2b23d0ba 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
marcozecchini 0:9fca2b23d0ba 8 * copies of the Software, and to permit persons to whom the Software is
marcozecchini 0:9fca2b23d0ba 9 * furnished to do so, subject to the following conditions:
marcozecchini 0:9fca2b23d0ba 10 *
marcozecchini 0:9fca2b23d0ba 11 * The above copyright notice and this permission notice shall be included in
marcozecchini 0:9fca2b23d0ba 12 * all copies or substantial portions of the Software.
marcozecchini 0:9fca2b23d0ba 13 *
marcozecchini 0:9fca2b23d0ba 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
marcozecchini 0:9fca2b23d0ba 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
marcozecchini 0:9fca2b23d0ba 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
marcozecchini 0:9fca2b23d0ba 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
marcozecchini 0:9fca2b23d0ba 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
marcozecchini 0:9fca2b23d0ba 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
marcozecchini 0:9fca2b23d0ba 20 * SOFTWARE.
marcozecchini 0:9fca2b23d0ba 21 */
marcozecchini 0:9fca2b23d0ba 22 #ifndef MBED_PROFILING_BLOCK_DEVICE_H
marcozecchini 0:9fca2b23d0ba 23 #define MBED_PROFILING_BLOCK_DEVICE_H
marcozecchini 0:9fca2b23d0ba 24
marcozecchini 0:9fca2b23d0ba 25 #include "BlockDevice.h"
marcozecchini 0:9fca2b23d0ba 26 #include "mbed.h"
marcozecchini 0:9fca2b23d0ba 27
marcozecchini 0:9fca2b23d0ba 28
marcozecchini 0:9fca2b23d0ba 29 /** Block device for measuring storage operations of another block device
marcozecchini 0:9fca2b23d0ba 30 *
marcozecchini 0:9fca2b23d0ba 31 * @code
marcozecchini 0:9fca2b23d0ba 32 * #include "mbed.h"
marcozecchini 0:9fca2b23d0ba 33 * #include "HeapBlockDevice.h"
marcozecchini 0:9fca2b23d0ba 34 * #include "ProfilingBlockDevice.h"
marcozecchini 0:9fca2b23d0ba 35 *
marcozecchini 0:9fca2b23d0ba 36 * // Create a heap block device and profiling block device
marcozecchini 0:9fca2b23d0ba 37 * HeapBlockDevice mem(64*512, 512);
marcozecchini 0:9fca2b23d0ba 38 * ProfilingBlockDevice profiler(&mem);
marcozecchini 0:9fca2b23d0ba 39 *
marcozecchini 0:9fca2b23d0ba 40 * // do block device work....
marcozecchini 0:9fca2b23d0ba 41 *
marcozecchini 0:9fca2b23d0ba 42 * printf("read count: %lld\n", profiler.get_read_count());
marcozecchini 0:9fca2b23d0ba 43 * printf("program count: %lld\n", profiler.get_program_count());
marcozecchini 0:9fca2b23d0ba 44 * printf("erase count: %lld\n", profiler.get_erase_count());
marcozecchini 0:9fca2b23d0ba 45 * @endcode
marcozecchini 0:9fca2b23d0ba 46 */
marcozecchini 0:9fca2b23d0ba 47 class ProfilingBlockDevice : public BlockDevice
marcozecchini 0:9fca2b23d0ba 48 {
marcozecchini 0:9fca2b23d0ba 49 public:
marcozecchini 0:9fca2b23d0ba 50 /** Lifetime of the memory block device
marcozecchini 0:9fca2b23d0ba 51 *
marcozecchini 0:9fca2b23d0ba 52 * @param bd Block device to back the ProfilingBlockDevice
marcozecchini 0:9fca2b23d0ba 53 */
marcozecchini 0:9fca2b23d0ba 54 ProfilingBlockDevice(BlockDevice *bd);
marcozecchini 0:9fca2b23d0ba 55
marcozecchini 0:9fca2b23d0ba 56 /** Lifetime of a block device
marcozecchini 0:9fca2b23d0ba 57 */
marcozecchini 0:9fca2b23d0ba 58 virtual ~ProfilingBlockDevice() {};
marcozecchini 0:9fca2b23d0ba 59
marcozecchini 0:9fca2b23d0ba 60 /** Initialize a block device
marcozecchini 0:9fca2b23d0ba 61 *
marcozecchini 0:9fca2b23d0ba 62 * @return 0 on success or a negative error code on failure
marcozecchini 0:9fca2b23d0ba 63 * @note The init and deinit functions do not effect profile counts
marcozecchini 0:9fca2b23d0ba 64 */
marcozecchini 0:9fca2b23d0ba 65 virtual int init();
marcozecchini 0:9fca2b23d0ba 66
marcozecchini 0:9fca2b23d0ba 67 /** Deinitialize a block device
marcozecchini 0:9fca2b23d0ba 68 *
marcozecchini 0:9fca2b23d0ba 69 * @return 0 on success or a negative error code on failure
marcozecchini 0:9fca2b23d0ba 70 * @note The init and deinit functions do not effect profile counts
marcozecchini 0:9fca2b23d0ba 71 */
marcozecchini 0:9fca2b23d0ba 72 virtual int deinit();
marcozecchini 0:9fca2b23d0ba 73
marcozecchini 0:9fca2b23d0ba 74 /** Read blocks from a block device
marcozecchini 0:9fca2b23d0ba 75 *
marcozecchini 0:9fca2b23d0ba 76 * @param buffer Buffer to read blocks into
marcozecchini 0:9fca2b23d0ba 77 * @param addr Address of block to begin reading from
marcozecchini 0:9fca2b23d0ba 78 * @param size Size to read in bytes, must be a multiple of read block size
marcozecchini 0:9fca2b23d0ba 79 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 80 */
marcozecchini 0:9fca2b23d0ba 81 virtual int read(void *buffer, bd_addr_t addr, bd_size_t size);
marcozecchini 0:9fca2b23d0ba 82
marcozecchini 0:9fca2b23d0ba 83 /** Program blocks to a block device
marcozecchini 0:9fca2b23d0ba 84 *
marcozecchini 0:9fca2b23d0ba 85 * The blocks must have been erased prior to being programmed
marcozecchini 0:9fca2b23d0ba 86 *
marcozecchini 0:9fca2b23d0ba 87 * @param buffer Buffer of data to write to blocks
marcozecchini 0:9fca2b23d0ba 88 * @param addr Address of block to begin writing to
marcozecchini 0:9fca2b23d0ba 89 * @param size Size to write in bytes, must be a multiple of program block size
marcozecchini 0:9fca2b23d0ba 90 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 91 */
marcozecchini 0:9fca2b23d0ba 92 virtual int program(const void *buffer, bd_addr_t addr, bd_size_t size);
marcozecchini 0:9fca2b23d0ba 93
marcozecchini 0:9fca2b23d0ba 94 /** Erase blocks on a block device
marcozecchini 0:9fca2b23d0ba 95 *
marcozecchini 0:9fca2b23d0ba 96 * The state of an erased block is undefined until it has been programmed
marcozecchini 0:9fca2b23d0ba 97 *
marcozecchini 0:9fca2b23d0ba 98 * @param addr Address of block to begin erasing
marcozecchini 0:9fca2b23d0ba 99 * @param size Size to erase in bytes, must be a multiple of erase block size
marcozecchini 0:9fca2b23d0ba 100 * @return 0 on success, negative error code on failure
marcozecchini 0:9fca2b23d0ba 101 */
marcozecchini 0:9fca2b23d0ba 102 virtual int erase(bd_addr_t addr, bd_size_t size);
marcozecchini 0:9fca2b23d0ba 103
marcozecchini 0:9fca2b23d0ba 104 /** Get the size of a readable block
marcozecchini 0:9fca2b23d0ba 105 *
marcozecchini 0:9fca2b23d0ba 106 * @return Size of a readable block in bytes
marcozecchini 0:9fca2b23d0ba 107 */
marcozecchini 0:9fca2b23d0ba 108 virtual bd_size_t get_read_size() const;
marcozecchini 0:9fca2b23d0ba 109
marcozecchini 0:9fca2b23d0ba 110 /** Get the size of a programable block
marcozecchini 0:9fca2b23d0ba 111 *
marcozecchini 0:9fca2b23d0ba 112 * @return Size of a programable block in bytes
marcozecchini 0:9fca2b23d0ba 113 * @note Must be a multiple of the read size
marcozecchini 0:9fca2b23d0ba 114 */
marcozecchini 0:9fca2b23d0ba 115 virtual bd_size_t get_program_size() const;
marcozecchini 0:9fca2b23d0ba 116
marcozecchini 0:9fca2b23d0ba 117 /** Get the size of a eraseable block
marcozecchini 0:9fca2b23d0ba 118 *
marcozecchini 0:9fca2b23d0ba 119 * @return Size of a eraseable block in bytes
marcozecchini 0:9fca2b23d0ba 120 * @note Must be a multiple of the program size
marcozecchini 0:9fca2b23d0ba 121 */
marcozecchini 0:9fca2b23d0ba 122 virtual bd_size_t get_erase_size() const;
marcozecchini 0:9fca2b23d0ba 123
marcozecchini 0:9fca2b23d0ba 124 /** Get the total size of the underlying device
marcozecchini 0:9fca2b23d0ba 125 *
marcozecchini 0:9fca2b23d0ba 126 * @return Size of the underlying device in bytes
marcozecchini 0:9fca2b23d0ba 127 */
marcozecchini 0:9fca2b23d0ba 128 virtual bd_size_t size() const;
marcozecchini 0:9fca2b23d0ba 129
marcozecchini 0:9fca2b23d0ba 130 /** Reset the current profile counts to zero
marcozecchini 0:9fca2b23d0ba 131 */
marcozecchini 0:9fca2b23d0ba 132 void reset();
marcozecchini 0:9fca2b23d0ba 133
marcozecchini 0:9fca2b23d0ba 134 /** Get number of bytes that have been read from the block device
marcozecchini 0:9fca2b23d0ba 135 *
marcozecchini 0:9fca2b23d0ba 136 * @return The number of bytes that have been read from the block device
marcozecchini 0:9fca2b23d0ba 137 */
marcozecchini 0:9fca2b23d0ba 138 bd_size_t get_read_count() const;
marcozecchini 0:9fca2b23d0ba 139
marcozecchini 0:9fca2b23d0ba 140 /** Get number of bytes that have been programed to the block device
marcozecchini 0:9fca2b23d0ba 141 *
marcozecchini 0:9fca2b23d0ba 142 * @return The number of bytes that have been programed to the block device
marcozecchini 0:9fca2b23d0ba 143 */
marcozecchini 0:9fca2b23d0ba 144 bd_size_t get_program_count() const;
marcozecchini 0:9fca2b23d0ba 145
marcozecchini 0:9fca2b23d0ba 146 /** Get number of bytes that have been erased from the block device
marcozecchini 0:9fca2b23d0ba 147 *
marcozecchini 0:9fca2b23d0ba 148 * @return The number of bytes that have been erased from the block device
marcozecchini 0:9fca2b23d0ba 149 */
marcozecchini 0:9fca2b23d0ba 150 bd_size_t get_erase_count() const;
marcozecchini 0:9fca2b23d0ba 151
marcozecchini 0:9fca2b23d0ba 152 private:
marcozecchini 0:9fca2b23d0ba 153 BlockDevice *_bd;
marcozecchini 0:9fca2b23d0ba 154 bd_size_t _read_count;
marcozecchini 0:9fca2b23d0ba 155 bd_size_t _program_count;
marcozecchini 0:9fca2b23d0ba 156 bd_size_t _erase_count;
marcozecchini 0:9fca2b23d0ba 157 };
marcozecchini 0:9fca2b23d0ba 158
marcozecchini 0:9fca2b23d0ba 159
marcozecchini 0:9fca2b23d0ba 160 #endif