TI's CC3100 websocket camera demo with Arducam mini ov5642 and freertos. Should work with other M3's. Work in progress test demo.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cc3100_nonos.h Source File

cc3100_nonos.h

00001 /*
00002  * nonos.h - 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 #ifndef NONOS_H_
00038 #define NONOS_H_
00039 
00040 #include "cc3100_simplelink.h"
00041     
00042 /*****************************************************************************/
00043 /* Macro declarations                                                        */
00044 /*****************************************************************************/
00045 
00046 #ifndef SL_PLATFORM_MULTI_THREADED
00047 
00048 namespace mbed_cc3100 {
00049 
00050 /* This function call the user defined function, if defined, from the sync wait loop  */
00051 /* The use case of this function is to allow nonos system to call a user function to put the device into sleep */
00052 /* The wake up should be activated after getting an interrupt from the device to Host */
00053 /* The user function must return without blocking to prevent a delay on the event handling */
00054 /*
00055 #define _SlSyncWaitLoopCallback  UserSleepFunction
00056 */
00057 
00058 const uint8_t NONOS_WAIT_FOREVER             =  0xFF;
00059 const uint8_t NONOS_NO_WAIT                  =  0x00;
00060 
00061 const uint8_t NONOS_RET_OK                   =  0;
00062 const int8_t  NONOS_RET_ERR                  =  0xFF;
00063 //const uint8_t OSI_OK                         =  0;
00064 
00065 const uint8_t NON_OS_SYNC_OBJ_CLEAR_VALUE    =  0x11;
00066 const uint8_t NON_OS_SYNC_OBJ_SIGNAL_VALUE   =  0x22;
00067 const uint8_t NON_OS_LOCK_OBJ_UNLOCK_VALUE   =  0x33;
00068 const uint8_t NON_OS_LOCK_OBJ_LOCK_VALUE     =  0x44;
00069 
00070 #define _SlTime_t               _SlNonOsTime_t
00071 
00072 #define _SlSyncObj_t            _SlNonOsSemObj_t
00073 
00074 #define _SlLockObj_t            _SlNonOsSemObj_t
00075 
00076 const uint8_t SL_OS_WAIT_FOREVER   =   NONOS_WAIT_FOREVER;
00077 
00078 const uint8_t SL_OS_RET_CODE_OK    =   NONOS_RET_OK;
00079 
00080 const uint8_t SL_OS_NO_WAIT        =   NONOS_NO_WAIT;
00081 
00082 
00083     /*****************************************************************************/
00084     /* Function prototypes                                                       */
00085     /*****************************************************************************/
00086 
00087     /*!
00088         \brief  This function creates a sync object
00089 
00090         The sync object is used for synchronization between different thread or ISR and
00091         a thread.
00092 
00093         \param  pSyncObj    -   pointer to the sync object control block
00094 
00095         \return upon successful creation the function return 0
00096                 Otherwise, a negative value indicating the error code shall be returned
00097         \note
00098         \warning
00099     */
00100 #define _SlNonOsSyncObjCreate(pSyncObj)         _SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_CLEAR_VALUE)
00101 
00102     /*!
00103         \brief  This function deletes a sync object
00104 
00105         \param  pSyncObj    -   pointer to the sync object control block
00106 
00107         \return upon successful deletion the function should return 0
00108                 Otherwise, a negative value indicating the error code shall be returned
00109         \note
00110         \warning
00111     */
00112 #define _SlNonOsSyncObjDelete(pSyncObj)         _SlNonOsSemSet(pSyncObj,0)//
00113 
00114     /*!
00115         \brief      This function generates a sync signal for the object.
00116 
00117         All suspended threads waiting on this sync object are resumed
00118 
00119         \param      pSyncObj    -   pointer to the sync object control block
00120 
00121         \return     upon successful signaling the function should return 0
00122                     Otherwise, a negative value indicating the error code shall be returned
00123         \note       the function could be called from ISR context
00124         \warning
00125     */
00126 #define _SlNonOsSyncObjSignal(pSyncObj)         _SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE)//
00127 
00128     /*!
00129         \brief  This function waits for a sync signal of the specific sync object
00130 
00131         \param  pSyncObj    -   pointer to the sync object control block
00132         \param  Timeout     -   numeric value specifies the maximum number of mSec to
00133                                 stay suspended while waiting for the sync signal
00134                                 Currently, the simple link driver uses only two values:
00135                                     - NONOS_WAIT_FOREVER
00136                                     - NONOS_NO_WAIT
00137 
00138         \return upon successful reception of the signal within the timeout window return 0
00139                 Otherwise, a negative value indicating the error code shall be returned
00140         \note
00141         \warning
00142     */
00143 #define _SlNonOsSyncObjWait(pSyncObj,Timeout)   _SlNonOsSemGet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE,NON_OS_SYNC_OBJ_CLEAR_VALUE,Timeout)//
00144 
00145     /*!
00146         \brief  This function clears a sync object
00147 
00148         \param  pSyncObj    -   pointer to the sync object control block
00149 
00150         \return upon successful clearing the function should return 0
00151                 Otherwise, a negative value indicating the error code shall be returned
00152         \note
00153         \warning
00154     */
00155 #define _SlNonOsSyncObjClear(pSyncObj)          _SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_CLEAR_VALUE)//
00156 
00157     /*!
00158         \brief  This function creates a locking object.
00159 
00160         The locking object is used for protecting a shared resources between different
00161         threads.
00162 
00163         \param  pLockObj    -   pointer to the locking object control block
00164 
00165         \return upon successful creation the function should return 0
00166                 Otherwise, a negative value indicating the error code shall be returned
00167         \note
00168         \warning
00169     */
00170 #define _SlNonOsLockObjCreate(pLockObj)         _SlNonOsSemSet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE)
00171 
00172     /*!
00173         \brief  This function deletes a locking object.
00174 
00175         \param  pLockObj    -   pointer to the locking object control block
00176 
00177         \return upon successful deletion the function should return 0
00178                 Otherwise, a negative value indicating the error code shall be returned
00179         \note
00180         \warning
00181     */
00182 #define _SlNonOsLockObjDelete(pLockObj)         _SlNonOsSemSet(pLockObj,0)//
00183 
00184     /*!
00185         \brief  This function locks a locking object.
00186 
00187         All other threads that call this function before this thread calls
00188         the _SlNonOsLockObjUnlock would be suspended
00189 
00190         \param  pLockObj    -   pointer to the locking object control block
00191         \param  Timeout     -   numeric value specifies the maximum number of mSec to
00192                                 stay suspended while waiting for the locking object
00193                                 Currently, the simple link driver uses only two values:
00194                                     - NONOS_WAIT_FOREVER
00195                                     - NONOS_NO_WAIT
00196 
00197 
00198         \return upon successful reception of the locking object the function should return 0
00199                 Otherwise, a negative value indicating the error code shall be returned
00200         \note
00201         \warning
00202     */
00203 #define _SlNonOsLockObjLock(pLockObj,Timeout)   _SlNonOsSemGet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE,NON_OS_LOCK_OBJ_LOCK_VALUE,Timeout)//
00204 
00205     /*!
00206         \brief  This function unlock a locking object.
00207 
00208         \param  pLockObj    -   pointer to the locking object control block
00209 
00210         \return upon successful unlocking the function should return 0
00211                 Otherwise, a negative value indicating the error code shall be returned
00212         \note
00213         \warning
00214     */
00215 #define _SlNonOsLockObjUnlock(pLockObj)         _SlNonOsSemSet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE)//
00216 
00217 /*****************************************************************************
00218 
00219     Overwrite SimpleLink driver OS adaptation functions
00220 
00221 
00222  *****************************************************************************/
00223  
00224 //class cc3100_nonos _nonos;
00225 
00226 #undef sl_SyncObjCreate
00227 #define sl_SyncObjCreate(pSyncObj,pName)            _SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_CLEAR_VALUE)
00228 
00229 #undef sl_SyncObjDelete
00230 #define sl_SyncObjDelete(pSyncObj)                  _SlNonOsSemSet(pSyncObj,0)
00231 
00232 #undef sl_SyncObjSignal
00233 #define sl_SyncObjSignal(pSyncObj)                  _SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE)
00234 
00235 #undef sl_SyncObjSignalFromIRQ
00236 #define sl_SyncObjSignalFromIRQ(pSyncObj)           _SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE)
00237 
00238 #undef sl_SyncObjWait
00239 #define sl_SyncObjWait(pSyncObj,Timeout)            _SlNonOsSemGet(pSyncObj,NON_OS_SYNC_OBJ_SIGNAL_VALUE,NON_OS_SYNC_OBJ_CLEAR_VALUE,Timeout)
00240 
00241 #undef sl_LockObjCreate
00242 #define sl_LockObjCreate(pLockObj,pName)            _SlNonOsSemSet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE)
00243 
00244 #undef sl_LockObjDelete
00245 #define sl_LockObjDelete(pLockObj)                  _SlNonOsSemSet(pLockObj,0)
00246 
00247 #undef sl_LockObjLock
00248 #define sl_LockObjLock(pLockObj,Timeout)            _SlNonOsSemGet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE,NON_OS_LOCK_OBJ_LOCK_VALUE,Timeout)
00249 
00250 #undef sl_LockObjUnlock
00251 #define sl_LockObjUnlock(pLockObj)                  _SlNonOsSemSet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE)
00252 /*
00253 #undef sl_Spawn
00254 #define sl_Spawn(pEntry,pValue,flags)               _nonos._SlNonOsSpawn(pEntry,pValue,flags)
00255 
00256 #undef _SlTaskEntry
00257 #define _SlTaskEntry                                _nonos._SlNonOsMainLoopTask
00258 */  
00259 /*!
00260     \brief type definition for the return values of this adaptation layer
00261 */
00262 typedef int8_t _SlNonOsRetVal_t;
00263 
00264 /*!
00265     \brief type definition for a time value
00266 */
00267 typedef uint8_t _SlNonOsTime_t;
00268 
00269 /*!
00270     \brief  type definition for a sync object container
00271 
00272     Sync object is object used to synchronize between two threads or thread and interrupt handler.
00273     One thread is waiting on the object and the other thread send a signal, which then
00274     release the waiting thread.
00275     The signal must be able to be sent from interrupt context.
00276     This object is generally implemented by binary semaphore or events.
00277 */
00278 typedef uint8_t _SlNonOsSemObj_t;   
00279     
00280 class cc3100_driver;
00281 
00282 class cc3100_nonos
00283 {
00284 
00285 public:
00286 
00287     cc3100_nonos(cc3100_driver &driver);
00288 
00289     ~cc3100_nonos();
00290 
00291     /*!
00292         \brief  This function call the pEntry callback from a different context
00293 
00294         \param  pEntry      -   pointer to the entry callback function
00295 
00296         \param  pValue      -   pointer to any type of memory structure that would be
00297                                 passed to pEntry callback from the execution thread.
00298 
00299         \param  flags       -   execution flags - reserved for future usage
00300 
00301         \return upon successful registration of the spawn the function return 0
00302                 (the function is not blocked till the end of the execution of the function
00303                 and could be returned before the execution is actually completed)
00304                 Otherwise, a negative value indicating the error code shall be returned
00305         \note
00306         \warning
00307     */
00308     _SlNonOsRetVal_t _SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , uint32_t flags);
00309 
00310 
00311     /*!
00312         \brief  This function must be called from the main loop in non-os paltforms
00313 
00314         \param  None
00315 
00316         \return 0 - No more activities
00317                 1 - Activity still in progress
00318         \note
00319         \warning
00320     */
00321     _SlNonOsRetVal_t _SlNonOsMainLoopTask(void);
00322 
00323     _SlNonOsRetVal_t _SlNonOsSemGet(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout);
00324     _SlNonOsRetVal_t _SlNonOsSemSet(_SlNonOsSemObj_t* pSemObj , _SlNonOsSemObj_t Value);
00325            
00326 
00327 #if (defined(_SlSyncWaitLoopCallback))
00328     void _SlSyncWaitLoopCallback(void);
00329 #endif
00330 
00331 private:
00332 
00333     cc3100_driver &_driver;
00334 
00335 };//class
00336 
00337 //extern _SlNonOsRetVal_t _SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , uint32_t flags);
00338 
00339 }//namespace mbed_cc3100
00340 
00341 #endif /* !SL_PLATFORM_MULTI_THREADED */
00342 
00343 
00344 
00345 #endif
00346