⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 handset.c

📁 在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LEA_4S的驱动,位置速寻算法,语音芯片ISD4004的录放音驱动,LED页面管理等等.从启动代码到操作系统的移植以及到业
💻 C
字号:
/****************************************************************
**                                                              *
**  FILE         :  Handset.C                                   *
**  COPYRIGHT    :  (c) 2001 .Xiamen Yaxon NetWork CO.LTD       *
**                                                              *
**                                                              *
**  By : CCH 2002.1.15                                          *
****************************************************************/
#define  HANDSET_GLOBALS
#include "includes.h"
#include "bsp.h"
#include "message.h"
#include "tools.h"
#include "sensor.h"
#include "public.h"
#include "timetask.h"
#include "at_core.h"
#include "phonedrv.h"
#include "hstcfg.h"
#include "record.h"
#include "keyboard.h"
#include "hstctl.h"
#include "winstack.h"
#include "prompt.h"
#include "virphone.h"
#include "adconst.h"
#include "succor.h"
#include "mainwin.h"
#include "watchdog.h"
#include "handset.h"

#include "debug.h"

#if EN_HANDSET > 0
 

/*
********************************************************************************
*                  DEFINE CONFIG PARAMETERS
********************************************************************************
*/
#define SIZE_MSGBUF                         20

#define PERIOD_RESET                        SECOND, 1

#define ON_                                 0xAA
#define OFF_                                0x55


/*
********************************************************************************
*                  DEFINE MODULE VARIANTS
********************************************************************************
*/
static OS_QMSG MsgBuf[SIZE_MSGBUF];
static OS_STK  HandsetStack[STACK_HANDSET];

static INT8U       status, wdgid;
static KEY_STRUCT  curkey;
static TMR_TSK    *ResetTmr;


static void ResetTmrProc(void)
{
    StopTmr(ResetTmr);
    Pullup_HANDSET_SAVE();
}

static void ResetHandset(void)
{
    Pulldown_HANDSET_SAVE();
    StartTmr(ResetTmr, PERIOD_RESET);
}

static void POWERON(void)
{
    TurnonHst();
    AdjustContrast();                           /* adjust handset constrast */
    DestroyWinStack();
    
    status         = ON_;
    HstMiss.NumTel = 0;
    StartDetectKeyBoard();

    ResetVirPhone();                            /* reset virphone */
    ActivateMainWin();                          /* activate mainwin */
}

static void POWEROFF(void)
{
    StopTmr(ResetTmr);
    Pulldown_HANDSET_SAVE();
    
    TurnoffHst();
    DestroyWinStack();
    StopDetectKeyBoard();
    status = OFF_;
}

static void HDL_KEY_INEXIST(void)
{
    ResetHandset();
}

static void HDL_KEY_NOOPERATE(void)
{
#if EN_GPSSLEEP > 0
    if (CanControlHandset()) {;
        if (!SensorValid_LOCK(_ACC) && status == ON_ && !VirPhoneIsActivated())
            POWEROFF();
    }
#endif
}

static void HdlACCON(void)
{
#if EN_GPSSLEEP > 0
    if (status != ON_ && SensorValid_LOCK(_ACC))
        ResetHandset();
#endif
}

/*
static void HdlExtInt(void)
{
    if (status != ON) return;
    
}

*/
static FUNCENTRY_STRUCT Handler_Key_entry[] = { 
                                                KEY_PWR_ON,                     POWERON,
                                                KEY_PWR_OFF,                    POWEROFF,
                                                KEY_INEXIST,                    HDL_KEY_INEXIST,
                                                KEY_NOOPERATE,                  HDL_KEY_NOOPERATE
                                              };
static void HdlKey(void)
{
    GetKeyMsg(&curkey);
    if (!FindProcEntry(curkey.key, Handler_Key_entry, sizeof(Handler_Key_entry)/sizeof(Handler_Key_entry[0])))
        WinStackProc();
}

static void HdlPhoneStatus(void)
{
    INT8U phonestatus;
    
    phonestatus = GetPhoneStatus(PHONE_COM);
    if (phonestatus == PHONE_RINGING) {
        if (status != ON_) 
            HangupVirPhone();
        else 
            ActivateVirPhone_Ring();
    } else {
        InformVirPhone(phonestatus);
    }
}

static void HdlRecvSM(void)
{
    if (status == ON_) {
        TurnonSMIndicator();
        if (!VirPhoneIsActivated()) RequestRing(HstCfg.SMRing);
    }
}

static void HdlSignal(void)
{
    if (status == ON_ && !VirPhoneIsActivated()) {
        CtlSignalIndicator(GetSignalIntensity());
    }
}

static FUNCENTRY_STRUCT functionentry[] = { 
                                            MSG_HANDSET_KEY,                HdlKey,
                                            MSG_HANDSET_RECVSM,             HdlRecvSM,
                                            MSG_HANDSET_PHONESTATUS,        HdlPhoneStatus,
                                            MSG_HANDSET_SIGNAL,             HdlSignal,
                                            MSG_HANDSET_STOPPHONE,          HangupVirPhone,
                                            MSG_HANDSET_ACCON,              HdlACCON
                                          };
                                          
static void HandsetTask(void *pd)
{
    pd = pd;
    
    status = OFF_;    
    InitKeyBoard();                         /* init keyboard */
    InitWinStack();                         /* init winstack */
    InitPrompt();                           /* init prompt */
    InitVirPhone();                         /* init virphone */
    InitSuccor();                           /* init succor */
    InitADConst();                          /* init ADConst */
    InitRecord();                           /* init record */  
    InitMainWin();                          /* init mainwin */
    wdgid    = ApplyWatchDogID();           /* install watch dog */
    ResetTmr = CreateTimer(ResetTmrProc, 0);
    if (!CanControlHandset()) {
        POWERON();                          /* power on handset */
    } else {
        ResetHandset();
    }

    for(;;) {
        if (OSQPend(HandsetMsgQue, 20, &HandsetCurMsg) == OS_NO_ERR) {
            if (!FindProcEntry(HandsetCurMsg.MsgID, functionentry, sizeof(functionentry)/sizeof(functionentry[0])))
                WinStackProc();
        }
        ResetWatchDog(wdgid);
    }
}

void CreateHandset(void)
{
    HandsetMsgQue = OSQCreate(MsgBuf, sizeof(MsgBuf)/sizeof(MsgBuf[0]));
    OSTaskCreate(HandsetTask, (void *)0, &HandsetStack[STACK_HANDSET], PRIO_HANDSET);
}

void SendKeyMsg(INT8U attrib, INT8U keyid)
{
    OSQPost(HandsetMsgQue, MSG_HANDSET_KEY, attrib, keyid);
}

void GetKeyMsg(KEY_STRUCT *key)
{
    key->attrib = HandsetCurMsg.LMsgPara;
    key->key    = HandsetCurMsg.HMsgPara;
}
#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -