Hi,

i send the source files with the initialization.
In the file apgs.c there is the main procedure that call the function InitRTEnv() that initialize all.

Thanks a lot

Best regards

Il 01/08/2011 16:42, Gilles Chanteperdrix ha scritto:
Could you show us the code which initializes the rtDesc member of the
structure, in order to allow us reproducing your scenario?


--
+------------------------------------------------------------------------------------------------+
                                                        
Roberto Bielli
Sviluppo Software                                       
Axel S.r.l.                                     
                                                        
Via Del Cannino, 3                              
21020 Crosio Della Valle                        
Varese - Italy                                  
                                                        
Telefono: +39 0332 949600                       
Fax:      +39 0332 969315                       
                                                        
E-mail:   [email protected]      
Web Site: www.axelsw.it

+------------------------------------------------------------------------------------------------+

Si precisa che le informazioni contenute in questo messaggio sono riservate e 
ad uso esclusivo del destinatario.
Qualora il messaggio in parola Le fosse pervenuto per errore, La preghiamo di 
eliminarlo senza copiarlo e di non inoltrarlo a terzi,
dandocene gentilmente comunicazione. Grazie.
Informativa sul trattamento dei dati personali (D. Lgs. 196/2003).
I dati utilizzati per la spedizione del presente messaggio sono utilizzati da 
Axel S.r.l., titolare del trattamento,
per l'invio delle comunicazioni dei diversi settori aziendali, non essendo 
autorizzata la divulgazione a terzi.
Potrete rivolgere alla seguente mail richieste di verifica, rettifica o 
cancellazione dei Vostri dati: [email protected]

This e-mail and any attachments is confidential and may contain privileged 
information
intended for the addressee(s) only. Dissemination, copying, printing or use by 
anybody
else is unauthorised. If you are not the intended recipient,
please delete this message and any attachments and advise the sender
by return e-mail.Thank you.                     
                                                        
+------------------------------------------------------------------------------------------------+

/** \file APgs.c
* Applicazione per eseguire PLC in tempo reale. Axel S.r.l. 2008
*
*/

#include <stdio.h>
#include <sys/ucontext.h>
#include <unistd.h>
#include <stdlib.h>

#include "cext.h"
#include "fujitsu.h"
#include "pc.h"
#include "rttasks.h"
#include "sysgen.h"
#include "version.h"

#include "alplc/communication.h"
#include "alplc/plcmanager.h"

#include "TraceInput.h"
#include "TraceLog.h"


/** versione Real time  */
#define RT_VERSION              "AXEL S.R.L - " NAME_ARM_APGS " - v. " 
VERS_ARM_APGS " - " DATE_ARM_APGS

/** opzioni da linea di comando */
#define CMD_OPT                 "p:hc:DM:"

static  boolean stopApplication;

