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

📄 lib_tc.c

📁 LPC based lcd interface
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifdef CORPS
//* Begin
{
    //* If timer index is too high, return False
    if ( timer_id >= NB_TIMER ) return ( FALSE ) ;

    //* Save the address of the interrupt handler in the table
    TCHandlerTable[timer_id] = handler_pt ;
    //* Enable the interrupt
    ConstTimer[timer_id].TCBBase->
            TC[ConstTimer[timer_id].ChannelId].TC_IER = mask ;

    //* Return True
    return ( TRUE ) ;
}
//* End
#endif

//*P
//*----------------------------------------------------------------------------
//* Function Name       : disable_timer_irq
//* Object              : Define pins as managed by the PIO controller
//* Input Parameters    : <mask> defines the pins to managed by the PIO
//* Output Parameters   : the value of the PIO Status Register
//* Functions called    : none
//*----------------------------------------------------------------------------
_REFERENCE (u_int disable_timer_irq ( u_int timer_id ))
#ifdef CORPS
//* Begin
{
    //* If timer index is too high, return False
    if ( timer_id >= NB_TIMER ) return ( FALSE ) ;

    //* Mask all the Timer Counter Channel Interrupt
    ConstTimer[timer_id].TCBBase->
            TC[ConstTimer[timer_id].ChannelId].TC_IDR = 0x1FF ;
    //* Save in the table the default handler address
    TCHandlerTable[timer_id] = no_handler_tc ;

    //* Return True
    return ( TRUE ) ;
}
//* End
#endif

//*P
//*----------------------------------------------------------------------------
//* Function Name       : soft_trig_timer
//* Object              : Generate a software trigger
//* Input Parameters    : <timer_id> = the channel number to trig
//*                     : if timer_id = NB_TIMER, all channels are triggered
//* Output Parameters   : True if the argument is correct, otherwise False
//* Functions called    : none
//*----------------------------------------------------------------------------
_REFERENCE (u_int soft_trig_timer ( u_int timer_id ))
#ifdef CORPS
//* Begin
{
    //* If timer index is too high, return False
    if ( timer_id >= NB_TIMER+NB_TC_BLOCK ) return ( FALSE ) ;

    //* If timer exists
    if ( timer_id < NB_TIMER )
    {
        //* Perform a Software trigger on the corresponding channel
        ConstTimer[timer_id].TCBBase->
                TC[ConstTimer[timer_id].ChannelId].TC_CCR = SWTRG ;
    }
    //* Else
    else
    {
        //* Perform a synchronization trigger
        ConstTimer[(timer_id-NB_TIMER)*NB_TC_CHANNEL].TCBBase->TC_BCR = TCSYNC ;
    }
    //* EndIf

    //* Return True
    return ( TRUE ) ;
}
//* End
#endif

//*P
//*----------------------------------------------------------------------------
//* Function Name       : delay_microsec
//* Object              : Run the specified handler after a defined delay in
//*                     : micro-seconds.
//* Input Parameters    : <timer_id> = the channel number to use
//*                     : <period> = period in micro-seconds
//*                     : <repeat> = if True, handler is run at each period
//*                     : <handler> = the handler to run after the delay
//* Output Parameters   : True if the arguments are correct, otherwise False
//* Functions called    : none
//*----------------------------------------------------------------------------
_REFERENCE (u_int delay_microsec ( u_int timer_id,
                                   u_int period,
                                   u_int repeat,
                                   TypeTCHandler handler ))
