Hi!

My name is Marcus and i wonder over somthing strange. I have a program
that more or less looks below.
My question now is why must i use global variables?? If i put "utdata3"
after "void start_routine(...)" (localy) then the varible doesn't work
properly. I use utdata3 in the function WriteDig2 which sends the data
to a ISA-card (and then a couple of lamps falshes realy nice). But if I
rmmods the program and then starts it again (insmod) then utdata3 isnt
equal 127, but instead it has the same value it had when I removed the
module. The solution to this problem was to put the variables outside
"start_routine" (globaly). Anouther soultion (a strange one): I could
see on the lamps that the old values from before were being used, but if
I used a rtl_printf and printet the value of variable, then I got the
new-initilized value! (printed value was correct and the lamps also
worked as they should)

Can't I use local variables if I want to be sure that their next
initialization after a rmmod followed by a insmod are correct?

--------------------------------------------------------------------------------------

#include....

pthread_t thread;

char utdata3=127;
int tid = 1000; //antal microsekunder
int k=0;

void start_routine(void) {

     pthread_make_periodic_np(pthread_self(),gethrtime(),tid*1000);

     while (1) {
           pthread_wait_np ();
           if (k>1000) {
                k=0;
               if (utdata3 <1)
                   utdata3 = 127;
               utdata3--;
               WriteDig2(1,2,utdata3);
           }
           k++;
     }
}

int init_module(void) {
 return pthread_create (&thread, NULL, start_routine, 0);
}

void cleanup_module(void) {
 pthread_delete_np (thread);
}
--------------------------------------------------------------------------------------------

-- [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