DeepCover Embedded Security in IoT: Public-key Secured Data Paths

Dependencies:   MaximInterface

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers nonos.h Source File

nonos.h

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