#ifdef CORPS
//* Begin
{
    StructTC    *tc_pt ;
    u_int       ra, rb, rc ;
    u_int       mode ;

    //* If timer index is too high, return False
    if ( timer_id >= NB_TIMER ) return ( FALSE ) ;

    //* Define the Timer Counter Channel Pointer
    tc_pt = &(ConstTimer[timer_id].TCBBase->
                    TC[ConstTimer[timer_id].ChannelId]) ;

    //* Compute registers value for maximum precision, if error return False
    //* Define RB as the period to enable stop on Load RB
    ra = 0 ;
    rb = period ;
    rc = period ;
    if ( compute_register ( &mode, &ra, &rb, &rc ) != TRUE ) return ( FALSE ) ;

    //* Define as pio the pins reserved for the Channel
    define_as_pio ( ConstTimer[timer_id].PioCtrl,
                        ConstTimer[timer_id].PioPin ) ;

    //* Save the handler in the table
    TCHandlerTable[timer_id] = handler ;

    //* Initialize the mode of the timer
    tc_pt->TC_CMR = mode | WAVE | (repeat ? CPCTRG : CPCDIS) ;

    //* Initialize the RC Register value
    tc_pt->TC_RC = rc ;

    //* Enable the RC Compare interrupt
    tc_pt->TC_IER = CPCS ;

    //* Enable the clock of the timer
    tc_pt->TC_CCR = CLKEN ;

    //* Trig the timer
    tc_pt->TC_CCR = SWTRG ;

    //* Return True
    return ( TRUE ) ;
}
//* End
#endif

//*P
//*----------------------------------------------------------------------------
//* Function Name       : both_pwm_high_first
//* Object              : Generate 2 PWM waveforms signals defining high level
//*                     : duration
//* Input Parameters    : <timer_id> = the channel number to use
//*                     : <period> = period of both signals in microseconds.
//*                     : <a_cycle> = TIOA high level duration in microseconds
//*                     : <b_cycle> = TIOB high level duration in microseconds
//* Output Parameters   : True if the arguments are correct, otherwise False
//* Functions called    : none
//*----------------------------------------------------------------------------
_REFERENCE (u_int both_pwm_high_first ( u_int timer_id,
                                        u_int period,
                                        u_int a_cycle,
                                        u_int b_cycle ))
#ifdef CORPS
//* Begin
{
    StructTC        *tc_pt ;
    u_int               ra, rb, rc ;
    u_int               mode ;

    //* If timer index is too high, return False
    if ( timer_id >= NB_TIMER ) return ( FALSE ) ;

    //* Define the Timer Counter Channel Pointer
    tc_pt = &(ConstTimer[timer_id].TCBBase->
                    TC[ConstTimer[timer_id].ChannelId]) ;

    //* Compute registers value for maximum precision, if error return False
    ra = a_cycle ;
    rb = b_cycle ;
    rc = period ;
    if ( compute_register ( &mode, &ra, &rb, &rc ) != TRUE ) return ( FALSE ) ;

    //* Define as peripheral the pins reserved for the Channel
    define_as_peripheral ( ConstTimer[timer_id].PioCtrl,
                           ConstTimer[timer_id].PioPin ) ;

    //* Initialize the mode of the timer
    tc_pt->TC_CMR = mode | WAVE | EEVTXc0  | CPCTRG |
                    ( SetOutput << B_BSWTRG ) | ( OutputNone << B_BEEVT ) |
                    ( SetOutput << B_BCPC ) | ( ClearOutput << B_BCPB ) |
                    ( SetOutput << B_ASWTRG ) | ( OutputNone << B_AEEVT ) |
                    ( SetOutput << B_ACPC ) | ( ClearOutput << B_ACPA ) ;

    //* Initialize the RA Register value
    tc_pt->TC_RA = ra ;

    //* Initialize the RB Register value
    tc_pt->TC_RB = rb ;

    //* Initialize the RC Register value
    tc_pt->TC_RC = rc ;

    //* Enable the clock of the timer
    tc_pt->TC_CCR = CLKEN ;

    //* Trig the timer
    tc_pt->TC_CCR = SWTRG ;

    //* Return True
    return ( TRUE ) ;
}
//* End
#endif

//*P
//*----------------------------------------------------------------------------
//* Function Name       : both_pwm_low_first
//* Object              : Generate 2 PWM waveforms signals defining low level
//*                     : duration
//* Input Parameters    : <timer_id> = the channel number to use
//*                     : <period> = period of both signals in microseconds.
//*                     : <a_cycle> = TIOA low level duration in microseconds
//*                     : <b_cycle> = TIOB low level duration in microseconds
//* Output Parameters   : True if the arguments are correct, otherwise False
//* Functions called    : none
//*----------------------------------------------------------------------------
_REFERENCE (u_int both_pwm_low_first ( u_int timer_id,
                                       u_int period,
                                       u_int a_cycle,
                                       u_int b_cycle ))
