首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

嵌入式系统各个模块的基础实验

嵌入式系统各个模块的基础实验

 最近开始摸索GE01MB板子,从这篇文章开始,我将顺便记录各个模块的基础实验,同时也增加自己的熟练度。

实验一、实时时钟试验

一、实时时钟介绍

实时时钟(RealTimeClock)模块,主要提供系统实时时钟,产生连续中断和定时的功能,具有下列特点:

1)、提供年,月,日,分,时,秒计时;

2)、设置定时中断;

3)、提供看门狗功能(定时需要操作系统复位寄存器,否则产生中断或者复位);

4)、提供1/256秒~1秒软件可配置的连续中断;

5)、提供闰年判断机制;

6)、32.768KHz操作。


二、寄存器地址映射表以及各个寄存器说明


(1)、寄存器地址映射表

地址 寄存器名称 读/写 宽度 描述 复位值
0x10002000 STA_YMOD 读/写 32 年、月、日计数寄存器 0x0000_0000
0x10002004 STA_HMS 读/写 32 小时、分钟、秒寄存器 0x0000_0000
0x10002008 ALARM_HM 读/写 32 定时小时、分寄存器 0x0000_0000
0x1000200c CTR 读/写 32 控制寄存器 0x0000_0001
0x10002010 INTREN 读/写 32 中断使能寄存器 0x0000_0010
0x10002014 INTRSTATUS 读 32 中断状态寄存器 0x0000_0000
0x10002018 SAMP 读/写 32 采样周期寄存器 0x0080_0080
0x1000201c WDCNT 读/写 32 Watch-Dog 计数值寄存器 0x8000_0080
0x10002020 WDSERVICE 写 32 Watch-Dog 服务寄存器 -

(2)、各个寄存器描述


1)、年、月、日计数寄存器(STA_YMOD)

Bits 31:27 ---- Reserved
STA_Y[10:0] ---- 年设定值
用于设定RTC 时钟的年。取值范围0~2047。
Bits 15:12 ---- Reserved
STA_MO[3:0]---- 月设定值
用于设定RTC 时钟的月。取值范围1~12
Bits 7:6 ---- Reserved
STA_D[5:0] ---- 日设定值
用于设定RTC 时钟的日。取值范围1~31


注意:由于RTC 中两个时域的同步问题,此寄存器设置新值后不能立即读取到设置的新值。一般而言,经
过1~2 个CLK32 时钟周期之后才可以正确读取到更新的新值。


2)、小时、分、秒计数寄存器(STA_HMS)

Bits 31:29 ---- Reserved
STA_H[4:0] ---- 小时设定值
设定RTC 时钟的小时。取值范围0~23。
Bits 23:22 ---- Reserved
STA_M[5:0] ---- 分设定值
设定RTC 时钟的分钟。取值范围0~59。
Bits 15:6 ---- Reserved
STA_S[5:0] ---- 秒设定值
设定RTC 时钟的秒。取值范围0~59。


注意:同年、月、日计数寄存器(STA_YMOD)。


3)、RTC Alarm 定时寄存器(ALARM_HM)

Bits 31:21 ---- Reserved
ALARM_H[4:0]---- 定时小时设定 设置定时器的小时。取值范围0~23。
Bits 15:6 ---- Reserved
ALARM_M[5:0]---- 定时分设定 设置定时器的分钟。取值范围0~59。


4)、RTC 控制寄存器(CTR)

Bits 31:2 ---- Reserved
WEN(1) ---- Watchdog Enable Watchdog 使能控制位。
0 = Watchdog disable
1 = Watchdog enable
DIS(0) ---- RTC Disable RTC使能控制位。控制TIMER 和SAMPLE 功能。
0 = RTC enable
1 = RTC disable


5)、RTC 中断使能寄存器(INTREN)

Bits 31:6 ---- Reserved
REN(5) ---- Reset Enable
Watchdog 复位使能位。应用软件必须在RTC 的Watchdog 的计数器减到1 之前对Watchdog 进行访问,否则Watchdog 会产生复位信号(如果REN 位使能)。
0 = Watchdog reset disable
1 = Watchdog reset enable
WIE(4) ---- Watchdog Interrupt Enable
Watchdog 中断使能位。RTC 的Watchdog 递减计数到1 时,如果中断使能则能够产生中断。
0 = Watchdog interrupt disable
1 = Watchdog interrupt enable
AIE(3) ---- Alarm Interrupt Enable
RTC的Alarm 中断使能位。当RTC Alarm 定时寄存器和当前计时匹配时,如果此中断使能则可以产生中断。
0 = Alarm interrupt disable
1 = Alarm interrupt enable
MIE(2) ---- Minute Interrupt Enable
RTC分钟中断使能位。如果此位使能,则每隔一分钟产生一次分中断。
0 = Minute interrupt disable
1 = Minute interrupt enable
SIE(1) ---- Second Interrupt Enable
RTC秒中断使能位。如果此位使能,则每隔一秒产生一次秒中断。
0 = Second interrupt disable
1 = Second interrupt enable
SAE(0) ---- Sample Interrupt Enable
RTC sample 中断使能位。如果RTC 使能,则RTC 通过sample 功能可以产生定时的中断信号。中断产生时间可以通过RTC 采样周期寄存器设置。
0 = Sample interrupt disable
1 = Sample interrupt enable

