【uTenux实验】时间管理(系统时间/周期性处理/警报处理)
1、系统时间管理
系统时间管理函数用来对系统时间进行操作,是OS的一个基础性的东西。个人认为,设置系统时间和获取系统时间对OS来说基本是可有可无的。
uTenux提供了三个系统时间相关API。分别用于设置系统时间、获取系统时间和获取系统工作时间。其中,前两个比较蛋疼。时间的表示是从1985年1月1日0:00:00(GMT)开始以ms为单位的累加。要想获得可读的时分秒,还得手动转换。我最讨厌这个转换了,所以不想细做这个实验。
tk_get_otm获取的系统工作时间也是一ms表示的,只是这个数据比较直观,不需要再去转换了。
【实验说明】
我懒的去转换时间,本实验使用验证三个函数,用ms表示时间。
首先设置系统时间,然后读出十次otm,最后读出系统时间。看看读出的系统时间与写入的时间的差别。其实这时,板子上RTC功能没有打开,设置系统时钟这个功能基本等于没用。
我比较懒,这就就在例程的基础上添加几行代码。没有手动输入各个函数。
【代码及输出】
#include "TimeSample.h" EXPORT ER TimeSample( void )
{
B ostr[],hstr[],mstr[],sstr[];
UW i,hour,minute,second;
SYSTIM otm,systime;
ER ercd; //设置系统时间
systime.hi = ;
systime.lo = ;
tk_set_tim(&systime); tm_putstring((UB*)"Time sample is now starting!\n");
for(i=;i<;i++) {
ercd=tk_get_otm(&otm);
if(E_OK != ercd){
tm_putstring((UB*)"Time can't be got;\n");
PutErcd(ercd);
}
tm_putstring((UB*)"Now working up time is ");
second=otm.lo/;
minute=second/;
second=second%;
hour=minute/;
minute=minute%;
ltostr(otm.lo,ostr,,); /*put otm string */
tm_putstring((UB*)ostr);
tm_putstring((UB*)",");
ltostr(hour,hstr,,); /*put hour string */
tm_putstring((UB*)hstr);
tm_putstring((UB*)":");
ltostr(minute,mstr,,); /*put minute string */
tm_putstring((UB*)mstr);
tm_putstring((UB*)":");
ltostr(second,sstr,,); /*put second string */
tm_putstring((UB*)sstr);
tm_putstring((UB*)"\n"); Delay(0x1700000);
}
//获取系统时间并输出
tk_get_tim(&systime);
tm_putstring((UB*)"Now system time is ");
second=systime.lo/;
minute=second/;
second=second%;
hour=minute/;
minute=minute%;
ltostr(systime.lo,ostr,,); /*put otm string */
tm_putstring((UB*)ostr);
tm_putstring((UB*)",");
ltostr(hour,hstr,,); /*put hour string */
tm_putstring((UB*)hstr);
tm_putstring((UB*)":");
ltostr(minute,mstr,,); /*put minute string */
tm_putstring((UB*)mstr);
tm_putstring((UB*)":");
ltostr(second,sstr,,); /*put second string */
tm_putstring((UB*)sstr);
tm_putstring((UB*)"\n"); return E_OK;
}
输出:
----------------------------------------------------
micro Tenux Version 1.6.00(build 0180)
Supported MCU is ST STM32F407VG
Copyright(c) 2008-2013 by Dalian uLoong Co.,Ltd.
----------------------------------------------------
Time sample is now starting!
Now working up time is 0,0:0:0
Now working up time is 570,0:0:0
Now working up time is 1150,0:0:1
Now working up time is 1730,0:0:1
。。。。。。。。。。。。。。
Now working up time is 9230,0:0:9
Now working up time is 9810,0:0:9
Now working up time is 10390,0:0:10
Now working up time is 10960,0:0:10
Now system time is 12140,0:0:12
Push any key to shutdown the micro Tenux.
2、周期性处理
周期性处理程序是一个在规则的时间间隔内启动的时间事件处理程序。与任务不同,周期性处理函数不是死循环。执行一次就退出,但是不能单独存在。
建立好周期性处理函数之后,原任务就不用管了。OS会周期性地执行这个任务。这个周期性的函数,不受优先级限制。只要到期就会运行一次。不管多高优先级的任务在使用MCU。
在建立每个周期性处理程序时,会为它们设定程序启动时的时间间隔(周期时间)和周期相位。周期时间t就是每隔t时间会启动一次处理函数,周期相位m,是指每个周期的第m时间启动这个处理函数。
SVC描述
1、创建周期性处理程序
ID cycid=tk_cre_cyc(T_CCYC* pk_ccyc);
其中T_CCYC是创建结构体,定义如下
typedef struct t_ccyc {
VP exinf; /* Extended information */
ATR cycatr; /* Cycle handler attribute */
FP cychdr; /*处理程序入口地址*/
RELTIM cyctim; /* 处理周期*/
RELTIM cycphs; /* 相位*/
UB dsname[]; /* Object name */
} T_CCYC;
2、创建之后就实验tk_sta_cyc让周期函数可以运行了
3、停止周期运行tk_stp_cyc,删除周期处理tk_del_cyc,只要提供一个ID即可。
【实验描述】
1、创建一个周期运行程序并启动。
2、创建一个优先级较高的任务TaskA,启动后进入死循环。即不给初始任务再次运行的机会
3、周期处理函数,处理20次之后,自动停止并删除自己。
【代码及输出】
例子太简单了,自己加了点内容。
#include "CycSample.h" void CycHandler(void);
void CycTaskSampseA(W stacd,VP exinf);
void CycTaskSampseB(W stacd,VP exinf);
static B count;
static ID CycID;
static ID TaskA_ID; EXPORT ER CycSample( void )
{
ER ercd;
T_CCYC ccyc;
T_CTSK ctsk; ctsk.bufptr = NULL;
ctsk.exinf = (VP)NULL;;
ctsk.itskpri = ;
ctsk.stksz = ;
ctsk.task = CycTaskSampseA;
ctsk.tskatr = TA_HLNG | TA_RNG0;
TaskA_ID = tk_cre_tsk(&ctsk); //创建周期处理
ccyc.cycatr = TA_HLNG | TA_STA;
ccyc.cychdr = CycHandler;
ccyc.cycphs = ;
ccyc.cyctim = ;
ccyc.exinf = (VP)NULL;
CycID = tk_cre_cyc(&ccyc); if(E_OK<= CycID)
{
tm_putstring((UB*)"成功创建周期性处理\n");
}
else
{
}
if(E_OK <= tk_sta_cyc(CycID))
{
tm_putstring((UB*)"成功启动周期性处理\n");
} tk_sta_tsk(TaskA_ID,); return E_OK;
} //验证周期处理与任务优先级无关
void CycTaskSampseA(W stacd,VP exinf)
{
tm_putstring((UB*)"TaskA启动成功\n");
while();
} void CycHandler(void)
{
count++;
if(count == )
{
tm_putstring((UB*)"i will stop my cyc\n");
if(E_OK <= tk_stp_cyc(CycID))
{
tm_putstring((UB*)"sucess stop cyc\n");
}
tm_putstring((UB*)"i will delete my cyc\n");
if(E_OK <= tk_del_cyc(CycID))
{
tm_putstring((UB*)"sucess delete cyc\n");
}
return;
}
tm_putstring((UB*)"The times of cycle is: ");
tm_putchar(count+);
tm_putstring((UB*)" !\n");
}
输出:
----------------------------------------------------
micro Tenux Version 1.6.00(build 0180)
Supported MCU is ST STM32F407VG
Copyright(c) 2008-2013 by Dalian uLoong Co.,Ltd.
----------------------------------------------------
成功创建周期性处理
成功启动周期性处理
TaskA启动成功
The times of cycle is: 1 !
The times of cycle is: 2 !
The times of cycle is: 3 !
The times of cycle is: 4 !
The times of cycle is: 5 !
The times of cycle is: 6 !
The times of cycle is: 7 !
The times of cycle is: 8 !
The times of cycle is: 9 !
i will stop my cyc
sucess stop cyc
i will delete my cyc
sucess delete cyc
3、警报处理
警报处理程序是一个在特定时间启动的时间事件处理程序。警报处理也是有OS直接管理的。创建警报处理后,并不能立即激活警报,只有当调用了tk_sta_alm之后才能激活这个警报。
激活警报时,需要为警报处理提供警报持续时间。警报持续时间结束,或者手动调用tk_stp_alm停止警报时,警报停止。
这个就像大楼里边的火警,发生火情(事件)激活警报,警报开始工作。警报持续一段时间,该知道发生火情的人都知道了,警报就停止了。也可能是虚惊一场,然后大楼管理员按了停止按钮,警报就停止了。
uTenux提供的警报处理API:
1、创建警报:
ID almid=tk_cre_alm(T_CALM* pk_calm);
创建结构体如下:
typedef struct t_calm {
VP exinf; /* Extended information */
ATR almatr; /* Alarm handler attribute */
FP almhdr; /* Alarm handler address */
UB dsname[8]; /* Object name */
}T_CALM;
即只需要提供警报处理的函数入口和处理程序属性即可。
2、激活警报
ER ercd= tk_sta_alm(ID almid,RELTIM almtim);
提供警报处理的ID和警报持续时间。即可
3、停止警报
ER ercd= tk_stp_alm(ID almid);
将警报almid停止掉。
【实验描述】
1、创建一个警报,并启动
2、在警报处理函数中,输出一段信息
3、等待警报时间到,自动结束
4、删除警报,返回
【代码及输出】
#include "CycSample.h" void CycHandler(void);
void CycTaskSampseA(W stacd,VP exinf);
void CycTaskSampseB(W stacd,VP exinf);
static B count;
static ID CycID;
static ID TaskA_ID; EXPORT ER CycSample( void )
{
ER ercd;
T_CCYC ccyc;
T_CTSK ctsk; ctsk.bufptr = NULL;
ctsk.exinf = (VP)NULL;;
ctsk.itskpri = ;
ctsk.stksz = ;
ctsk.task = CycTaskSampseA;
ctsk.tskatr = TA_HLNG | TA_RNG0;
TaskA_ID = tk_cre_tsk(&ctsk); //创建周期处理
ccyc.cycatr = TA_HLNG | TA_STA;
ccyc.cychdr = CycHandler;
ccyc.cycphs = ;
ccyc.cyctim = ;
ccyc.exinf = (VP)NULL;
CycID = tk_cre_cyc(&ccyc); if(E_OK<= CycID)
{
tm_putstring((UB*)"成功创建周期性处理\n");
}
else
{
}
if(E_OK <= tk_sta_cyc(CycID))
{
tm_putstring((UB*)"成功启动周期性处理\n");
}
tk_sta_tsk(TaskA_ID,); return E_OK;
} //验证周期处理与任务优先级无关
void CycTaskSampseA(W stacd,VP exinf)
{
tm_putstring((UB*)"TaskA启动成功\n");
while();
} void CycHandler(void)
{
count++;
if(count == )
{
tm_putstring((UB*)"i will stop my cyc\n");
if(E_OK <= tk_stp_cyc(CycID))
{
tm_putstring((UB*)"sucess stop cyc\n");
}
tm_putstring((UB*)"i will delete my cyc\n");
if(E_OK <= tk_del_cyc(CycID))
{
tm_putstring((UB*)"sucess delete cyc\n");
}
return;
}
tm_putstring((UB*)"The times of cycle is: ");
tm_putchar(count+);
tm_putstring((UB*)" !\n");
}
输出:
----------------------------------------------------
micro Tenux Version 1.6.00(build 0180)
Supported MCU is ST STM32F407VG
Copyright(c) 2008-2013 by Dalian uLoong Co.,Ltd.
----------------------------------------------------
Start alarm sucess
Wait alarm stop
Wait alarm stop
Wait alarm stop
Wait alarm stop
Wait alarm stop
Wait alarm stop
Now alarm will delete
Delete alarm sucess
Push any key to shutdown the micro Tenux.
【uTenux实验】时间管理(系统时间/周期性处理/警报处理)的更多相关文章
- Linux的硬件时间、校正Linux系统时间及系统时间调用流程
第一部分: 一)概述: 事实上在Linux中有两个时钟系统,分别是系统时间和硬件时间 UTC是协调世界时(Universal Time Coordinated)英文缩写,它比北京时间早8个小时. ...
- ubuntu下的时间设定(硬件时间,系统时间,本地时间)
问题的来由是在这里: 在cron里设定任务是在凌晨6点执行,检查日志时发现时间总是不对,是在22点左右的时间执行的.研究发现,任务是在本地时间的6点执行了,但不知为什么syslog中的时间都是为utc ...
- java new Date()得到的时间和系统时间不一样
造成这种问题的原因是:操作系统时区跟JVM的时区不一致. [root@paas244 ~]# timedatectl Local time: Thu 2016-12-29 15:35:44 CST U ...
- Log4j 输出的日志中时间比系统时间少了8小时的解决方法,log4j日志文件重复输出
1. 第一个问题:时间少了8小时 Log4j 输出的日志中,时间比系统时间少了8小时,但是 eclipse 控制台输出的日志的时间却是对的. log4j配置如下: #all logger output ...
- ftp上来显示的时间和系统时间不一致
ftp上来显示的时间和系统时间不一致,是因为默认情况下,vsftpd 是用GMT做为他的时间的,所以和系统的时间可能会不一致 修改也非常简单: vi /etc/vsftpd/vsftpd.conf 在 ...
- linux 系统文件类型、系统安装时间、系统启动时间、系统运行时间、设置及显示时间、系统时间和硬件时间
系统文件类型: 1) $mout 2) df -l:仅列出本地文件系统:-h (--human-readable):-T:文件系统类型 $df -lhf 3) file -s (--special-f ...
- IIS7日志中时间与系统时间不一致的原因
最近在分析web日志,发现IIS7日志中时间与系统时间不一致,即本该上班时间才产生的产并发访问日志,全部发生在凌晨至上班前. 本以为是系统时间设置错误,检查后一切正常.后查询资料,原来是这个原因: 日 ...
- tomcat时间与系统时间不一致问题
我在部署应用到centos系统上的tomcat服务器中运行,发现操作系统的时间和tomcat中的访问日志的时间与系统时间不一致,但是查看当前操作系统的时区也是CST时区(中国标准时区). 查看系统的时 ...
- Centos7 修改硬件时间和系统时间
查看系统时间 [root@localhost ~]# date Tue Jun 13 10:20:13 CST 2017 查看硬件时间 [root@localhost ~]# hwclock --sh ...
- centos7系统日志时间与系统时间相差8小时
场景:当我们修改完系统时间的时区后,我们去查看我们的系统日志的时间发现时区还是在之前的系统时间时区. [root@vp-n ~]# ls -l /etc/localtime lrwxrwxrwx 1 ...
随机推荐
- 登陆界面Login
最终界面: XMAL 代码: <Grid > <Grid.RowDefinitions> <RowDefinition /> <RowDefinition ...
- 字符串与模式匹配(一)——KMP算法
源码:kmp.cpp // KMP.cpp : Defines the entry point for the console application. // #include "stdaf ...
- 通过MD5排除重复文件
今天下载了好多美女图片壁纸,可是看了一下发现好多图片重复了,有强迫症的我必须把重复的都给剔除掉,首先想到的当然是百度了,问问度娘有没有什么图片去重的工具,搜了一下还真有.奈何本人智商捉急用不来这高级的 ...
- DeepLearning之路(一)逻辑回归
逻辑回归 1. 总述 逻辑回归来源于回归分析,用来解决分类问题,即预测值变为较少数量的离散值. 2. 基本概念 回归分析(Regression Analysis):存在一堆观测资料,希望获得数据内 ...
- Lantern卫星接收器:为你提供免费上网服务
包括笔者在内,许多现代人的日常生活都无法离开网络,因为在网络上我们几乎可以找到任何我们需要的信息.但你是否有想过在户外无网络信号的情况下如何接收网络数据呢?一个名为Outernet Inc.的公司为我 ...
- 设置类型Double小数点位数
Double amount = 100;DecimalFormat dcmFmt = new DecimalFormat("0.0000"); String amountStr = ...
- 视频转gif
如何把视频变成GIF https://shop16541393.koudaitong.com/v2/feature/1x6q09fa?openid=ov0dfwb6-DBFqTzvekSNAjT59U ...
- C# 代码示例_结构/数组/枚举...
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- WCF终结点配置
错误信息:已有针对 IP 终结点 127.0.0.1:8235 的侦听器.如果有其他应用程序已在侦听此终结点,或者,如果在服务主机中具有多个服务终结点,这些终结点具有相同的 IP 终结点但绑定配置不兼 ...
- pip install 出现报asciii码错误的问题
原因是pip安装python包会加载我的用户目录,我的用户目录恰好是中文的,ascii不能编码. 解决办法是: python目录 Python27\Lib\site-packages 建一个文件sit ...