📄 sma_mls.c
字号:
/***********************************************************************
* $Workfile: SMA_mls.c $
* $Revision: 1.0 $
* $Author: KovitzP $
* $Date: May 30 2002 17:37:58 $
*
* Project: MLS
*
* Description:
* This file contains functions for setting up and generating
* Maximum-Length Sequences with shift registers up to 24-bits
* in length.
*
* Notes:
* To use these functions, call mls_setup() to initialize mask
* and the generators array. Then call mls_next_reg. The
* initial reg should be mask. Subsequent calls to mls_next_reg
* should use the previously returned reg as the reg argument.
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/CHIPS/archives/SOC/Source/SMA_mls.c-arc $
*
* Rev 1.0 May 30 2002 17:37:58 KovitzP
* Initial revision.
*
***********************************************************************
*
* Copyright (c) 2002 Sharp Microelectronics of the Americas
*
* All rights reserved
*
* SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
* OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
* AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES,
* SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
*
* SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY
* FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A
* SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
* FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
*
**********************************************************************/
#include "SMA_mls.h"
/*
* mls_taps[i][j] contains the bit number (1 is the LSB;
* 0 means no tap) of the jth tap for a shift reigster with i + 1 bits.
*/
static UNS_32 mls_taps[MLS_MAXREG][MLS_MAXTAPS] =
{
{0, 0, 0, 0},
{1, 2, 0, 0},
{2, 3, 0, 0},
{3, 4, 0, 0},
{3, 5, 0, 0},
{5, 6, 0, 0},
{6, 7, 0, 0},
{2, 3, 5, 8},
{5, 9, 0, 0},
{7,10, 0, 0},
{9,11, 0, 0},
{6, 8,11,12},
{9,10,12,13},
{4, 8,13,14},
{14,15, 0, 0},
{4,13,15,16},
{14,17, 0, 0},
{11,18, 0, 0},
{14,17,18,19},
{17,20, 0, 0},
{19,21, 0, 0},
{21,22, 0, 0},
{18,23, 0, 0},
{17,22,23,24}
};
/**********************************************************************
*
* Function: mls_setup
*
* Purpose:
* Setup data structures required for making a shift register
* sequence for a given shift register length.
*
* Processing:
* Form the the shift register taps as bitmasks in the generators
* array, then form the bitmask that is the length of shift register
*
* Parameters:
* reg_length: the number of bits in the MLS shift register
* generators: ANDing the shift register with generator[i] yields
* non-zero if the ith tap from the shift register is set
* The array will be overwritten by this function.
* mask: pointer to data that will contain _BITMASK(reg_length)
*
* Outputs:
* generators, mask
*
* Returns:
* _NO_ERROR: if function was successful
* _ERROR: if reg_length is out of range
*
* Notes: None
*
*********************************************************************/
INT_32 mls_setup(UNS_8 reg_length,
UNS_32 generators[MLS_MAXTAPS],
UNS_32 * mask)
{
UNS_32 i, tap;
if (reg_length == 0 || reg_length > MLS_MAXREG)
return _ERROR;
for (i=0; i < MLS_MAXTAPS; i++)
{
tap = mls_taps[reg_length-1][i];
generators[i] = (tap == 0) ? 0 : _BIT(tap - 1);
}
*mask = _BITMASK(reg_length);
return _NO_ERROR;
}
/**********************************************************************
*
* Function: mls_next_reg
*
* Purpose:
* Setup data structures required for making a shift register
* sequence for a given shift register length.
*
* Processing:
* Form the the shift register taps as bitmasks in the generators
* array, then form the bitmask that is the length of shift register
*
* Parameters:
* reg: The previous register contents in the sequence
* generators: ANDing the shift register with generator[i] yields
* non-zero if the ith tap from the shift register is set
* mask: _BITMASK(reg_length)
*
* Outputs: None
*
* Returns:
* The next value of the shift register
*
* Notes:
* The first time this function is called, use mask as the initial
* value for reg.
*
*********************************************************************/
UNS_32 mls_next_reg(UNS_32 reg,
UNS_32 generators[MLS_MAXTAPS],
UNS_32 mask)
{
UNS_32 shift_in;
// form mod 2 sum of shift register taps
shift_in = ((reg & generators[0]) != 0) ? 1 : 0;
shift_in += ((reg & generators[1]) != 0) ? 1 : 0;
shift_in += ((reg & generators[2]) != 0) ? 1 : 0;
shift_in += ((reg & generators[3]) != 0) ? 1 : 0;
shift_in &= 1;
// shift in the mod 2 sum
reg = ((reg << 1) | shift_in) & mask;
return reg;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -