Beispiel #1
0
/*FUNCTION****************************************************************
* 
* Function Name    : _rtc_get_status
* Returned Value   : bitmask of actual RTC interrupt requests + RTC enabled bit
* Comments         :
*    This function returns bitmask of pending RTC interrupt requests along
*    with RTC enabled bit (bit MCF52XX_RTC_RTCISR_EN).
*
*END*********************************************************************/
uint_32 _rtc_get_status 
(
    void
)
{
    uint_32 result;
    VMCF52XX_RTC_STRUCT_PTR rtc = _bsp_get_rtc_base_address ();
    result = _rtc_register_read ((pointer)&rtc->RTCISR, TRUE);
    if (_rtc_register_read ((pointer)&rtc->RTCCTL, TRUE) & MCF52XX_RTC_RTCCTL_EN)
    {
        result |= (uint_32)MCF52XX_RTC_RTCISR_EN;
    }
    return result;
}
Beispiel #2
0
/*FUNCTION*-------------------------------------------------------------------
* 
* Function Name    : _bsp_rtc_io_init
* Returned Value   : none
* Comments         :
*    This function performs BSP-specific initialization related to RTC
*
*END*----------------------------------------------------------------------*/
void _bsp_rtc_io_init 
(
    void
)
{
    VMCF5225_CLK_STRUCT_PTR clk = &(((VMCF5225_STRUCT_PTR)_PSP_GET_IPSBAR())->CLK);
    VMCF52XX_RTC_STRUCT_PTR rtc = _bsp_get_rtc_base_address ();
    clk->RTCCR = MCF5225_CLOCK_RTCCR_EXTALEN | MCF5225_CLOCK_RTCCR_REFS | MCF5225_CLOCK_RTCCR_LPEN | MCF5225_CLOCK_RTCCR_RTCSEL;
    rtc->RTCGOCU = BSP_RTC_PRESCALER_GOCU;
    rtc->RTCGOCU = BSP_RTC_PRESCALER_GOCU;    // according to RTC register write protocol - 2x
    rtc->RTCGOCL = BSP_RTC_PRESCALER_GOCL;
    rtc->RTCGOCL = BSP_RTC_PRESCALER_GOCL;    // according to RTC register write protocol - 2x
    _rtc_init (RTC_INIT_FLAG_ENABLE);
}
Beispiel #3
0
/*FUNCTION****************************************************************
* 
* Function Name    : _rtc_int_install
* Returned Value   : MQX error code
* Comments         :
*    This function installs given ISR for RTC module.
*
*END*********************************************************************/
uint_32 _rtc_int_install 
(
    /* [IN] pointer to user ISR code */
    pointer isr
)
{
    typedef void(*ISR_PTR)(pointer);
    void (_CODE_PTR_ result)(pointer);
    VMCF52XX_RTC_STRUCT_PTR rtc;
    if (NULL == isr) return MQX_INVALID_POINTER;
    rtc = _bsp_get_rtc_base_address ();
    result = _int_install_isr (_bsp_get_rtc_vector (), (ISR_PTR)isr, (pointer)rtc);
    if (NULL == result) return _task_get_error ();
    return MQX_OK;
}
Beispiel #4
0
/*FUNCTION****************************************************************
* 
* Function Name    : _rtc_set_time
* Returned Value   : none
* Comments         :
*    This function sets the RTC time according to given time struct.
*
*END*********************************************************************/
void _rtc_set_time 
(
    /* [IN] given time to be set as RTC time */
    RTC_TIME_STRUCT_PTR time
)
{
    VMCF51XX_RTC_STRUCT_PTR rtc = _bsp_get_rtc_base_address ();
    uint_8 tmp = rtc->RTCSC & MCF51XX_RTC_RTCSC_RTIE;   
    rtc->RTCSC &= (~ MCF51XX_RTC_RTCSC_RTIE);             // disable RTC
    real_time = *time;                                    // set new time
    if (real_time.seconds > 59) real_time.seconds = 59;   // correct time
    if (real_time.minutes > 59) real_time.minutes = 59;
    if (real_time.hours > 23) real_time.hours = 23;
    rtc->RTCSC |= MCF51XX_RTC_RTCSC_RTIF;                 // clear RTC request
    rtc->RTCSC |= tmp;                                    // restore RTC state
}
Beispiel #5
0
/*FUNCTION****************************************************************
* 
* Function Name    : _rtc_set_alarm
* Returned Value   : none
* Comments         :
*    This function sets RTC alarm time according to given time struct.
*    Alarm happens a half second after match.
*
*END*********************************************************************/
void _rtc_set_alarm 
(
	/* [IN] time to be set as RTC alarm time */
	RTC_TIME_STRUCT_PTR time
)
{ /* Body */
	uint_32 tmp;
	VMCF53XX_RTC_STRUCT_PTR rtc = _bsp_get_rtc_base_address ();
	tmp = _rtc_register_read ((pointer)&rtc->RTC_IER, TRUE);
	_rtc_register_write ((pointer)&rtc->RTC_IER, TRUE, tmp & (~ MCF53XX_RTC_IER_ALM));
	_rtc_register_write ((pointer)&rtc->RTC_ALRM_DAY, FALSE, MCF53XX_RTC_ALRM_DAY(time->days));
	_rtc_register_write ((pointer)&rtc->RTC_ALRM_SEC, TRUE, MCF53XX_RTC_ALRM_SEC_WRITE(time->seconds));
	_rtc_register_write ((pointer)&rtc->RTC_ALRM_HM, TRUE, MCF53XX_RTC_ALRM_HM_MINUTES_WRITE(time->minutes) | MCF53XX_RTC_ALRM_HM_HOURS_WRITE(time->hours));
	_rtc_clear_requests (MCF53XX_RTC_ISR_ALM);
	_rtc_register_write ((pointer)&rtc->RTC_IER, TRUE, tmp);
} /* Endbody */
Beispiel #6
0
/*FUNCTION****************************************************************
* 
* Function Name    : _rtc_set_time
* Returned Value   : none
* Comments         :
*    This function sets the RTC time according to given time struct.
*
*END*********************************************************************/
void _rtc_set_time 
(
	/* [IN] given time to be set as RTC time */
	RTC_TIME_STRUCT_PTR time
)
{ /* Body */
    uint_32 tmp;
	VMCF53XX_RTC_STRUCT_PTR rtc = _bsp_get_rtc_base_address ();
	tmp = _rtc_register_write ((pointer)&rtc->RTC_CR, TRUE, 0);
	_rtc_register_write ((pointer)&rtc->RTC_DAYS, FALSE, MCF53XX_RTC_DAYS(time->days));
	_rtc_register_write ((pointer)&rtc->RTC_SECONDS, TRUE, MCF53XX_RTC_SECONDS_WRITE(time->seconds));
	_rtc_register_write ((pointer)&rtc->RTC_HOURMIN, TRUE, MCF53XX_RTC_HOURMIN_HOURS_WRITE(time->hours) | MCF53XX_RTC_HOURMIN_MINUTES_WRITE(time->minutes));
	if (tmp & MCF53XX_RTC_CR_EN) 
	{
		_rtc_register_write ((pointer)&rtc->RTC_CR, TRUE, MCF53XX_RTC_CR_EN);
	}
} /* Endbody */
Beispiel #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;
    VMCF51XX_RTC_STRUCT_PTR rtc = _bsp_get_rtc_base_address ();
    rtc->RTCSC = MCF51XX_RTC_RTCSC_RTCLKS(0) | MCF51XX_RTC_RTCSC_RTCPS(0x0F);  // clear the interrupt flag, 1kHz internal clock,1s interval
    rtc->RTCMOD = 0;             // 1s interrupt

    // clear time, alarm and stopwatch, if requested
    if (flags & RTC_INIT_FLAG_CLEAR) {      
      real_time.seconds = 0;
      real_time.minutes = 0;
      real_time.hours = 0;
      real_time.days = 0;
      alarm_time.seconds = 0;
      alarm_time.minutes = 0;
      alarm_time.hours = 0;
      alarm_time.days = 0;
      stopwatch = 0;
    }

    // reset current user interrupt state and callback, if requested
    if (flags & RTC_INIT_FLAG_RESET) {
      user_requests = 0;
      user_enables = 0;
      user_isr = NULL;
      stopwatch = (uint_32)-1;
    }

    // install HW interrupt and run the RTC, if requested
    if (flags & RTC_INIT_FLAG_ENABLE) {
      if (NULL == _int_install_isr (_bsp_get_rtc_vector (), (void (_CODE_PTR_))_rtc_isr, (pointer)rtc)) result = _task_get_error ();
      if (MQX_OK == result) {
        rtc->RTCSC |= MCF51XX_RTC_RTCSC_RTIE;
      }
    }

    return result;
}
Beispiel #8
0
/*FUNCTION****************************************************************
* 
* Function Name    : _rtc_get_time
* Returned Value   : none
* Comments         :
*    This function gets the RTC time and stores it in given time struct.
*
*END*********************************************************************/
void _rtc_get_time 
(
	/* [OUT] this parameter gets actual RTC time */
	RTC_TIME_STRUCT_PTR time
)
{ /* Body */
	vuint_32 hm;
    RTC_TIME_STRUCT tmp;
	VMCF53XX_RTC_STRUCT_PTR rtc = _bsp_get_rtc_base_address ();
	time->hours = 0xFF;
	do 
	{
		tmp.days = time->days;
		tmp.seconds = time->seconds;
		tmp.hours = time->hours;
		tmp.minutes = time->minutes;
		time->days = MCF53XX_RTC_DAYS(_rtc_register_read ((pointer)&rtc->RTC_DAYS, FALSE));
		time->seconds = MCF53XX_RTC_SECONDS_READ(_rtc_register_read ((pointer)&rtc->RTC_SECONDS, TRUE));
		hm = _rtc_register_read ((pointer)&rtc->RTC_HOURMIN, TRUE);
		time->hours = MCF53XX_RTC_HOURMIN_HOURS_READ(hm);
		time->minutes = MCF53XX_RTC_HOURMIN_MINUTES_READ(hm);
	} while ((tmp.seconds != time->seconds) || (tmp.minutes != time->minutes) || (tmp.hours != time->hours) || (tmp.days != time->days));
} /* Endbody */