欧美性猛交xxxx免费看_牛牛在线视频国产免费_天堂草原电视剧在线观看免费_国产粉嫩高清在线观看_国产欧美日本亚洲精品一5区

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

【英飛凌開發(fā)板模塊評測任務(wù)大挑戰(zhàn)】硬件定時器的使用

冬至子 ? 來源:chejia12 ? 作者:chejia12 ? 2023-08-11 17:25 ? 次閱讀

4.硬件定時器的使用和學(xué)習(xí)

這里依然使用mdk的看法環(huán)境,使用mdk編譯程序,下載程序

4.1配置使能硬件定時器2

1.jpg

4.2 編寫定時器的測試函數(shù)

/*

程序清單:這是一個 hwtimer 設(shè)備使用例程
例程導(dǎo)出了 hwtimer_sample 命令到控制終端
命令調(diào)用格式:hwtimer_sample
程序功能:硬件定時器超時回調(diào)函數(shù)周期性的打印當(dāng)前tick值,2次tick值之差換算為時間等同于定時時間值。
/
#include
#include
#define HWTIMER_DEV_NAME "time2" /
定時器名稱 /
/
定時器超時回調(diào)函數(shù) /
static rt_err_t timeout_cb(rt_device_t dev, rt_size_t size)
{
rt_kprintf("this is hwtimer timeout callback fucntion!n");
rt_kprintf("tick is :%d !n", rt_tick_get());
return 0;
}
int hwtimer_sample(void)
{
rt_err_t ret = RT_EOK;
rt_hwtimerval_t timeout_s; /
定時器超時值 /
rt_device_t hw_dev = RT_NULL; /
定時器設(shè)備句柄 /
rt_hwtimer_mode_t mode; /
定時器模式 /
rt_uint32_t freq = 10000; /
計數(shù)頻率 /
/
查找定時器設(shè)備 /
hw_dev = rt_device_find(HWTIMER_DEV_NAME);
if (hw_dev == RT_NULL)
{
rt_kprintf("hwtimer sample run failed! can't find %s device!n", HWTIMER_DEV_NAME);
return RT_ERROR;
}
/
以讀寫方式打開設(shè)備 /
ret = rt_device_open(hw_dev, RT_DEVICE_OFLAG_RDWR);
if (ret != RT_EOK)
{
rt_kprintf("open %s device failed!n", HWTIMER_DEV_NAME);
return ret;
}
/
設(shè)置超時回調(diào)函數(shù) /
rt_device_set_rx_indicate(hw_dev, timeout_cb);
/
設(shè)置計數(shù)頻率(若未設(shè)置該項,默認(rèn)為1Mhz 或 支持的最小計數(shù)頻率) /
rt_device_control(hw_dev, HWTIMER_CTRL_FREQ_SET, &freq);
/
設(shè)置模式為周期性定時器(若未設(shè)置,默認(rèn)是HWTIMER_MODE_ONESHOT)/
mode = HWTIMER_MODE_PERIOD;
ret = rt_device_control(hw_dev, HWTIMER_CTRL_MODE_SET, &mode);
if (ret != RT_EOK)
{
rt_kprintf("set mode failed! ret is :%dn", ret);
return ret;
}
/
設(shè)置定時器超時值為5s并啟動定時器 /
timeout_s.sec = 5; /
/
timeout_s.usec = 0; /
微秒 /
if (rt_device_write(hw_dev, 0, &timeout_s, sizeof(timeout_s)) != sizeof(timeout_s))
{
rt_kprintf("set timeout value failedn");
return RT_ERROR;
}
/
延時3500ms /
rt_thread_mdelay(3500);
/
讀取定時器當(dāng)前值 /
rt_device_read(hw_dev, 0, &timeout_s, sizeof(timeout_s));
rt_kprintf("Read: Sec = %d, Usec = %dn", timeout_s.sec, timeout_s.usec);
return ret;
}
/
導(dǎo)出到 msh 命令列表中 */
MSH_CMD_EXPORT(hwtimer_sample, hwtimer sample);

4.3測試函數(shù),查看運(yùn)行結(jié)果

1.jpg

4.4硬件定時器設(shè)備驅(qū)動框架學(xué)習(xí)

使用方法:

4.4.1實(shí)現(xiàn)定時器的各個操作函數(shù)

