A board support package for the LPC4088 Display Module.

Dependencies:   DM_HttpServer DM_USBHost

Dependents:   lpc4088_displaymodule_emwin lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI ... more

Fork of DMSupport by EmbeddedArtists AB

Committer:
embeddedartists
Date:
Mon Nov 04 14:32:50 2019 +0000
Revision:
42:bbfe299d4a0c
Parent:
9:a33326afd686
More updates related to mbed OS 5

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:6b68dac0d986 1 /*
embeddedartists 9:a33326afd686 2 * Copyright 2014 Embedded Artists AB
embeddedartists 0:6b68dac0d986 3 *
embeddedartists 0:6b68dac0d986 4 * Licensed under the Apache License, Version 2.0 (the "License");
embeddedartists 0:6b68dac0d986 5 * you may not use this file except in compliance with the License.
embeddedartists 0:6b68dac0d986 6 * You may obtain a copy of the License at
embeddedartists 0:6b68dac0d986 7 *
embeddedartists 0:6b68dac0d986 8 * http://www.apache.org/licenses/LICENSE-2.0
embeddedartists 0:6b68dac0d986 9 *
embeddedartists 0:6b68dac0d986 10 * Unless required by applicable law or agreed to in writing, software
embeddedartists 0:6b68dac0d986 11 * distributed under the License is distributed on an "AS IS" BASIS,
embeddedartists 0:6b68dac0d986 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
embeddedartists 0:6b68dac0d986 13 * See the License for the specific language governing permissions and
embeddedartists 0:6b68dac0d986 14 * limitations under the License.
embeddedartists 0:6b68dac0d986 15 */
embeddedartists 0:6b68dac0d986 16
embeddedartists 0:6b68dac0d986 17 #ifndef QSPIFILESYSTEM_H
embeddedartists 0:6b68dac0d986 18 #define QSPIFILESYSTEM_H
embeddedartists 0:6b68dac0d986 19
embeddedartists 0:6b68dac0d986 20 #include "mbed.h"
embeddedartists 0:6b68dac0d986 21 #include "FileSystemLike.h"
embeddedartists 0:6b68dac0d986 22
embeddedartists 0:6b68dac0d986 23 /** Access the filesystem on an QSPI flash using SPIFI
embeddedartists 0:6b68dac0d986 24 *
embeddedartists 0:6b68dac0d986 25 * One way to utilize the 8MByte of QSPI FLASH on the LPC4088 QuickStart Board
embeddedartists 0:6b68dac0d986 26 * is to place a file system on it. The QSPIFileSystem is using the
embeddedartists 0:6b68dac0d986 27 * FileSystemLike interface making using it is as simple as:
embeddedartists 0:6b68dac0d986 28 *
embeddedartists 0:6b68dac0d986 29 * @code
embeddedartists 0:6b68dac0d986 30 * #include "mbed.h"
embeddedartists 0:6b68dac0d986 31 * #include "QSPIFileSystem.h"
embeddedartists 0:6b68dac0d986 32 *
embeddedartists 0:6b68dac0d986 33 * QSPIFileSystem qspifs("qspi");
embeddedartists 0:6b68dac0d986 34 *
embeddedartists 0:6b68dac0d986 35 * int main() {
embeddedartists 0:6b68dac0d986 36 * if (!qspifs.isformatted()) {
embeddedartists 0:6b68dac0d986 37 * qspifs.format();
embeddedartists 0:6b68dac0d986 38 * }
embeddedartists 0:6b68dac0d986 39 *
embeddedartists 0:6b68dac0d986 40 * FILE *fp = fopen("/qspi/myfile.txt", "w");
embeddedartists 0:6b68dac0d986 41 * if (fp != NULL) {
embeddedartists 0:6b68dac0d986 42 * fwrite("Hello World!", 12, 1, fp);
embeddedartists 0:6b68dac0d986 43 * fclose(fp);
embeddedartists 0:6b68dac0d986 44 * }
embeddedartists 0:6b68dac0d986 45 * }
embeddedartists 0:6b68dac0d986 46 * @endcode
embeddedartists 0:6b68dac0d986 47 *
embeddedartists 0:6b68dac0d986 48 * The file system can be formatted to a specific size in increments of 1MByte
embeddedartists 0:6b68dac0d986 49 * and will allways be placed at the top of the address range. For the 8 MByte
embeddedartists 0:6b68dac0d986 50 * memory on the LPC4088 QuickStart Board this means:
embeddedartists 0:6b68dac0d986 51 *
embeddedartists 0:6b68dac0d986 52 * <pre>
embeddedartists 0:6b68dac0d986 53 * 0x28000000 0x28800000
embeddedartists 0:6b68dac0d986 54 * |------|------|------|------|------|------|------|------|
embeddedartists 0:6b68dac0d986 55 * qspifs.format(1) | available for program | FS |
embeddedartists 0:6b68dac0d986 56 * |------|------|------|------|------|------|------|------|
embeddedartists 0:6b68dac0d986 57 * </pre><pre>
embeddedartists 0:6b68dac0d986 58 * |------|------|------|------|------|------|------|------|
embeddedartists 0:6b68dac0d986 59 * qspifs.format(2) | available for program | FileSystem |
embeddedartists 0:6b68dac0d986 60 * |------|------|------|------|------|------|------|------|
embeddedartists 0:6b68dac0d986 61 * </pre><pre>
embeddedartists 0:6b68dac0d986 62 * |------|------|------|------|------|------|------|------|
embeddedartists 0:6b68dac0d986 63 * qspifs.format(7) | PROG | FileSystem |
embeddedartists 0:6b68dac0d986 64 * |------|------|------|------|------|------|------|------|
embeddedartists 0:6b68dac0d986 65 * </pre><pre>
embeddedartists 0:6b68dac0d986 66 * |------|------|------|------|------|------|------|------|
embeddedartists 0:6b68dac0d986 67 * qspifs.format(8) | FileSystem |
embeddedartists 0:6b68dac0d986 68 * |------|------|------|------|------|------|------|------|
embeddedartists 0:6b68dac0d986 69 * </pre>
embeddedartists 0:6b68dac0d986 70 * The file system must be placed at the top of the memory because the linker scripts
embeddedartists 0:6b68dac0d986 71 * places your program at the bottom of the memory (if needed).
embeddedartists 0:6b68dac0d986 72 *
embeddedartists 0:6b68dac0d986 73 * The file system is using one or more blocks (each the size of one erase block) per
embeddedartists 0:6b68dac0d986 74 * file. Each file is stored in a sequence of blocks. If a file is written to so that
embeddedartists 0:6b68dac0d986 75 * it's size will occupy more than one block and the block after is already used by
embeddedartists 0:6b68dac0d986 76 * a different file the entire file will be moved, like this:
embeddedartists 0:6b68dac0d986 77 *
embeddedartists 0:6b68dac0d986 78 * <pre>
embeddedartists 0:6b68dac0d986 79 * |-------|-------|-------|-------|-------|-------|-------|
embeddedartists 0:6b68dac0d986 80 * Before |///////| FILE1 | FILE2 | FILE3 |///////|///////|///////|
embeddedartists 0:6b68dac0d986 81 * |-------|-------|-------|-------|-------|-------|-------|
embeddedartists 0:6b68dac0d986 82 * </pre><pre>
embeddedartists 0:6b68dac0d986 83 * After writing |-------|-------|-------|-------|-------|-------|-------|
embeddedartists 0:6b68dac0d986 84 * to FILE2 |///////| FILE1 |///////| FILE3 | FILE2 |///////|
embeddedartists 0:6b68dac0d986 85 * |-------|-------|-------|-------|-------|-------|-------|
embeddedartists 0:6b68dac0d986 86 * </pre>
embeddedartists 0:6b68dac0d986 87 *
embeddedartists 0:6b68dac0d986 88 * <b>Note: </b>As each file takes up at least one block it will limit the total number of files that
embeddedartists 0:6b68dac0d986 89 * can be stored on the file system. The formula for this is roughly
embeddedartists 0:6b68dac0d986 90 * <pre>
embeddedartists 0:6b68dac0d986 91 * max_num_files = fs_size_in_bytes / erase_block_size
embeddedartists 0:6b68dac0d986 92 * </pre>
embeddedartists 0:6b68dac0d986 93 * For the SPI flash on the LPC4088 QuickStart Board it means
embeddedartists 0:6b68dac0d986 94 * <pre>
embeddedartists 0:6b68dac0d986 95 * max_num_files = 8MByte / 4KByte = 2048
embeddedartists 0:6b68dac0d986 96 * </pre>
embeddedartists 0:6b68dac0d986 97 *
embeddedartists 0:6b68dac0d986 98 * Some of the blocks are used to store the table of content (TOC) at the very end of
embeddedartists 0:6b68dac0d986 99 * the spi flash. The TOC will contain a list of all blocks on the flash (even those
embeddedartists 0:6b68dac0d986 100 * not used by the file system) and will mark each block as "reserved","in use" or "free".
embeddedartists 0:6b68dac0d986 101 * For a file system that is 4MByte on a 8MByte flash half of the blocks will be marked
embeddedartists 0:6b68dac0d986 102 * as "reserved".
embeddedartists 0:6b68dac0d986 103 *
embeddedartists 0:6b68dac0d986 104 * <b>Note: </b>The file system will not store any date/time information.
embeddedartists 0:6b68dac0d986 105 *
embeddedartists 0:6b68dac0d986 106 * <b>Note: </b>The file system will not store any file attributes (hidden/system/read only).
embeddedartists 0:6b68dac0d986 107 *
embeddedartists 0:6b68dac0d986 108 * <b>Note: </b>The file system stores the absolute path of each file (path + file name) in
embeddedartists 0:6b68dac0d986 109 * the file's first block's first 256 bytes. Folders are never stored themselves. This has
embeddedartists 0:6b68dac0d986 110 * the drawback that the file system cannot hold empty folders.
embeddedartists 0:6b68dac0d986 111 */
embeddedartists 0:6b68dac0d986 112 class QSPIFileSystem : public FileSystemLike {
embeddedartists 0:6b68dac0d986 113 public:
embeddedartists 0:6b68dac0d986 114
embeddedartists 0:6b68dac0d986 115 /** Create the File System for accessing a QSPI Flash
embeddedartists 0:6b68dac0d986 116 *
embeddedartists 0:6b68dac0d986 117 * @param name The name used to access the virtual filesystem
embeddedartists 0:6b68dac0d986 118 */
embeddedartists 0:6b68dac0d986 119 QSPIFileSystem(const char* name);
embeddedartists 0:6b68dac0d986 120
embeddedartists 42:bbfe299d4a0c 121 virtual int open(FileHandle **file, const char *filename, int flags);
embeddedartists 42:bbfe299d4a0c 122 virtual int open(DirHandle **dir, const char *path);
embeddedartists 42:bbfe299d4a0c 123
embeddedartists 0:6b68dac0d986 124 virtual int remove(const char *filename);
embeddedartists 0:6b68dac0d986 125 virtual int rename(const char *oldname, const char *newname);
embeddedartists 42:bbfe299d4a0c 126
embeddedartists 0:6b68dac0d986 127 virtual int mkdir(const char *name, mode_t mode);
embeddedartists 0:6b68dac0d986 128
embeddedartists 0:6b68dac0d986 129 /** Creates a new file system on the QSPI flash.
embeddedartists 0:6b68dac0d986 130 * The file system will have the specified size and will always
embeddedartists 0:6b68dac0d986 131 * be positioned at the end of the QSPI flash. If the fsSizeInMB is
embeddedartists 0:6b68dac0d986 132 * less than the size of the QSPI flash the lower end of the flash
embeddedartists 0:6b68dac0d986 133 * will be left untouched.
embeddedartists 0:6b68dac0d986 134 *
embeddedartists 0:6b68dac0d986 135 * @param fsSizeInMB The size of the file system
embeddedartists 0:6b68dac0d986 136 *
embeddedartists 0:6b68dac0d986 137 * @returns
embeddedartists 0:6b68dac0d986 138 * 0 on success,
embeddedartists 0:6b68dac0d986 139 * -1 on failure.
embeddedartists 0:6b68dac0d986 140 */
embeddedartists 0:6b68dac0d986 141 int format(unsigned int fsSizeInMB = 8);
embeddedartists 0:6b68dac0d986 142
embeddedartists 0:6b68dac0d986 143 /** Tests if there is a file system present on the QSPI flash
embeddedartists 0:6b68dac0d986 144 *
embeddedartists 0:6b68dac0d986 145 * @returns
embeddedartists 0:6b68dac0d986 146 * True if a valid file system could be found,
embeddedartists 0:6b68dac0d986 147 * False on failure.
embeddedartists 0:6b68dac0d986 148 */
embeddedartists 0:6b68dac0d986 149 bool isformatted();
embeddedartists 0:6b68dac0d986 150
embeddedartists 0:6b68dac0d986 151 /** Retrieves the start and end addresses for the file system.
embeddedartists 0:6b68dac0d986 152 * The pStartAddr and pEndAddr will only be assigned values if the
embeddedartists 0:6b68dac0d986 153 * function returns true.
embeddedartists 0:6b68dac0d986 154 *
embeddedartists 0:6b68dac0d986 155 * @param pStartAddr Will return the start of the file system area
embeddedartists 0:6b68dac0d986 156 * @param pEndAddr Will return the end of the file system area
embeddedartists 0:6b68dac0d986 157 *
embeddedartists 0:6b68dac0d986 158 * @returns
embeddedartists 0:6b68dac0d986 159 * True if there is a file system,
embeddedartists 0:6b68dac0d986 160 * False on failure.
embeddedartists 0:6b68dac0d986 161 */
embeddedartists 0:6b68dac0d986 162 bool getMemoryBoundaries(uint32_t* pStartAddr, uint32_t* pEndAddr);
embeddedartists 0:6b68dac0d986 163 };
embeddedartists 0:6b68dac0d986 164
embeddedartists 0:6b68dac0d986 165 #endif