Tests Using '2012-09-18-wheezy-raspbian.img'

Using this code running:

	while (1)
		bcm2835_gpio_write(RPI_GPIO_P1_13, 0);
		bcm2835_gpio_write(RPI_GPIO_P1_13, 1);

Running the application at the command prompt (no GUI) gave this on the pin:

i.e. no significant process interruptions.

Running the application inside the GUI (startx) with nothing else specific happening gave this:

Very occasional process interruptions.

Now starting the Midori browser to make the RPi busy gave this:

This remained until the browser was fully loaded at which point the pin output returned to the previous state.


Good applications tell the linux scheduler when they are happy to be halted so another process can be run.  The scheduler is a complex beast but we have found that simply using delayMicroseconds(10) say in your programs main loop is enough to give the scheduler an opportunity to run another process and avoid it letting the your application run but periodically halt it for a significantly longer time for many other processes to be run before handing execution back to your application.  If your application needs constant fast monitoring of inputs or control of outputs then including this can help reduce the length of time your application is halted, assuming no other heavy process runs in the system (in which case you are stuffed as the scheduler will decide how to split running time between you and the other process – e.g. switching every 10mS in the Midori startup test above).  

Guaranteeing a slice of time for critical IO operations

Another approach if you need to know you are not going to be interrupted by the scheduler, for instance say you want to generate RC servo PWM signals using GPIO pins, could be to just ensure you limit your operations to less than 10mS before calling delayMicroseconds() letting the scheduler know you are happy to sleep.  This way you limit the maximum time your process needs to run before interruption to below the schedulers maximum time (often 10mS) and just accept that you don't know how long it will be before you get another slice of time, but at which point you are as sure as you can be that you will get the next block of time you need to complete another set of your IO operations.  We've not tried this, but it seems like an approach that could work well to overcome some of the real time issues of working on top of an OS and its scheduler – 10mS is a lot of time to get IO operations done.

We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published. Required fields are marked *