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

📄 sensor.c

📁 在ARM7和UC/OSII的平台上实现了GPS自动报站的功能,涉及GPS模块LEA_4S的驱动,位置速寻算法,语音芯片ISD4004的录放音驱动,LED页面管理等等.从启动代码到操作系统的移植以及到业
💻 C
字号:
/****************************************************************
**                                                              *
**  FILE         :  Sensor.C                                    *
**  COPYRIGHT    :  (c) 2001 .Xiamen Yaxon NetWork CO.LTD       *
**                                                              *
**                                                              *
**  By : Cyb 2007.7.1                                          *
****************************************************************/
#include "includes.h"
#include "bsp.h"
#include "errcode.h"
#include "errtask.h"
#include "message.h"
#include "hardware.h"
#include "tools.h"
#include "timetask.h"
#include "systask.h"
#include "almtask.h"
#include "sensor.h"
#include "uart_drv.h"


/*
********************************************************************************
*                  DEFINE CONFIG PARAMETERS
********************************************************************************
*/
#define NUM_SENSOR                              1

#define PERIOD_SAMPLE                           MILTICK, 1              /* PERIOD_SAMPLE = 50 ms */


/*
********************************************************************************
*                  DEFINE SENSOR PARAMETERS STRUCTURE
********************************************************************************
*/
typedef struct {
    INT16U      poscode;
    INT16U      validtime_logiclow;             /* UNIT: 100 ms */
    INT16U      validtime_logichigh;            /* UNIT: 100 ms */
} SENSORPARA_STRUCT;


/*
********************************************************************************
*                  DEFINE SENSOR PARAMETERS
********************************************************************************
*/
static SENSORPARA_STRUCT sensorpara[NUM_SENSOR] = {
                                                      { 0x0800,   20,    20}   /* REC_CON */
                                                  };


/*
********************************************************************************
*                  DEFINE MODULE VARIANT
********************************************************************************
*/
static INT16U   ct_hold[NUM_SENSOR];
static INT16U   filterstatus, curstatus, prestatus;
static TMR_TSK *sampletmr;



static void InitReadPort(void)
{
      
      InitPort_RECCON();
}

void ReadPort(void)
{

    curstatus = 0;
    
   
    if (ReadPort_RECCON())    curstatus |= sensorpara[_RECCON].poscode;
   

}

static void HdlTrigger(INT16U trigger)
{
    INT16U poscode;

	
    poscode = sensorpara[_RECCON].poscode;                             /* PORT: RECCON */
    
	if (trigger & poscode) 
	{
         if (filterstatus & poscode) 
	     {
             OSQPost(AlmTaskMsgQue,  MSG_SENSOR_TRIGGERECCON, 0, 0);
         }
	}
}


static void ReadCurStatus(void)
{
    INT8U  i;
    INT16U poscode;

    ReadPort();
    
    for (i = 0; i < NUM_SENSOR; i++) 
    {
        poscode = sensorpara[i].poscode;
        
        if ((curstatus & poscode) != (prestatus & poscode)) 
        {
            ct_hold[i] = 0;
            prestatus &= (~poscode);
            prestatus |= (curstatus & poscode);
        } 
        else if (ct_hold[i] != 0xffff) 
        {
            ct_hold[i]++;
        }
    }
}

static void SetStatus(void)
{
    INT8U  i;
    INT16U trigger, poscode, validtime;

    trigger       = 0;
    
    
    for (i = 0; i < NUM_SENSOR; i++) 
    {
        
       
        poscode = sensorpara[i].poscode;

        if (curstatus & poscode)
            validtime = sensorpara[i].validtime_logichigh;
        else
            validtime = sensorpara[i].validtime_logiclow;
        
        validtime *= 2;

        if (ct_hold[i] >= validtime) 
        {
            if (ct_hold[i] == validtime) 
            {
                if ((curstatus & poscode) != (filterstatus & poscode)) 
                {
                    trigger |= poscode;
                    if (curstatus & poscode) filterstatus |= poscode;
                    else filterstatus &= (~poscode);
                }
            }

           
       }
  }
    
    HdlTrigger(trigger);
   
}

static void SampleTmrProc(void)
{
    
    StartTmr(sampletmr, PERIOD_SAMPLE);
    ReadCurStatus();
    SetStatus();
}



static void DiagnoseProc(void)
{
   
    if (GetTmrSwitch(sampletmr) != ON) ErrExit(ERR_SENSOR_TMR);
}

void InitSensor(void)
{
    InitReadPort();                     /* Initialize Read Port */

    curstatus    = 0;
    prestatus    = 0;
    filterstatus = 0;
    

    InitBuf((INT8U *)ct_hold, 0, sizeof(ct_hold));
    

    sampletmr = CreateTimer(SampleTmrProc, 0);
    StartTmr(sampletmr, PERIOD_SAMPLE);

    InstallDiagProc(DiagnoseProc);
}

void UnlockSensor(INT8U type)
{
    if (type > NUM_SENSOR) ErrExit(ERR_SENSOR_TYPE);

       SampleTmrProc();
}

BOOLEAN ParseSensor(INT8U type, INT16U status)
{
    if (type >= NUM_SENSOR) {
        ErrExit(ERR_SENSOR_TYPE);
        return FALSE;
    }

    if (status & sensorpara[type].poscode) return TRUE;
    else return FALSE;
}



BOOLEAN SensorValid_FILTER(INT8U type)
{
    return ParseSensor(type, filterstatus);
}

⌨️ 快捷键说明

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