#ifndef _xmk_sch_eidi_h_
#define _xmk_sch_eidi_h_
/*----------------------------------------------------------------------------
** SUMMARY: XMK Enable/Disable Scheduling Interfaces (SCH_EIDI)
**
** DESCRIPTION:
**  This file provides interfaces for advance scheduling related operations.
**
** CONFIGURATION OPTION: USE_XMK_SCHEDULER_EI_DI_SWITCHING
**
** DEPENDENCIES:
**  To use this interface the following XMK service(s) MUST always be
**  enabled/configured:
**      USE_XMK_CORE_KERNEL
**
**  NOTES:
**  1. For efficency/optimization some methods are 'inlined'.  The inlining
**     is done by using the preprocessor/macros.  The application should
**     treat all methods as function calls and not rely on the fact they may
**     be currently defined as a macro.
**
----------------------------------------------------------------------------*/

#include "xmkcfg.h"     /* For: Project/Application kernel configuraiton          */


#ifdef __cplusplus
extern "C" {
#endif

/*-------------- MAGIC CONSTANTS -------------------------------------------*/

/*
** ERROR CODES 
*/
/** Invalid sequencing of thread switching enable/disable calls.  Xmk_enableSwitching() 
    was called before Xmk_disableSwitching().
 */
#define XMK_ERRFATAL_SCH_EIDI_INVALID_SEQUENCE          _XMK_ERRFATAL_SCH_EIDI_INVALID_SEQUENCE

/** To many nested calls to Xmk_disableSwitching(), exceeding the kernel's
    internal reference counter.
 */
#define XMK_ERRFATAL_SCH_EIDI_NESTING_OVERFLOW          _XMK_ERRFATAL_SCH_EIDI_NESTING_OVERFLOW



/*-------------- PUBLIC/PUBLISHED API --------------------------------------*/
/** This method suspends thread scheduling.  The calling thread will
    stay as the active thread, i.e. no context switching of application 
    threads will occur, until Xmk_enableSwitching() is called.  Interrupt
    processing is NOT disabled and will continue as normal.  However, all
    context switch requests for other application threads by an ISR will be 
    postponed until Xmk_enabledSwitching() is called.
    NOTES:
        o The application can 'nest' the calls to Xmk_disableSwitching().
          Thread scheduling will not be re-enabled until Xmk_enableSwitch() 
          is called the same corresponding number of times.  The maximum depth 
          of the nesting is 255.
        o Since the calling thread stays the 'active' thread, the calling
          thread can wait/sleep/block etc. and still be revived since
          interrupts are still operating, assuming the 'wake-up signal'
          comes from an ISR!!! 
        o This method does NOT prevent the IDLE thread from running when
          calling thread is blocked.
        o This method can NOT be called from an interrupt service routine.
        o Be careful! You can cripple/lock-up your entire application if
          context switching is disabled for extended periods of time!
    Prototype:
        void Xmk_disableSwitching(void);
 */
#define Xmk_disableSwitching()          _Xmk_disableSwitching()

/** This method resumes thread scheduling.  If there is ready-to-run thread
    with a higher priority than the calling thread, an immediate context 
    switch will occur, else the current thread continues to run.
    NOTE: This method can NOT be called from an interrupt service routine.
    Prototype:
        void Xmk_enableSwitching(void);
 */
#define Xmk_enableSwitching()           _Xmk_enableSwitching()

/** This method returns non-zero if scheduling is disbaled.  Actually, it
    returns the current 'nesting' level of the number times _Xmk_disableSwitching()
    has been called.  If the 'nesting' level is zero, then scheduling is
    enabled.
    Prototype:
        XMK_BYTE _Xmk_isSchedulingDisabled(void);
*/
#define Xmk_isSchedulingDisabled()     _Xmk_isSchedulingDisabled() 


#ifdef __cplusplus
}
#endif
/*--------------------------------------------------------------------------*/
#endif  /* end _xmk_sch_eidi_h_ */

