⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtos.h

📁 This project should serve as an "easy start" with embOS. All pathes are relative to the project fil
💻 H
📖 第 1 页 / 共 4 页
字号:
        OS_SwitchFromInt(); \
      }                     \
    }                       \
    OS_RegionCnt--;         \
  }
#endif

#ifndef OS_LeaveInterruptNoSwitch   /* Allow override in OSChip.h */
  #define OS_LeaveInterruptNoSwitch() { \
    OS_MARK_OUTOF_ISR(); \
    OS_DICnt--; \
    OS_RegionCnt--; \
  }
#endif

#ifndef OS_LeaveNestableInterruptNoSwitch   /* Allow override in OSChip.h */
  #define OS_LeaveNestableInterruptNoSwitch() { \
    OS_DI(); \
    OS_MARK_OUTOF_ISR(); \
    OS_RegionCnt--; \
  }
#endif

#ifndef OS_EnterIntStack
  void OS__EnterIntStack(void);
  #define OS_EnterIntStack() {OS_DI(); OS__EnterIntStack(); OS_RestoreI(); }
#endif

#ifndef OS_LeaveIntStack
  void OS__LeaveIntStack(void);
  #define OS_LeaveIntStack() {OS_DI(); OS__LeaveIntStack(); }
#endif

/*********************************************************************
*
*       Resource semaphores
*
**********************************************************************
*/

int      OS_Use             (OS_RSEMA * pRSema); /* OSRsem.c   */
void     OS_Unuse           (OS_RSEMA * pRSema); /* OSRsem.c   */
char     OS_Request         (OS_RSEMA * pRSema); /* OSRsemRQ.c */
int      OS_GetSemaValue    (OS_RSEMA * pRSema); /* OSRSemGV.c */
OS_TASK* OS_GetResourceOwner(OS_RSEMA * pRSema); /* OSRsemGO.c */

void     OS_CreateRSema     (OS_RSEMA * pRSema); /* OSRsem.c   */

#define OS_CREATERSEMA(ps) OS_CreateRSema(ps)

/*********************************************************************
*
*       Counting semaphores
*
**********************************************************************
*/

void OS_CreateCSema   (OS_CSEMA * pCSema, OS_U8 InitValue);  /* OSCSEM.c   */
void OS_DeleteCSema   (OS_CSEMA * pCSema);                   /* OSDELCS.c  */
int  OS_GetCSemaValue (OS_CSEMA * pCSema);                   /* OSCSEMGV.c */
void OS_SignalCSema   (OS_CSEMA * pCSema);                   /* OSCSEM.c   */
void OS_WaitCSema     (OS_CSEMA * pCSema);                   /* OSCSEM.c   */
int  OS_WaitCSemaTimed(OS_CSEMA * pCSema, int TimeOut);      /* OSCSEMT.c  */

#define OS_CREATECSEMA(ps) OS_CreateCSema(ps,0)

/*********************************************************************
*
*       Mailboxes
*
**********************************************************************
*/
#define CREATEMB(MAILBOX, size, max, Buffer) OS_CreateMB(MAILBOX,size, max, Buffer);
void OS_CreateMB          (OS_MAILBOX * pMB, OS_U8 sizeofMsg, OS_UINT maxnofMsg, void* Buffer);    /* initialize mailbox */
void OS_ClearMB           (OS_MAILBOX * pMB);
void OS_PutMail           (OS_MAILBOX * pMB, void* pMail);
char OS_PutMailCond       (OS_MAILBOX * pMB, void* pMail);
void OS_PutMailFront      (OS_MAILBOX * pMB, void* pMail);
char OS_PutMailFrontCond  (OS_MAILBOX * pMB, void* pMail);
void OS_GetMail           (OS_MAILBOX * pMB, void* pDest);
char OS_GetMailCond       (OS_MAILBOX * pMB, void* pDest);
void OS_PutMail1          (OS_MAILBOX * pMB, const char* pMail);
char OS_PutMailCond1      (OS_MAILBOX * pMB, const char* pMail);
void OS_PutMailFront1     (OS_MAILBOX * pMB, const char* pMail);
char OS_PutMailFrontCond1 (OS_MAILBOX * pMB, const char* pMail);
void OS_GetMail1          (OS_MAILBOX * pMB, char* pDest);
char OS_GetMailCond1      (OS_MAILBOX * pMB, char* pDest);
char OS_GetMailTimed      (OS_MAILBOX * pMB, void* pDest, int Timeout);
void OS_DeleteMB          (OS_MAILBOX * pMB);
void OS_WaitMail          (OS_MAILBOX * pMB);

#if OS_DEBUG == 0
  #define OS_GetMessageCnt(pMB) (*pMB).nofMsg
