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