注、SAMPLE 功能可以设定一定间隔后产生中断。清除中断标志位后,经过相同的间隔后将再次产生中断。

6)、RTC 中断状态寄存器(INTRSTATUS)
Bits 31:5 ---- Reserved
WIF(4) ---- Watchdog Interrupt Flag
Watchdog 中断标志位。当Watchdog 递减计数到1 且WIE 位使能,则此标志位置位。当向此位写“1”,可以清除该标志位。
0 = No Watchdog interrupt occurred
1 = Watchdog interrupt occurred
AIF(3) ---- Alarm Interrupt Flag
Alarm中断标志位。当Alarm 定时寄存器的值和当前RTC 时间(小时和分)相匹配时且AIE 位使能,则此标志位置位。当向此位写“1”,可以清除该标志位。
0 = No alarm interrupt occurred
1 = Alarm interrupt occurred
MIF(2) ---- Minute Interrupt Flag
Minute中断标志位。当RTC timer 每计时一分钟且MIE 位使能,则此标志位置位。当向此位写“1”,可以清除该标志位。
0 = No minute interrupt occurred
1 = Minute interrupt occurred
SIF(1) ---- Second Interrupt Flag
Second中断标志位。当RTC timer 每计时一秒钟且SIE 位使能,则此标志位置位。当向此位写“1”,可以清除该标志位。
0 = No second interrupt occurred
1 = Second interrupt occurred
SAF(0) ---- Sample Interrupt Flag
Sample中断标志位。当RTC sample 递减计数到1 且SAE 位使能,则此标志位置位。当向此位写“1”,可以清除该标志位。
0 = No sample interrupt occurred
1 = Sample interrupt occurred
7)、RTC 采样周期寄存器(SAMP)
SAMP[31:16] ---- Sample 值
设置sample 模块中计数器的重新加载值。每次递减计数器计数到“1”(计数时间T)后,如果软件清除SAF 标志位则sample 模块的计数器使用SAMP[31:16]重新加载。

计数时间T = SAMP[31:16] / 32768 (秒)
当SAMP=0x80 时, T = 1/256 秒。
当SAMP=0x8000 时,T = 1 秒。
当SAMP=0x1 时, T = 0 秒。
SAMP=0x0和SAMP=0xffff 的T 值近似。

SYN_SAMP[15:0] ---- Synchronous Sample 值
SYN_SAMP[15:0]位反映了sample 功能模块计数器的当前值。当其计数到“1”后,如果中断使能则产生中断。如果软件清除SAF 标志位则其加载SAMP[15:0]的值。也可以直接通过写操作改变当前计数器的值。

8)、Watchdog 计数值寄存器(WDCNT)
WDRELOAD[7:0] ---- Watchdog Relaod 值
用于重新加载Watchdog 的计数器。当Watchdog 中断标志位WIF 被清除或者向Wathchdog 服务寄存器写0xAAAA 时,此值被加载到Watchdog 计数器中初始化计数器。

Bits 23:16 ---- Reserved
Bits 15:24 ---- Reserved

SYNC_WD[7:0] ---- Synchronous Watchdog 值
当前Watchdog 计数器的值。当其递减计数到“1”时,如果WIE 位使能则可以产生中断;若REN 位使能则可以产生Watchdog 复位信号。当Watchdog中断标志位WIF 被清除或者向Wathchdog 服务寄存器写0xAAAA 时,WDRELOAD 的值被加载到其中。也可以直接通过写操作改变当前计数器的值。

9)、Watchdog 服务寄存器(WDSERVICE)
Bits 31:16 ---- Reserved
WDSERVICE(15:0) ---- Watchdog Service
Watchdog服务位。当向这个地址写0xAAAA 时,WDRELOAD 的值被加载到Watchdog 的计数器中,阻止计数器递减到“1”,从而避免产生中断或复位。

三、实验代码流程
1)、时钟实验
该实验主要是设计一个时钟显示器,用户可以在程序中定义当前的时间,从当前时间开始计时,每隔一分钟通过AXD 的Console 窗口可以打印出实际的时间。
2)、定时实验
该实验主要是实现一个定时的功能,用户可以在程序中的set_alarm 函数中定义一个时间,等到当前时间与set_alarm 函数中的时间相等后可以通过AXD 的Console 打印出所定时的时间以实现闹铃功能。

第一部分、main函数之前的系统配置
可以参照GE01MB开发板的相关资料 中b __main之前的相关代码

第二部分、系统初始化(配置系统时钟、使能中断并屏蔽)、设置年月日时分秒、运行时钟和等待中断产生
代码流程:
ModuleRtc()---
--------------system_init()
------------------------------pmc_init()
------------------------------INT_INIT()
------------------------------serial_init()/*串行端口初始化*/
--------------unmask_irq()/* open rtc interrrupt mask */
--------------set_ymd()
--------------set_hms()
--------------set_alarm()
--------------run_rtc()/*设置相关控制寄存器*/
值得注意的是中断处理函数
通过在int_vec_handler.c中把相应的NULL改成自己定义的中断函数名就可以了。
返回列表