Introduction to various port operation functions of S3C2440

Publisher:平安心境Latest update time:2024-08-09 Source: cnblogsKeywords:S3C2440 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

micro2440 uses the S3C2440 processor (which is not much different from the S3C2410). In its Linux source code, the code related to this platform is mainly in arch/arm/mach-s3c2410 and include/asm-arm/arch-s3c2410, and the related drivers are in the drivers directory.



(1) DM9000 network card driver
kernel-2.6.13/drivers/net/dm9000x.c
(2) Serial port (including three serial port drivers 0, 1, 2, corresponding to the device name /dev/tts/0, 1, 2)
kernel-2.6.13/drivers/serial/s3c2410.c
(3) Real-time clock RTC driver
kernel-2.6.13/drivers/char/s3c2410-rtc.c
(4) LED driver
kernel-2.6.13/drivers/char/qq2440_leds.c
(5) Button driver
kernel-2.6.13/drivers/char/qq2440_buttons.c
(6) Touch screen driver
kernel-2.6.13/drivers/input/touchscreen/s3c2410_ts.c
(7) Yaffs file system source code directory
kernel-2.6.13/fs/yaffs2
(8) USB mouse, keyboard source code
kernel-2.6.13/drivers/usb/input/hid-input.c
(9) SD/MMC card driver source code directory (in the 2.6.13 kernel, only SD cards with a capacity of less than 2G are supported)
kernel-2.6.13/drivers/mmc
(10) NandFlash driver
kernel-2.6.13/drivers/mtd/nand
(11) UDA1341 audio driver directory
kernel-2.6.13/sound/oss/uda1341.c
kernel-2.6.13/ drivers/l3
(12) LCD driver (including drivers of sizes of 3.5", 7", 8.4", 10.4", 12.4", 15")
kernel-2.6.13/drivers/video/s3c2410fb.c
(13) USB support driver
kernel-2.6.13/drivers/usb/storage
(14) Vimicro USB camera driver
kernel-2.6.13/drivers/usb/media/gspca



1.S3C2410_GPB5 is the port number, defined in regs-gpio.h,

#define S3C2410_GPIO_BANKB   (32*1)
#defineS3C2410_GPIONO(bank,offset)   ((bank) + (offset))
#defineS3C2410_GPB5        S3C2410_GPIONO(S3C2410_GPIO_BANKB, 5)

S3C2410 has a total of 130 GPIOs, divided into 9 groups (GPA~GPJ), each group can have up to 32, each GPIO has 2~4 optional functions, and each group has 4 control register spaces. For example, for GPB, there are GPBCON, GPBDAT, GPBUP and Reserved, which are function configuration, data cache, pull-up enable and reservation respectively.

The S3C2410_GPB5 above is the GPIO number, that is, the position in the number space (0~32*9-1), bank is the base number of the group, and offset is the offset within the group.



2.S3C2410_GPB5_OUTP is the port function, defined in regs-gpio.h,

#define S3C2410_GPB5_INP     (0x00 <<10)
#define S3C2410_GPB5_OUTP    (0x01 <<10)

The 10th and 11th bits of GPBCON are used to configure the function of GPB5, 00 = Input, 01 = Output

3.S3C2410 GPIO operation functions

In the hardware.h file, there are:

s3c2410_gpio_cfgpin //Configure the GPIO function of the port
s3c2410_gpio_getcfg //Read function configuration
s3c2410_gpio_pullup //Configure the pull-up resistor
s3c2410_modify_misccr //Miscellaneous configuration

s3c2410_gpio_getirq //Given the port, convert the IRQ number
s3c2410_gpio_irqfilter //Configure whether IRQ filtering is enabled

s3c2410_gpio_setpin //Write data to the port
s3c2410_gpio_getpin //Read data from the port

The implementation of these functions is in gpio.h

void s3c2410_gpio_setpin(unsigned int pin, unsigned intto)
{
void __iomem *base = S3C2410_GPIO_BASE(pin);
unsignedlong offs = S3C2410_GPIO_OFFSET(pin);
unsigned longflags;
unsigned long dat;

local_irq_save(flags);

dat = __raw_readl(base + 0x04);
dat &= ~(1 < dat |= to << offs;
__raw_writel(dat, base +0x04);

local_irq_restore(flags);
}

(My own understanding: dat = __raw_readl(base + 0x04); dat &= ~(1 << offs); dat |= to<< offs; For example, if the operation is on port 5, these sentences can ensure that other ports maintain their original values, and only the value of port 5 changes)



4.S3C2410_GPIO_BASE and S3C2410_GPIO_OFFSET are also defined in the regs-gpio.h file.

#define S3C2410_GPIO_BASE(pin)      ((((pin) & ~31) >> 1) + S3C24XX_VA_GPIO)
#defineS3C2410_GPIO_OFFSET(pin)   ((pin) & 31)

And in map.h there is:


#define S3C24XX_VA_GPIO S3C2410_ADDR(0x00E00000) //Virtual address S3C24XX_VA_GPIO=0xF0E00000
#define S3C2400_PA_GPIO (0x15600000)
#define S3C2410_PA_GPIO (0x56000000) //GPACON physical address
#defineS3C24XX_SZ_GPIO SZ_1M //0x100000 = 1024 *1024

The function of S3C2410_GPIO_BASE is to calculate the virtual base address of the group where the port belongs according to the port number pin. ((pin)&~31) removes the decimals less than or equal to 31 in the pin (clear the lower 5 bits to 0). The reason for >>1 is that there can be up to 32 ports in each GPIO group. Controlling these ports requires 4 register spaces, and 4 register spaces require 4*4=16 bytes for addressing. 32/16=2, which is just enough to shift left by one bit. In other words, the number difference between the previous group of ports and the next group of ports is 32, while the address difference of the control register is 16. (My own understanding: Because each GPIO port corresponds to 4 registers, each register is 32 bits, S3C2410_GPIO_BASE only calculates the virtual base address, no matter which specific port, 2 to the fifth power is exactly 32, ((pin)&~31) can mask the lower five bits, and the right shift is because the number of ports does not exceed 32. Each GPIO port corresponds to 4 registers, each register is 32 bits, 4*32/8=16=0x10, for example, GPIOA=0X10+S3C24XX_VA_GPIO, GPIOB=0X20+S3C24XX_VA_GPIO, the number of numbers represented by 0x10 exceeds 32)

The function of S3C2410_GPIO_OFFSET is to calculate the offset of the group to which the port belongs according to the port number pin. ((pin)& 31) means to remove the number greater than 31 (clear the bits above the 6th bit to 0).



5. __raw_readl和__raw_writel

Linux's I/O operations are defined in asm/io.h, and on the ARM platform, they are in asm-arm/io.h.

#define __raw_readl(a)   (__chk_io_ptr(a), *(volatileunsigned int __force   *)(a))
#define __raw_writel(v,a)(__chk_io_ptr(a), *(volatile unsigned int __force   *)(a)= (v))

In includelinuxcompiler.h:

#ifdef __CHECKER__
……
extern void __chk_io_ptr(void__iomem *);
#else
……
# define __chk_io_ptr(x)(void)0
……
#endif

__raw_readl(a) is expanded to: ((void)0,*(volatile unsigned int _force*)(a)). When __CHECKER__ is defined, __chk_io_ptr is called first to check the address, otherwise __chk_io_ptr does nothing, and *(volatileunsigned int _force*)(a) returns the value at address a. The (void)xx approach is sometimes useful, for example, when the compiler turns on checking for unused parameters, it is necessary to do this to get the unused parameters to pass the compilation.

There are two ways to program the physical address of I/O in the CPU: one is I/O mapping, and the other is memory mapping. __raw_readl and __raw_writel are the original methods of operating I/O, and the derived operation methods are: inb, outb, _memcpy_fromio, readb, writeb, ioread8, iowrite8, etc.



6.local_irq_save和local_irq_restore

Disabling and enabling interrupts are defined in asm-arm/system.h.

#define local_irq_save(x)
({
__asm____volatile__(
"mrs %0,cpsr   @ local_irq_saven"
"cpsid i"
: "=r" (x) : : "memory", "cc");
})

#define local_irq_save(x)
({
unsigned long temp;
(void)(&temp == &x);
__asm____volatile__(
"mrs %0,cpsr   @ local_irq_saven"
" orr %1, %0,#128n"
" msr cpsr_c,%1"
: "=r" (x),"=r" (temp)
:
: "memory", "cc");
})


Keywords:S3C2440 Reference address:Introduction to various port operation functions of S3C2440

Previous article:Ubuntu 12.04 embedded cross-compilation environment arm-linux-gcc construction process diagram
Next article:s3c2410_gpio_setpin() and other functions

Recommended ReadingLatest update time:2024-11-15 12:57

S3c2440 I2C driver and test program trace cross analysis
VMware virtual machine + Fedora10, hardware platform TQ2440, kernel 2.6.30.4 Recently I learned about the linux I2C driver and used teacher Liu Hongtao's test program to test the kernel's built-in driver. After turning on the debugging statement dev_dbg (refer to my other blog for details), I found that the driver cor
[Microcontroller]
s3c2440 bare metal - code relocation (1. Introduction of relocation, why code relocation is needed)
1. Introduction of relocation (why code relocation is needed) We know that the CPU of s3c2440 starts fetching instructions from address 0 and executes them. When starting from nor, address 0 corresponds to nor. Nor can be read like memory, but cannot be written like memory. We can fetch instructions from nor and execu
[Microcontroller]
s3c2440 bare metal - code relocation (1. Introduction of relocation, why code relocation is needed)
Some details of the differences between s3c2410 and s3c2440
Both socs are arm920, cpuid is 0x41129200, and many register settings are the same, but if you want to directly use the bootloader and kernel of 2410 on 2440, it will definitely go wrong. There are many articles like this on the Internet, most of which only mention macro aspects, such as camera driver, main frequency,
[Microcontroller]
Application and calibration of touch screen of s3c2440
Touch screen is the most popular human-computer interaction interface today. It is widely used in consumer electronic products such as mobile phones. At present, this technology has a trend of developing towards PCs. Based on different principles, touch screens can be divided into resistive, capacitive, surface acousti
[Microcontroller]
Application and calibration of touch screen of s3c2440
S3C2440 uses C language to light up LED
1. From assembly to C function 1. Set up the stack Why do we need to set up a stack when calling a C function from an assembly? 1. Because the parameters of the arm assembly call to a C function must follow the APCS rule. That is, if the number of parameters is less than or equal to 4, R0-R3 can be u
[Microcontroller]
S3C2440 uses C language to light up LED
S3c2440 bus frequency and clock settings in LINUX
The normal operation of many hardware requires the support of bus clock, such as LCD, I2C and other devices. This article analyzes the bus clock of s3c2440 and the related operations of s3c2440 bus clock frequency in Linux. First, analyze the bus clock of hardware s3c2440. 1. FCLK HCLK PCLK of s3c2440: The clock s
[Microcontroller]
s3c2440 bare metal - abnormal interrupt 5 - irq timer interrupt
I have talked about the s3c2440 clock system before. After looking at the clock system and then looking at the timer interrupt, it will be better to combine and apply the knowledge points learned. S3c2440 has 2 types of timers: 1.Watchdog watchdog timer 2.PWM pulse modulated timer The following is a deta
[Microcontroller]
s3c2440 bare metal-nandflash programming (2. nand controller and nand access timing)
1.Steppingstone We know that nand does not have an independent address line, and the CPU cannot directly access the instructions on nand, so nand cannot be executed on-chip. So why does the program still support nand startup? To support NAND boot, the S3C2440A is equipped with an internal SRAM buffer called "Steppin
[Microcontroller]
s3c2440 bare metal-nandflash programming (2. nand controller and nand access timing)
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号