16. M601 低功耗测试

1 电源管理 API

电源管理包括电源相关的操作,例如关机,重启,电源键控制和低功耗使能禁止,可以参考 SDK 中 zyf_power.h 文件。


1.1 用法

开机/关机
如果 PWRKEY 引脚没有接地,调用 ZYF_PowerDown 函数后,模块执行关机。
休眠
调用 ZYF_SleepEnable 函数使能模块休眠模式,使能后模块会在空闲时进入休眠模式。在模块进入休眠模式后,定时器超时,来电,收到新短信,GPRS 数据和中断事件都可以唤醒模块。ZYF_SleepDisable 函数禁止模块进入休眠模式。

1.2 GPIO 相关 API

1.2.1 ZYF_PowerKeyRegister 注册电源键通知消息
这个函数主要用于注册电源键通知消息回调函数,当有 PWRKEY 按下或松开,在回调函数会有通知消息。“KEY_DOWN”表示按键按下,“KEY_UP”表示按键松开。
函数原型
int32_t ZYF_PowerKeyRegister(ZYF_PowerKeyCallback callback_pwrKey)
参数
callback_pwrKey:
[输入]指向电源键消息回调函数指针
返回结果
ZYF_RET_OK:成功
ZYF_RET_ERR_INVALID_PARAMETER:无效参数

1.2.2 ZYF_PowerDown 模块关机
这个函数主要是让模块关机,调用此函数去关闭模块时,模块会先注销网络,然后才关机。 所以关机时间有可能会长点。
函数原型
void ZYF_PowerDown(uint8_t pwrDwnType)
参数
pwrDwnType: [输入]输入类型,必须是 1,表示正常关机
返回结果
NONE


1.2.3 ZYF_Reboot 模块重启

这个函数主要是让模块重启。调用此函数重启模块时,跟网络无关,可快速重启。
函数原型
void ZYF_Reboot(void)
参数
NONE
返回结果
NONE


1.2.4 ZYF_SleepEnable 使能休眠模式

函数原型
int32_t ZYF_SleepEnable(void)
参数
NONE
返回结果
ZYF_RET_OK: 成功
ZYF_RET_NOT_SUPPORT: 不支持


1.2.5 ZYF_SleepDisable 退出休眠模式
函数原型
int32_t ZYF_SleepDisable (void)
参数:NONE
返回结果
ZYF_RET_OK: 成功

1.2.6 ZYF_GetPowerOnReason 获取开机原因
函数原型
int32_t ZYF_GetPowerOnReason(void)
参数
NONE
返回结果
开机的原因,为 Enum_PowerOnReason 的一个值。


1.2.7 ZYF_LockPower
说明:此功能锁定模块的电源。当仅电源键由应用程序控制时使用。
函数原型
void ZYF_LockPower(void)
参数
NONE
返回结果
NONE


1.2.8 ZYF_PmuLdoCtrl
说明:此功能用于设置 LDO 启用或禁用以及 LDO 启用时的 LDO 输出电压。
函数原型
int32_t ZYF_PmuLdoCtrl(uint32_t ldoNo, bool enable, uint32_t voltage)
参数
ldoNo:ldo 选择
启用:
电压:输出电压 0.01mv
返回结果
NONE

2 低功耗测试例程

编译方法:.\examples\build\对应的.bat 文件双击执行或打开就可以编译。
生成文件:.\out\对应目录\hex\M601_example_**.pac



#include <stdlib.h>
#include <string.h>
#include "zyf_trace.h"
#include "zyf_system.h"
#include "zyf_app.h"
#include "zyf_uart.h"
#include "zyf_thread.h"
#include "zyf_time.h"
#include "zyf_gpio.h"

#include "zyf_error.h"
#include "uart_proto.h"

#define __weak __attribute__((weak))


