Update revision to use TI's mqtt and Freertos.

Dependencies:   mbed client server

Fork of cc3100_Test_mqtt_CM3 by David Fletcher

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cc3100_nonos.cpp Source File

cc3100_nonos.cpp

00001 /*
00002 * nonos.c - CC31xx/CC32xx Host Driver Implementation
00003 *
00004 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
00005 *
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *    Redistributions of source code must retain the above copyright
00012 *    notice, this list of conditions and the following disclaimer.
00013 *
00014 *    Redistributions in binary form must reproduce the above copyright
00015 *    notice, this list of conditions and the following disclaimer in the
00016 *    documentation and/or other materials provided with the
00017 *    distribution.
00018 *
00019 *    Neither the name of Texas Instruments Incorporated nor the names of
00020 *    its contributors may be used to endorse or promote products derived
00021 *    from this software without specific prior written permission.
00022 *
00023 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00026 *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
00027 *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00028 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00029 *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00030 *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00031 *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00032 *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034 *
00035 */
00036 
00037 
00038 
00039 /*****************************************************************************/
00040 /* Include files                                                             */
00041 /*****************************************************************************/
00042 
00043 #ifndef SL_PLATFORM_MULTI_THREADED
00044 
00045 #include "cc3100_simplelink.h"
00046 #include "cc3100_nonos.h"
00047 #include "fPtr_func.h"
00048 
00049 namespace mbed_cc3100 {
00050         
00051 #ifndef SL_TINY_EXT
00052 #define NONOS_MAX_SPAWN_ENTRIES     5
00053 #else
00054 #define NONOS_MAX_SPAWN_ENTRIES     1
00055 #endif  
00056 
00057 cc3100_nonos::cc3100_nonos(cc3100_driver &driver)
00058     : _driver(driver)
00059 {
00060     
00061 }
00062 
00063 cc3100_nonos::~cc3100_nonos()
00064 {
00065 
00066 }
00067 
00068 typedef struct {
00069     _SlSpawnEntryFunc_t         pEntry;
00070     void*                       pValue;
00071 } _SlNonOsSpawnEntry_t;
00072 
00073 typedef struct {
00074     _SlNonOsSpawnEntry_t    SpawnEntries[NONOS_MAX_SPAWN_ENTRIES];
00075 } _SlNonOsCB_t;
00076 
00077 _SlNonOsCB_t g_SlNonOsCB;
00078 
00079 
00080 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsSemSet(_SlNonOsSemObj_t* pSemObj , _SlNonOsSemObj_t Value)
00081 {
00082     *pSemObj = Value;
00083     return NONOS_RET_OK;
00084 }
00085 
00086 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsSemGet(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout)
00087 {
00088 #ifdef _SlSyncWaitLoopCallback
00089     _SlNonOsTime_t timeOutRequest = Timeout; 
00090 #endif    
00091     
00092     while (Timeout > 0) {
00093         if (WaitValue == *pSyncObj) {
00094             *pSyncObj = SetValue;            
00095             break;
00096         }
00097         if (Timeout != NONOS_WAIT_FOREVER) {
00098             Timeout--;
00099         }
00100         _SlNonOsMainLoopTask();
00101         
00102 #ifdef _SlSyncWaitLoopCallback
00103         if( (__NON_OS_SYNC_OBJ_SIGNAL_VALUE == WaitValue) && (timeOutRequest != NONOS_NO_WAIT) ) {
00104             if (WaitValue == *pSyncObj) {
00105                 *pSyncObj = SetValue;
00106                 break;
00107             }
00108             _SlSyncWaitLoopCallback();
00109         }
00110 #endif
00111 
00112     }
00113 
00114     if (0 == Timeout) {        
00115         return NONOS_RET_ERR;
00116     } else {        
00117         return NONOS_RET_OK;
00118     }
00119 }
00120 
00121 
00122 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , uint32_t flags)
00123 {
00124     int8_t i = 0;
00125     
00126 #ifndef SL_TINY_EXT     
00127     for (i=0 ; i<NONOS_MAX_SPAWN_ENTRIES ; i++)
00128 #endif     
00129     {
00130         _SlNonOsSpawnEntry_t* pE = &g_SlNonOsCB.SpawnEntries[i];
00131     
00132         if (NULL == pE->pEntry)
00133         {
00134             pE->pValue = pValue;
00135             pE->pEntry = pEntry;
00136 #ifndef SL_TINY_EXT                             
00137             break;
00138 #endif                        
00139         }
00140     }
00141         
00142         
00143         return NONOS_RET_OK;
00144 }
00145 
00146 _SlNonOsRetVal_t cc3100_nonos::_SlNonOsMainLoopTask(void)
00147 {
00148     int8_t i = 0;
00149         
00150 #ifndef SL_TINY_EXT
00151     for (i=0 ; i<NONOS_MAX_SPAWN_ENTRIES ; i++)
00152 #endif
00153     {
00154         _SlNonOsSpawnEntry_t* pE = &g_SlNonOsCB.SpawnEntries[i];
00155         _SlSpawnEntryFunc_t         pF = pE->pEntry;
00156         
00157         if (NULL != pF)
00158         {
00159             if(RxIrqCnt != (g_pCB)->RxDoneCnt) {                
00160                 _SlDrvMsgReadSpawnCtx(0);
00161                 //pF(0);/*(pValue);*//*Function pointer*/                
00162         }
00163             pE->pEntry = NULL;
00164             pE->pValue = NULL;
00165         }
00166     }
00167         
00168         return NONOS_RET_OK;
00169 }
00170 /*
00171 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjCreate(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_CLEAR_VALUE)
00172     
00173     *pSemObj = Value;
00174     return NONOS_RET_OK;
00175 
00176 }
00177 */
00178 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjDelete(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,0)
00179     
00180     *pSemObj = Value;
00181     return NONOS_RET_OK;
00182 }
00183 
00184 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjSignal(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE)
00185 
00186     *pSemObj = Value;
00187     return NONOS_RET_OK;
00188 }
00189     
00190 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjSignalFromIRQ(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE)
00191 
00192         *pSemObj = Value;
00193         return NONOS_RET_OK;
00194 }
00195 /*    
00196 _SlNonOsRetVal_t cc3100_nonos::sl_LockObjCreate(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE)
00197 
00198         *pSemObj = Value;
00199         return NONOS_RET_OK;
00200 }        
00201 */        
00202 _SlNonOsRetVal_t cc3100_nonos::sl_LockObjDelete(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pLockObj,0)
00203 
00204     *pSemObj = Value;
00205     return NONOS_RET_OK;
00206 }    
00207            
00208 _SlNonOsRetVal_t cc3100_nonos::sl_LockObjUnlock(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t Value){//_SlNonOsSemSet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE)
00209 
00210     *pSemObj = Value;
00211     return NONOS_RET_OK;
00212 }    
00213     
00214 _SlNonOsRetVal_t cc3100_nonos::sl_SyncObjWait(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout){//_SlNonOsSemGet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE,NON_OS_SYNC_OBJ_CLEAR_VALUE,Timeout)
00215 
00216 #ifdef _SlSyncWaitLoopCallback
00217     _SlNonOsTime_t timeOutRequest = Timeout; 
00218 #endif     
00219     
00220     while (Timeout > 0) {
00221         if (WaitValue == *pSyncObj) {
00222             *pSyncObj = SetValue;            
00223             break;
00224         }
00225         if (Timeout != NONOS_WAIT_FOREVER) {
00226             Timeout--;
00227         }
00228         _SlNonOsMainLoopTask();
00229         
00230 #ifdef _SlSyncWaitLoopCallback
00231         if( (__NON_OS_SYNC_OBJ_SIGNAL_VALUE == WaitValue) && (timeOutRequest != NONOS_NO_WAIT) ) {
00232             if (WaitValue == *pSyncObj) {
00233                 *pSyncObj = SetValue;
00234                 break;
00235             }
00236             _SlSyncWaitLoopCallback();
00237         }
00238 #endif
00239 
00240     }
00241 
00242     if (0 == Timeout) {        
00243         return NONOS_RET_ERR;
00244     } else {        
00245         return NONOS_RET_OK;
00246     }
00247 }
00248 
00249 _SlNonOsRetVal_t cc3100_nonos::sl_LockObjLock(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout){//_SlNonOsSemGet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE,NON_OS_LOCK_OBJ_LOCK_VALUE,Timeout)
00250 
00251 #ifdef _SlSyncWaitLoopCallback
00252     _SlNonOsTime_t timeOutRequest = Timeout; 
00253 #endif    
00254     
00255     while (Timeout > 0) {
00256         if (WaitValue == *pSyncObj) {
00257             *pSyncObj = SetValue;            
00258             break;
00259         }
00260         if (Timeout != NONOS_WAIT_FOREVER) {
00261             Timeout--;
00262         }
00263         _SlNonOsMainLoopTask();
00264         
00265 #ifdef _SlSyncWaitLoopCallback
00266         if( (__NON_OS_SYNC_OBJ_SIGNAL_VALUE == WaitValue) && (timeOutRequest != NONOS_NO_WAIT) ) {
00267             if (WaitValue == *pSyncObj) {
00268                 *pSyncObj = SetValue;
00269                 break;
00270             }
00271             _SlSyncWaitLoopCallback();
00272         }
00273 #endif
00274 
00275     }
00276 
00277     if (0 == Timeout) {        
00278         return NONOS_RET_ERR;
00279     } else {        
00280         return NONOS_RET_OK;
00281     }
00282 }
00283 
00284 }//namespace mbed_cc3100
00285 
00286 #endif /*(SL_PLATFORM != SL_PLATFORM_NON_OS)*/
00287 
00288 
00289 
00290 
00291