/** gestore dei segnali di processo */
void sigHandler( int sig, siginfo_t *info,void *context )
{
        ucontext_t *uc = (ucontext_t *)context;
        int i = 0;
        RT_TASK_INFO dstTaskSig;

        if (! stopApplication)
        {
                for( i = 0; i < NUMTASKS; i++ )
                {
                        if( rt_task_inquire( tabRtTask[i].rtDesc, &dstTaskSig ) 
== 0 && ( dstTaskSig.status & 0x380 ) == 0x380 )
                        {
                                AltTraceInN( ALTRACE_LEV_BASE,  "Il Task RT %s 
ha generato un segnale: 0x%08X", dstTaskSig.name, dstTaskSig.status );
                                break;
                        }
                }

                switch( sig )
                {
                        case SIGTERM:
                                AltTraceIn0( ALTRACE_LEV_BASE, "Arrivato 
segnale di SIGTERM" );
                                break;

//          case SIGINT:
//              PrintTimeMex( TRUE,"Arrivato segnale di SIGINT\n" );
//              break;

                        case SIGPIPE:
                                AltTraceIn0( ALTRACE_LEV_BASE,"Arrivato segnale 
di SIGPIPE" );
                                break;

                        case SIGFPE:
                                AltTraceInN( ALTRACE_LEV_BASE,"Arrivato segnale 
di SIGFPE all'indirizzo: 0x%08x", uc->uc_mcontext.fault_address );
                                break;

                        case SIGSEGV:
                                AltTraceInN( ALTRACE_LEV_BASE,"Arrivato segnale 
di SIGSEGV all'indirizzo: 0x%08x",  uc->uc_mcontext.fault_address );
                                signal( SIGSEGV, SIG_DFL );
                                break;

            case SIGBUS:
                AltTraceInN( ALTRACE_LEV_BASE, "Arrivato segnale di SIGBUS 
all'indirizzo: 0x%08x", uc->uc_mcontext.arm_pc);
                signal( SIGBUS, SIG_DFL );
                break;

            default:
                AltTraceIn0( ALTRACE_LEV_BASE, "Arrivato segnale NON 
riconosciuto" );
                break;
                }

        // quando verrà eseguito il main viene fermata l'applicazione, tranne 
nel caso di segmentation fault
        // perchè così può essere costruito un core dump dell'applicazione
        stopApplication = TRUE;

        // Faccio partire task di chiusura
        AltTraceIn0( ALTRACE_LEV_BASE,"Start task Apgs (sigHandler) ...");
        mtresumetask( tsk_APGS );
        }
}


void    ChiusuraAPGS (void)
{
    /* terminazione dell'applicazione su kill */
    AltTraceIn0( ALTRACE_LEV_BASE,"Disabilitazione irq fujitsu..." );
    disable_irq_fujitsu();

    AltTraceIn0( ALTRACE_LEV_BASE,"Eliminazione tasks realtime..." );
    CleanRtEnv();

    AltTraceIn0( ALTRACE_LEV_BASE,"Stop della comunicazione di rete..." );
    StopCommunication();

    AltTraceIn0( ALTRACE_LEV_BASE,"Messa in reset del fujitsu..." );
    put_rst_fujtusu();

    AltTraceIn0( ALTRACE_LEV_BASE,"Eliminazione della memoria IO mappata..." );
    unmapMicroRegMemory();
    unmapFujMem();
    unmapPCMem();
    closeIOMem();
}


int main (int argc, char *argv[])
{
        //      Porta di comunicazione
        int s;

        mlockall(MCL_CURRENT|MCL_FUTURE);

        // gestione signal handler
        struct sigaction sa;
        sa.sa_sigaction = sigHandler;
        sigemptyset (&sa.sa_mask);
        sa.sa_flags = SA_SIGINFO;

        sigaction(SIGTERM, &sa, NULL);
//      sigaction(SIGINT, &sa, NULL);
        sigaction(SIGPIPE, &sa, NULL);
        sigaction(SIGFPE, &sa, NULL);
        sigaction(SIGSEGV, &sa, NULL);
    sigaction(SIGBUS, &sa, NULL);

        printf( RT_VERSION"\n" );

                //creazione area di trace
        if( !AltCreateTraceArea( _T("APGS"), 0x1000 ) )
                perror( "Impossibile creare l'area di trace " );
                
        AltSetTraceMask( ALTRACE_LEV_BASE );
        AltSetTraceTime( FALSE );

        // lettura degli argomenti dalla riga di comando con getopt 
------------------------
        s = getopt( argc,argv,CMD_OPT );
        if ( s == 'h' )
        {
                printf( "utilizzo: APGS \n"
                                "  [-h]         # Mostra questo help\n"
                                "  [-c]         # Path del file .cod"
                                "  [-p]         # Setta la porta di 
comunicazione del LogicLab\n"
                "  [-D]     # Lancia applicativo in Debug\n"
                                "  [-M]     # Cambia maschera di trace di 
acquisizione\n");
                exit( 0 );
        }

        do
        {
                switch (s)
                {
                        case 'p':
                                        //      Inizializzazione e partenza del 
gestore PLC
                                SetTcpPort( atoi( optarg ) );
                                break;

                        case 'c':
                                        // settiamo il path del file .cod
                                SetCodPath( optarg );
                                break;

            case 'D':
                mt_debug = VERO;
                break;

                        case 'M':
                                AltSetTraceMask( strtoul( optarg, NULL, 0 ) );
                break;

                }
        } while ( (s = getopt( argc,argv,CMD_OPT ) ) != EOF);


                //partenza acquisizione da parte di AlTrace
        AltStartTrace();

        AltTraceIn0( ALTRACE_LEV_BASE, _T("AlTrace configured, levels active:") 
);

        AltTraceIn0( ALTRACE_LEV_BASE,          _T("ALTRACE_LEV_BASE - Base 
level") );
        AltTraceIn0( ALTRACE_LEV_OS_TASK,       _T("ALTRACE_LEV_OS_TASK - OS 
task management") );
        AltTraceIn0( ALTRACE_LEV_OS_SEM,        _T("ALTRACE_LEV_OS_SEM - OS     
semaphore calls") );
        AltTraceIn0( ALTRACE_LEV_OS_SLEEP,      _T("ALTRACE_LEV_OS_SLEEP - OS 
sleep calls") );
        AltTraceIn0( ALTRACE_LEV_OS_REGION,     _T("ALTRACE_LEV_OS_REGION - OS 
mutex calls") );
        AltTraceIn0( ALTRACE_LEV_OS_MBX,        _T("ALTRACE_LEV_OS_MBX - OS 
mailbox calls") );
        AltTraceIn0( ALTRACE_LEV_OS_LINUX,      _T("ALTRACE_LEV_OS_LINUX - OS 
base services linux calls") );
        AltTraceIn0( ALTRACE_LEV_RT_PLC,        _T("ALTRACE_LEV_RT_PLC - PLC 
runtime operations") );
        AltTraceIn0( ALTRACE_LEV_GDB,           _T("ALTRACE_LEV_GDB - GDB 
protocol operations") );

        
//----------------------------------------------------------------------------------

        AltTraceIn0( ALTRACE_LEV_BASE, "Apertura Memoria IO...");
        if ( ! openIOMem() )
        {
                AltTraceIn0( ALTRACE_LEV_BASE, "Errore su apertura memoria di 
IO");
                return 0;
        }

    AltTraceIn0( ALTRACE_LEV_BASE, "Mappatura memorie di IO e risorse arm...");
        if ( ! mapPcMem()|| ! mapFujMem() || ! mapMicroRegMemory() )
        {
                AltTraceIn0( ALTRACE_LEV_BASE,"Errore: Memorie IO non mappate o 
risosrse non valide");
                return FALSE;
        }

        AltTraceIn0( ALTRACE_LEV_BASE,"Generazione del sistema realtime...");

        AltTraceIn0( ALTRACE_LEV_BASE,"Inizializzazione IRQ da Fujitsu...");
        init_irq_fujitsu();

        AltTraceIn0( ALTRACE_LEV_BASE,"Disabilitazione IRQ da fujitsu e reset 
fujitsu...");
        disable_irq_fujitsu();

        // mettiamo in reset il fujitsu
        put_rst_fujtusu();
        usleep (10000);
        // rimuoviamo il reset del fujitsu
        remove_rst_fujitsu();

        AltTraceIn0( ALTRACE_LEV_BASE,"Inizializzazione ambiente realtime..." );
        if( ! InitRTEnv() )
    {
        ChiusuraAPGS ();
        exit(0);
    }

        AltTraceIn0( ALTRACE_LEV_BASE, "Start task Sysgen ...");
        mtresumetask( tsk_SYSGEN );

        for( ;; )
        {
                usleep (1000000);
        }

        return(0);
}

void    Apgs (void)
{
    ChiusuraAPGS ();
    exit(0);
}

/** \file rttasks.c
*   implementazione delle funzioni e dei task real time Axel
*/

#include "cext.h"
#include "pc.h"
#include "rttasks.h"

#include "apgs.h"
#include "inout.h"
#include "iomanag.h"
#include "sysgen.h"
#include "datacan.h"
#include "reghyd.h"
#include "mper.h"
#include "canbus.h"
#include "cansrv.h"
#include "can443.h"
#include "gestdp.h"
#include "canbus.h"
#include "execc.h"
#include "barri.h"
#include "execnn.h"
#include "execyzvw.h"
#include "foratura.h"
#include "funsw.h"
#include "funswy.h"
#include "funswz.h"
#include "funswv.h"
#include "funsww.h"
#include "testa.h"
#include "testa2.h"
#include "hostc.h"
#include "per_par.h"
#include "funino.h"
#include "clk.h"
#include "alplc/plcmanager.h"

#include "TraceInput.h"
#include "TraceLog.h"



RT_INTR         int_desc;                               /* definizione irq 
Xenomai */
RT_TASK         tskHndXeno[NUMTASKS];   /* Descrittore dei task Xenomai */
RT_SEM          tskSem[NUMTASKS];               /* Definizione degli handle dei 
semafori di avvio per ogni task */
RT_SEM          envSem[NUMSYSSEM];              /* semafori di sistema */
RT_MUTEX        envReg[NUMSYSREG];              /* regioni di sistema */
RT_QUEUE        envMbx[NUMSYSMBX];              /* mailbox di sistema */


/* ----------------TABELLA DEI TASK------------------------------------------ */


//  ;   Tasks
//  ;
//  ;           Nome                Pri     Stack   Start
//  
//  #def task,  Sysgen,             31,     400,    sysgen
//  #def task,  Polkey,             31,     400,    poll_key
//  #def task,  plc,                28,     400,    exe_plc     ; PLC
//  #def task,  Inout,              25,     800,    inout
//  #def task,  Alarm,              24,     400,    alarm
//  #def task,  Exemsg,             23,     800,    exemsg
//  #def task,  Exec,               22,     800,    exec        ; Exec
//  #def task,  Execc,              21,     800,    execc       ; Exec canonico
//  #def task,  Arbix,              21,     800,    arbix
//  #def task,  Barri,              20,     800,    barri
//  #def task,  AxeCan,             20,     400,    AxeCan      ; Gestore assi 
CAN
//  #def task,  IniCan,             20,     400,    IniCan      ; Gestore assi 
INI CAN
//  #def task,  CanBus,             19,     400,    CanBus      ; Task Canbus
//  #def task,  Exec00,             18,     400,    exec00
//  #def task,  Exec01,             18,     400,    exec01
//  #def task,  Exec02,             18,     400,    exec02
//  #def task,  Exec03,             18,     400,    exec03
//  #def task,  Exec04,             18,     400,    exec04
//  #def task,  Exec05,             18,     400,    exec05
//  #def task,  Exec06,             18,     400,    exec06
//  #def task,  Exec07,             18,     400,    exec07
//  #def task,  Exec08,             18,     400,    exec08
//  #def task,  Exec09,             18,     400,    exec09
//  #def task,  Exec10,             18,     400,    exec10
//  #def task,  Exec11,             18,     400,    exec11
//  #def task,  Exec12,             18,     400,    exec12
//  #def task,  Exec13,             18,     400,    exec13
//  #def task,  Exec14,             18,     400,    exec14
//  #def task,  Exec15,             18,     400,    exec15
//  #def task,  Exec16,             18,     400,    exec16
//  #def task,  Exec17,             18,     400,    exec17
//  #def task,  Exec18,             18,     400,    exec18
//  #def task,  Exec19,             18,     400,    exec19
//  #def task,  Execy,              18,     800,    execy
//  #def task,  Execz,              18,     800,    execz
//  #def task,  Execv,              18,     800,    execv
//  #def task,  Execw,              18,     800,    execw
//  #def task,  Fun,                18,     800,    fun
//  #def task,  Funy,               18,     800,    funy
//  #def task,  Funz,               18,     800,    funz
//  #def task,  Funv,               18,     800,    funv
//  #def task,  Funw,               18,     800,    funw
//  #def task,  Cuty,               18,     800,    cuty
//  #def task,  Cutz,               18,     800,    cutz
//  #def task,  Cutv,               18,     800,    cutv
//  #def task,  Cutw,               18,     800,    cutw
//  #def task,  Cutp,               18,     800,    CutPz       ; Cambio 
utensile punzo TipoC
//  #def task,  Testa,              18,     800,    testa
//  #def task,  Testa2,             18,     800,    testa2
//  #def task,  Hostc,              18,     800,    hostc
//  #def task,  RefParC,            16,     800,    RefParC     ; Ref Par CanBus
//  #def task,  Gdbplc,             15,     800,    gdbplc
//  #def task,  Gdbdp,              15,     800,    gdbdp
//  #def task,  FunIno,             13,     800,    funIno
//  #def task,  Gestdp,             13,     800,    gestdp
//  #def task,  bckplc,             10,     400,    bckplc
//  #def task,  orologio,            2,     400,    orologio



RTTASKS tabRtTask[] = {
    //
        // Tabella dei task - contiene nell'ordine tutti i task da lanciare nel 
sistema realtime.
    //
//pr  name           rtDescriptor                 stkSize  mode    semaphore  
fnAddr                    tskArgs
{ 90, "TskAPGS",     &tskHndXeno[tsk_APGS],       0x8000,  0,  0,         
(word32) Apgs,            NULL },
{ 85, "TskSysgen",   &tskHndXeno[tsk_SYSGEN],     0x8000,  0,  0,         
(word32) Sysgen,          NULL },
{ 80, "TskIoManag",  &tskHndXeno[tsk_IOMANAG],    0x8000,  0,  0,         
(word32) IOManag,         NULL },
{ 31, "TskPolKey",   &tskHndXeno[tsk_POLKEY],     0x8000,  0,  0,         
(word32) poll_key,        NULL },
{ 25, "TskInout",        &tskHndXeno[tsk_INOUT],          0x8000,  0,  0,       
  (word32) Inout,             NULL },
{ 24, "TskAlarm",        &tskHndXeno[tsk_ALARM],          0x80000,  0,  0,      
   (word32) Alarm,            NULL },
{ 23, "TskExeMsg",       &tskHndXeno[tsk_EXEMSG],         0x8000,  0,  0,       
  (word32) exemsg,            NULL },
{ 22, "TskExec",         &tskHndXeno[tsk_EXEC],           0x80000,  0,  0,      
   (word32) Exec,                 NULL },
{ 21, "TskExecc",        &tskHndXeno[tsk_EXECC],          0x8000,  0,  0,       
  (word32) execc,             NULL },
{ 21, "TskArbix",        &tskHndXeno[tsk_ARBIX],          0x8000,  0,  0,       
  (word32) arbix,             NULL },
{ 20, "TskBarri",        &tskHndXeno[tsk_BARRI],          0x8000,  0,  0,       
  (word32) barri,             NULL },
{ 20, "TskAxeCan",       &tskHndXeno[tsk_AXECAN],         0x8000,  0,  0,       
  (word32) AxeCan,            NULL },
{ 20, "TskIniCan",       &tskHndXeno[tsk_INICAN],         0x8000,  0,  0,       
  (word32) IniCan,          NULL },
{ 19, "TskCanBus",       &tskHndXeno[tsk_CANBUS],         0x8000,  0,  0,       
  (word32) CanBus,          NULL },
{ 18, "TskExec00",       &tskHndXeno[tsk_EXEC00],         0x8000,  0,  0,       
  (word32) exec00,          NULL },
{ 18, "TskExec01",       &tskHndXeno[tsk_EXEC01],         0x8000,  0,  0,       
  (word32) exec01,          NULL },
{ 18, "TskExec02",       &tskHndXeno[tsk_EXEC02],         0x8000,  0,  0,       
  (word32) exec02,          NULL },
{ 18, "TskExec03",       &tskHndXeno[tsk_EXEC03],         0x8000,  0,  0,       
  (word32) exec03,          NULL },
{ 18, "TskExec04",       &tskHndXeno[tsk_EXEC04],         0x8000,  0,  0,       
  (word32) exec04,          NULL},
{ 18, "TskExec05",       &tskHndXeno[tsk_EXEC05],         0x8000,  0,  0,       
  (word32) exec05,          NULL},
{ 18, "TskExec06",       &tskHndXeno[tsk_EXEC06],         0x8000,  0,  0,       
  (word32) exec06,          NULL},
{ 18, "TskExec07",       &tskHndXeno[tsk_EXEC07],         0x8000,  0,  0,       
  (word32) exec07,          NULL},
{ 18, "TskExec08",       &tskHndXeno[tsk_EXEC08],         0x8000,  0,  0,       
  (word32) exec08,          NULL},
{ 18, "TskExec09",       &tskHndXeno[tsk_EXEC09],         0x8000,  0,  0,       
  (word32) exec09,          NULL},
{ 18, "TskExec10",       &tskHndXeno[tsk_EXEC10],         0x8000,  0,  0,       
  (word32) exec10,          NULL},
{ 18, "TskExec11",       &tskHndXeno[tsk_EXEC11],         0x8000,  0,  0,       
  (word32) exec11,          NULL},
{ 18, "TskExec12",       &tskHndXeno[tsk_EXEC12],         0x8000,  0,  0,       
  (word32) exec12,          NULL},
{ 18, "TskExec13",       &tskHndXeno[tsk_EXEC13],         0x8000,  0,  0,       
  (word32) exec13,          NULL},
{ 18, "TskExec14",       &tskHndXeno[tsk_EXEC14],         0x8000,  0,  0,       
  (word32) exec14,          NULL},
{ 18, "TskExec15",       &tskHndXeno[tsk_EXEC15],         0x8000,  0,  0,       
  (word32) exec15,          NULL},
{ 18, "TskExec16",       &tskHndXeno[tsk_EXEC16],         0x8000,  0,  0,       
  (word32) exec16,          NULL},
{ 18, "TskExec17",       &tskHndXeno[tsk_EXEC17],         0x8000,  0,  0,       
  (word32) exec17,          NULL},
{ 18, "TskExec18",       &tskHndXeno[tsk_EXEC18],         0x8000,  0,  0,       
  (word32) exec18,          NULL},
{ 18, "TskExec19",       &tskHndXeno[tsk_EXEC19],         0x8000,  0,  0,       
  (word32) exec19,          NULL},
{ 18, "TskExecY",        &tskHndXeno[tsk_EXECY],          0x8000,  0,  0,       
  (word32) ExecY,           NULL},
{ 18, "TskExecZ",        &tskHndXeno[tsk_EXECZ],          0x8000,  0,  0,       
  (word32) ExecZ,           NULL},
{ 18, "TskExecV",        &tskHndXeno[tsk_EXECV],          0x8000,  0,  0,       
  (word32) ExecV,           NULL},
{ 18, "TskExecW",        &tskHndXeno[tsk_EXECW],          0x8000,  0,  0,       
  (word32) ExecW,           NULL},
{ 18, "TskFun",          &tskHndXeno[tsk_FUN],        0x8000,  0,  0,         
(word32) fun,             NULL},
{ 18, "TskFunY",         &tskHndXeno[tsk_FUNY],           0x8000,  0,  0,       
  (word32) funy,            NULL},
{ 18, "TskFunZ",         &tskHndXeno[tsk_FUNZ],           0x8000,  0,  0,       
  (word32) funz,            NULL},
{ 18, "TskFunV",         &tskHndXeno[tsk_FUNV],           0x8000,  0,  0,       
  (word32) funv,            NULL},
{ 18, "TskFunW",         &tskHndXeno[tsk_FUNW],           0x8000,  0,  0,       
  (word32) funw,            NULL},
{ 18, "TskForY",         &tskHndXeno[tsk_FORY],           0x8000,  0,  0,       
  (word32) ForaY,           NULL},
{ 18, "TskForZ",         &tskHndXeno[tsk_FORZ],           0x8000,  0,  0,       
  (word32) ForaZ,           NULL},
{ 18, "TskForV",         &tskHndXeno[tsk_FORV],           0x8000,  0,  0,       
  (word32) ForaV,           NULL},
{ 18, "TskForW",         &tskHndXeno[tsk_FORW],           0x8000,  0,  0,       
  (word32) ForaW,           NULL },
{ 18, "TskCutY",         &tskHndXeno[tsk_CUTY],           0x8000,  0,  0,       
  (word32) cuty,            NULL },
{ 18, "TskCutZ",         &tskHndXeno[tsk_CUTZ],           0x8000,  0,  0,       
  (word32) cutz,            NULL },
{ 18, "TskCutV",         &tskHndXeno[tsk_CUTV],           0x8000,  0,  0,       
  (word32) cutv,            NULL },
{ 18, "TskCutW",         &tskHndXeno[tsk_CUTW],           0x8000,  0,  0,       
  (word32) cutw,            NULL },
{ 18, "TskCutP",         &tskHndXeno[tsk_CUTP],           0x8000,  0,  0,       
  (word32) CutPz,           NULL },
{ 18, "TskTesta",        &tskHndXeno[tsk_TESTA],      0x8000,  0,  0,         
(word32) testa,           NULL },
{ 18, "TskTesta2",       &tskHndXeno[tsk_TESTA2],     0x8000,  0,  0,         
(word32) testa2,          NULL },
{ 18, "TskHostc",        &tskHndXeno[tsk_HOSTC],      0x8000,  0,  0,         
(word32) hostc,           NULL },
{ 16, "TskRefParC",  &tskHndXeno[tsk_REFPARC],    0x8000,  0,  0,         
(word32) RefParC,         NULL },
{ 15, "TskPlcQuery", &tskHndXeno[ID_RTTASK_PLD],  0x8000,  0,  0,         
(word32) tskHnd_PlcQuery, NULL },
{ 13, "TskFunIno",   &tskHndXeno[tsk_FUNINO],     0x8000,  0,  0,         
(word32) funIno,          NULL },
{ 13, "TskGestdp",   &tskHndXeno[tsk_GESTDP],     0x8000,  0,  0,         
(word32) gestdp,          NULL },
{ 10, "TskBckPlc",       &tskHndXeno[tsk_BCKPLC],         0x8000,  0,  0,       
  (word32) bckplc,            NULL },
{  2, "TskOrologio", &tskHndXeno[tsk_OROLOGIO],   0x8000,  0,  0,         
(word32) orologio,        NULL },
};

/*----------------------------------------------------------------------------*/

/*corpo del task background */
void tskHnd_PlcQuery ( void *cookie )
{
                //      Comandi di background per runtime
        for( ;; ) 
        {
                PLCRuntimeBackground();
                mtsleep( 100 );
        }

}

//attivazione tasks realtime
boolean InitRTEnv( void )
{
        int     err, i;
        char    nameSem[ MAXSEMLENNAME ];

    // ???
        AltTraceIn0(ALTRACE_LEV_BASE, "INTR Xenomai userspace...");
        err = rt_intr_create( &int_desc, IRQNAME , IRQNUMBER, I_PROPAGATE );
        AltTraceInN(ALTRACE_LEV_OS_TASK, "rt_intr_create : %s - err %d", 
IRQNAME, err );
        if ( err != 0 )
        {
                AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
                return FALSE;
        }

        

        AltTraceIn0(ALTRACE_LEV_BASE,"OK" );

        // gestione del timer periodico
        err = rt_timer_set_mode( QUANTUMTIMENS );
        AltTraceInN(ALTRACE_LEV_OS_TASK, "rt_timer_set_mode - err %d", err );
        if ( err != 0 )
        {
                AltTraceIn0(ALTRACE_LEV_BASE,"Errore su rt_timer_set_mode" );
                return FALSE;
        }

        

        
    // creazione dei semafori realtime
        for(i=0; i < NUMSYSSEM; i++ )
        {
                sprintf( nameSem, "envSem%d", i );
                AltTraceInN(ALTRACE_LEV_BASE,"SEM environment %s...", nameSem );
                err = rt_sem_create( &envSem[i], nameSem, 0, S_FIFO );
                AltTraceInN(ALTRACE_LEV_OS_SEM, "rt_sem_create : %s - err %d", 
nameSem, err );
                if ( err != 0 )
                {
                        
AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
                        return FALSE;
                }

                
                AltTraceIn0(ALTRACE_LEV_BASE,"OK" );
        }

    // creazione delle mailbox realtime
        for(i=0; i < NUMSYSMBX; i++ )
        {
                sprintf( nameSem, "envMbx%d", i );
                AltTraceInN(ALTRACE_LEV_BASE,"MBX environment %s...", nameSem );
                err = rt_queue_create( &envMbx[i], nameSem, MBX_SIZE_POOL, 
Q_UNLIMITED, Q_FIFO );
                AltTraceInN(ALTRACE_LEV_OS_MBX, "rt_queue_create : %s - err 
%d", nameSem, err );
                if ( err != 0 )
                {
                        
AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
                        return FALSE;
                }

                AltTraceIn0(ALTRACE_LEV_BASE,"OK" );
        }

    // creazione delle regioni realtime
        for(i=0; i < NUMSYSREG; i++ )
        {
                sprintf( nameSem, "envReg%d", i );
                AltTraceInN(ALTRACE_LEV_BASE,"RGN environment %s...", nameSem );
                err = rt_mutex_create( &envReg[i], nameSem );
                AltTraceInN(ALTRACE_LEV_OS_REGION, "rt_mutex_create : %s - err 
%d", nameSem, err );
                if ( err != 0 )
                {
                        
AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
                        return FALSE;
                }

                AltTraceIn0(ALTRACE_LEV_BASE,"OK" );
        }

        // creazione dei task realtime
        for ( i = 0; i < NUMTASKS; i++ )
        {
                // creazione dei semafori per ogni task
                if( tabRtTask[i].enabSem != 0 )
                {
                        AltTraceInN(ALTRACE_LEV_BASE,"SEM task %s...", 
tabRtTask[i].name );

                        sprintf( nameSem, "%sSem%d", tabRtTask[i].name, i );
                        err = rt_sem_create( tabRtTask[i].enabSem, nameSem, 0, 
S_FIFO | S_PULSE );
                        AltTraceInN(ALTRACE_LEV_OS_SEM, "rt_sem_create : %s - 
err %d", nameSem, err );
                        if ( err != 0 )
                        {
                                
AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
                                return FALSE;
                        }

                        AltTraceIn0(ALTRACE_LEV_BASE,"OK" );
                }

                AltTraceInN(ALTRACE_LEV_BASE,"TSK %s create...", 
tabRtTask[i].name );

                err = rt_task_create( tabRtTask[i].rtDesc, tabRtTask[i].name, 
tabRtTask[i].stkSize,tabRtTask[i].priority,tabRtTask[i].mode);
                AltTraceInN(ALTRACE_LEV_OS_SEM, "rt_task_create : %s - err %d", 
tabRtTask[i].name, err );
                if ( err != 0 )
                {
                        
AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
                        return FALSE;
                }

                AltTraceIn0(ALTRACE_LEV_BASE,"OK" );
        }

    //creazione mutex di sincronizzazione cancellazioni
    err = rt_mutex_create( &mutexDelete, "mutexDelete" );
    if ( err != 0 )
    {
        AltTraceInN(ALTRACE_LEV_BASE,"Impossible to create mutexDelete err = 
%d", err );
        return FALSE;
    }
        return TRUE;
}


boolean CleanRtEnv( void )
{
        int i, err;
        char nameSem[ MAXSEMLENNAME ];

    // Il primo task APGS non deve essere resettato perchè deve chiudere 
l'applicazione !!!!
        for ( i=NUMTASKS-1; i > 0; i-- )
        {
                AltTraceInN(ALTRACE_LEV_BASE,"TSK %s delete...", 
tabRtTask[i].name );
                err = rt_task_delete( tabRtTask[i].rtDesc );
                if ( err != 0 )
                        
AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
        else
            AltTraceIn0(ALTRACE_LEV_BASE,"OK" );

                if( tabRtTask[i].enabSem != 0 )
                {
                        AltTraceInN(ALTRACE_LEV_BASE,"SEM task %s delete...", 
tabRtTask[i].name );

                        err = rt_sem_delete( tabRtTask[i].enabSem );
                        if ( err != 0 )
                                
AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
            else
                AltTraceIn0(ALTRACE_LEV_BASE,"OK" );
                }
        }

        AltTraceIn0(ALTRACE_LEV_BASE,"INTR Xenomai userspace delete...");
        err = rt_intr_delete( &int_desc );
        if ( err != 0 )
                AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
    else
        AltTraceIn0(ALTRACE_LEV_BASE,"OK" );

        for ( i=0; i < NUMSYSSEM; i++ )
        {
                sprintf( nameSem, "envSem%d", i );
                AltTraceInN(ALTRACE_LEV_BASE,"SEM environment %s delete...", 
nameSem );

                err = rt_sem_delete( getEnvSem( i ) );
                if ( err != 0 )
                        
AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
        else
            AltTraceIn0(ALTRACE_LEV_BASE,"OK" );
        }

        for ( i=0; i < NUMSYSREG; i++ )
        {
                sprintf( nameSem, "envReg%d", i );
                AltTraceInN(ALTRACE_LEV_BASE,"RGN environment %s delete...", 
nameSem );
                err = rt_mutex_delete( &envReg[i] );
                if ( err != 0 )
                        
AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
        else
            AltTraceIn0(ALTRACE_LEV_BASE,"OK" );
        }

        for ( i=0; i < NUMSYSMBX; i++ )
        {
                sprintf( nameSem, "envMbx%d", i );
                AltTraceInN(ALTRACE_LEV_BASE,"MBX environment %s delete...", 
nameSem );
                err = rt_queue_delete( getEnvMbx( i ) );
                if ( err != 0 )
                        
AltTraceIn0(ALTRACE_LEV_BASE,".........................KO" );
        else
            AltTraceIn0(ALTRACE_LEV_BASE,"OK" );
        }

        return TRUE;
}

//----------------------------------------------------------------------------
#ifndef _RTTASKS_H
#define _RTTASKS_H

#include "mitos.h"
#include "fujitsu.h"
#include "utilities.h"

#define MAXTSKLENNAME   16
#define MAXSEMLENNAME   MAXTSKLENNAME + 6

//incremento dei cicli effettuati dall'avvio del realtime
extern RT_INTR  int_desc;

/* costanti di definizione dei task */
#define NUMTASKS                        61      // TOTALI
#define tsk_APGS                    0
#define tsk_SYSGEN                      1
#define tsk_IOMANAG             2
#define tsk_POLKEY              3
#define tsk_INOUT                       4
#define tsk_ALARM                       5
#define tsk_EXEMSG                      6
#define tsk_EXEC                        7
#define tsk_EXECC                       8
#define tsk_ARBIX                       9
#define tsk_BARRI                   10
#define tsk_AXECAN                      11
#define tsk_INICAN                      12
#define tsk_CANBUS                  13
#define tsk_EXEC00                  14
#define tsk_EXEC01                  15
#define tsk_EXEC02                  16
#define tsk_EXEC03                  17
#define tsk_EXEC04                  18
#define tsk_EXEC05                  19
#define tsk_EXEC06                  20
#define tsk_EXEC07                  21
#define tsk_EXEC08                  22
#define tsk_EXEC09                  23
#define tsk_EXEC10                  24
#define tsk_EXEC11                  25
#define tsk_EXEC12                  26
#define tsk_EXEC13                  27
#define tsk_EXEC14                  28
#define tsk_EXEC15                  29
#define tsk_EXEC16                  30
#define tsk_EXEC17                  31
#define tsk_EXEC18                  32
#define tsk_EXEC19                  33
#define tsk_EXECY                   34
#define tsk_EXECZ                   35
#define tsk_EXECV                   36
#define tsk_EXECW                   37
#define tsk_FUN                     38
#define tsk_FUNY                    39
#define tsk_FUNZ                    40
#define tsk_FUNV                    41
#define tsk_FUNW                    42
#define tsk_FORY                    43
#define tsk_FORZ                    44
#define tsk_FORV                    45
#define tsk_FORW                    46
#define tsk_CUTY                        47
#define tsk_CUTZ                        48
#define tsk_CUTV                        49
#define tsk_CUTW                        50
#define tsk_CUTP                        51
#define tsk_TESTA                       52
#define tsk_TESTA2                      53
#define tsk_HOSTC                       54
#define tsk_REFPARC                     55
#define ID_RTTASK_PLD           56
#define tsk_FUNINO                      57
#define tsk_GESTDP                      58
#define tsk_BCKPLC          59
#define tsk_OROLOGIO            60


#define NUMSYSSEM                       28      // TOTALI
#define ID_SEM_EXE                      0
#define ID_SEM_AXECAN           1
#define ID_SEM_INICAN           2
#define ID_SEM_ALA                      3
#define ID_SEM_EXY                      4
#define ID_SEM_EXZ                      5
#define ID_SEM_EXV                      6
#define ID_SEM_EXW                      7
#define ID_SEM_REX                      8
#define ID_SEM_FUN                      9
#define ID_SEM_FUNY                     10
#define ID_SEM_FUNZ                     11
#define ID_SEM_FUNV                     12
#define ID_SEM_FUNW                     13
#define ID_SEM_FORY                     14
#define ID_SEM_FORZ                     15
#define ID_SEM_FORV                     16
#define ID_SEM_FORW                     17
#define ID_SEM_CUTY             18
#define ID_SEM_CUTZ                     19
#define ID_SEM_CUTV                     20
#define ID_SEM_CUTW                     21
#define ID_SEM_CUTP                     22
#define ID_SEM_INOUT            23
#define ID_SEM_PKEY                     24
#define ID_SEM_MSG                      25
#define ID_SEM_RESMSG           26
#define ID_SEM_SDO                      27

#define NUMSYSREG                       2       // TOTALI
#define ID_REG_MEM                      0
#define ID_REG_SDO                      1

#define NUMSYSMBX                       29      // TOTALI
#define ID_MBX_CUTY             0       
#define ID_MBX_RCUTY            1          
#define ID_MBX_CUTZ                     2    
#define ID_MBX_RCUTZ            3          
#define ID_MBX_CUTV                     4    
#define ID_MBX_RCUTV            5   
#define ID_MBX_CUTW                     6    
#define ID_MBX_RCUTW            7          
#define ID_MBX_CUTP                     8   //  Mailbox per invio a CUTP
#define ID_MBX_RCUTP            9   //  Mailbox per risposta da CUTP
#define ID_MBX_BAR                      10  
#define ID_MBX_RBAR_C           11
#define ID_MBX_RBAR_B           12
#define ID_MBX_ARB                      13
#define ID_MBX_RARB_A           14
#define ID_MBX_RARB_B           15
#define ID_MBX_RARB_C           16
#define ID_MBX_RARB_D           17
#define ID_MBX_RARB_E           18
#define ID_MBX_RARB_F           19
#define ID_MBX_TSA                      20     
#define ID_MBX_RTSA                     21    
#define ID_MBX_TSA2                     22    
#define ID_MBX_RTSA2            23   
#define ID_MBX_EXEC                     24  //   Comando Task EXEC CANONICO
#define ID_MBX_REXE                     25  //   Risposta dei Task EXEC 
CANONICO e SECONDO
#define ID_MBX_MSG                      26  //   Mailbox per task EXEMSG
#define ID_MBX_RESMSG           27  //   Mailbox richiesta reset coda per EXEMSG
#define ID_MBX_CANBUS           28  //   Mailbox richiesta task CanBus

///////////////////////////////////////////////////////////////////////////////


typedef struct
{
    int         priority;                           // range between 99 and 0, 
99 is the most priority
    char        name[MAXTSKLENNAME];    // nome da assegnare al task
    RT_TASK     * rtDesc;                           // descrittore che viene 
valorizzato durante la create
    int         stkSize;                            // dimensione dello stack 
da istanziare, con valore 0 viene scelto dal sistem
    int         mode;                               // vedi documentazione 
Xenomai, funzione rt_task_create
    RT_SEM              * enabSem;                          // semaforo di 
abilitazione del task
    word32      fnAddr;                             // puntatore alla funzione 
da eseguire
    void *      tskArgs;                            // puntatore agli argomenti 
da passare alla funzione eseguita dal task

}
RTTASKS;

extern RTTASKS          tabRtTask[];
extern RT_SEM           envSem[NUMSYSSEM];
extern RT_MUTEX         envReg[NUMSYSREG];
extern RT_QUEUE         envMbx[NUMSYSMBX];

//attivazione tasks realtime
extern boolean InitRTEnv( void );
extern boolean CleanRtEnv( void );

//prototipi handler dei task
//      extern void tskHnd_IrqFuj       ( void *cookie );
//      extern void tskHnd_Inout        ( void *cookie );
//      extern void tskHnd_PlcFast      ( void *cookie );
//      extern void tskHnd_PlcSlow      ( void *cookie );
//      extern void tskHnd_CanSrv       ( void *cookie );
//      extern void tskHnd_Bck          ( void *cookie );
extern void tskHnd_PlcQuery     ( void *cookie );

    //prototipi task esterni
extern void AxeCan( void );
extern void IniCan( void );
extern void exemsg (void);
extern void arbix (void);
extern void cuty  (void);
extern void cutv  (void);
extern void cutw  (void);
extern void CutPz (void);
extern void cutz  (void);
extern void CutPz (void);

#endif
_______________________________________________
Xenomai-core mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-core

Reply via email to