示例#1
0
/*FUNCTION****************************************************************
*
* Function Name    : _rtc_init
* Returned Value   : MQX error code
* Comments         :
*    This function (re)initializes/clears/enables RTC module.
*    If cleared, alarm happens after RTC overflow, stopwatch happens next minute.
*    Reset disables and clears all interrupts and stopwatch (even if cleared).
*
*END*********************************************************************/
uint_32 _rtc_init
(
    /* [IN] flags identifying init operations */
    uint_32 flags
)
{
    uint_32 result = MQX_OK;
    RTC_MemMapPtr rtc = RTC_BASE_PTR;

    /* Clear time, alarm and stopwatch, if requested */
    if (flags & RTC_INIT_FLAG_CLEAR)
    {
        _int_disable();
        /* Resets all RTC registers except for SWR bit. */
        rtc->CR |= RTC_CR_SWR_MASK;
        alarm_time.seconds = 0;
        sw_time.seconds = 0;
        user_enables = 0;
        user_requests = 0;
        rtc->CR &= ~RTC_CR_SWR_MASK;
        rtc->TAR = 0xFFFFFFFF; /* e2574: RTC: Writing RTC_TAR[TAR] = 0 does not disable RTC alarm */
        rtc->TSR = 1;
        _int_enable();
    }
    /* reset current user interrupt state and callback, if requested */
    if (flags & RTC_INIT_FLAG_RESET)
    {
        _int_disable();
        /* Resets all RTC registers except for SWR bit. */
        rtc->CR |= RTC_CR_SWR_MASK;
        rtc->CR &= ~RTC_CR_SWR_MASK;
        rtc->TSR = 1;
        user_enables = 0;
        user_requests = 0;
        _int_enable();
    }

    /* install HW interrupt and run the RTC, if requested */
    if (flags & RTC_INIT_FLAG_ENABLE)
    {
        /* disable reset RTC */
        if( rtc->CR & RTC_CR_SWR_MASK )
        {
            rtc->CR &= ~RTC_CR_SWR_MASK;
        }

/* wk@130510 -->  */
    /* default */
//        if (NULL == _int_install_isr (INT_RTC, _rtc_isr, (pointer)rtc))
//        {
//            result = _task_get_error ();
//        }
    /* wk */       
        if (NULL == _int_install_isr (INT_RTC, _rtc_isr_app, (pointer)rtc))
        {
            result = _task_get_error ();
        }
 /* end */

        if (MQX_OK == result)
        {
            if( !(rtc->SR & RTC_SR_TCE_MASK) || !(rtc->CR & RTC_CR_OSCE_MASK) )
            {
                rtc->CR |= RTC_CR_OSCE_MASK;
                /* recommended 125 ms delay for oscillator start */
                _rtc_wait_ms(125);
                
                rtc->TAR=rtc->TSR;  // wk@130405 -->
                
                rtc->SR |= RTC_SR_TCE_MASK;
            }
            _bsp_int_init(INT_RTC, BSP_RTC_INT_LEVEL, 0, TRUE);

        }
    }
    
#if PSP_MQX_CPU_IS_KINETIS_K70
    /* Enable monotonic counter */
    RTC_MER = RTC_MER_MCE_MASK;
#if 0
    /* Enable Tamper */
    RTC_TER =   (RTC_TER_TME_MASK | \
                 RTC_TER_VTE_MASK | \
                 RTC_TER_CTE_MASK | \
                 RTC_TER_TTE_MASK | \
                 RTC_TER_FSE_MASK | \
                 RTC_TER_TME_MASK);

#else    
    /* Disable all tampers */
    RTC_TER = 0;
#endif
        
        
#endif    
    
    return result;
}
示例#2
0
文件: krtc.c 项目: mihaSoro/MQX-3.7.0
/*FUNCTION****************************************************************
* 
* Function Name    : _rtc_init
* Returned Value   : MQX error code
* Comments         :
*    This function (re)initializes/clears/enables RTC module.
*    If cleared, alarm happens after RTC overflow, stopwatch happens next minute.
*    Reset disables and clears all interrupts and stopwatch (even if cleared).
*
*END*********************************************************************/
uint_32 _rtc_init 
(
    /* [IN] flags identifying init operations */
    uint_32 flags
)
{
    uint_32 result = MQX_OK;
    RTC_MemMapPtr rtc = RTC_BASE_PTR;        
    
    /* Clear time, alarm and stopwatch, if requested */
    if (flags & RTC_INIT_FLAG_CLEAR) 
    {      
        _int_disable();
    	/* Resets all RTC registers except for SWR bit. */
        rtc->CR |= RTC_CR_SWR_MASK;
        alarm_time.seconds = 0;
        sw_time.seconds = 0;
        user_enables = 0;
        user_requests = 0;          
        rtc->CR &= ~RTC_CR_SWR_MASK;
        rtc->TAR = 0xFFFFFFFF; /* e2574: RTC: Writing RTC_TAR[TAR] = 0 does not disable RTC alarm */
        rtc->TSR = 1;
        _int_enable();
    }
    /* reset current user interrupt state and callback, if requested */
    if (flags & RTC_INIT_FLAG_RESET) 
    {
    	_int_disable();
    	/* Resets all RTC registers except for SWR bit. */
        rtc->CR |= RTC_CR_SWR_MASK;
        rtc->CR &= ~RTC_CR_SWR_MASK;
        rtc->TSR = 1;
        user_enables = 0;
        user_requests = 0;
        _int_enable();
    }

    /* install HW interrupt and run the RTC, if requested */    
    if (flags & RTC_INIT_FLAG_ENABLE) 
    {
        /* disable reset RTC */
        if( rtc->CR & RTC_CR_SWR_MASK )
        {
            rtc->CR &= ~RTC_CR_SWR_MASK;
        } 
   	
    	if (NULL == _int_install_isr (INT_RTC, _rtc_isr, (pointer)rtc))
        {        
            result = _task_get_error ();
        }
                
        if (MQX_OK == result) 
        {
            if( !(rtc->SR & RTC_SR_TCE_MASK) || !(rtc->CR & RTC_CR_OSCE_MASK) )
            {    
                rtc->CR |= RTC_CR_OSCE_MASK;
                /* recommended 125 ms delay for oscillator start */
                _rtc_wait_ms(125); 
                rtc->SR |= RTC_SR_TCE_MASK;
            }
            _bsp_int_init(INT_RTC, BSP_RTC_INT_LEVEL, 0, TRUE);

        }
    }
    return result;
}