Hi all,

I got a problem when I upgrade the driver for ServoToGo board.

This driver works fine under RH 6.0, Linux Kernel 2.2.13, RTLinux 2.0. I
just change the path and compile it under RH 7.0, Linux Kernel 2.2.18,
RTLinux 3.0. It compiles fine, but when I want to insmod the driver, the
system will freeze. I found out the problem is coming from the function:
pthread_make_periodic_np(pthread_t thread, hrtime_t start_time, hrtime_t
period), when I change the period to a bigger value, the system will be
able to work for a while, but then freeze too. The bigger value I set to
period, the longer the system can work fine. I am totally confused,
what's wrong with the code.

Please give me some help on my problem!

Thanks in advance!
Hai Xu

ps The following is part of the code:

// This is the RT-Linux server thread
void *mainLoop(void *t)
{
        while(1)
        {
                pthread_wait_np();
                server->doMessageLoop();
        }
}

int init_module(void)
{
        int period;
        pthread_attr_t threadAttributes;
        struct sched_param schedulingParameters;
        int retval;

        sprintf(usageShmName, "%s_Usage", name);
        numOfUsage = (int *)shmmgnt_k_create(usageShmName, sizeof(int));

        if(!numOfUsage)
        {
                printk("servo2go: Error creating shared memory for usage
counter!\n");
                return(1);
        }
        *numOfUsage = 0;

        printk("servo2go: Setting up STGServer...\n");

        server = (STGServer *)kmalloc(sizeof(STGServer), GFP_KERNEL);

        if(!server)
        {
                printk("Cannot allocate memory for I/O Board
Server!\n");
                shmmgnt_k_delete(usageShmName);
                return 1;
        }

        new (server) STGServer(0, 0, 0, frequency, 0, numAdc, numDac,
                        numEncoders, portADirection, portBDirection,
portCDirection,
                        portDDirection, name, 0, boardIndex, irq,
adcRange, useAdcIrq);

        if(server->isStatusError())
        {
                printk("servo2go: Error setting up server\n");
                // We need to call the destructor because a derived
class constructor
                // may have failed after a base class constructor
allocated resources
                goto EXIT;
        }

        if( frequency == 0 )
        {
                printk("frequency cannot be zero! Changed to 1kHz!\n");
                frequency = 1000;
        }

        period = HRTICKS_PER_SEC / frequency;

        // Set up to run the RT thread
        printk("servo2go: Starting server thread...");
        pthread_attr_init(&threadAttributes);
        schedulingParameters.sched_priority = 99;
        pthread_attr_setschedparam(&threadAttributes,
&schedulingParameters);
        pthread_attr_setstacksize(&threadAttributes, 32000);
        pthread_create(&ourThread, &threadAttributes, mainLoop, (void *)
1);
        printk("thread ID is 0x%X\n", ourThread);
        pthread_setfp_np(ourThread, 1);
        retval = pthread_make_periodic_np(ourThread, gethrtime(), period
);

        if( retval )
        {
                printk("Can not start I/O Board Server!\n");
                goto EXIT;
        }

        return 0;

EXIT:
        shmmgnt_k_delete(usageShmName);
        server->~STGServer();
        kfree(server);
        return 1;
}

void cleanup_module(void)
{
        // Kill the server thread
        pthread_delete_np(ourThread);

        // Destroy the server object
        server->~STGServer();

        // Check the usage count.  We can't prevent unloading, but we
can complain.
        if(*numOfUsage)
                printk("servo2go: Server %s is exiting, but is in use by
%d client(s)!\n",
                                name, *numOfUsage);

        shmmgnt_k_delete(usageShmName);
        kfree(server);
        printk("servo2go: Server stopped sucessfully\n");
}
}



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

Reply via email to