6. El uso del perro guardián M601

1 API de vigilancia de software


La estructura de datos y la API introducidas en este artículo pueden hacer referencia al archivo zyf_wtd.h en el SDK


1.1 Uso


En la solución OpenCPU, el perro guardián de hardware está habilitado en la biblioteca de forma predeterminada y alimentará al perro con regularidad, por lo que el desarrollador no necesita lidiar con esta lógica. Además, esta solución proporciona a los desarrolladores un perro guardián de software. El perro guardián del software se enciende llamando a ZYF_Wdt_Enable. Después de encenderlo, si el valor del contador del perro guardián del software no se borra dentro del tiempo especificado, el módulo se reiniciará. Borre el contador de vigilancia del software a través de ZYF_FeedDog. En caso de que el módulo se reinicie. El perro guardián se puede apagar a través de ZYF_Wdt_Disable.


1.2 funciones API


1.2.1 ZYF_Wdt_Enable
Esta función se utiliza para habilitar el perro guardián
· Prototipo de función
bool ZYF_Wdt_Enable (uint32_t max_interval_ms);
· Parámetro
max_interval_ms:
[entrada]: tiempo de activación del perro guardián
· Valor de retorno
El resultado de habilitar el perro guardián


1.2.2 ZYF_Wdt_Disable
Esta función se utiliza para apagar el perro guardián
Función prototipo
bool ZYF_Wdt_Disable (void);

· Parámetro
NINGUNO
· Valor de retorno
El resultado de apagar el perro guardián


1.2.3 ZYF_FeedDog alimenta al
perro, es decir, pone a cero el valor del registro.
· Prototipo de función
void ZYF_FeedDog (void);
· Parámetro
NINGUNO
· Valor de retorno
NINGUNO

 

2 Introducción a las rutinas de vigilancia

Este capítulo presenta principalmente cómo usar example_wtd.c en el SDK para probar la función de vigilancia por separado.

En el ejemplo, inicie un hilo SMSThread_Example para probar la función de vigilancia. ZYF_WtdTest () se
utiliza para configurar los parámetros del temporizador. La función de ZYF_Wtd () es establecer el tiempo de espera del perro guardián en 10 segundos; por otro
lado, es establecer el período de alimentación del temporizador en 9 segundos. detalles como sigue:


#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include "zyf_timer.h"
#include "zyf_wtd.h"

#include "zyf_trace.h"
#include "zyf_app.h"
#include "zyf_uart.h"
#include "zyf_thread.h"



typedef struct
{
    uint32_t max_interval;
    uint32_t feed_interval;
    ZYF_Timer_t *feed_timer;
} ZYF_Wdt_t;

static ZYF_Wdt_t gBsjWdt;

static Uart_Param_t g_uart1param;

void UartWriteCallBack(void* Param) // general com
{
    Uart_Param_t *uartparam = (Uart_Param_t *)Param; 
    if(Param == NULL)
    {
        return;
    }    

    ZYF_UartWrite(uartparam->port,(uint8_t *)"UartWrite succeed\r\n",strlen("UartWrite succeed\r\n"));
    ZYF_UartWriteCallbackSwitch(uartparam->port,false);

}

void UartReadCallBack(void* Param) // 
{
    uint32_t recvlen = 0;
    Uart_Param_t *uartparam = (Uart_Param_t *)Param; 

    ZYF_LOG("Uart%d recv",uartparam->port);

    while(ZYF_UartRead(uartparam->port, &(uartparam->uartbuf[recvlen]), 1))
    {
        ZYF_LOG("recv :%02x",uartparam->uartbuf[recvlen]);
        recvlen++;
    }
    ZYF_UartWrite(uartparam->port,uartparam->uartbuf,recvlen);
    ZYF_UartWriteCallbackSwitch(uartparam->port,true);
}


static void AppUartInit(void)
{
    int32_t ret;
    g_uart1param.port = DEBUG_PORT;
    ZYF_UartRegister(g_uart1param.port, UartReadCallBack,&g_uart1param);
    ZYF_UartWriteCbRegister(g_uart1param.port,UartWriteCallBack,&g_uart1param);
    ZYF_UartOpen(g_uart1param.port, 115200, ZYF_FC_NONE);

    ZYF_LOG("AppUartInit");
    return;
}


static void _feedDog(void *wd_)
{
    ZYF_Wdt_t *wd = (ZYF_Wdt_t *)wd_;
    ZYF_LOG("ZYF_feedDog");

    
    ZYF_FeedDog();
    ZYF_StartTimer(wd->feed_timer, wd->feed_interval);
}

void ZYF_WtdClose(void)
{
    ZYF_Wdt_Disable();
}

bool ZYF_WtdOpen(uint32_t max_interval_ms, uint32_t feed_interval_ms)
{
    ZYF_Wdt_t *wd = &gBsjWdt;
    if (max_interval_ms < feed_interval_ms)
        return false;

    ZYF_Wdt_t *timer = ZYF_CreateTimer(_feedDog, (void *)wd);
    if (timer == NULL)
        return false;

    wd->max_interval = max_interval_ms;
    wd->feed_interval = feed_interval_ms;
    wd->feed_timer = timer;

    bool r = ZYF_Wdt_Enable(max_interval_ms);
    if (!r)
    {
        ZYF_DeleteTimer(timer);
        return false;
    }

    ZYF_StartTimer(wd->feed_timer, wd->feed_interval);
    return true;
}

void ZYF_WtdTest(void)
{
    bool ret = ZYF_WtdOpen(10000, 9000);
    if(!ret)
    {
        ZYF_LOG("ZYF_WTD init failed.");
    }
    ZYF_LOG("ZYF_WTD init success!");
}

void SMSThread_Example(void * Param)
{
    ZYF_MsgQ_t *ptMsg;
    ZYF_AppMsg_t tMsg;
    int iRet = -1;
    ptMsg = ZYF_MsgQCreate(10, sizeof(ZYF_AppMsg_t));
    ZYF_LOG("thread enter!");

    ZYF_WtdTest();
    
    while (1) {
        ZYF_LOG("in while.");
        iRet = ZYF_MsgQGet(ptMsg, (void *)&tMsg);
        if (iRet < 0) {
            ZYF_LOG("Failed to get msg");
            ZYF_ThreadSleep(1000);
        }
    }

}


static void prvInvokeGlobalCtors(void)
{
    extern void (*__init_array_start[])();
    extern void (*__init_array_end[])();

    size_t count = __init_array_end - __init_array_start;
    for (size_t i = 0; i < count; ++i)
        __init_array_start[i]();
}


int appimg_enter(void *param)
{
    AppUartInit();
    ZYF_LOG("application image enter, param 0x%x", param);

    prvInvokeGlobalCtors();

    ZYF_ThreadCreate("SMSThread_Example", SMSThread_Example, NULL, ZYF_PRIORITY_HIGH, 10*1024);
    return 0;
}

void appimg_exit(void)
{
    OSI_LOGI(0, "application image exit");
}







 

Supongo que te gusta

Origin blog.csdn.net/w_hizyf_m/article/details/107084052
Recomendado
Clasificación