static Uart_Param_t g_uart1param;
static Uart_Param_t g_uart2param;
static Uart_Param_t g_uart3param;



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 __weak UartReadCallBack(void* Param) // 
{
    uint32_t recvlen = 0;
    Uart_Param_t *uartparam = (Uart_Param_t *)Param; 

    /*
    UART_PORT1 = 0,
    UART_PORT2 = 1,
    UART_PORT3 = 2,
    */
    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 _AppUart1Init(void)
{
    int32_t ret;
    g_uart1param.port = UART_PORT1;
    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("_AppUart1Init");
    return;
}


static void _AppUart2Init(void)
{  
    g_uart2param.port = UART_PORT2;
    ZYF_UartRegister(UART_PORT2, UartReadCallBack,&g_uart2param);
    ZYF_UartWriteCbRegister(UART_PORT2,UartWriteCallBack,&g_uart2param);
    ZYF_UartOpen(UART_PORT2, 115200, ZYF_FC_NONE);
    ZYF_LOG("_AppUart2Init");

    return;
}


static void _AppUart3Init(void)
{   
    g_uart3param.port = UART_PORT3;
    ZYF_UartRegister(UART_PORT3, UartReadCallBack,&g_uart3param);
    ZYF_UartWriteCbRegister(UART_PORT3,UartWriteCallBack,&g_uart3param);
    ZYF_UartOpen(UART_PORT3, 115200, ZYF_FC_NONE);
    ZYF_LOG("_AppUart3Init");

    return;
}



void AppUartInit(void)
{
    _AppUart1Init();
    _AppUart2Init();
    _AppUart3Init();
}

#if 1
static void GetIccidCallback(void*msg)
{
    uint8_t idx;


    if(NULL == msg)
    {
        ZYF_LOG("SystemApi GetIccid fail");
        return;
    }
    idx = strlen((char*)msg);
    if((idx < 3) || (idx > 20))
    {
        ZYF_LOG("SystemApi GetIccid fail,idx:%d",idx);
        return;
    }
    ZYF_LOG("SystemApi GetIccid %s",(char*)msg);
 
    
}


static void GetImsiCallback(void*msg)
{
    uint8_t idx;

    
    ZYF_LOG("GetImsiCallback");

    if(NULL == msg)
    {
        ZYF_LOG("SystemApi GetImsi fail");
        return;
    }
    idx = strlen((char*)msg);
    if((idx < 3) || (idx > 20))
    {
        ZYF_LOG("SystemApi GetImsi fail,idx:%d",idx);
        //return;
    }
    ZYF_LOG("SystemApi GetImsi %s",(char*)msg);
 
    
}

static void FlightModeOnOff(int on_off)
{
    ZYF_LOG("FlightModeOnOff %d",on_off);
}

#endif


void ZYF_SystemApiTest(void)
{
    uint8_t Imei[16+1] = {0};
    uint8_t csq = 0;
    uint8_t CregStatus = 0;
    uint8_t CgregStatus = 0,plmn[6] = {0};
    uint32_t lac_value = 0,ci_value = 0;
    uint64_t ms = 0,sec = 0;;
    uint32_t high = 0;
    uint32_t low = 0;
    int32_t nwMode = 0;

    if(0 == ZYF_IsSimValid())
    {
        ZYF_LOG("SystemApi IsSimValid:true");
    }
    else
    {
        ZYF_LOG("SystemApi IsSimValid:false");
    }

    if(ZYF_RET_OK == ZYF_GetNetworkInfo(&nwMode))
    {
        ZYF_LOG("ZYF_GetNetworkInfo:%d",nwMode);
    }
    else
    {
        ZYF_LOG("ZYF_GetNetworkInfo fail");
    }
    
    ms = ZYF_GetTickMs();
    high = (ms >> 32) & 0xFFFFFFFF;
    low = ms & 0xFFFFFFFF;
    ZYF_LOG("ZYF_GetLocalTimeMs %lu,%lu", high,low);

    sec = ZYF_GetLocalTimeSec();
    high = (sec >> 32) & 0xFFFFFFFF;
    low = sec& 0xFFFFFFFF;

    ZYF_LOG("ZYF_GetLocalTimeSec: %lu,%lu", high,low);

    //ZYF_LOG("ZYF_FlightModeOnOff:%d",ZYF_FlightModeOnOff(1,FlightModeOnOff));
    ZYF_LOG("ZYF_FlightModeIsOn:%d",ZYF_FlightModeIsOn());


    ZYF_LOG("SystemApi nwscanmode:%d",ZYF_Getnwscanmode());
    ZYF_GetImei(Imei,sizeof(Imei));
    ZYF_LOG("SystemApi Imei:%s",Imei);
    ZYF_GetCsqValue(&csq);
    ZYF_LOG("SystemApi csq:%d",csq);
    ZYF_GetCregStatus(&CregStatus);
    ZYF_LOG("SystemApi CregStatus:%d",CregStatus);

    ZYF_GetCgregStatus(&CgregStatus, plmn, &lac_value, &ci_value);
    ZYF_LOG("SystemApi CregStatus:CgregStatus:%02X,plmn:%02x%x%02x,lac_value:%X,ci_value:%X",\
                    CregStatus, plmn[0],plmn[1],plmn[2], lac_value, ci_value);

    ZYF_GetIccid(GetIccidCallback);
    ZYF_GetImsi(GetImsiCallback);

    ZYF_LOG("ZYF_SleepEnable:%d",ZYF_SleepEnable());
    
    for (int i = 0; i < PINNAME_MAX; i ++) {
        if(i == PINNAME_AP_READY || i == PINNAME_WAKE_IN)
            continue;
        ZYF_GpioInit((Enum_PinName)i, PINDIRECTION_IN, PINLEVEL_HIGH, PINPULLSEL_DISABLE);
        ZYF_ThreadSleep(10);
    }
    ZYF_GpioInit(PINNAME_AP_READY, PINDIRECTION_OUT, PINLEVEL_HIGH, PINPULLSEL_DISABLE);
    ZYF_GpioInit(PINNAME_WAKE_IN, PINDIRECTION_OUT, PINLEVEL_HIGH, PINPULLSEL_DISABLE);
    ZYF_ThreadSleep(2000);
    init_eints_pin();
    ZYF_ThreadSleep(1000);

    setmcu2poweroffM601(12000000); //power off M601
//    Nordic_sleep_func();        //lowpoer nrf52832

}


void SystemApiThread_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_SystemApiTest();
    
    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("UartThread_Example", SystemApiThread_Example, NULL, ZYF_PRIORITY_HIGH, 10*1024);
    return 0;
}

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








猜你喜欢

转载自blog.csdn.net/w_hizyf_m/article/details/108358604