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

📄 hamaro_bcd.c

📁 QPSK Tuner details, for conexant chipset.
💻 C
📖 第 1 页 / 共 2 页
字号:
/* hamaro_bcd.c */

/*+++ *******************************************************************\
*
*   Copyright and Disclaimer:
*
*       ---------------------------------------------------------------
*       ALL SOFTWARE, APPLICATIONS, DOCUMENTATION, OR MATERIALS        
*       FURNISHED HEREIN IS PROVIDED *AS IS*.  CONEXANT DOES NOT MAKE  
*       ANY WARRANTIES, EITHER EXPRESS OR IMPLIED, AND HEREBY EXPRESSLY
*       DISCLAIMS ANY AND ALL SUCH WARRANTIES TO THE EXTENT PERMITTED  
*       BY LAW, INCLUDING, SPECIFICALLY, ANY IMPLIED WARRANTY ARISING  
*       BY STATUTE OR OTHERWISE IN LAW OR FROM A COURSE OF DEALING OR  
*       USAGE OF TRADE.  CONEXANT DOES NOT MAKE ANY WARRANTIES, EITHER 
*       EXPRESS OR IMPLIED, AND HEREBY EXPRESSLY DISCLAIMS ANY AND ALL 
*       SUCH WARRANTIES WITH RESPECT TO ALL SOFTWARE, APPLICATIONS,    
*       DOCUMENTATION, AND MATERIALS INCLUDING ALL IMPLIED WARRANTIES  
*       OF MERCHANTABILITY, OR OF MERCHANTABLE QUALITY, OR OF FITNESS  
*       FOR ANY PURPOSE, PARTICULAR, SPECIFIC OR OTHERWISE, OR OF      
*       NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OF OTHERS,     
*       RELATING TO THE SOFTWARE, APPLICATIONS, OPERATION,             
*       DOCUMENTATION, DATA OR RESULTS GENERATED BY THE OPERATION OR   
*       USE THEREOF, AND MATERIALS PROVIDED HEREIN.  THE ENTIRE RISK AS
*       TO THE SUBSTANCE, QUALITY AND PERFORMANCE OF SOFTWARE,         
*       APPLICATIONS, AND DOCUMENTATION DESCRIBING SUCH SOFTWARE       
*       REMAINS WITH THE BUYER.                                        
*                                                                      
*       REGARDLESS OF WHETHER ANY REMEDY SET FORTH HEREIN FAILS OF ITS 
*       ESSENTIAL PURPOSE OR OTHERWISE, CONEXANT SHALL NOT BE LIABLE   
*       FOR ANY EXEMPLARY, SPECIAL, PUNITIVE, SPECULATIVE, INDIRECT,   
*       CONSEQUENTIAL OR INCIDENTAL DAMAGES OF ANY KIND (INCLUDING     
*       WITHOUT LIMITATION LOST PROFITS, LOSS OF INCOME, LOSS OF       
*       GOODWILL, OR OTHER TANGIBLE OR INTANGIBLE BUSINESS LOSS)       
*       ARISING OUT OF OR IN CONNECTION WITH, DIRECTLY OR INDIRECTLY,  
*       SOFTWARE, APPLICATIONS, DOCUMENTATION, OR ANY SERVICES OR      
*       MATERIALS PROVIDED HEREUNDER, OR USE OR INABILITY TO USE THE   
*       SOFTWARE, EVEN IF CONEXANT HAS BEEN ADVISED OF THE POSSIBILITY 
*       OF SUCH DAMAGES.                                               
*
*       Copyright (c) 2001 Conexant Systems, Inc.
*       All Rights Reserved.
*       ---------------------------------------------------------------
*
*   Module Revision Id:
*
*       $Header: hamaro_bcd.c, 2, 2006-4-8 0:15:52, ShenWei Wang$
*
*   Abstract:
*
*       Contains internal Hamaro Driver software that is called by the API and 
*       other software layers.
*
\******************************************************************* ---*/

#include <time.h>                      /* ANSI Standard */
#include <string.h>                    /* ANSI Standard */
#include <stdlib.h>                    /* ANSI Standard (used for labs() )*/

#undef HAMAROEXT                       /* forces globals to be static to this function */

