![]() These software-controlled input/outputs can be controlled from Linux user space using the GPIO Sysfs Interface (using a Linux shell directly or from within an executable), which enables you to activate a GPIO and set its state. General Purpose Input/Outputs (GPIOs) are described in detail in Chapter 6 and in my previous articles/videos. I am not suggesting that you write all of your GPIO code in kernel space, but these examples may provide inspiration for discrete tasks that you can perform in kernel space - the higher-level code can still be written in Linux user space. The first example in this article demonstrates how you can write an LKM that uses GPIOs and interrupts to achieve a faster response time than is possible in user space. Unlike Linux user space, the Linux kernel space has support for interrupts. I have demonstrated in my book that it is possible to achieve response times of about one third of a millisecond, with negligible CPU overhead, from within Linux user space by using ptreads, callback functions and sys/poll.h. This approach can appear to be inefficient (especially if you have experience of traditional embedded systems) however, these file entries are memory-mapped and the performance is sufficient for most applications. When interfacing to electronics circuits under embedded Linux you are immediately exposed to Sysfs and the use of low-level file operations. The auto-generated Doxygen documentation for these code examples is available in HTML format and PDF format. The /extras/kernel/ directories gpio_test, button, and led are the most important directories for this article. Video DemonstrationĪ short YouTube video is provided here that presents an overview of the functionality of the LKMs that are developed in this git clone There are easier ways to interface to buttons and flash LEDs but these examples introduce several concepts that are vital to more complex kernel programming tasks. Essentially, an LED is flashed at a frequency using a kernel module, which can be controlled from Linux user space. Example 3: Enhanced LED GPIO Driver: This example is used to flash an LED, which allows for a discussion on Linux kthreads.The example also introduces the use of timing in kernel code. This allows you to send data to and receive data from the LKM at run time. Example 2: Enhanced Button GPIO Driver: This example is used to introduce kobjects and a mechanism for adding your own entries to Sysfs.This example is used to test the interrupt performance. To perform this task, the concept of kernel interrupts is introduced and the use of the library of code that can be accessed using linux/gpio.h. Example 1: Button Press, LED Light: In this example an LED lights when a button is pressed - simple! (no not really).Therefore, there are three different LKMs described in this article, each with its own individual purpose and needs: This article is focused on education and training rather than a deep practical need - I believe that if you can read a button press and flash an LED then you are well on your way to interfacing to most digital devices. ![]() The BeagleBone is used as the deployment platform for this article, and while it is desirable that you use the BeagleBone in order to follow along with this article, it is not a requirement.Ĭlick for the HTML and PDF version of the auto-generated Doxygen code documentation This article describes how you can write kernel code that interfaces to custom electronics circuits that are attached to the GPIOs of a Linux embedded system, and how you can add enhanced functionality for such devices that is not available by default under embedded Linux. Such detail is not repeated in this article. Writing a Linux Kernel Module - Part 2: A Character Device,īefore moving on to this article, as those articles explain how to build, load and unload loadable kernel modules (LKMs) and character device drivers. ![]()
0 Comments
Leave a Reply. |