#else
  int OS_GetMessageCnt(OS_MAILBOX * pMB);   /* get no. of available Messages */
#endif

/*********************************************************************
*
*       Message Queues (OSQ.c)
*
**********************************************************************
*/

void OS_Q_Create(OS_Q* pQ, void*pData, OS_UINT Size);
void OS_Q_Clear(OS_Q* pQ);                    /* OSQCL.c  */
int  OS_Q_GetMessageCnt(OS_Q* pQ);            /* OSQGMC.c */
int  OS_Q_Put(OS_Q* pQ, const void* pSrc, OS_UINT Size);
int  OS_Q_GetPtr(OS_Q* pQ, void**ppData);
int  OS_Q_GetPtrCond(OS_Q* pQ, void**ppData); /* OSQGPC.c */
void OS_Q_Purge(OS_Q* pQ);

/*********************************************************************
*
*       Events
*
**********************************************************************
*/

char OS_ClearEvents          (OS_TASK * pTask);             /* OSEVENCL.c  */
char OS_GetEventsOccured     (OS_TASK * pTask);             /* OSEVENGE.c  */
void OS_SignalEvent          (char Event, OS_TASK * pTask); /* OSENENS.c   */
char OS_WaitEvent            (char EventMask);              /* OSEVENW.c   */
char OS_WaitEventTimed       (char EventMask, int TimeOut); /* OSEVENT.c   */
char OS_WaitSingleEvent      (char EventMask);              /* OSEVENWS.c  */
char OS_WaitSingleEventTimed (char EventMask, int TimeOut); /* OSEVENWST.c */

/*********************************************************************
*
*       Timers(OSTIME.c)
*
**********************************************************************
*/

#ifdef OS_SIZEOF_INT
  #if OS_SIZEOF_INT == 2
    #define OS_TIMER_MAX_TIME 0x7F00
  #elif OS_SIZEOF_INT == 4
    #define OS_TIMER_MAX_TIME 0x7FFFFF00
  #else
    #error "OS_SIZEOF_INT not correctly defined"
  #endif
#endif
 
void    OS_CreateTimer    (OS_TIMER * pTimer, OS_TIMERROUTINE* Callback, OS_UINT Timeout);
void    OS_RetriggerTimer (OS_TIMER * pTimer);
void    OS_StartTimer     (OS_TIMER * pTimer);
void    OS_StopTimer      (OS_TIMER * pTimer);
void    OS_DeleteTimer    (OS_TIMER * pTimer);                  /* OSTIMED.c  */
int     OS_GetTimerPeriod (OS_TIMER * pTimer);                  /* OSTIMEGP.c */
OS_U8   OS_GetTimerStatus (OS_TIMER * pTimer);                  /* OSTIMEGS.c */
int     OS_GetTimerValue  (OS_TIMER * pTimer);                  /* OSTIMEGV.c */
void    OS_SetTimerPeriod (OS_TIMER * pTimer, OS_UINT Period);  /* OSTIMES.c */

#define OS_CREATETIMER(pTimer,c,d) \
        OS_CreateTimer(pTimer,c,d); \
        OS_StartTimer(pTimer);

/*********************************************************************
*
*       Extended timers (OSTIMERX.c)
*
**********************************************************************
*/
void    OS_CreateTimerEx    (OS_TIMER_EX * pTimerEx, OS_TIMER_EX_ROUTINE* Callback, OS_UINT Timeout, void * pData);

#define OS_RetriggerTimerEx(pTimerEx)  OS_RetriggerTimer(&pTimerEx->Timer)
#define OS_StartTimerEx    (pTimerEx)  OS_StartTimer    (&pTimerEx->Timer)
#define OS_StopTimerEx     (pTimerEx)  OS_StopTimer     (&pTimerEx->Timer)
#define OS_DeleteTimerEx   (pTimerEx)  OS_DeleteTimer   (&pTimerEx->Timer)
#define OS_GetTimerPeriodEx(pTimerEx)  OS_GetTimerPeriod(&pTimerEx->Timer)
#define OS_GetTimerStatusEx(pTimerEx)  OS_GetTimerStatus(&pTimerEx->Timer)
#define OS_GetTimerValueEx (pTimerEx)  OS_GetTimerValue (&pTimerEx->Timer)
#define OS_SetTimerPeriodEx(pTimerEx,Period)  OS_SetTimerPeriod(&pTimerEx->Timer, Period)

#define OS_CREATETIMER_EX(pTimerEx,c,d, pData) \
        OS_CreateTimerEx(pTimerEx,c,d, pData); \
        OS_StartTimerEx(pTimerEx);
/*********************************************************************
*
*       Heap type memory management (OS_Alloc.c)
*
**********************************************************************

  This functions might not be implemented in all embOS ports.
  Therefore declaration depends on condition OS_SUPPORT_OS_ALLOC
  which has to be defined in CPU specific part

*/

