📄 cmx_interval.c
字号:
//*****************************************************************************
//*****************************************************************************
// FILENAME: CMX_INTERVAL.c
// Version: 1.1, Updated on 2008/6/23 at 14:8:8
//
//
// DESCRIPTION: This file contains the C code for the INTERVAL driver.
//
// Note:
//
//-----------------------------------------------------------------------------
// Copyright (c) Cypress MicroSystems 2004. All Rights Reserved.
//*****************************************************************************
//*****************************************************************************
#include "m8c.h"
#include "PSoCAPI.h"
#include "CMX_INTERVAL.h"
#include "cmx.h"
#include "SystemTimer.h"
WORD CMX_INTERVAL_StartTicks[CMX_INTERVAL_COUNT];
unsigned char CMX_INTERVAL_Status[CMX_INTERVAL_COUNT];
//-----------------------------------------------------------------------------
// FUNCTION NAME: INTERVAL_Instantiate(const CMX_INTERVAL_ParameterBlock * thisBLK)
//
// DESCRIPTION:
// This function initializes the INTERVAL timer.
//
//-----------------------------------------------------------------------------
//
// ARGUMENTS:
// thisBLK => Pointer to ParameterBlock for this instance.
//
// RETURNS: None
//
// SIDE EFFECTS:
//
// THEORY of OPERATION or PROCEDURE:
//
//-----------------------------------------------------------------------------
void CMX_INTERVAL_Instantiate(const CMX_INTERVAL_ParameterBlock * thisBLK)
{
BYTE bInstance;
bInstance = thisBLK->bInstance; // Get Instance number
CMX_INTERVAL_Status[bInstance] = 0;
CMX_INTERVAL_StartTicks[bInstance] = SystemTimer_iGetTickCntr(); // Reset ticks
}
//-----------------------------------------------------------------------------
// FUNCTION NAME: INTERVAL_GetValue(const CMX_INTERVAL_ParameterBlock * thisBLK)
//
// DESCRIPTION:
// Adds the address given by bAddrOffset with the default address.
//
//-----------------------------------------------------------------------------
//
// ARGUMENTS: None
//
//
// RETURNS:
// Returns a 1 if timer has expired.
//
// SIDE EFFECTS:
//
// THEORY of OPERATION or PROCEDURE:
//
//-----------------------------------------------------------------------------
BYTE CMX_INTERVAL_GetValue(const CMX_INTERVAL_ParameterBlock * thisBLK)
{
BYTE bInstance; // Current INTERVAL instance
BYTE bMode; // 0 = Pulse, 1 = Toggle
BYTE bResult;
bInstance = thisBLK->bInstance; // Get Instance of this INTERVAL.
bMode = thisBLK->bMode;
bResult = CMX_INTERVAL_Status[bInstance]; // Get last status
if(((WORD)SystemTimer_iGetTickCntr() - CMX_INTERVAL_StartTicks[bInstance])>=thisBLK->iInterval)
{
CMX_INTERVAL_StartTicks[bInstance] = SystemTimer_iGetTickCntr();
if(bMode == 0)
{ // If pulse mode
bResult = 1; // Set to 1
}
else
{ // Toggle mode
bResult ^= 1; // Toggle output
}
}
else
{ // Timer has not expired
if(bMode == 0)
{ // Pulse mode?
bResult = 0; // Clear output
} // Else no change.
}
CMX_INTERVAL_Status[bInstance] = bResult; // Save current state
return bResult;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -