Hi Gabor and Vasili, thanks for your attention,

I changed somethings in my code and i think that because of this i've not
been get negative values writing or reading from fifos. Anyway i'd like to
know what is the meaning of the return values that i get. Now, i've been
getting 12 when i write to the fifos  (is it the number of bytes? Is there
some documentation about it?).

 Another thing is that my system always freeze in the first time that i
send  commands to initiate the periodic tasks, i mean: i turn on the
computer, do a insmod with my module name and when i try initiate my
periodic tasks (running a monitor program) the system freeze, so i have to
reset the computer, my HD is checked and i try everything again, and this
time it works. Is there any way to check what happened when the system
freeze? 

A piece of my module:

int comando(unsigned int fifo)
{
  int err;

#ifdef V1
   RTIME now;
#endif

#ifdef V2
hrtime_t now;
#endif

printk("Handler Comando Chamado\n");

  err= rtf_get(fifo, &MSG, sizeof(MSG));
  switch (MSG.command){
        case START_TASK:
         printk("Comando: %d, Tarefa: %d, Periodo: %d\n",
MSG.command,MSG.tarefa,MSG.period);
               #ifdef V2
               now = gethrtime();
               pthread_wakeup_np(tarefa[MSG.tarefa]);
               err=pthread_make_periodic_np(tarefa[MSG.tarefa], now,
MSG.period*5000);
               if (err<0) { printk("Erro fazendo a tarefa %d periodica, err=
%i\n",MSG.tarefa,err);} else {printk("Sucesso fazendo a tarefa %d
periodica, err= %i\n",MSG.tarefa,err);}
               #endif
               #ifdef V1
                now = rt_get_time(); 
                err=rt_task_make_periodic(&tarefa[MSG.tarefa], now,MSG.period);
                if (err<0) { printk("Erro fazendo a tarefa %d periodica, err=
%i\n",MSG.tarefa,err);} else {printk("Sucesso fazendo a tarefa %d
periodica, err= %i\n",MSG.tarefa,err);}
                #endif
          break;      
        case STOP_TASK:
         printk("Comando: %d, Tarefa: %d, Periodo: %d\n",
MSG.command,MSG.tarefa,MSG.period);
               #ifdef V2
               err=pthread_suspend_np(tarefa[MSG.tarefa]);
               if (err<0) { printk("Erro suspendedo a tarefa %d periodica, err=
%i\n",MSG.tarefa,err);} else {printk("Sucesso suspendendo a tarefa %d
periodica, err= %i \n",MSG.tarefa,err);}
               #endif
               #ifdef V1
               err=rt_task_suspend(&tarefa[MSG.tarefa]);
               if (err<0) { printk("Erro suspendedo a tarefa %d periodica,
err= %i\n",MSG.tarefa,err);} else {printk("Sucesso suspendendo a tarefa %d
periodica, err= %i \n",MSG.tarefa,err);}
               #endif
               count =0;
           break;
        default:
        printk("Dados errados\n");
        printk("Comando: %d, Tarefa: %d, Periodo: %d\n",
MSG.command,MSG.tarefa,MSG.period);
        return -EINVAL;

printk("Handler Comando Finalizado\n");
  return 0;
}

int init_module(void)
{
  int adstatus;
  int err;
  int c[5];

#ifdef V1
  RTIME now;
#endif

#ifdef V2
 struct sched_param sched_param;
 hrtime_t now;
#endif


#ifdef DAS1600
int base = das1601_port_base ? das1601_port_base : AD_BASE;  //Determina se
o endereco base sera o mesmo do arquivo .h
range=0x20;
if (AD_POL==0) {
 VADPP  = 10.0;}  // a placa do DAS esta ajustada para trabalhar de 0 a +10
volts 
else { 
 VADPP  = 20.0;} // a placa do DAS esta ajustada para trabalhar de -10 a
+10 volts 
#endif

#ifdef AIO
int base = AIO_port_base ? AIO_port_base : AD_BASE;        //Determina se o
endereco base sera o mesmo do arquivo .h
range=0x20;     
VADPP=5.0;       // a placa do STD trabalha de 0 a 5 volts
#endif


  if((err=init_ad(base, 0x20)) != 0 ) {         //Se o AD nao puder ser
inicializado retorna uma mensagem de erro    
    printk(KERN_INFO "I/O Address already used\n");
    printk("I/O Address already used\n");       
    return(-1);
  }

  init_ctrl(); //Inicializa as variaveis de tempo, frequencia, escala, etc.
  
  
  // Cria as FIFOs
  
  c[0] = rtf_create(0, 1000);  // y 
  c[1] = rtf_create(1, 1000);  // status ad 
  c[2] = rtf_create(2, 1000);  // parametros PID 
  c[3] = rtf_create(3, 1000);  // u
  c[4] = rtf_create(4, 1000); //comandos para o tarefa0 (lei_controle) e
para o tarefa1 (salvar_dados)

  printk("Fifo return 0=%d 1=%d 2=%d 3=%d 4=%d\n",c[0],c[1],c[2],c[3],c[4]);


 
  // Cria as threads
  
#ifdef V2
  pthread_create(&tarefa[0], NULL,lei_controle, (void *)1);
  if (err<0) { printk("Erro iniciando a tarefa 0\n");} else {printk("Tarefa
0 inicializada corretamente\n");}
  sched_param.sched_priority = 1;
  pthread_setschedparam (tarefa[0],  SCHED_FIFO, &sched_param);

  pthread_create (&tarefa[1], NULL,salvar_dados, (void *)1);
  if (err<0) { printk("Erro iniciando a tarefa 1\n");} else {printk("Tarefa
1 inicializada corretamente\n");}
  sched_param.sched_priority = 4;
  pthread_setschedparam (tarefa[1],  SCHED_FIFO, &sched_param);
 
 now = gethrtime();
 
  /* the 2 tasks run periodically with an offset of 100 time units -> Nao
entendi o comentario */
  
pthread_make_periodic_np(tarefa[0], now + 1 * NSECS_PER_SEC, RT_TICKS_CTRL);
pthread_make_periodic_np(tarefa[1], now + 2 * NSECS_PER_SEC, RT_TICKS_SAVE);


#endif

#ifdef V1

err = rt_task_init(&tarefa[0],(void *)lei_controle,1,3000,1);
if (err<0) { printk("Erro iniciando a tarefa 0\n");} else {printk("Tarefa 0
inicializada corretamente\n");}
rt_task_init(&tarefa[1],(void *)salvar_dados,1,3000,4);
if (err<0) { printk("Erro iniciando a tarefa 1\n");} else {printk("Tarefa 1
inicializada corretamente\n");}

//printk("Tarefas inicializadas\n");

now = rt_get_time(); 

  /* the 2 tasks run periodically with an offset of 100 time units */

err=rt_task_make_periodic(&tarefa[0], now,120000);
if (err<0) { printk("Erro fazendo a tarefa 0 periodica\n");} else
{printk("Sucesso fazendo a tarefa 0 periodica\n");}
rt_task_make_periodic(&tarefa[1], now + 3000,120000);
if (err<0) { printk("Erro fazendo a tarefa 1 periodica\n");} else
{printk("Sucesso fazendo a tarefa 1 periodica\n");}
#endif

  // Cria o handler de modificacao dos parametros do PID
  
err=rtf_create_handler(2,&mod_pid); //Toda vez que ha uma modificacao da
fifo 2 mod_pid eh chamada
if (err<0) { printk("Erro criando o handler 1\n");} else {printk("Sucesso
criando o handler 1\n");}  
err=rtf_create_handler(4,&comando); //A rotina comando le a fifo 4 e
determina o inicio e o fim das tarefas
if (err<0) { printk("Erro criando o handler 2\n");} else {printk("Sucesso
criando o handler 2\n");}
 
  return 0;
}

My monitor:

#include <stdio.h>
#include <errno.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <rtl_fifo.h>
#include <rtl_time.h>
#include "declaracoes.h"


#define BUFSIZE 70

char buf[BUFSIZE];
char ch;


int main()
{
  
        int fd0, fd1, ctl;
                int n;
        int i;
        int err;
        mensagens MSG;
        ch='\0';
        
        if ((fd0 = open("/dev/rtf0", O_RDONLY)) < 0) {
                fprintf(stderr, "Error opening /dev/rtf0\n");
                exit(1);
        }

        if ((fd1 = open("/dev/rtf3", O_RDONLY)) < 0) {
                fprintf(stderr, "Error opening /dev/rtf3\n");
                exit(1);
        }

        if ((ctl = open("/dev/rtf4", O_WRONLY)) < 0) {
                fprintf(stderr, "Error opening /dev/rtf4\n");
                exit(1);
        }

        /* now start the tasks */
        MSG.command = START_TASK;
        MSG.tarefa = 0;
        MSG.period = 200000;
        err = write(ctl, &MSG, sizeof(MSG));
               fprintf(stderr, "Return value to write to ctl (comand fifo,
rtf4) : %i\n", err);

        
        MSG.tarefa = 1;
        MSG.period = 400000;
        err = write(ctl, &MSG, sizeof(MSG));
                fprintf(stderr, "Return value to write to ctl (comand fifo,
rtf4) : %i\n", err);
        
        


        fprintf(stderr,"Tecle f para finalizar: ");
        while (ch != 'f') {ch = getchar();}

        fprintf(stderr, "frank_app: now sending commands to stop RT-tasks\n");

        // stop the tasks 
        MSG.command = STOP_TASK;
        MSG.tarefa = 0;
        MSG.period = 200000;
        err = write(ctl, &MSG, sizeof(MSG));
                fprintf(stderr, "Return value to write to ctl (comand fifo,
rtf4) : %i\n", err);
        
        MSG.tarefa = 1;
        MSG.period = 400000;
        err= write(ctl, &MSG, sizeof(MSG));
        fprintf(stderr, "Return value to write to ctl (comand fifo, rtf4) : %i\n",
err);
        
        return 0;
}


                                                        Thanks again,

                                                                                
Daniela.




At 08:53 AM 14/06/00 +0100, you wrote:
>
>
>Daniela Soares de Almeida schrieb:
>
>> Gabor,
>>
>> Thank you very much for your help.
>> I got initiate two periodic tasks using a comand passed trough a fifo (from
>> a linux task) but it's happening something strange. When i write to the
>> fifo in my linux task the return value is negative (like the task couldn't
>> have wrote correctly to the fifo) but when i test in my rt-linux module if
>> the commands were received they are there (with the right values!) the same
>> occurs when i test if my peridic task was initiliazed (in rt module) the
>> return vale is negative but the tasks are initialized. The program seems
>> works well but i'd like to understand better how rt-linux works so you or
>> somebody else has some idea why this occurs?
>>
>
>Its difficult to give help on this without having a look on the source.
>You should add some of the lines which are writing/ reading to/from the fifos
>
>Vasili
>
>>
>>                                                                 Thanks,
>>
>>
       Daniela.
>>
>> At 12:17 PM 09/06/00 +0200, you wrote:
>> >
>> >>      I'd like to know if it's possible to change the period of a
periodic task
>> >> running rt_make_periodic (or pthread_make_periodic_np) more than one
time
>> >> in the same module. I mean: each time my linux program write to a
fifo  a
>> >
>> >Yes, I do this.
>> >Several times I call pthread_make_periodic_np() in order to specify
>> >when the task have to return from the following rt_task_delay().
>> >
>> >> handler runs in my rt-module with  rt_make_periodic (or
>> >> pthread_make_periodic_np) using period values passed through the fifo
>> >> (something like frank_app running START_TASK many times, each time
with a
>> >> "msg.period" different)
>> >
>> >Regards
>> >
>> >Gabor
>> >-- [rtl] ---
>> >To unsubscribe:
>> >echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
>> >echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
>> >---
>> >For more information on Real-Time Linux see:
>> >http://www.rtlinux.org/rtlinux/
>> >
>> >
>>
>> -- [rtl] ---
>> To unsubscribe:
>> echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
>> echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
>> ---
>> For more information on Real-Time Linux see:
>> http://www.rtlinux.org/rtlinux/
>
>--
>--------------------------------------------------------------------------
>
>  SensoLogic GmbH                                voice: +49 40 529567-40
>
>  Dipl. Ing. technische Informatik
>  Vasili Goutas                                    fax: +49 40 529567-99
>
>  - Software Developer -                     internet: www.sensologic.de
>
>  Hummelsb�tteler Steindamm 78a
>  22851 Norderstedt, Germany                   Software + Sensor Systems
>
>  e-mail:   [EMAIL PROTECTED]
>  internet: http://www.sensologic.de/
>--------------------------------------------------------------------------
>
>
>-- [rtl] ---
>To unsubscribe:
>echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
>echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
>---
>For more information on Real-Time Linux see:
>http://www.rtlinux.org/rtlinux/
>
>

-- [rtl] ---
To unsubscribe:
echo "unsubscribe rtl" | mail [EMAIL PROTECTED] OR
echo "unsubscribe rtl <Your_email>" | mail [EMAIL PROTECTED]
---
For more information on Real-Time Linux see:
http://www.rtlinux.org/rtlinux/

Reply via email to