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 osi.h Source File

osi.h

00001 //*****************************************************************************
00002 // osi.h
00003 //
00004 // MACRO and Function prototypes for TI-RTOS and Free-RTOS API calls
00005 //
00006 // Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ 
00007 // 
00008 // 
00009 //  Redistribution and use in source and binary forms, with or without 
00010 //  modification, are permitted provided that the following conditions 
00011 //  are met:
00012 //
00013 //    Redistributions of source code must retain the above copyright 
00014 //    notice, this list zof conditions and the following disclaimer.
00015 //
00016 //    Redistributions in binary form must reproduce the above copyright
00017 //    notice, this list of conditions and the following disclaimer in the 
00018 //    documentation and/or other materials provided with the   
00019 //    distribution.
00020 //
00021 //    Neither the name of Texas Instruments Incorporated nor the names of
00022 //    its contributors may be used to endorse or promote products derived
00023 //    from this software without specific prior written permission.
00024 //
00025 //  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00026 //  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00027 //  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
00028 //  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
00029 //  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00030 //  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00031 //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00032 //  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00033 //  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00034 //  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00035 //  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 //*****************************************************************************
00038 
00039 #ifndef __OSI_H__
00040 #define __OSI_H__
00041 
00042 #ifdef  __cplusplus
00043 extern "C" {
00044 #endif
00045 
00046 #include "portable.h"
00047   
00048 #define OSI_WAIT_FOREVER            (0xFFFFFFFF)
00049 
00050 #define OSI_NO_WAIT                 (0)
00051 
00052 typedef int OsiReturnVal_e;
00053 
00054 #define OSI_OK                  (0)
00055 #define OSI_FAILURE             (-1)
00056 #define OSI_OPERATION_FAILED    (-2)
00057 #define OSI_ABORTED             (-3)
00058 #define OSI_INVALID_PARAMS      (-4)
00059 #define OSI_MEMORY_ALLOCATION_FAILURE    (-5)
00060 #define OSI_TIMEOUT                      (-6)
00061 #define OSI_EVENTS_IN_USE                (-7)
00062 #define OSI_EVENT_OPEARTION_FAILURE      (-8)
00063 
00064 /*typedef enum
00065 {
00066   OSI_OK = 0,
00067   OSI_FAILURE = -1,
00068   OSI_OPERATION_FAILED = -2,
00069   OSI_ABORTED = -3,
00070   OSI_INVALID_PARAMS = -4,
00071   OSI_MEMORY_ALLOCATION_FAILURE = -5,
00072   OSI_TIMEOUT = -6,
00073   OSI_EVENTS_IN_USE = -7,
00074   OSI_EVENT_OPEARTION_FAILURE = -8
00075 }OsiReturnVal_e;*/
00076 
00077 
00078 //#define ENTER_CRITICAL_SECTION            osi_EnterCritical()
00079 //#define EXIT_CRITICAL_SECTION         osi_ExitCritical()
00080 
00081 typedef void* OsiMsgQ_t;
00082 
00083  /*!
00084     \brief type definition for a time value
00085 
00086     \note   On each porting or platform the type could be whatever is needed - integer, pointer to structure etc.
00087 */
00088 typedef uint32_t OsiTime_t;
00089 //typedef unsigned long OsiTime_t;
00090 /*!
00091     \brief  type definition for a sync object container
00092 
00093     Sync object is object used to synchronize between two threads or thread and interrupt handler.
00094     One thread is waiting on the object and the other thread send a signal, which then
00095     release the waiting thread.
00096     The signal must be able to be sent from interrupt context.
00097     This object is generally implemented by binary semaphore or events.
00098 
00099     \note   On each porting or platform the type could be whatever is needed - integer, structure etc.
00100 */
00101 //typedef unsigned int OsiSyncObj_t;
00102 typedef void * OsiSyncObj_t;
00103 
00104 /*!
00105     \brief  type definition for a locking object container
00106 
00107     Locking object are used to protect a resource from mutual accesses of two or more threads.
00108     The locking object should support re-entrant locks by a signal thread.
00109     This object is generally implemented by mutex semaphore
00110 
00111     \note   On each porting or platform the type could be whatever is needed - integer, structure etc.
00112 */
00113 //typedef unsigned int OsiLockObj_t;
00114 typedef void * OsiLockObj_t;
00115 
00116 /*!
00117     \brief  type definition for a spawn entry callback
00118 
00119     the spawn mechanism enable to run a function on different context.
00120     This mechanism allow to transfer the execution context from interrupt context to thread context
00121     or changing the context from an unknown user thread to general context.
00122     The implementation of the spawn mechanism depends on the user's system requirements and could varies
00123     from implementation of serialized execution using single thread to creating thread per call
00124 
00125     \note   The stack size of the execution thread must be at least of TBD bytes!
00126 */
00127 typedef void (*P_OSI_SPAWN_ENTRY)(void* pValue);
00128 
00129 typedef void (*P_OSI_EVENT_HANDLER)(void* pValue);
00130 
00131 typedef void (*P_OSI_TASK_ENTRY)(void* pValue);
00132 
00133 typedef void (*P_OSI_INTR_ENTRY)(void);
00134 
00135 typedef void* OsiTaskHandle;
00136 
00137 /*!
00138     \brief  This function registers an interrupt in NVIC table
00139 
00140     The sync object is used for synchronization between different thread or ISR and
00141     a thread.
00142 
00143     \param  iIntrNum    -   Interrupt number to register
00144     \param  pEntry      -   Pointer to the interrupt handler
00145 
00146     \return upon successful creation the function should return 0
00147             Otherwise, a negative value indicating the error code shall be returned
00148     \note
00149     \warning
00150 */
00151 OsiReturnVal_e osi_InterruptRegister(int iIntrNum,P_OSI_INTR_ENTRY pEntry,unsigned char ucPriority);
00152 
00153 /*!
00154     \brief  This function De-registers an interrupt in NVIC table
00155 
00156     \param  iIntrNum    -   Interrupt number to register
00157     \param  pEntry      -   Pointer to the interrupt handler
00158 
00159     \return upon successful creation the function should return Positive number
00160             Otherwise, a negative value indicating the error code shall be returned
00161     \note
00162     \warning
00163 */
00164 void osi_InterruptDeRegister(int iIntrNum);
00165 
00166 
00167 /*!
00168     \brief  This function creates a sync object
00169 
00170     The sync object is used for synchronization between different thread or ISR and
00171     a thread.
00172 
00173     \param  pSyncObj    -   pointer to the sync object control block
00174 
00175     \return upon successful creation the function should return 0
00176             Otherwise, a negative value indicating the error code shall be returned
00177     \note
00178     \warning
00179 */
00180 OsiReturnVal_e osi_SyncObjCreate(OsiSyncObj_t* pSyncObj);
00181 
00182 
00183 /*!
00184     \brief  This function deletes a sync object
00185 
00186     \param  pSyncObj    -   pointer to the sync object control block
00187 
00188     \return upon successful deletion the function should return 0
00189             Otherwise, a negative value indicating the error code shall be returned
00190     \note
00191     \warning
00192 */
00193 OsiReturnVal_e osi_SyncObjDelete(OsiSyncObj_t* pSyncObj);
00194 
00195 /*!
00196     \brief      This function generates a sync signal for the object.
00197 
00198     All suspended threads waiting on this sync object are resumed
00199 
00200     \param      pSyncObj    -   pointer to the sync object control block
00201 
00202     \return     upon successful signalling the function should return 0
00203                 Otherwise, a negative value indicating the error code shall be returned
00204     \note       the function could be called from ISR context
00205     \warning
00206 */
00207 OsiReturnVal_e osi_SyncObjSignal(OsiSyncObj_t* pSyncObj);
00208 
00209 /*!
00210     \brief      This function generates a sync signal for the object.
00211                 from ISR context.
00212 
00213     All suspended threads waiting on this sync object are resumed
00214 
00215     \param      pSyncObj    -   pointer to the sync object control block
00216 
00217     \return     upon successful signalling the function should return 0
00218                 Otherwise, a negative value indicating the error code shall be returned
00219     \note       the function is called from ISR context
00220     \warning
00221 */
00222 OsiReturnVal_e osi_SyncObjSignalFromISR(OsiSyncObj_t* pSyncObj);
00223 
00224 /*!
00225     \brief  This function waits for a sync signal of the specific sync object
00226 
00227     \param  pSyncObj    -   pointer to the sync object control block
00228     \param  Timeout     -   numeric value specifies the maximum number of mSec to
00229                             stay suspended while waiting for the sync signal
00230                             Currently, the simple link driver uses only two values:
00231                                 - OSI_WAIT_FOREVER
00232                                 - OSI_NO_WAIT
00233 
00234     \return upon successful reception of the signal within the timeout window return 0
00235             Otherwise, a negative value indicating the error code shall be returned
00236     \note
00237     \warning
00238 */
00239 OsiReturnVal_e osi_SyncObjWait(OsiSyncObj_t* pSyncObj , OsiTime_t Timeout);
00240 
00241 /*!
00242     \brief  This function clears a sync object
00243 
00244     \param  pSyncObj    -   pointer to the sync object control block
00245 
00246     \return upon successful clearing the function should return 0
00247             Otherwise, a negative value indicating the error code shall be returned
00248     \note
00249     \warning
00250 */
00251 OsiReturnVal_e osi_SyncObjClear(OsiSyncObj_t* pSyncObj);
00252 
00253 /*!
00254     \brief  This function creates a locking object.
00255 
00256     The locking object is used for protecting a shared resources between different
00257     threads.
00258 
00259     \param  pLockObj    -   pointer to the locking object control block
00260 
00261     \return upon successful creation the function should return 0
00262             Otherwise, a negative value indicating the error code shall be returned
00263     \note
00264     \warning
00265 */
00266 OsiReturnVal_e osi_LockObjCreate(OsiLockObj_t* pLockObj);
00267 
00268 /*!
00269     \brief  This function deletes a locking object.
00270 
00271     \param  pLockObj    -   pointer to the locking object control block
00272 
00273     \return upon successful deletion the function should return 0
00274             Otherwise, a negative value indicating the error code shall be returned
00275     \note
00276     \warning
00277 */
00278 OsiReturnVal_e osi_LockObjDelete(OsiLockObj_t* pLockObj);
00279 
00280 /*!
00281     \brief  This function locks a locking object.
00282 
00283     All other threads that call this function before this thread calls
00284     the osi_LockObjUnlock would be suspended
00285 
00286     \param  pLockObj    -   pointer to the locking object control block
00287     \param  Timeout     -   numeric value specifies the maximum number of mSec to
00288                             stay suspended while waiting for the locking object
00289                             Currently, the simple link driver uses only two values:
00290                                 - OSI_WAIT_FOREVER
00291                                 - OSI_NO_WAIT
00292 
00293 
00294     \return upon successful reception of the locking object the function should return 0
00295             Otherwise, a negative value indicating the error code shall be returned
00296     \note
00297     \warning
00298 */
00299 OsiReturnVal_e osi_LockObjLock(OsiLockObj_t* pLockObj , OsiTime_t Timeout);
00300 
00301 /*!
00302     \brief  This function unlock a locking object.
00303 
00304     \param  pLockObj    -   pointer to the locking object control block
00305 
00306     \return upon successful unlocking the function should return 0
00307             Otherwise, a negative value indicating the error code shall be returned
00308     \note
00309     \warning
00310 */
00311 OsiReturnVal_e osi_LockObjUnlock(OsiLockObj_t* pLockObj);
00312 
00313 
00314 /*!
00315     \brief  This function call the pEntry callback from a different context
00316 
00317     \param  pEntry      -   pointer to the entry callback function
00318 
00319     \param  pValue      -   pointer to any type of memory structure that would be
00320                             passed to pEntry callback from the execution thread.
00321 
00322     \param  flags       -   execution flags - reserved for future usage
00323 
00324     \return upon successful registration of the spawn the function should return 0
00325             (the function is not blocked till the end of the execution of the function
00326             and could be returned before the execution is actually completed)
00327             Otherwise, a negative value indicating the error code shall be returned
00328     \note
00329     \warning
00330 */
00331 /*!
00332     \brief  This function creates a Task.
00333 
00334     Creates a new Task and add it to the last of tasks that are ready to run
00335 
00336     \param  pEntry  -   pointer to the Task Function
00337     \param  pcName  -   Task Name String
00338     \param  usStackDepth    -   Stack Size Stack Size in 32-bit long words
00339     \param  pvParameters    -   pointer to structure to be passed to the Task Function
00340     \param  uxPriority  -   Task Priority
00341 
00342     \return upon successful unlocking the function should return 0
00343             Otherwise, a negative value indicating the error code shall be returned
00344     \note
00345     \warning
00346 */
00347 OsiReturnVal_e osi_TaskCreate(P_OSI_TASK_ENTRY pEntry,const signed char * const pcName,unsigned short usStackDepth,void *pvParameters,uint32_t uxPriority,OsiTaskHandle *pTaskHandle);
00348 
00349 /*!
00350     \brief  This function Deletes a Task.
00351 
00352     Deletes a  Task and remove it from list of running task
00353 
00354     \param  pTaskHandle -   Task Handle
00355 
00356     \note
00357     \warning
00358 */
00359 void osi_TaskDelete(OsiTaskHandle* pTaskHandle);
00360 
00361 /*!
00362     \brief  This function call the pEntry callback from a different context
00363 
00364     \param  pEntry      -   pointer to the entry callback function
00365 
00366     \param  pValue      -   pointer to any type of memory structure that would be
00367                             passed to pEntry callback from the execution thread.
00368 
00369     \param  flags       -   execution flags - reserved for future usage
00370 
00371     \return upon successful registration of the spawn the function should return 0
00372             (the function is not blocked till the end of the execution of the function
00373             and could be returned before the execution is actually completed)
00374             Otherwise, a negative value indicating the error code shall be returned
00375     \note
00376     \warning
00377 */
00378 OsiReturnVal_e osi_Spawn(P_OSI_SPAWN_ENTRY pEntry , void* pValue , uint32_t flags);
00379 
00380 
00381 /*******************************************************************************
00382 
00383 This function creates a message queue that is typically used for inter thread
00384 communication. 
00385 
00386 Parameters:
00387 
00388     pMsgQ       -   pointer to the message queue control block
00389     pMsgQName   -   pointer to the name of the message queue
00390     MsgSize     -   the size of the message. 
00391 
00392             NOTICE: THE MESSGAE SIZE MUST BE SMALLER THAN 16
00393 
00394     MaxMsgs     -   maximum number of messages.
00395 
00396 Please note that this function allocates the entire memory required 
00397 for the maximum number of messages (MsgSize * MaxMsgs). 
00398 
00399 ********************************************************************************/
00400 OsiReturnVal_e osi_MsgQCreate(OsiMsgQ_t*        pMsgQ , 
00401                               char*             pMsgQName,
00402                               uint32_t      MsgSize,
00403                               uint32_t      MaxMsgs);
00404 
00405 /*******************************************************************************
00406 
00407 This function deletes a specific message queue.
00408 All threads suspended waiting for a message from this queue are resumed with
00409 an error return value. 
00410 
00411 Parameters:
00412 
00413     pMsgQ       -   pointer to the message queue control block
00414 
00415 ********************************************************************************/
00416 OsiReturnVal_e osi_MsgQDelete(OsiMsgQ_t* pMsgQ);
00417 
00418 
00419 /*******************************************************************************
00420 
00421 This function writes a message to a specific message queue.
00422 
00423 Notice that the message is copied to the queue from the memory area specified 
00424 by pMsg pointer.
00425 
00426 --------------------------------------------------------------------------------
00427 THIS FUNCTION COULD BE CALLED FROM ISR AS LONG AS THE TIMEOUT PARAMETER IS 
00428 SET TO "OSI_NO_WAIT"
00429 --------------------------------------------------------------------------------
00430 
00431 Parameters:
00432 
00433     pMsgQ       -   pointer to the message queue control block
00434     pMsg        -   pointer to the message
00435     Timeout     -   numeric value specifies the maximum number of mSec to stay 
00436                     suspended while waiting for available space for the message
00437 
00438 ********************************************************************************/
00439 OsiReturnVal_e osi_MsgQWrite(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout);
00440 
00441 
00442 /*******************************************************************************
00443 
00444 This function retrieves a message from the specified message queue. The
00445 retrieved message is copied from the queue into the memory area specified by 
00446 the pMsg pointer 
00447 
00448 Parameters:
00449 
00450     pMsgQ       -   pointer to the message queue control block
00451     pMsg        -   pointer that specify the location where to copy the message
00452     Timeout     -   numeric value specifies the maximum number of mSec to stay 
00453                     suspended while waiting for a message to be available
00454 
00455 ********************************************************************************/
00456 OsiReturnVal_e osi_MsgQRead(OsiMsgQ_t* pMsgQ, void* pMsg , OsiTime_t Timeout);
00457 
00458 /*!
00459     \brief  This function starts the OS Scheduler
00460     \param  - void
00461     \return - void
00462     \note
00463     \warning
00464 */
00465 void osi_start();
00466 
00467 /*!
00468     \brief                  Allocates Memory on Heap
00469     \param  Size        -   Size of the Buffer to be allocated
00470     \sa
00471     \note
00472     \warning
00473 */
00474 void * mem_Malloc(uint32_t Size);
00475 
00476 
00477 /*!
00478     \brief              Deallocates Memory
00479     \param  pMem        -   Pointer to the Buffer to be freed
00480     \return void
00481     \sa
00482     \note
00483     \warning
00484 */
00485 void mem_Free(void *pMem);
00486 
00487 
00488 /*!
00489     \brief              Set Memory
00490     \param  pBuf        -   Pointer to the Buffer
00491     \param  Val         -   Value to be set
00492     \param  Size        -   Size of the memory to be set
00493     \sa
00494     \note
00495     \warning        
00496 */
00497 void  mem_set(void *pBuf,int Val,size_t Size);
00498 
00499 /*!
00500     \brief              Copy Memory
00501     \param  pDst        -   Pointer to the Destination Buffer
00502     \param  pSrc        -   Pointer to the Source Buffer
00503     \param  Size        -   Size of the memory to be copied
00504     \return void
00505     \note
00506     \warning        
00507 */
00508 void  mem_copy(void *pDst, void *pSrc,size_t Size);
00509 
00510 /*!
00511     \brief          Enter Critical Section
00512     \sa
00513     \note
00514     \warning        
00515 */
00516 uint32_t osi_EnterCritical(void);
00517 
00518 /*!
00519     \brief          Exit Critical Section
00520     \sa
00521     \note
00522     \warning        
00523 */
00524 void osi_ExitCritical(uint32_t ulKey);
00525 
00526 /*!
00527     \brief  This function used to save the os context before sleep
00528     \param  void
00529     \return void
00530     \note
00531     \warning
00532 */
00533 void osi_ContextSave();
00534 /*!
00535     \brief  This function used to retrieve the context after sleep
00536     \param  void
00537     \return void
00538     \note
00539     \warning
00540 */
00541 void osi_ContextRestore();
00542 
00543 /*!
00544     \brief  This function used to suspend the task for the specified number of milli secs
00545     \param  MilliSecs   -   Time in millisecs to suspend the task
00546     \return void
00547     \note
00548     \warning
00549 */
00550 void osi_Sleep(unsigned int MilliSecs);
00551 
00552 /*!
00553     \brief  This function used to disable the tasks
00554     \param  - void
00555     \return - Key with the suspended tasks
00556     \note
00557     \warning
00558 */
00559 uint32_t osi_TaskDisable(void);
00560 
00561 /*!
00562     \brief  This function used to enable all tasks
00563     \param  unsigned long
00564     \return - void
00565     \note
00566     \warning
00567 */
00568 void osi_TaskEnable(uint32_t);
00569 /*!
00570     \brief structure definition for simple link spawn message
00571 
00572     \note   On each porting or platform the type could be whatever is needed - integer, pointer to structure etc.
00573 */
00574   
00575 typedef struct
00576 {
00577     P_OSI_SPAWN_ENTRY pEntry;
00578     void* pValue;
00579 }tSimpleLinkSpawnMsg;
00580   
00581 /* The queue used to send message to simple link spawn task. */
00582 extern void* xSimpleLinkSpawnQueue;
00583 
00584 /* API for SL Task*/
00585 OsiReturnVal_e VStartSimpleLinkSpawnTask(unsigned portBASE_TYPE uxPriority);
00586 void VDeleteSimpleLinkSpawnTask( void );
00587 
00588 
00589 
00590 #ifdef  __cplusplus
00591 }
00592 #endif // __cplusplus
00593 
00594 #endif
00595