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

📄 int.c

📁 Real Time Operating System for Hi-Tech C compiler.
💻 C
字号:
/************************************************************ 
Copyright (C) 1995-2002 Pumpkin, Inc. and its
Licensor(s). Freely distributable.

$Source: C:\\RCS\\D\\salvo\\demo\\d5\\int.c,v $
$Author: aek $
$Revision: 1.8 $
$Date: 2001-10-25 19:56:49-07 $

Support file.

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

#ifndef INT_C_INCLUDES
#define INT_C_INCLUDES

#include "d5.h"
#include "main.h"
#include "salvo.h"

#if TRANSMITTERS >= 1
unsigned char intPS;
#endif



/************************************************************
****                                                     ****
**                                                         **
intVector()

Periodic interrupt via TMR2 occurs every quarter bit time.  
TMR2 is reloaded automatically from period register PR2. This
is the system tick period. Every system tick, Rx lines are 
sampled and flagged if we detect a start bit. If detected, 
a timestamp is recorded, and the associated receiver task is
started. This only happens if the associated receiver task 
is inactive. OSTimer() is called at system tick rate.

Hardware UART activity is handled on an interrupt basis.

**                                                         **
****                                                     ****
************************************************************/
#pragma interrupt_level 0
void interrupt ISR( void )
{
    ToggleTPInt();

    #if TRANSMITTERS >= 1
    /* when idling, check to see if we've been          */
    /*  signaled by TaskTx().                           */
    if ( txState == TXSTATE_IDLE ) {
        if ( OSTryBinSem(BINSEM_TXSTART_P) ) {
            /* if so, start up state machine and        */
            /*  set PS to minimize delay.               */
            txState++;
            intPS = 1;
        }
    }
    
    /* we're now transmitting data every fourth         */
    /*  system tick. By using if() if() instead of      */
    /*  if() else we reduce startup delay by 1          */
    /*  system tick.                                    */
    if ( txState != TXSTATE_IDLE ) {
        if ( --intPS == 0 ) {
            intPS = 4;
            
            /* first, set start bit for each active     */
            /*  transmitter.                            */
            if ( txState == TXSTATE_START ) {
            
                if ( txStatus.tx1Active )
                    TX1 = 0;
                
                #if TRANSMITTERS >= 2
                if ( txStatus.tx2Active )
                    TX2 = 0;
                #endif
                
                #if TRANSMITTERS >= 3
                if ( txStatus.tx3Active )
                    TX3 = 0;
                #endif
                
                #if TRANSMITTERS >= 4
                if ( txStatus.tx4Active )
                    TX4 = 0;
                #endif
                
                    
                ++txState;
            }
                                                        
            /* now pump the data out, bit by bit.       */
            /*  Do nothing if transmitter is            */
            /*  disabled, i.e. has no data to xmit.     */
            else if ( txState < TXSTATE_STOP ) {
              
                if ( txStatus.tx1Active ) {
                    if ( tx1Data & 0x01 )
                        TX1 = 1;
                    else
                        TX1 = 0;
                    tx1Data >>= 1;
                }
    
                #if TRANSMITTERS >= 2
                if ( txStatus.tx2Active ) {
                    if ( tx2Data & 0x01 )
                        TX2 = 1;
                    else
                        TX2 = 0;
                    tx2Data >>= 1;
                }
                #endif
        
                #if TRANSMITTERS >= 3
                if ( txStatus.tx3Active ) {
                    if ( tx3Data & 0x01 )
                        TX3 = 1;
                    else
                        TX3 = 0;
                    tx3Data >>= 1;
                }
                #endif
        
                #if TRANSMITTERS >= 4
                if ( txStatus.tx4Active ) {
                    if ( tx4Data & 0x01 )
                        TX4 = 1;
                    else
                        TX4 = 0;
                    tx4Data >>= 1;
                }
                #endif
                
                ++txState;
            }
                                                                    
            /* now send the stop bit. Can set it        */
            /*  regardless of txStatus.txNActive.       */
            else if ( txState == TXSTATE_STOP ) {
                  
                TX1 = 1;
                
                #if TRANSMITTERS >= 2
                TX2 = 1;
                #endif
                
                #if TRANSMITTERS >= 3
                TX3 = 1;
                #endif
                
                #if TRANSMITTERS >= 4
                TX4 = 1;
                #endif
                
                ++txState;
            }
            
            /* we got here after a full bit delay,      */
            /*  so stop bit is valid -- done.           */
            else if ( txState == TXSTATE_DONE ) {
                txState = TXSTATE_IDLE;
                OSSignalBinSem(BINSEM_TXDONE_P);
            }
        }
    }
    #endif /* #if TRANSMITTERS >= 1 */


    if ( TMR2IE && TMR2IF )    {
                                                        
        /* clear flag -- req'd.                         */
        TMR2IF = 0;
        
        /* any start bit activity on RX1? If we haven't */
        /*  detected any already, capture free-running  */
        /*  instruction cycle counter and start task.   */
        /*  If successful (i.e. task was stopped when   */
        /*  OSStartTask() was called) then disable this */
        /*  start-bit detector. It will be re-enabled   */
        /*  when TaskRx1() is finished receiving this   */
        /*  character. If not successful (i.e. task     */
        /*  hadn't stopped yet), then we'll be back in  */
        /*  one system tick to check again. Test RX1    */
        /*  twice to ensure it wasn't noise.            */
        #if RECEIVERS >= 1
        if ( !rxStatus.rx1Active )
            if ( !RX1 && !RX1 ) {        
                DisableTMR1();
                rx1Timestamp = TMR1;
                EnableTMR1();
                if ( OSStartTask(TASKRX1_P) == OSNOERR )
                    rxStatus.rx1Active = 1;
            }
        #endif
            
        #if RECEIVERS >= 2
        if ( !rxStatus.rx2Active )
            if ( !RX2 && !RX2 ) {            
                DisableTMR1();
                rx2Timestamp = TMR1;
                EnableTMR1();
                if ( OSStartTask(TASKRX2_P) == OSNOERR )
                    rxStatus.rx2Active = 1;
            }
        #endif
            
        #if RECEIVERS >= 3
        if ( !rxStatus.rx3Active )
            if ( !RX3 && !RX3 ) {        
                DisableTMR1();
                rx3Timestamp = TMR1;
                EnableTMR1();
                if ( OSStartTask(TASKRX3_P) == OSNOERR )
                    rxStatus.rx3Active = 1;
            }
        #endif
            
        #if RECEIVERS >= 4
        if ( !rxStatus.rx4Active )
            if ( !RX4 && !RX4 ) {        
                DisableTMR1();
                rx4Timestamp = TMR1;
                EnableTMR1();
                if ( OSStartTask(TASKRX4_P) == OSNOERR )
                    rxStatus.rx4Active = 1;
            }
        #endif
                            
        /* finally, call Salvo's timer since this is    */
        /*  all happening at the system tick rate.      */    
        OSTimer();
    }
    
    /*                                                  */
    if ( RCIF ) {
        rx5Buff[rx5InP++] = RCREG;
        
        if ( rx5InP > RX5_BUFF_SIZE-1 )
            rx5InP = 0;
        
        rx5Count++;
    }

    /*                                                  */
    if ( tx5Count && TRMT ) {
        /* send the valid char, and advance the         */
        /*  pointer.                                    */
        TXREG = tx5Buff[tx5OutP++];
        
        if ( tx5OutP > TX5_BUFF_SIZE-1 )
            tx5OutP = 0;
            
        tx5Count--;
    } 


    /* this will NEVER occur. It's here because the     */
    /*  Salvo library in use groups many services       */
    /*  together as callable from interrupts, and all   */
    /*  such services are #pragma interrupt_level 0.    */
    /*  This isn't too costly, ROM-wise, so don't       */
    /*  worry about it.                                 */
    #if TRANSMITTERS >= 1
    if ( TMR1CS ) {
        OSCreateBinSem(BINSEM_TXBUFF_P, 0);
        OSSignalBinSem(BINSEM_TXBUFF_P);
        OSTryBinSem(BINSEM_TXSTART_P);
    }
    #endif
    
    ToggleTPIntDone();
}

#endif

⌨️ 快捷键说明

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