#if OS_SUPPORT_OS_ALLOC
  void* OS_malloc(unsigned int);
  void  OS_free  (void* pMemBlock);
  void* OS_realloc  (void* pMemBlock, unsigned NewSize);
#endif

/*********************************************************************
*
*       Fixed Block memory management
*
**********************************************************************
*/

void  OS_MEMF_Create(OS_MEMF* pMEMF, void* pPool, OS_U16 NumBlocks, OS_U16 BlockSize);
void  OS_MEMF_Delete(OS_MEMF* pMEMF);
void* OS_MEMF_Alloc(OS_MEMF* pMEMF, int Purpose);
void* OS_MEMF_AllocTimed(OS_MEMF* pMEMF, int Timeout, int Purpose);
void* OS_MEMF_Request(OS_MEMF* pMEMF, int Purpose);
void  OS_MEMF_Release(OS_MEMF* pMEMF, void* pMemBlock);
void  OS_MEMF_FreeBlock(void* pMemBlock);
int   OS_MEMF_GetNumFreeBlocks(OS_MEMF* pMEMF);
char  OS_MEMF_IsInPool(OS_MEMF* pMEMF, void* pMemBlock);
int   OS_MEMF_GetMaxUsed(OS_MEMF* pMEMF);
int   OS_MEMF_GetNumBlocks(OS_MEMF* pMEMF);
int   OS_MEMF_GetBlockSize(OS_MEMF* pMEMF);

/*********************************************************************
*
*       Event object module
*
**********************************************************************
*/

void OS_EVENT_Create(OS_EVENTOBJ* pEventObj, OS_EVENT_MASK Events);
void OS_EVENT_Delete(OS_EVENTOBJ* pEventObj);
void OS_EVENT_Free  (OS_EVENTOBJ* pEventObj);

void OS_EVENT_ClearEvents(OS_EVENTOBJ* pEventObj, OS_EVENT_MASK Events);
void OS_EVENT_ClearAllEvents(OS_EVENTOBJ* pEventObj);

void OS_EVENT_SetEvent(OS_EVENTOBJ* pEventObj, OS_EVENT_MASK Events);

OS_EVENT_MASK OS_EVENT_GetEvents(OS_EVENTOBJ* pEventObj);

OS_EVENT_MASK OS_EVENT_WaitAnyEvent(OS_EVENTOBJ* pEventObj, OS_EVENT_MASK EventMask, OS_U8 Consume);
OS_EVENT_MASK OS_EVENT_WaitAllEvent(OS_EVENTOBJ* pEventObj, OS_EVENT_MASK EventMask, OS_U8 Consume);
OS_EVENT_MASK OS_EVENT_WaitAnyEventTimed(OS_EVENTOBJ* pEventObj, OS_EVENT_MASK EventMask, OS_U8 Consume, int Timeout, char* ErrorCode);
OS_EVENT_MASK OS_EVENT_WaitAllEventTimed(OS_EVENTOBJ* pEventObj, OS_EVENT_MASK EventMask, OS_U8 Consume, int Timeout, char* ErrorCode);

/*********************************************************************
*
*       Timing support (OSTiming.c)
*
**********************************************************************

 New in V3.04, but not yet documented to the end user. Great for
 run-time measurement.
*/

#define OS_TIMING OS_U32
void    OS_Timing_Start(OS_TIMING* pCycle);
void    OS_Timing_End(OS_TIMING* pCycle);
OS_U32  OS_Timing_Getus(OS_TIMING* pCycle);
#define OS_Timing_GetCycles(pPara) (*pPara)

/*********************************************************************
*
*       Advanced profiling support (Module OsKern.c)
*
**********************************************************************
*/
#if OS_PROFILE >= 1
  void OS_EnableProfiling(int Period);
  #define OS_DisableProfiling() { OS_ProfilingOn=0; }
#else
  #define OS_EnableProfiling(Period);
  #define OS_DisableProfiling()
#endif

/*********************************************************************
*
*       Configuration
*
**********************************************************************
*/

#ifdef __RTOS_ALLOWFRACT__  /* For K0 only */
  #define OS_CONFIG(f, div) \
  OS_TicksPerMS  = f/1000; \
  OS_IntMSInc    = div*1000L/f; \
  OS_IntTicksInc = div-(f/1000)*(div*1000L/f);
#else
  #define OS_CONFIG(f, div) \
  OS_IntMSInc    = div*1000L/f;
#endif

/*********************************************************************
*
*       Trace support (OSTrace.c)
*
**********************************************************************

Trace support is enabled by defining OS_TRACE 1.
This is automatically done, when OS_LIBMODE_T is defined.

*/

