Computational routine
eng
pfd
/* 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.
*/
/* pfd Scicos Phase Frequency Detector block including
* D Flip/Flop Tristate Phase/Frequency comparator and charge Pump
* Type 4 simulation function ver 1.0 - scilab-3.0
* 13 janvier 2004 - IRCOM GROUP - Author : A.Layec
*/
/* REVISION HISTORY :
* $Log$
*/
#include "modnum_lib.h"
#include "scicos_block.h"
/* entrées régulières : néant
* sorties : y[0..ny-1] : vecteur de sortie du courant de la pompe de charge
* entrées évènementielles : nev = 1 : entrée d'horloge de mise à jour du cpf
* nev = 2 : entrée d'horloge du diviseur de retour
* sortie évènementielles :
* paramètres entiers : outsz[0] : taille du vecteur (ny)
* ipar[0..ny] : type de bruit de la pompe de charge (typ_leak)
* 0: pas de fuite
* 1: fuite constante
* 2: fuite bruit normal
* paramètres réels : rpar[0..ny-1] : courant max de la pompe de charge
* rpar[ny..2ny-1] : courant de fuite moyen de la pompe de charge
* rpar[2*ny..3*ny-1] : deviation du courant de fuite
* Etats discrets : z[0],z[ny] : etats mémoires des bascules
* Etats discrets dynamiques : up et down valeur de sortie du CPF
*/
/*prototype*/
void pfd(scicos_block *block,int flag)
{
/*déclaration*/
int ny;
int nev;
double *y;
double *z__;
double *up,*down;
int typ_leak;
double *Io,*Ileak_d,*Ileak_m;
/*récupération des adresses*/
y=(double *)block->outptr[0];
nev=block->nevprt;
/*Récupération des paramètres*/
ny=block->outsz[0];
typ_leak=block->ipar[0];
Io=&block->rpar[0];
Ileak_m=&block->rpar[ny];
Ileak_d=&block->rpar[2*ny];
/* init : fait l'allocation de work */
if (flag==4) {
/*Allocation de 2 vecteurs de taille ny*/
if ((*block->work=scicos_malloc(sizeof(double)*(2*ny)))== NULL) {
set_block_error(-16);
return;
}
}
/*calcule les états*/
else if (flag==2) {
/*Appel cpfz_c*/
cpfz_c(&ny,&nev,&block->z[0],&block->z[ny]);
}
/*calcule les sorties*/
else if (flag==1) {
/*Récupération de l'adresse de départ du vecteur alloué*/
z__=*block->work;
/*Déclaration de pointeurs auxiliaires*/
up=&(z__[0]);down=&(z__[ny]); /*vecteur up et down*/
/*Appel cpfy_c*/
cpfy_c(&ny,&nev,&block->z[0],&block->z[ny],&up[0],&down[0]);
/*Appel chargepump_c*/
chargepump_c(&ny,&up[0],&down[0],&Io[0],&typ_leak,&Ileak_m[0],&Ileak_d[0],&y[0]);
}
/*Terminaison */
else if (flag==5) {
/*Libère mémoire allouée*/
scicos_free(*block->work);
}
}