dql2016 发表于 2021-6-25 21:43

RSL10 RTE添加定时器

<p>&nbsp;RTE(run-time environment) 是 MDK V5.0 之后加入的运行时环境,里面包含了遵循CMSIS Driver规范开发的常用外设驱动,如GPIO、UART、I2C、SPI、USB等,称之为RTE driver即运行时环境驱动。RTE提供图形化配置方式,使用十分方便。</p>

<p>安森美提供的SDK也给出了定时器的例程,这里我需要在自己的工程中加入定时器以便进行定时数据采集。</p>

<p></p>

<p>双击<span style="background-color:#2ecc71;">xx.rteconfig</span>文件打开RTE配置界面。</p>

<p></p>

<p>这里将<span style="background-color:#f1c40f;">Timer</span>选中,若驱动依赖其它组件则会给出提示。接下来是贷款<span style="background-color:#f1c40f;">RTE_Device.h</span>这个文件进行详细参数的配置,<span style="background-color:#f1c40f;">RTE_Device.h</span>的编写遵循RTE的相关规范,可以使用图形化的方式打开,也可以直接编辑源文件。</p>

<p>测试代码如下,可见CMSIS驱动的使用十分简洁。</p>

<pre>
<code class="language-cpp">
#include &lt;app.h&gt;
#include &lt;RTE_Device.h&gt;
#include &lt;TIMER_RSLxx.h&gt;

#if !RTE_TIMER
    #error "Please configure TIMER in RTE_Device.h"
#endif    /* if !RTE_TIMER */

/* Global variables and types */
DRIVER_TIMER_t *timer;
extern DRIVER_TIMER_t Driver_TIMER;
/* Timer 0 timeout value */
static uint32_t timeout = 0;
/* Timeout values */
#define TIMER0_BASE_TIMEOUT             0x3000
#define TIMER0_TIMEOUT_STEP             0x800

/* ----------------------------------------------------------------------------
* Function      : void Timer_EventCallback(uint32_t event)
* ----------------------------------------------------------------------------
* Description   : This function is a callback registered by the function
*               Initialize. Based on event argument different actions are
*               executed.
* Inputs      : None
* Outputs       : None
* Assumptions   : None
* ------------------------------------------------------------------------- */
void Timer_EventCallback(uint32_t event)
{
    /* Check if timer0 event has been triggered */
    if (event &amp; TIMER_TIMER0_EVENT)
    {
      PRINTF("TIMER0 TRIGGERED\n");
      return;
    }
}


int main(void)
{
    /* Configure hardware */
    Device_Initialize();


    /* Initialize timer structure */
    timer = &amp;Driver_TIMER;
    /* Configure timer callback function */
    timer-&gt;Initialize(Timer_EventCallback);//设置定时器溢出回调函数
    timeout = TIMER0_BASE_TIMEOUT;
    timer-&gt;SetValue(TIMER_0, timeout);//设置超时值
    /* Start timer 0 (free run mode) */
    timer-&gt;Start(TIMER_0);//启动定时器
    PRINTF("STARTED TIMER0\n");

    while (1)
    {
      Sys_Watchdog_Refresh();
    }
}
</code></pre>

<p>效果:</p>

<p></p>

w494143467 发表于 2021-6-26 14:44

<p>你这定时器是多少毫秒的计时?</p>

dql2016 发表于 2021-6-29 00:38

w494143467 发表于 2021-6-26 14:44
你这定时器是多少毫秒的计时?

<p>没算过,那个定时器驱动还不清楚里面的机制</p>
页: [1]
查看完整版本: RSL10 RTE添加定时器