#include "hamaro.h"                     /* Hamaro include files, ordered */
#include "hamaro_regs.h"                /* Hamaro Internal */

#include "hamaro_bcd.h" 

/*******************************************************************************************************/
/* BCD Functions ***************************************************************************************/
/*******************************************************************************************************/

/*******************************************************************************************************/
/* HAMARO_BCD_add_bcd() */
/*******************************************************************************************************/
void   HAMARO_BCD_add_bcd(                    /* bcd math function used when LONG might be saturated */
HAMARO_BCDNO  *bcd,                           /* bcd struct */
HAMARO_BCDNO  *bcdtoadd)                      /* bcd struct to be used to add to bcd */
{
  int  idx;
  int  result;

  /* add two bcd numbers */
  if (HAMARO_BCD_getsign(bcd) != HAMARO_BCD_getsign(bcdtoadd))
  {
    if (HAMARO_BCD_compare(bcd,bcdtoadd) < 0)
    {
      HAMARO_BCD_subt_bcd(bcdtoadd,HAMARO_BCD_abs(bcd));
      HAMARO_BCD_move_bcd(bcd,bcdtoadd);
    }
    else  HAMARO_BCD_subt_bcd(bcd,bcdtoadd);
    return;
  }

  for (idx = HAMARO_MAX_BCDNO-1 ; idx > 0 ; idx--)
  {
    result = (bcd->digits[idx] + bcdtoadd->digits[idx]);
    bcd->digits[idx] = (signed char)result;
  }

  /* (CR 6805) */
  _HAMARO_BCD_adjust(bcd);

  return;

}  /* HAMARO_BCD_add_bcd() */


/*******************************************************************************************************/
/* _BCD_adjust_improved() */
/*******************************************************************************************************/
void   _HAMARO_BCD_adjust_improved(           /* internal bcd function to adjust bcd struct after computation */
HAMARO_BCDNO  *bcd,                           /* pointer to bcd struct */
int    ledge)                          /* left edge (highest digit) last melded into bcd (add/subt) */
{
  register int  idx;

  for (idx = HAMARO_MAX_BCDNO-1 ; idx > ledge ; )
  {
    if (bcd->digits[idx] >= 0 && bcd->digits[idx] <= 9)  idx--;
    else
    {
      if (bcd->digits[idx] > 9)
      {
        bcd->digits[idx-1]++;
        bcd->digits[idx] -= 10;
      }
      else
      {
        bcd->digits[idx-1]--;
        bcd->digits[idx] += 10;
      }
    }
  }
  
  return;

}  /* _HAMARO_BCD_adjust_improved() */  


/*******************************************************************************************************/
/* HAMARO_BCD_set() */
/*******************************************************************************************************/
void           HAMARO_BCD_set(                /* function to set a value into a HAMARO_BCDNO struct */
HAMARO_BCDNO          *bcd,                   /* pointer to bcd struct */
unsigned long  newval)                 /* no. to convert into a HAMARO_BCDNO */
{
  int    idx;
  unsigned long  ulTemp = HAMARO_M*HAMARO_MM;

  /* clear the bcd storage */  
  bcd->sign[0] = CNULL;
  for (idx = 0 ; idx < HAMARO_MAX_BCDNO ; idx++)  bcd->digits[idx] = CNULL;

  idx = HAMARO_MAX_BCDNO-10;
  while (ulTemp > 0UL && newval != 0UL)
  {
    if (newval >= ulTemp)
    {
      bcd->digits[idx]++;
      newval -= ulTemp;
    }
    else
    {
      idx++;
      ulTemp /= 10UL;
    }
  }

}  /* HAMARO_BCD_set() */


/*******************************************************************************************************/
/* BCD_add() */
/*******************************************************************************************************/
void           HAMARO_BCD_add(                /* function to add a binary number value into a HAMARO_BCDNO number */
HAMARO_BCDNO          *bcd,                   /* pointer to bcd struct */
unsigned long  add)                    /* binary numbr to add into HAMARO_BCDNO */
{
  HAMARO_BCDNO  temp_bcd;

  /* convert number to add to a bcd, then proceed */
  HAMARO_BCD_set(&temp_bcd,add);
  HAMARO_BCD_add_bcd(bcd,&temp_bcd);
  return;

}  /* HAMARO_BCD_add() */


