Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

Committer:
dflet
Date:
Thu Sep 03 14:02:37 2015 +0000
Revision:
3:a8c249046181
SPI Mode change 1 to 0

Who changed what in which revision?

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