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

📄 rtc_functions.c

📁 MMI层OBJ不能完全编译
💻 C
📖 第 1 页 / 共 3 页
字号:
/************************************************************************************/
/* rtc_functions.c :            contains low level function for the rtc             */
/*                                                                                  */
/*                                                                                  */
/*   Author: Laurent Sollier                                                        */
/*                                                                                  */
/*   version: 1.0                                                                   */
/*                                                                                  */
/*   Date: 03/20/01                                                                 */
/*   (C) Copyright 2001 by Texas Instruments Incorporated, All Rights Reserved      */   
/************************************************************************************/

#ifndef _WINDOWS
   #include "l1sw.cfg" 
   #include "chipset.cfg"
#endif

#include <string.h> /* needed for memset */
#include "nucleus.h"

#include "rtc/rtc_messages_i.h"
#include "rvm/rvm_use_id_list.h"
#include "rtc/rtc_api.h"
#include "rtc/rtc_i.h"
#include "rtc/board/rtc_config.h" 

#include "memif/mem.h"
#include "inth/iq.h"
#include "ulpd/ulpd.h"

#if (CHIPSET == 12)
  #include "inth/sys_inth.h"
#else
  #include "inth/inth.h"
#endif

#if (CHIPSET == 15)
/* This fix is provided to avoid compilation errors
 * because of mutiple definition for TRUE and FALSE
 * in different header files */
 #undef TRUE
 #undef FALSE

 #include "bspTwl3029.h"
 #include "bspTwl3029_I2c.h"
 #include "bspTwl3029_IntC.h"
 #include "bspTwl3029_Rtc.h"
#endif

#if (CHIPSET != 15)

/* ----- Macro ----- */
/*-------------------------------------------------------------*/
/* RTC_STOP                                                    */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Stop the RTC (STOP_RTC is cleared)          */
/*-------------------------------------------------------------*/
#define RTC_STOP  (* (volatile UINT8 *) RTC_CTRL_REG &= ~RTC_START_RTC)

/*-------------------------------------------------------------*/
/* RTC_START                                                   */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Start the RTC                               */
/*-------------------------------------------------------------*/
#define RTC_START (* (volatile UINT8 *) RTC_CTRL_REG |= RTC_START_RTC) 

/*-------------------------------------------------------------*/
/* RTC_SET_32_CNT                                              */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Set the SET_32_COUNTER bit                  */
/*-------------------------------------------------------------*/
#define RTC_SET_32_CNT (* (volatile UINT8 *) RTC_CTRL_REG |= RTC_SET_32_COUNTER)

/*-------------------------------------------------------------*/
/* RTC_RESET_32_CNT                                            */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Reset the SET_32_COUNTER bit                */
/*-------------------------------------------------------------*/
#define RTC_RESET_32_CNT  (* (volatile UINT8 *) RTC_CTRL_REG &= ~RTC_SET_32_COUNTER)

/*-------------------------------------------------------------*/
/* RTC_SET_TEST_MODE                                           */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Set the TEST_MODE bit                       */
/*-------------------------------------------------------------*/
#define RTC_SET_TEST_MODE (* (volatile UINT8 *) RTC_CTRL_REG |= RTC_TEST_MODE)

/*-------------------------------------------------------------*/
/* RTC_ENABLE_IT_ALARM                                         */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Enable the IT_ALARM                         */
/*-------------------------------------------------------------*/
#define RTC_ENABLE_IT_ALARM (* (volatile UINT8 *) RTC_INTERRUPTS_REG |= RTC_IT_ALARM)

/*-------------------------------------------------------------*/
/* RTC_DISABLE_IT_ALARM                                        */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Disable the IT_ALARM                        */
/*-------------------------------------------------------------*/
#define RTC_DISABLE_IT_ALARM (* (volatile UINT8 *) RTC_INTERRUPTS_REG &= ~RTC_IT_ALARM)

/*-------------------------------------------------------------*/
/* RTC_ENABLE_IT_TIMER                                         */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Enable the IT_TIMER                         */
/*-------------------------------------------------------------*/
#define RTC_ENABLE_IT_TIMER (* (volatile UINT8 *) RTC_INTERRUPTS_REG |= RTC_IT_TIMER)

/*-------------------------------------------------------------*/
/* RTC_DISABLE_IT_TIMER                                        */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Disable the IT_TIMER                        */
/*-------------------------------------------------------------*/
#define RTC_DISABLE_IT_TIMER (* (volatile UINT8 *) RTC_INTERRUPTS_REG &= ~RTC_IT_TIMER)

/*-------------------------------------------------------------*/
/* RTC_SET_EVENT_TIMER                                         */
/*-------------------------------------------------------------*/
/* Parameters :   event to enable or disable                   */
/* Return :   none                                             */
/* Functionality : Set the event for the IT_TIMER              */
/*         Enable or disable IT                                */
/*-------------------------------------------------------------*/
#define RTC_SET_EVENT_TIMER(x) (* (volatile UINT8 *) RTC_INTERRUPTS_REG = (* (volatile UINT8 *) RTC_INTERRUPTS_REG & 0xfffc) | (x))

/*-------------------------------------------------------------*/
/* RTC_TEST_BUSY                                               */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Return the RTC state busy signal            */
/*-------------------------------------------------------------*/
#define RTC_TEST_BUSY ((* (volatile UINT8 *) RTC_STATUS_REG) & RTC_BUSY) 

/*-------------------------------------------------------------*/
/* RTC_RUN_STATE                                               */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Return the RTC run state                    */
/*-------------------------------------------------------------*/
#define RTC_RUN_STATE ((* (volatile UINT8 *) RTC_STATUS_REG) & RTC_RUN) 