/*

  1. 定時器 初始化函數(shù)
  2. 定時器起始函數(shù)
  3. 定時器停止函數(shù)
  4. 定時器的計數(shù)值獲取
  5. 定時器的控制函數(shù)
    */
    struct rt_hwtimer_ops
    {
    void (*init)(struct rt_hwtimer_device *timer, rt_uint32_t state);
    rt_err_t (*start)(struct rt_hwtimer_device *timer, rt_uint32_t cnt, rt_hwtimer_mode_t mode);
    void (*stop)(struct rt_hwtimer_device *timer);
    rt_uint32_t (*count_get)(struct rt_hwtimer_device *timer);
    rt_err_t (*control)(struct rt_hwtimer_device *timer, rt_uint32_t cmd, void args);
    };
    4.4.2配置定時器的基本參數(shù)
    /
    定時器特征描述 Timer Feature Information /
    struct rt_hwtimer_info
    {
    rt_int32_t maxfreq; /
    最大頻率 the maximum count frequency timer support /
    rt_int32_t minfreq; /
    最小頻率 the minimum count frequency timer support /
    rt_uint32_t maxcnt; /
    最大計數(shù) 值counter maximum value /
    rt_uint8_t cntmode; /
    計數(shù)方向 count mode (inc/dec) */
    };
    typedef struct rt_hwtimer_device
    {
    struct rt_device parent;//基本設(shè)備驅(qū)動框架
    const struct rt_hwtimer_ops *ops;//定時器特有的操作函數(shù)
    const struct rt_hwtimer_info info;//定時器相關(guān)的參數(shù)信息
    rt_int32_t freq; /
    用戶設(shè)置的計數(shù)頻率 counting frequency set by the user /
    rt_int32_t overflow; /
    定時器溢出 timer overflows /
    float period_sec;
    rt_int32_t cycles; /
    溢出后將生成超時事件多少次 how many times will generate a timeout event after overflow /
    rt_int32_t reload; /
    重新加載循環(huán)(使用周期模式) reload cycles(using in period mode) /
    rt_hwtimer_mode_t mode; /
    計時模式(一次/周期) timing mode(oneshot/period) /
    } rt_hwtimer_t;
    4.4.3注冊定時器的設(shè)備到驅(qū)動框架
    /

    定時器設(shè)備注冊函數(shù)
    */
    rt_err_t rt_device_hwtimer_register(rt_hwtimer_t *timer, const char *name, void *user_data);

4.4.4詳細(xì)的定時器設(shè)備驅(qū)動相關(guān)

