TI's CC3100. A test demo with very little testing done!

Dependencies:   mbed

Fork of cc3100_Test_Demo2 by 高 杨

Committer:
gaoyang
Date:
Sun Jul 30 06:32:08 2017 +0000
Revision:
9:b8da46b97970
Parent:
6:778b081f6a13
DAS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 6:778b081f6a13 1 /*
dflet 6:778b081f6a13 2 * nonos.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
dflet 6:778b081f6a13 43 #ifndef SL_PLATFORM_MULTI_THREADED
dflet 6:778b081f6a13 44
dflet 6:778b081f6a13 45 #include "cc3100_simplelink.h"
dflet 6:778b081f6a13 46 #include "cc3100_nonos.h"
dflet 6:778b081f6a13 47 #include "fPtr_func.h"
dflet 6:778b081f6a13 48
dflet 6:778b081f6a13 49 namespace mbed_cc3100 {
dflet 6:778b081f6a13 50
dflet 6:778b081f6a13 51 #ifndef SL_TINY_EXT
dflet 6:778b081f6a13 52 #define NONOS_MAX_SPAWN_ENTRIES 5
dflet 6:778b081f6a13 53 #else
dflet 6:778b081f6a13 54 #define NONOS_MAX_SPAWN_ENTRIES 1
dflet 6:778b081f6a13 55 #endif
dflet 6:778b081f6a13 56
dflet 6:778b081f6a13 57 cc3100_nonos::cc3100_nonos(cc3100_driver &driver)
dflet 6:778b081f6a13 58 : _driver(driver)
dflet 6:778b081f6a13 59 {
dflet 6:778b081f6a13 60
dflet 6:778b081f6a13 61 }
dflet 6:778b081f6a13 62
dflet 6:778b081f6a13 63 cc3100_nonos::~cc3100_nonos()
dflet 6:778b081f6a13 64 {
dflet 6:778b081f6a13 65
dflet 6:778b081f6a13 66 }
dflet 6:778b081f6a13 67
dflet 6:778b081f6a13 68 typedef struct {
dflet 6:778b081f6a13 69 _SlSpawnEntryFunc_t pEntry;
dflet 6:778b081f6a13 70 void* pValue;
dflet 6:778b081f6a13 71 } _SlNonOsSpawnEntry_t;
dflet 6:778b081f6a13 72
dflet 6:778b081f6a13 73 typedef struct {
dflet 6:778b081f6a13 74 _SlNonOsSpawnEntry_t SpawnEntries[NONOS_MAX_SPAWN_ENTRIES];
dflet 6:778b081f6a13 75 } _SlNonOsCB_t;
dflet 6:778b081f6a13 76
dflet 6:778b081f6a13 77 _SlNonOsCB_t g_SlNonOsCB;
dflet 6:778b081f6a13 78
dflet 6:778b081f6a13 79
dflet 6:778b081f6a13 80 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsSemSet(_SlNonOsSemObj_t* pSemObj , _SlNonOsSemObj_t Value)
dflet 6:778b081f6a13 81 {
dflet 6:778b081f6a13 82 *pSemObj = Value;
dflet 6:778b081f6a13 83 return NONOS_RET_OK;
dflet 6:778b081f6a13 84 }
dflet 6:778b081f6a13 85
dflet 6:778b081f6a13 86 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsSemGet(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout)
dflet 6:778b081f6a13 87 {
dflet 6:778b081f6a13 88 #ifdef _SlSyncWaitLoopCallback
dflet 6:778b081f6a13 89 _SlNonOsTime_t timeOutRequest = Timeout;
dflet 6:778b081f6a13 90 #endif
dflet 6:778b081f6a13 91
dflet 6:778b081f6a13 92 while (Timeout > 0) {
dflet 6:778b081f6a13 93 if (WaitValue == *pSyncObj) {
dflet 6:778b081f6a13 94 *pSyncObj = SetValue;
dflet 6:778b081f6a13 95 break;
dflet 6:778b081f6a13 96 }
dflet 6:778b081f6a13 97 if (Timeout != NONOS_WAIT_FOREVER) {
dflet 6:778b081f6a13 98 Timeout--;
dflet 6:778b081f6a13 99 }
dflet 6:778b081f6a13 100 _SlNonOsMainLoopTask();
dflet 6:778b081f6a13 101
dflet 6:778b081f6a13 102 #ifdef _SlSyncWaitLoopCallback
dflet 6:778b081f6a13 103 if( (__NON_OS_SYNC_OBJ_SIGNAL_VALUE == WaitValue) && (timeOutRequest != NONOS_NO_WAIT) ) {
dflet 6:778b081f6a13 104 if (WaitValue == *pSyncObj) {
dflet 6:778b081f6a13 105 *pSyncObj = SetValue;
dflet 6:778b081f6a13 106 break;
dflet 6:778b081f6a13 107 }
dflet 6:778b081f6a13 108 _SlSyncWaitLoopCallback();
dflet 6:778b081f6a13 109 }
dflet 6:778b081f6a13 110 #endif
dflet 6:778b081f6a13 111
dflet 6:778b081f6a13 112 }
dflet 6:778b081f6a13 113
dflet 6:778b081f6a13 114 if (0 == Timeout) {
dflet 6:778b081f6a13 115 return NONOS_RET_ERR;
dflet 6:778b081f6a13 116 } else {
dflet 6:778b081f6a13 117 return NONOS_RET_OK;
dflet 6:778b081f6a13 118 }
dflet 6:778b081f6a13 119 }
dflet 6:778b081f6a13 120
dflet 6:778b081f6a13 121
dflet 6:778b081f6a13 122 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , uint32_t flags)
dflet 6:778b081f6a13 123 {
dflet 6:778b081f6a13 124 int8_t i = 0;
dflet 6:778b081f6a13 125
dflet 6:778b081f6a13 126 #ifndef SL_TINY_EXT
dflet 6:778b081f6a13 127 for (i=0 ; i<NONOS_MAX_SPAWN_ENTRIES ; i++)
dflet 6:778b081f6a13 128 #endif
dflet 6:778b081f6a13 129 {
dflet 6:778b081f6a13 130 _SlNonOsSpawnEntry_t* pE = &g_SlNonOsCB.SpawnEntries[i];
dflet 6:778b081f6a13 131
dflet 6:778b081f6a13 132 if (NULL == pE->pEntry)
dflet 6:778b081f6a13 133 {
dflet 6:778b081f6a13 134 pE->pValue = pValue;
dflet 6:778b081f6a13 135 pE->pEntry = pEntry;
dflet 6:778b081f6a13 136 #ifndef SL_TINY_EXT
dflet 6:778b081f6a13 137 break;
dflet 6:778b081f6a13 138 #endif
dflet 6:778b081f6a13 139 }
dflet 6:778b081f6a13 140 }
dflet 6:778b081f6a13 141
dflet 6:778b081f6a13 142
dflet 6:778b081f6a13 143 return NONOS_RET_OK;
dflet 6:778b081f6a13 144 }
dflet 6:778b081f6a13 145
dflet 6:778b081f6a13 146 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsMainLoopTask(void)
dflet 6:778b081f6a13 147 {
dflet 6:778b081f6a13 148 int8_t i = 0;
dflet 6:778b081f6a13 149
dflet 6:778b081f6a13 150 #ifndef SL_TINY_EXT
dflet 6:778b081f6a13 151 for (i=0 ; i<NONOS_MAX_SPAWN_ENTRIES ; i++)
dflet 6:778b081f6a13 152 #endif
dflet 6:778b081f6a13 153 {
dflet 6:778b081f6a13 154 _SlNonOsSpawnEntry_t* pE = &g_SlNonOsCB.SpawnEntries[i];
dflet 6:778b081f6a13 155 _SlSpawnEntryFunc_t pF = pE->pEntry;
dflet 6:778b081f6a13 156
dflet 6:778b081f6a13 157 if (NULL != pF)
dflet 6:778b081f6a13 158 {
dflet 6:778b081f6a13 159 if(RxIrqCnt != (g_pCB)->RxDoneCnt) {
dflet 6:778b081f6a13 160 _driver._SlDrvMsgReadSpawnCtx_(0);
dflet 6:778b081f6a13 161 //pF(0);/*(pValue);*//*Function pointer*/
dflet 6:778b081f6a13 162 }
dflet 6:778b081f6a13 163 pE->pEntry = NULL;
dflet 6:778b081f6a13 164 pE->pValue = NULL;
dflet 6:778b081f6a13 165 }
dflet 6:778b081f6a13 166 }
dflet 6:778b081f6a13 167
dflet 6:778b081f6a13 168 return NONOS_RET_OK;
dflet 6:778b081f6a13 169 }
dflet 6:778b081f6a13 170 /*
dflet 6:778b081f6a13 171 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjCreate(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_CLEAR_VALUE)
dflet 6:778b081f6a13 172
dflet 6:778b081f6a13 173 *pSemObj = Value;
dflet 6:778b081f6a13 174 return NONOS_RET_OK;
dflet 6:778b081f6a13 175
dflet 6:778b081f6a13 176 }
dflet 6:778b081f6a13 177 */
dflet 6:778b081f6a13 178 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjDelete(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,0)
dflet 6:778b081f6a13 179
dflet 6:778b081f6a13 180 *pSemObj = Value;
dflet 6:778b081f6a13 181 return NONOS_RET_OK;
dflet 6:778b081f6a13 182 }
dflet 6:778b081f6a13 183
dflet 6:778b081f6a13 184 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjSignal(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE)
dflet 6:778b081f6a13 185
dflet 6:778b081f6a13 186 *pSemObj = Value;
dflet 6:778b081f6a13 187 return NONOS_RET_OK;
dflet 6:778b081f6a13 188 }
dflet 6:778b081f6a13 189
dflet 6:778b081f6a13 190 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjSignalFromIRQ(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE)
dflet 6:778b081f6a13 191
dflet 6:778b081f6a13 192 *pSemObj = Value;
dflet 6:778b081f6a13 193 return NONOS_RET_OK;
dflet 6:778b081f6a13 194 }
dflet 6:778b081f6a13 195 /*
dflet 6:778b081f6a13 196 _SlNonOsRetVal_t cc3100_nonos::sl_LockObjCreate(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE)
dflet 6:778b081f6a13 197
dflet 6:778b081f6a13 198 *pSemObj = Value;
dflet 6:778b081f6a13 199 return NONOS_RET_OK;
dflet 6:778b081f6a13 200 }
dflet 6:778b081f6a13 201 */
dflet 6:778b081f6a13 202 _SlNonOsRetVal_t cc3100_nonos::sl_LockObjDelete(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pLockObj,0)
dflet 6:778b081f6a13 203
dflet 6:778b081f6a13 204 *pSemObj = Value;
dflet 6:778b081f6a13 205 return NONOS_RET_OK;
dflet 6:778b081f6a13 206 }
dflet 6:778b081f6a13 207
dflet 6:778b081f6a13 208 _SlNonOsRetVal_t cc3100_nonos::sl_LockObjUnlock(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE)
dflet 6:778b081f6a13 209
dflet 6:778b081f6a13 210 *pSemObj = Value;
dflet 6:778b081f6a13 211 return NONOS_RET_OK;
dflet 6:778b081f6a13 212 }
dflet 6:778b081f6a13 213
dflet 6:778b081f6a13 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 6:778b081f6a13 215
dflet 6:778b081f6a13 216 #ifdef _SlSyncWaitLoopCallback
dflet 6:778b081f6a13 217 _SlNonOsTime_t timeOutRequest = Timeout;
dflet 6:778b081f6a13 218 #endif
dflet 6:778b081f6a13 219
dflet 6:778b081f6a13 220 while (Timeout > 0) {
dflet 6:778b081f6a13 221 if (WaitValue == *pSyncObj) {
dflet 6:778b081f6a13 222 *pSyncObj = SetValue;
dflet 6:778b081f6a13 223 break;
dflet 6:778b081f6a13 224 }
dflet 6:778b081f6a13 225 if (Timeout != NONOS_WAIT_FOREVER) {
dflet 6:778b081f6a13 226 Timeout--;
dflet 6:778b081f6a13 227 }
dflet 6:778b081f6a13 228 _SlNonOsMainLoopTask();
dflet 6:778b081f6a13 229
dflet 6:778b081f6a13 230 #ifdef _SlSyncWaitLoopCallback
dflet 6:778b081f6a13 231 if( (__NON_OS_SYNC_OBJ_SIGNAL_VALUE == WaitValue) && (timeOutRequest != NONOS_NO_WAIT) ) {
dflet 6:778b081f6a13 232 if (WaitValue == *pSyncObj) {
dflet 6:778b081f6a13 233 *pSyncObj = SetValue;
dflet 6:778b081f6a13 234 break;
dflet 6:778b081f6a13 235 }
dflet 6:778b081f6a13 236 _SlSyncWaitLoopCallback();
dflet 6:778b081f6a13 237 }
dflet 6:778b081f6a13 238 #endif
dflet 6:778b081f6a13 239
dflet 6:778b081f6a13 240 }
dflet 6:778b081f6a13 241
dflet 6:778b081f6a13 242 if (0 == Timeout) {
dflet 6:778b081f6a13 243 return NONOS_RET_ERR;
dflet 6:778b081f6a13 244 } else {
dflet 6:778b081f6a13 245 return NONOS_RET_OK;
dflet 6:778b081f6a13 246 }
dflet 6:778b081f6a13 247 }
dflet 6:778b081f6a13 248
dflet 6:778b081f6a13 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 6:778b081f6a13 250
dflet 6:778b081f6a13 251 #ifdef _SlSyncWaitLoopCallback
dflet 6:778b081f6a13 252 _SlNonOsTime_t timeOutRequest = Timeout;
dflet 6:778b081f6a13 253 #endif
dflet 6:778b081f6a13 254
dflet 6:778b081f6a13 255 while (Timeout > 0) {
dflet 6:778b081f6a13 256 if (WaitValue == *pSyncObj) {
dflet 6:778b081f6a13 257 *pSyncObj = SetValue;
dflet 6:778b081f6a13 258 break;
dflet 6:778b081f6a13 259 }
dflet 6:778b081f6a13 260 if (Timeout != NONOS_WAIT_FOREVER) {
dflet 6:778b081f6a13 261 Timeout--;
dflet 6:778b081f6a13 262 }
dflet 6:778b081f6a13 263 _SlNonOsMainLoopTask();
dflet 6:778b081f6a13 264
dflet 6:778b081f6a13 265 #ifdef _SlSyncWaitLoopCallback
dflet 6:778b081f6a13 266 if( (__NON_OS_SYNC_OBJ_SIGNAL_VALUE == WaitValue) && (timeOutRequest != NONOS_NO_WAIT) ) {
dflet 6:778b081f6a13 267 if (WaitValue == *pSyncObj) {
dflet 6:778b081f6a13 268 *pSyncObj = SetValue;
dflet 6:778b081f6a13 269 break;
dflet 6:778b081f6a13 270 }
dflet 6:778b081f6a13 271 _SlSyncWaitLoopCallback();
dflet 6:778b081f6a13 272 }
dflet 6:778b081f6a13 273 #endif
dflet 6:778b081f6a13 274
dflet 6:778b081f6a13 275 }
dflet 6:778b081f6a13 276
dflet 6:778b081f6a13 277 if (0 == Timeout) {
dflet 6:778b081f6a13 278 return NONOS_RET_ERR;
dflet 6:778b081f6a13 279 } else {
dflet 6:778b081f6a13 280 return NONOS_RET_OK;
dflet 6:778b081f6a13 281 }
dflet 6:778b081f6a13 282 }
dflet 6:778b081f6a13 283
dflet 6:778b081f6a13 284
dflet 6:778b081f6a13 285
dflet 6:778b081f6a13 286 #endif /*(SL_PLATFORM != SL_PLATFORM_NON_OS)*/
dflet 6:778b081f6a13 287
dflet 6:778b081f6a13 288 }//namespace mbed_cc3100
dflet 6:778b081f6a13 289
dflet 6:778b081f6a13 290
dflet 6:778b081f6a13 291