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.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                         =  NONOS_RET_OK;
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 #undef sl_SyncObjCreate
00225 #define sl_SyncObjCreate(pSyncObj,pName)           _SlNonOsSemSet(pSyncObj,NON_OS_SYNC_OBJ_CLEAR_VALUE)
00226 
00227 #undef sl_LockObjCreate
00228 #define sl_LockObjCreate(pLockObj,pName)            _SlNonOsSemSet(pLockObj,NON_OS_LOCK_OBJ_UNLOCK_VALUE)
00229 /*
00230 #undef sl_Spawn
00231 #define sl_Spawn(pEntry,pValue,flags)               _nonos._SlNonOsSpawn(pEntry,pValue,flags)
00232 
00233 #undef _SlTaskEntry
00234 #define _SlTaskEntry                                _nonos._SlNonOsMainLoopTask
00235 */
00236     
00237 /*!
00238     \brief type definition for the return values of this adaptation layer
00239 */
00240 typedef int8_t _SlNonOsRetVal_t;
00241 
00242 /*!
00243     \brief type definition for a time value
00244 */
00245 typedef uint8_t _SlNonOsTime_t;
00246 
00247 /*!
00248     \brief  type definition for a sync object container
00249 
00250     Sync object is object used to synchronize between two threads or thread and interrupt handler.
00251     One thread is waiting on the object and the other thread send a signal, which then
00252     release the waiting thread.
00253     The signal must be able to be sent from interrupt context.
00254     This object is generally implemented by binary semaphore or events.
00255 */
00256 typedef uint8_t _SlNonOsSemObj_t;   
00257     
00258 class cc3100_driver;
00259 
00260 class cc3100_nonos
00261 {
00262 
00263 public:
00264 
00265     cc3100_nonos(cc3100_driver &driver);
00266 
00267     ~cc3100_nonos();
00268 
00269     /*!
00270         \brief  This function call the pEntry callback from a different context
00271 
00272         \param  pEntry      -   pointer to the entry callback function
00273 
00274         \param  pValue      -   pointer to any type of memory structure that would be
00275                                 passed to pEntry callback from the execution thread.
00276 
00277         \param  flags       -   execution flags - reserved for future usage
00278 
00279         \return upon successful registration of the spawn the function return 0
00280                 (the function is not blocked till the end of the execution of the function
00281                 and could be returned before the execution is actually completed)
00282                 Otherwise, a negative value indicating the error code shall be returned
00283         \note
00284         \warning
00285     */
00286     _SlNonOsRetVal_t _SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , uint32_t flags);
00287 
00288 
00289     /*!
00290         \brief  This function must be called from the main loop in non-os paltforms
00291 
00292         \param  None
00293 
00294         \return 0 - No more activities
00295                 1 - Activity still in progress
00296         \note
00297         \warning
00298     */
00299     _SlNonOsRetVal_t _SlNonOsMainLoopTask(void);
00300 
00301     _SlNonOsRetVal_t _SlNonOsSemGet(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t WaitValue, _SlNonOsSemObj_t SetValue, _SlNonOsTime_t Timeout);
00302     _SlNonOsRetVal_t _SlNonOsSemSet(_SlNonOsSemObj_t* pSemObj , _SlNonOsSemObj_t Value);
00303 //    _SlNonOsRetVal_t _SlNonOsSpawn(_SlSpawnEntryFunc_t pEntry , void* pValue , uint32_t flags);
00304 //    _SlNonOsRetVal_t sl_SyncObjCreate(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t NON_OS_SYNC_OBJ_CLEAR_VALUE);
00305     _SlNonOsRetVal_t sl_SyncObjDelete(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t );
00306     _SlNonOsRetVal_t sl_SyncObjSignal(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t NON_OS_SYNC_OBJ_SIGNAL_VALUE);
00307     _SlNonOsRetVal_t sl_SyncObjSignalFromIRQ(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t NON_OS_SYNC_OBJ_SIGNAL_VALUE);
00308 //    _SlNonOsRetVal_t sl_LockObjCreate(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t NON_OS_LOCK_OBJ_UNLOCK_VALUE);
00309     _SlNonOsRetVal_t sl_LockObjDelete(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t );
00310     _SlNonOsRetVal_t sl_LockObjUnlock(_SlNonOsSemObj_t* pSemObj, _SlNonOsSemObj_t NON_OS_LOCK_OBJ_UNLOCK_VALUE);
00311     _SlNonOsRetVal_t sl_SyncObjWait(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t NON_OS_SYNC_OBJ_SIGNAL_VALUE, _SlNonOsSemObj_t NON_OS_SYNC_OBJ_CLEAR_VALUE, _SlNonOsTime_t Timeout);
00312     _SlNonOsRetVal_t sl_LockObjLock(_SlNonOsSemObj_t* pSyncObj, _SlNonOsSemObj_t NON_OS_LOCK_OBJ_UNLOCK_VALUE, _SlNonOsSemObj_t NON_OS_LOCK_OBJ_LOCK_VALUE, _SlNonOsTime_t Timeout);
00313     
00314 
00315 #if (defined(_SlSyncWaitLoopCallback))
00316     void _SlSyncWaitLoopCallback(void);
00317 #endif
00318 
00319 private:
00320 
00321     cc3100_driver &_driver;
00322 
00323 };//class
00324 
00325 }//namespace mbed_cc3100
00326 
00327 #endif /* !SL_PLATFORM_MULTI_THREADED */
00328 
00329 
00330 
00331 #endif
00332