TI's CC3100 host driver and demo. Experimental and a work in progress.

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