当前位置:网站首页>Analysis and configuration process of epit periodic timer for imx6ull bare metal development
Analysis and configuration process of epit periodic timer for imx6ull bare metal development
2022-04-23 00:57:00 【Swiler】
Cycle interrupt timer
About EPIT The contents of the timer are located in 《IMX6UL Reference manual 》 Of 1013 page .
Enhanced Periodic Interrupt Timer (EPIT): Enhanced cycle interrupt timer , The counting mode of this timer is to count down . That is, count once and subtract one . And the main work of this timer is to complete periodic interrupt timing .
EPIT The composition of
EPIT It consists of five parts : Clock source ,12 Bit frequency divider , Three 32 Bit register , interrupt , Output pin .
Clock source It can come from :ipg_clk、ipg_clk_32、ipg_clk_highfreq.
12 Bit prescaler The division coefficient of is :1~4096. The following is by 4 Frequency division to 2 Clock variation diagram of frequency division .

3 individual 32 Bit register : Count register (EPIT_CNR)、 Load register (EPIT_LR) And comparison register (EPIT_CMPR), The count register holds the current count value , The comparison register also stores a value , When this value is equal to the count register, a comparison event is generated . The load register is used when the count register counts 0 when , Reload count .
interrupt : The count register and the comparison register pass through CMP The comparator , When the two values are equal , There will be a comparison interrupt , That is, timed interrupt .
Output pin :EPIT Pin output can be configured , Through the corresponding pin (EPITn_OUT) The output signal . The corresponding output pins are shown in the figure below

EPIT The block diagram is as follows :

Count value 、 It's worth 、 The output signal 、 The relationship between interruption, etc

As shown in the figure :
- The value set by the counter is 4、 The comparison value is 2
One clock pulse counts once , And count down , When you count to 2 when , There will be an interruption , also Output Signal Level reversal occurs , When you count to 0 when , Reload the count value to start a new round of counting .
Timer related registers MAP

From this table, we can find ,IMX6U There are two EPIT, And each EPIT Corresponding to a set of register groups , Each set of registers contains :
- Control register (EPITn_CR): For configuring timer
- Status register (EPITn_SR): For reading timer status
- Load register (EPITn_LR)
- Compare register (EPITn_CMPR)
- Count register (EPITn_CNR): Only this permission is read-only
CR Register details

EPITn_CR->CLKSRC: Used to select clock source ;
EPITn_CR->OM: Used to configure the output mode of the output pin ;
EPITn_CR->STOPEN: Enable stop mode ( Reset by the hardware itself );
EPITn_CR->WAITEN: Enable wait mode ( Reset by the hardware itself );
EPITn_CR->DBGEN: Can make debug Pattern ( Reset by the hardware itself );
EPITn_CR->IOVW: To configure EPIT Counter override write , When enabled, all writes to the load register will overwrite the contents of the counter ;
EPITn_CR->SWR: Software reset ( Set up 1 Reset , And self clearing );
EPITn_CR->PRESCALAR: Configure the prescaled value of counter clock ,0~4095;
EPITn_CR->RLD: Counter reload mode , by 0 yes free-running Pattern , by 1 yes set-and-forget Pattern ;
EPITn_CR->OCIEN: Enable output of compare interrupt events ;
EPITn_CR->ENMOD: Timer enabled mode ;
EPITn_CR->EN: Enable timer . by 0 Close when EPIT, by 1 Time to enable EPIT.
SR register