#if OS_TRACE
  void OS_TraceVoid (OS_U8 id);
  void OS_TracePtr  (OS_U8 id, void* p);
  void OS_TraceData (OS_U8 id, int v);
  void OS_TraceDataPtr (OS_U8 id, int v, void*p);
  void OS_TraceU32Ptr  (OS_U8 id, OS_U32 p0, void*p1);
  void OS_TraceEnable(void);
  void OS_TraceDisable(void);
  void OS_TraceEnableAll(void);                              /* OSTrace1.c */
  void OS_TraceDisableAll(void);                             /* OSTrace1.c */
  void OS_TraceEnableId(OS_U8 id);                           /* OSTrace1.c */
  void OS_TraceDisableId(OS_U8 id);                          /* OSTrace1.c */
  void OS_TraceEnableFilterId(OS_U8 FilterIndex, OS_U8 id);  /* OSTrace1.c */
  void OS_TraceDisableFilterId(OS_U8 FilterIndex, OS_U8 id); /* OSTrace1.c */
#else
  #define OS_TraceVoid(id)
  #define OS_TracePtr(id, p)
  #define OS_TraceData(id, v)
  #define OS_TraceDataPtr(id, v, p)
  #define OS_TraceU32Ptr(id, p0, p1)
  #define OS_TraceEnable()
  #define OS_TraceDisable()
  #define OS_TraceEnableAll()
  #define OS_TraceDisableAll()
  #define OS_TraceEnableId(id)
  #define OS_TraceDisableId(id)
  #define OS_TraceEnableFilterId(FilterIndex, id)
  #define OS_TraceDisableFilterId(FilterIndex, id)
#endif  

/*********************************************************************
*
*        RTOSInit and misc.
*
**********************************************************************

The routines declared below are available on all targets.

*/

/* Routines in RTOSInit.c */
void   OS_InitHW(void);
void   OS_Idle(void);
OS_U32 OS_ConvertCycles2us(OS_U32 Cycles);
OS_U32 OS_GetTime_Cycles(void);
void   OS_COM_Init(void);
void   OS_COM_Send1(unsigned char c);

/* Routines in OS_Error.c, delivered as source file */
void   OS_Error(int code);

/* Routines in library */
 void OS_ChangeTask(void);

void OS_Start(void);                /* RTOS ASM part   */
void OS_Switch(void);               /* RTOS ASM part   */
void OS_SwitchFromInt(void);        /* RTOS ASM part   */

void  OS_InitKern(void);             /* OSKern.c        */
OS_U8 OS_OnTx(void);                 /* OSComRxTx1.c Returns 1 on last byte */
void  OS_OnRx(unsigned char c);      /* OSComRxTx1.c    */
void  OS_Send1(OS_U8 c);             /* not implemented */
void  OS_SendString(const char* s);  /* OSSend.c        */
OS_RX_CALLBACK* OS_SetRxCallback(OS_RX_CALLBACK* cb); 
OS_U8 OS_EvaPacketEx(const OS_U8 * pSrc, OS_U16 SrcLen, OS_U8** pReturn);  /* OS_EvaPacketEx.c */

void  OS_COM_ClearTxActive(void);    /* OSCom2.c */

/*********************************************************************
*
*        RTOS misc. optional 
*
**********************************************************************

The routines declared below are available on some targets
only. (Because they do not make much sense on others)
*/

/* Timing routines. Their existance depends on the CPU. In general,
  8-bit CPUs require both routines, where 16-bit CPUs require one
  and 32-bit CPUs require none of these.
*/
#ifndef OS_GetTime
  int OS_GetTime(void);
#endif
#ifndef OS_GetTime32
  OS_I32 OS_GetTime32(void);
#endif

void OS__di(void);
void OS__ei(void);
void OS__SaveIPL(void);
void OS__RestIPL(void);
void OS_SIM_Init(void);

void OS_TickHandler(void);    
void OS_HandleTickDI(void);
void OS_HandleTick(void);     /* New version of OS_TickHandler() without Enter- Leave-Interrupt */

/* Routines for the PC-version running in native mode (non-windows) */
void OS_SetIntFreq(OS_UINT f);
void OS_Exit(int code);
void OS_UseDos(void);
void OS_UnuseDos(void);
int  OS_GetKey(void);
int  OS_WaitKey(void);

/* Compatibility with manual */
#define OS_CREATEMB          OS_CreateMB
#define OS_GetUseCnt         OS_GetSemaValue     
#define OS_WaitCSema_Timed   OS_WaitCSemaTimed
#define OS_WaitEvent_Timed   OS_WaitEventTimed

/********************************************************************/

#ifdef __cplusplus
  }
#endif

#endif /* RTOS_H_INCLUDED */

/*****  EOF  ********************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -