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

📄 utc.c

📁 汉字在计算机内存放分为两种情况
💻 C
📖 第 1 页 / 共 2 页
字号:
/*******************************************************************************
** Notice: Copyright (c) 2001 LSI Logic Corporation - All Rights Reserved 
**
** File Name:  utc.c
**
** $Revision: \main\20010426_1.4_integration_branch\7 $ 
** $Date:     Tue Jul  2 13:24:04 2002 $
**
** Description:  This file contains UTC control and manipulation functions.
**
*******************************************************************************/
#include "gendef.h"
#include "keydef.h"
#include "utc.h"

#define UTC_MAX_OFFSETS  (3)

#define UTC_DEBUG        (FALSE)

typedef struct
{
  UINT16 countryCode;
  UINT8  regionID;
  UINT16 offset;
  UINT8  negative;
} T_UTCOffset;
#if 0
struct COUNTRY countries[] =
{
  {"Afghanistan", 136}, /* AFG */
  {"Albania", 287}, /* ALB */
  {"Algeria", 2678}, /* DZA */
  {"American Samoa", 480}, /* ASM */
  {"Andorra", 341}, /* AND */
  {"Angola", 170}, /* AGO */
  {"Anguilla", 208}, /* AIA */
  {"Antigua & Barbuda", 500}, /* ATG */
  {"Argentina", 448}, /* ARG */
  {"Armenia", 454}, /* ARM */
  {"Aruba", 48}, /* ABW */
  {"Australia", 538}, /* AUS */
  {"Austria", 539}, /* AUT */
  {"Azerbaijan", 654}, /* AZE */
  {"Bahamas", 876}, /* BHS */
  {"Bahrain", 875}, /* BHR */
  {"Bangladesh", 835}, /* BGD */
  {"Barbados", 1119}, /* BRB */
  {"Belarus", 979}, /* BLR */
  {"Belgium", 791}, /* BEL */
  {"Belize", 987}, /* BLZ */
  {"Benin", 793}, /* BEN */
  {"Bermuda", 1008}, /* BMU */
  {"Bhutan", 1183}, /* BTN */
  {"Bolivia", 1051}, /* BOL */
  {"Bosnia & Herzegovina", 891}, /* BIH */
  {"Botswana", 1248}, /* BWA */
  {"Brazil", 1118}, /* BRA */
  {"British Virgin Is", 14353}, /* VGB */
  {"Brunei Darussalam", 1131}, /* BRN */
  {"Bulgaria", 849}, /* BGR */
  {"Burkina Faso", 806}, /* BFA */
  {"Burundi", 762}, /* BDI */
  {"Cambodia", 6954}, /* KHM */
  {"Cameroon", 1681}, /* CMR */
  {"Canada", 1365}, /* CAN */
  {"Cape Verde", 1763}, /* CPV */
  {"Cayman Islands", 1988}, /* CYM */
  {"Central African Republic", 1357}, /* CAF */
  {"Chad", 12899}, /* TCD */
  {"Chile", 1545}, /* CHL */
  {"China", 1547}, /* CHN */
  {"Colombia", 1727}, /* COL */
  {"Comoros", 1728}, /* COM */
  {"Congo", 1722}, /* COG */
  {"Cook Islands", 1726}, /* COK */
  {"Costa Rica", 1802}, /* CRI */
  {"Cote d'Ivoire", 1581}, /* CIV */
  {"Croatia", 5195}, /* HRV */
  {"Cuba", 1873}, /* CUB */
  {"Cyprus", 1991}, /* CYP */
  {"Czech Republic", 2006}, /* CZE */
  {"Democratic Rep of the Congo", 1719}, /* COD */
  {"Denmark", 2376}, /* DNK */
  {"Djibouti", 2270}, /* DJI */
  {"Dominica", 2340}, /* DMA */
  {"Dominican Republic", 2404}, /* DOM */
  {"East Timor", 13171}, /* TMP */
  {"Ecuador", 2776}, /* ECU */
  {"Egypt", 2884}, /* EGY */
  {"El Salvador", 12475}, /* SLV */
  {"Equatorial Guinea", 4410}, /* GNQ */
  {"Eritrea", 3154}, /* ERI */
  {"Estonia", 3191}, /* EST */
  {"Ethiopia", 3205}, /* ETH */
  {"Faeroe Islands", 3836}, /* FRO */
  {"Falkland Islands", 3676}, /* FLK */
  {"Fiji", 3622}, /* FJI */
  {"Finland", 3601}, /* FIN */
  {"France", 3822}, /* FRA */
  {"French Guiana", 4581}, /* GUF */
  {"French Polynesia", 10769}, /* PYF */
  {"Gabon", 4057}, /* GAB */
  {"Gambia", 4369}, /* GMB */
  {"Georgia", 4174}, /* GEO */
  {"Germany", 2152}, /* DEU */
  {"Ghana", 4238}, /* GHA */
  {"Gibraltar", 4265}, /* GIB */
  {"Greece", 4500}, /* GRC */
  {"Greenland", 4509}, /* GRL */
  {"Grenada", 4501}, /* GRD */
  {"Guadeloupe", 4357}, /* GLP */
  {"Guam", 4588}, /* GUM */
  {"Guatemala", 4562}, /* GTM */
  {"Guinea", 4277}, /* GIN */
  {"Guinea-Bissau", 4395}, /* GNB */
  {"Guyana", 4600}, /* GUY */
  {"Haiti", 5234}, /* HTI */
  {"Holy See", 14215}, /* VAT */
  {"Honduras", 5073}, /* HND */
  {"Hong Kong", 4998}, /* HKG */
  {"Hungary", 5265}, /* HUN */
  {"Iceland", 5887}, /* ISL */
  {"India", 5749}, /* IND */
  {"Indonesia", 5499}, /* IDN */
  {"Iran", 5863}, /* IRN */
  {"Iraq", 5866}, /* IRQ */
  {"Ireland", 5861}, /* IRL */
  {"Isle of Man", 5744}, /* IMY */
  {"Israel", 5893}, /* ISR */
  {"Italy", 5902}, /* ITA */
  {"Jamaica", 6096}, /* JAM */
  {"Japan", 6487}, /* JPN */
  {"Jordan", 6465}, /* JOR */
  {"Kazakhstan", 6785}, /* KAZ */
  {"Kenya", 6877}, /* KEN */
  {"Kiribati", 6985}, /* KIR */
  {"Korea, North", 10592}, /* PRK */
  {"Korea, South", 7141}, /* KOR */
  {"Kuwait", 7351}, /* KWT */
  {"Kyrgyzstan", 6941}, /* KGZ */
  {"Lao People's Democratic Rep", 7450}, /* LAO */
  {"Latvia", 7982}, /* LVA */
  {"Lebanon", 7475}, /* LBN */
  {"Lesotho", 7918}, /* LSO */
  {"Liberia", 7479}, /* LBR */
  {"Libya", 7486}, /* LBY */
  {"Liechtenstein", 7648}, /* LIE */
  {"Lithuania", 7950}, /* LTU */
  {"Luxembourg", 7979}, /* LUX */
  {"Macao", 8114}, /* MAC */
  {"Macedonia", 8375}, /* MKD */
  {"Madagascar", 8196}, /* MDG */
  {"Malawi", 8692}, /* MWI */
  {"Malaysia", 8754}, /* MYS */
  {"Maldives", 8211}, /* MDV */
  {"Mali", 8406}, /* MLI */
  {"Malta", 8417}, /* MLT */
  {"Marshall Islands", 8305}, /* MHL */
  {"Martinique", 8622}, /* MTQ */
  {"Mauritania", 8573}, /* MRT */
  {"Mauritius", 8650}, /* MUS */
  {"Mexico", 8239}, /* MEX */
  {"Micronesia, Fed States of", 3860}, /* FSM */
  {"Monaco", 8178}, /* MCO */
  {"Mongolia", 8456}, /* MNG */
  {"Montserrat", 8597}, /* MSR */
  {"Morocco", 8129}, /* MAR */
  {"Mozambique", 8501}, /* MOZ */
  {"Myanmar", 8441}, /* MMR */
  {"Namibia", 8800}, /* NAM */
  {"Nauru", 9250}, /* NRU */
  {"Nepal", 9189}, /* NPL */
  {"Netherlands", 9077}, /* NLD */
  {"Netherlands Antilles", 357}, /* ANT */
  {"New Caledonia", 8851}, /* NCL */
  {"New Zealand", 9449}, /* NZL */
  {"Nicaragua", 8998}, /* NIC */
  {"Niger", 8909}, /* NER */
  {"Nigeria", 8944}, /* NGA */
  {"Niue", 9016}, /* NIU */
  {"Norfolk Island", 8928}, /* NFK */
  {"Northern Mariana Islands", 8465}, /* MNP */
  {"Norway", 9169}, /* NOR */
  {"Occupied Palestinian Territory", 10612}, /* PSE */
  {"Oman", 9789}, /* OMN */
  {"Pakistan", 10150}, /* PAK */
  {"Palau", 10448}, /* PLW */
  {"Panama", 10153}, /* PAN */
  {"Papua New Guinea", 10484}, /* PNG */
  {"Paraguay", 10606}, /* PRY */
  {"Peru", 10261}, /* PER */
  {"Philippines", 10333}, /* PHL */
  {"Pitcairn", 10205}, /* PCN */
  {"Poland", 10515}, /* POL */
  {"Portugal", 10601}, /* PRT */
  {"Puerto Rico", 10590}, /* PRI */
  {"Qatar", 10835}, /* QAT */
  {"Republic of Moldova", 8190}, /* MDA */
  {"Reunion", 11616}, /* REU */
  {"Romania", 11868}, /* ROM */
  {"Russian Federation", 12030}, /* RUS */
  {"Rwanda", 12064}, /* RWA */
  {"Saint Helena", 12363}, /* SHN */
  {"Saint Kitts & Nevis", 7098}, /* KNA */
  {"Saint Lucia", 7488}, /* LCA */
  {"Saint Pierre & Miquelon", 12570}, /* SPM */
  {"St Vincent & the Grenadines", 14267}, /* VCT */
  {"Samoa", 15352}, /* WSM */
  {"San Marino", 12497}, /* SMR */
  {"Sao Tome & Principe", 12677}, /* STP */
  {"Saudi Arabia", 12188}, /* SAU */
  {"Senegal", 12285}, /* SEN */
  {"Seychelles", 12794}, /* SYC */
  {"Sierra Leone", 12458}, /* SLE */
  {"Singapore", 12339}, /* SGP */
  {"Slovakia", 12724}, /* SVK */
  {"Slovenia", 12727}, /* SVN */
  {"Solomon Islands", 12455}, /* SLB */
  {"Somalia", 12544}, /* SOM */
  {"South Africa", 16905}, /* ZAF */
  {"Spain", 3187}, /* ESP */
  {"Sri Lanka", 7696}, /* LKA */
  {"Sudan", 12259}, /* SDN */
  {"Suriname", 12705}, /* SUR */
  {"Svalbard & Jan Mayen Is", 12414}, /* SJM */
  {"Swaziland", 12765}, /* SWZ */
  {"Sweden", 12744}, /* SWE */
  {"Switzerland", 1538}, /* CHE */
  {"Syrian Arab Republic", 12809}, /* SYR */
  {"Taiwan", 13429}, /* TWN */
  {"Tajikistan", 13088}, /* TJK */
  {"Tanzania", 13494}, /* TZA */
  {"Thailand", 13026}, /* THA */
  {"Togo", 13014}, /* TGO */
  {"Tokelau", 13115}, /* TKL */
  {"Tonga", 13221}, /* TON */
  {"Trinidad & Tobago", 13352}, /* TTO */
  {"Tunisia", 13377}, /* TUN */
  {"Turkey", 13381}, /* TUR */
  {"Turkmenistan", 13116}, /* TKM */
  {"Turks & Caicos Is", 12896}, /* TCA */
  {"Tuvalu", 13385}, /* TUV */
  {"Uganda", 13676}, /* UGA */
  {"Ukraine", 13797}, /* UKR */
  {"United Arab Emirates", 446}, /* ARE */
  {"United Kingdom", 4099}, /* GBR */
  {"United States", 13988}, /* USA */
  {"US Virgin Is", 14421}, /* VIR */
  {"Uruguay", 13986}, /* URY */
  {"Uzbekistan", 14171}, /* UZB */
  {"Vanuatu", 14735}, /* VUT */
  {"Venezuela", 14313}, /* VEN */
  {"Viet Nam", 14546}, /* VNM */
  {"Wallis & Futuna Is", 15163}, /* WLF */
  {"Western Sahara", 3179}, /* ESH */
  {"Yemen", 16340}, /* YEM */
  {"Yugoslavia", 16750}, /* YUG */
  {"Zambia", 17213}, /* ZMB */
  {"Zimbabwe", 17476}, /* ZWE */
};
#endif
static T_UTCOffset UTCOffsets[UTC_MAX_OFFSETS] = {
  { 1547,   0xFF, 0, 0 },
  { 0xFFFF, 0xFF, 0, 0 },
  { 0xFFFF, 0xFF, 0, 0 }
};

static UINT16       UTCCurrentTime = 0;
static UINT16       UTCCurrentMJD = 0;
static T_UTCOffset *UTCCurrentOffset;

/****************************************************************************
** Function       UTCInitialize
**
** Description    Initialize the UTC module bu setting the current time and 
**                offset.
**              
** Input          None
**
** Modified       None
**
** Return         Nothing
**              
*****************************************************************************/
void UTCInitialize( void )
{
  UTCCurrentTime   = 0;
  UTCCurrentOffset = NULL;
}

/****************************************************************************
** Function     UTCGetCurrentTime
**
** Description  Returns the UTC value of the current time, specifically the
**              last TDT value which may only be updated every 30 seconds.
**
** Input        None
**
** Modified     None
**
** Return       UTC value of current time - last TDT value
**
*****************************************************************************/
UINT16 UTCGetCurrentTime( void )
{
  return(UTCCurrentTime);  
}  

/****************************************************************************
** Function     UTCGetCurrentDate
**
** Description  Returns the MJD value of the current date, specifically the
**              last TDT value which may only be updated every 30 seconds.
**
** Input        None
**
** Modified     None
**
** Return       MJD value of current date - last TDT value
**
*****************************************************************************/
UINT16 UTCGetCurrentDate( void )
{
  return(UTCCurrentMJD);  
}  

/****************************************************************************
** Function     UTCConvertToString
**
** Description  Convert a UTC BCD time to a string of the following format:
**               hh:mm. It will always take 6 bytes (including terminating
**               char)
**
** Input        UINT16 utc - BCD coded time code of the format [hhmm]
**
** Modified     buffer - 6 bytes written to.
**
** Return       nothing
**
*****************************************************************************/
void UTCConvertToString( UINT16 utc, UINT8 *buffer )
{
  *buffer++ = (UINT8)(((utc & 0xF000) >> 12) + '0');
  *buffer++ = (UINT8)(((utc & 0x0F00) >> 8) + '0');
  *buffer++ = ':';
  *buffer++ = (UINT8)(((utc & 0x00F0) >> 4) + '0');
  *buffer++ = (UINT8)((utc & 0x000F) + '0');
  *buffer   = '\0';  
}

/****************************************************************************
** Function     UTCAdd
**
** Description  Add to UTC BCD times. If the times overflow 24:00, then bit 
**              [16] is set.
**
** Input        UINT16 lhs - BCD coded time code of the format [hhmm]
**              UINT16 rhs - BCD coded time code of the format [hhmm]
**
** Modified     None
**
** Return       UINT32 - lhs + rhs including overflow
**
*****************************************************************************/
UINT32 UTCAdd(UINT16 lhs, UINT16 rhs)
{
  UINT32 result;
  INT32  hours,
         minutes,
         overflow = 0;

  hours   = ((((lhs & 0xF000) >> 12) * 10) + ((lhs & 0x0F00) >> 8) +
             (((rhs & 0xF000) >> 12) * 10) + ((rhs & 0x0F00) >> 8));
  minutes = ((((lhs & 0x00F0) >>  4) * 10) +  (lhs & 0x000F) +
             (((rhs & 0x00F0) >>  4) * 10) +  (rhs & 0x000F));

  /* Check for overflows */
  if (minutes >= 60)
  {
    hours++;
    minutes -= 60;
  }
  
  if (hours >= 24)
  {
    overflow++;
    hours -= 24;
  }

  /*
  ** Hours digits.
  */
  result  = (UINT32)(overflow << 16);
  result |= (UINT32)(((hours / 10) & 0xF) << 12);
  result |= (UINT32)(((hours % 10) & 0xF) << 8);

  /*
  ** Minutes digits.
  */
  result |= (UINT32)(((minutes / 10) & 0xF) << 4);
  result |= (UINT32) ((minutes % 10) & 0xF);

  return result;
}

/****************************************************************************
** Function     UTCSubtract
**
** Description  Subtract two UTC BCD times. If the time underflows, then bit 
**              [31:16] are set.
**
** Input        UINT16 lhs - BCD coded time code of the format [hhmm]
**              UINT16 rhs - BCD coded time code of the format [hhmm]
**
** Modified     None
**
** Return       UINT32 - lhs - rhs including underflow
**
*****************************************************************************/
UINT32 UTCSubtract( UINT16 lhs, UINT16 rhs )
{
  INT32  hours;
  INT32  minutes;

⌨️ 快捷键说明

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