AM335x Linux定时器实现原理及应用 (am335x linux 定时器)

随着物联网技术的发展,越来越多的设备需要实现定时功能来保障设备运行的稳定性和精确度。针对这一需求,AM335x推出了Linux定时器,该定时器可以在设备启动时自主启动,实现多种定时功能。本文将介绍AM335x Linux定时器的原理、应用以及配置方法。

一、AM335x Linux定时器原理

AM335x Linux定时器是一种高精度的定时器,在Linux内核中的响应中断子系统中实现。它具有支持多个中断源的能力、高精度的时钟源以及灵活的计时周期设置。在Linux内核启动时,定时器会自主启动开始计时,计时周期可根据应用需求进行设置。当计时器达到指定时间时,即时触发中断并执行设定中的中断服务程序。

定时器的核心是周期性中断服务程序,它在定时器计时周期内执行,实现设备的保护和控制。周期性中断服务程序在代码中被定义为中断处理函数,其主要功能是响应定时器中断并执行响应动作的代码。该功能需要结合设备的特性和细节进行实现。

在AM335x Linux定时器中,中断处理函数主要包括设备寄存器的读写、寄存器状态设置等操作。通过对中断处理函数的定制,可以实现设备对特定事件的响应,满足设备各项要求。同时,委派其他的设备或模块协同工作,实现设备的高效独立运行,提高设备的性能和可靠性。

二、AM335x Linux定时器应用

AM335x Linux定时器应用广泛,它可以用于多种应用场景。以下介绍几种常见的应用情况:

1. 定时轮询系统:该应用用于轮询状态和周期操作。通过定时器信号实现轮询操作,定时器的周期长度根据轮询的时间间隔和设备特性确定。该应用通常用于网络协议通信、进程同步等场景。

2. 定时触发事件:该应用用于设备控制,定时器在设定的时间点执行中断处理函数,触发设备对特定事件的响应。该应用通常用于实现设备启动保护、任务调度、数据输出等场景。

3. 定时采集数据:该应用用于统计数据和信号采集。设定定时器周期为采样周期,通过定时器信号触发信号采集和数据处理。该应用通常用于仪器仪表、传感器信号采集等场景。

不同应用场景的需求不同,需要根据具体场景和设备要求进行周期性和事件性等不同类型的定时器实现。

三、AM335x Linux定时器配置

AM335x Linux定时器提供了一套API进行配置。应用程序可以使用此API进行计时器配置和中断服务程序定义。以下是常见的常用API:

1. 配置定时器周期

在设备驱动函数中添加以下代码行,将计时周期设定为10毫秒:

“`

static struct timer_list my_timer;

my_timer.expires = jiffies + HZ/100;

“`

2. 注册中断服务程序

在设备初始化函数中注册相应的中断处理函数:

“`

int timer_irq_setup(int irq, irq_handler_t handler, unsigned long flags);

ret = request_irq(IRQ_TIMER, my_timer_handler, IRQF_TRIGGER_HIGH, “my_timer_handler”, NULL);

“`

3. 定义中断处理函数

中断处理函数的主要功能是设定定时器状态和控制寄存器。以下是一个简单的中断处理函数实现,修改了计时器中的count值并输出当前数值:

“`

void my_timer_handler(unsigned long arg)

{

static int count = 0;

printk(KERN_INFO “\n timer interrupt %d”, count++);

mytimer.expires = jiffies + HZ/100;

add_timer(&mytimer);

}

“`

四、

AM335x Linux定时器是一种多功能定时器,它实现了高性能定时和灵活性设置。根据应用不同需求,可以通过API配置定时器周期、注册中断服务程序以及定义中断处理函数等方式进行实际应用。定时器的精确度和周期性可以大大提高设备的稳定性和可靠性,特别是对于实时设备,具有重要意义。

相关问题拓展阅读:

请教am335x 双网口配置的问题

,自己御乎做的板子 双网口,broadcom50610 phy芯片,在 sdk-07.00.00.00之前的版本中,即3.2内核中销扮,使用都正常,在新版本(linux 3.12.10)中怎么配置都有问题,亏拆灶请教各位大侠!

从外面ping 板子显示:

From 192.168.10.105 icmp_seq=1 Destination Host Unreachable

From 192.168.10.105 icmp_seq=2 Destination Host Unreachable

From 192.168.10.105 icmp_seq=3 Destination Host Unreachable

From 192.168.10.105 icmp_seq=5 Destination Host Unreachable

From 192.168.10.105 icmp_seq=6 Destination Host Unreachable

From 192.168.10.105 icmp_seq=7 Destination Host Unreachable

From 192.168.10.105 icmp_seq=9 Destination Host Unreachable

From 192.168.10.105 icmp_seq=10 Destination Host Unreachable

启动信息

U-Boot SPL 2023.g78d8ebd-dirty (Sep:24:57)

Could not probe the EEPROM; something fundamentally wrong on the I2C bus.

Could not get board ID.

reading args

spl: error reading image args, err – -1

reading u-boot.img

reading u-boot.img

U-Boot 2023.g78d8ebd-dirty (Sep:24:57)

I2C: ready

DRAM: 256 MiB

NAND: 0 MiB

MMC: OMAP SD/MMC: 0, OMAP SD/MMC: 1

*** Error – No Valid Environment Area found

*** Warning – bad CRC, using default environment

Net: not set. Validating first E-fuse MAC

Could not get PHY for cpsw: addr 18

cpsw, u_ether

Hit any key to stop autoboot: 0

mmc0 is current device

Scanning mmc 0…

bytes read in 264 ms (14.9 MiB/s)

33206 bytes read in 24 ms (1.3 MiB/s)

mmc0 is current device

SD/MMC found on device 0

reading uEnv.txt

674 bytes read in 3 ms (218.8 KiB/s)

Loaded environment from uEnv.txt

Importing environment from mmc …

Running uenvcmd …

reading uImage

bytes read in 245 ms (15.9 MiB/s)

reading am335x-bone.dtb

35525 bytes read in 7 ms (4.8 MiB/s)

## Booting kernel from Legacy Image at…

Image Name: Linux-3.12.10-rt21-ti2023.12.01

Image Type: ARM Linux Kernel Image (uncompressed)

Data Size:Bytes = 3.9 MiB

Load Address:

Entry Point:

Verifying Checksum … OK

## Flattened Device Tree blob at 80f80000

Booting using the fdt blob at 0x80f80000

Loading Kernel Image … OK

Loading Device Tree to 8f320230, end 8f32bac4 … OK

Starting kernel …

Booting Linux on physical CPU 0x0

Linux version 3.12.10-rt21-ti2023.12.01 (wu@robot) (gcc version 4.7.(prerelease) (crosstool-NG5

CPU: ARMv7 Processor revision 2 (ARMv7), cr=10c53c7d

CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache

Machine: Generic AM33XX (Flattened Device Tree), model: TI AM335x BeagleBone

cma: CMA: reserved 24 MiB at 8d800000

Memory policy: ECC disabled, Data cache writeback

CPU: All CPU(s) started in SVC mode.

AM335X ES2.1 (sgx neon )

Built 1 zonelists in Zone order, mobility grouping on. Total pages: 64256

Kernel command line: console=ttyO0,115200n8 root=/dev/mmcblk0p2 rw rootfstype=ext4 rootwait ip=off login=0

PID hash table entries: 1024 (order: 0, 4096 bytes)

Dentry cache hash table entries:(order: 5,bytes)

Inode-cache hash table entries:(order: 4,bytes)

Memory:K/259072K available (5539K kernel code, 560K rwdata, 1812K rodata, 343K init, 252K bss, 355)

Virtual kernel memory layout:

vector : 0xffffxffff1000 ( 4 kB)

fixmap : 0xfffxfffe0000 ( 896 kB)

vmalloc : 0xdxff( 744 MB)

lowmem : 0xcxd( 256 MB)

pkmap : 0xbfexc( 2 MB)

modules : 0xbfxbfe00000 ( 14 MB)

.text : 0xcxc073604c (7353 kB)

.init : 0xcxc078ce50 ( 344 kB)

.data : 0xc078exc081a0b0 ( 561 kB)

.bss : 0xc081a0bc – 0xc( 253 kB)

SLUB: HWalign=64, Order=0-3, MinObjects=0, CPUs=1, Nodes=1

Preemptible hierarchical RCU implementation.

NR_IRQS:16 nr_irqs:16 16

IRQ: Found an INTC at 0xfa(revision 5.0) with 128 interrupts

Total of 128 interrupts on 1 active controller

OMAP clockevent source: timer2 atHz

sched_clock: 32 bits at 24MHz, resolution 41ns, wraps everyms

OMAP clocksource: timer1 atHz

Console: colour dummy device 80×30

Calibrating delay loop… 531.66 BogoMIPS (lpj=)

pid_max: default:minimum: 301

Security Framework initialized

Mount-cache hash table entries: 512

CPU: Testing write buffer coherency: ok

Setting up static identity map for 0xc056exc056e7e8

devtmpfs: initialized

VFP support v0.3: implementor 41 architecture 3 part 30 variant c rev 3

omap_hwmod: debugss: _wait_target_disable failed

pinctrl core: initialized pinctrl subsystem

regulator-dummy: no parameters

NET: Registered protocol family 16

DMA: preallocated 256 KiB pool for atomic coherent allocations

cpuidle: using governor ladder

cpuidle: using governor menu

platform mpu.1: FIXME: clock-name ‘fck’ DOES NOT exist in dt!

platform.edma: FIXME: clock-name ‘fck’ DOES NOT exist in dt!

OMAP GPIO hardware version 0.1

platform.sgx: FIXME: clock-name ‘fck’ DOES NOT exist in dt!

DSS not supported on this SoC

No ATAGs?

hw-breakpoint: debug architecture 0x4 unsupported.

bio: create slab at 0

edma-dma-engine edma-dma-engine.0: TI EDMA DMA engine driver

vmmcsd_fixed: 3300 mV

netpower_fixed: no parameters

netphyreset_fixed: no parameters

ledpower_fixed: no parameters

vgaarb: loaded

SCSI subsystem initialized

ucore: registered new interface driver ufs

ucore: registered new interface driver hub

ucore: registered new device driver u

omap_i2c 44e0b000.i2c: could not find pctldev for node /pinmux@44e10800/pinmux_i2c0_pins, deferring probe

platform 44e0b000.i2c: Driver omap_i2c requests probe deferral

pps_core: LinuxPPS API ver. 1 registered

pps_core: Software ver. 5.3.6 – CopyrightRodolfo Giometti

PTP clock support registered

Switched to clocksource timer1

NET: Registered protocol family 2

TCP established hash table entries: 2023 (order: 2,bytes)

TCP bind hash table entries: 2023 (order: 3,bytes)

TCP: Hash tables configured (established 2023 bind 2023)

TCP: reno registered

UDP hash table entries: 256 (order: 2,bytes)

UDP-Lite hash table entries: 256 (order: 2,bytes)

NET: Registered protocol family 1

RPC: Registered named UNIX socket transport module.

RPC: Registered udp transport module.

RPC: Registered tcp transport module.

RPC: Registered tcp NFSv4.1 backchannel transport module.

NetWinder Floating Point Emulator V0.97 (double precision)

PM: Loading am335x-pm-firmware.bin

VFS: Disk quotas dquot_6.5.2

Dquot-cache hash table entries: 1024 (order 0, 4096 bytes)

NFS: Registering the id_resolver key type

Key type id_resolver registered

Key type id_legacy registered

jffs2: version 2.2. (NAND) (SUMMARY) ©Red Hat, Inc.

msgmni has been set to 484

NET: Registered protocol family 38

io scheduler noop registered

io scheduler deadline registered

io scheduler cfq registered (default)

pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size 568

Console: switching to colour frame buffer device 100×37

Serial: 8250/16550 driver, 4 ports, IRQ sharing enabled

44e09000.serial: ttyO0 at MMIO 0x44e09000 (irq = 88, base_baud =) is a OMAP UART0

console enabled

omap_rng.rng: OMAP Random Number Generator ver. 20

brd: module loaded

loop: module loaded

mtdoops: mtd device (mtddev=name/number) must be supplied

ucore: registered new interface driver asix

ucore: registered new interface driver ax88179_178a

ucore: registered new interface driver cdc_ether

ucore: registered new interface driver r815x

ucore: registered new interface driver sc95xx

ucore: registered new interface driver net1080

ucore: registered new interface driver cdc_subset

ucore: registered new interface driver zaurus

如何在ARM Linux上使用FDT和initrd

FDT是ARM Linux最新的设备驱动程序信息表,使用FDT的内核,就不用像过去的内核那样,一个板子加一个mach的C文件,所有的设备信息可以记录在一个树状信息文件里面。

目前这方面资料比较含纤轮少,我以AM335x处理器为例概括一下FDT的使用:

FDT仅仅是一个信息的目录和参数表,要使用某个功能内核中还必须有相应的驱动程序代码

FDT的源文件位置在:arch/arm/boot/dts,例如,TI的Beagle bone black,源文件是arch/arm/boot/dts/am335x_boneblack.dts

FDT在make ARCH=arm的时候就会自动生成,竖碰也可用make ARCH=arm dtbs来生成,例如TI的Beagle bone black生成的文件是arch/arm/boot/dts/am335x_boneblack.dtb,这是一个二进制文件

要想新增你自定义的FDT,请修改arch/arm/boot/dts/Makefile,并在相应的Kconfig中增加config选项,例如,TI的Beagle bone black,Kconfig的位置在arch/arm/mach-omap2/Kconfig

FDT的dtb文件由u-boot传递给内核,u-boot必须把这个文件拷贝到内核解压地址之后的某个位置,确保内核解压的时谈信候不会覆盖,然后使用“bootm – ”来启动内核

如果dtb文件不正确,对于3.10以上的内核,可能什么显示都没有,3.8内核,可能就显示到Uncompressing kernel……done

FDT的编写规则说明在Documentation/devicetree/bindings,不同的设备有相应的txt文件说明,其中的“compatible”可以作为关键字搜索驱动程序的源文件,例如,AM335x的GPIO,用“ti,omap4-gpio”为关键字,可以找到其代码位于drivers/gpio/gpio-omap.c

/bin/bash: xsltproc: 未找到命令 什么意思? To Build Android Filesystem时出现.(TI-amx)

应该安卓的环境没有,或者环境变量没配好

没安装xsltproc,sudo apt-get install xsltproc

关于am335x linux 定时器的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。


数据运维技术 » AM335x Linux定时器实现原理及应用 (am335x linux 定时器)