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

📄 rtc_functions.c

📁 MMI层OBJ不能完全编译
💻 C
📖 第 1 页 / 共 3 页
字号:
}


/*******************************************************************************
 *
 *                               RTC_SetAlarm
 *
 ******************************************************************************/

T_RVF_RET RTC_SetAlarm(T_RTC_DATE_TIME date_time, T_RV_RETURN return_path)
{
#if (CHIPSET != 15)
   UINT8 sec;
   UINT8 min;
   UINT8 hour;
   UINT8 day;
   UINT8 month;
   UINT8 year;
   UINT8 wday;


   /* testing parameter range validity */
   if (!format_date_available(date_time))
   {
	SetInitAlmTime(date_time);
   }

   sec = conv_bcd(date_time.second);
   min = conv_bcd(date_time.minute);

   if (date_time.mode_12_hour == FALSE)
      hour = conv_bcd(date_time.hour);
   else
      hour = conv_bcd(date_time.hour) | (date_time.PM_flag << 7);

   day = conv_bcd(date_time.day);
   month = conv_bcd(date_time.month);
   year = conv_bcd(date_time.year);
   wday = conv_bcd(date_time.wday);

   /* Disable all IT before reading register */
   rvf_disable();

   if (RTC_TEST_BUSY)
   {   
      rvf_enable();
      return RVF_NOT_READY;
   }
   else
   {
      *(volatile UINT8*) RTC_ALARM_DAYS_REG = day;
      *(volatile UINT8*) RTC_ALARM_MONTHS_REG = month;
      *(volatile UINT8*) RTC_ALARM_YEARS_REG = year;   
      *(volatile UINT8*) RTC_ALARM_SECONDS_REG = sec;
      *(volatile UINT8*) RTC_ALARM_MINUTES_REG = min;
      *(volatile UINT8*) RTC_ALARM_HOURS_REG = hour;

      /* Enable alarm*/
      RTC_ENABLE_IT_ALARM;
      rvf_enable();

      /* Save callback */
      rtc_return_path.callback_func = return_path.callback_func;
      rtc_return_path.addr_id        = return_path.addr_id;
   }
#else
   bspTwl3029_Rtc_DateTime dateTime;

#if 0   
   /* testing parameter range validity */
   if (!format_date_available(date_time))
      return RVF_INVALID_PARAMETER;

   dateTime.second = conv_bcd(date_time.second);
   dateTime.minute = conv_bcd(date_time.minute);

   if (date_time.mode_12_hour == FALSE)
      dateTime.hour = conv_bcd(date_time.hour);
   else
      dateTime.hour = conv_bcd(date_time.hour) | (date_time.PM_flag << 7);

   dateTime.day = conv_bcd(date_time.day);
   dateTime.month = conv_bcd(date_time.month);
   dateTime.year = conv_bcd(date_time.year);
   dateTime.wday = conv_bcd(date_time.wday);
#endif

   dateTime.second = date_time.second;
   dateTime.minute = date_time.minute;
   dateTime.hour = date_time.hour;
   dateTime.day = date_time.day;
   dateTime.month = date_time.month;
   dateTime.year = date_time.year;
   dateTime.wday = date_time.wday;
   dateTime.hourType = date_time.PM_flag;

   if( 1 == date_time.mode_12_hour  )
	dateTime.hourMode = BSPTWL3029_RTC_12_HOURMODE;
   else
	dateTime.hourMode = BSPTWL3029_RTC_24_HOURMODE;

    if( BSP_TWL3029_RETURN_CODE_FAILURE == bspTwl3029_Rtc_SetAlarm(dateTime, RTC_ItAlarmHandle))
    {
        return RVF_INTERNAL_ERR;
    }

   /* Save callback */
   rtc_return_path.callback_func = return_path.callback_func;
   rtc_return_path.addr_id        = return_path.addr_id;
   
#endif
   
   return RVF_OK;
}


/*******************************************************************************
 *
 *                               RTC_UnsetAlarm
 *
 ******************************************************************************/

T_RVF_RET RTC_UnsetAlarm(void)
{
#if (CHIPSET != 15)
   /* Disable all IT before reading register */
   rvf_disable();

   if (RTC_TEST_BUSY)
   {   
      rvf_enable();
      return RVF_NOT_READY;
   }
   else
   {
      /* Disable alarm*/
      RTC_DISABLE_IT_ALARM;
      rvf_enable();
   }
#else
   if( BSP_TWL3029_RETURN_CODE_FAILURE == bspTwl3029_Rtc_UnsetAlarm () )
   {
      return RVF_INTERNAL_ERR;
   }

#endif
   return RVF_OK;
}


/*******************************************************************************
 *
 *                               RTC_Rounding30s
 *
 ******************************************************************************/

void RTC_Rounding30s(void)
{
#if (CHIPSET != 15)
   *(UINT8*) RTC_CTRL_REG |= RTC_ROUND_30S;
#else
   bspTwl3029_Rtc_Rounding30s();
#endif
}


/*******************************************************************************
 *
 *                               RTC_Set12HourMode
 *
 ******************************************************************************/

void RTC_Set12HourMode(BOOL Mode12Hour)
{
#if (CHIPSET != 15)
  if ( Mode12Hour == FALSE)
   * (volatile UINT8*) RTC_CTRL_REG &= 0xf7;
  else
   * (volatile UINT8*) RTC_CTRL_REG |= 0x08;
#else

  if(0 == Mode12Hour)
  {
  	bspTwl3029_Rtc_Set12HourMode(BSPTWL3029_RTC_24_HOURMODE);
  }
  else
	bspTwl3029_Rtc_Set12HourMode(BSPTWL3029_RTC_12_HOURMODE);
  
#endif
}


