bitmanip

Capsim Block Documentation

Short Description

Review code.

Top
Input Connections
Port Type Name
0 float x
Top
Output Connections
Port Type Name
0 float y
Top
Parameters
Num Description Type Name Default Value
0 Number of bits per frame (Info Only) int numberOfBits 128
1 Debug:1=true,0=false int debugFlag 0
Top
States
Num Type Name Initial Value Description
0 UINT16 rx 0
1 UINT16 outBits 0
2 int outBitsCount 0
3 int outFlag 0
4 int count 0
5 int insertZero 0
6 int shreg 0
7 int bitCount 0
8 int endFrame 0
9 int begFlag 1
10 int endFlag 0
11 int fcs 0
12 int frameCount 0
13 int contFlag
14 int ns 0
15 int nss 0
16 int nt 0
17 int infoLengthBytes
18 char* queue_A[8]
19 int numberBitsCollected 0
20 UINT16 buildByte 0
21 int buildByteBits 0
22 int byteCount 0
23 int bitsProc 0
24 int nr 0
25 int rej 0
26 int rr 1
27 int first 1
28 FILE* debug_F
29 int infoComplete
Top

Declarations


 

unsigned short	carry;
int	bit;
int	i;
unsigned int	m;
int	numberOfSamples;
UINT16	checkStuff;
int	mask;
int	done;
int	bitPos;
int	bytePos;
int	rc;



Top

Initialization Code



 

if(debugFlag) {
        debug_F=fopen("bitmanip.dbg","w");
        if(debug_F == NULL) return(2);
}
infoLengthBytes = numberOfBits/8+1;
for(i=0; i<8; i++) {
	queue_A[i]=(char*)calloc(infoLengthBytes,sizeof(char));
	if(queue_A[i]==NULL) {
		fprintf(stderr,"bitmanip could not allocate space\n");
		return(1);
	}
}




Top

Main Code



 




while(IT_IN(0) ) {
       	/*
       	 * collect the bits
	 * and store them in a buffer
	 * first info frames are stored in queue zero
       	 */
       	bit=(int)(x(0)+0.001);
	buildByte |= bit;
	buildByteBits++;
if(debugFlag) 
	fprintf(debug_F,"bit=%d,buildByte=%4x,buildByteBits=%d,byteCount=%d\n",
		bit,buildByte,buildByteBits,byteCount);
	if(buildByteBits == 8) {

		queue_A[0][byteCount]=buildByte;
		buildByte=0;
		buildByteBits=0;
		byteCount++;
	}
	
	bitCount++;
	if(bitCount == numberOfBits) {
		infoComplete=1;
		queue_A[0][byteCount]=buildByte;
		byteCount=0;
		buildByte=0;
		buildByteBits=0;
		bitCount=0;
		break;
	}
	buildByte <<= 1;
}

if(infoComplete) {
   done=0;
   bitsProc=0;
   while(!done) {
       	/*
       	 * get a bit
       	 */
	bytePos=bitsProc >> 3;
	bitPos = 7-(bitsProc % 8);
	mask=1; mask <<= bitPos;
	bit = (queue_A[0][bytePos] & mask) ? 1:0;
if(debugFlag) 
	fprintf(debug_F,"output:bit=%d,queue=%4x,bitPos=%d,bytePos=%d\n", bit,queue_A[0][bytePos],bitPos,bytePos);
	bitsProc++;
	if(bitsProc == numberOfBits) { 
		endFrame=1;
		bitsProc=0;
	}
	/*
	 * Output bit
	 */
	if(IT_OUT(0) ){ KrnOverflow("bitmanip",0); return(99); }
	y(0) = bit;
	if(endFrame) {
		/*
		 * Finished outputting
		 * Reset everything
		 */
		frameCount++;

		done=1;
		infoComplete=0;
		endFrame=0;

	}
   }
	

}

	
return(0);




Top

Wrapup Code



 

	fprintf(stderr,"bitmanip: number of outputted frames=%d\n",frameCount);
for(i=0; i<8; i++) 
	free(queue_A[i]);
	if(debugFlag)
		fclose(debug_F);




Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2017  Silicon DSP Corporation

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

    http://www.silicondsp.com
    Silicon DSP  Corporation
    Las Vegas, Nevada
*/


Top

Description



 

/*

bitmanip


Review code.


Written by: Sasan H. Ardalan
Date: November 30, 1993

 */