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

Dependencies:   mbed

Fork of cc3100_Test_Demo2 by 高 杨

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 * spawn.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
dflet 6:778b081f6a13 44 #include "cc3100_spawn.h"
dflet 6:778b081f6a13 45
dflet 6:778b081f6a13 46 namespace mbed_cc3100 {
dflet 6:778b081f6a13 47
dflet 6:778b081f6a13 48 #if (defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))
dflet 6:778b081f6a13 49
dflet 6:778b081f6a13 50 #define _SL_MAX_INTERNAL_SPAWN_ENTRIES 10
dflet 6:778b081f6a13 51
dflet 6:778b081f6a13 52
dflet 6:778b081f6a13 53 typedef struct _SlInternalSpawnEntry_t {
dflet 6:778b081f6a13 54 _SlSpawnEntryFunc_t pEntry;
dflet 6:778b081f6a13 55 void* pValue;
dflet 6:778b081f6a13 56 struct _SlInternalSpawnEntry_t* pNext;
dflet 6:778b081f6a13 57 } _SlInternalSpawnEntry_t;
dflet 6:778b081f6a13 58
dflet 6:778b081f6a13 59 typedef struct {
dflet 6:778b081f6a13 60 _SlInternalSpawnEntry_t SpawnEntries[_SL_MAX_INTERNAL_SPAWN_ENTRIES];
dflet 6:778b081f6a13 61 _SlInternalSpawnEntry_t* pFree;
dflet 6:778b081f6a13 62 _SlInternalSpawnEntry_t* pWaitForExe;
dflet 6:778b081f6a13 63 _SlInternalSpawnEntry_t* pLastInWaitList;
dflet 6:778b081f6a13 64 _SlSyncObj_t SyncObj;
dflet 6:778b081f6a13 65 _SlLockObj_t LockObj;
dflet 6:778b081f6a13 66 } _SlInternalSpawnCB_t;
dflet 6:778b081f6a13 67
dflet 6:778b081f6a13 68 _SlInternalSpawnCB_t g_SlInternalSpawnCB;
dflet 6:778b081f6a13 69
dflet 6:778b081f6a13 70 cc3100_spawn::cc3100_spawn()
dflet 6:778b081f6a13 71 {
dflet 6:778b081f6a13 72
dflet 6:778b081f6a13 73 }
dflet 6:778b081f6a13 74
dflet 6:778b081f6a13 75 cc3100_spawn::~cc3100_spawn()
dflet 6:778b081f6a13 76 {
dflet 6:778b081f6a13 77
dflet 6:778b081f6a13 78 }
dflet 6:778b081f6a13 79
dflet 6:778b081f6a13 80
dflet 6:778b081f6a13 81 void cc3100_spawn::_SlInternalSpawnTaskEntry()
dflet 6:778b081f6a13 82 {
dflet 6:778b081f6a13 83 int16_t i;
dflet 6:778b081f6a13 84 _SlInternalSpawnEntry_t* pEntry;
dflet 6:778b081f6a13 85 uint8_t LastEntry;
dflet 6:778b081f6a13 86
dflet 6:778b081f6a13 87 /* create and lock the locking object. lock in order to avoid race condition
dflet 6:778b081f6a13 88 on the first creation */
dflet 6:778b081f6a13 89 sl_LockObjCreate(&g_SlInternalSpawnCB.LockObj,"SlSpawnProtect");
dflet 6:778b081f6a13 90 sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_NO_WAIT);
dflet 6:778b081f6a13 91
dflet 6:778b081f6a13 92 /* create and clear the sync object */
dflet 6:778b081f6a13 93 sl_SyncObjCreate(&g_SlInternalSpawnCB.SyncObj,"SlSpawnSync");
dflet 6:778b081f6a13 94 sl_SyncObjWait(&g_SlInternalSpawnCB.SyncObj,SL_OS_NO_WAIT);
dflet 6:778b081f6a13 95
dflet 6:778b081f6a13 96 g_SlInternalSpawnCB.pFree = &g_SlInternalSpawnCB.SpawnEntries[0];
dflet 6:778b081f6a13 97 g_SlInternalSpawnCB.pWaitForExe = NULL;
dflet 6:778b081f6a13 98 g_SlInternalSpawnCB.pLastInWaitList = NULL;
dflet 6:778b081f6a13 99
dflet 6:778b081f6a13 100 /* create the link list between the entries */
dflet 6:778b081f6a13 101 for (i=0 ; i<_SL_MAX_INTERNAL_SPAWN_ENTRIES - 1 ; i++) {
dflet 6:778b081f6a13 102 g_SlInternalSpawnCB.SpawnEntries[i].pNext = &g_SlInternalSpawnCB.SpawnEntries[i+1];
dflet 6:778b081f6a13 103 g_SlInternalSpawnCB.SpawnEntries[i].pEntry = NULL;
dflet 6:778b081f6a13 104 }
dflet 6:778b081f6a13 105 g_SlInternalSpawnCB.SpawnEntries[i].pNext = NULL;
dflet 6:778b081f6a13 106
dflet 6:778b081f6a13 107 _SlDrvObjUnLock(&g_SlInternalSpawnCB.LockObj);
dflet 6:778b081f6a13 108
dflet 6:778b081f6a13 109
dflet 6:778b081f6a13 110 /* here we ready to execute entries */
dflet 6:778b081f6a13 111
dflet 6:778b081f6a13 112 while (TRUE) {
dflet 6:778b081f6a13 113 sl_SyncObjWait(&g_SlInternalSpawnCB.SyncObj,SL_OS_WAIT_FOREVER);
dflet 6:778b081f6a13 114 /* go over all entries that already waiting for execution */
dflet 6:778b081f6a13 115 LastEntry = FALSE;
dflet 6:778b081f6a13 116 do {
dflet 6:778b081f6a13 117 /* get entry to execute */
dflet 6:778b081f6a13 118 _SlDrvObjLockWaitForever(&g_SlInternalSpawnCB.LockObj);
dflet 6:778b081f6a13 119
dflet 6:778b081f6a13 120 pEntry = g_SlInternalSpawnCB.pWaitForExe;
dflet 6:778b081f6a13 121 if ( NULL == pEntry ) {
dflet 6:778b081f6a13 122 _SlDrvObjUnLock(&g_SlInternalSpawnCB.LockObj);
dflet 6:778b081f6a13 123 break;
dflet 6:778b081f6a13 124 }
dflet 6:778b081f6a13 125 g_SlInternalSpawnCB.pWaitForExe = pEntry->pNext;
dflet 6:778b081f6a13 126 if (pEntry == g_SlInternalSpawnCB.pLastInWaitList) {
dflet 6:778b081f6a13 127 g_SlInternalSpawnCB.pLastInWaitList = NULL;
dflet 6:778b081f6a13 128 LastEntry = TRUE;
dflet 6:778b081f6a13 129 }
dflet 6:778b081f6a13 130
dflet 6:778b081f6a13 131 _SlDrvObjUnLock(&g_SlInternalSpawnCB.LockObj);
dflet 6:778b081f6a13 132
dflet 6:778b081f6a13 133
dflet 6:778b081f6a13 134 /* pEntry could be null in case that the sync was already set by some
dflet 6:778b081f6a13 135 of the entries during execution of earlier entry */
dflet 6:778b081f6a13 136 if (NULL != pEntry) {
dflet 6:778b081f6a13 137 pEntry->pEntry(pEntry->pValue);
dflet 6:778b081f6a13 138 /* free the entry */
dflet 6:778b081f6a13 139 _SlDrvObjLockWaitForever(&g_SlInternalSpawnCB.LockObj);
dflet 6:778b081f6a13 140
dflet 6:778b081f6a13 141 pEntry->pNext = g_SlInternalSpawnCB.pFree;
dflet 6:778b081f6a13 142 g_SlInternalSpawnCB.pFree = pEntry;
dflet 6:778b081f6a13 143
dflet 6:778b081f6a13 144
dflet 6:778b081f6a13 145 if (NULL != g_SlInternalSpawnCB.pWaitForExe) {
dflet 6:778b081f6a13 146 /* new entry received meanwhile */
dflet 6:778b081f6a13 147 LastEntry = FALSE;
dflet 6:778b081f6a13 148 }
dflet 6:778b081f6a13 149
dflet 6:778b081f6a13 150 _SlDrvObjUnLock(&g_SlInternalSpawnCB.LockObj);
dflet 6:778b081f6a13 151
dflet 6:778b081f6a13 152 }
dflet 6:778b081f6a13 153
dflet 6:778b081f6a13 154 } while (!LastEntry);
dflet 6:778b081f6a13 155 }
dflet 6:778b081f6a13 156 }
dflet 6:778b081f6a13 157
dflet 6:778b081f6a13 158
dflet 6:778b081f6a13 159 int16_t cc3100_spawn::_SlInternalSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , uint32_t flags)
dflet 6:778b081f6a13 160 {
dflet 6:778b081f6a13 161 int16_t Res = 0;
dflet 6:778b081f6a13 162 _SlInternalSpawnEntry_t* pSpawnEntry;
dflet 6:778b081f6a13 163
dflet 6:778b081f6a13 164 if (NULL == pEntry) {
dflet 6:778b081f6a13 165 Res = -1;
dflet 6:778b081f6a13 166 } else {
dflet 6:778b081f6a13 167 _SlDrvObjLockWaitForever(&g_SlInternalSpawnCB.LockObj);
dflet 6:778b081f6a13 168
dflet 6:778b081f6a13 169 pSpawnEntry = g_SlInternalSpawnCB.pFree;
dflet 6:778b081f6a13 170 g_SlInternalSpawnCB.pFree = pSpawnEntry->pNext;
dflet 6:778b081f6a13 171
dflet 6:778b081f6a13 172 pSpawnEntry->pEntry = pEntry;
dflet 6:778b081f6a13 173 pSpawnEntry->pValue = pValue;
dflet 6:778b081f6a13 174 pSpawnEntry->pNext = NULL;
dflet 6:778b081f6a13 175
dflet 6:778b081f6a13 176 if (NULL == g_SlInternalSpawnCB.pWaitForExe) {
dflet 6:778b081f6a13 177 g_SlInternalSpawnCB.pWaitForExe = pSpawnEntry;
dflet 6:778b081f6a13 178 g_SlInternalSpawnCB.pLastInWaitList = pSpawnEntry;
dflet 6:778b081f6a13 179 } else {
dflet 6:778b081f6a13 180 g_SlInternalSpawnCB.pLastInWaitList->pNext = pSpawnEntry;
dflet 6:778b081f6a13 181 g_SlInternalSpawnCB.pLastInWaitList = pSpawnEntry;
dflet 6:778b081f6a13 182 }
dflet 6:778b081f6a13 183
dflet 6:778b081f6a13 184 _SlDrvObjUnLock(&g_SlInternalSpawnCB.LockObj);
dflet 6:778b081f6a13 185
dflet 6:778b081f6a13 186 /* this sync is called after releasing the lock object to avoid unnecessary context switches */
dflet 6:778b081f6a13 187 _SlDrvSyncObjSignal(&g_SlInternalSpawnCB.SyncObj);
dflet 6:778b081f6a13 188 }
dflet 6:778b081f6a13 189
dflet 6:778b081f6a13 190 return Res;
dflet 6:778b081f6a13 191 }
dflet 6:778b081f6a13 192
dflet 6:778b081f6a13 193 #endif
dflet 6:778b081f6a13 194
dflet 6:778b081f6a13 195 }//namespace mbed_cc3100