您好,TI:
我正在MCU2_0 (RTOS)中使用RTI28作为WDT,将CLK_SEL设置为32kHz,但它不起作用,下面是测试代码,请帮助检查。
src文件:
/* ========================================================================== */
/* Include Files */
/* ========================================================================== */
#include <stdint.h>
#include <stdio.h>
#include <ti/csl/csl_types.h>
#include <ti/csl/hw_types.h>
#include <ti/csl/csl_rti.h>
#include <ti/csl/soc.h>
#include <ti/board/board.h>
#include <ti/osal/osal.h>
#include <ti/drv/sciclient/sciclient.h>
#include <utils/console_io/include/app_log.h>
#include <ti/board/board.h>
#include <utils/watchdog/include/rti_wtd.h>
/* ========================================================================== */
/* Macros */
/* ========================================================================== */
#define APP_NAME "R5F RTI APP"
/* ========================================================================== */
/* Structures and Enums */
/* ========================================================================== */
/**
* \brief Enum to select the clock source for RTI module.
*/
typedef enum rtiClockSource
{
RTI_CLOCK_SOURCE_HFOSC0_CLKOUT = 0U,
/**< to select clock frequency of hfosc0 */
RTI_CLOCK_SOURCE_LFOSC_CLKOUT = 1U,
/**< to select clock frequency of lfosc */
RTI_CLOCK_SOURCE_12MHZ = 2U,
/**< to select clock frequency of 12 MHz */
RTI_CLOCK_SOURCE_32KHZ = 3U,
/**< to select clock frequency of 32KHz */
}rtiClockSource_t;
/* ========================================================================== */
/* Global Variables */
/* ========================================================================== */
volatile uint32_t isrFlag = 0U;
/**< Flag used to indicate interrupt is generated */
/* ========================================================================== */
/* Internal Function Declarations */
/* ========================================================================== */
/**
* \brief This API to select clock source for RTI module.
*
*
* \param rtiClockSource RTI module clock source
* Values given by enum #rtiClockSource_t
*
* \return none.
*/
static void RTISetClockSource(uint32_t rtiClockSourceSelect);
/**
* \brief This API to calculate preload value from given time-out value.
*
* \param rtiClockSource RTI module clock source
* Values given by enum #rtiClockSource_t
*
* \param timeoutVal RTI DWWD time-out value in mili-seconds.
*
* \return Preload value Time-out value in RTI source clock cycles.
*/
static uint32_t RTIGetPreloadValue(uint32_t rtiClkSource, uint32_t timeoutVal);
/**
* \brief This API to register interrupt for a given instance.
*
*
* \return 0: Success, -1: Failure
*/
static int32_t RTIInterruptConfig(void);
/**
* \brief ISR after interrupt generation, sets global flag
*
* \retval None
*/
static void RTIAppISR(uintptr_t handle);
/* ========================================================================== */
/* Function Definitions */
/* ========================================================================== */
void test_csl_rti_dwwd_test_app(void)
{
uint32_t rtiModule, rtiWindow_size, rtiPreload_value, rtiReaction;
int32_t config_status;
appLogPrintf("\n Board init complete\n");
/* Register Interrupt */
isrFlag = 0U;
if(RTIInterruptConfig() != 0)
{
appLogPrintf("\r\nRTI Interrupt configuration failed. \r\n");
return;
}
appLogPrintf("\n Interrupt config complete\n");
/* Configure RTI parameters */
rtiModule = RTI_APP_RTI_CFG_BASE;
rtiWindow_size = APP_RTI_DWWD_WINDOW_SIZE;
rtiReaction = APP_RTI_DWWD_REACTION;
rtiPreload_value = RTIGetPreloadValue((uint32_t) RTI_CLOCK_SOURCE_32KHZ,
(uint32_t) APP_RTI_DWWD_TIMEOUT_VALUE);
/* Select RTI module clock source */
RTISetClockSource((uint32_t) RTI_CLOCK_SOURCE_32KHZ);
config_status = RTIDwwdWindowConfig(rtiModule, rtiReaction,
rtiPreload_value,
rtiWindow_size);
if (config_status == CSL_EFAIL)
{
appLogPrintf(APP_NAME ": Error during Window configuration.\n");
}
else
{
appLogPrintf(APP_NAME ": DWWD is configured for %u ms time-out \n",
APP_RTI_DWWD_TIMEOUT_VALUE);
appLogPrintf(APP_NAME ": DWWD will generate interrupt after "
"above time-out period.\n");
RTIDwwdCounterEnable(rtiModule);
/* Let DWWD expire here */
appLogPrintf(APP_NAME ": Wait for %u ms for interrupt "
"to be generated by DWWD.\n", APP_RTI_DWWD_TIMEOUT_VALUE);
appLogPrintf("isrFlag=%lu\n",isrFlag);
while (0U == isrFlag)
{
/* Wait for interrupt */
}
appLogPrintf(APP_NAME ": RTI App completed successfully.\n");
appLogPrintf("\n All tests have passed. \n");
}
}
static void RTISetClockSource(uint32_t rtiClockSourceSelect)
{
volatile uint32_t *hwRegPtr;
hwRegPtr = (uint32_t *) (RTI_APP_CTRL_MMR_CFG_BASE + RTI_APP_CTRL_MMR_CLKSEL_OFFSET);
hwRegPtr[0] = (hwRegPtr[0] & (~RTI_APP_RTI_CLK_SEL_FIELD_MASK)) | (rtiClockSourceSelect << RTI_APP_RTI_CLK_SEL_FIELD_SHIFT);
}
static int32_t RTIInterruptConfig(void)
{
int32_t retVal = 0;
OsalRegisterIntrParams_t intrPrms;
OsalInterruptRetCode_e osalRetVal;
HwiP_Handle hwiHandle;
uint32_t rtiIntNum;
Osal_RegisterInterrupt_initParams(&intrPrms);
intrPrms.corepacConfig.arg = (uintptr_t)0;
intrPrms.corepacConfig.priority = 1U;
intrPrms.corepacConfig.corepacEventNum = 0U; /* NOT USED ? */
rtiIntNum = RTI_APP_WDT_INT_NUM;
if (retVal == 0)
{
intrPrms.corepacConfig.isrRoutine = &RTIAppISR;
intrPrms.corepacConfig.intVecNum = rtiIntNum;
osalRetVal = Osal_RegisterInterrupt(&intrPrms, &hwiHandle);
if(OSAL_INT_SUCCESS != osalRetVal)
{
appLogPrintf(APP_NAME ": Error Could not register ISR !!!\n");
retVal = -1;
}
}
return retVal;
}
static uint32_t RTIGetPreloadValue(uint32_t rtiClkSource, uint32_t timeoutVal)
{
uint32_t clkFreqKHz = (uint32_t) RTI_CLOCK_SOURCE_32KHZ_FREQ_KHZ,
timeoutNumCycles = 0;
switch (rtiClkSource)
{
case RTI_CLOCK_SOURCE_32KHZ:
clkFreqKHz = (uint32_t) RTI_CLOCK_SOURCE_32KHZ_FREQ_KHZ;
break;
default:
break;
}
/* Get the clock ticks for given time-out value */
timeoutNumCycles = timeoutVal * clkFreqKHz;
return timeoutNumCycles;
}
static void RTIAppISR(uintptr_t handle)
{
uint32_t intrStatus;
#ifdef WDT_RESET
int32_t status;
#endif
RTIDwwdGetStatus(RTI_APP_RTI_CFG_BASE, &intrStatus);
RTIDwwdClearStatus(RTI_APP_RTI_CFG_BASE, intrStatus);
appLogPrintf(APP_NAME ": Interrupt Generated!!!\n");
#ifdef WDT_RESET
status = Sciclient_pmDeviceReset(SCICLIENT_SERVICE_WAIT_FOREVER);
if (status != 0)
{
appLogPrintf(APP_NAME ": Sciclient_pmDeviceReset Failed : stauts = %d!!!\n", status);
}
#endif
isrFlag = 1U;
}
头文件:
/**< RTI Instance */ #define APP_RTI_DWWD_WINDOW_SIZE (RTI_RTIDWWDSIZECTRL_DWWDSIZE_50_PERCENT) /**< DWWD Window Size */ #define APP_RTI_DWWD_TIMEOUT_VALUE (60000U) /**< DWWD Time Out Value */ #define APP_RTI_DWWD_REACTION (RTI_RTIDWWDRXNCTRL_DWWDRXN_INTERRUPT) //0XA /**< DWWD Reaction After Timeout */ #define RTI_CLOCK_SOURCE_32KHZ_FREQ_KHZ (32U) /**< RTI Clock Source Selection */ #define RTI_APP_CTRL_MMR_CFG_BASE (CSL_CTRL_MMR0_CFG0_BASE) //0x100000UL /**< RTI CTRL MMR Config Base address */ #define RTI_APP_RTI_CFG_BASE (CSL_RTI28_CFG_BASE) /**< RTI Config Base address */ #define RTI_APP_CTRL_MMR_CLKSEL_OFFSET (CSL_MAIN_CTRL_MMR_CFG0_WWD28_CLKSEL) //0x000083F0U /**< RTI Clock select Register offset */ #define RTI_APP_RTI_CLK_SEL_FIELD_MASK (CSL_MAIN_CTRL_MMR_CFG0_WWD28_CLKSEL_CLK_SEL_MASK) //7 /**< RTI CLock select Register field mask */ #define RTI_APP_RTI_CLK_SEL_FIELD_SHIFT (CSL_MAIN_CTRL_MMR_CFG0_WWD28_CLKSEL_CLK_SEL_SHIFT) //0 /**< RTI CLock select Register field shift */ /**< RTI WWD interrupt number*/ #define RTI_APP_WDT_INT_NUM (2)
test_csL_RTI_dwwd_test_app 将在app_init.c中调用,但我看不到正确的倒计时,请您帮忙,谢谢