Simple LED control project using CC3100 as Access Point and socket
Fork of cc3100_Test_Demo by
simplelink/cc3100_fs.h@6:778b081f6a13, 2015-03-19 (annotated)
- Committer:
- dflet
- Date:
- Thu Mar 19 15:39:08 2015 +0000
- Revision:
- 6:778b081f6a13
Updated to CC3100SDK1.1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dflet | 6:778b081f6a13 | 1 | /* |
dflet | 6:778b081f6a13 | 2 | * fs.h - CC31xx/CC32xx Host Driver Implementation |
dflet | 6:778b081f6a13 | 3 | * |
dflet | 6:778b081f6a13 | 4 | * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ |
dflet | 6:778b081f6a13 | 5 | * |
dflet | 6:778b081f6a13 | 6 | * |
dflet | 6:778b081f6a13 | 7 | * Redistribution and use in source and binary forms, with or without |
dflet | 6:778b081f6a13 | 8 | * modification, are permitted provided that the following conditions |
dflet | 6:778b081f6a13 | 9 | * are met: |
dflet | 6:778b081f6a13 | 10 | * |
dflet | 6:778b081f6a13 | 11 | * Redistributions of source code must retain the above copyright |
dflet | 6:778b081f6a13 | 12 | * notice, this list of conditions and the following disclaimer. |
dflet | 6:778b081f6a13 | 13 | * |
dflet | 6:778b081f6a13 | 14 | * Redistributions in binary form must reproduce the above copyright |
dflet | 6:778b081f6a13 | 15 | * notice, this list of conditions and the following disclaimer in the |
dflet | 6:778b081f6a13 | 16 | * documentation and/or other materials provided with the |
dflet | 6:778b081f6a13 | 17 | * distribution. |
dflet | 6:778b081f6a13 | 18 | * |
dflet | 6:778b081f6a13 | 19 | * Neither the name of Texas Instruments Incorporated nor the names of |
dflet | 6:778b081f6a13 | 20 | * its contributors may be used to endorse or promote products derived |
dflet | 6:778b081f6a13 | 21 | * from this software without specific prior written permission. |
dflet | 6:778b081f6a13 | 22 | * |
dflet | 6:778b081f6a13 | 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
dflet | 6:778b081f6a13 | 24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
dflet | 6:778b081f6a13 | 25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
dflet | 6:778b081f6a13 | 26 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
dflet | 6:778b081f6a13 | 27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
dflet | 6:778b081f6a13 | 28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
dflet | 6:778b081f6a13 | 29 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
dflet | 6:778b081f6a13 | 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
dflet | 6:778b081f6a13 | 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
dflet | 6:778b081f6a13 | 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
dflet | 6:778b081f6a13 | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
dflet | 6:778b081f6a13 | 34 | * |
dflet | 6:778b081f6a13 | 35 | */ |
dflet | 6:778b081f6a13 | 36 | |
dflet | 6:778b081f6a13 | 37 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 38 | /* Include files */ |
dflet | 6:778b081f6a13 | 39 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 40 | |
dflet | 6:778b081f6a13 | 41 | #include "cc3100_simplelink.h" |
dflet | 6:778b081f6a13 | 42 | |
dflet | 6:778b081f6a13 | 43 | #ifndef FS_H_ |
dflet | 6:778b081f6a13 | 44 | #define FS_H_ |
dflet | 6:778b081f6a13 | 45 | |
dflet | 6:778b081f6a13 | 46 | /*! |
dflet | 6:778b081f6a13 | 47 | |
dflet | 6:778b081f6a13 | 48 | \addtogroup FileSystem |
dflet | 6:778b081f6a13 | 49 | @{ |
dflet | 6:778b081f6a13 | 50 | |
dflet | 6:778b081f6a13 | 51 | */ |
dflet | 6:778b081f6a13 | 52 | |
dflet | 6:778b081f6a13 | 53 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 54 | /* Macro declarations */ |
dflet | 6:778b081f6a13 | 55 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 56 | |
dflet | 6:778b081f6a13 | 57 | /* FS error codes */ |
dflet | 6:778b081f6a13 | 58 | #define SL_FS_OK (0) |
dflet | 6:778b081f6a13 | 59 | #define SL_FS_ERR_EMPTY_SFLASH (-67) |
dflet | 6:778b081f6a13 | 60 | #define SL_FS_ERR_FILE_IS_NOT_SECURE_AND_SIGN (-66) |
dflet | 6:778b081f6a13 | 61 | #define SL_FS_ERASING_FLASH (-65) |
dflet | 6:778b081f6a13 | 62 | #define SL_FS_FILE_HAS_NOT_BEEN_CLOSE_CORRECTLY (-64) |
dflet | 6:778b081f6a13 | 63 | #define SL_FS_WRONG_SIGNATURE (-63) |
dflet | 6:778b081f6a13 | 64 | #define SL_FS_WRONG_SIGNATURE_OR_CERTIFIC_NAME_LENGTH (-62) |
dflet | 6:778b081f6a13 | 65 | #define SL_FS_NOT_16_ALIGNED (-61) |
dflet | 6:778b081f6a13 | 66 | #define SL_FS_CERT_CHAIN_ERROR (-60) |
dflet | 6:778b081f6a13 | 67 | #define SL_FS_FILE_NAME_EXIST (-59) |
dflet | 6:778b081f6a13 | 68 | #define SL_FS_SECURITY_BUF_ALREADY_ALLOC (-58) |
dflet | 6:778b081f6a13 | 69 | #define SL_FS_SECURE_FILE_MUST_BE_COMMIT (-57) |
dflet | 6:778b081f6a13 | 70 | #define SL_FS_ERR_INCORRECT_OFFSET_ALIGNMENT (-56) |
dflet | 6:778b081f6a13 | 71 | #define SL_FS_ERR_FAILED_READ_NVMEM_HEADER (-55) |
dflet | 6:778b081f6a13 | 72 | #define SL_FS_WRONG_FILE_NAME (-54) |
dflet | 6:778b081f6a13 | 73 | #define SL_FS_FILE_SYSTEM_IS_LOCKED (-53) |
dflet | 6:778b081f6a13 | 74 | #define SL_FS_SECURITY_ALLERT (-52) |
dflet | 6:778b081f6a13 | 75 | #define SL_FS_FILE_UNVALID_FILE_SIZE (-51) |
dflet | 6:778b081f6a13 | 76 | #define SL_FS_ERR_TOKEN_IS_NOT_VALID (-50) |
dflet | 6:778b081f6a13 | 77 | #define SL_FS_NO_DEVICE_IS_LOADED (-49) |
dflet | 6:778b081f6a13 | 78 | #define SL_FS_DATA_ADDRESS_SHOUD_BE_IN_DATA_RAM (-48) |
dflet | 6:778b081f6a13 | 79 | #define SL_FS_DATA_IS_NOT_ALIGNED (-47) |
dflet | 6:778b081f6a13 | 80 | #define SL_FS_ERR_OVERLAP_DETECTION_THRESHHOLD (-46) |
dflet | 6:778b081f6a13 | 81 | #define SL_FS_FILE_HAS_RESERVED_NV_INDEX (-45) |
dflet | 6:778b081f6a13 | 82 | #define SL_FS_ERR_MAX_FS_FILES_IS_LARGER (-44) |
dflet | 6:778b081f6a13 | 83 | #define SL_FS_ERR_MAX_FS_FILES_IS_SMALLER (-43) |
dflet | 6:778b081f6a13 | 84 | #define SL_FS_FILE_MAX_SIZE_EXCEEDED (-42) |
dflet | 6:778b081f6a13 | 85 | #define SL_FS_INVALID_BUFFER_FOR_READ (-41) |
dflet | 6:778b081f6a13 | 86 | #define SL_FS_INVALID_BUFFER_FOR_WRITE (-40) |
dflet | 6:778b081f6a13 | 87 | #define SL_FS_ERR_FILE_IMAGE_IS_CORRUPTED (-39) |
dflet | 6:778b081f6a13 | 88 | #define SL_FS_ERR_SIZE_OF_FILE_EXT_EXCEEDED (-38) |
dflet | 6:778b081f6a13 | 89 | #define SL_FS_WARNING_FILE_NAME_NOT_KEPT (-37) |
dflet | 6:778b081f6a13 | 90 | #define SL_FS_ERR_DEVICE_IS_NOT_FORMATTED (-36) |
dflet | 6:778b081f6a13 | 91 | #define SL_FS_ERR_FAILED_WRITE_NVMEM_HEADER (-35) |
dflet | 6:778b081f6a13 | 92 | #define SL_FS_ERR_NO_AVAILABLE_NV_INDEX (-34) |
dflet | 6:778b081f6a13 | 93 | #define SL_FS_ERR_FAILED_TO_ALLOCATE_MEM (-33) |
dflet | 6:778b081f6a13 | 94 | #define SL_FS_ERR_FAILED_TO_READ_INTEGRITY_HEADER_2 (-32) |
dflet | 6:778b081f6a13 | 95 | #define SL_FS_ERR_FAILED_TO_READ_INTEGRITY_HEADER_1 (-31) |
dflet | 6:778b081f6a13 | 96 | #define SL_FS_ERR_NO_AVAILABLE_BLOCKS (-30) |
dflet | 6:778b081f6a13 | 97 | #define SL_FS_ERR_FILE_MAX_SIZE_BIGGER_THAN_EXISTING_FILE (-29) |
dflet | 6:778b081f6a13 | 98 | #define SL_FS_ERR_FILE_EXISTS_ON_DIFFERENT_DEVICE_ID (-28) |
dflet | 6:778b081f6a13 | 99 | #define SL_FS_ERR_INVALID_ACCESS_TYPE (-27) |
dflet | 6:778b081f6a13 | 100 | #define SL_FS_ERR_FILE_ALREADY_EXISTS (-26) |
dflet | 6:778b081f6a13 | 101 | #define SL_FS_ERR_PROGRAM (-25) |
dflet | 6:778b081f6a13 | 102 | #define SL_FS_ERR_NO_ENTRIES_AVAILABLE (-24) |
dflet | 6:778b081f6a13 | 103 | #define SL_FS_ERR_FILE_ACCESS_IS_DIFFERENT (-23) |
dflet | 6:778b081f6a13 | 104 | #define SL_FS_ERR_BAD_FILE_MODE (-22) |
dflet | 6:778b081f6a13 | 105 | #define SL_FS_ERR_FAILED_READ_NVFILE (-21) |
dflet | 6:778b081f6a13 | 106 | #define SL_FS_ERR_FAILED_INIT_STORAGE (-20) |
dflet | 6:778b081f6a13 | 107 | #define SL_FS_ERR_CONTINUE_WRITE_MUST_BE_MOD_4 (-19) |
dflet | 6:778b081f6a13 | 108 | #define SL_FS_ERR_FAILED_LOAD_FILE (-18) |
dflet | 6:778b081f6a13 | 109 | #define SL_FS_ERR_INVALID_HANDLE (-17) |
dflet | 6:778b081f6a13 | 110 | #define SL_FS_ERR_FAILED_TO_WRITE (-16) |
dflet | 6:778b081f6a13 | 111 | #define SL_FS_ERR_OFFSET_OUT_OF_RANGE (-15) |
dflet | 6:778b081f6a13 | 112 | #define SL_FS_ERR_ALLOC (-14) |
dflet | 6:778b081f6a13 | 113 | #define SL_FS_ERR_READ_DATA_LENGTH (-13) |
dflet | 6:778b081f6a13 | 114 | #define SL_FS_ERR_INVALID_FILE_ID (-12) |
dflet | 6:778b081f6a13 | 115 | #define SL_FS_ERR_FILE_NOT_EXISTS (-11) |
dflet | 6:778b081f6a13 | 116 | #define SL_FS_ERR_EMPTY_ERROR (-10) |
dflet | 6:778b081f6a13 | 117 | #define SL_FS_ERR_INVALID_ARGS (-9) |
dflet | 6:778b081f6a13 | 118 | #define SL_FS_ERR_FAILED_TO_CREATE_FILE (-8) |
dflet | 6:778b081f6a13 | 119 | #define SL_FS_ERR_FS_ALREADY_LOADED (-7) |
dflet | 6:778b081f6a13 | 120 | #define SL_FS_ERR_UNKNOWN (-6) |
dflet | 6:778b081f6a13 | 121 | #define SL_FS_ERR_FAILED_TO_CREATE_LOCK_OBJ (-5) |
dflet | 6:778b081f6a13 | 122 | #define SL_FS_ERR_DEVICE_NOT_LOADED (-4) |
dflet | 6:778b081f6a13 | 123 | #define SL_FS_ERR_INVALID_MAGIC_NUM (-3) |
dflet | 6:778b081f6a13 | 124 | #define SL_FS_ERR_FAILED_TO_READ (-2) |
dflet | 6:778b081f6a13 | 125 | #define SL_FS_ERR_NOT_SUPPORTED (-1) |
dflet | 6:778b081f6a13 | 126 | /* end of error codes */ |
dflet | 6:778b081f6a13 | 127 | |
dflet | 6:778b081f6a13 | 128 | #define _FS_MODE_ACCESS_RESERVED_OFFSET (24) |
dflet | 6:778b081f6a13 | 129 | #define _FS_MODE_ACCESS_RESERVED_MASK (0xFF) |
dflet | 6:778b081f6a13 | 130 | #define _FS_MODE_ACCESS_FLAGS_OFFSET (16) |
dflet | 6:778b081f6a13 | 131 | #define _FS_MODE_ACCESS_FLAGS_MASK (0xFF) |
dflet | 6:778b081f6a13 | 132 | #define _FS_MODE_ACCESS_OFFSET (12) |
dflet | 6:778b081f6a13 | 133 | #define _FS_MODE_ACCESS_MASK (0xF) |
dflet | 6:778b081f6a13 | 134 | #define _FS_MODE_OPEN_SIZE_GRAN_OFFSET (8) |
dflet | 6:778b081f6a13 | 135 | #define _FS_MODE_OPEN_SIZE_GRAN_MASK (0xF) |
dflet | 6:778b081f6a13 | 136 | #define _FS_MODE_OPEN_SIZE_OFFSET (0) |
dflet | 6:778b081f6a13 | 137 | #define _FS_MODE_OPEN_SIZE_MASK (0xFF) |
dflet | 6:778b081f6a13 | 138 | #define MAX_MODE_SIZE (0xFF) |
dflet | 6:778b081f6a13 | 139 | #define _FS_MODE(Access, SizeGran, Size,Flags) (uint32_t)(((uint32_t)((Access) & _FS_MODE_ACCESS_MASK)<<_FS_MODE_ACCESS_OFFSET) | \ |
dflet | 6:778b081f6a13 | 140 | ((uint32_t)((SizeGran) & _FS_MODE_OPEN_SIZE_GRAN_MASK)<<_FS_MODE_OPEN_SIZE_GRAN_OFFSET) | \ |
dflet | 6:778b081f6a13 | 141 | ((uint32_t)((Size) & _FS_MODE_OPEN_SIZE_MASK)<<_FS_MODE_OPEN_SIZE_OFFSET) | \ |
dflet | 6:778b081f6a13 | 142 | ((uint32_t)((Flags) & _FS_MODE_ACCESS_FLAGS_MASK)<<_FS_MODE_ACCESS_FLAGS_OFFSET)) |
dflet | 6:778b081f6a13 | 143 | |
dflet | 6:778b081f6a13 | 144 | |
dflet | 6:778b081f6a13 | 145 | /* sl_FsOpen options */ |
dflet | 6:778b081f6a13 | 146 | /* Open for Read */ |
dflet | 6:778b081f6a13 | 147 | #define FS_MODE_OPEN_READ _FS_MODE(_FS_MODE_OPEN_READ,0,0,0) |
dflet | 6:778b081f6a13 | 148 | /* Open for Write (in case file exist) */ |
dflet | 6:778b081f6a13 | 149 | #define FS_MODE_OPEN_WRITE _FS_MODE(_FS_MODE_OPEN_WRITE,0,0,0) |
dflet | 6:778b081f6a13 | 150 | /* Open for Creating a new file */ |
dflet | 6:778b081f6a13 | 151 | #define FS_MODE_OPEN_CREATE(maxSizeInBytes,accessModeFlags) _sl_GetCreateFsMode(maxSizeInBytes,accessModeFlags) |
dflet | 6:778b081f6a13 | 152 | |
dflet | 6:778b081f6a13 | 153 | namespace mbed_cc3100 { |
dflet | 6:778b081f6a13 | 154 | |
dflet | 6:778b081f6a13 | 155 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 156 | /* Structure/Enum declarations */ |
dflet | 6:778b081f6a13 | 157 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 158 | typedef struct { |
dflet | 6:778b081f6a13 | 159 | uint16_t flags; |
dflet | 6:778b081f6a13 | 160 | uint32_t FileLen; |
dflet | 6:778b081f6a13 | 161 | uint32_t AllocatedLen; |
dflet | 6:778b081f6a13 | 162 | uint32_t Token[4]; |
dflet | 6:778b081f6a13 | 163 | } SlFsFileInfo_t; |
dflet | 6:778b081f6a13 | 164 | |
dflet | 6:778b081f6a13 | 165 | typedef enum { |
dflet | 6:778b081f6a13 | 166 | _FS_MODE_OPEN_READ = 0, |
dflet | 6:778b081f6a13 | 167 | _FS_MODE_OPEN_WRITE, |
dflet | 6:778b081f6a13 | 168 | _FS_MODE_OPEN_CREATE, |
dflet | 6:778b081f6a13 | 169 | _FS_MODE_OPEN_WRITE_CREATE_IF_NOT_EXIST |
dflet | 6:778b081f6a13 | 170 | } SlFsFileOpenAccessType_e; |
dflet | 6:778b081f6a13 | 171 | |
dflet | 6:778b081f6a13 | 172 | typedef enum { |
dflet | 6:778b081f6a13 | 173 | _FS_FILE_OPEN_FLAG_COMMIT = 0x1, /* MIRROR - for fail safe */ |
dflet | 6:778b081f6a13 | 174 | _FS_FILE_OPEN_FLAG_SECURE = 0x2, /* SECURE */ |
dflet | 6:778b081f6a13 | 175 | _FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST = 0x4, /* Relevant to secure file only */ |
dflet | 6:778b081f6a13 | 176 | _FS_FILE_OPEN_FLAG_STATIC = 0x8, /* Relevant to secure file only */ |
dflet | 6:778b081f6a13 | 177 | _FS_FILE_OPEN_FLAG_VENDOR = 0x10, /* Relevant to secure file only */ |
dflet | 6:778b081f6a13 | 178 | _FS_FILE_PUBLIC_WRITE= 0x20, /* Relevant to secure file only, the file can be opened for write without Token */ |
dflet | 6:778b081f6a13 | 179 | _FS_FILE_PUBLIC_READ = 0x40 /* Relevant to secure file only, the file can be opened for read without Token */ |
dflet | 6:778b081f6a13 | 180 | } SlFileOpenFlags_e; |
dflet | 6:778b081f6a13 | 181 | |
dflet | 6:778b081f6a13 | 182 | typedef enum { |
dflet | 6:778b081f6a13 | 183 | _FS_MODE_SIZE_GRAN_256B = 0, /* MAX_SIZE = 64K */ |
dflet | 6:778b081f6a13 | 184 | _FS_MODE_SIZE_GRAN_1KB, /* MAX_SIZE = 256K */ |
dflet | 6:778b081f6a13 | 185 | _FS_MODE_SIZE_GRAN_4KB, /* MAX_SZIE = 1M */ |
dflet | 6:778b081f6a13 | 186 | _FS_MODE_SIZE_GRAN_16KB, /* MAX_SIZE = 4M */ |
dflet | 6:778b081f6a13 | 187 | _FS_MODE_SIZE_GRAN_64KB, /* MAX_SIZE = 16M */ |
dflet | 6:778b081f6a13 | 188 | _FS_MAX_MODE_SIZE_GRAN |
dflet | 6:778b081f6a13 | 189 | } _SlFsFileOpenMaxSizeGran_e; |
dflet | 6:778b081f6a13 | 190 | |
dflet | 6:778b081f6a13 | 191 | class cc3100_driver; |
dflet | 6:778b081f6a13 | 192 | |
dflet | 6:778b081f6a13 | 193 | class cc3100_fs |
dflet | 6:778b081f6a13 | 194 | { |
dflet | 6:778b081f6a13 | 195 | |
dflet | 6:778b081f6a13 | 196 | public: |
dflet | 6:778b081f6a13 | 197 | |
dflet | 6:778b081f6a13 | 198 | cc3100_fs(cc3100_driver &driver); |
dflet | 6:778b081f6a13 | 199 | |
dflet | 6:778b081f6a13 | 200 | ~cc3100_fs(); |
dflet | 6:778b081f6a13 | 201 | |
dflet | 6:778b081f6a13 | 202 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 203 | /* Internal Function prototypes */ |
dflet | 6:778b081f6a13 | 204 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 205 | uint32_t _sl_GetCreateFsMode(uint32_t maxSizeInBytes,uint32_t accessFlags); |
dflet | 6:778b081f6a13 | 206 | uint16_t _sl_Strlen(const uint8_t *buffer); |
dflet | 6:778b081f6a13 | 207 | |
dflet | 6:778b081f6a13 | 208 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 209 | /* Function prototypes */ |
dflet | 6:778b081f6a13 | 210 | /*****************************************************************************/ |
dflet | 6:778b081f6a13 | 211 | |
dflet | 6:778b081f6a13 | 212 | /*! |
dflet | 6:778b081f6a13 | 213 | \brief open file for read or write from/to storage device |
dflet | 6:778b081f6a13 | 214 | |
dflet | 6:778b081f6a13 | 215 | \param[in] pFileName File Name buffer pointer |
dflet | 6:778b081f6a13 | 216 | \param[in] AccessModeAndMaxSize Options: As described below |
dflet | 6:778b081f6a13 | 217 | \param[in] pToken Reserved for future use. Use NULL for this field |
dflet | 6:778b081f6a13 | 218 | \param[out] pFileHandle Pointing on the file and used for read and write commands to the file |
dflet | 6:778b081f6a13 | 219 | |
dflet | 6:778b081f6a13 | 220 | AccessModeAndMaxSize possible input \n |
dflet | 6:778b081f6a13 | 221 | FS_MODE_OPEN_READ - Read a file \n |
dflet | 6:778b081f6a13 | 222 | FS_MODE_OPEN_WRITE - Open for write for an existing file \n |
dflet | 6:778b081f6a13 | 223 | FS_MODE_OPEN_CREATE(maxSizeInBytes,accessModeFlags) - Open for creating a new file. Max file size is defined in bytes. \n |
dflet | 6:778b081f6a13 | 224 | For optimal FS size, use max size in 4K-512 bytes steps (e.g. 3584,7680,117760) \n |
dflet | 6:778b081f6a13 | 225 | Several access modes bits can be combined together from SlFileOpenFlags_e enum |
dflet | 6:778b081f6a13 | 226 | |
dflet | 6:778b081f6a13 | 227 | \return On success, zero is returned. On error, an error code is returned |
dflet | 6:778b081f6a13 | 228 | |
dflet | 6:778b081f6a13 | 229 | \sa sl_FsRead sl_FsWrite sl_FsClose |
dflet | 6:778b081f6a13 | 230 | \note belongs to \ref basic_api |
dflet | 6:778b081f6a13 | 231 | \warning |
dflet | 6:778b081f6a13 | 232 | \par Example: |
dflet | 6:778b081f6a13 | 233 | \code |
dflet | 6:778b081f6a13 | 234 | char* DeviceFileName = "MyFile.txt"; |
dflet | 6:778b081f6a13 | 235 | unsigned long MaxSize = 63 * 1024; //62.5K is max file size |
dflet | 6:778b081f6a13 | 236 | long DeviceFileHandle = -1; |
dflet | 6:778b081f6a13 | 237 | long RetVal; //negative retval is an error |
dflet | 6:778b081f6a13 | 238 | unsigned long Offset = 0; |
dflet | 6:778b081f6a13 | 239 | uint8_t InputBuffer[100]; |
dflet | 6:778b081f6a13 | 240 | |
dflet | 6:778b081f6a13 | 241 | // Create a file and write data. The file in this example is secured, without signature and with a fail safe commit |
dflet | 6:778b081f6a13 | 242 | RetVal = sl_FsOpen((uint8_t *)DeviceFileName, |
dflet | 6:778b081f6a13 | 243 | FS_MODE_OPEN_CREATE(MaxSize , _FS_FILE_OPEN_FLAG_NO_SIGNATURE_TEST | _FS_FILE_OPEN_FLAG_COMMIT ), |
dflet | 6:778b081f6a13 | 244 | NULL, &DeviceFileHandle); |
dflet | 6:778b081f6a13 | 245 | |
dflet | 6:778b081f6a13 | 246 | Offset = 0; |
dflet | 6:778b081f6a13 | 247 | //Preferred in secure file that the Offset and the length will be aligned to 16 bytes. |
dflet | 6:778b081f6a13 | 248 | RetVal = sl_FsWrite( DeviceFileHandle, Offset, (uint8_t *)"HelloWorld", strlen("HelloWorld")); |
dflet | 6:778b081f6a13 | 249 | |
dflet | 6:778b081f6a13 | 250 | RetVal = sl_FsClose(DeviceFileHandle, NULL, NULL , 0); |
dflet | 6:778b081f6a13 | 251 | |
dflet | 6:778b081f6a13 | 252 | // open the same file for read, using the Token we got from the creation procedure above |
dflet | 6:778b081f6a13 | 253 | RetVal = sl_FsOpen((uint8_t *)DeviceFileName, |
dflet | 6:778b081f6a13 | 254 | FS_MODE_OPEN_READ, |
dflet | 6:778b081f6a13 | 255 | NULL, &DeviceFileHandle); |
dflet | 6:778b081f6a13 | 256 | |
dflet | 6:778b081f6a13 | 257 | Offset = 0; |
dflet | 6:778b081f6a13 | 258 | RetVal = sl_FsRead( DeviceFileHandle, Offset, (uint8_t *)InputBuffer, strlen("HelloWorld")); |
dflet | 6:778b081f6a13 | 259 | |
dflet | 6:778b081f6a13 | 260 | RetVal = sl_FsClose(DeviceFileHandle, NULL, NULL , 0); |
dflet | 6:778b081f6a13 | 261 | |
dflet | 6:778b081f6a13 | 262 | \endcode |
dflet | 6:778b081f6a13 | 263 | */ |
dflet | 6:778b081f6a13 | 264 | #if _SL_INCLUDE_FUNC(sl_FsOpen) |
dflet | 6:778b081f6a13 | 265 | int32_t sl_FsOpen(const uint8_t *pFileName, const uint32_t AccessModeAndMaxSize,uint32_t *pToken,int32_t *pFileHandle); |
dflet | 6:778b081f6a13 | 266 | #endif |
dflet | 6:778b081f6a13 | 267 | |
dflet | 6:778b081f6a13 | 268 | /*! |
dflet | 6:778b081f6a13 | 269 | \brief close file in storage device |
dflet | 6:778b081f6a13 | 270 | |
dflet | 6:778b081f6a13 | 271 | \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen) |
dflet | 6:778b081f6a13 | 272 | \param[in] pCeritificateFileName Reserved for future use. Use NULL. |
dflet | 6:778b081f6a13 | 273 | \param[in] pSignature Reserved for future use. Use NULL. |
dflet | 6:778b081f6a13 | 274 | \param[in] SignatureLen Reserved for future use. Use 0. |
dflet | 6:778b081f6a13 | 275 | |
dflet | 6:778b081f6a13 | 276 | |
dflet | 6:778b081f6a13 | 277 | \return On success, zero is returned. On error, an error code is returned |
dflet | 6:778b081f6a13 | 278 | |
dflet | 6:778b081f6a13 | 279 | \sa sl_FsRead sl_FsWrite sl_FsOpen |
dflet | 6:778b081f6a13 | 280 | \note Call the fs_Close with signature = 'A' signature len = 1 for activating an abort action |
dflet | 6:778b081f6a13 | 281 | \warning |
dflet | 6:778b081f6a13 | 282 | \par Example: |
dflet | 6:778b081f6a13 | 283 | \code |
dflet | 6:778b081f6a13 | 284 | sl_FsClose(FileHandle,0,0,0); |
dflet | 6:778b081f6a13 | 285 | \endcode |
dflet | 6:778b081f6a13 | 286 | */ |
dflet | 6:778b081f6a13 | 287 | #if _SL_INCLUDE_FUNC(sl_FsClose) |
dflet | 6:778b081f6a13 | 288 | int16_t sl_FsClose(const int32_t FileHdl, const uint8_t* pCeritificateFileName, const uint8_t* pSignature, const uint32_t SignatureLen); |
dflet | 6:778b081f6a13 | 289 | #endif |
dflet | 6:778b081f6a13 | 290 | |
dflet | 6:778b081f6a13 | 291 | /*! |
dflet | 6:778b081f6a13 | 292 | \brief Read block of data from a file in storage device |
dflet | 6:778b081f6a13 | 293 | |
dflet | 6:778b081f6a13 | 294 | \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen) |
dflet | 6:778b081f6a13 | 295 | \param[in] Offset Offset to specific read block |
dflet | 6:778b081f6a13 | 296 | \param[out] pData Pointer for the received data |
dflet | 6:778b081f6a13 | 297 | \param[in] Len Length of the received data |
dflet | 6:778b081f6a13 | 298 | |
dflet | 6:778b081f6a13 | 299 | \return On success, returns the number of read bytes. On error, negative number is returned |
dflet | 6:778b081f6a13 | 300 | |
dflet | 6:778b081f6a13 | 301 | \sa sl_FsClose sl_FsWrite sl_FsOpen |
dflet | 6:778b081f6a13 | 302 | \note belongs to \ref basic_api |
dflet | 6:778b081f6a13 | 303 | \warning |
dflet | 6:778b081f6a13 | 304 | \par Example: |
dflet | 6:778b081f6a13 | 305 | \code |
dflet | 6:778b081f6a13 | 306 | Status = sl_FsRead(FileHandle, 0, &readBuff[0], readSize); |
dflet | 6:778b081f6a13 | 307 | \endcode |
dflet | 6:778b081f6a13 | 308 | */ |
dflet | 6:778b081f6a13 | 309 | #if _SL_INCLUDE_FUNC(sl_FsRead) |
dflet | 6:778b081f6a13 | 310 | int32_t sl_FsRead(const int32_t FileHdl,uint32_t Offset ,uint8_t* pData,uint32_t Len); |
dflet | 6:778b081f6a13 | 311 | #endif |
dflet | 6:778b081f6a13 | 312 | |
dflet | 6:778b081f6a13 | 313 | /*! |
dflet | 6:778b081f6a13 | 314 | \brief write block of data to a file in storage device |
dflet | 6:778b081f6a13 | 315 | |
dflet | 6:778b081f6a13 | 316 | \param[in] FileHdl Pointer to the file (assigned from sl_FsOpen) |
dflet | 6:778b081f6a13 | 317 | \param[in] Offset Offset to specific block to be written |
dflet | 6:778b081f6a13 | 318 | \param[in] pData Pointer the transmitted data to the storage device |
dflet | 6:778b081f6a13 | 319 | \param[in] Len Length of the transmitted data |
dflet | 6:778b081f6a13 | 320 | |
dflet | 6:778b081f6a13 | 321 | \return On success, returns the number of written bytes. On error, an error code is returned |
dflet | 6:778b081f6a13 | 322 | |
dflet | 6:778b081f6a13 | 323 | \sa |
dflet | 6:778b081f6a13 | 324 | \note belongs to \ref basic_api |
dflet | 6:778b081f6a13 | 325 | \warning |
dflet | 6:778b081f6a13 | 326 | \par Example: |
dflet | 6:778b081f6a13 | 327 | \code |
dflet | 6:778b081f6a13 | 328 | Status = sl_FsWrite(FileHandle, 0, &buff[0], readSize); |
dflet | 6:778b081f6a13 | 329 | \endcode |
dflet | 6:778b081f6a13 | 330 | */ |
dflet | 6:778b081f6a13 | 331 | #if _SL_INCLUDE_FUNC(sl_FsWrite) |
dflet | 6:778b081f6a13 | 332 | int32_t sl_FsWrite(const int32_t FileHdl,uint32_t Offset,uint8_t* pData,uint32_t Len); |
dflet | 6:778b081f6a13 | 333 | #endif |
dflet | 6:778b081f6a13 | 334 | |
dflet | 6:778b081f6a13 | 335 | /*! |
dflet | 6:778b081f6a13 | 336 | \brief get info on a file |
dflet | 6:778b081f6a13 | 337 | |
dflet | 6:778b081f6a13 | 338 | \param[in] pFileName File name |
dflet | 6:778b081f6a13 | 339 | \param[in] Token Reserved for future use. Use 0 |
dflet | 6:778b081f6a13 | 340 | \param[out] pFsFileInfo Returns the File's Information: flags,file size, allocated size and Tokens |
dflet | 6:778b081f6a13 | 341 | |
dflet | 6:778b081f6a13 | 342 | \return On success, zero is returned. On error, an error code is returned |
dflet | 6:778b081f6a13 | 343 | |
dflet | 6:778b081f6a13 | 344 | \sa sl_FsOpen |
dflet | 6:778b081f6a13 | 345 | \note belongs to \ref basic_api |
dflet | 6:778b081f6a13 | 346 | \warning |
dflet | 6:778b081f6a13 | 347 | \par Example: |
dflet | 6:778b081f6a13 | 348 | \code |
dflet | 6:778b081f6a13 | 349 | Status = sl_FsGetInfo("FileName.html",0,&FsFileInfo); |
dflet | 6:778b081f6a13 | 350 | \endcode |
dflet | 6:778b081f6a13 | 351 | */ |
dflet | 6:778b081f6a13 | 352 | #if _SL_INCLUDE_FUNC(sl_FsGetInfo) |
dflet | 6:778b081f6a13 | 353 | int16_t sl_FsGetInfo(const uint8_t *pFileName, const uint32_t Token,SlFsFileInfo_t* pFsFileInfo); |
dflet | 6:778b081f6a13 | 354 | #endif |
dflet | 6:778b081f6a13 | 355 | |
dflet | 6:778b081f6a13 | 356 | /*! |
dflet | 6:778b081f6a13 | 357 | \brief Delete specific file from a storage or all files from a storage (format) |
dflet | 6:778b081f6a13 | 358 | |
dflet | 6:778b081f6a13 | 359 | \param[in] pFileName File Name |
dflet | 6:778b081f6a13 | 360 | \param[in] Token Reserved for future use. Use 0 |
dflet | 6:778b081f6a13 | 361 | \return On success, zero is returned. On error, an error code is returned |
dflet | 6:778b081f6a13 | 362 | |
dflet | 6:778b081f6a13 | 363 | \sa |
dflet | 6:778b081f6a13 | 364 | \note belongs to \ref basic_api |
dflet | 6:778b081f6a13 | 365 | \warning |
dflet | 6:778b081f6a13 | 366 | \par Example: |
dflet | 6:778b081f6a13 | 367 | \code |
dflet | 6:778b081f6a13 | 368 | Status = sl_FsDel("FileName.html",0); |
dflet | 6:778b081f6a13 | 369 | \endcode |
dflet | 6:778b081f6a13 | 370 | */ |
dflet | 6:778b081f6a13 | 371 | #if _SL_INCLUDE_FUNC(sl_FsDel) |
dflet | 6:778b081f6a13 | 372 | int16_t sl_FsDel(const uint8_t *pFileName, const uint32_t Token); |
dflet | 6:778b081f6a13 | 373 | #endif |
dflet | 6:778b081f6a13 | 374 | |
dflet | 6:778b081f6a13 | 375 | private: |
dflet | 6:778b081f6a13 | 376 | |
dflet | 6:778b081f6a13 | 377 | cc3100_driver &_driver; |
dflet | 6:778b081f6a13 | 378 | |
dflet | 6:778b081f6a13 | 379 | };//class |
dflet | 6:778b081f6a13 | 380 | |
dflet | 6:778b081f6a13 | 381 | }//namespace mbed_cc3100 |
dflet | 6:778b081f6a13 | 382 | |
dflet | 6:778b081f6a13 | 383 | /*! |
dflet | 6:778b081f6a13 | 384 | |
dflet | 6:778b081f6a13 | 385 | Close the Doxygen group. |
dflet | 6:778b081f6a13 | 386 | @} |
dflet | 6:778b081f6a13 | 387 | |
dflet | 6:778b081f6a13 | 388 | */ |
dflet | 6:778b081f6a13 | 389 | |
dflet | 6:778b081f6a13 | 390 | #endif /* __FS_H__ */ |
dflet | 6:778b081f6a13 | 391 | |
dflet | 6:778b081f6a13 | 392 |