Computational routine
eng


pevtdlyz_c

File content


/* Modnumlib Scicos interfacing function
 * Copyright (C) 2009-2011 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.
 */
 
/* pevtdlyz_c Scicos Phase Modulator Event block
 * Type 4 simulation function ver 1.0 - scilab-4.1.2
 * 10 février 2008 - INRIA - Author : A.Layec
 */

/* REVISION HISTORY :
 * $Log$
 */

#include "scicos_block4.h"
#define M_PI 3.14159265358979323846

#if WIN32
#define NULL    0
#endif
/* Cette fonction de simulation calcul des instants de transistion
 * modulée en phase.
 * Entrées régulières : phase (compris entre -2*%pi;2*%pi)
 * Sorties régulières : néant
 * Entrées évènementielles : néant
 * Sortie évènementielles :  sortie modulée
 *
 * paramères : rpar[0] : instant initial
 *             rpar[1] : période de déclenchement
 *
 */

/*prototype*/
void pevtdlyz_c(scicos_block *block,int flag)
{
 /*déclaration*/
 double init_T;    /*instant initial*/
 double T;         /*période fixe*/
 double t;         /*temps simulateur*/
 double *u;        /*ptr pour entrée régulière*/

 long long int *i; /*compteur de période*/

 /*récupération de l'adresse du port d'entrée*/
 u=(double *)block->inptr[0];

 /*récupération des paramètres*/
 init_T = block->rpar[0]; /* t initial */
 T      = block->rpar[1]; /* période */

 /*récupère valeur temps du simulateur*/
 t = get_scicos_time();

  switch(flag)
  {
   /* initialisation */
   case 4  : {
              /*work est utilisé pour stocker le compteur de période*/
              if ((*block->work=scicos_malloc(sizeof(long long int)))==NULL) {
                set_block_error(-16);
                return;
              }

              /*récupère ptr du compteur*/
              i = *block->work;

              /*initialise compteur */
              *i = 1;

              break;
             }

   /*le flag 3 calcule les dates de sorties*/
   case 3  : {
              /*récupère ptr des compteurs*/
              i=*block->work;

              /*détection zero crossing*/
              if (block->nevprt<0) {
                /*augmente compteur */
                (*i)++;

                /*produit événement*/
                block->evout[0]=0;
              }

              break;
             }

   /*le flag 9 calcule les surfaces de détections à zéro*/
   case 9  : {
              /*récupère ptr du compteur*/
              i=*block->work;

              /*test sur valeur d'entrée*/
              if ((u[0]<(2*M_PI)) && (u[0]>-(2*M_PI))) {
                block->g[0] = t - ((*i)*T + T*(u[0]/(2*M_PI)));
              }
              /*sinon retourne erreur*/
              else {
                /*Coserror("flag=9, valeur de phase incorrecte : %f.\n",u[0]);*/
                /*else*/
                  set_block_error(-1);
                /**/
                return;
              }

              break;
             }

   /* terminaison */
   case 5  : {
              scicos_free(*block->work); /*libère le workspace*/
              break;
             }

   default : break;
  }

}