cc3100_Socket_Wifi_Server with Ethernet Interface not working

Dependencies:   EthernetInterface mbed-rtos mbed

Fork of cc3100_Test_Demo by David Fletcher

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