OCIF: Output comparison interrupt flag . When the counter value is equal to the value of this register, an interrupt will be generated . Write 1 Clears the interrupt flag bit .
Timer configuration steps
- Set the clock source 、 Division coefficient 、 Counter reload mode 、 The initial value of the counter comes from
- Enable comparison interrupt , Set load value and compare value ( That is, configure timer interrupt cycle )
- Can make EPITn interrupt , Register interrupt service function
- Add an initialization function to the main function and enable the timer
Sample code
.c file
#include "bsp_epittimer.h"
#include "bsp_int.h"
#include "bsp_led.h"
/* * @description : initialization EPIT Timer .EPIT The timer is 32 Bit down counter , The clock source uses ipg=66Mhz * @param - frac : Frequency division value , The scope is 0~4095, They correspond to each other 1~4096 frequency division . * @param - value : Countdown value . * @return : nothing */
void epit1_init(unsigned int frac, unsigned int value)
{
/* Limit the prescaler factor to no more than 4095*/
if(frac > 0XFFF)
frac = 0XFFF;
EPIT1->CR = 0; // Clear it first CR register
EPIT1->CR = 1<<24; // Configure clock source Peripheral clock=66MHz
EPIT1->CR = frac << 4; // Configure prescaler coefficient
EPIT1->CR = 1 << 3; // Configure counting mode : Count to 0 Then reload the count value
EPIT1->CR = 1 << 2; // Enable comparison interrupt
EPIT1->CR = 1 << 1; // The initial value of configuration count comes from LR register
EPIT1->LR = value; // Countdown value
EPIT1->CMPR = 0; // Compare register , When the counter value is equal to the value of this register, an interrupt will be generated
/* Can make GIC Corresponding interrupt in */
GIC_EnableIRQ(EPIT1_IRQn);
/* Register interrupt service function */
system_register_irqhandler(EPIT1_IRQn, (system_irq_handler_t)epit1_irqhandler, NULL);
EPIT1->CR |= 1<<0; /* Can make EPIT1 */
}
/* * @description : EPIT Interrupt handling function * @param : nothing * @return : nothing */
void epit1_irqhandler(void)
{
static unsigned char state = 0;
state = !state;
if(EPIT1->SR & (1<<0)) /* Judge and compare the occurrence of events */
{
led_switch(LED0, state); /* Timer cycle to , reverse LED */
}
EPIT1->SR |= 1<<0; /* Clears the interrupt flag bit */
}
.h file
#ifndef _BSP_EPITTIMER_H
#define _BSP_EPITTIMER_H
#include "imx6ul.h"
void epit1_init(unsigned int frac, unsigned int value);
void epit1_irqhandler(void);
#endif
版权声明
本文为[Swiler]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230053490624.html
边栏推荐
- [what is istio?] You're out before you know it. You can understand it quickly in 40 minutes
- [HCTF 2018]admin
- IMX6ULL裸机开发之硬件IIC分析及配置过程
- Source code analysis of synchronousqueue
- Snap installation repo problem
- L2-002 linked list weight removal (25 points)
- L3-1 straight beat Huanglong (30 points) DJK + DFS
- C#中的类型转换-自定义隐式转换和显式转换
- Yyds dry goods counting flag variable rule
- What is tooljet and how about it—— Evaluation of low code development platform
猜你喜欢

Secret of 66% performance surge: AMD 25000 yuan 768mb 3D cache Xiaolong opened the cover for the first time

Common problems and solutions of crashsight access reporting

C#/. Net uses questpdf operation to generate PDF faster and more efficient!

曦智科技沈亦晨入选2022达沃斯世界经济论坛“全球青年领袖”

Research and application of power monitoring system in sports training center

简单聊聊Ruby

2.57 - Programming show_ short, show_ Long and show_ Double, which print the byte representation of C language objects of types short, long and double respectively. Please try running on several machi

Selection and evolution of microservices under cloud native architecture

flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】

Software testing immortal documents, even Ali interviewers said it was too detailed. Understanding these directly is P7 level
随机推荐
[HCTF 2018]admin
leetcode 396. Rotation function
The origin explanation and use example of image pre training model
The addition inverse element (a ^ a = 0) XOR operation, which has no performance advantage, is just an intelligence game
L2-013 red alarm (25 points)
Partial ways of converting JSP to thymeleaf format
L2-035 sequence traversal of complete binary tree (25 points)
396. Rotation function / Sword finger offer II 013 Sum of two-dimensional submatrix
Ethtool process of viewing network card statistics
Get in the car, the era of intelligent database autonomy has come, and Tencent cloud database x AI has made a new breakthrough
L2-021 点赞狂魔 (25 分)
flask项目跨域拦截处理以及dbm数据库学习【包头文创网站开发】
The thymeleaf template < img th: SRC = "${map. User. Headerurl}" used in idea reports an error cannot resolve 'user‘
IMX6ULL裸机开发之硬件SPI分析及配置过程
Acrel-2000型电力监控系统在兴庆坊新兴广场配电所配电回路用电的实时监控和管理
L2-020 Kung Fu successor (25 points)
Tdengine deployment cluster installation
Mobile Jingdong Mall
Lightly: a new generation of go IDE
C#中的类型转换-自定义隐式转换和显式转换