GTM 如何使用?

#include "r_gtm.h"

#include "r_rspi.h"

FSP_HEADER

/** GTM Timer Instance */

extern const timer_instance_t g_timer0;

/** Access the GTM instance using these structures when calling API functions directly (::p_api is not used). */

extern gtm_instance_ctrl_t g_timer0_ctrl;

extern const timer_cfg_t g_timer0_cfg;

#ifndef Timer_1S_callback

void Timer_1S_callback(timer_callback_args_t *p_args);

#endif

在 e2 开发环境中定义了 GTM 定时器,如何让定时中断工作?

#include "User_program_thread.h"

#include "FreeRTOS.h"
#include "openamp/open_amp.h"
#include "platform_info.h"
#include "rsc_table.h"


void Timer_1S_callback(timer_callback_args_t *p_args)
{
LPRINTF("Timer_1S is running--- \n");
}

/* User program Thread entry function */
/* pvParameters contains TaskHandle_t */
void User_program_thread_entry(void *pvParameters) {
FSP_PARAMETER_NOT_USED(pvParameters);

LPRINTF("User Program is running--- \n");

/* TODO: add your own code here */
while (1)
{

vTaskDelay(1);
}


}

在上述程序中定时中断未被执行,没在串口终端打印出内容。

Parents
  • 请问有在主函数里初始化并启用timer吗?

  • #include "User_program.h"

    #include "FreeRTOS.h"

    #include "openamp/open_amp.h"

    #include "platform_info.h"

    #include "rsc_table.h"

    void g_timer0_callback(timer_callback_args_t *p_args)

    {

    LPRINTF("g_timer0_callback is running--- \n");

    }

    /* User task Thread entry function */

    /* pvParameters contains TaskHandle_t */

    void User_program_entry(void *pvParameters) {

    FSP_PARAMETER_NOT_USED(pvParameters);

    /* TODO: add your own code here */

    LPRINTF("User program is running--- \n");

    fsp_err_t err = FSP_SUCCESS;

    /* Initializes the module. */

    err = R_GTM_Open(&g_timer0_ctrl, &g_timer0_cfg);

    /* Handle any errors. This function should be defined by the user. */

    assert(FSP_SUCCESS == err);

    /* Start the timer. */

    (void) R_GTM_Start(&g_timer0_ctrl);

    /* (Optional) Stop the timer. */

    //(void) R_GTM_Stop(&g_timer_ctrl);

    while (1) {

    vTaskDelay(1);

    }

    }

    初始化也不行

  • gtm_instance_ctrl_t g_timer0_ctrl;

    const gtm_extended_cfg_t g_timer0_extend = { .generate_interrupt_when_starts =

    GTM_GIWS_TYPE_ENABLED, .gtm_mode = GTM_TIMER_MODE_INTERVAL, };

    const timer_cfg_t g_timer0_cfg = { .mode = TIMER_MODE_PERIODIC, .period_counts =

    (uint32_t) 0x98967f /* Actual period: 0.1 seconds. */, .channel = 1,

    .p_callback = g_timer0_callback, .p_context = NULL, .cycle_end_ipl = 5,

    .p_extend = &g_timer0_extend,

    #if defined(VECTOR_NUMBER_GTM1_COUNTER_OVERFLOW)

    .cycle_end_irq = VECTOR_NUMBER_GTM1_COUNTER_OVERFLOW,

    #else

    .cycle_end_irq = GTM1_OSTM1INT_IRQn,

    #endif

    };

    /* Instance structure to use this module. */

    const timer_instance_t g_timer0 = { .p_ctrl = &g_timer0_ctrl, .p_cfg =

    &g_timer0_cfg, .p_api = &g_timer_on_gtm };

    extern uint32_t g_fsp_common_thread_count;

    const rm_freertos_port_parameters_t User_program_parameters = { .p_context =

    (void*) NULL, };

  • 配置看起来没问题,你看看中断里加一下断点或者定义个counter看看没进中断还是进中断没有打印

  • /* TODO: add your own code here */

    LPRINTF("User program is running--- \n");

    这个打印了

    void g_timer0_callback(timer_callback_args_t *p_args)

    {

    LPRINTF("g_timer0_callback is running--- \n");

    }    这句不打印,说明中断没发生

    开发板没引出仿真接口,没办法实时仿真 CM33,只能通过串口打印来观察程序执行

  • 如果你的LPRINTF是基于中断实现的,那么在timer中断里打印可能异常

  • uint32_t timer0_count=0;

    void g_timer0_callback(timer_callback_args_t *p_args)

    {

    //LPRINTF("g_timer0_callback is running--- \n");

    timer0_count++;

    }

    /* User task Thread entry function */

    /* pvParameters contains TaskHandle_t */

    void User_program_entry(void *pvParameters) {

    FSP_PARAMETER_NOT_USED(pvParameters);

    /* TODO: add your own code here */

    LPRINTF("User program is running--- \n");

    fsp_err_t err = FSP_SUCCESS;

    /* Initializes the module. */

    err = R_GTM_Open(&g_timer0_ctrl, &g_timer0_cfg);

    /* Handle any errors. This function should be defined by the user. */

    assert(FSP_SUCCESS == err);

    /* Start the timer. */

    (void) R_GTM_Start(&g_timer0_ctrl);

    /* (Optional) Stop the timer. */

    //(void) R_GTM_Stop(&g_timer_ctrl);

    while (1) {

    LPRINTF("timer0_count = %u \n", timer0_count);

    vTaskDelay(1000);

    }

    }

    运行结果:

    Successfully probed IPI device
    Successfully open uio device: 42F00000.rsctbl.
    Successfully added memory device 42F00000.rsctbl.
    Successfully open uio device: 43000000.vring-ctl0.
    Successfully added memory device 43000000.vring-ctl0.
    Successfully open uio device: 43200000.vring-shm0.
    Successfully added memory device 43200000.vring-shm0.
    Initialize remoteproc successfully.
    creating remoteproc virtio
    initializing rpmsg vdev
    User program is running---
    timer0_count = 1
    timer0_count = 11
    timer0_count = 21

    定时器工作了,但只打印了 3 行就停了

