RTE (run-time environment) is a runtime environment added after MDK V5.0. It contains common peripheral drivers developed in accordance with the CMSIS Driver specification, such as GPIO, UART, I2C, SPI, USB, etc., which are called RTE drivers, that is, runtime environment drivers. RTE provides a graphical configuration method, which is very convenient to use.
The SDK provided by ON Semiconductor also provides timer routines. Here I need to add a timer to my own project to perform regular data collection.
Double-click the xx.rteconfig file to open the RTE configuration interface.
Select Timer here . If the driver depends on other components, a prompt will be given.
Next, configure the detailed parameters in the RTE_Device.h file. The writing of RTE_Device.h follows the relevant specifications of RTE. You can open it in a graphical way or edit the source file directly.
The test code is as follows, which shows that the use of CMSIS driver is very simple.
#include <app.h>
#include <RTE_Device.h>
#include <TIMER_RSLxx.h>
#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 & TIMER_TIMER0_EVENT)
{
PRINTF("TIMER0 TRIGGERED\n");
return;
}
}
int main(void)
{
/* Configure hardware */
Device_Initialize();
/* Initialize timer structure */
timer = &Driver_TIMER;
/* Configure timer callback function */
timer->Initialize(Timer_EventCallback);//设置定时器溢出回调函数
timeout = TIMER0_BASE_TIMEOUT;
timer->SetValue(TIMER_0, timeout);//设置超时值
/* Start timer 0 (free run mode) */
timer->Start(TIMER_0);//启动定时器
PRINTF("STARTED TIMER0\n");
while (1)
{
Sys_Watchdog_Refresh();
}
}
Effect:
|