?? mfr1.c
字號:
/** ###################################################################
** THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : MFR1.C
** Project : vvvf_56F8346
** Processor : 56F8346
** Beantype : DSP_Func_MFR
** Version : Bean 01.040, Driver 01.08, CPU db: 2.87.097
** Compiler : Metrowerks DSP C Compiler
** Date/Time : 2008-3-7, 9:38
** Abstract :
** This bean encapsulates the basic math functions for both
** 16-bit and 32-bit fractional types.
** Settings :
** Bean Name : MFR1
** Use Assembler Files : no
** Contents :
** abs_s - Frac16 abs_s(Frac16 x);
** add - Frac16 add(Frac16 x,Frac16 y);
** div_s - Frac16 div_s(Frac16 x,Frac16 y);
** mac_r - Frac16 mac_r(Frac32 w,Frac16 x,Frac16 y);
** msu_r - Frac16 msu_r(Frac32 w,Frac16 x,Frac16 y);
** mult - Frac16 mult(Frac16 x,Frac16 y);
** mult_r - Frac16 mult_r(Frac16 x,Frac16 y);
** negate - Frac16 negate(Frac16 x);
** round - Frac16 round(Frac32 x);
** shl - Frac16 shl(Frac16 x,Int16 n);
** shr - Frac16 shr(Frac16 x,Int16 n);
** shr_r - Frac16 shr_r(Frac16 x,Int16 n);
** sub - Frac16 sub(Frac16 x,Frac16 y);
** L_abs - Frac32 L_abs(Frac32 x);
** L_add - Frac32 L_add(Frac32 x,Word32 y);
** div_ls - Frac16 div_ls(Frac32 x,Frac16 y);
** L_mac - Frac32 L_mac(Frac32 w,Frac16 x,Frac16 y);
** L_msu - Frac32 L_msu(Frac32 w,Frac16 x,Frac16 y);
** L_mult - Frac32 L_mult(Frac16 x,Frac16 y);
** L_mult_ls - Frac32 L_mult_ls(Frac32 x,Frac16 y);
** L_negate - Frac32 L_negate(Frac32 x);
** L_shl - Frac16 L_shl(Frac32 x,Int16 n);
** L_shr - Frac32 L_shr(Frac32 x,Int16 n);
** L_shr_r - Frac32 L_shr_r(Frac32 x,Int16 n);
** L_deposit_h - Frac32 L_deposit_h(Frac16 x);
** L_deposit_l - Frac32 L_deposit_l(Frac16 x);
** L_sub - Frac32 L_sub(Frac32 x,Frac32 y);
** extract_h - Frac16 extract_h(Frac32 x);
** extract_l - Frac16 extract_l(Frac32 x);
** norm_s - Int16 norm_s(Frac16 x);
** norm_l - Int16 norm_l(Frac32 x);
** mfr16Rand - Frac16 mfr16Rand(void);
** mfr16SetRandSeed - void mfr16SetRandSeed(Frac16 x);
** mfr16Sqrt - Frac16 mfr16Sqrt(Frac16 x);
** mfr32Sqrt - Frac16 mfr32Sqrt(Frac32 x);
**
** (c) Freescale Semiconductor
** 2004 All Rights Reserved
**
** (c) Copyright UNIS, spol. s r.o. 1997-2005
** UNIS, spol. s r.o.
** Jundrovska 33
** 624 00 Brno
** Czech Republic
** http : www.processorexpert.com
** mail : info@processorexpert.com
** ###################################################################*/
/* MODULE MFR1. */
#include "MFR1.h"
static volatile Int16 LastRandomNumber = 21845;
/*
** ===================================================================
** Method : MFR1_mfr16Rand (bean DSP_Func_MFR)
**
** Description :
** The rand function calculates a pseudo-random number.
** Parameters : None
** Returns :
** --- - The rand function returns the
** pseudo-random number calculated.
** ===================================================================
*/
Frac16 mfr16Rand(void)
{
bool bSaturationMode;
/* Turn saturation mode off in order to get mod op */
bSaturationMode = archGetSetSaturationMode(false);
LastRandomNumber = (LastRandomNumber * 31821) + 13849;
archGetSetSaturationMode (bSaturationMode);
return *((Frac16 *)(&LastRandomNumber));
}
/*
** ===================================================================
** Method : MFR1_mfr16SetRandSeed (bean DSP_Func_MFR)
**
** Description :
** The randseed function sets the random number seed used by
** the pseudo-random number generation algorithm.
** Parameters :
** NAME - DESCRIPTION
** x - The input data value to be used as the
** random number seed.
** Returns : Nothing
** ===================================================================
*/
void MFR1_mfr16SetRandSeed(Frac16 x)
{
LastRandomNumber = *((Int16 *)(&x));
}
/*
** ===================================================================
** Method : MFR1_mfr16Sqrt (bean DSP_Func_MFR)
**
** Description :
** The sqrt function calculates the square root of the
** fractional input data value.
** Parameters :
** NAME - DESCRIPTION
** x - The input data value.
** Returns :
** --- - The sqrt function returns the result of
** the square root calculation.
** ===================================================================
*/
Frac16 mfr16Sqrt(Frac16 x)
{
Frac16 var;
var = mfr32Sqrt(L_deposit_h(x));
return(var);
}
/*
** ===================================================================
** Method : MFR1_mfr32Sqrt (bean DSP_Func_MFR)
**
** Description :
** The sqrt function calculates the square root of the
** fractional input data value.
** Parameters :
** NAME - DESCRIPTION
** x - The input data value.
** Returns :
** --- - The sqrt function returns the result of
** the square root calculation.
** ===================================================================
*/
Frac16 mfr32Sqrt(Frac32 x)
{
Frac16 Est;
Frac16 EstR;
Frac16 Bit = 0x4000;
Frac32 Temp;
UInt16 i;
Est = 0x0000;
for (i=0; i<14; i++) {
Est = add(Est, Bit);
Temp = L_mult(Est,Est);
if (Temp > x) {
Est = sub(Est, Bit);
}
Bit = shr (Bit, 1);
}
/* Choose between estimate & rounded estimate for most accurate result */
EstR = add(Est, 1);
if (L_abs(L_sub(x,L_mult(EstR, EstR))) < L_sub(x,L_mult(Est,Est))) {
Est = EstR;
}
return Est;
}
/*
** ===================================================================
** Method : MFR1_L_deposit_h (bean DSP_Func_MFR)
**
** This method can be used also under name "L_deposit_h"
**
** Description :
** The L_deposit_h function places a 16-bit fractional value
** into the most significant 16-bits of the 32-bit
** fractional output value and zeroes the least significant
** 16 bits.
** Parameters :
** NAME - DESCRIPTION
** x - The input data value.
** Returns :
** --- - The function returns a 32-bit
** fractional value.
** ===================================================================
*/
/*
Frac16 MFR1_L_deposit_h(Frac16 x)
{
This method is implemented by Metrowerks
}
*/
/*
** ===================================================================
** Method : MFR1_L_shr_r (bean DSP_Func_MFR)
**
** This method can be used also under name "L_shr_r"
**
** Description :
** The L_shr_r function arithmetically shifts the input
** variable x right n positions, sign extending the result.
** If n is negative, the L_shr_r function arithmetically
** shifts x left by -n bits, zero filling the least
** significant bits. L_shr_r differs from L_shr in that
** L_shr_r rounds the 32-bit fractional result.
** Parameters :
** NAME - DESCRIPTION
** x - The input data value.
** n - The number of bits to right shift x; n is
** signed and, if negative, implies a right
** shift.
** Returns :
** --- - The function returns the value x
** arithmetically shifted by n bits.
** ===================================================================
*/
/*
Frac32 MFR1_L_shr_r(Frac32 x,Frac16 n)
{
This method is implemented by Metrowerks
}
*/
/*
** ===================================================================
** Method : MFR1_abs_s (bean DSP_Func_MFR)
**
** This method can be used also under name "abs_s"
**
** Description :
** The abs_s function calculates the 16-bit absolute value
** of the input value.
** Parameters :
** NAME - DESCRIPTION
** x - The input data value.
** Returns :
** --- - The abs function returns the result of
** the 16-bit absolute value calculation.
** ===================================================================
*/
/*
Frac16 MFR1_abs_s(Frac16 x)
{
This method is implemented by Metrowerks
}
*/
/*
** ===================================================================
** Method : MFR1_L_abs (bean DSP_Func_MFR)
**
** This method can be used also under name "L_abs"
**
** Description :
** The L_abs function calculates the 32-bit absolute value
** of the input value.
** Parameters :
** NAME - DESCRIPTION
** x - The input data value.
** Returns :
** --- - The L_abs function returns the result
** of the 32-bit absolute value calculation.
** ===================================================================
*/
/*
Frac32 MFR1_L_abs(Frac32 x)
{
This method is implemented by Metrowerks
}
*/
/*
** ===================================================================
** Method : MFR1_add (bean DSP_Func_MFR)
**
** This method can be used also under name "add"
**
** Description :
** The add function adds two 16-bit fractional numbers (x +
** y).
** Parameters :
** NAME - DESCRIPTION
** x - The first input value.
** y - The second input value.
** Returns :
** --- - The add function returns the 16-bit
** results of the addition.
** ===================================================================
*/
/*
Frac16 MFR1_add(Frac16 x,Frac16 y)
{
This method is implemented by Metrowerks
}
*/
/*
** ===================================================================
** Method : MFR1_L_add (bean DSP_Func_MFR)
**
** This method can be used also under name "L_add"
**
** Description :
** The add function adds two 32-bit fractional numbers (x +
** y).
** Parameters :
** NAME - DESCRIPTION
** x - The first input value.
** y - The second input value.
** Returns :
** --- - The add function returns the 32-bit
** results of the addition.
** ===================================================================
*/
/*
Frac32 MFR1_L_add(Frac32 x,Word32 y)
{
This method is implemented by Metrowerks
}
*/
/*
** ===================================================================
** Method : MFR1_div_s (bean DSP_Func_MFR)
**
** This method can be used also under name "div_s"
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -