Simple LED control project using CC3100 as Access Point and socket

Dependencies:   mbed

Fork of cc3100_Test_Demo by David Fletcher

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?

UserRevisionLine numberNew contents of line
dflet 6:778b081f6a13 1 /*
dflet 6:778b081f6a13 2 * fs.c - 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
dflet 6:778b081f6a13 39 /*****************************************************************************/
dflet 6:778b081f6a13 40 /* Include files */
dflet 6:778b081f6a13 41 /*****************************************************************************/
dflet 6:778b081f6a13 42 #include "cc3100_simplelink.h"
dflet 6:778b081f6a13 43 #include "cc3100_protocol.h"
dflet 6:778b081f6a13 44 #include "cc3100_driver.h"
dflet 6:778b081f6a13 45
dflet 6:778b081f6a13 46 #include "cc3100_fs.h"
dflet 6:778b081f6a13 47
dflet 6:778b081f6a13 48 /*****************************************************************************/
dflet 6:778b081f6a13 49 /* Macro declarations */
dflet 6:778b081f6a13 50 /*****************************************************************************/
dflet 6:778b081f6a13 51 #define sl_min(a,b) (((a) < (b)) ? (a) : (b))
dflet 6:778b081f6a13 52 #define MAX_NVMEM_CHUNK_SIZE 1460
dflet 6:778b081f6a13 53
dflet 6:778b081f6a13 54 namespace mbed_cc3100 {
dflet 6:778b081f6a13 55
dflet 6:778b081f6a13 56 cc3100_fs::cc3100_fs(cc3100_driver &driver)
dflet 6:778b081f6a13 57 : _driver(driver)
dflet 6:778b081f6a13 58 {
dflet 6:778b081f6a13 59
dflet 6:778b081f6a13 60 }
dflet 6:778b081f6a13 61
dflet 6:778b081f6a13 62 cc3100_fs::~cc3100_fs()
dflet 6:778b081f6a13 63 {
dflet 6:778b081f6a13 64
dflet 6:778b081f6a13 65 }
dflet 6:778b081f6a13 66
dflet 6:778b081f6a13 67 #ifndef SL_TINY
dflet 6:778b081f6a13 68 /*****************************************************************************/
dflet 6:778b081f6a13 69 /* Internal functions */
dflet 6:778b081f6a13 70 /*****************************************************************************/
dflet 6:778b081f6a13 71
dflet 6:778b081f6a13 72
dflet 6:778b081f6a13 73 /*****************************************************************************/
dflet 6:778b081f6a13 74 /* _sl_Strlen */
dflet 6:778b081f6a13 75 /*****************************************************************************/
dflet 6:778b081f6a13 76 uint16_t cc3100_fs::_sl_Strlen(const uint8_t *buffer)
dflet 6:778b081f6a13 77 {
dflet 6:778b081f6a13 78 uint16_t len = 0;
dflet 6:778b081f6a13 79 if( buffer != NULL ) {
dflet 6:778b081f6a13 80 while(*buffer++) len++;
dflet 6:778b081f6a13 81 }
dflet 6:778b081f6a13 82 return len;
dflet 6:778b081f6a13 83 }
dflet 6:778b081f6a13 84
dflet 6:778b081f6a13 85 /*****************************************************************************/
dflet 6:778b081f6a13 86 /* _sl_GetCreateFsMode */
dflet 6:778b081f6a13 87 /*****************************************************************************/
dflet 6:778b081f6a13 88 uint32_t cc3100_fs::_sl_GetCreateFsMode(uint32_t maxSizeInBytes,uint32_t accessFlags)
dflet 6:778b081f6a13 89 {
dflet 6:778b081f6a13 90 uint32_t granIdx = 0;
dflet 6:778b081f6a13 91 uint32_t granNum = 0;
dflet 6:778b081f6a13 92 uint32_t granTable[_FS_MAX_MODE_SIZE_GRAN] = {256,1024,4096,16384,65536};
dflet 6:778b081f6a13 93 for(granIdx= _FS_MODE_SIZE_GRAN_256B ; granIdx< _FS_MAX_MODE_SIZE_GRAN; granIdx++) {
dflet 6:778b081f6a13 94 if( granTable[granIdx]*255 >= maxSizeInBytes )
dflet 6:778b081f6a13 95 break;
dflet 6:778b081f6a13 96 }
dflet 6:778b081f6a13 97 granNum = maxSizeInBytes/granTable[granIdx];
dflet 6:778b081f6a13 98 if( maxSizeInBytes % granTable[granIdx] != 0 )
dflet 6:778b081f6a13 99 granNum++;
dflet 6:778b081f6a13 100
dflet 6:778b081f6a13 101 return _FS_MODE(_FS_MODE_OPEN_WRITE_CREATE_IF_NOT_EXIST, granIdx, granNum, accessFlags);
dflet 6:778b081f6a13 102 }
dflet 6:778b081f6a13 103 #endif
dflet 6:778b081f6a13 104
dflet 6:778b081f6a13 105 /*****************************************************************************/
dflet 6:778b081f6a13 106 /* API functions */
dflet 6:778b081f6a13 107 /*****************************************************************************/
dflet 6:778b081f6a13 108
dflet 6:778b081f6a13 109 /*****************************************************************************/
dflet 6:778b081f6a13 110 /* sl_FsOpen */
dflet 6:778b081f6a13 111 /*****************************************************************************/
dflet 6:778b081f6a13 112 typedef union {
dflet 6:778b081f6a13 113 _FsOpenCommand_t Cmd;
dflet 6:778b081f6a13 114 _FsOpenResponse_t Rsp;
dflet 6:778b081f6a13 115 } _SlFsOpenMsg_u;
dflet 6:778b081f6a13 116
dflet 6:778b081f6a13 117 #if _SL_INCLUDE_FUNC(sl_FsOpen)
dflet 6:778b081f6a13 118 const _SlCmdCtrl_t _SlFsOpenCmdCtrl = {
dflet 6:778b081f6a13 119 SL_OPCODE_NVMEM_FILEOPEN,
dflet 6:778b081f6a13 120 sizeof(_FsOpenCommand_t),
dflet 6:778b081f6a13 121 sizeof(_FsOpenResponse_t)
dflet 6:778b081f6a13 122 };
dflet 6:778b081f6a13 123
dflet 6:778b081f6a13 124 int32_t cc3100_fs::sl_FsOpen(const uint8_t *pFileName, const uint32_t AccessModeAndMaxSize, uint32_t *pToken,int32_t *pFileHandle)
dflet 6:778b081f6a13 125 {
dflet 6:778b081f6a13 126 _SlReturnVal_t RetVal;
dflet 6:778b081f6a13 127 _SlFsOpenMsg_u Msg;
dflet 6:778b081f6a13 128 _SlCmdExt_t CmdExt;
dflet 6:778b081f6a13 129
dflet 6:778b081f6a13 130 CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); // add 4: 1 for NULL and the 3 for align
dflet 6:778b081f6a13 131 CmdExt.RxPayloadLen = 0;
dflet 6:778b081f6a13 132 CmdExt.pTxPayload = (uint8_t *)pFileName;
dflet 6:778b081f6a13 133 CmdExt.pRxPayload = NULL;
dflet 6:778b081f6a13 134
dflet 6:778b081f6a13 135 Msg.Cmd.Mode = AccessModeAndMaxSize;
dflet 6:778b081f6a13 136
dflet 6:778b081f6a13 137 if(pToken != NULL) {
dflet 6:778b081f6a13 138 Msg.Cmd.Token = *pToken;
dflet 6:778b081f6a13 139 } else {
dflet 6:778b081f6a13 140 Msg.Cmd.Token = 0;
dflet 6:778b081f6a13 141 }
dflet 6:778b081f6a13 142
dflet 6:778b081f6a13 143 RetVal = _driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsOpenCmdCtrl, &Msg, &CmdExt);
dflet 6:778b081f6a13 144 *pFileHandle = Msg.Rsp.FileHandle;
dflet 6:778b081f6a13 145 if (pToken != NULL) {
dflet 6:778b081f6a13 146 *pToken = Msg.Rsp.Token;
dflet 6:778b081f6a13 147 }
dflet 6:778b081f6a13 148
dflet 6:778b081f6a13 149 /* in case of an error, return the erros file handler as an error code */
dflet 6:778b081f6a13 150 if( *pFileHandle < 0 ) {
dflet 6:778b081f6a13 151 return *pFileHandle;
dflet 6:778b081f6a13 152 }
dflet 6:778b081f6a13 153 return (int32_t)RetVal;
dflet 6:778b081f6a13 154 }
dflet 6:778b081f6a13 155 #endif
dflet 6:778b081f6a13 156
dflet 6:778b081f6a13 157 /*****************************************************************************/
dflet 6:778b081f6a13 158 /* sl_FsClose */
dflet 6:778b081f6a13 159 /*****************************************************************************/
dflet 6:778b081f6a13 160 typedef union {
dflet 6:778b081f6a13 161 _FsCloseCommand_t Cmd;
dflet 6:778b081f6a13 162 _BasicResponse_t Rsp;
dflet 6:778b081f6a13 163 } _SlFsCloseMsg_u;
dflet 6:778b081f6a13 164
dflet 6:778b081f6a13 165 #if _SL_INCLUDE_FUNC(sl_FsClose)
dflet 6:778b081f6a13 166 const _SlCmdCtrl_t _SlFsCloseCmdCtrl = {
dflet 6:778b081f6a13 167 SL_OPCODE_NVMEM_FILECLOSE,
dflet 6:778b081f6a13 168 sizeof(_FsCloseCommand_t),
dflet 6:778b081f6a13 169 sizeof(_FsCloseResponse_t)
dflet 6:778b081f6a13 170 };
dflet 6:778b081f6a13 171
dflet 6:778b081f6a13 172 int16_t cc3100_fs::sl_FsClose(const int32_t FileHdl, const uint8_t* pCeritificateFileName, const uint8_t* pSignature ,const uint32_t SignatureLen)
dflet 6:778b081f6a13 173 {
dflet 6:778b081f6a13 174 _SlFsCloseMsg_u Msg = {0};
dflet 6:778b081f6a13 175 _SlCmdExt_t ExtCtrl;
dflet 6:778b081f6a13 176
dflet 6:778b081f6a13 177 Msg.Cmd.FileHandle = FileHdl;
dflet 6:778b081f6a13 178 if( pCeritificateFileName != NULL ) {
dflet 6:778b081f6a13 179 Msg.Cmd.CertificFileNameLength = (_sl_Strlen(pCeritificateFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */
dflet 6:778b081f6a13 180 }
dflet 6:778b081f6a13 181 Msg.Cmd.SignatureLen = SignatureLen;
dflet 6:778b081f6a13 182
dflet 6:778b081f6a13 183 ExtCtrl.TxPayloadLen = ((SignatureLen+3) & (~3)); /* align */
dflet 6:778b081f6a13 184 ExtCtrl.pTxPayload = (uint8_t*)pSignature;
dflet 6:778b081f6a13 185 ExtCtrl.RxPayloadLen = (int16_t)Msg.Cmd.CertificFileNameLength;
dflet 6:778b081f6a13 186 ExtCtrl.pRxPayload = (uint8_t*)pCeritificateFileName; /* Add signature */
dflet 6:778b081f6a13 187
dflet 6:778b081f6a13 188 if(ExtCtrl.pRxPayload != NULL && ExtCtrl.RxPayloadLen != 0) {
dflet 6:778b081f6a13 189 ExtCtrl.RxPayloadLen = ExtCtrl.RxPayloadLen * (-1);
dflet 6:778b081f6a13 190 }
dflet 6:778b081f6a13 191
dflet 6:778b081f6a13 192 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsCloseCmdCtrl, &Msg, &ExtCtrl));
dflet 6:778b081f6a13 193
dflet 6:778b081f6a13 194 return (int16_t)((int16_t)Msg.Rsp.status);
dflet 6:778b081f6a13 195 }
dflet 6:778b081f6a13 196 #endif
dflet 6:778b081f6a13 197
dflet 6:778b081f6a13 198
dflet 6:778b081f6a13 199 /*****************************************************************************/
dflet 6:778b081f6a13 200 /* sl_FsRead */
dflet 6:778b081f6a13 201 /*****************************************************************************/
dflet 6:778b081f6a13 202 typedef union {
dflet 6:778b081f6a13 203 _FsReadCommand_t Cmd;
dflet 6:778b081f6a13 204 _FsReadResponse_t Rsp;
dflet 6:778b081f6a13 205 } _SlFsReadMsg_u;
dflet 6:778b081f6a13 206
dflet 6:778b081f6a13 207 #if _SL_INCLUDE_FUNC(sl_FsRead)
dflet 6:778b081f6a13 208 const _SlCmdCtrl_t _SlFsReadCmdCtrl = {
dflet 6:778b081f6a13 209 SL_OPCODE_NVMEM_FILEREADCOMMAND,
dflet 6:778b081f6a13 210 sizeof(_FsReadCommand_t),
dflet 6:778b081f6a13 211 sizeof(_FsReadResponse_t)
dflet 6:778b081f6a13 212 };
dflet 6:778b081f6a13 213
dflet 6:778b081f6a13 214 int32_t cc3100_fs::sl_FsRead(const int32_t FileHdl, uint32_t Offset, uint8_t* pData, uint32_t Len)
dflet 6:778b081f6a13 215 {
dflet 6:778b081f6a13 216 _SlFsReadMsg_u Msg;
dflet 6:778b081f6a13 217 _SlCmdExt_t ExtCtrl;
dflet 6:778b081f6a13 218 uint16_t ChunkLen;
dflet 6:778b081f6a13 219 _SlReturnVal_t RetVal =0;
dflet 6:778b081f6a13 220 int32_t RetCount = 0;
dflet 6:778b081f6a13 221
dflet 6:778b081f6a13 222 ExtCtrl.TxPayloadLen = 0;
dflet 6:778b081f6a13 223 ExtCtrl.pTxPayload = NULL;
dflet 6:778b081f6a13 224
dflet 6:778b081f6a13 225 ChunkLen = (uint16_t)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
dflet 6:778b081f6a13 226 ExtCtrl.RxPayloadLen = ChunkLen;
dflet 6:778b081f6a13 227 ExtCtrl.pRxPayload = (uint8_t *)(pData);
dflet 6:778b081f6a13 228 Msg.Cmd.Offset = Offset;
dflet 6:778b081f6a13 229 Msg.Cmd.Len = ChunkLen;
dflet 6:778b081f6a13 230 Msg.Cmd.FileHandle = FileHdl;
dflet 6:778b081f6a13 231 do {
dflet 6:778b081f6a13 232 RetVal = _driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsReadCmdCtrl, &Msg, &ExtCtrl);
dflet 6:778b081f6a13 233 if(SL_OS_RET_CODE_OK == RetVal) {
dflet 6:778b081f6a13 234 if( Msg.Rsp.status < 0) {
dflet 6:778b081f6a13 235 if( RetCount > 0) {
dflet 6:778b081f6a13 236 return RetCount;
dflet 6:778b081f6a13 237 } else {
dflet 6:778b081f6a13 238 return Msg.Rsp.status;
dflet 6:778b081f6a13 239 }
dflet 6:778b081f6a13 240 }
dflet 6:778b081f6a13 241 RetCount += (int32_t)Msg.Rsp.status;
dflet 6:778b081f6a13 242 Len -= ChunkLen;
dflet 6:778b081f6a13 243 Offset += ChunkLen;
dflet 6:778b081f6a13 244 Msg.Cmd.Offset = Offset;
dflet 6:778b081f6a13 245 ExtCtrl.pRxPayload += ChunkLen;
dflet 6:778b081f6a13 246 ChunkLen = (uint16_t)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
dflet 6:778b081f6a13 247 ExtCtrl.RxPayloadLen = ChunkLen;
dflet 6:778b081f6a13 248 Msg.Cmd.Len = ChunkLen;
dflet 6:778b081f6a13 249 Msg.Cmd.FileHandle = FileHdl;
dflet 6:778b081f6a13 250 } else {
dflet 6:778b081f6a13 251 return RetVal;
dflet 6:778b081f6a13 252 }
dflet 6:778b081f6a13 253 } while(ChunkLen > 0);
dflet 6:778b081f6a13 254
dflet 6:778b081f6a13 255 return (int32_t)RetCount;
dflet 6:778b081f6a13 256 }
dflet 6:778b081f6a13 257 #endif
dflet 6:778b081f6a13 258
dflet 6:778b081f6a13 259 /*****************************************************************************/
dflet 6:778b081f6a13 260 /* sl_FsWrite */
dflet 6:778b081f6a13 261 /*****************************************************************************/
dflet 6:778b081f6a13 262 typedef union {
dflet 6:778b081f6a13 263 _FsWriteCommand_t Cmd;
dflet 6:778b081f6a13 264 _FsWriteResponse_t Rsp;
dflet 6:778b081f6a13 265 } _SlFsWriteMsg_u;
dflet 6:778b081f6a13 266
dflet 6:778b081f6a13 267 #if _SL_INCLUDE_FUNC(sl_FsWrite)
dflet 6:778b081f6a13 268 const _SlCmdCtrl_t _SlFsWriteCmdCtrl = {
dflet 6:778b081f6a13 269 SL_OPCODE_NVMEM_FILEWRITECOMMAND,
dflet 6:778b081f6a13 270 sizeof(_FsWriteCommand_t),
dflet 6:778b081f6a13 271 sizeof(_FsWriteResponse_t)
dflet 6:778b081f6a13 272 };
dflet 6:778b081f6a13 273
dflet 6:778b081f6a13 274 int32_t cc3100_fs::sl_FsWrite(const int32_t FileHdl, uint32_t Offset, uint8_t* pData, uint32_t Len)
dflet 6:778b081f6a13 275 {
dflet 6:778b081f6a13 276 _SlFsWriteMsg_u Msg;
dflet 6:778b081f6a13 277 _SlCmdExt_t ExtCtrl;
dflet 6:778b081f6a13 278 uint16_t ChunkLen;
dflet 6:778b081f6a13 279 _SlReturnVal_t RetVal;
dflet 6:778b081f6a13 280 int32_t RetCount = 0;
dflet 6:778b081f6a13 281
dflet 6:778b081f6a13 282 ExtCtrl.RxPayloadLen = 0;
dflet 6:778b081f6a13 283 ExtCtrl.pRxPayload = NULL;
dflet 6:778b081f6a13 284
dflet 6:778b081f6a13 285 ChunkLen = (uint16_t)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
dflet 6:778b081f6a13 286 ExtCtrl.TxPayloadLen = ChunkLen;
dflet 6:778b081f6a13 287 ExtCtrl.pTxPayload = (uint8_t *)(pData);
dflet 6:778b081f6a13 288 Msg.Cmd.Offset = Offset;
dflet 6:778b081f6a13 289 Msg.Cmd.Len = ChunkLen;
dflet 6:778b081f6a13 290 Msg.Cmd.FileHandle = FileHdl;
dflet 6:778b081f6a13 291
dflet 6:778b081f6a13 292 do {
dflet 6:778b081f6a13 293
dflet 6:778b081f6a13 294 RetVal = _driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsWriteCmdCtrl, &Msg, &ExtCtrl);
dflet 6:778b081f6a13 295 if(SL_OS_RET_CODE_OK == RetVal) {
dflet 6:778b081f6a13 296 if( Msg.Rsp.status < 0) {
dflet 6:778b081f6a13 297 if( RetCount > 0) {
dflet 6:778b081f6a13 298 return RetCount;
dflet 6:778b081f6a13 299 } else {
dflet 6:778b081f6a13 300 return Msg.Rsp.status;
dflet 6:778b081f6a13 301 }
dflet 6:778b081f6a13 302 }
dflet 6:778b081f6a13 303
dflet 6:778b081f6a13 304 RetCount += (int32_t)Msg.Rsp.status;
dflet 6:778b081f6a13 305 Len -= ChunkLen;
dflet 6:778b081f6a13 306 Offset += ChunkLen;
dflet 6:778b081f6a13 307 Msg.Cmd.Offset = Offset;
dflet 6:778b081f6a13 308 ExtCtrl.pTxPayload += ChunkLen;
dflet 6:778b081f6a13 309 ChunkLen = (uint16_t)sl_min(MAX_NVMEM_CHUNK_SIZE,Len);
dflet 6:778b081f6a13 310 ExtCtrl.TxPayloadLen = ChunkLen;
dflet 6:778b081f6a13 311 Msg.Cmd.Len = ChunkLen;
dflet 6:778b081f6a13 312 Msg.Cmd.FileHandle = FileHdl;
dflet 6:778b081f6a13 313 } else {
dflet 6:778b081f6a13 314 return RetVal;
dflet 6:778b081f6a13 315 }
dflet 6:778b081f6a13 316 } while(ChunkLen > 0);
dflet 6:778b081f6a13 317
dflet 6:778b081f6a13 318 return (int32_t)RetCount;
dflet 6:778b081f6a13 319 }
dflet 6:778b081f6a13 320 #endif
dflet 6:778b081f6a13 321
dflet 6:778b081f6a13 322 /*****************************************************************************/
dflet 6:778b081f6a13 323 /* sl_FsGetInfo */
dflet 6:778b081f6a13 324 /*****************************************************************************/
dflet 6:778b081f6a13 325 typedef union {
dflet 6:778b081f6a13 326 _FsGetInfoCommand_t Cmd;
dflet 6:778b081f6a13 327 _FsGetInfoResponse_t Rsp;
dflet 6:778b081f6a13 328 } _SlFsGetInfoMsg_u;
dflet 6:778b081f6a13 329
dflet 6:778b081f6a13 330 #if _SL_INCLUDE_FUNC(sl_FsGetInfo)
dflet 6:778b081f6a13 331 const _SlCmdCtrl_t _SlFsGetInfoCmdCtrl = {
dflet 6:778b081f6a13 332 SL_OPCODE_NVMEM_FILEGETINFOCOMMAND,
dflet 6:778b081f6a13 333 sizeof(_FsGetInfoCommand_t),
dflet 6:778b081f6a13 334 sizeof(_FsGetInfoResponse_t)
dflet 6:778b081f6a13 335 };
dflet 6:778b081f6a13 336
dflet 6:778b081f6a13 337 int16_t cc3100_fs::sl_FsGetInfo(const uint8_t *pFileName, const uint32_t Token,SlFsFileInfo_t* pFsFileInfo)
dflet 6:778b081f6a13 338 {
dflet 6:778b081f6a13 339 _SlFsGetInfoMsg_u Msg;
dflet 6:778b081f6a13 340 _SlCmdExt_t CmdExt;
dflet 6:778b081f6a13 341
dflet 6:778b081f6a13 342 CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */
dflet 6:778b081f6a13 343 CmdExt.RxPayloadLen = 0;
dflet 6:778b081f6a13 344 CmdExt.pTxPayload = (uint8_t *)pFileName;
dflet 6:778b081f6a13 345 CmdExt.pRxPayload = NULL;
dflet 6:778b081f6a13 346 Msg.Cmd.Token = Token;
dflet 6:778b081f6a13 347
dflet 6:778b081f6a13 348 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsGetInfoCmdCtrl, &Msg, &CmdExt));
dflet 6:778b081f6a13 349
dflet 6:778b081f6a13 350 pFsFileInfo->flags = Msg.Rsp.flags;
dflet 6:778b081f6a13 351 pFsFileInfo->FileLen = Msg.Rsp.FileLen;
dflet 6:778b081f6a13 352 pFsFileInfo->AllocatedLen = Msg.Rsp.AllocatedLen;
dflet 6:778b081f6a13 353 pFsFileInfo->Token[0] = Msg.Rsp.Token[0];
dflet 6:778b081f6a13 354 pFsFileInfo->Token[1] = Msg.Rsp.Token[1];
dflet 6:778b081f6a13 355 pFsFileInfo->Token[2] = Msg.Rsp.Token[2];
dflet 6:778b081f6a13 356 pFsFileInfo->Token[3] = Msg.Rsp.Token[3];
dflet 6:778b081f6a13 357 return (int16_t)((int16_t)Msg.Rsp.Status);
dflet 6:778b081f6a13 358 }
dflet 6:778b081f6a13 359 #endif
dflet 6:778b081f6a13 360
dflet 6:778b081f6a13 361 /*****************************************************************************/
dflet 6:778b081f6a13 362 /* sl_FsDel */
dflet 6:778b081f6a13 363 /*****************************************************************************/
dflet 6:778b081f6a13 364 typedef union {
dflet 6:778b081f6a13 365 _FsDeleteCommand_t Cmd;
dflet 6:778b081f6a13 366 _FsDeleteResponse_t Rsp;
dflet 6:778b081f6a13 367 } _SlFsDeleteMsg_u;
dflet 6:778b081f6a13 368
dflet 6:778b081f6a13 369 #if _SL_INCLUDE_FUNC(sl_FsDel)
dflet 6:778b081f6a13 370 const _SlCmdCtrl_t _SlFsDeleteCmdCtrl = {
dflet 6:778b081f6a13 371 SL_OPCODE_NVMEM_FILEDELCOMMAND,
dflet 6:778b081f6a13 372 sizeof(_FsDeleteCommand_t),
dflet 6:778b081f6a13 373 sizeof(_FsDeleteResponse_t)
dflet 6:778b081f6a13 374 };
dflet 6:778b081f6a13 375
dflet 6:778b081f6a13 376 int16_t cc3100_fs::sl_FsDel(const uint8_t *pFileName, const uint32_t Token)
dflet 6:778b081f6a13 377 {
dflet 6:778b081f6a13 378 _SlFsDeleteMsg_u Msg;
dflet 6:778b081f6a13 379 _SlCmdExt_t CmdExt;
dflet 6:778b081f6a13 380
dflet 6:778b081f6a13 381 CmdExt.TxPayloadLen = (_sl_Strlen(pFileName)+4) & (~3); /* add 4: 1 for NULL and the 3 for align */
dflet 6:778b081f6a13 382 CmdExt.RxPayloadLen = 0;
dflet 6:778b081f6a13 383 CmdExt.pTxPayload = (uint8_t *)pFileName;
dflet 6:778b081f6a13 384 CmdExt.pRxPayload = NULL;
dflet 6:778b081f6a13 385 Msg.Cmd.Token = Token;
dflet 6:778b081f6a13 386
dflet 6:778b081f6a13 387
dflet 6:778b081f6a13 388 VERIFY_RET_OK(_driver._SlDrvCmdOp((_SlCmdCtrl_t *)&_SlFsDeleteCmdCtrl, &Msg, &CmdExt));
dflet 6:778b081f6a13 389
dflet 6:778b081f6a13 390 return (int16_t)((int16_t)Msg.Rsp.status);
dflet 6:778b081f6a13 391 }
dflet 6:778b081f6a13 392 #endif
dflet 6:778b081f6a13 393
dflet 6:778b081f6a13 394 }//namespace mbed_cc3100
dflet 6:778b081f6a13 395
dflet 6:778b081f6a13 396