Port of TI's CC3100 Websock camera demo. Using FreeRTOS, mbedTLS, also parts of Arducam for cams ov5642 and 0v2640. Can also use MT9D111. Work in progress. Be warned some parts maybe a bit flacky. This is for Seeed Arch max only, for an M3, see the demo for CM3 using the 0v5642 aducam mini.

Dependencies:   mbed

Committer:
dflet
Date:
Tue Sep 15 16:45:04 2015 +0000
Revision:
22:f9b5e0b80bf2
Parent:
20:409ebd125b9c
Removed some debug.

Who changed what in which revision?

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