TI's CC3100 host driver and demo. Experimental and a work in progress.

Dependencies:   mbed

Committer:
dflet
Date:
Wed Nov 19 23:04:04 2014 +0000
Revision:
2:a3e52cf86086
Parent:
0:bbe98578d4c0
Added more boards!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dflet 0:bbe98578d4c0 1 /*
dflet 0:bbe98578d4c0 2 * spawn.c - CC31xx/CC32xx Host Driver Implementation
dflet 0:bbe98578d4c0 3 *
dflet 0:bbe98578d4c0 4 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
dflet 0:bbe98578d4c0 5 *
dflet 0:bbe98578d4c0 6 *
dflet 0:bbe98578d4c0 7 * Redistribution and use in source and binary forms, with or without
dflet 0:bbe98578d4c0 8 * modification, are permitted provided that the following conditions
dflet 0:bbe98578d4c0 9 * are met:
dflet 0:bbe98578d4c0 10 *
dflet 0:bbe98578d4c0 11 * Redistributions of source code must retain the above copyright
dflet 0:bbe98578d4c0 12 * notice, this list of conditions and the following disclaimer.
dflet 0:bbe98578d4c0 13 *
dflet 0:bbe98578d4c0 14 * Redistributions in binary form must reproduce the above copyright
dflet 0:bbe98578d4c0 15 * notice, this list of conditions and the following disclaimer in the
dflet 0:bbe98578d4c0 16 * documentation and/or other materials provided with the
dflet 0:bbe98578d4c0 17 * distribution.
dflet 0:bbe98578d4c0 18 *
dflet 0:bbe98578d4c0 19 * Neither the name of Texas Instruments Incorporated nor the names of
dflet 0:bbe98578d4c0 20 * its contributors may be used to endorse or promote products derived
dflet 0:bbe98578d4c0 21 * from this software without specific prior written permission.
dflet 0:bbe98578d4c0 22 *
dflet 0:bbe98578d4c0 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dflet 0:bbe98578d4c0 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dflet 0:bbe98578d4c0 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dflet 0:bbe98578d4c0 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dflet 0:bbe98578d4c0 27 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dflet 0:bbe98578d4c0 28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dflet 0:bbe98578d4c0 29 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dflet 0:bbe98578d4c0 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dflet 0:bbe98578d4c0 31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dflet 0:bbe98578d4c0 32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dflet 0:bbe98578d4c0 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
dflet 0:bbe98578d4c0 34 *
dflet 0:bbe98578d4c0 35 */
dflet 0:bbe98578d4c0 36
dflet 0:bbe98578d4c0 37
dflet 0:bbe98578d4c0 38
dflet 0:bbe98578d4c0 39 /*****************************************************************************/
dflet 0:bbe98578d4c0 40 /* Include files */
dflet 0:bbe98578d4c0 41 /*****************************************************************************/
dflet 0:bbe98578d4c0 42 #include "cc3100_simplelink.h"
dflet 0:bbe98578d4c0 43
dflet 0:bbe98578d4c0 44
dflet 0:bbe98578d4c0 45 #if (defined (SL_PLATFORM_MULTI_THREADED)) && (!defined (SL_PLATFORM_EXTERNAL_SPAWN))
dflet 0:bbe98578d4c0 46
dflet 0:bbe98578d4c0 47 #define _SL_MAX_INTERNAL_SPAWN_ENTRIES 10
dflet 0:bbe98578d4c0 48
dflet 0:bbe98578d4c0 49 typedef struct _SlInternalSpawnEntry_t
dflet 0:bbe98578d4c0 50 {
dflet 0:bbe98578d4c0 51 _SlSpawnEntryFunc_t pEntry;
dflet 0:bbe98578d4c0 52 void* pValue;
dflet 0:bbe98578d4c0 53 struct _SlInternalSpawnEntry_t* pNext;
dflet 0:bbe98578d4c0 54 }_SlInternalSpawnEntry_t;
dflet 0:bbe98578d4c0 55
dflet 0:bbe98578d4c0 56 typedef struct
dflet 0:bbe98578d4c0 57 {
dflet 0:bbe98578d4c0 58 _SlInternalSpawnEntry_t SpawnEntries[_SL_MAX_INTERNAL_SPAWN_ENTRIES];
dflet 0:bbe98578d4c0 59 _SlInternalSpawnEntry_t* pFree;
dflet 0:bbe98578d4c0 60 _SlInternalSpawnEntry_t* pWaitForExe;
dflet 0:bbe98578d4c0 61 _SlInternalSpawnEntry_t* pLastInWaitList;
dflet 0:bbe98578d4c0 62 _SlSyncObj_t SyncObj;
dflet 0:bbe98578d4c0 63 _SlLockObj_t LockObj;
dflet 0:bbe98578d4c0 64 }_SlInternalSpawnCB_t;
dflet 0:bbe98578d4c0 65
dflet 0:bbe98578d4c0 66 _SlInternalSpawnCB_t g_SlInternalSpawnCB;
dflet 0:bbe98578d4c0 67
dflet 0:bbe98578d4c0 68
dflet 0:bbe98578d4c0 69 void _SlInternalSpawnTaskEntry()
dflet 0:bbe98578d4c0 70 {
dflet 0:bbe98578d4c0 71 _i16 i;
dflet 0:bbe98578d4c0 72 _SlInternalSpawnEntry_t* pEntry;
dflet 0:bbe98578d4c0 73 _u8 LastEntry;
dflet 0:bbe98578d4c0 74
dflet 0:bbe98578d4c0 75 /* create and lock the locking object. lock in order to avoid race condition
dflet 0:bbe98578d4c0 76 on the first creation */
dflet 0:bbe98578d4c0 77 sl_LockObjCreate(&g_SlInternalSpawnCB.LockObj,"SlSpawnProtect");
dflet 0:bbe98578d4c0 78 sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_NO_WAIT);
dflet 0:bbe98578d4c0 79
dflet 0:bbe98578d4c0 80 /* create and clear the sync object */
dflet 0:bbe98578d4c0 81 sl_SyncObjCreate(&g_SlInternalSpawnCB.SyncObj,"SlSpawnSync");
dflet 0:bbe98578d4c0 82 sl_SyncObjWait(&g_SlInternalSpawnCB.SyncObj,SL_OS_NO_WAIT);
dflet 0:bbe98578d4c0 83
dflet 0:bbe98578d4c0 84 g_SlInternalSpawnCB.pFree = &g_SlInternalSpawnCB.SpawnEntries[0];
dflet 0:bbe98578d4c0 85 g_SlInternalSpawnCB.pWaitForExe = NULL;
dflet 0:bbe98578d4c0 86 g_SlInternalSpawnCB.pLastInWaitList = NULL;
dflet 0:bbe98578d4c0 87
dflet 0:bbe98578d4c0 88 /* create the link list between the entries */
dflet 0:bbe98578d4c0 89 for (i=0 ; i<_SL_MAX_INTERNAL_SPAWN_ENTRIES - 1 ; i++)
dflet 0:bbe98578d4c0 90 {
dflet 0:bbe98578d4c0 91 g_SlInternalSpawnCB.SpawnEntries[i].pNext = &g_SlInternalSpawnCB.SpawnEntries[i+1];
dflet 0:bbe98578d4c0 92 g_SlInternalSpawnCB.SpawnEntries[i].pEntry = NULL;
dflet 0:bbe98578d4c0 93 }
dflet 0:bbe98578d4c0 94 g_SlInternalSpawnCB.SpawnEntries[i].pNext = NULL;
dflet 0:bbe98578d4c0 95
dflet 0:bbe98578d4c0 96 sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj);
dflet 0:bbe98578d4c0 97
dflet 0:bbe98578d4c0 98
dflet 0:bbe98578d4c0 99 /* here we ready to execute entries */
dflet 0:bbe98578d4c0 100
dflet 0:bbe98578d4c0 101 while (TRUE)
dflet 0:bbe98578d4c0 102 {
dflet 0:bbe98578d4c0 103 sl_SyncObjWait(&g_SlInternalSpawnCB.SyncObj,SL_OS_WAIT_FOREVER);
dflet 0:bbe98578d4c0 104 /* go over all entries that already waiting for execution */
dflet 0:bbe98578d4c0 105 LastEntry = FALSE;
dflet 0:bbe98578d4c0 106 do
dflet 0:bbe98578d4c0 107 {
dflet 0:bbe98578d4c0 108 /* get entry to execute */
dflet 0:bbe98578d4c0 109 sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_WAIT_FOREVER);
dflet 0:bbe98578d4c0 110
dflet 0:bbe98578d4c0 111 pEntry = g_SlInternalSpawnCB.pWaitForExe;
dflet 0:bbe98578d4c0 112 if ( NULL == pEntry )
dflet 0:bbe98578d4c0 113 {
dflet 0:bbe98578d4c0 114 sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj);
dflet 0:bbe98578d4c0 115 break;
dflet 0:bbe98578d4c0 116 }
dflet 0:bbe98578d4c0 117 g_SlInternalSpawnCB.pWaitForExe = pEntry->pNext;
dflet 0:bbe98578d4c0 118 if (pEntry == g_SlInternalSpawnCB.pLastInWaitList)
dflet 0:bbe98578d4c0 119 {
dflet 0:bbe98578d4c0 120 g_SlInternalSpawnCB.pLastInWaitList = NULL;
dflet 0:bbe98578d4c0 121 LastEntry = TRUE;
dflet 0:bbe98578d4c0 122 }
dflet 0:bbe98578d4c0 123
dflet 0:bbe98578d4c0 124 sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj);
dflet 0:bbe98578d4c0 125
dflet 0:bbe98578d4c0 126
dflet 0:bbe98578d4c0 127 /* pEntry could be null in case that the sync was already set by some
dflet 0:bbe98578d4c0 128 of the entries during execution of earlier entry */
dflet 0:bbe98578d4c0 129 if (NULL != pEntry)
dflet 0:bbe98578d4c0 130 {
dflet 0:bbe98578d4c0 131 pEntry->pEntry(pEntry->pValue);
dflet 0:bbe98578d4c0 132 /* free the entry */
dflet 0:bbe98578d4c0 133 sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_WAIT_FOREVER);
dflet 0:bbe98578d4c0 134
dflet 0:bbe98578d4c0 135 pEntry->pNext = g_SlInternalSpawnCB.pFree;
dflet 0:bbe98578d4c0 136 g_SlInternalSpawnCB.pFree = pEntry;
dflet 0:bbe98578d4c0 137
dflet 0:bbe98578d4c0 138
dflet 0:bbe98578d4c0 139 if (NULL != g_SlInternalSpawnCB.pWaitForExe)
dflet 0:bbe98578d4c0 140 {
dflet 0:bbe98578d4c0 141 /* new entry received meanwhile */
dflet 0:bbe98578d4c0 142 LastEntry = FALSE;
dflet 0:bbe98578d4c0 143 }
dflet 0:bbe98578d4c0 144
dflet 0:bbe98578d4c0 145 sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj);
dflet 0:bbe98578d4c0 146
dflet 0:bbe98578d4c0 147 }
dflet 0:bbe98578d4c0 148
dflet 0:bbe98578d4c0 149 }while (!LastEntry);
dflet 0:bbe98578d4c0 150 }
dflet 0:bbe98578d4c0 151 }
dflet 0:bbe98578d4c0 152
dflet 0:bbe98578d4c0 153
dflet 0:bbe98578d4c0 154 _i16 _SlInternalSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , _u32 flags)
dflet 0:bbe98578d4c0 155 {
dflet 0:bbe98578d4c0 156 _i16 Res = 0;
dflet 0:bbe98578d4c0 157 _SlInternalSpawnEntry_t* pSpawnEntry;
dflet 0:bbe98578d4c0 158
dflet 0:bbe98578d4c0 159 if (NULL == pEntry)
dflet 0:bbe98578d4c0 160 {
dflet 0:bbe98578d4c0 161 Res = -1;
dflet 0:bbe98578d4c0 162 }
dflet 0:bbe98578d4c0 163 else
dflet 0:bbe98578d4c0 164 {
dflet 0:bbe98578d4c0 165 sl_LockObjLock(&g_SlInternalSpawnCB.LockObj,SL_OS_WAIT_FOREVER);
dflet 0:bbe98578d4c0 166
dflet 0:bbe98578d4c0 167 pSpawnEntry = g_SlInternalSpawnCB.pFree;
dflet 0:bbe98578d4c0 168 g_SlInternalSpawnCB.pFree = pSpawnEntry->pNext;
dflet 0:bbe98578d4c0 169
dflet 0:bbe98578d4c0 170 pSpawnEntry->pEntry = pEntry;
dflet 0:bbe98578d4c0 171 pSpawnEntry->pValue = pValue;
dflet 0:bbe98578d4c0 172 pSpawnEntry->pNext = NULL;
dflet 0:bbe98578d4c0 173
dflet 0:bbe98578d4c0 174 if (NULL == g_SlInternalSpawnCB.pWaitForExe)
dflet 0:bbe98578d4c0 175 {
dflet 0:bbe98578d4c0 176 g_SlInternalSpawnCB.pWaitForExe = pSpawnEntry;
dflet 0:bbe98578d4c0 177 g_SlInternalSpawnCB.pLastInWaitList = pSpawnEntry;
dflet 0:bbe98578d4c0 178 }
dflet 0:bbe98578d4c0 179 else
dflet 0:bbe98578d4c0 180 {
dflet 0:bbe98578d4c0 181 g_SlInternalSpawnCB.pLastInWaitList->pNext = pSpawnEntry;
dflet 0:bbe98578d4c0 182 g_SlInternalSpawnCB.pLastInWaitList = pSpawnEntry;
dflet 0:bbe98578d4c0 183 }
dflet 0:bbe98578d4c0 184
dflet 0:bbe98578d4c0 185 sl_LockObjUnlock(&g_SlInternalSpawnCB.LockObj);
dflet 0:bbe98578d4c0 186 /* this sync is called after releasing the lock object to avoid unnecessary context switches */
dflet 0:bbe98578d4c0 187 sl_SyncObjSignal(&g_SlInternalSpawnCB.SyncObj);
dflet 0:bbe98578d4c0 188 }
dflet 0:bbe98578d4c0 189
dflet 0:bbe98578d4c0 190 return Res;
dflet 0:bbe98578d4c0 191 }
dflet 0:bbe98578d4c0 192
dflet 0:bbe98578d4c0 193
dflet 0:bbe98578d4c0 194
dflet 0:bbe98578d4c0 195
dflet 0:bbe98578d4c0 196
dflet 0:bbe98578d4c0 197 #endif
dflet 0:bbe98578d4c0 198