#ifdef CORPS
//* Begin
{
    StructTC    *tc_pt ;
    u_int       ra, rb, rc ;
    u_int       mode ;

    //* If timer index is too high, return False
    if ( timer_id >= NB_TIMER ) return ( FALSE ) ;

    //* Define the Timer Counter Channel Pointer
    tc_pt = &(ConstTimer[timer_id].TCBBase->
                    TC[ConstTimer[timer_id].ChannelId]) ;

    //* Compute registers value for maximum precision, if error return False
    ra = a_cycle ;
    rb = b_cycle ;
    rc = period ;
    if ( compute_register ( &mode, &ra, &rb, &rc ) != TRUE ) return ( FALSE ) ;

    //* Define as peripheral the pins reserved for the Channel
    define_as_peripheral ( ConstTimer[timer_id].PioCtrl,
                           ConstTimer[timer_id].PioPin ) ;

    //* Initialize the mode of the timer
    tc_pt->TC_CMR = mode | WAVE | EEVTXc0  | CPCTRG |
                    ( ClearOutput << B_BSWTRG ) | ( OutputNone << B_BEEVT ) |
                    ( ClearOutput << B_BCPC ) | ( SetOutput << B_BCPB ) |
                    ( ClearOutput << B_ASWTRG ) | ( OutputNone << B_AEEVT ) |
                    ( ClearOutput << B_ACPC ) | ( SetOutput << B_ACPA ) ;

    //* Initialize the RA Register value
    tc_pt->TC_RA = ra ;

    //* Initialize the RB Register value
    tc_pt->TC_RB = rb ;

    //* Initialize the RC Register value
    tc_pt->TC_RC = rc ;

    //* Enable the clock of the timer
    tc_pt->TC_CCR = CLKEN ;

    //* Trig the timer
    tc_pt->TC_CCR = SWTRG ;

    //* Return True
    return ( TRUE ) ;
}
//* End
#endif

//*P
//*----------------------------------------------------------------------------
//* Function Name       : init_timer_capture
//* Object              : Initialize the TC Channel in Capture Mode
//* Input Parameters    : <timer_id> = channel to initialize
//*                     : <mode> = value of the Mode Register to be programmed
//*                     : <regc> = value of the Register C to be programmed
//* Output Parameters   : False if an error occurs, otherwise True
//* Functions called    : none
//*----------------------------------------------------------------------------
_REFERENCE (u_int init_timer_capture ( u_int timer_id ,
                                       u_int mode ,
                                       u_int regc ))
#ifdef CORPS
//* Begin
{
    StructTC *tc_pt ;

    //* If timer_id is out of range, return False
    if ( timer_id >= NB_TIMER ) return ( FALSE ) ;

    //* Define the Timer Counter Channel Pointer
    tc_pt = &(ConstTimer[timer_id].TCBBase->
                TC[ConstTimer[timer_id].ChannelId]) ;

        //* Define as peripheral the pins reserved for the Channel
    define_as_peripheral ( ConstTimer[timer_id].PioCtrl,
                           ConstTimer[timer_id].PioPin ) ;

    //* Disable the clock on the Timer Counter
    tc_pt->TC_CCR = CLKDIS ;
    //* Initialize the Mode Register of the Channel
    tc_pt->TC_CMR = ( mode & ~WAVE ) ;
    //* Initialize the Register C Value
    tc_pt->TC_RC = regc ;
    //* Enable the Clock
    tc_pt->TC_CCR = CLKEN ;

    //* If no external trigger is enabled
    if (( mode & ETRGEDG ) == 0 )
    {
        //* Send a Software Trigger
        tc_pt->TC_CCR = SWTRG ;
    }
    //* EndIf

    //* Return True
    return ( TRUE ) ;
}
#endif

⌨️ 快捷键说明

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