/*******************************************************************************
 *
 *                               RTC_Is12HourMode
 *
 ******************************************************************************/

BOOL RTC_Is12HourMode(void)
{
#if (CHIPSET != 15)
   if ( (*(volatile UINT8*) RTC_CTRL_REG & RTC_MODE_12_24) )
      return TRUE;
   else
      return FALSE;
#else
   if ( bspTwl3029_Rtc_Is12HourMode() == BSPTWL3029_RTC_12_HOURMODE )
   	return TRUE;
   else
        return FALSE;
#endif
}


/*******************************************************************************
 *
 *                               RTC_ItTimerHandle
 *
 ******************************************************************************/

void RTC_ItTimerHandle(void)
{
#if (CHIPSET != 15 )
   static double compensation = 0;
   static UINT8 nb_sample = 0;
   double delta;
   UINT16 value = 0;
   INT16 tmp_value = 0;
   UINT8 cmp[15];

   /* Evaluate average on one hour max */
   if ( nb_sample < 60)
      nb_sample++;

   /* perform calculation of auto compensation each minute and evaluate an
      average on one hour */
   /* Number of 32 kHz clock lost in one second */
   /* Accurate operation is : delta = CLK_32 - rtc_nb_32khz*CLK_PLL/g_nb_hf */
   /* with CLK_32 = 32768 Hz and CLK_PLL depend on chipset */
   delta = RTC_CLOCK_32K - rtc_nb_32khz*RTC_CLOCK_HF/rtc_nb_hf;

   /* Number of 32 kHz clock lost in one hour */
   delta *= 3600.0;

   /* Average of the compensation to load */
   compensation = (compensation*(nb_sample-1) + delta)/nb_sample;

   if (compensation >= 0x7FFF)
      tmp_value = 0x7FFE;
   else if (compensation <= -0x7FFF)
      tmp_value = -0x7FFE;
   else
      tmp_value = (INT16) compensation;

   if (tmp_value > 0) /* if 32 Khz clock is slow */
      value = tmp_value;
   if (tmp_value < 0) /* if 32 Khz clock is fast */
      value = 0xFFFF + tmp_value + 1;

   /* Set value in compensation register */
   if (!RTC_TEST_BUSY)
   {
      *(volatile UINT8*) RTC_COMP_MSB_REG = (UINT8) (value >> 8);
      *(volatile UINT8*) RTC_COMP_LSB_REG = (UINT8) (value & 0xFF);
   }
/*toto = value; tmp*/
/*NU_Activate_HISR(&hisr); tmp*/
#endif
}


/*******************************************************************************
 *
 *                               RTC_ItAlarmHandle
 *
 ******************************************************************************/

void RTC_ItAlarmHandle(void)
{
   /* Sending alarm event */
   /* Post alarm event in RTC mailbox */
   NU_Activate_HISR(&hisr);

   /*if (rtc_msg_alarm_event)
      rvf_send_msg(rtc_env_ctrl_blk->task_id, rtc_env_ctrl_blk->mbox_id, rtc_msg_alarm_event);*/

#if (CHIPSET != 15)
   /* Free alarm IT line */
   RTC_FREE_AL_ITLINE;
#endif

}

/*******************************************************************************
 *
 *                               RTC_GaugingHandler
 *
 ******************************************************************************/
void RTC_GaugingHandler(void)
{
   /* Number of 32 Khz clock at the end of the gauging */
   rtc_nb_32khz =  ((*(volatile UINT16 *)ULDP_COUNTER_32_MSB_REG) * 0x10000) +
             (*(volatile UINT16 *)ULDP_COUNTER_32_LSB_REG);     

   /* Number of high frequency clock at the end of the gauging */
   /* To convert in nbr of 13 Mhz clocks (5*13=65Mhz) */
   rtc_nb_hf =   ( ((*(volatile UINT16 *)ULDP_COUNTER_HI_FREQ_MSB_REG) * 0x10000) +
            (*(volatile UINT16 *)ULDP_COUNTER_HI_FREQ_LSB_REG) );
}


/*******************************************************************************
 *
 *                               RTC_ProcessAlarmEvent
 *
 ******************************************************************************/

void RTC_ProcessAlarmEvent(void)
{
   T_RVF_MB_STATUS mb_status;
   T_RTC_ALARM* msg_alarm;

   /* Call MMI */
   if (rtc_return_path.callback_func != NULL)
   {
      rtc_return_path.callback_func(NULL);
   }
   else
   {

   	 rvf_send_trace("RTC_ProcessAlarmEvent  rtc_return_path.cb == NULL ",50, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RTC_USE_ID );
	 #if 0  //by dingwei for invalid message 20061012
      /* Reserve memory for alarm event */
      mb_status = rvf_get_buf (rtc_env_ctrl_blk->prim_id, sizeof (T_RTC_ALARM ), (void **) &msg_alarm);   

      if ((mb_status == RVF_GREEN) || (mb_status == RVF_YELLOW)) /* Memory allocation success */
      {      
         msg_alarm->os_hdr.msg_id = RTC_ALARM_EVT;
         /* Send event in the mailbox */
         rvf_send_msg(rtc_return_path.addr_id, msg_alarm);
      }
	
      else
      {
         rvf_send_trace("Memory allocation error",23, NULL_PARAM, RV_TRACE_LEVEL_ERROR, RTC_USE_ID );
      }
	    #endif
   }
}



/*---------------------------------------------------------------------------------------*/

⌨️ 快捷键说明

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