Xunwei 4412 Development Board-Experimental LEDS Driver One

14.1 Introduction to
this chapter This section of the experiment introduces a complete GPIO driver.  You can imitate or transplant this driver if you need to deal with the GPIO driver in  Linux
.
14.1.1 Tools
14.1.1.1 Hardware tools
1) iTOP4412 development board
2) U disk or TF card
3) PC
4) serial port
14.1.1.1.2 software tools
1) virtual machine Vmware
2) Ubuntu 12.04.2
3) HyperTerminal (serial port Assistant)
4) Source code folder “leds”
14.1.2 Preliminary course
Experiment
12_Physical address virtual address Experiment 13_GPIO initialization
14.1.3 Video resources
The video resource for this section is “Video 14  LED S Driver One”
14.2 Learning Objectives
This chapter needs to learn the following Content:
Led hardware principle briefly introduces
the call, assignment and configuration of
LED pins. Write a simple application to call LED pins and test.
14.3 Led hardware principle briefly introduces the
Led circuit is relatively simple, generally using a triodeBuild a control circuit.
As shown in the figure below, it is the control circuit of two LEDs in the schematic diagram. KP_COL0 and VDD50_EN network control the on and off of the LED.

As shown in FIG.
When the KP_COL0 and VDD50_EN networks are at high level, the BE of the transistor L9014 is turned on, and the CE is turned on. The VSYS voltage equivalent to 5V is  added to the 1K and Led lights, and the lights will light.
When the KP_COL0 and VDD50_EN networks are at low level, the BE of the transistor L9014 will be cut off, and the CE will be cut off. The VSYS voltage equivalent to 5V is applied to the 1K, Led small lamp and an infinite resistor . The current is zero and the small lamp is Will go out.
14.4 Calling, Assignment and Configuration of Led Pins
This section introduces some functions related to GPIO call, assignment and configuration.
14.4.1 GPIO application and release function If
you want to use any GPIO, you must apply first.
There is Linux default GPIO application function in the header file "include/linux/gpio.h". This header file belongs to the embedded  Linux platform, and any embedded Linux kernel can be used in this way.
As shown in the figure below, use the command "vim include/linux/gpio.h" in the source directory to open the file.

As shown in the figure below, it is the function gpio_request that needs to be used in this section of the experiment.

As shown in the figure above, briefly introduce the gpio_request function.
First of all, this function has an important "detection" function, that is, if the IO is applied for in other places, then an error will be returned here, indicating that it has been occupied. This is a standard usage in Linux.
The gpio_request function has two parameters
unsigned gpio. The GPIO applied for is usually the macro definition
const char *label corresponding to the GPIO
. Give the GPIO a name for easy reading . As shown in the figure below, the gpio_request function corresponds to the gpio_free function.

After calling the gpio_request function, it indicates to the system that the IO has been occupied, and generally needs to call the gpio_free function to release it when the driver is uninstalled.
The parameters of the gpio_free function are relatively simple. There is only one GPIO parameter, and you can use the macro definition corresponding to GPIO.
As shown in the figure below, there is also an assignment function gpio_set_value.

After configuring the GPIO to output mode, you also need to assign values ​​to the GPIO, which are generally high level and low level.
The two parameters are
unsigned gpio, GPIO
int value, high level 1 and low level 0.
14.4.2 GPIO configuration parameter macro definition
GPIO is initialized in Linux, after mapping, calling GPIO operation function to operate GPIO macro definition is to operate GPIO.
This GPIO macro definition file is provided by the original manufacturer, and it must have been completed and belongs to the BSP board-level development kit.
As shown in the figure below, use the command in the source directory
"Vim arch/arm/mach-exynos/include/mach/gpio-exynos4.h" to open the file.

As shown in the figure below, you can see that all GPIOs have been defined.

Find the KP_COL0, VDD50_EN network in the schematic diagram, and the final part connected to 4412 is shown in the figure below.

As shown in the figure above, the macro definitions of the two Leds are EXYNOS4_GPL2(0), EXYNOS4_GPK1(1).
14.4.3 GPIO configuration functions and parameters
In Linux, GPIO configuration functions and parameters have been integrated into the Samsung board-level development kit.
First look at the configuration function, as shown in the figure below, use the command
"vim arch/arm/plat-samsung/include/plat/gpio-cfg.h" in the source directory to open the file.

As shown in the figure below, the s3c_gpio_cfgpin function is required for the experiment in this section.

As shown in the figure above, the function extern int s3c_gpio_cfgpin(unsigned int pin, unsigned int to);
generally speaking, the function with s3cxxx is the function that can be used by Samsung platform.
The s3c_gpio_cfgpin pin configuration function has two parameters:
parameter unsigned int pin, pin
parameter unsigned int to, configuration parameter.
Look at the configuration parameters again, as shown in the figure below, use the command in the source code directory
"Vim arch/arm/plat-samsung/include/plat/gpio-cfg.h" to open the file, the configuration parameters and functions are in the same function.

As shown in the figure below, GPIO needs to be configured as output mode, which corresponds to the S3C_GPIO_OUTPUT macro definition.

14.5 Write a simple application to call LED pins, and test
Add code to the previous devicenode_linux_module.c file, first change the file name devicenode_linux_module.c to leds.c.
First deal with the compiled file Makefile, as shown in the figure below, change devicenode_linux_module to leds.

Then modify the leds.c file.
First add the required header files, as shown in the figure below, which are the header files for GPIO, configuration functions, configuration parameters, GPIO macro definitions, etc. Then change the device node name from hello_ctl123 to hello_ctl

and the probe function needs to be modified. Generally speaking, the initialization of GPIO is in the probe. As shown in the figure below, call the configuration function and the configuration function.

Then it is to modify the ioctl function. The control of GPIO in Linux generally uses ioctl. Although the write function can also achieve similar functions, the ioctl function is more efficient. As shown in the figure below, assign values ​​to GPIO according to the parameters passed in by the application.

As shown in the figure above, first make a simple judgment on the parameters, and then assign values ​​to the leds.
Then look at the application. As shown in the figure below, the application is relatively simple. Call the delay function. First, light the LED for three seconds, then turn it off for three seconds, and then light it up.

Create a new leds folder under the Ubuntu system, copy the written leds and compilation script to the leds folder, use the Makefile command to compile the driver, and use
"arm-none-linux-gnueabi-gcc -o invoke_leds invoke_leds.c -static" Command to compile the application. As shown in

the figure below, copy the files invoke_leds and leds.ko in the figure above to a USB flash drive.
Start the development board, insert the U disk into the development board, use the command "mount /dev/sda1 /mnt/udisk/" to load the U disk character,
use the command "insmod /mnt/udisk/leds.ko" to load the driver leds.ko,
use The command "./mnt/udisk/invoke_leds" runs the small application invoke_leds, as shown in the figure below.

After the above operation, it can be observed that the small led lights will turn on and off, with an interval of about three seconds.

Guess you like

Origin blog.csdn.net/mucheni/article/details/112220041