/* 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. */ /* perrdsm : phase error introduced by a delta-sigma modulator * in a fractional synthesizer * * Type 4 simulation function ver 1.0 - scilab-3.0 * 24 février 2008 - INRIA - Author : A.Layec */ /* REVISION HISTORY : * $Log$ */ #include "modnum_lib.h" #include "scicos_block.h" #if WIN32 #define NULL 0 #endif /* entrées régulières u[0..(mu*nu)-1] : modulateur(s) sigma-delta (int32) * * sorties : y[0..(mu*nu)-1] : erreur(s) de phase (double) * * entrées évènementielles : période de déclenchement * * sortie évènementielles : néant * * paramètres entiers : ipar[0..(mu*nu)-1] : K * ipar[nu..2*(mu*nu)-1] : M * * Etats discrets : work->i compteur 1/N * work->j compteur K/M */ typedef struct work_st { long long int *i; long long int *j; } work_struct; void perrdsm(scicos_block *block,int flag) { /*déclaration*/ int *M; int *K; int *u; int *y; int ny,my; int i; /*ptr of the struct of that block*/ work_struct *work; /*get he struct of that block*/ work = (work_struct*) *block->work; /*récupération des adresses*/ u = (int *)block->inptr[0]; y = (int *)block->outptr[0]; /*récupération des paramètres*/ ny = block->outsz[0]; my = block->outsz[1]; K = &block->ipar[0]; M = &block->ipar[ny*my]; switch(flag) { /* initialisation */ case 4 : { if ((work=(work_struct*) scicos_malloc(sizeof(work_struct))) == NULL) { set_block_error(-16); return; } if ((work->i=(long long int*) scicos_malloc(my*ny*sizeof(long long int))) == NULL) { set_block_error(-16); return; } if ((work->j=(long long int*) scicos_malloc(my*ny*sizeof(long long int))) == NULL) { set_block_error(-16); return; } /*initialise compteurs */ for (i=0;i<my*ny;i++) { work->i[i] = 0; /* K/M */ work->j[i] = 0; /* 1/N */ } *block->work=(void *)work; /*store my_st in *block->work*/ break; } case 6 : case 1 : perrdsmy_c(&ny,&my,M,K,work->i,work->j,u,y); break; case 2 : perrdsmz_c(&ny,&my,work->i,work->j,u); break; /* terminaison */ case 5 : { scicos_free(work->i); scicos_free(work->j); scicos_free(*block->work); break; } default : break; } }