Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

Committer:
dflet
Date:
Thu Sep 03 14:02:37 2015 +0000
Revision:
3:a8c249046181
SPI Mode change 1 to 0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 3:a8c249046181 1 /*
dflet 3:a8c249046181 2 * nonos.c - CC31xx/CC32xx Host Driver Implementation
dflet 3:a8c249046181 3 *
dflet 3:a8c249046181 4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
dflet 3:a8c249046181 5 *
dflet 3:a8c249046181 6 *
dflet 3:a8c249046181 7 * Redistribution and use in source and binary forms, with or without
dflet 3:a8c249046181 8 * modification, are permitted provided that the following conditions
dflet 3:a8c249046181 9 * are met:
dflet 3:a8c249046181 10 *
dflet 3:a8c249046181 11 * Redistributions of source code must retain the above copyright
dflet 3:a8c249046181 12 * notice, this list of conditions and the following disclaimer.
dflet 3:a8c249046181 13 *
dflet 3:a8c249046181 14 * Redistributions in binary form must reproduce the above copyright
dflet 3:a8c249046181 15 * notice, this list of conditions and the following disclaimer in the
dflet 3:a8c249046181 16 * documentation and/or other materials provided with the
dflet 3:a8c249046181 17 * distribution.
dflet 3:a8c249046181 18 *
dflet 3:a8c249046181 19 * Neither the name of Texas Instruments Incorporated nor the names of
dflet 3:a8c249046181 20 * its contributors may be used to endorse or promote products derived
dflet 3:a8c249046181 21 * from this software without specific prior written permission.
dflet 3:a8c249046181 22 *
dflet 3:a8c249046181 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 3:a8c249046181 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 3:a8c249046181 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 3:a8c249046181 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 3:a8c249046181 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 3:a8c249046181 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 3:a8c249046181 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 3:a8c249046181 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 3:a8c249046181 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 3:a8c249046181 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 3:a8c249046181 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 3:a8c249046181 34 *
dflet 3:a8c249046181 35 */
dflet 3:a8c249046181 36
dflet 3:a8c249046181 37
dflet 3:a8c249046181 38
dflet 3:a8c249046181 39 /*****************************************************************************/
dflet 3:a8c249046181 40 /* Include files */
dflet 3:a8c249046181 41 /*****************************************************************************/
dflet 3:a8c249046181 42
dflet 3:a8c249046181 43 #ifndef SL_PLATFORM_MULTI_THREADED
dflet 3:a8c249046181 44
dflet 3:a8c249046181 45 #include "cc3100_simplelink.h"
dflet 3:a8c249046181 46 #include "cc3100_nonos.h"
dflet 3:a8c249046181 47 #include "fPtr_func.h"
dflet 3:a8c249046181 48
dflet 3:a8c249046181 49 namespace mbed_cc3100 {
dflet 3:a8c249046181 50
dflet 3:a8c249046181 51 #ifndef SL_TINY_EXT
dflet 3:a8c249046181 52 #define NONOS_MAX_SPAWN_ENTRIES 5
dflet 3:a8c249046181 53 #else
dflet 3:a8c249046181 54 #define NONOS_MAX_SPAWN_ENTRIES 1
dflet 3:a8c249046181 55 #endif
dflet 3:a8c249046181 56
dflet 3:a8c249046181 57 cc3100_nonos::cc3100_nonos(cc3100_driver &driver)
dflet 3:a8c249046181 58 : _driver(driver)
dflet 3:a8c249046181 59 {
dflet 3:a8c249046181 60
dflet 3:a8c249046181 61 }
dflet 3:a8c249046181 62
dflet 3:a8c249046181 63 cc3100_nonos::~cc3100_nonos()
dflet 3:a8c249046181 64 {
dflet 3:a8c249046181 65
dflet 3:a8c249046181 66 }
dflet 3:a8c249046181 67
dflet 3:a8c249046181 68 typedef struct {
dflet 3:a8c249046181 69 _SlSpawnEntryFunc_t pEntry;
dflet 3:a8c249046181 70 void* pValue;
dflet 3:a8c249046181 71 } _SlNonOsSpawnEntry_t;
dflet 3:a8c249046181 72
dflet 3:a8c249046181 73 typedef struct {
dflet 3:a8c249046181 74 _SlNonOsSpawnEntry_t SpawnEntries[NONOS_MAX_SPAWN_ENTRIES];
dflet 3:a8c249046181 75 } _SlNonOsCB_t;
dflet 3:a8c249046181 76
dflet 3:a8c249046181 77 _SlNonOsCB_t g_SlNonOsCB;
dflet 3:a8c249046181 78
dflet 3:a8c249046181 79
dflet 3:a8c249046181 80 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsSemSet(_SlNonOsSemObj_t* pSemObj , _SlNonOsSemObj_t Value)
dflet 3:a8c249046181 81 {
dflet 3:a8c249046181 82 *pSemObj = Value;
dflet 3:a8c249046181 83 return NONOS_RET_OK;
dflet 3:a8c249046181 84 }
dflet 3:a8c249046181 85
dflet 3:a8c249046181 86 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsSemGet(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout)
dflet 3:a8c249046181 87 {
dflet 3:a8c249046181 88 #ifdef _SlSyncWaitLoopCallback
dflet 3:a8c249046181 89 _SlNonOsTime_t timeOutRequest = Timeout;
dflet 3:a8c249046181 90 #endif
dflet 3:a8c249046181 91
dflet 3:a8c249046181 92 while (Timeout > 0) {
dflet 3:a8c249046181 93 if (WaitValue == *pSyncObj) {
dflet 3:a8c249046181 94 *pSyncObj = SetValue;
dflet 3:a8c249046181 95 break;
dflet 3:a8c249046181 96 }
dflet 3:a8c249046181 97 if (Timeout != NONOS_WAIT_FOREVER) {
dflet 3:a8c249046181 98 Timeout--;
dflet 3:a8c249046181 99 }
dflet 3:a8c249046181 100 _SlNonOsMainLoopTask();
dflet 3:a8c249046181 101
dflet 3:a8c249046181 102 #ifdef _SlSyncWaitLoopCallback
dflet 3:a8c249046181 103 if( (__NON_OS_SYNC_OBJ_SIGNAL_VALUE == WaitValue) && (timeOutRequest != NONOS_NO_WAIT) ) {
dflet 3:a8c249046181 104 if (WaitValue == *pSyncObj) {
dflet 3:a8c249046181 105 *pSyncObj = SetValue;
dflet 3:a8c249046181 106 break;
dflet 3:a8c249046181 107 }
dflet 3:a8c249046181 108 _SlSyncWaitLoopCallback();
dflet 3:a8c249046181 109 }
dflet 3:a8c249046181 110 #endif
dflet 3:a8c249046181 111
dflet 3:a8c249046181 112 }
dflet 3:a8c249046181 113
dflet 3:a8c249046181 114 if (0 == Timeout) {
dflet 3:a8c249046181 115 return NONOS_RET_ERR;
dflet 3:a8c249046181 116 } else {
dflet 3:a8c249046181 117 return NONOS_RET_OK;
dflet 3:a8c249046181 118 }
dflet 3:a8c249046181 119 }
dflet 3:a8c249046181 120
dflet 3:a8c249046181 121
dflet 3:a8c249046181 122 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , uint32_t flags)
dflet 3:a8c249046181 123 {
dflet 3:a8c249046181 124 int8_t i = 0;
dflet 3:a8c249046181 125
dflet 3:a8c249046181 126 #ifndef SL_TINY_EXT
dflet 3:a8c249046181 127 for (i=0 ; i<NONOS_MAX_SPAWN_ENTRIES ; i++)
dflet 3:a8c249046181 128 #endif
dflet 3:a8c249046181 129 {
dflet 3:a8c249046181 130 _SlNonOsSpawnEntry_t* pE = &g_SlNonOsCB.SpawnEntries[i];
dflet 3:a8c249046181 131
dflet 3:a8c249046181 132 if (NULL == pE->pEntry)
dflet 3:a8c249046181 133 {
dflet 3:a8c249046181 134 pE->pValue = pValue;
dflet 3:a8c249046181 135 pE->pEntry = pEntry;
dflet 3:a8c249046181 136 #ifndef SL_TINY_EXT
dflet 3:a8c249046181 137 break;
dflet 3:a8c249046181 138 #endif
dflet 3:a8c249046181 139 }
dflet 3:a8c249046181 140 }
dflet 3:a8c249046181 141
dflet 3:a8c249046181 142
dflet 3:a8c249046181 143 return NONOS_RET_OK;
dflet 3:a8c249046181 144 }
dflet 3:a8c249046181 145
dflet 3:a8c249046181 146 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsMainLoopTask(void)
dflet 3:a8c249046181 147 {
dflet 3:a8c249046181 148 int8_t i = 0;
dflet 3:a8c249046181 149
dflet 3:a8c249046181 150 #ifndef SL_TINY_EXT
dflet 3:a8c249046181 151 for (i=0 ; i<NONOS_MAX_SPAWN_ENTRIES ; i++)
dflet 3:a8c249046181 152 #endif
dflet 3:a8c249046181 153 {
dflet 3:a8c249046181 154 _SlNonOsSpawnEntry_t* pE = &g_SlNonOsCB.SpawnEntries[i];
dflet 3:a8c249046181 155 _SlSpawnEntryFunc_t pF = pE->pEntry;
dflet 3:a8c249046181 156
dflet 3:a8c249046181 157 if (NULL != pF)
dflet 3:a8c249046181 158 {
dflet 3:a8c249046181 159 if(RxIrqCnt != (g_pCB)->RxDoneCnt) {
dflet 3:a8c249046181 160 _SlDrvMsgReadSpawnCtx(0);
dflet 3:a8c249046181 161 //pF(0);/*(pValue);*//*Function pointer*/
dflet 3:a8c249046181 162 }
dflet 3:a8c249046181 163 pE->pEntry = NULL;
dflet 3:a8c249046181 164 pE->pValue = NULL;
dflet 3:a8c249046181 165 }
dflet 3:a8c249046181 166 }
dflet 3:a8c249046181 167
dflet 3:a8c249046181 168 return NONOS_RET_OK;
dflet 3:a8c249046181 169 }
dflet 3:a8c249046181 170 /*
dflet 3:a8c249046181 171 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjCreate(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_CLEAR_VALUE)
dflet 3:a8c249046181 172
dflet 3:a8c249046181 173 *pSemObj = Value;
dflet 3:a8c249046181 174 return NONOS_RET_OK;
dflet 3:a8c249046181 175
dflet 3:a8c249046181 176 }
dflet 3:a8c249046181 177 */
dflet 3:a8c249046181 178 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjDelete(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,0)
dflet 3:a8c249046181 179
dflet 3:a8c249046181 180 *pSemObj = Value;
dflet 3:a8c249046181 181 return NONOS_RET_OK;
dflet 3:a8c249046181 182 }
dflet 3:a8c249046181 183
dflet 3:a8c249046181 184 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjSignal(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE)
dflet 3:a8c249046181 185
dflet 3:a8c249046181 186 *pSemObj = Value;
dflet 3:a8c249046181 187 return NONOS_RET_OK;
dflet 3:a8c249046181 188 }
dflet 3:a8c249046181 189
dflet 3:a8c249046181 190 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjSignalFromIRQ(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE)
dflet 3:a8c249046181 191
dflet 3:a8c249046181 192 *pSemObj = Value;
dflet 3:a8c249046181 193 return NONOS_RET_OK;
dflet 3:a8c249046181 194 }
dflet 3:a8c249046181 195 /*
dflet 3:a8c249046181 196 _SlNonOsRetVal_t cc3100_nonos::sl_LockObjCreate(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE)
dflet 3:a8c249046181 197
dflet 3:a8c249046181 198 *pSemObj = Value;
dflet 3:a8c249046181 199 return NONOS_RET_OK;
dflet 3:a8c249046181 200 }
dflet 3:a8c249046181 201 */
dflet 3:a8c249046181 202 _SlNonOsRetVal_t cc3100_nonos::sl_LockObjDelete(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pLockObj,0)
dflet 3:a8c249046181 203
dflet 3:a8c249046181 204 *pSemObj = Value;
dflet 3:a8c249046181 205 return NONOS_RET_OK;
dflet 3:a8c249046181 206 }
dflet 3:a8c249046181 207
dflet 3:a8c249046181 208 _SlNonOsRetVal_t cc3100_nonos::sl_LockObjUnlock(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE)
dflet 3:a8c249046181 209
dflet 3:a8c249046181 210 *pSemObj = Value;
dflet 3:a8c249046181 211 return NONOS_RET_OK;
dflet 3:a8c249046181 212 }
dflet 3:a8c249046181 213
dflet 3:a8c249046181 214 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjWait(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout){//_SlNonOsSemGet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE,NON_OS_SYNC_OBJ_CLEAR_VALUE,Timeout)
dflet 3:a8c249046181 215
dflet 3:a8c249046181 216 #ifdef _SlSyncWaitLoopCallback
dflet 3:a8c249046181 217 _SlNonOsTime_t timeOutRequest = Timeout;
dflet 3:a8c249046181 218 #endif
dflet 3:a8c249046181 219
dflet 3:a8c249046181 220 while (Timeout > 0) {
dflet 3:a8c249046181 221 if (WaitValue == *pSyncObj) {
dflet 3:a8c249046181 222 *pSyncObj = SetValue;
dflet 3:a8c249046181 223 break;
dflet 3:a8c249046181 224 }
dflet 3:a8c249046181 225 if (Timeout != NONOS_WAIT_FOREVER) {
dflet 3:a8c249046181 226 Timeout--;
dflet 3:a8c249046181 227 }
dflet 3:a8c249046181 228 _SlNonOsMainLoopTask();
dflet 3:a8c249046181 229
dflet 3:a8c249046181 230 #ifdef _SlSyncWaitLoopCallback
dflet 3:a8c249046181 231 if( (__NON_OS_SYNC_OBJ_SIGNAL_VALUE == WaitValue) && (timeOutRequest != NONOS_NO_WAIT) ) {
dflet 3:a8c249046181 232 if (WaitValue == *pSyncObj) {
dflet 3:a8c249046181 233 *pSyncObj = SetValue;
dflet 3:a8c249046181 234 break;
dflet 3:a8c249046181 235 }
dflet 3:a8c249046181 236 _SlSyncWaitLoopCallback();
dflet 3:a8c249046181 237 }
dflet 3:a8c249046181 238 #endif
dflet 3:a8c249046181 239
dflet 3:a8c249046181 240 }
dflet 3:a8c249046181 241
dflet 3:a8c249046181 242 if (0 == Timeout) {
dflet 3:a8c249046181 243 return NONOS_RET_ERR;
dflet 3:a8c249046181 244 } else {
dflet 3:a8c249046181 245 return NONOS_RET_OK;
dflet 3:a8c249046181 246 }
dflet 3:a8c249046181 247 }
dflet 3:a8c249046181 248
dflet 3:a8c249046181 249 _SlNonOsRetVal_t cc3100_nonos::sl_LockObjLock(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout){//_SlNonOsSemGet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE,NON_OS_LOCK_OBJ_LOCK_VALUE,Timeout)
dflet 3:a8c249046181 250
dflet 3:a8c249046181 251 #ifdef _SlSyncWaitLoopCallback
dflet 3:a8c249046181 252 _SlNonOsTime_t timeOutRequest = Timeout;
dflet 3:a8c249046181 253 #endif
dflet 3:a8c249046181 254
dflet 3:a8c249046181 255 while (Timeout > 0) {
dflet 3:a8c249046181 256 if (WaitValue == *pSyncObj) {
dflet 3:a8c249046181 257 *pSyncObj = SetValue;
dflet 3:a8c249046181 258 break;
dflet 3:a8c249046181 259 }
dflet 3:a8c249046181 260 if (Timeout != NONOS_WAIT_FOREVER) {
dflet 3:a8c249046181 261 Timeout--;
dflet 3:a8c249046181 262 }
dflet 3:a8c249046181 263 _SlNonOsMainLoopTask();
dflet 3:a8c249046181 264
dflet 3:a8c249046181 265 #ifdef _SlSyncWaitLoopCallback
dflet 3:a8c249046181 266 if( (__NON_OS_SYNC_OBJ_SIGNAL_VALUE == WaitValue) && (timeOutRequest != NONOS_NO_WAIT) ) {
dflet 3:a8c249046181 267 if (WaitValue == *pSyncObj) {
dflet 3:a8c249046181 268 *pSyncObj = SetValue;
dflet 3:a8c249046181 269 break;
dflet 3:a8c249046181 270 }
dflet 3:a8c249046181 271 _SlSyncWaitLoopCallback();
dflet 3:a8c249046181 272 }
dflet 3:a8c249046181 273 #endif
dflet 3:a8c249046181 274
dflet 3:a8c249046181 275 }
dflet 3:a8c249046181 276
dflet 3:a8c249046181 277 if (0 == Timeout) {
dflet 3:a8c249046181 278 return NONOS_RET_ERR;
dflet 3:a8c249046181 279 } else {
dflet 3:a8c249046181 280 return NONOS_RET_OK;
dflet 3:a8c249046181 281 }
dflet 3:a8c249046181 282 }
dflet 3:a8c249046181 283
dflet 3:a8c249046181 284 }//namespace mbed_cc3100
dflet 3:a8c249046181 285
dflet 3:a8c249046181 286 #endif /*(SL_PLATFORM != SL_PLATFORM_NON_OS)*/
dflet 3:a8c249046181 287
dflet 3:a8c249046181 288
dflet 3:a8c249046181 289
dflet 3:a8c249046181 290
dflet 3:a8c249046181 291