free modbus 源码阅读笔记之中断

void
EnterCriticalSection( void )
{
    USHORT usOldSR;
    if( ucCriticalNesting == 0 )
    {
#if defined (__GNUC__)
        usOldSR = READ_SR;
        _DINT( );
#else
        usOldSR = _DINT( );
#endif
        ucGIEWasEnabled = usOldSR & GIE ? TRUE : FALSE;
    }
    ucCriticalNesting++;//每关一次中断自增
}

void
ExitCriticalSection( void )
{
    ucCriticalNesting--;//没错调用开中断函数减减
    if( ucCriticalNesting == 0 )
    {
        if( ucGIEWasEnabled )
        {
            _EINT(  );
        }
    }
}

//此处中断计数的作用是由于开关中断函数总是成对出现
//防止这两对函数之间的代码误开启中断

你可能感兴趣的:(free modbus 源码阅读笔记之中断)