/*******************************************************************************************************/
/* HAMARO_BCD_subt() */
/*******************************************************************************************************/
void           HAMARO_BCD_subt(               /* function to subtract a binary number value into a HAMARO_BCDNO number */
HAMARO_BCDNO          *bcd,                   /* pointer to bcd struct */
unsigned long  subt)                   /* binary numbr to add into HAMARO_BCDNO */
{
  HAMARO_BCDNO  temp_bcd;

  /* convert number to subtract to a bcd, then proceed */
  HAMARO_BCD_set(&temp_bcd,subt);
  HAMARO_BCD_subt_bcd(bcd,&temp_bcd);
  return;

}  /* HAMARO_BCD_subt() */


/*******************************************************************************************************/
/* HAMARO_BCD_subt_bcd() */
/*******************************************************************************************************/
void   HAMARO_BCD_subt_bcd(                   /* function to subtract a HAMARO_BCDNO from a HAMARO_BCDNO */
HAMARO_BCDNO  *bcd,                           /* pointer to bcd struct */
HAMARO_BCDNO  *subt)                          /* pointer to bcd struct */
{
  int  idx;
  int  bstart;
  int  result;

  /* determine the range of bcd digits that must be addressed */
  for ( bstart = 0 ; bstart <= HAMARO_MAX_BCDNO-1 ; bstart++)
  {
    if (subt->digits[bstart] != 0)
    {
      if (bstart > 0)  bstart -= 1;
    
      /* subtract from bcd */
      for (idx = HAMARO_MAX_BCDNO-1 ; idx > bstart  ; idx--)
      {
        result = (bcd->digits[idx] - subt->digits[idx]);
        bcd->digits[idx] = (signed char)result;
      }
      _HAMARO_BCD_adjust_improved(bcd,bstart);
      return;
    }
  }
  
  return;

}  /* HAMARO_BCD_subt_bcd() */


/*******************************************************************************************************/
/* HAMARO_BCD_mult() */
/*******************************************************************************************************/
void           HAMARO_BCD_mult(               /* function to multiply a HAMARO_BCDNO by a binary number */
HAMARO_BCDNO          *bcd,                   /* pointer to bcd struct */
unsigned long  multby)                 /* binary number to multiply by */
{
  static  HAMARO_BCDNO  temp_bcd;

  /* convert multby to bcd, then proceed */
  HAMARO_BCD_set(&temp_bcd,multby);
  HAMARO_BCD_mult_bcd(bcd,&temp_bcd);
  return;

}  /* HAMARO_BCD_mult() */


/*******************************************************************************************************/
/* _HAMARO_BCD_mult_bcd_ones() */
/*******************************************************************************************************/
void   _HAMARO_BCD_mult_bcd_ones(             /* function to multiply HAMARO_BCDNO one digit at a time */
HAMARO_BCDNO  *bcd,                           /* pointer to bcd struct */
char   digit)                          /* digit to multiply by */
{
  int    idx;

  /* loop through each temp_bcd low digit until temp_bcd == zero */
  for (idx = HAMARO_MAX_BCDNO-1 ; idx > 0 ; idx--)
  {
    char  result;
      
    /* compute result */
    result = (signed char)(bcd->digits[idx] * digit);
    bcd->digits[idx] = result;
  }
  _HAMARO_BCD_adjust(bcd);

  return;

}  /* _HAMARO_BCD_mult_bcd_ones() */


/*******************************************************************************************************/
/* HAMARO_BCD_mult_bcd() */
/*******************************************************************************************************/
void   HAMARO_BCD_mult_bcd(                   /* function to multiply HAMARO_BCDNO by a HAMARO_BCDNO */
HAMARO_BCDNO  *bcd,                           /* pointer to bcd struct */
HAMARO_BCDNO  *bcdmultby)                     /* pointer to bcd struct */
{
  int  i;
  int  cnt;

  signed char   digit;
  signed int    sign;

  HAMARO_BCDNO  temp_bcd;
  HAMARO_BCDNO  result;

⌨️ 快捷键说明

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