Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C linux programming question

  • 16-04-2009 11:46pm
    #1
    Registered Users, Registered Users 2 Posts: 3,945 ✭✭✭


    I'm currently writing a program for linux that runs on a development board. One of the programs interfaces to an LCD thats on the board. My problem is the timing is all skewed because of context switches (I think) while the timer function is running.

    As in, I have 7-8 functions (LCDInit, LCDClearScreen etc) that write different values to a register and pause between each write to get the correct signal timing.

    Initially I was using usleep() and nanosleep() but these arent accurate enough and usually add on 10-20 ms more than what I need. So now I'm using one of the timers on the board. I can't use its interrupt because the kernel isn't in charge of its operation and I think it will probably cause a crash if I do. So the timer is polled until it has counted to the right value.

    This isn't ideal but the times are quite small (>2 ms max) so its not hogging to much cpu(50mhz). My question is, is there any way of blocking the kernel from switching whilst in a function? I remember there was a way in another OS I was using where you could turn off the scheduler/interrupts.

    Any help would be great, thanks.


Comments

  • Registered Users, Registered Users 2 Posts: 40,038 ✭✭✭✭Sparks


    Blocking a context switch from a userspace program in linux? No, you have to be in kernel mode for that. If you're in kernel mode, a udelay() or mdelay() call will sit there without switching, but 2ms is a long time for a CPU, just sitting there would be suboptimal. You're much better off using a kernel timer instead (that way your function gets called when you specify, rather than when the scheduler specifies, within limits - Linux doesn't really do hard realtime stuff that well, though some variations take a good stab at it, usually by having another OS run Linux as a task and letting kernel-level linux stuff talk to the underlying OS... which is a bit complicated :) ). Have you read Linux Device Drivers yet? Chapter 6 covers what you need.


Advertisement