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

Dependencies:   mbed

Fork of cc3100_Test_Demo2 by 高 杨

Committer:
dflet
Date:
Tue Feb 10 12:09:29 2015 +0000
Revision:
0:e89ba455dbcf
Child:
2:b3fd5b3d9860
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?

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