/*-------------------------------------------------------------*/
/* RTC_FREE_AL_ITLINE                                          */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : free it AL line                             */
/*-------------------------------------------------------------*/

#define RTC_FREE_AL_ITLINE ((* (volatile UINT8 *) RTC_STATUS_REG) |= RTC_ALARM) 

/*-------------------------------------------------------------*/
/* RTC_FREE_POWER_UP                                           */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : clear reset event                           */
/*-------------------------------------------------------------*/

#define RTC_FREE_POWER_UP ((* (volatile UINT8 *) RTC_STATUS_REG) |= RTC_POWER_UP) 


/*-------------------------------------------------------------*/
/* RTC_GET_EVENT_TIMER                                         */
/*-------------------------------------------------------------*/
/* Parameters :   none                                         */
/* Return :   none                                             */
/* Functionality : Get the event status for the IT_TIMER       */
/*-------------------------------------------------------------*/
#define RTC_GET_EVENT_TIMER ((* (volatile UINT8 *) RTC_STATUS_REG & 0x3c))

#endif


/* ----- Global variables ----- */
static T_RTC_DATE_TIME rtc_date_time_alarm = {0};
static void SetInitAlmTime(T_RTC_DATE_TIME date_time);
static T_RV_RETURN rtc_return_path = {RVF_INVALID_ADDR_ID, NULL};
static T_RTC_ALARM* rtc_msg_alarm_event = NULL;

extern T_RTC_ENV_CTRL_BLK* rtc_env_ctrl_blk;


/* Number of 32 Khz clock */
static UINT32 rtc_nb_32khz = 0;

/* Number of high frequency clock */
static UINT32 rtc_nb_hf = 0;

static NU_HISR hisr;
#ifndef HISR_STACK_SHARING
char hisrStack[512];
#endif

// UINT16 toto = 0; tmp

void HisrEntryFunc(void)
{
   if (rtc_msg_alarm_event)
      rvf_send_msg(rtc_env_ctrl_blk->addr_id, rtc_msg_alarm_event);
   //char comp[15];
/*   sprintf(comp,"%d",toto);
   LCDG_WriteString( 4, 0, "              ");
   LCDG_WriteString( 3, 0, (char*) comp); //tmp */
}


/*---------------------------------------------------------------*/
/* conv_bin   DCB => B                                           */
/*---------------------------------------------------------------*/
/* Parameters : value to be convert                              */
/* Return :   none                                               */
/* Functionality : BCD et binary conversion function             */
/*---------------------------------------------------------------*/

static UINT8 conv_bin(UINT8 value)
{
   return (10*(value>>4) + ( value & 0x0f));
}

/*---------------------------------------------------------------*/
/* conv_bcd    B => DCB                                          */
/*---------------------------------------------------------------*/
/* Parameters : value to be convert                              */
/* Return :   none                                               */
/* Functionality : Binary to BCD conversion function             */
/*---------------------------------------------------------------*/

static UINT8 conv_bcd(UINT8 value)
{
   return ((value%10) | ( (value/10) <<4));
}


static void SetInitAlmTime(T_RTC_DATE_TIME date_time)
{
	date_time.second = 0;
	date_time.minute = 0;
   	if (date_time.mode_12_hour == FALSE)
   	{
		date_time.hour = 0;
   	}
   	else
   	{
     		date_time.hour = 1;
   	}
	date_time.month = 1;
	date_time.year = 0;
	date_time.wday = 6;
 	date_time.month = 1;

}
/*---------------------------------------------------------------*/
/* format_date_available                                         */
/*---------------------------------------------------------------*/
/* Parameters : T_RTC_DATE_TIME structure                        */
/* Return :     TRUE if format is available                      */
/*              FALSE else                                       */
/* Functionality : test if date and time format is available     */
/*---------------------------------------------------------------*/

BOOL format_date_available(T_RTC_DATE_TIME date_time)
{
   UINT8 m;

   if (date_time.second < 0 || date_time.second > 59)
      return FALSE;
   if (date_time.minute < 0 || date_time.minute > 59)
      return FALSE;
   if (date_time.mode_12_hour == FALSE)
   {
      if (date_time.hour < 0 || date_time.hour > 23)
         return FALSE;
   }
   else
      if (date_time.hour < 1 || date_time.hour > 12)
         return FALSE;

   if (date_time.month < 1 || date_time.month > 12)
      return FALSE;
   if (date_time.year < 0 || date_time.year > 99)
      return FALSE;
   if (date_time.wday < 0 || date_time.wday > 6)
      return FALSE;
   m = date_time.month;
   if (m == 1||m == 3||m == 5||m == 7||m == 8||m == 10||m == 12)
   {
      if (date_time.day < 1 || date_time.day > 31)
         return FALSE;
   }
   else
   {
      if (m == 4||m == 6||m == 9||m == 11)
      {
         if (date_time.day < 1 || date_time.day > 30)
            return FALSE;
      }
      else
      {
         if (date_time.year%4)
         {
            if (date_time.day < 1 || date_time.day > 29)
               return FALSE;
         }
         else
         {
            if (date_time.day < 1 || date_time.day > 28)
               return FALSE;
         }
      }
   }
   return TRUE;
}



/*******************************************************************************
 *
 *                               RTC_Initialize
 *
 ******************************************************************************/



T_RVF_RET RTC_Initialize(void)
{
   T_RVF_MB_STATUS   mb_status;

   // Bgn >>> Add 在calypso平台为了解决rtc不准加入,现在locosto中暂时丢弃,
   //以观后效。若需修改,需依locosto register map查看。----caisheng 20060526
   /**((volatile unsigned short *) 0xfffef00c) = 0x2C;
   *((volatile unsigned short *) 0xfffe1815) = 0x2C;*/
   // End <<<

   /* Reserve memory for alarm event */

⌨️ 快捷键说明

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