cc3100_Socket_Wifi_Server with Ethernet Interface not working
Dependencies: EthernetInterface mbed-rtos mbed
Fork of cc3100_Test_Demo by
simplelink/cc3100_fs.cpp@0:e89ba455dbcf, 2015-02-10 (annotated)
- Committer:
- dflet
- Date:
- Tue Feb 10 12:09:29 2015 +0000
- Revision:
- 0:e89ba455dbcf
For test only! Not much has been tested, but the 2 demo apps run ok. Alot more work needs to be done!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dflet | 0:e89ba455dbcf | 1 | /* |
dflet | 0:e89ba455dbcf | 2 | * fs.c - CC31xx/CC32xx Host Driver Implementation |
dflet | 0:e89ba455dbcf | 3 | * |
dflet | 0:e89ba455dbcf | 4 | * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ |
dflet | 0:e89ba455dbcf | 5 | * |
dflet | 0:e89ba455dbcf | 6 | * |
dflet | 0:e89ba455dbcf | 7 | * Redistribution and use in source and binary forms, with or without |
dflet | 0:e89ba455dbcf | 8 | * modification, are permitted provided that the following conditions |
dflet | 0:e89ba455dbcf | 9 | * are met: |
dflet | 0:e89ba455dbcf | 10 | * |
dflet | 0:e89ba455dbcf | 11 | * Redistributions of source code must retain the above copyright |
dflet | 0:e89ba455dbcf | 12 | * notice, this list of conditions and the following disclaimer. |
dflet | 0:e89ba455dbcf | 13 | * |
dflet | 0:e89ba455dbcf | 14 | * Redistributions in binary form must reproduce the above copyright |
dflet | 0:e89ba455dbcf | 15 | * notice, this list of conditions and the following disclaimer in the |
dflet | 0:e89ba455dbcf | 16 | * documentation and/or other materials provided with the |
dflet | 0:e89ba455dbcf | 17 | * distribution. |
dflet | 0:e89ba455dbcf | 18 | * |
dflet | 0:e89ba455dbcf | 19 | * Neither the name of Texas Instruments Incorporated nor the names of |
dflet | 0:e89ba455dbcf | 20 | * its contributors may be used to endorse or promote products derived |
dflet | 0:e89ba455dbcf | 21 | * from this software without specific prior written permission. |
dflet | 0:e89ba455dbcf | 22 | * |
dflet | 0:e89ba455dbcf | 23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
dflet | 0:e89ba455dbcf | 24 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
dflet | 0:e89ba455dbcf | 25 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
dflet | 0:e89ba455dbcf | 26 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
dflet | 0:e89ba455dbcf | 27 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
dflet | 0:e89ba455dbcf | 28 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
dflet | 0:e89ba455dbcf | 29 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
dflet | 0:e89ba455dbcf | 30 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
dflet | 0:e89ba455dbcf | 31 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
dflet | 0:e89ba455dbcf | 32 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
dflet | 0:e89ba455dbcf | 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
dflet | 0:e89ba455dbcf | 34 | * |
dflet | 0:e89ba455dbcf | 35 | */ |
dflet | 0:e89ba455dbcf | 36 | |
dflet | 0:e89ba455dbcf | 37 | |
dflet | 0:e89ba455dbcf | 38 | |
dflet | 0:e89ba455dbcf | 39 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 40 | /* Include files */ |
dflet | 0:e89ba455dbcf | 41 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 42 | #include "cc3100_simplelink.h" |
dflet | 0:e89ba455dbcf | 43 | #include "cc3100_protocol.h" |
dflet | 0:e89ba455dbcf | 44 | #include "cc3100_driver.h" |
dflet | 0:e89ba455dbcf | 45 | |
dflet | 0:e89ba455dbcf | 46 | #include "cc3100_fs.h" |
dflet | 0:e89ba455dbcf | 47 | |
dflet | 0:e89ba455dbcf | 48 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 49 | /* Macro declarations */ |
dflet | 0:e89ba455dbcf | 50 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 51 | #define sl_min(a,b) (((a) < (b)) ? (a) : (b)) |
dflet | 0:e89ba455dbcf | 52 | #define MAX_NVMEM_CHUNK_SIZE 1460 |
dflet | 0:e89ba455dbcf | 53 | |
dflet | 0:e89ba455dbcf | 54 | namespace mbed_cc3100 { |
dflet | 0:e89ba455dbcf | 55 | |
dflet | 0:e89ba455dbcf | 56 | cc3100_fs::cc3100_fs(cc3100_driver &driver) |
dflet | 0:e89ba455dbcf | 57 | : _driver(driver) |
dflet | 0:e89ba455dbcf | 58 | { |
dflet | 0:e89ba455dbcf | 59 | |
dflet | 0:e89ba455dbcf | 60 | } |
dflet | 0:e89ba455dbcf | 61 | |
dflet | 0:e89ba455dbcf | 62 | cc3100_fs::~cc3100_fs() |
dflet | 0:e89ba455dbcf | 63 | { |
dflet | 0:e89ba455dbcf | 64 | |
dflet | 0:e89ba455dbcf | 65 | } |
dflet | 0:e89ba455dbcf | 66 | |
dflet | 0:e89ba455dbcf | 67 | |
dflet | 0:e89ba455dbcf | 68 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 69 | /* Internal functions */ |
dflet | 0:e89ba455dbcf | 70 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 71 | |
dflet | 0:e89ba455dbcf | 72 | |
dflet | 0:e89ba455dbcf | 73 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 74 | /* _sl_Strlen */ |
dflet | 0:e89ba455dbcf | 75 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 76 | uint16_t cc3100_fs::_sl_Strlen(const uint8_t *buffer) |
dflet | 0:e89ba455dbcf | 77 | { |
dflet | 0:e89ba455dbcf | 78 | uint16_t len = 0; |
dflet | 0:e89ba455dbcf | 79 | if( buffer != NULL ) { |
dflet | 0:e89ba455dbcf | 80 | while(*buffer++) len++; |
dflet | 0:e89ba455dbcf | 81 | } |
dflet | 0:e89ba455dbcf | 82 | return len; |
dflet | 0:e89ba455dbcf | 83 | } |
dflet | 0:e89ba455dbcf | 84 | |
dflet | 0:e89ba455dbcf | 85 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 86 | /* _sl_GetCreateFsMode */ |
dflet | 0:e89ba455dbcf | 87 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 88 | uint32_t cc3100_fs::_sl_GetCreateFsMode(uint32_t maxSizeInBytes,uint32_t accessFlags) |
dflet | 0:e89ba455dbcf | 89 | { |
dflet | 0:e89ba455dbcf | 90 | uint32_t granIdx = 0; |
dflet | 0:e89ba455dbcf | 91 | uint32_t granNum = 0; |
dflet | 0:e89ba455dbcf | 92 | uint32_t granTable[_FS_MAX_MODE_SIZE_GRAN] = {256,1024,4096,16384,65536}; |
dflet | 0:e89ba455dbcf | 93 | for(granIdx= _FS_MODE_SIZE_GRAN_256B ; granIdx< _FS_MAX_MODE_SIZE_GRAN; granIdx++) { |
dflet | 0:e89ba455dbcf | 94 | if( granTable[granIdx]*255 >= maxSizeInBytes ) |
dflet | 0:e89ba455dbcf | 95 | break; |
dflet | 0:e89ba455dbcf | 96 | } |
dflet | 0:e89ba455dbcf | 97 | granNum = maxSizeInBytes/granTable[granIdx]; |
dflet | 0:e89ba455dbcf | 98 | if( maxSizeInBytes % granTable[granIdx] != 0 ) |
dflet | 0:e89ba455dbcf | 99 | granNum++; |
dflet | 0:e89ba455dbcf | 100 | |
dflet | 0:e89ba455dbcf | 101 | return _FS_MODE(_FS_MODE_OPEN_WRITE_CREATE_IF_NOT_EXIST, granIdx, granNum, accessFlags); |
dflet | 0:e89ba455dbcf | 102 | } |
dflet | 0:e89ba455dbcf | 103 | |
dflet | 0:e89ba455dbcf | 104 | |
dflet | 0:e89ba455dbcf | 105 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 106 | /* API functions */ |
dflet | 0:e89ba455dbcf | 107 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 108 | |
dflet | 0:e89ba455dbcf | 109 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 110 | /* sl_FsOpen */ |
dflet | 0:e89ba455dbcf | 111 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 112 | typedef union { |
dflet | 0:e89ba455dbcf | 113 | _FsOpenCommand_t Cmd; |
dflet | 0:e89ba455dbcf | 114 | _FsOpenResponse_t Rsp; |
dflet | 0:e89ba455dbcf | 115 | } _SlFsOpenMsg_u; |
dflet | 0:e89ba455dbcf | 116 | |
dflet | 0:e89ba455dbcf | 117 | const _SlCmdCtrl_t _SlFsOpenCmdCtrl = { |
dflet | 0:e89ba455dbcf | 118 | SL_OPCODE_NVMEM_FILEOPEN, |
dflet | 0:e89ba455dbcf | 119 | sizeof(_FsOpenCommand_t), |
dflet | 0:e89ba455dbcf | 120 | sizeof(_FsOpenResponse_t) |
dflet | 0:e89ba455dbcf | 121 | }; |
dflet | 0:e89ba455dbcf | 122 | |
dflet | 0:e89ba455dbcf | 123 | #if _SL_INCLUDE_FUNC(sl_FsOpen) |
dflet | 0:e89ba455dbcf | 124 | int32_t cc3100_fs::sl_FsOpen(uint8_t *pFileName,uint32_t AccessModeAndMaxSize, uint32_t *pToken,int32_t *pFileHandle) |
dflet | 0:e89ba455dbcf | 125 | { |
dflet | 0:e89ba455dbcf | 126 | _SlReturnVal_t RetVal; |
dflet | 0:e89ba455dbcf | 127 | _SlFsOpenMsg_u Msg; |
dflet | 0:e89ba455dbcf | 128 | _SlCmdExt_t CmdExt; |
dflet | 0:e89ba455dbcf | 129 | |
dflet | 0:e89ba455dbcf | 130 | CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); // add 4: 1 for NULL and the 3 for align |
dflet | 0:e89ba455dbcf | 131 | CmdExt.RxPayloadLen = 0; |
dflet | 0:e89ba455dbcf | 132 | CmdExt.pTxPayload = pFileName; |
dflet | 0:e89ba455dbcf | 133 | CmdExt.pRxPayload = NULL; |
dflet | 0:e89ba455dbcf | 134 | |
dflet | 0:e89ba455dbcf | 135 | Msg.Cmd.Mode = AccessModeAndMaxSize; |
dflet | 0:e89ba455dbcf | 136 | |
dflet | 0:e89ba455dbcf | 137 | if(pToken != NULL) { |
dflet | 0:e89ba455dbcf | 138 | Msg.Cmd.Token = *pToken; |
dflet | 0:e89ba455dbcf | 139 | } else { |
dflet | 0:e89ba455dbcf | 140 | Msg.Cmd.Token = 0; |
dflet | 0:e89ba455dbcf | 141 | } |
dflet | 0:e89ba455dbcf | 142 | |
dflet | 0:e89ba455dbcf | 143 | RetVal = _driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsOpenCmdCtrl, &Msg, &CmdExt); |
dflet | 0:e89ba455dbcf | 144 | *pFileHandle = Msg.Rsp.FileHandle; |
dflet | 0:e89ba455dbcf | 145 | if (pToken != NULL) { |
dflet | 0:e89ba455dbcf | 146 | *pToken = Msg.Rsp.Token; |
dflet | 0:e89ba455dbcf | 147 | } |
dflet | 0:e89ba455dbcf | 148 | |
dflet | 0:e89ba455dbcf | 149 | /* in case of an error, return the erros file handler as an error code */ |
dflet | 0:e89ba455dbcf | 150 | if( *pFileHandle < 0 ) { |
dflet | 0:e89ba455dbcf | 151 | return *pFileHandle; |
dflet | 0:e89ba455dbcf | 152 | } |
dflet | 0:e89ba455dbcf | 153 | return (int32_t)RetVal; |
dflet | 0:e89ba455dbcf | 154 | } |
dflet | 0:e89ba455dbcf | 155 | #endif |
dflet | 0:e89ba455dbcf | 156 | |
dflet | 0:e89ba455dbcf | 157 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 158 | /* sl_FsClose */ |
dflet | 0:e89ba455dbcf | 159 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 160 | typedef union { |
dflet | 0:e89ba455dbcf | 161 | _FsCloseCommand_t Cmd; |
dflet | 0:e89ba455dbcf | 162 | _BasicResponse_t Rsp; |
dflet | 0:e89ba455dbcf | 163 | } _SlFsCloseMsg_u; |
dflet | 0:e89ba455dbcf | 164 | |
dflet | 0:e89ba455dbcf | 165 | const _SlCmdCtrl_t _SlFsCloseCmdCtrl = { |
dflet | 0:e89ba455dbcf | 166 | SL_OPCODE_NVMEM_FILECLOSE, |
dflet | 0:e89ba455dbcf | 167 | sizeof(_FsCloseCommand_t), |
dflet | 0:e89ba455dbcf | 168 | sizeof(_FsCloseResponse_t) |
dflet | 0:e89ba455dbcf | 169 | }; |
dflet | 0:e89ba455dbcf | 170 | |
dflet | 0:e89ba455dbcf | 171 | #if _SL_INCLUDE_FUNC(sl_FsClose) |
dflet | 0:e89ba455dbcf | 172 | int16_t cc3100_fs::sl_FsClose(int32_t FileHdl, uint8_t* pCeritificateFileName,uint8_t* pSignature ,uint32_t SignatureLen) |
dflet | 0:e89ba455dbcf | 173 | { |
dflet | 0:e89ba455dbcf | 174 | _SlFsCloseMsg_u Msg = {0}; |
dflet | 0:e89ba455dbcf | 175 | _SlCmdExt_t ExtCtrl; |
dflet | 0:e89ba455dbcf | 176 | |
dflet | 0:e89ba455dbcf | 177 | Msg.Cmd.FileHandle = FileHdl; |
dflet | 0:e89ba455dbcf | 178 | if( pCeritificateFileName != NULL ) { |
dflet | 0:e89ba455dbcf | 179 | Msg.Cmd.CertificFileNameLength = (_sl_Strlen(pCeritificateFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */ |
dflet | 0:e89ba455dbcf | 180 | } |
dflet | 0:e89ba455dbcf | 181 | Msg.Cmd.SignatureLen = SignatureLen; |
dflet | 0:e89ba455dbcf | 182 | |
dflet | 0:e89ba455dbcf | 183 | ExtCtrl.TxPayloadLen = ((SignatureLen+3) & (~3)); /* align */ |
dflet | 0:e89ba455dbcf | 184 | ExtCtrl.pTxPayload = pSignature; |
dflet | 0:e89ba455dbcf | 185 | ExtCtrl.RxPayloadLen = (uint16_t)Msg.Cmd.CertificFileNameLength; |
dflet | 0:e89ba455dbcf | 186 | ExtCtrl.pRxPayload = pCeritificateFileName; /* Add signature */ |
dflet | 0:e89ba455dbcf | 187 | |
dflet | 0:e89ba455dbcf | 188 | if(ExtCtrl.pRxPayload != NULL && ExtCtrl.RxPayloadLen != 0) { |
dflet | 0:e89ba455dbcf | 189 | g_pCB->RelayFlagsViaRxPayload = TRUE; |
dflet | 0:e89ba455dbcf | 190 | } |
dflet | 0:e89ba455dbcf | 191 | |
dflet | 0:e89ba455dbcf | 192 | VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsCloseCmdCtrl, &Msg, &ExtCtrl)); |
dflet | 0:e89ba455dbcf | 193 | |
dflet | 0:e89ba455dbcf | 194 | return (int16_t)((int16_t)Msg.Rsp.status); |
dflet | 0:e89ba455dbcf | 195 | } |
dflet | 0:e89ba455dbcf | 196 | #endif |
dflet | 0:e89ba455dbcf | 197 | |
dflet | 0:e89ba455dbcf | 198 | |
dflet | 0:e89ba455dbcf | 199 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 200 | /* sl_FsRead */ |
dflet | 0:e89ba455dbcf | 201 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 202 | typedef union { |
dflet | 0:e89ba455dbcf | 203 | _FsReadCommand_t Cmd; |
dflet | 0:e89ba455dbcf | 204 | _FsReadResponse_t Rsp; |
dflet | 0:e89ba455dbcf | 205 | } _SlFsReadMsg_u; |
dflet | 0:e89ba455dbcf | 206 | |
dflet | 0:e89ba455dbcf | 207 | const _SlCmdCtrl_t _SlFsReadCmdCtrl = { |
dflet | 0:e89ba455dbcf | 208 | SL_OPCODE_NVMEM_FILEREADCOMMAND, |
dflet | 0:e89ba455dbcf | 209 | sizeof(_FsReadCommand_t), |
dflet | 0:e89ba455dbcf | 210 | sizeof(_FsReadResponse_t) |
dflet | 0:e89ba455dbcf | 211 | }; |
dflet | 0:e89ba455dbcf | 212 | |
dflet | 0:e89ba455dbcf | 213 | #if _SL_INCLUDE_FUNC(sl_FsRead) |
dflet | 0:e89ba455dbcf | 214 | int32_t cc3100_fs::sl_FsRead(int32_t FileHdl, uint32_t Offset, uint8_t* pData, uint32_t Len) |
dflet | 0:e89ba455dbcf | 215 | { |
dflet | 0:e89ba455dbcf | 216 | _SlFsReadMsg_u Msg; |
dflet | 0:e89ba455dbcf | 217 | _SlCmdExt_t ExtCtrl; |
dflet | 0:e89ba455dbcf | 218 | uint16_t ChunkLen; |
dflet | 0:e89ba455dbcf | 219 | _SlReturnVal_t RetVal =0; |
dflet | 0:e89ba455dbcf | 220 | int32_t RetCount = 0; |
dflet | 0:e89ba455dbcf | 221 | |
dflet | 0:e89ba455dbcf | 222 | ExtCtrl.TxPayloadLen = 0; |
dflet | 0:e89ba455dbcf | 223 | ExtCtrl.pTxPayload = NULL; |
dflet | 0:e89ba455dbcf | 224 | |
dflet | 0:e89ba455dbcf | 225 | ChunkLen = (uint16_t)sl_min(MAX_NVMEM_CHUNK_SIZE,Len); |
dflet | 0:e89ba455dbcf | 226 | ExtCtrl.RxPayloadLen = ChunkLen; |
dflet | 0:e89ba455dbcf | 227 | ExtCtrl.pRxPayload = (uint8_t *)(pData); |
dflet | 0:e89ba455dbcf | 228 | Msg.Cmd.Offset = Offset; |
dflet | 0:e89ba455dbcf | 229 | Msg.Cmd.Len = ChunkLen; |
dflet | 0:e89ba455dbcf | 230 | Msg.Cmd.FileHandle = FileHdl; |
dflet | 0:e89ba455dbcf | 231 | do { |
dflet | 0:e89ba455dbcf | 232 | RetVal = _driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsReadCmdCtrl, &Msg, &ExtCtrl); |
dflet | 0:e89ba455dbcf | 233 | if(SL_OS_RET_CODE_OK == RetVal) { |
dflet | 0:e89ba455dbcf | 234 | if( Msg.Rsp.status < 0) { |
dflet | 0:e89ba455dbcf | 235 | if( RetCount > 0) { |
dflet | 0:e89ba455dbcf | 236 | return RetCount; |
dflet | 0:e89ba455dbcf | 237 | } else { |
dflet | 0:e89ba455dbcf | 238 | return Msg.Rsp.status; |
dflet | 0:e89ba455dbcf | 239 | } |
dflet | 0:e89ba455dbcf | 240 | } |
dflet | 0:e89ba455dbcf | 241 | RetCount += (int32_t)Msg.Rsp.status; |
dflet | 0:e89ba455dbcf | 242 | Len -= ChunkLen; |
dflet | 0:e89ba455dbcf | 243 | Offset += ChunkLen; |
dflet | 0:e89ba455dbcf | 244 | Msg.Cmd.Offset = Offset; |
dflet | 0:e89ba455dbcf | 245 | ExtCtrl.pRxPayload += ChunkLen; |
dflet | 0:e89ba455dbcf | 246 | ChunkLen = (uint16_t)sl_min(MAX_NVMEM_CHUNK_SIZE,Len); |
dflet | 0:e89ba455dbcf | 247 | ExtCtrl.RxPayloadLen = ChunkLen; |
dflet | 0:e89ba455dbcf | 248 | Msg.Cmd.Len = ChunkLen; |
dflet | 0:e89ba455dbcf | 249 | Msg.Cmd.FileHandle = FileHdl; |
dflet | 0:e89ba455dbcf | 250 | } else { |
dflet | 0:e89ba455dbcf | 251 | return RetVal; |
dflet | 0:e89ba455dbcf | 252 | } |
dflet | 0:e89ba455dbcf | 253 | } while(ChunkLen > 0); |
dflet | 0:e89ba455dbcf | 254 | |
dflet | 0:e89ba455dbcf | 255 | return (int32_t)RetCount; |
dflet | 0:e89ba455dbcf | 256 | } |
dflet | 0:e89ba455dbcf | 257 | #endif |
dflet | 0:e89ba455dbcf | 258 | |
dflet | 0:e89ba455dbcf | 259 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 260 | /* sl_FsWrite */ |
dflet | 0:e89ba455dbcf | 261 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 262 | typedef union { |
dflet | 0:e89ba455dbcf | 263 | _FsWriteCommand_t Cmd; |
dflet | 0:e89ba455dbcf | 264 | _FsWriteResponse_t Rsp; |
dflet | 0:e89ba455dbcf | 265 | } _SlFsWriteMsg_u; |
dflet | 0:e89ba455dbcf | 266 | |
dflet | 0:e89ba455dbcf | 267 | const _SlCmdCtrl_t _SlFsWriteCmdCtrl = { |
dflet | 0:e89ba455dbcf | 268 | SL_OPCODE_NVMEM_FILEWRITECOMMAND, |
dflet | 0:e89ba455dbcf | 269 | sizeof(_FsWriteCommand_t), |
dflet | 0:e89ba455dbcf | 270 | sizeof(_FsWriteResponse_t) |
dflet | 0:e89ba455dbcf | 271 | }; |
dflet | 0:e89ba455dbcf | 272 | |
dflet | 0:e89ba455dbcf | 273 | |
dflet | 0:e89ba455dbcf | 274 | #if _SL_INCLUDE_FUNC(sl_FsWrite) |
dflet | 0:e89ba455dbcf | 275 | int32_t cc3100_fs::sl_FsWrite(int32_t FileHdl, uint32_t Offset, uint8_t* pData, uint32_t Len) |
dflet | 0:e89ba455dbcf | 276 | { |
dflet | 0:e89ba455dbcf | 277 | _SlFsWriteMsg_u Msg; |
dflet | 0:e89ba455dbcf | 278 | _SlCmdExt_t ExtCtrl; |
dflet | 0:e89ba455dbcf | 279 | uint16_t ChunkLen; |
dflet | 0:e89ba455dbcf | 280 | _SlReturnVal_t RetVal; |
dflet | 0:e89ba455dbcf | 281 | int32_t RetCount = 0; |
dflet | 0:e89ba455dbcf | 282 | |
dflet | 0:e89ba455dbcf | 283 | ExtCtrl.RxPayloadLen = 0; |
dflet | 0:e89ba455dbcf | 284 | ExtCtrl.pRxPayload = NULL; |
dflet | 0:e89ba455dbcf | 285 | |
dflet | 0:e89ba455dbcf | 286 | ChunkLen = (uint16_t)sl_min(MAX_NVMEM_CHUNK_SIZE,Len); |
dflet | 0:e89ba455dbcf | 287 | ExtCtrl.TxPayloadLen = ChunkLen; |
dflet | 0:e89ba455dbcf | 288 | ExtCtrl.pTxPayload = (uint8_t *)(pData); |
dflet | 0:e89ba455dbcf | 289 | Msg.Cmd.Offset = Offset; |
dflet | 0:e89ba455dbcf | 290 | Msg.Cmd.Len = ChunkLen; |
dflet | 0:e89ba455dbcf | 291 | Msg.Cmd.FileHandle = FileHdl; |
dflet | 0:e89ba455dbcf | 292 | |
dflet | 0:e89ba455dbcf | 293 | do { |
dflet | 0:e89ba455dbcf | 294 | |
dflet | 0:e89ba455dbcf | 295 | RetVal = _driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsWriteCmdCtrl, &Msg, &ExtCtrl); |
dflet | 0:e89ba455dbcf | 296 | if(SL_OS_RET_CODE_OK == RetVal) { |
dflet | 0:e89ba455dbcf | 297 | if( Msg.Rsp.status < 0) { |
dflet | 0:e89ba455dbcf | 298 | if( RetCount > 0) { |
dflet | 0:e89ba455dbcf | 299 | return RetCount; |
dflet | 0:e89ba455dbcf | 300 | } else { |
dflet | 0:e89ba455dbcf | 301 | return Msg.Rsp.status; |
dflet | 0:e89ba455dbcf | 302 | } |
dflet | 0:e89ba455dbcf | 303 | } |
dflet | 0:e89ba455dbcf | 304 | |
dflet | 0:e89ba455dbcf | 305 | RetCount += (int32_t)Msg.Rsp.status; |
dflet | 0:e89ba455dbcf | 306 | Len -= ChunkLen; |
dflet | 0:e89ba455dbcf | 307 | Offset += ChunkLen; |
dflet | 0:e89ba455dbcf | 308 | Msg.Cmd.Offset = Offset; |
dflet | 0:e89ba455dbcf | 309 | ExtCtrl.pTxPayload += ChunkLen; |
dflet | 0:e89ba455dbcf | 310 | ChunkLen = (uint16_t)sl_min(MAX_NVMEM_CHUNK_SIZE,Len); |
dflet | 0:e89ba455dbcf | 311 | ExtCtrl.TxPayloadLen = ChunkLen; |
dflet | 0:e89ba455dbcf | 312 | Msg.Cmd.Len = ChunkLen; |
dflet | 0:e89ba455dbcf | 313 | Msg.Cmd.FileHandle = FileHdl; |
dflet | 0:e89ba455dbcf | 314 | } else { |
dflet | 0:e89ba455dbcf | 315 | return RetVal; |
dflet | 0:e89ba455dbcf | 316 | } |
dflet | 0:e89ba455dbcf | 317 | } while(ChunkLen > 0); |
dflet | 0:e89ba455dbcf | 318 | |
dflet | 0:e89ba455dbcf | 319 | return (int32_t)RetCount; |
dflet | 0:e89ba455dbcf | 320 | } |
dflet | 0:e89ba455dbcf | 321 | #endif |
dflet | 0:e89ba455dbcf | 322 | |
dflet | 0:e89ba455dbcf | 323 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 324 | /* sl_FsGetInfo */ |
dflet | 0:e89ba455dbcf | 325 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 326 | typedef union { |
dflet | 0:e89ba455dbcf | 327 | _FsGetInfoCommand_t Cmd; |
dflet | 0:e89ba455dbcf | 328 | _FsGetInfoResponse_t Rsp; |
dflet | 0:e89ba455dbcf | 329 | } _SlFsGetInfoMsg_u; |
dflet | 0:e89ba455dbcf | 330 | |
dflet | 0:e89ba455dbcf | 331 | const _SlCmdCtrl_t _SlFsGetInfoCmdCtrl = { |
dflet | 0:e89ba455dbcf | 332 | SL_OPCODE_NVMEM_FILEGETINFOCOMMAND, |
dflet | 0:e89ba455dbcf | 333 | sizeof(_FsGetInfoCommand_t), |
dflet | 0:e89ba455dbcf | 334 | sizeof(_FsGetInfoResponse_t) |
dflet | 0:e89ba455dbcf | 335 | }; |
dflet | 0:e89ba455dbcf | 336 | |
dflet | 0:e89ba455dbcf | 337 | #if _SL_INCLUDE_FUNC(sl_FsGetInfo) |
dflet | 0:e89ba455dbcf | 338 | int16_t cc3100_fs::sl_FsGetInfo(uint8_t *pFileName,uint32_t Token,SlFsFileInfo_t* pFsFileInfo) |
dflet | 0:e89ba455dbcf | 339 | { |
dflet | 0:e89ba455dbcf | 340 | _SlFsGetInfoMsg_u Msg; |
dflet | 0:e89ba455dbcf | 341 | _SlCmdExt_t CmdExt; |
dflet | 0:e89ba455dbcf | 342 | |
dflet | 0:e89ba455dbcf | 343 | CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */ |
dflet | 0:e89ba455dbcf | 344 | CmdExt.RxPayloadLen = 0; |
dflet | 0:e89ba455dbcf | 345 | CmdExt.pTxPayload = pFileName; |
dflet | 0:e89ba455dbcf | 346 | CmdExt.pRxPayload = NULL; |
dflet | 0:e89ba455dbcf | 347 | Msg.Cmd.Token = Token; |
dflet | 0:e89ba455dbcf | 348 | |
dflet | 0:e89ba455dbcf | 349 | VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsGetInfoCmdCtrl, &Msg, &CmdExt)); |
dflet | 0:e89ba455dbcf | 350 | |
dflet | 0:e89ba455dbcf | 351 | pFsFileInfo->flags = Msg.Rsp.flags; |
dflet | 0:e89ba455dbcf | 352 | pFsFileInfo->FileLen = Msg.Rsp.FileLen; |
dflet | 0:e89ba455dbcf | 353 | pFsFileInfo->AllocatedLen = Msg.Rsp.AllocatedLen; |
dflet | 0:e89ba455dbcf | 354 | pFsFileInfo->Token[0] = Msg.Rsp.Token[0]; |
dflet | 0:e89ba455dbcf | 355 | pFsFileInfo->Token[1] = Msg.Rsp.Token[1]; |
dflet | 0:e89ba455dbcf | 356 | pFsFileInfo->Token[2] = Msg.Rsp.Token[2]; |
dflet | 0:e89ba455dbcf | 357 | pFsFileInfo->Token[3] = Msg.Rsp.Token[3]; |
dflet | 0:e89ba455dbcf | 358 | return (int16_t)((int16_t)Msg.Rsp.Status); |
dflet | 0:e89ba455dbcf | 359 | } |
dflet | 0:e89ba455dbcf | 360 | #endif |
dflet | 0:e89ba455dbcf | 361 | |
dflet | 0:e89ba455dbcf | 362 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 363 | /* sl_FsDel */ |
dflet | 0:e89ba455dbcf | 364 | /*****************************************************************************/ |
dflet | 0:e89ba455dbcf | 365 | typedef union { |
dflet | 0:e89ba455dbcf | 366 | _FsDeleteCommand_t Cmd; |
dflet | 0:e89ba455dbcf | 367 | _FsDeleteResponse_t Rsp; |
dflet | 0:e89ba455dbcf | 368 | } _SlFsDeleteMsg_u; |
dflet | 0:e89ba455dbcf | 369 | |
dflet | 0:e89ba455dbcf | 370 | const _SlCmdCtrl_t _SlFsDeleteCmdCtrl = { |
dflet | 0:e89ba455dbcf | 371 | SL_OPCODE_NVMEM_FILEDELCOMMAND, |
dflet | 0:e89ba455dbcf | 372 | sizeof(_FsDeleteCommand_t), |
dflet | 0:e89ba455dbcf | 373 | sizeof(_FsDeleteResponse_t) |
dflet | 0:e89ba455dbcf | 374 | }; |
dflet | 0:e89ba455dbcf | 375 | |
dflet | 0:e89ba455dbcf | 376 | #if _SL_INCLUDE_FUNC(sl_FsDel) |
dflet | 0:e89ba455dbcf | 377 | int16_t cc3100_fs::sl_FsDel(uint8_t *pFileName,uint32_t Token) |
dflet | 0:e89ba455dbcf | 378 | { |
dflet | 0:e89ba455dbcf | 379 | _SlFsDeleteMsg_u Msg; |
dflet | 0:e89ba455dbcf | 380 | _SlCmdExt_t CmdExt; |
dflet | 0:e89ba455dbcf | 381 | |
dflet | 0:e89ba455dbcf | 382 | CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */ |
dflet | 0:e89ba455dbcf | 383 | CmdExt.RxPayloadLen = 0; |
dflet | 0:e89ba455dbcf | 384 | CmdExt.pTxPayload = pFileName; |
dflet | 0:e89ba455dbcf | 385 | CmdExt.pRxPayload = NULL; |
dflet | 0:e89ba455dbcf | 386 | Msg.Cmd.Token = Token; |
dflet | 0:e89ba455dbcf | 387 | |
dflet | 0:e89ba455dbcf | 388 | |
dflet | 0:e89ba455dbcf | 389 | VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsDeleteCmdCtrl, &Msg, &CmdExt)); |
dflet | 0:e89ba455dbcf | 390 | |
dflet | 0:e89ba455dbcf | 391 | return (int16_t)((int16_t)Msg.Rsp.status); |
dflet | 0:e89ba455dbcf | 392 | } |
dflet | 0:e89ba455dbcf | 393 | #endif |
dflet | 0:e89ba455dbcf | 394 | |
dflet | 0:e89ba455dbcf | 395 | }//namespace mbed_cc3100 |
dflet | 0:e89ba455dbcf | 396 | |
dflet | 0:e89ba455dbcf | 397 |