/** \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; } //----------------------------------------------------------------------------