功能安全 - aman396271/Flagchip_Study GitHub Wiki

1、FARC(Flash Alias Region Controller)

This module is available on FC4150F1M_B only.

2、FWM(FunSa Watchdog Monitor,功能安全看门狗监视器)

RM理解

FWM凭借产生置位信号通知MCU外部电路发生异常,其主要置位逻辑为更新点是否在CMPL和CMPH区间内、在区间内更新时外部输入引脚是否被置位,正常情况下不会置位 image FWM不会像一般看门狗一样复位MCU,其告警逻辑为: The FWM module includes a counter which is allowed to overflow, and the correct range is determined by CMPL and CMPH.At the same time, the FWM will not reset the MCU's CPU and peripherals, but provides an output signal when asserted resets or an external circuit needs to be placed into a safe mode.

置位电平选择

由FWM_CTRL的INASTSEL位决定 image

FWM刷新有效性

image

FWM时钟

The FWM counter is an 8-bit counter with a clock source from AON_CLKFWM使用了独立时钟AON_CLK(Always on clock) 需配置SMISC(System Miscellaneous Controller)打开AON_CLK image 代码配置为:

void Bsp_SMISC_Init(void)
{
    SMISC_ClkoutType smiscClkOut = {0};
    SMISC_AONCLKSRType smiscAonClkSrc;

    smiscClkOut.eDivider = SMISC_CLKOUT_DIV_BY1;
    smiscClkOut.bEnable = true;
    smiscClkOut.eSource = SMISC_CLKOUT_AON_CLK;
    SMISC_SetClockout(&smiscClkOut);

    smiscAonClkSrc.eAon32KSel = SMISC_AON32K_SIRC32K;
    smiscAonClkSrc.eRtcSel = SMISC_RTC_SIRC32K;
    smiscAonClkSrc.eAonSel = SMISC_AON_SIRC32_1K;
    SMISC_SetAonClkSrc(&smiscAonClkSrc);
}

开启FWM时钟

{PCC_CLK_FWM, true, PCC_CLKGATE_SRC_OFF, PCC_CLK_DIV_BY1}

获取时钟频率

SMISC_GetSMISCClockFreq(SMISC_AON_CLK, &u32FwmFreq)

初始化配置

PWM配置结构体

typedef struct
{
    bool       bIntEn;        /**< FWM_CTRL[INTEN], Interrupt Enable        */
    bool       bInputEn;      /**< FWM_CTRL[INEN],  Input Enable            */
    bool       bInAstSel;     /**< FWM_CTRL[INASTSEL],
                                Setting the ASSIN bit inverts the assert
                                state of input signal to a logic one       */
    bool       bFwmEn;        /**< FWM_CTRL[FWMEN], Interrupt Enable, W1C   */
    uint8_t    u8CompareL;     /**< FWM_CMPL[COMPARE],  Compare low value             */
    uint8_t    u8CompareH;     /**< FWM_CMPH[COMPAREH]   Compare high value            */
    uint8_t    u8ClkDiv;       /**< FWM_CLKPRESCALER[CLK_DIV],FWM clock = SIRC frequency / ( 1 + CLK_DIV ) */
    uint8_t    reserve;
    void (*pResetSignalCallback)(FWM_HandleType *pHandle);       /**<  The FWM ISR callback function. */
} FWM_CfgType;

SDK中的初始化描述已经很详尽

FWM_HandleType g_tFwmHandle;