/*

Copyright (c) 2006-2023, RT-Thread Development Team

SPDX-License-Identifier: Apache-2.0

Change Logs:
Date Author Notes
/
#ifndef HWTIMER_H
#define HWTIMER_H
#include
#ifdef __cplusplus
extern "C" {
#endif
/
定時器的控制命令類型 /
typedef enum
{
HWTIMER_CTRL_FREQ_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x01, /
設(shè)置技術(shù)的頻率set the count frequency /
HWTIMER_CTRL_STOP = RT_DEVICE_CTRL_BASE(Timer) + 0x02, /
停止定時器stop timer /
HWTIMER_CTRL_INFO_GET = RT_DEVICE_CTRL_BASE(Timer) + 0x03, /
獲取計時器功能信息 get a timer feature information /
HWTIMER_CTRL_MODE_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x04 /
設(shè)置定時器的工作模式 Setting the timing mode(oneshot/period) /
} rt_hwtimer_ctrl_t;
/
Timing Mode /
typedef enum
{
HWTIMER_MODE_ONESHOT = 0x01,//單次模式
HWTIMER_MODE_PERIOD//周期模式
} rt_hwtimer_mode_t;
/
Time Value /
typedef struct rt_hwtimerval
{
rt_int32_t sec; /
秒 second /
rt_int32_t usec; /
微秒 microsecond /
} rt_hwtimerval_t;
/ 計數(shù)的方向 /
#define HWTIMER_CNTMODE_UP 0x01 /
increment count mode /
#define HWTIMER_CNTMODE_DW 0x02 /
decreasing count mode /
struct rt_hwtimer_device;
/

  1. 定時器 初始化函數(shù)
  2. 定時器起始函數(shù)
  3. 定時器停止函數(shù)
  4. 定時器的計數(shù)值獲取
  5. 定時器的控制函數(shù)
    */
    struct rt_hwtimer_ops
    {
    void (*init)(struct rt_hwtimer_device *timer, rt_uint32_t state);
    rt_err_t (*start)(struct rt_hwtimer_device *timer, rt_uint32_t cnt, rt_hwtimer_mode_t mode);
    void (*stop)(struct rt_hwtimer_device *timer);
    rt_uint32_t (*count_get)(struct rt_hwtimer_device *timer);
    rt_err_t (*control)(struct rt_hwtimer_device *timer, rt_uint32_t cmd, void args);
    };
    /
    定時器特征描述 Timer Feature Information /
    struct rt_hwtimer_info
    {
    rt_int32_t maxfreq; /
    最大頻率 the maximum count frequency timer support /
    rt_int32_t minfreq; /
    最小頻率 the minimum count frequency timer support /
    rt_uint32_t maxcnt; /
    最大計數(shù) 值counter maximum value /
    rt_uint8_t cntmode; /
    計數(shù)方向 count mode (inc/dec) */
    };
    typedef struct rt_hwtimer_device
    {
    struct rt_device parent;//基本設(shè)備驅(qū)動框架
    const struct rt_hwtimer_ops *ops;//定時器特有的操作函數(shù)
    const struct rt_hwtimer_info info;//定時器相關(guān)的參數(shù)信息
    rt_int32_t freq; /
    用戶設(shè)置的計數(shù)頻率 counting frequency set by the user /
    rt_int32_t overflow; /
    定時器溢出 timer overflows /
    float period_sec;
    rt_int32_t cycles; /
    溢出后將生成超時事件多少次 how many times will generate a timeout event after overflow /
    rt_int32_t reload; /
    重新加載循環(huán)(使用周期模式) reload cycles(using in period mode) /
    rt_hwtimer_mode_t mode; /
    計時模式(一次/周期) timing mode(oneshot/period) /
    } rt_hwtimer_t;
    /

    定時器設(shè)備注冊函數(shù)
    */
    rt_err_t rt_device_hwtimer_register(rt_hwtimer_t *timer, const char *name, void *user_data);
    / 定時器回調(diào)函數(shù) /
    void rt_device_hwtimer_isr(rt_hwtimer_t *timer);
    #ifdef __cplusplus
    }
    #endif
    #endif
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 驅(qū)動器
    +關(guān)注

    關(guān)注

    53

    文章

    8288

    瀏覽量

    147139
  • 定時器
    +關(guān)注

    關(guān)注

    23

    文章

    3256

    瀏覽量

    115442
  • 計時器
    +關(guān)注

    關(guān)注

    1

    文章

    426

    瀏覽量

    32877
  • 回調(diào)函數(shù)
    +關(guān)注

    關(guān)注

    0

    文章

    87

    瀏覽量

    11626
  • RT-Thread
    +關(guān)注

    關(guān)注

    31

    文章

    1305

    瀏覽量

    40419
收藏 人收藏

    評論

    相關(guān)推薦

    如何利用STM32L475開發(fā)板去處理定時器捕獲模塊應(yīng)用程序

    我想在捕獲模塊上進(jìn)行測試,以找出實(shí)際應(yīng)用中定時器引腳處到達(dá)脈沖的脈沖寬度。所以,在這里我想要一個 STM32L475 的開發(fā)板來處理這個應(yīng)用程序,比如從一個定時器 PWM 生成脈沖并循
    發(fā)表于 12-23 09:08

    【實(shí)驗(yàn)38】定時器定時

    HL配套C實(shí)驗(yàn)例程100例之定時器定時,配合開發(fā)板學(xué)習(xí)效果更好。
    發(fā)表于 04-11 16:09 ?7次下載

    HL配套C實(shí)驗(yàn)例程定時器

    HL配套C實(shí)驗(yàn)例程定時器,配合開發(fā)板學(xué)習(xí)效果更好。
    發(fā)表于 04-11 17:04 ?2次下載

    基于MCU的模塊定時器的詳細(xì)解析

    在MCU中(M16),定時器是獨(dú)立的一個模塊,M16有三個獨(dú)立的定時器模塊,即T/C0、T/C1和T/C2;其中T/C0和T/C2都是8位的定時器
    的頭像 發(fā)表于 01-16 09:42 ?1.1w次閱讀

    新唐 NuMaker-M2354模塊評測任務(wù)挑戰(zhàn)

    評測任務(wù)挑戰(zhàn)活動,讓開發(fā)者小伙伴們互相協(xié)作,對開發(fā)板的每個模塊功能進(jìn)行
    的頭像 發(fā)表于 11-16 16:42 ?1363次閱讀

    基于硬件定時器的軟件定時器

    概括硬件定時器很精確,軟件定時器無論如何都有延遲,主要用在不需要精確定時的地方,而且軟件定時比較浪費(fèi)單片機(jī)資源。梳理講到
    發(fā)表于 11-25 09:51 ?8次下載
    基于<b class='flag-5'>硬件</b><b class='flag-5'>定時器</b>的軟件<b class='flag-5'>定時器</b>

    基于cubemx的stm32開發(fā)之路(使用正點(diǎn)原子戰(zhàn)艦V3開發(fā)板)——基本定時器的應(yīng)用

    1hz的閃爍實(shí)驗(yàn)設(shè)備正點(diǎn)原子新戰(zhàn)艦V3 STM32F103ZET6開發(fā)板學(xué)習(xí)st-link燒錄定時器原理F103定時器組成STM32F1
    發(fā)表于 12-08 15:21 ?5次下載
    基于cubemx的stm32<b class='flag-5'>開發(fā)</b>之路(使用正點(diǎn)原子戰(zhàn)艦V3<b class='flag-5'>開發(fā)板</b>)——基本<b class='flag-5'>定時器</b>的應(yīng)用

    MM32F0140定時器模塊計數(shù)定時功能

    本篇筆記主要探討 MM32F0140 定時器模塊的框圖結(jié)構(gòu)、定時器提供的計數(shù)定時等功能以及配置定時器的流程,并以 pokt-f0140
    的頭像 發(fā)表于 04-07 16:31 ?2841次閱讀
    MM32F0140<b class='flag-5'>定時器</b><b class='flag-5'>模塊</b>計數(shù)<b class='flag-5'>定時</b>功能

    Linux驅(qū)動開發(fā)高精度定時器的精度測量評測

    正點(diǎn)原子的示波器能不能支撐嵌入式開發(fā)流程。 Linux高精度定時器說明 其實(shí)傳統(tǒng)的低分辨率定時器隨著技術(shù)的演進(jìn),已經(jīng)無法滿足開發(fā)需求。而且硬件
    的頭像 發(fā)表于 08-09 11:17 ?2083次閱讀

    【合宙Air105開發(fā)板試用體驗(yàn)】小小定時器,能有大作用!

    本文來源電子發(fā)燒友社區(qū),作者:HonestQiao, 帖子地址: https://bbs.elecfans.com/jishu_2283057_1_1.html 案例演示(開發(fā)板體驗(yàn)視頻,詳見作者
    的頭像 發(fā)表于 12-02 15:02 ?912次閱讀

    N32L40XCL-STB 開發(fā)板模塊評測任務(wù)挑戰(zhàn)

    評測任務(wù)挑戰(zhàn)活動,讓開發(fā)者小伙伴們互相協(xié)作,對開發(fā)板的每個模塊功能進(jìn)行
    的頭像 發(fā)表于 03-28 03:25 ?918次閱讀

    英飛凌開發(fā)板模塊評測任務(wù)挑戰(zhàn)

    ?RT-Thread 官方特聯(lián)合合作伙伴發(fā)起開發(fā)板評測任務(wù)挑戰(zhàn)活動,讓開發(fā)者小伙伴們互相協(xié)作,對開發(fā)板
    的頭像 發(fā)表于 04-11 09:05 ?948次閱讀

    英飛凌開發(fā)板模塊評測任務(wù)挑戰(zhàn)-SPI驅(qū)動測試

    使用PSoC? 62 with CAPSENSE? evaluation kit開發(fā)板適配的RTT SPI驅(qū)動,做顯示測試。
    發(fā)表于 08-10 15:44 ?765次閱讀
    <b class='flag-5'>英飛凌</b><b class='flag-5'>開發(fā)板</b><b class='flag-5'>模塊</b><b class='flag-5'>評測</b><b class='flag-5'>任務(wù)</b>大<b class='flag-5'>挑戰(zhàn)</b>-SPI驅(qū)動測試

    定時器中斷程序怎么寫

    達(dá)到預(yù)定的定時時間時,它會產(chǎn)生一個中斷信號,稱為定時器中斷。在本文中,我們將詳細(xì)了解如何編寫定時器中斷程序。 #1. 硬件配置 在開始編寫定時器
    的頭像 發(fā)表于 09-01 10:17 ?2040次閱讀

    英飛凌開發(fā)板模塊評測任務(wù)挑戰(zhàn)】mdk開發(fā)板環(huán)境搭建

    在rtt源碼內(nèi)部生成英飛凌芯片的獨(dú)立的工程
    的頭像 發(fā)表于 10-27 12:39 ?931次閱讀
    【<b class='flag-5'>英飛凌</b><b class='flag-5'>開發(fā)板</b><b class='flag-5'>模塊</b><b class='flag-5'>評測</b><b class='flag-5'>任務(wù)</b>大<b class='flag-5'>挑戰(zhàn)</b>】mdk<b class='flag-5'>開發(fā)板</b>環(huán)境搭建