Mouse code for the MacroRat

Dependencies:   ITG3200 QEI

Committer:
sahilmgandhi
Date:
Sat Jun 03 00:22:44 2017 +0000
Revision:
46:b156ef445742
Parent:
18:6a4db94011d3
Final code for internal battlebot competition.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sahilmgandhi 18:6a4db94011d3 1 /* mbed Microcontroller Library
sahilmgandhi 18:6a4db94011d3 2 * Copyright (c) 2017 ARM Limited
sahilmgandhi 18:6a4db94011d3 3 *
sahilmgandhi 18:6a4db94011d3 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
sahilmgandhi 18:6a4db94011d3 5 * of this software and associated documentation files (the "Software"), to deal
sahilmgandhi 18:6a4db94011d3 6 * in the Software without restriction, including without limitation the rights
sahilmgandhi 18:6a4db94011d3 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
sahilmgandhi 18:6a4db94011d3 8 * copies of the Software, and to permit persons to whom the Software is
sahilmgandhi 18:6a4db94011d3 9 * furnished to do so, subject to the following conditions:
sahilmgandhi 18:6a4db94011d3 10 *
sahilmgandhi 18:6a4db94011d3 11 * The above copyright notice and this permission notice shall be included in
sahilmgandhi 18:6a4db94011d3 12 * all copies or substantial portions of the Software.
sahilmgandhi 18:6a4db94011d3 13 *
sahilmgandhi 18:6a4db94011d3 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
sahilmgandhi 18:6a4db94011d3 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
sahilmgandhi 18:6a4db94011d3 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
sahilmgandhi 18:6a4db94011d3 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
sahilmgandhi 18:6a4db94011d3 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
sahilmgandhi 18:6a4db94011d3 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
sahilmgandhi 18:6a4db94011d3 20 * SOFTWARE.
sahilmgandhi 18:6a4db94011d3 21 */
sahilmgandhi 18:6a4db94011d3 22 #ifndef MBED_FLASHIAP_H
sahilmgandhi 18:6a4db94011d3 23 #define MBED_FLASHIAP_H
sahilmgandhi 18:6a4db94011d3 24
sahilmgandhi 18:6a4db94011d3 25 #ifdef DEVICE_FLASH
sahilmgandhi 18:6a4db94011d3 26
sahilmgandhi 18:6a4db94011d3 27 #include "flash_api.h"
sahilmgandhi 18:6a4db94011d3 28 #include "platform/SingletonPtr.h"
sahilmgandhi 18:6a4db94011d3 29 #include "platform/PlatformMutex.h"
sahilmgandhi 18:6a4db94011d3 30
sahilmgandhi 18:6a4db94011d3 31 namespace mbed {
sahilmgandhi 18:6a4db94011d3 32
sahilmgandhi 18:6a4db94011d3 33 /** \addtogroup drivers */
sahilmgandhi 18:6a4db94011d3 34 /** @{*/
sahilmgandhi 18:6a4db94011d3 35
sahilmgandhi 18:6a4db94011d3 36 /** Flash IAP driver. It invokes flash HAL functions.
sahilmgandhi 18:6a4db94011d3 37 *
sahilmgandhi 18:6a4db94011d3 38 * Note Synchronization level: Thread safe
sahilmgandhi 18:6a4db94011d3 39 */
sahilmgandhi 18:6a4db94011d3 40 class FlashIAP {
sahilmgandhi 18:6a4db94011d3 41 public:
sahilmgandhi 18:6a4db94011d3 42 FlashIAP();
sahilmgandhi 18:6a4db94011d3 43 ~FlashIAP();
sahilmgandhi 18:6a4db94011d3 44
sahilmgandhi 18:6a4db94011d3 45 /** Initialize a flash IAP device
sahilmgandhi 18:6a4db94011d3 46 *
sahilmgandhi 18:6a4db94011d3 47 * Should be called once per lifetime of the object.
sahilmgandhi 18:6a4db94011d3 48 * @return 0 on success or a negative error code on failure
sahilmgandhi 18:6a4db94011d3 49 */
sahilmgandhi 18:6a4db94011d3 50 int init();
sahilmgandhi 18:6a4db94011d3 51
sahilmgandhi 18:6a4db94011d3 52 /** Deinitialize a flash IAP device
sahilmgandhi 18:6a4db94011d3 53 *
sahilmgandhi 18:6a4db94011d3 54 * @return 0 on success or a negative error code on failure
sahilmgandhi 18:6a4db94011d3 55 */
sahilmgandhi 18:6a4db94011d3 56 int deinit();
sahilmgandhi 18:6a4db94011d3 57
sahilmgandhi 18:6a4db94011d3 58 /** Read data from a flash device.
sahilmgandhi 18:6a4db94011d3 59 *
sahilmgandhi 18:6a4db94011d3 60 * This method invokes memcpy - reads number of bytes from the address
sahilmgandhi 18:6a4db94011d3 61 *
sahilmgandhi 18:6a4db94011d3 62 * @param buffer Buffer to write to
sahilmgandhi 18:6a4db94011d3 63 * @param addr Flash address to begin reading from
sahilmgandhi 18:6a4db94011d3 64 * @param size Size to read in bytes
sahilmgandhi 18:6a4db94011d3 65 * @return 0 on success, negative error code on failure
sahilmgandhi 18:6a4db94011d3 66 */
sahilmgandhi 18:6a4db94011d3 67 int read(void *buffer, uint32_t addr, uint32_t size);
sahilmgandhi 18:6a4db94011d3 68
sahilmgandhi 18:6a4db94011d3 69 /** Program data to pages
sahilmgandhi 18:6a4db94011d3 70 *
sahilmgandhi 18:6a4db94011d3 71 * The sectors must have been erased prior to being programmed
sahilmgandhi 18:6a4db94011d3 72 *
sahilmgandhi 18:6a4db94011d3 73 * @param buffer Buffer of data to be written
sahilmgandhi 18:6a4db94011d3 74 * @param addr Address of a page to begin writing to, must be a multiple of program and sector sizes
sahilmgandhi 18:6a4db94011d3 75 * @param size Size to write in bytes, must be a multiple of program and sector sizes
sahilmgandhi 18:6a4db94011d3 76 * @return 0 on success, negative error code on failure
sahilmgandhi 18:6a4db94011d3 77 */
sahilmgandhi 18:6a4db94011d3 78 int program(const void *buffer, uint32_t addr, uint32_t size);
sahilmgandhi 18:6a4db94011d3 79
sahilmgandhi 18:6a4db94011d3 80 /** Erase sectors
sahilmgandhi 18:6a4db94011d3 81 *
sahilmgandhi 18:6a4db94011d3 82 * The state of an erased sector is undefined until it has been programmed
sahilmgandhi 18:6a4db94011d3 83 *
sahilmgandhi 18:6a4db94011d3 84 * @param addr Address of a sector to begin erasing, must be a multiple of the sector size
sahilmgandhi 18:6a4db94011d3 85 * @param size Size to erase in bytes, must be a multiple of the sector size
sahilmgandhi 18:6a4db94011d3 86 * @return 0 on success, negative error code on failure
sahilmgandhi 18:6a4db94011d3 87 */
sahilmgandhi 18:6a4db94011d3 88 int erase(uint32_t addr, uint32_t size);
sahilmgandhi 18:6a4db94011d3 89
sahilmgandhi 18:6a4db94011d3 90 /** Get the sector size at the defined address
sahilmgandhi 18:6a4db94011d3 91 *
sahilmgandhi 18:6a4db94011d3 92 * Sector size might differ at address ranges.
sahilmgandhi 18:6a4db94011d3 93 * An example <0-0x1000, sector size=1024; 0x10000-0x20000, size=2048>
sahilmgandhi 18:6a4db94011d3 94 *
sahilmgandhi 18:6a4db94011d3 95 * @param addr Address of or inside the sector to query
sahilmgandhi 18:6a4db94011d3 96 * @return Size of a sector in bytes or MBED_FLASH_INVALID_SIZE if not mapped
sahilmgandhi 18:6a4db94011d3 97 */
sahilmgandhi 18:6a4db94011d3 98 uint32_t get_sector_size(uint32_t addr) const;
sahilmgandhi 18:6a4db94011d3 99
sahilmgandhi 18:6a4db94011d3 100 /** Get the flash start address
sahilmgandhi 18:6a4db94011d3 101 *
sahilmgandhi 18:6a4db94011d3 102 * @return Flash start address
sahilmgandhi 18:6a4db94011d3 103 */
sahilmgandhi 18:6a4db94011d3 104 uint32_t get_flash_start() const;
sahilmgandhi 18:6a4db94011d3 105
sahilmgandhi 18:6a4db94011d3 106 /** Get the flash size
sahilmgandhi 18:6a4db94011d3 107 *
sahilmgandhi 18:6a4db94011d3 108 * @return Flash size
sahilmgandhi 18:6a4db94011d3 109 */
sahilmgandhi 18:6a4db94011d3 110 uint32_t get_flash_size() const;
sahilmgandhi 18:6a4db94011d3 111
sahilmgandhi 18:6a4db94011d3 112 /** Get the program page size
sahilmgandhi 18:6a4db94011d3 113 *
sahilmgandhi 18:6a4db94011d3 114 * @return Size of a program page in bytes
sahilmgandhi 18:6a4db94011d3 115 */
sahilmgandhi 18:6a4db94011d3 116 uint32_t get_page_size() const;
sahilmgandhi 18:6a4db94011d3 117
sahilmgandhi 18:6a4db94011d3 118 private:
sahilmgandhi 18:6a4db94011d3 119
sahilmgandhi 18:6a4db94011d3 120 /** Check if address and size are aligned to a sector
sahilmgandhi 18:6a4db94011d3 121 *
sahilmgandhi 18:6a4db94011d3 122 * @param addr Address of block to check for alignment
sahilmgandhi 18:6a4db94011d3 123 * @param size Size of block to check for alignment
sahilmgandhi 18:6a4db94011d3 124 * @return true if the block is sector aligned, false otherwise
sahilmgandhi 18:6a4db94011d3 125 */
sahilmgandhi 18:6a4db94011d3 126 bool is_aligned_to_sector(uint32_t addr, uint32_t size);
sahilmgandhi 18:6a4db94011d3 127
sahilmgandhi 18:6a4db94011d3 128 flash_t _flash;
sahilmgandhi 18:6a4db94011d3 129 static SingletonPtr<PlatformMutex> _mutex;
sahilmgandhi 18:6a4db94011d3 130 };
sahilmgandhi 18:6a4db94011d3 131
sahilmgandhi 18:6a4db94011d3 132 } /* namespace mbed */
sahilmgandhi 18:6a4db94011d3 133
sahilmgandhi 18:6a4db94011d3 134 #endif /* DEVICE_FLASH */
sahilmgandhi 18:6a4db94011d3 135
sahilmgandhi 18:6a4db94011d3 136 #endif /* MBED_FLASHIAP_H */
sahilmgandhi 18:6a4db94011d3 137
sahilmgandhi 18:6a4db94011d3 138 /** @}*/