Reply
  • uint32_t timer0_count=0;

    void g_timer0_callback(timer_callback_args_t *p_args)

    {

    //LPRINTF("g_timer0_callback is running--- \n");

    timer0_count++;

    }

    /* User task Thread entry function */

    /* pvParameters contains TaskHandle_t */

    void User_program_entry(void *pvParameters) {

    FSP_PARAMETER_NOT_USED(pvParameters);

    /* TODO: add your own code here */

    LPRINTF("User program is running--- \n");

    fsp_err_t err = FSP_SUCCESS;

    /* Initializes the module. */

    err = R_GTM_Open(&g_timer0_ctrl, &g_timer0_cfg);

    /* Handle any errors. This function should be defined by the user. */

    assert(FSP_SUCCESS == err);

    /* Start the timer. */

    (void) R_GTM_Start(&g_timer0_ctrl);

    /* (Optional) Stop the timer. */

    //(void) R_GTM_Stop(&g_timer_ctrl);

    while (1) {

    LPRINTF("timer0_count = %u \n", timer0_count);

    vTaskDelay(1000);

    }

    }

    运行结果:

    Successfully probed IPI device
    Successfully open uio device: 42F00000.rsctbl.
    Successfully added memory device 42F00000.rsctbl.
    Successfully open uio device: 43000000.vring-ctl0.
    Successfully added memory device 43000000.vring-ctl0.
    Successfully open uio device: 43200000.vring-shm0.
    Successfully added memory device 43200000.vring-shm0.
    Initialize remoteproc successfully.
    creating remoteproc virtio
    initializing rpmsg vdev
    User program is running---
    timer0_count = 1
    timer0_count = 11
    timer0_count = 21

    定时器工作了,但只打印了 3 行就停了

Children
No Data