void Bsp_Fwm_Init(void)
{
    uint32_t u32FwmFreq = 0U;
    uint8_t u8Count1s = 0U;
    FWM_CfgType Fwm_InitStruct = {0};

    Fwm_InitStruct.bIntEn = true;
    Fwm_InitStruct.bInputEn = true;

    /*  Default assert state of the FWM_in signal is logic zero */
    Fwm_InitStruct.bInAstSel = true;
    Fwm_InitStruct.pResetSignalCallback = NULL;

    /* get AON_CLK, range 1K--128K */
    /* According SMISC setting, AON_CLK set to 32K   */
    SMISC_GetSMISCClockFreq(SMISC_AON_CLK,  &u32FwmFreq);
    if (u32FwmFreq == SMISC_AONCLK_32K)
    {
        /* clkDiv bit 7--0, range 0--255  */
        /* pre-scale clock frequency = SIRC frequency / (1 + CLK_DIV) */
        Fwm_InitStruct.u8ClkDiv = 255U;

        /* get 1s counter */
        u8Count1s = (uint8_t)(u32FwmFreq / (Fwm_InitStruct.u8ClkDiv + 1U));
    }
    else if (u32FwmFreq == SMISC_AONCLK_1K)
    {
        /* clkDiv bit 7--0, range 0--255  */
        /* pre-scale clock frequency = SIRC frequency / (1 + CLK_DIV) */
        Fwm_InitStruct.u8ClkDiv = 7U;

        /* get 1s counter */
        u8Count1s = (uint8_t)(u32FwmFreq / (Fwm_InitStruct.u8ClkDiv + 1U));
    }
    else
    {
        /* reserve 128K clock source, can not maintain 1s counter */
    }

    if (u8Count1s != 0U)
    {
        /* COMPAREL bit 7--0, range 0--255,set compareL as 0.4s  */
        Fwm_InitStruct.u8CompareL = (uint8_t)(u8Count1s * 0.4);

        /* COMPAREH bit 7--0, range 0--255  */
        Fwm_InitStruct.u8CompareH = (uint8_t)(u8Count1s * 1.2);

        Fwm_InitStruct.bFwmEn = true;

        FWM_Init(&g_tFwmHandle, &Fwm_InitStruct);
    }
    else
    {

    }
}

FWM_Refresh

在FWM更新,即向FWM的SERV寄存器写入FWM_REFRESH_CMD1 0xFC20UFWM_REFRESH_CMD2 0x20CFU时,由于需要写入两个寄存器,该原子操作为避免被中断打断,需先关断中断,结束刷新后再打开中断

void Bsp_Fwm_Refresh(void)
{
    DISABLE_INTERRUPTS();
    FWM_Refresh();
    ENABLE_INTERRUPTS();
}

Debug

There is no impact on the FWM when entering debug mode, the FWM will keep the same state before entering debug mode. 在Debug时,FWM的进行不会受到影响,当打断点时,FWM会继续count,会导致超过CMPH,从而出现告警中断,在进行Debug时应视情况关闭此功能

3、WDOG(Watchdog)看门狗

4、EIM

Error Injection Module,错误注入模块 The Error Injection Module (EIM) is mainly used for ECC and parity etc. logic self-test and diagnostic purposes. It provides a method for diagnostic coverage of the peripheral memories. Each EIM channel corresponds to a specific memory image

寄存器功能分析

image EIM_CR寄存器使能中断 image EIM_CHENR寄存器在EIM_CR开启时,报告中断,需手动清楚 image EIM_WORD0_CHRn配置校验位掩码 image EIM_WORD1_CHRn配置数据位掩码

5、ERM

Error Reporting Module 错误报告模块 image

寄存器功能分析

image ERM_CR0控制Memory n的单个位错误纠正中断和无法纠正错误中断,共有5个memory image ERM_SR0状态位 image ERM_EARn错误发生地址

INTM(Interrupt Monitor)

概述

The Interrupt Monitor (INTM) module is used to monitor the latency of interrupt sources to ensure that these interrupt requests are executed within the expected time, increasing the reliability of the device监控中断源延迟,确保在预期时间执行,增加可靠性

功能描述

image 1、 IRQSELR[IRQ]选择中断源 2、 IRQSELR[INTE] or IRQSELR[RSTE] 启用中断,或超时复位 3、 LATR配置超时时间 4、 ER使能监视器 5、 进入中断服务后写IACKR(Interrupt Acknowledge Register),得知中断已触发 6、 在TMR超过LATR后,SR寄存器被置位

#End