Updated to use external spawn.

Fork of simplelink_V2 by David Fletcher

Committer:
dflet
Date:
Sat Jun 06 13:48:29 2015 +0000
Revision:
1:9b68e650b3f6
Parent:
0:1a07906111ec
Oppps

Who changed what in which revision?

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