/* Modnumlib Scicos interfacing function * Copyright (C) 2009 Alan Layec * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 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 * General Public License for more details. * * You should have received a copy of the GNU 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. */ /* binaccu Scicos Bit Acummulator with * left shift circulate * * Type 4 simulation function ver 1.0 - scilab-4.1 * 13 Mars 2006 - INRIA - Author : A.Layec * 20 Mars 2007 - INRIA - Author : A.Layec */ /* REVISION HISTORY : * $Log$ */ #include "scicos_block.h" /* * Cette fonction de simulation réalise un accumulateur de bits * Chaque paquet de bits en entrée (de longueur nbit) * est stocké dans un mot de longueur nbit*npack * où npack représente le nombre de paquets à stocker. * Le ième mot est placé à la place i*nbit et le mot * de sortie est codé en code complément à 2 * * Entrée régulière : * - u[0..nu-1] entier codés sur nbit * * Sortie régulière : * - y[0..nu-1] entier codés sur nbit*nbpack * * Entrée évènementielle : * - Instant d'acquisition du mot en entrée * * Sortie évènementielle : néant * * Paramètres entiers : * - ipar[0..nu-1] flag code complément à 2 en entrée * 0 : nombre entier non signé * 1 : nombre entier signé * - ipar[nu..2*nu-1] flag code complément à 2 en sortie * 0 : nombre entier non signé * 1 : nombre entier signé * - ipar[2*nu..3*nu-1] Nombre de paquet (npack) * * - ipar[3*nu..4*nu-1] Nombre de bit (nbit) * * - ipar[4*nu..5*nu-1] nombre de conditions intiales * * - ipar[5*nu..5*nu+sum(ipar[4*nu..5*nu-1])] * conditions initiales * * Etats discrets : * - z[0..nu-1] compteur paquet * - z[nu..2*nu-1] valeur du mot de sortie * - z[2*nu..3*nu-1] compteurs de condition(s) initiale(s) */ /* prototype */ void binaccu(scicos_block *block,int flag) { double *y; double *u; int nu; int *cc2_in; int *cc2_out; int *npack; int *nbit; int *ci; int *nci; int i,j; double *z_npack; double *z_value; double *z_nci; y = (double *)block->outptr[0]; u = (double *)block->inptr[0]; nu = block->insz[0]; cc2_in = &block->ipar[0]; cc2_out = &block->ipar[nu]; npack = &block->ipar[2*nu]; nbit = &block->ipar[3*nu]; nci = &block->ipar[4*nu]; ci = &block->ipar[5*nu]; z_npack = &block->z[0]; z_value = &block->z[nu]; z_nci = &block->z[2*nu]; /* compute output */ if ((flag==1)||(flag==6)) { for (j=0;j<nu;j++) { i = (int)(z_value[j]); if (cc2_out[j]==1) { i -= 2<<((nbit[j]*npack[j])-2); i &= (2<<((nbit[j]*npack[j])-1)) - 1; i -= 2<<((nbit[j]*npack[j])-2); } y[j] = (double)i; } } /* compute discrete state */ else if ((flag==2)||(flag==4)) { for (j=0;j<nu;j++) { if(z_nci[j]==0) { i = (int)u[j]; if (cc2_in[j]==1) { i &= (2<<(nbit[j]-1)) - 1; } i=i<<(nbit[j]*(int)(z_npack[j])); if (z_npack[j]==0) { z_value[j] = (double)i; } else { z_value[j] += (double)i; } z_npack[j]++; if (z_npack[j]==(double)npack[j]) { z_npack[j]=0; } } else { z_value[j] = (double)ci[nci[j]+(int)(z_nci[j]-1)]; z_nci[j]--; } } } }