Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/daplink/drag-n-drop/virtual_fs.h@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | /** |
Pawel Zarembski |
0:01f31e923fe2 | 2 | * @file virtual_fs.h |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * @brief FAT 12/16 filesystem handling |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved |
Pawel Zarembski |
0:01f31e923fe2 | 7 | * SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 8 | * |
Pawel Zarembski |
0:01f31e923fe2 | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Pawel Zarembski |
0:01f31e923fe2 | 10 | * not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 11 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 12 | * |
Pawel Zarembski |
0:01f31e923fe2 | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 14 | * |
Pawel Zarembski |
0:01f31e923fe2 | 15 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 18 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 19 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 20 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 21 | |
Pawel Zarembski |
0:01f31e923fe2 | 22 | #ifndef VIRTUAL_FS_H |
Pawel Zarembski |
0:01f31e923fe2 | 23 | #define VIRTUAL_FS_H |
Pawel Zarembski |
0:01f31e923fe2 | 24 | |
Pawel Zarembski |
0:01f31e923fe2 | 25 | #include <stdint.h> |
Pawel Zarembski |
0:01f31e923fe2 | 26 | |
Pawel Zarembski |
0:01f31e923fe2 | 27 | #ifdef __cplusplus |
Pawel Zarembski |
0:01f31e923fe2 | 28 | extern "C" { |
Pawel Zarembski |
0:01f31e923fe2 | 29 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 30 | |
Pawel Zarembski |
0:01f31e923fe2 | 31 | #define VFS_CLUSTER_SIZE 0x1000 |
Pawel Zarembski |
0:01f31e923fe2 | 32 | #define VFS_SECTOR_SIZE 512 |
Pawel Zarembski |
0:01f31e923fe2 | 33 | #define VFS_INVALID_SECTOR 0xFFFFFFFF |
Pawel Zarembski |
0:01f31e923fe2 | 34 | #define VFS_FILE_INVALID 0 |
Pawel Zarembski |
0:01f31e923fe2 | 35 | #define VFS_MAX_FILES 16 |
Pawel Zarembski |
0:01f31e923fe2 | 36 | |
Pawel Zarembski |
0:01f31e923fe2 | 37 | typedef char vfs_filename_t[11]; |
Pawel Zarembski |
0:01f31e923fe2 | 38 | |
Pawel Zarembski |
0:01f31e923fe2 | 39 | typedef enum { |
Pawel Zarembski |
0:01f31e923fe2 | 40 | VFS_FILE_ATTR_READ_ONLY = (1 << 0), |
Pawel Zarembski |
0:01f31e923fe2 | 41 | VFS_FILE_ATTR_HIDDEN = (1 << 1), |
Pawel Zarembski |
0:01f31e923fe2 | 42 | VFS_FILE_ATTR_SYSTEM = (1 << 2), |
Pawel Zarembski |
0:01f31e923fe2 | 43 | VFS_FILE_ATTR_VOLUME_LABEL = (1 << 3), |
Pawel Zarembski |
0:01f31e923fe2 | 44 | VFS_FILE_ATTR_SUB_DIR = (1 << 4), |
Pawel Zarembski |
0:01f31e923fe2 | 45 | VFS_FILE_ATTR_ARCHIVE = (1 << 5), |
Pawel Zarembski |
0:01f31e923fe2 | 46 | } vfs_file_attr_bit_t; |
Pawel Zarembski |
0:01f31e923fe2 | 47 | |
Pawel Zarembski |
0:01f31e923fe2 | 48 | typedef enum { |
Pawel Zarembski |
0:01f31e923fe2 | 49 | VFS_FILE_CREATED = 0, /*!< A new file was created */ |
Pawel Zarembski |
0:01f31e923fe2 | 50 | VFS_FILE_DELETED, /*!< An existing file was deleted */ |
Pawel Zarembski |
0:01f31e923fe2 | 51 | VFS_FILE_CHANGED, /*!< Some attribute of the file changed. |
Pawel Zarembski |
0:01f31e923fe2 | 52 | Note: when a file is deleted or |
Pawel Zarembski |
0:01f31e923fe2 | 53 | created a file changed |
Pawel Zarembski |
0:01f31e923fe2 | 54 | notification will also occur*/ |
Pawel Zarembski |
0:01f31e923fe2 | 55 | } vfs_file_change_t; |
Pawel Zarembski |
0:01f31e923fe2 | 56 | |
Pawel Zarembski |
0:01f31e923fe2 | 57 | typedef void *vfs_file_t; |
Pawel Zarembski |
0:01f31e923fe2 | 58 | typedef uint32_t vfs_sector_t; |
Pawel Zarembski |
0:01f31e923fe2 | 59 | |
Pawel Zarembski |
0:01f31e923fe2 | 60 | // Callback for when data is written to a file on the virtual filesystem |
Pawel Zarembski |
0:01f31e923fe2 | 61 | typedef void (*vfs_write_cb_t)(uint32_t sector_offset, const uint8_t *data, uint32_t num_sectors); |
Pawel Zarembski |
0:01f31e923fe2 | 62 | // Callback for when data is ready from the virtual filesystem |
Pawel Zarembski |
0:01f31e923fe2 | 63 | typedef uint32_t (*vfs_read_cb_t)(uint32_t sector_offset, uint8_t *data, uint32_t num_sectors); |
Pawel Zarembski |
0:01f31e923fe2 | 64 | // Callback for when a file's attributes are changed on the virtual filesystem. Note that the 'file' parameter |
Pawel Zarembski |
0:01f31e923fe2 | 65 | // can be saved and compared to other files to see if they are referencing the same object. The |
Pawel Zarembski |
0:01f31e923fe2 | 66 | // same cannot be done with new_file_data since it points to a temporary buffer. |
Pawel Zarembski |
0:01f31e923fe2 | 67 | typedef void (*vfs_file_change_cb_t)(const vfs_filename_t filename, vfs_file_change_t change, |
Pawel Zarembski |
0:01f31e923fe2 | 68 | vfs_file_t file, vfs_file_t new_file_data); |
Pawel Zarembski |
0:01f31e923fe2 | 69 | |
Pawel Zarembski |
0:01f31e923fe2 | 70 | // Initialize the filesystem with the given size and name |
Pawel Zarembski |
0:01f31e923fe2 | 71 | void vfs_init(const vfs_filename_t drive_name, uint32_t disk_size); |
Pawel Zarembski |
0:01f31e923fe2 | 72 | |
Pawel Zarembski |
0:01f31e923fe2 | 73 | // Get the total size of the virtual filesystem |
Pawel Zarembski |
0:01f31e923fe2 | 74 | uint32_t vfs_get_total_size(void); |
Pawel Zarembski |
0:01f31e923fe2 | 75 | |
Pawel Zarembski |
0:01f31e923fe2 | 76 | // Add a file to the virtual FS and return a handle to this file. |
Pawel Zarembski |
0:01f31e923fe2 | 77 | // This must be called before vfs_read or vfs_write are called. |
Pawel Zarembski |
0:01f31e923fe2 | 78 | // Adding a new file after vfs_read or vfs_write have been called results in undefined behavior. |
Pawel Zarembski |
0:01f31e923fe2 | 79 | vfs_file_t vfs_create_file(const vfs_filename_t filename, vfs_read_cb_t read_cb, vfs_write_cb_t write_cb, uint32_t len); |
Pawel Zarembski |
0:01f31e923fe2 | 80 | |
Pawel Zarembski |
0:01f31e923fe2 | 81 | // Set the attributes of a file |
Pawel Zarembski |
0:01f31e923fe2 | 82 | void vfs_file_set_attr(vfs_file_t file, vfs_file_attr_bit_t attr); |
Pawel Zarembski |
0:01f31e923fe2 | 83 | |
Pawel Zarembski |
0:01f31e923fe2 | 84 | // Get the starting sector of this file. |
Pawel Zarembski |
0:01f31e923fe2 | 85 | // NOTE - If the file size is 0 there is no starting |
Pawel Zarembski |
0:01f31e923fe2 | 86 | // sector so VFS_INVALID_SECTOR will be returned. |
Pawel Zarembski |
0:01f31e923fe2 | 87 | vfs_sector_t vfs_file_get_start_sector(vfs_file_t file); |
Pawel Zarembski |
0:01f31e923fe2 | 88 | |
Pawel Zarembski |
0:01f31e923fe2 | 89 | // Get the size of the file. |
Pawel Zarembski |
0:01f31e923fe2 | 90 | uint32_t vfs_file_get_size(vfs_file_t file); |
Pawel Zarembski |
0:01f31e923fe2 | 91 | |
Pawel Zarembski |
0:01f31e923fe2 | 92 | // Get the attributes of a file |
Pawel Zarembski |
0:01f31e923fe2 | 93 | vfs_file_attr_bit_t vfs_file_get_attr(vfs_file_t file); |
Pawel Zarembski |
0:01f31e923fe2 | 94 | |
Pawel Zarembski |
0:01f31e923fe2 | 95 | // Set the callback when a file is created, deleted or has atributes changed. |
Pawel Zarembski |
0:01f31e923fe2 | 96 | void vfs_set_file_change_callback(vfs_file_change_cb_t cb); |
Pawel Zarembski |
0:01f31e923fe2 | 97 | |
Pawel Zarembski |
0:01f31e923fe2 | 98 | // Read one or more sectors from the virtual filesystem |
Pawel Zarembski |
0:01f31e923fe2 | 99 | void vfs_read(uint32_t sector, uint8_t *buf, uint32_t num_of_sectors); |
Pawel Zarembski |
0:01f31e923fe2 | 100 | |
Pawel Zarembski |
0:01f31e923fe2 | 101 | // Write one or more sectors to the virtual filesystem |
Pawel Zarembski |
0:01f31e923fe2 | 102 | void vfs_write(uint32_t sector, const uint8_t *buf, uint32_t num_of_sectors); |
Pawel Zarembski |
0:01f31e923fe2 | 103 | |
Pawel Zarembski |
0:01f31e923fe2 | 104 | #ifdef __cplusplus |
Pawel Zarembski |
0:01f31e923fe2 | 105 | } |
Pawel Zarembski |
0:01f31e923fe2 | 106 | #endif |
Pawel Zarembski |
0:01f31e923fe2 | 107 | |
Pawel Zarembski |
0:01f31e923fe2 | 108 | #endif |